UNPKG

@grafana/ui

Version:
118 lines (113 loc) 4.07 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var jsxRuntime = require('react/jsx-runtime'); var css = require('@emotion/css'); var ThemeContext = require('../../themes/ThemeContext.cjs'); var mixins = require('../../themes/mixins.cjs'); "use strict"; const CardInner = ({ children, href }) => { const { inner } = ThemeContext.useStyles2(getCardInnerStyles); return href ? /* @__PURE__ */ jsxRuntime.jsx("a", { className: inner, href, children }) : /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }); }; const getCardInnerStyles = (theme) => ({ inner: css.css({ display: "flex", width: "100%", padding: theme.spacing(2) }) }); const CardContainer = ({ children, disableEvents, disableHover, isSelected, className, href, noMargin, hasDescriptionComponent = false, hasTagsComponent = false, ...props }) => { const { oldContainer } = ThemeContext.useStyles2( getCardContainerStyles, disableEvents, disableHover, hasDescriptionComponent, hasTagsComponent, isSelected, void 0, noMargin ); return /* @__PURE__ */ jsxRuntime.jsx("div", { ...props, className: css.cx(oldContainer, className), children: /* @__PURE__ */ jsxRuntime.jsx(CardInner, { href, children }) }); }; const getCardContainerStyles = (theme, disabled = false, disableHover = false, hasDescriptionComponent, hasTagsComponent, isSelected, isCompact, noMargin = false) => { const isSelectable = isSelected !== void 0; const headingRow = `"Figure Heading ${hasTagsComponent && !isSelectable ? "Tags" : "Heading"}" ${hasDescriptionComponent ? "" : "1fr"}`; const metaRow = `"Figure Meta ${hasTagsComponent ? "Tags" : "Meta"}"`; const descriptionRow = `"Figure Description ${hasTagsComponent ? "Tags" : "Description"}" 1fr`; const actionsRow = `"Figure Actions Secondary" / auto 1fr auto`; return { container: css.css({ display: "grid", position: "relative", gridTemplate: ` ${headingRow} ${metaRow} ${hasDescriptionComponent ? descriptionRow : ""} ${actionsRow} `, gridAutoColumns: "1fr", gridAutoFlow: "row", width: "100%", padding: theme.spacing(isCompact ? 1 : 2), background: theme.colors.background.secondary, borderRadius: theme.shape.radius.lg, marginBottom: theme.spacing(noMargin ? 0 : 1), pointerEvents: disabled ? "none" : "auto", [theme.transitions.handleMotion("no-preference", "reduce")]: { 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": mixins.getFocusStyles(theme) }, ...isSelectable && { cursor: "pointer" }, ...isSelected && { outline: `solid 2px ${theme.colors.primary.border}` } }), oldContainer: css.css({ display: "flex", width: "100%", background: theme.colors.background.secondary, borderRadius: theme.shape.radius.lg, position: "relative", pointerEvents: disabled ? "none" : "auto", marginBottom: theme.spacing(noMargin ? 0 : 1), [theme.transitions.handleMotion("no-preference", "reduce")]: { 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": mixins.getFocusStyles(theme) } }) }; }; exports.CardContainer = CardContainer; exports.getCardContainerStyles = getCardContainerStyles; //# sourceMappingURL=CardContainer.cjs.map