@mantine/core
Version:
React components library focused on usability, accessibility and developer experience
1 lines • 4.54 kB
Source Map (JSON)
{"version":3,"file":"Overlay.cjs","names":["getDefaultZIndex","createVarsResolver","rgba","rem","getRadius","polymorphicFactory","useProps","Box","useStyles","classes"],"sources":["../../../src/components/Overlay/Overlay.tsx"],"sourcesContent":["import {\n Box,\n BoxProps,\n createVarsResolver,\n getDefaultZIndex,\n getRadius,\n MantineRadius,\n polymorphicFactory,\n PolymorphicFactory,\n rem,\n rgba,\n StylesApiProps,\n useProps,\n useStyles,\n} from '../../core';\nimport classes from './Overlay.module.css';\n\nexport type OverlayStylesNames = 'root';\nexport type OverlayCssVariables = {\n root: '--overlay-bg' | '--overlay-filter' | '--overlay-radius' | '--overlay-z-index';\n};\n\nexport interface OverlayProps extends BoxProps, StylesApiProps<OverlayFactory> {\n /** Overlay `background-color` opacity 0–1, ignored when `gradient` prop is set @default 0.6 */\n backgroundOpacity?: number;\n\n /** Overlay `background-color` @default #000 */\n color?: React.CSSProperties['backgroundColor'];\n\n /** Overlay background blur in px (converted to rem). Applies `backdrop-filter: blur()`. Note: backdrop-filter is not supported in all browsers. @default 0 */\n blur?: number | string;\n\n /** Changes overlay to gradient. If set, both `color` and `backgroundOpacity` props are ignored. */\n gradient?: string;\n\n /** Overlay z-index @default 200 */\n zIndex?: string | number;\n\n /** Key of `theme.radius` or any valid CSS value to set border-radius @default 0 */\n radius?: MantineRadius;\n\n /** Content inside overlay */\n children?: React.ReactNode;\n\n /** Centers content inside the overlay using flexbox (sets display: flex, align-items: center, justify-content: center) @default false */\n center?: boolean;\n\n /** Changes position from `absolute` to `fixed` (viewport-relative instead of parent-relative) @default false */\n fixed?: boolean;\n}\n\nexport type OverlayFactory = PolymorphicFactory<{\n props: OverlayProps;\n defaultRef: HTMLDivElement;\n defaultComponent: 'div';\n stylesNames: OverlayStylesNames;\n vars: OverlayCssVariables;\n}>;\n\nconst defaultProps = {\n zIndex: getDefaultZIndex('modal'),\n} satisfies Partial<OverlayProps>;\n\nconst varsResolver = createVarsResolver<OverlayFactory>(\n (_, { gradient, color, backgroundOpacity, blur, radius, zIndex }) => ({\n root: {\n '--overlay-bg':\n gradient ||\n ((color !== undefined || backgroundOpacity !== undefined) &&\n rgba(color || '#000', backgroundOpacity ?? 0.6)) ||\n undefined,\n '--overlay-filter': blur ? `blur(${rem(blur)})` : undefined,\n '--overlay-radius': radius === undefined ? undefined : getRadius(radius),\n '--overlay-z-index': zIndex?.toString(),\n },\n })\n);\n\nexport const Overlay = polymorphicFactory<OverlayFactory>((_props) => {\n const props = useProps('Overlay', defaultProps, _props);\n const {\n classNames,\n className,\n style,\n styles,\n unstyled,\n vars,\n fixed,\n center,\n children,\n radius,\n zIndex,\n gradient,\n blur,\n color,\n backgroundOpacity,\n mod,\n attributes,\n ...others\n } = props;\n\n const getStyles = useStyles<OverlayFactory>({\n name: 'Overlay',\n props,\n classes,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n });\n\n return (\n <Box {...getStyles('root')} mod={[{ center, fixed }, mod]} {...others}>\n {children}\n </Box>\n );\n});\n\nOverlay.classes = classes;\nOverlay.varsResolver = varsResolver;\nOverlay.displayName = '@mantine/core/Overlay';\n"],"mappings":";;;;;;;;;;;;;;AA2DA,MAAM,eAAe,EACnB,QAAQA,4BAAAA,iBAAiB,QAAQ,EAClC;AAED,MAAM,eAAeC,6BAAAA,oBAClB,GAAG,EAAE,UAAU,OAAO,mBAAmB,MAAM,QAAQ,cAAc,EACpE,MAAM;CACJ,gBACE,aACE,UAAU,KAAA,KAAa,sBAAsB,KAAA,MAC7CC,aAAAA,KAAK,SAAS,QAAQ,qBAAqB,GAAI,IACjD,KAAA;CACF,oBAAoB,OAAO,QAAQC,YAAAA,IAAI,KAAK,CAAC,KAAK,KAAA;CAClD,oBAAoB,WAAW,KAAA,IAAY,KAAA,IAAYC,iBAAAA,UAAU,OAAO;CACxE,qBAAqB,QAAQ,UAAU;CACxC,EACF,EACF;AAED,MAAa,UAAUC,4BAAAA,oBAAoC,WAAW;CACpE,MAAM,QAAQC,kBAAAA,SAAS,WAAW,cAAc,OAAO;CACvD,MAAM,EACJ,YACA,WACA,OACA,QACA,UACA,MACA,OACA,QACA,UACA,QACA,QACA,UACA,MACA,OACA,mBACA,KACA,YACA,GAAG,WACD;AAgBJ,QACE,iBAAA,GAAA,kBAAA,KAACC,YAAAA,KAAD;EAAK,GAfWC,mBAAAA,UAA0B;GAC1C,MAAM;GACN;GACA,SAAA,uBAAA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACD,CAAC,CAGmB,OAAO;EAAE,KAAK,CAAC;GAAE;GAAQ;GAAO,EAAE,IAAI;EAAE,GAAI;EAC5D;EACG,CAAA;EAER;AAEF,QAAQ,UAAUC,uBAAAA;AAClB,QAAQ,eAAe;AACvB,QAAQ,cAAc"}