, Ca
disableEvents?: boolean;
/** No style change on hover */
disableHover?: boolean;
+ /** Makes the card selectable, set to "true" to apply selected styles */
+ isSelected?: boolean;
/** Custom container styles */
className?: string;
}
@@ -48,12 +50,13 @@ export const CardContainer = ({
children,
disableEvents,
disableHover,
+ isSelected,
className,
href,
...props
}: CardContainerProps) => {
const theme = useTheme2();
- const { oldContainer } = getCardContainerStyles(theme, disableEvents, disableHover);
+ const { oldContainer } = getCardContainerStyles(theme, disableEvents, disableHover, isSelected);
return (
{children}
@@ -61,59 +64,71 @@ export const CardContainer = ({
);
};
-export const getCardContainerStyles = stylesFactory((theme: GrafanaTheme2, disabled = false, disableHover = false) => {
- return {
- container: css({
- display: 'grid',
- position: 'relative',
- gridTemplateColumns: 'auto 1fr auto',
- gridTemplateRows: '1fr auto auto auto',
- gridAutoColumns: '1fr',
- gridAutoFlow: 'row',
- gridTemplateAreas: `
+export const getCardContainerStyles = stylesFactory(
+ (theme: GrafanaTheme2, disabled = false, disableHover = false, isSelected = false) => {
+ const isSelectable = isSelected !== undefined;
+
+ return {
+ container: css({
+ display: 'grid',
+ position: 'relative',
+ gridTemplateColumns: 'auto 1fr auto',
+ gridTemplateRows: '1fr auto auto auto',
+ gridAutoColumns: '1fr',
+ gridAutoFlow: 'row',
+ gridTemplateAreas: `
"Figure Heading Tags"
"Figure Meta Tags"
"Figure Description Tags"
"Figure Actions Secondary"`,
- width: '100%',
- padding: theme.spacing(2),
- background: theme.colors.background.secondary,
- borderRadius: theme.shape.borderRadius(),
- marginBottom: '8px',
- pointerEvents: disabled ? 'none' : 'auto',
- transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color', 'color'], {
- duration: theme.transitions.duration.short,
- }),
+ width: '100%',
+ padding: theme.spacing(2),
+ background: theme.colors.background.secondary,
+ borderRadius: theme.shape.borderRadius(),
+ marginBottom: '8px',
+ pointerEvents: disabled ? 'none' : 'auto',
+ transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color', 'color'], {
+ duration: theme.transitions.duration.short,
+ }),
- ...(!disableHover && {
- '&:hover': {
- background: theme.colors.emphasize(theme.colors.background.secondary, 0.03),
- cursor: 'pointer',
- zIndex: 1,
- },
- '&:focus': styleMixins.getFocusStyles(theme),
- }),
- }),
- oldContainer: css({
- display: 'flex',
- width: '100%',
- background: theme.colors.background.secondary,
- borderRadius: theme.shape.borderRadius(),
- position: 'relative',
- pointerEvents: disabled ? 'none' : 'auto',
- marginBottom: theme.spacing(1),
- transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color', 'color'], {
- duration: theme.transitions.duration.short,
- }),
+ ...(!disableHover && {
+ '&:hover': {
+ background: theme.colors.emphasize(theme.colors.background.secondary, 0.03),
+ cursor: 'pointer',
+ zIndex: 1,
+ },
+ '&:focus': styleMixins.getFocusStyles(theme),
+ }),
- ...(!disableHover && {
- '&:hover': {
- background: theme.colors.emphasize(theme.colors.background.secondary, 0.03),
+ ...(isSelectable && {
cursor: 'pointer',
- zIndex: 1,
- },
- '&:focus': styleMixins.getFocusStyles(theme),
+ }),
+
+ ...(isSelected && {
+ outline: `solid 2px ${theme.colors.primary.border}`,
+ }),
}),
- }),
- };
-});
+ oldContainer: css({
+ display: 'flex',
+ width: '100%',
+ background: theme.colors.background.secondary,
+ borderRadius: theme.shape.borderRadius(),
+ position: 'relative',
+ pointerEvents: disabled ? 'none' : 'auto',
+ marginBottom: theme.spacing(1),
+ transition: theme.transitions.create(['background-color', 'box-shadow', 'border-color', 'color'], {
+ duration: theme.transitions.duration.short,
+ }),
+
+ ...(!disableHover && {
+ '&:hover': {
+ background: theme.colors.emphasize(theme.colors.background.secondary, 0.03),
+ cursor: 'pointer',
+ zIndex: 1,
+ },
+ '&:focus': styleMixins.getFocusStyles(theme),
+ }),
+ }),
+ };
+ }
+);