UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 3.56 kB
{"version":3,"file":"GridVariables.cjs","names":["useMantineTheme","filterProps","getSpacing","getBaseValue","keys","getSortedBreakpoints","InlineStyles"],"sources":["../../../src/components/Grid/GridVariables.tsx"],"sourcesContent":["import {\n filterProps,\n getBaseValue,\n getSortedBreakpoints,\n getSpacing,\n InlineStyles,\n keys,\n useMantineTheme,\n} from '../../core';\nimport type { GridProps } from './Grid';\nimport type { GridBreakpoints } from './Grid.context';\n\ninterface GridVariablesProps extends GridProps {\n selector: string;\n}\n\nexport function GridVariables({\n gap,\n rowGap,\n columnGap,\n selector,\n breakpoints,\n type,\n}: GridVariablesProps) {\n const theme = useMantineTheme();\n const _breakpoints = breakpoints || theme.breakpoints;\n\n const baseStyles: Record<string, string | undefined> = filterProps({\n '--grid-gap': getSpacing(getBaseValue(gap)),\n '--grid-row-gap': getSpacing(getBaseValue(rowGap)),\n '--grid-column-gap': getSpacing(getBaseValue(columnGap)),\n });\n\n const queries = keys(_breakpoints).reduce<Record<string, Record<string, any>>>(\n (acc, breakpoint) => {\n if (!acc[breakpoint]) {\n acc[breakpoint] = {};\n }\n\n if (typeof gap === 'object' && gap[breakpoint] !== undefined) {\n acc[breakpoint]['--grid-gap'] = getSpacing(gap[breakpoint]);\n }\n\n if (typeof rowGap === 'object' && rowGap[breakpoint] !== undefined) {\n acc[breakpoint]['--grid-row-gap'] = getSpacing(rowGap[breakpoint]);\n }\n\n if (typeof columnGap === 'object' && columnGap[breakpoint] !== undefined) {\n acc[breakpoint]['--grid-column-gap'] = getSpacing(columnGap[breakpoint]);\n }\n\n return acc;\n },\n {}\n );\n\n const sortedBreakpoints = getSortedBreakpoints(keys(queries), _breakpoints).filter(\n (breakpoint) => keys(queries[breakpoint.value]).length > 0\n );\n\n const values = sortedBreakpoints.map((breakpoint) => ({\n query:\n type === 'container'\n ? `mantine-grid (min-width: ${_breakpoints[breakpoint.value as keyof GridBreakpoints]})`\n : `(min-width: ${_breakpoints[breakpoint.value as keyof GridBreakpoints]})`,\n styles: queries[breakpoint.value],\n }));\n\n return (\n <InlineStyles\n styles={baseStyles}\n media={type === 'container' ? undefined : values}\n container={type === 'container' ? values : undefined}\n selector={selector}\n />\n );\n}\n"],"mappings":";;;;;;;;;;;AAgBA,SAAgB,cAAc,EAC5B,KACA,QACA,WACA,UACA,aACA,QACqB;CACrB,MAAM,QAAQA,6BAAAA,gBAAgB;CAC9B,MAAM,eAAe,eAAe,MAAM;CAE1C,MAAM,aAAiDC,qBAAAA,YAAY;EACjE,cAAcC,iBAAAA,WAAWC,uBAAAA,aAAa,GAAG,CAAC;EAC1C,kBAAkBD,iBAAAA,WAAWC,uBAAAA,aAAa,MAAM,CAAC;EACjD,qBAAqBD,iBAAAA,WAAWC,uBAAAA,aAAa,SAAS,CAAC;CACzD,CAAC;CAED,MAAM,UAAUC,aAAAA,KAAK,YAAY,EAAE,QAChC,KAAK,eAAe;EACnB,IAAI,CAAC,IAAI,aACP,IAAI,cAAc,CAAC;EAGrB,IAAI,OAAO,QAAQ,YAAY,IAAI,gBAAgB,KAAA,GACjD,IAAI,YAAY,gBAAgBF,iBAAAA,WAAW,IAAI,WAAW;EAG5D,IAAI,OAAO,WAAW,YAAY,OAAO,gBAAgB,KAAA,GACvD,IAAI,YAAY,oBAAoBA,iBAAAA,WAAW,OAAO,WAAW;EAGnE,IAAI,OAAO,cAAc,YAAY,UAAU,gBAAgB,KAAA,GAC7D,IAAI,YAAY,uBAAuBA,iBAAAA,WAAW,UAAU,WAAW;EAGzE,OAAO;CACT,GACA,CAAC,CACH;CAMA,MAAM,SAJoBG,+BAAAA,qBAAqBD,aAAAA,KAAK,OAAO,GAAG,YAAY,EAAE,QACzE,eAAeA,aAAAA,KAAK,QAAQ,WAAW,MAAM,EAAE,SAAS,CAG5B,EAAE,KAAK,gBAAgB;EACpD,OACE,SAAS,cACL,4BAA4B,aAAa,WAAW,OAAgC,KACpF,eAAe,aAAa,WAAW,OAAgC;EAC7E,QAAQ,QAAQ,WAAW;CAC7B,EAAE;CAEF,OACE,iBAAA,GAAA,kBAAA,KAACE,qBAAAA,cAAD;EACE,QAAQ;EACR,OAAO,SAAS,cAAc,KAAA,IAAY;EAC1C,WAAW,SAAS,cAAc,SAAS,KAAA;EACjC;CACX,CAAA;AAEL"}