Skip to content

Commit

Permalink
feat(Highlighter): support wrap props
Browse files Browse the repository at this point in the history
  • Loading branch information
Carrotzpc committed Aug 12, 2024
1 parent ce8141b commit 17b6edd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Highlighter/demos/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default () => {
value: 'block',
},
fullFeatured: false,
wrap: false,
},
{ store }
);
Expand Down
8 changes: 7 additions & 1 deletion src/Highlighter/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export interface HighlighterProps extends DivProps {
* @description The style of the code content
*/
contentStyle?: React.CSSProperties;
/**
* @description Control text wrap
* @default false
*/
wrap?: boolean;
}

export const Highlighter = memo<HighlighterProps>(
Expand All @@ -65,10 +70,11 @@ export const Highlighter = memo<HighlighterProps>(
fileName,
icon,
contentStyle,
wrap,
...rest
}) => {
const { styles, cx } = useStyles(type);
const container = cx(styles.container, className);
const container = cx(styles.container, !wrap && styles.nowrap, className);

if (fullFeatured)
return (
Expand Down
6 changes: 5 additions & 1 deletion src/Highlighter/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ export const useStyles = createStyles(
}
code {
text-wrap: nowrap !important;
background: transparent !important;
}
`
Expand All @@ -90,6 +89,11 @@ export const useStyles = createStyles(
transition: opacity 0.1s;
`
),
nowrap: css`
code {
text-wrap: nowrap !important;
}
`,
scroller: css`
overflow: auto;
width: 100%;
Expand Down

0 comments on commit 17b6edd

Please sign in to comment.