@mantine/code-highlight
Version:
Code highlight with Mantine theme
1 lines • 3.21 kB
Source Map (JSON)
{"version":3,"file":"InlineCodeHighlight.mjs","names":["classes"],"sources":["../../src/CodeHighlight/InlineCodeHighlight.tsx"],"sourcesContent":["import {\n BoxProps,\n createVarsResolver,\n ElementProps,\n factory,\n Factory,\n getRadius,\n getThemeColor,\n MantineColor,\n MantineRadius,\n StylesApiProps,\n useProps,\n useStyles,\n} from '@mantine/core';\nimport { CodeHighlight } from './CodeHighlight';\nimport classes from '../CodeHighlight.module.css';\n\nexport type InlineCodeHighlightStylesNames = 'inlineCodeHighlight';\nexport type InlineCodeHighlightCssVariables = {\n inlineCodeHighlight: '--ch-background' | '--ch-radius';\n};\n\nexport interface InlineCodeHighlightProps\n extends BoxProps, StylesApiProps<InlineCodeHighlightFactory>, ElementProps<'code'> {\n /** Code to highlight */\n code: string;\n\n /** Language of the code, used to determine syntax highlighting */\n language?: string;\n\n /** Controls background color of the code. By default, the value depends on color scheme. */\n background?: MantineColor;\n\n /** Key of `theme.radius` or any valid CSS value to set border-radius @default 'sm' */\n radius?: MantineRadius;\n\n /** Adds border to the root element @default false */\n withBorder?: boolean;\n}\n\nexport type InlineCodeHighlightFactory = Factory<{\n props: InlineCodeHighlightProps;\n ref: HTMLElement;\n stylesNames: InlineCodeHighlightStylesNames;\n vars: InlineCodeHighlightCssVariables;\n}>;\n\nconst varsResolver = createVarsResolver<InlineCodeHighlightFactory>(\n (theme, { background, radius }) => ({\n inlineCodeHighlight: {\n '--ch-background': background ? getThemeColor(background, theme) : undefined,\n '--ch-radius': typeof radius !== 'undefined' ? getRadius(radius) : undefined,\n },\n })\n);\n\nexport const InlineCodeHighlight = factory<InlineCodeHighlightFactory>((_props) => {\n const props = useProps('InlineCodeHighlight', null, _props);\n const { classNames, className, style, styles, unstyled, vars, attributes, ref, ...others } =\n props;\n\n const getStyles = useStyles<InlineCodeHighlightFactory>({\n name: 'InlineCodeHighlight',\n classes,\n props,\n className,\n style,\n classNames,\n styles,\n unstyled,\n attributes,\n vars,\n varsResolver,\n rootSelector: 'inlineCodeHighlight',\n });\n\n return (\n <CodeHighlight {...others} ref={ref as any} {...getStyles('inlineCodeHighlight')} __inline />\n );\n});\n\nInlineCodeHighlight.displayName = '@mantine/code-highlight/InlineCodeHighlight';\nInlineCodeHighlight.classes = classes;\nInlineCodeHighlight.varsResolver = varsResolver;\n"],"mappings":";;;;;;AA+CA,MAAM,eAAe,oBAClB,OAAO,EAAE,YAAY,cAAc,EAClC,qBAAqB;CACnB,mBAAmB,aAAa,cAAc,YAAY,KAAK,IAAI,KAAA;CACnE,eAAe,OAAO,WAAW,cAAc,UAAU,MAAM,IAAI,KAAA;AACrE,EACF,EACF;AAEA,MAAa,sBAAsB,SAAqC,WAAW;CACjF,MAAM,QAAQ,SAAS,uBAAuB,MAAM,MAAM;CAC1D,MAAM,EAAE,YAAY,WAAW,OAAO,QAAQ,UAAU,MAAM,YAAY,KAAK,GAAG,WAChF;CAEF,MAAM,YAAY,UAAsC;EACtD,MAAM;EACN,SAAA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,cAAc;CAChB,CAAC;CAED,OACE,oBAAC,eAAD;EAAe,GAAI;EAAa;EAAY,GAAI,UAAU,qBAAqB;EAAG,UAAA;CAAU,CAAA;AAEhG,CAAC;AAED,oBAAoB,cAAc;AAClC,oBAAoB,UAAUA;AAC9B,oBAAoB,eAAe"}