UNPKG

@mantine/core

Version:

React components library focused on usability, accessibility and developer experience

1 lines 1.69 kB
{"version":3,"file":"InlineStyles.cjs","names":["useMantineStyleNonce","stylesToString"],"sources":["../../../src/core/InlineStyles/InlineStyles.tsx"],"sourcesContent":["import { useMantineStyleNonce } from '../MantineProvider';\nimport { InlineStylesInput, stylesToString } from './styles-to-string/styles-to-string';\n\nexport interface InlineStylesProps\n extends InlineStylesInput, Omit<React.ComponentProps<'style'>, keyof InlineStylesInput> {\n deduplicate?: boolean;\n}\n\nfunction simpleHash(str: string): string {\n let hash = 5381;\n for (let i = 0; i < str.length; i++) {\n hash = ((hash << 5) + hash + str.charCodeAt(i)) & 0xffffffff;\n }\n return (hash >>> 0).toString(36);\n}\n\nexport function InlineStyles({ deduplicate, ...props }: InlineStylesProps) {\n const nonce = useMantineStyleNonce();\n const css = stylesToString(props);\n\n if (deduplicate) {\n return (\n <style href={`mantine-${simpleHash(css)}`} precedence=\"mantine\" nonce={nonce?.()}>\n {css}\n </style>\n );\n }\n\n return (\n <style\n data-mantine-styles=\"inline\"\n nonce={nonce?.()}\n dangerouslySetInnerHTML={{ __html: css }}\n />\n );\n}\n"],"mappings":";;;;;;AAQA,SAAS,WAAW,KAAqB;CACvC,IAAI,OAAO;CACX,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,KAC9B,QAAS,QAAQ,KAAK,OAAO,IAAI,WAAW,CAAC,IAAK;CAEpD,QAAQ,SAAS,GAAG,SAAS,EAAE;AACjC;AAEA,SAAgB,aAAa,EAAE,aAAa,GAAG,SAA4B;CACzE,MAAM,QAAQA,wBAAAA,qBAAqB;CACnC,MAAM,MAAMC,yBAAAA,eAAe,KAAK;CAEhC,IAAI,aACF,OACE,iBAAA,GAAA,kBAAA,KAAC,SAAD;EAAO,MAAM,WAAW,WAAW,GAAG;EAAK,YAAW;EAAU,OAAO,QAAQ;YAC5E;CACI,CAAA;CAIX,OACE,iBAAA,GAAA,kBAAA,KAAC,SAAD;EACE,uBAAoB;EACpB,OAAO,QAAQ;EACf,yBAAyB,EAAE,QAAQ,IAAI;CACxC,CAAA;AAEL"}