Skip to content

Commit 6103ef6

Browse files
chore(components): make the changes to modular css with global overrides
1 parent 33810d0 commit 6103ef6

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

packages/components/src/Snippet.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { cx } from 'classix';
12
import Prism from 'prismjs';
23
import { type JSX, useLayoutEffect, useRef } from 'react';
34

@@ -44,7 +45,7 @@ import { CopyToClipboard } from './CopyToClipboard';
4445

4546
import 'prismjs/plugins/line-numbers/prism-line-numbers.css';
4647

47-
import './styles/Snippet.css';
48+
import styles from './styles/Snippet.module.css';
4849

4950
export const languages = [
5051
'bash',
@@ -146,16 +147,19 @@ export function Snippet({
146147
return (
147148
<>
148149
{withHeader && (
149-
<div className="header">
150+
<div className={styles.header}>
150151
{label && <span>{label}</span>}
151152
{lang && <span>{lang}</span>}
152153
</div>
153154
)}
154155
<div
155-
className={`snippet ${className ?? ''} ${withCopyButton ? 'copyable' : ''} ${useDefaultHighlighting ? 'useDefaultHighlighting' : ''}`}
156+
className={cx(styles.snippet, className, {
157+
[styles.copyable]: withCopyButton,
158+
[styles.useDefaultHighlighting]: useDefaultHighlighting,
159+
})}
156160
>
157161
<pre
158-
className={withLineNumbers ? 'line-numbers' : ''}
162+
className={withLineNumbers ? styles['line-numbers'] : ''}
159163
data-start={1}
160164
data-line-offset={highlightOffset ? highlightOffset.toString() : ''}
161165
data-line={highlightRange}
@@ -166,7 +170,7 @@ export function Snippet({
166170
{withCopyButton && (
167171
<CopyToClipboard text={children as string} showTooltip={false}>
168172
<IconButton
169-
className="copyButton"
173+
className={styles.copyButton}
170174
aria-label="Copy code snippet"
171175
variant="minimal"
172176
icon="copy-code"

packages/components/src/styles/Snippet.css renamed to packages/components/src/styles/Snippet.module.css

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
background: #3c4200;
8484
}
8585

86-
.snippet pre[class*='language-'].line-numbers {
86+
.snippet :global(pre[class*='language-'].line-numbers) {
8787
line-height: 0.625rem;
8888
padding-bottom: var(--lp-spacing-400);
8989
padding-top: var(--lp-spacing-400);
@@ -92,36 +92,36 @@
9292
z-index: var(--stacking-above-new-context);
9393
}
9494

95-
.snippet .line-numbers .line-numbers-rows {
95+
.snippet :global(.line-numbers .line-numbers-rows) {
9696
border: none;
9797
left: -3em;
9898
width: 2em;
9999
}
100100

101-
.snippet .token.operator,
102-
.snippet .token.punctuation {
101+
.snippet :global(.token.operator),
102+
.snippet :global(.token.punctuation) {
103103
color: var(--lp-color-text-ui-primary-base);
104104
}
105105

106-
.snippet .token.function {
106+
.snippet :global(.token.function) {
107107
color: var(--lp-color-text-code-function);
108108
font-weight: var(--lp-font-weight-regular);
109109
}
110110

111-
.snippet .token.tag {
111+
.snippet :global(.token.tag) {
112112
color: var(--lp-color-text-code-tag);
113113
}
114114

115-
.token.attr-value,
116-
.token.string {
115+
.snippet :global(.token.attr-value),
116+
.snippet :global(.token.string) {
117117
color: var(--lp-color-text-code-string);
118118
}
119119

120-
.snippet .token.property {
120+
.snippet :global(.token.property) {
121121
color: var(--lp-color-text-code-keyword);
122122
}
123123

124-
.snippet .token.keyword {
124+
.snippet :global(.token.keyword) {
125125
color: var(--lp-color-text-code-keyword);
126126
}
127127

0 commit comments

Comments
 (0)