UNPKG

@grafana/ui

Version:
211 lines (208 loc) • 5.84 kB
import { jsx } from 'react/jsx-runtime'; import { cx, css } from '@emotion/css'; import { forwardRef } from 'react'; import { useStyles2 } from '../../../themes/ThemeContext.mjs'; import { getResponsiveStyle } from '../utils/responsiveness.mjs'; import { getSizeStyles } from '../utils/styles.mjs'; const Box = forwardRef((props, ref) => { const { children, margin, marginX, marginY, marginTop, marginBottom, marginLeft, marginRight, padding, paddingX, paddingY, paddingTop, paddingBottom, paddingLeft, paddingRight, display, backgroundColor, grow, shrink, basis, flex, borderColor, borderStyle, borderRadius, direction, justifyContent, alignItems, boxShadow, element, gap, width, minWidth, maxWidth, height, minHeight, maxHeight, position, ...rest } = props; const styles = useStyles2( getStyles, margin, marginX, marginY, marginTop, marginBottom, marginLeft, marginRight, padding, paddingX, paddingY, paddingTop, paddingBottom, paddingLeft, paddingRight, display, backgroundColor, grow, shrink, basis, flex, borderColor, borderStyle, borderRadius, direction, justifyContent, alignItems, boxShadow, gap, position ); const sizeStyles = useStyles2(getSizeStyles, width, minWidth, maxWidth, height, minHeight, maxHeight); const Element = element != null ? element : "div"; return /* @__PURE__ */ jsx(Element, { ref, className: cx(styles.root, sizeStyles), ...rest, children }); }); Box.displayName = "Box"; const customBorderColor = (color, theme) => { switch (color) { case "error": case "success": case "info": case "warning": return theme.colors[color].borderTransparent; default: return color ? theme.colors.border[color] : void 0; } }; const customBackgroundColor = (color, theme) => { switch (color) { case "error": case "success": case "info": case "warning": return theme.colors[color].transparent; default: return color ? theme.colors.background[color] : void 0; } }; const getStyles = (theme, margin, marginX, marginY, marginTop, marginBottom, marginLeft, marginRight, padding, paddingX, paddingY, paddingTop, paddingBottom, paddingLeft, paddingRight, display, backgroundColor, grow, shrink, basis, flex, borderColor, borderStyle, borderRadius, direction, justifyContent, alignItems, boxShadow, gap, position) => { return { root: css([ getResponsiveStyle(theme, margin, (val) => ({ margin: theme.spacing(val) })), getResponsiveStyle(theme, marginX, (val) => ({ marginLeft: theme.spacing(val), marginRight: theme.spacing(val) })), getResponsiveStyle(theme, marginY, (val) => ({ marginTop: theme.spacing(val), marginBottom: theme.spacing(val) })), getResponsiveStyle(theme, marginTop, (val) => ({ marginTop: theme.spacing(val) })), getResponsiveStyle(theme, marginBottom, (val) => ({ marginBottom: theme.spacing(val) })), getResponsiveStyle(theme, marginLeft, (val) => ({ marginLeft: theme.spacing(val) })), getResponsiveStyle(theme, marginRight, (val) => ({ marginRight: theme.spacing(val) })), getResponsiveStyle(theme, padding, (val) => ({ padding: theme.spacing(val) })), getResponsiveStyle(theme, paddingX, (val) => ({ paddingLeft: theme.spacing(val), paddingRight: theme.spacing(val) })), getResponsiveStyle(theme, paddingY, (val) => ({ paddingTop: theme.spacing(val), paddingBottom: theme.spacing(val) })), getResponsiveStyle(theme, paddingTop, (val) => ({ paddingTop: theme.spacing(val) })), getResponsiveStyle(theme, paddingBottom, (val) => ({ paddingBottom: theme.spacing(val) })), getResponsiveStyle(theme, paddingLeft, (val) => ({ paddingLeft: theme.spacing(val) })), getResponsiveStyle(theme, paddingRight, (val) => ({ paddingRight: theme.spacing(val) })), getResponsiveStyle(theme, display, (val) => ({ display: val })), getResponsiveStyle(theme, backgroundColor, (val) => ({ backgroundColor: customBackgroundColor(val, theme) })), getResponsiveStyle(theme, direction, (val) => ({ flexDirection: val })), getResponsiveStyle(theme, grow, (val) => ({ flexGrow: val })), getResponsiveStyle(theme, shrink, (val) => ({ flexShrink: val })), getResponsiveStyle(theme, basis, (val) => ({ flexBasis: val })), getResponsiveStyle(theme, flex, (val) => ({ flex: val })), getResponsiveStyle(theme, borderStyle, (val) => ({ borderStyle: val })), getResponsiveStyle(theme, borderColor, (val) => ({ borderColor: customBorderColor(val, theme) })), (borderStyle || borderColor) && { borderWidth: "1px" }, getResponsiveStyle(theme, justifyContent, (val) => ({ justifyContent: val })), getResponsiveStyle(theme, alignItems, (val) => ({ alignItems: val })), getResponsiveStyle(theme, borderRadius, (val) => ({ borderRadius: theme.shape.radius[val] })), getResponsiveStyle(theme, boxShadow, (val) => ({ boxShadow: theme.shadows[val] })), getResponsiveStyle(theme, gap, (val) => ({ gap: theme.spacing(val) })), getResponsiveStyle(theme, position, (val) => ({ position: val })) ]) }; }; export { Box }; //# sourceMappingURL=Box.mjs.map