Skip to content

Commit

Permalink
[@mantine/Prism] Fix lines highlight color not respecting colorScheme…
Browse files Browse the repository at this point in the history
… prop (#2404)
  • Loading branch information
rtivital committed Sep 14, 2022
1 parent 4967a38 commit 6963d64
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 6 deletions.
34 changes: 34 additions & 0 deletions src/mantine-prism/src/Prism/Prism.story.tsx
Expand Up @@ -54,3 +54,37 @@ export const LargeLine = () => (
is so large that it will cause overflow Lorem ipsum dolor sit amet consectetur,
</Prism>
);

const demoCode = `
import { Button } from '@mantine/core';
function Demo() {
return <Button>Hello</Button>
}
function Usage() {
return <ActionIcon>Hello</ActionIcon>;
}
`;
export function LinesHighlightWithCustomTheme() {
const deleted = { color: 'red', label: '-' };
const added = { color: 'green', label: '+' };

return (
<Prism
language="tsx"
withLineNumbers
colorScheme="dark"
highlightLines={{
3: deleted,
4: deleted,
5: deleted,
7: added,
8: added,
9: added,
}}
>
{demoCode}
</Prism>
);
}
2 changes: 1 addition & 1 deletion src/mantine-prism/src/Prism/Prism.styles.ts
Expand Up @@ -36,7 +36,7 @@ export default createStyles(
zIndex: 2,

'&, &:hover': {
backgroundColor: theme.colorScheme === 'dark' ? theme.colors.dark[8] : theme.colors.gray[0],
backgroundColor: colorScheme === 'dark' ? theme.colors.dark[8] : theme.colors.gray[0],
},
},

Expand Down
11 changes: 6 additions & 5 deletions src/mantine-prism/src/Prism/Prism.tsx
Expand Up @@ -96,9 +96,10 @@ export const Prism = forwardRef<HTMLDivElement, PrismProps>((props: PrismProps,

const theme = useMantineTheme();
const clipboard = useClipboard();
const _colorScheme = colorScheme || theme.colorScheme;
const { classes, cx } = useStyles(
{
colorScheme: colorScheme || theme.colorScheme,
colorScheme: _colorScheme,
native: ScrollAreaComponent !== ScrollArea,
maxLineSize,
radius,
Expand Down Expand Up @@ -131,7 +132,7 @@ export const Prism = forwardRef<HTMLDivElement, PrismProps>((props: PrismProps,

<Highlight
{...defaultProps}
theme={getPrismTheme(theme, colorScheme || theme.colorScheme)}
theme={getPrismTheme(theme, _colorScheme)}
code={code}
language={language}
>
Expand All @@ -158,7 +159,7 @@ export const Prism = forwardRef<HTMLDivElement, PrismProps>((props: PrismProps,
const lineProps = getLineProps({ line, key: index });
const shouldHighlight = lineNumber in highlightLines;
const lineColor =
theme.colorScheme === 'dark'
_colorScheme === 'dark'
? theme.fn.rgba(
theme.fn.themeColor(highlightLines[lineNumber]?.color, 9),
0.25
Expand All @@ -178,7 +179,7 @@ export const Prism = forwardRef<HTMLDivElement, PrismProps>((props: PrismProps,
color: shouldHighlight
? theme.fn.themeColor(
highlightLines[lineNumber]?.color,
theme.colorScheme === 'dark' ? 5 : 8
_colorScheme === 'dark' ? 5 : 8
)
: undefined,
}}
Expand All @@ -198,7 +199,7 @@ export const Prism = forwardRef<HTMLDivElement, PrismProps>((props: PrismProps,
color: shouldHighlight
? theme.fn.themeColor(
highlightLines[lineNumber]?.color,
theme.colorScheme === 'dark' ? 5 : 8
_colorScheme === 'dark' ? 5 : 8
)
: (tokenProps?.style?.color as string),
}}
Expand Down

0 comments on commit 6963d64

Please sign in to comment.