@mantine/code-highlight 7.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -0
- package/cjs/CodeHighlight.js +126 -0
- package/cjs/CodeHighlight.js.map +1 -0
- package/cjs/CodeHighlight.module.css.js +8 -0
- package/cjs/CodeHighlight.module.css.js.map +1 -0
- package/cjs/CodeHighlight.theme.module.css.js +8 -0
- package/cjs/CodeHighlight.theme.module.css.js.map +1 -0
- package/cjs/CodeHighlightTabs.js +196 -0
- package/cjs/CodeHighlightTabs.js.map +1 -0
- package/cjs/CopyIcon.js +70 -0
- package/cjs/CopyIcon.js.map +1 -0
- package/cjs/ExpandIcon.js +83 -0
- package/cjs/ExpandIcon.js.map +1 -0
- package/cjs/FileIcon.js +22 -0
- package/cjs/FileIcon.js.map +1 -0
- package/cjs/InlineCodeHighlight.js +78 -0
- package/cjs/InlineCodeHighlight.js.map +1 -0
- package/cjs/index.css +326 -0
- package/cjs/index.js +14 -0
- package/cjs/index.js.map +1 -0
- package/cjs/use-highlight.js +27 -0
- package/cjs/use-highlight.js.map +1 -0
- package/esm/CodeHighlight.js +117 -0
- package/esm/CodeHighlight.js.map +1 -0
- package/esm/CodeHighlight.module.css.js +4 -0
- package/esm/CodeHighlight.module.css.js.map +1 -0
- package/esm/CodeHighlight.theme.module.css.js +4 -0
- package/esm/CodeHighlight.theme.module.css.js.map +1 -0
- package/esm/CodeHighlightTabs.js +186 -0
- package/esm/CodeHighlightTabs.js.map +1 -0
- package/esm/CopyIcon.js +62 -0
- package/esm/CopyIcon.js.map +1 -0
- package/esm/ExpandIcon.js +75 -0
- package/esm/ExpandIcon.js.map +1 -0
- package/esm/FileIcon.js +14 -0
- package/esm/FileIcon.js.map +1 -0
- package/esm/InlineCodeHighlight.js +68 -0
- package/esm/InlineCodeHighlight.js.map +1 -0
- package/esm/index.css +326 -0
- package/esm/index.js +4 -0
- package/esm/index.js.map +1 -0
- package/esm/use-highlight.js +19 -0
- package/esm/use-highlight.js.map +1 -0
- package/lib/CodeHighlight.d.ts +29 -0
- package/lib/CodeHighlightTabs.d.ts +55 -0
- package/lib/CopyIcon.d.ts +9 -0
- package/lib/ExpandIcon.d.ts +6 -0
- package/lib/FileIcon.d.ts +8 -0
- package/lib/InlineCodeHighlight.d.ts +19 -0
- package/lib/index.d.ts +6 -0
- package/lib/use-highlight.d.ts +15 -0
- package/package.json +42 -0
- package/src/CodeHighlight.module.css +153 -0
- package/src/CodeHighlight.story.tsx +218 -0
- package/src/CodeHighlight.test.tsx +30 -0
- package/src/CodeHighlight.theme.module.css +95 -0
- package/src/CodeHighlight.tsx +123 -0
- package/src/CodeHighlightTabs.test.tsx +39 -0
- package/src/CodeHighlightTabs.tsx +252 -0
- package/src/CopyIcon.tsx +37 -0
- package/src/ExpandIcon.tsx +42 -0
- package/src/FileIcon.tsx +19 -0
- package/src/InlineCodeHighlight.test.tsx +25 -0
- package/src/InlineCodeHighlight.tsx +72 -0
- package/src/index.ts +23 -0
- package/src/use-highlight.ts +30 -0
- package/styles.css +326 -0
- package/tsconfig.build.json +23 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +23 -0
package/esm/index.css
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
1
|
+
.mantine-XIBJZDt {
|
|
2
|
+
display: inline-block;
|
|
3
|
+
padding: 0.0625rem 0.1875rem;
|
|
4
|
+
font-size: 0.8125rem;
|
|
5
|
+
border-radius: var(--mantine-radius-xs);
|
|
6
|
+
line-height: var(--_code-line-height, var(--mantine-line-height));
|
|
7
|
+
font-family: var(--mantine-font-family-monospace);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.mantine-RDvBcjB {
|
|
11
|
+
display: block;
|
|
12
|
+
padding: var(--mantine-spacing-xs) var(--mantine-spacing-md);
|
|
13
|
+
margin: 0;
|
|
14
|
+
--_code-line-height: 1.7;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.mantine-cmEtjrV {
|
|
18
|
+
display: flex;
|
|
19
|
+
align-items: flex-start;
|
|
20
|
+
justify-content: space-between;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.mantine-059sM-t {
|
|
24
|
+
display: flex;
|
|
25
|
+
margin-top: 0.4375rem;
|
|
26
|
+
margin-right: 0.4375rem;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.mantine-tB-P5PD,
|
|
30
|
+
.mantine-NTm-nGn {
|
|
31
|
+
background-color: transparent;
|
|
32
|
+
opacity: 0.8;
|
|
33
|
+
margin: 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@media (hover: hover) {
|
|
37
|
+
|
|
38
|
+
.mantine-tB-P5PD:hover, .mantine-NTm-nGn:hover {
|
|
39
|
+
opacity: 1;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@media (hover: none) {
|
|
44
|
+
|
|
45
|
+
.mantine-tB-P5PD:active, .mantine-NTm-nGn:active {
|
|
46
|
+
opacity: 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@media (max-width: 40em) {
|
|
51
|
+
|
|
52
|
+
.mantine-tB-P5PD,
|
|
53
|
+
.mantine-NTm-nGn {
|
|
54
|
+
display: none
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
.mantine-tB-P5PD {
|
|
59
|
+
position: absolute;
|
|
60
|
+
top: 0.3125rem;
|
|
61
|
+
right: 0.3125rem;
|
|
62
|
+
z-index: 1;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.mantine-PBrPXnu {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: center;
|
|
69
|
+
font-size: var(--mantine-font-size-xs);
|
|
70
|
+
gap: 0.4375rem;
|
|
71
|
+
padding: 0.4375rem 0.75rem;
|
|
72
|
+
font-family: var(--mantine-font-family-monospace);
|
|
73
|
+
font-weight: 700;
|
|
74
|
+
line-height: 1;
|
|
75
|
+
user-select: none;
|
|
76
|
+
cursor: var(--_file-cursor);
|
|
77
|
+
border: 0.0625rem solid var(--_file-bd);
|
|
78
|
+
border-top: 0;
|
|
79
|
+
border-left: 0;
|
|
80
|
+
color: var(--_file-color);
|
|
81
|
+
opacity: var(--_file-opacity);
|
|
82
|
+
background-color: var(--_file-bg);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@media (hover: hover) {
|
|
86
|
+
|
|
87
|
+
.mantine-PBrPXnu:hover {
|
|
88
|
+
--_file-opacity: 1;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@media (hover: none) {
|
|
93
|
+
|
|
94
|
+
.mantine-PBrPXnu:active {
|
|
95
|
+
--_file-opacity: 1;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
.mantine-PBrPXnu:last-of-type {
|
|
100
|
+
border-bottom-right-radius: var(--mantine-radius-sm);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.mantine-PBrPXnu:only-child {
|
|
104
|
+
--_file-cursor: default;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.mantine-PBrPXnu[data-active] {
|
|
108
|
+
--_file-opacity: 1;
|
|
109
|
+
--_file-color: var(--_file-active-color) !important;
|
|
110
|
+
--_file-bg: var(--_file-active-bg);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
.mantine-PBrPXnu {
|
|
114
|
+
|
|
115
|
+
--_file-opacity: 0.8;
|
|
116
|
+
--_file-cursor: pointer;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
[data-mantine-color-scheme='light'] .mantine-PBrPXnu {
|
|
120
|
+
--_file-color: var(--mantine-color-gray-8);
|
|
121
|
+
--_file-bd: var(--mantine-color-gray-2);
|
|
122
|
+
--_file-active-bg: var(--mantine-color-white);
|
|
123
|
+
--_file-active-color: var(--mantine-color-black);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@media (prefers-color-scheme: light) {
|
|
127
|
+
|
|
128
|
+
.mantine-PBrPXnu {
|
|
129
|
+
--_file-color: var(--mantine-color-gray-8);
|
|
130
|
+
--_file-bd: var(--mantine-color-gray-2);
|
|
131
|
+
--_file-active-bg: var(--mantine-color-white);
|
|
132
|
+
--_file-active-color: var(--mantine-color-black);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
[data-mantine-color-scheme='dark'] .mantine-PBrPXnu {
|
|
137
|
+
--_file-color: var(--mantine-color-dark-0);
|
|
138
|
+
--_file-bd: var(--mantine-color-dark-4);
|
|
139
|
+
--_file-active-bg: var(--mantine-color-dark-6);
|
|
140
|
+
--_file-active-color: var(--mantine-color-white);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@media (prefers-color-scheme: dark) {
|
|
144
|
+
|
|
145
|
+
.mantine-PBrPXnu {
|
|
146
|
+
--_file-color: var(--mantine-color-dark-0);
|
|
147
|
+
--_file-bd: var(--mantine-color-dark-4);
|
|
148
|
+
--_file-active-bg: var(--mantine-color-dark-6);
|
|
149
|
+
--_file-active-color: var(--mantine-color-white);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.mantine-IvOddiX {
|
|
154
|
+
display: flex;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.mantine-YfYyOiA {
|
|
158
|
+
max-height: var(--ch-max-collapsed-height);
|
|
159
|
+
overflow: hidden;
|
|
160
|
+
position: relative;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.mantine-YfYyOiA::before {
|
|
164
|
+
content: '';
|
|
165
|
+
position: absolute;
|
|
166
|
+
inset: 0;
|
|
167
|
+
pointer-events: none;
|
|
168
|
+
background-image: linear-gradient(0deg, var(--_background) 16%, rgba(0, 0, 0, 0) 100%);
|
|
169
|
+
border-radius: calc(var(--mantine-radius-md) - 0.0625rem);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
.mantine-YfYyOiA[data-expanded] {
|
|
173
|
+
max-height: none;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
.mantine-YfYyOiA[data-expanded]::before {
|
|
177
|
+
display: none;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.mantine-haNyFRC {
|
|
181
|
+
position: absolute;
|
|
182
|
+
bottom: 0;
|
|
183
|
+
left: 50%;
|
|
184
|
+
transform: translateX(-50%);
|
|
185
|
+
font-size: var(--mantine-font-size-sm);
|
|
186
|
+
color: var(--mantine-color-anchor);
|
|
187
|
+
width: 100%;
|
|
188
|
+
text-align: center;
|
|
189
|
+
padding-top: var(--mantine-spacing-xs);
|
|
190
|
+
padding-bottom: var(--mantine-spacing-xs);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
.mantine-haNyFRC[data-hidden] {
|
|
194
|
+
display: none;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.mantine-k6OJW8l {
|
|
198
|
+
margin-top: 0;
|
|
199
|
+
position: relative;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.mantine-h-DP-Yw {
|
|
203
|
+
color: var(--_color);
|
|
204
|
+
background: var(--_background);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
[data-mantine-color-scheme='light'] .mantine-h-DP-Yw {
|
|
208
|
+
--_color: var(--mantine-color-gray-7);
|
|
209
|
+
--_background: var(--mantine-color-gray-0);
|
|
210
|
+
--code-comment-color: var(--mantine-color-gray-6);
|
|
211
|
+
--code-keyword-color: var(--mantine-color-violet-8);
|
|
212
|
+
--code-tag-color: var(--mantine-color-red-9);
|
|
213
|
+
--code-literal-color: var(--mantine-color-blue-6);
|
|
214
|
+
--code-string-color: var(--mantine-color-blue-9);
|
|
215
|
+
--code-variable-color: var(--mantine-color-lime-9);
|
|
216
|
+
--code-class-color: var(--mantine-color-orange-9);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@media (prefers-color-scheme: light) {
|
|
220
|
+
|
|
221
|
+
.mantine-h-DP-Yw {
|
|
222
|
+
--_color: var(--mantine-color-gray-7);
|
|
223
|
+
--_background: var(--mantine-color-gray-0);
|
|
224
|
+
--code-comment-color: var(--mantine-color-gray-6);
|
|
225
|
+
--code-keyword-color: var(--mantine-color-violet-8);
|
|
226
|
+
--code-tag-color: var(--mantine-color-red-9);
|
|
227
|
+
--code-literal-color: var(--mantine-color-blue-6);
|
|
228
|
+
--code-string-color: var(--mantine-color-blue-9);
|
|
229
|
+
--code-variable-color: var(--mantine-color-lime-9);
|
|
230
|
+
--code-class-color: var(--mantine-color-orange-9);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
[data-mantine-color-scheme='dark'] .mantine-h-DP-Yw {
|
|
235
|
+
--_color: var(--mantine-color-dark-1);
|
|
236
|
+
--_background: var(--mantine-color-dark-8);
|
|
237
|
+
--code-comment-color: var(--mantine-color-dark-3);
|
|
238
|
+
--code-keyword-color: var(--mantine-color-violet-3);
|
|
239
|
+
--code-tag-color: var(--mantine-color-yellow-4);
|
|
240
|
+
--code-literal-color: var(--mantine-color-blue-4);
|
|
241
|
+
--code-string-color: var(--mantine-color-green-6);
|
|
242
|
+
--code-variable-color: var(--mantine-color-blue-2);
|
|
243
|
+
--code-class-color: var(--mantine-color-orange-5);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
@media (prefers-color-scheme: dark) {
|
|
247
|
+
|
|
248
|
+
.mantine-h-DP-Yw {
|
|
249
|
+
--_color: var(--mantine-color-dark-1);
|
|
250
|
+
--_background: var(--mantine-color-dark-8);
|
|
251
|
+
--code-comment-color: var(--mantine-color-dark-3);
|
|
252
|
+
--code-keyword-color: var(--mantine-color-violet-3);
|
|
253
|
+
--code-tag-color: var(--mantine-color-yellow-4);
|
|
254
|
+
--code-literal-color: var(--mantine-color-blue-4);
|
|
255
|
+
--code-string-color: var(--mantine-color-green-6);
|
|
256
|
+
--code-variable-color: var(--mantine-color-blue-2);
|
|
257
|
+
--code-class-color: var(--mantine-color-orange-5);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.mantine-h-DP-Yw .hljs-comment,
|
|
262
|
+
.mantine-h-DP-Yw .hljs-quote {
|
|
263
|
+
font-style: italic;
|
|
264
|
+
color: var(--code-comment-color);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
.mantine-h-DP-Yw .hljs-doctag,
|
|
268
|
+
.mantine-h-DP-Yw .hljs-formula,
|
|
269
|
+
.mantine-h-DP-Yw .hljs-keyword {
|
|
270
|
+
color: var(--code-keyword-color);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
.mantine-h-DP-Yw .hljs-deletion,
|
|
274
|
+
.mantine-h-DP-Yw .hljs-name,
|
|
275
|
+
.mantine-h-DP-Yw .hljs-section,
|
|
276
|
+
.mantine-h-DP-Yw .hljs-selector-tag,
|
|
277
|
+
.mantine-h-DP-Yw .hljs-subst {
|
|
278
|
+
color: var(--code-tag-color);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.mantine-h-DP-Yw .hljs-literal {
|
|
282
|
+
color: var(--code-literal-color);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.mantine-h-DP-Yw .hljs-addition,
|
|
286
|
+
.mantine-h-DP-Yw .hljs-attribute,
|
|
287
|
+
.mantine-h-DP-Yw .hljs-meta .hljs-string,
|
|
288
|
+
.mantine-h-DP-Yw .hljs-regexp,
|
|
289
|
+
.mantine-h-DP-Yw .hljs-string {
|
|
290
|
+
color: var(--code-string-color);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
.mantine-h-DP-Yw .hljs-attr,
|
|
294
|
+
.mantine-h-DP-Yw .hljs-number,
|
|
295
|
+
.mantine-h-DP-Yw .hljs-selector-attr,
|
|
296
|
+
.mantine-h-DP-Yw .hljs-selector-class,
|
|
297
|
+
.mantine-h-DP-Yw .hljs-selector-pseudo,
|
|
298
|
+
.mantine-h-DP-Yw .hljs-template-variable,
|
|
299
|
+
.mantine-h-DP-Yw .hljs-type,
|
|
300
|
+
.mantine-h-DP-Yw .hljs-variable {
|
|
301
|
+
color: var(--code-variable-color);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
.mantine-h-DP-Yw .hljs-bullet,
|
|
305
|
+
.mantine-h-DP-Yw .hljs-link,
|
|
306
|
+
.mantine-h-DP-Yw .hljs-meta,
|
|
307
|
+
.mantine-h-DP-Yw .hljs-selector-id,
|
|
308
|
+
.mantine-h-DP-Yw .hljs-symbol,
|
|
309
|
+
.mantine-h-DP-Yw .hljs-title,
|
|
310
|
+
.mantine-h-DP-Yw .hljs-built_in,
|
|
311
|
+
.mantine-h-DP-Yw .hljs-class .hljs-title,
|
|
312
|
+
.mantine-h-DP-Yw .hljs-title.class_ {
|
|
313
|
+
color: var(--code-class-color);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.mantine-h-DP-Yw .hljs-emphasis {
|
|
317
|
+
font-style: italic;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.mantine-h-DP-Yw .hljs-strong {
|
|
321
|
+
font-weight: 700;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
.mantine-h-DP-Yw .hljs-link {
|
|
325
|
+
text-decoration: underline;
|
|
326
|
+
}
|
package/esm/index.js
ADDED
package/esm/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useState, useEffect } from 'react';
|
|
2
|
+
import hljs from 'highlight.js';
|
|
3
|
+
|
|
4
|
+
function useHighlight({ code, language, highlightOnClient }) {
|
|
5
|
+
const getHighlightedCode = () => hljs.highlight(code.trim(), { language }).value;
|
|
6
|
+
const [highlighted, setHighlighted] = useState(!highlightOnClient);
|
|
7
|
+
const [highlightedCode, setHighlightedCode] = useState(highlightOnClient ? code : getHighlightedCode());
|
|
8
|
+
const getCodeProps = () => highlighted ? { dangerouslySetInnerHTML: { __html: highlightedCode } } : { children: code.trim() };
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
if (highlightOnClient) {
|
|
11
|
+
setHighlightedCode(getHighlightedCode());
|
|
12
|
+
setHighlighted(true);
|
|
13
|
+
}
|
|
14
|
+
}, []);
|
|
15
|
+
return getCodeProps;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { useHighlight };
|
|
19
|
+
//# sourceMappingURL=use-highlight.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-highlight.js","sources":["../src/use-highlight.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport hljs from 'highlight.js';\n\ninterface UseHighlightInput {\n code: string;\n language: string;\n highlightOnClient: boolean | undefined;\n}\n\nexport function useHighlight({ code, language, highlightOnClient }: UseHighlightInput) {\n const getHighlightedCode = () => hljs.highlight(code.trim(), { language: language! }).value;\n const [highlighted, setHighlighted] = useState(!highlightOnClient);\n const [highlightedCode, setHighlightedCode] = useState(\n highlightOnClient ? code : getHighlightedCode()\n );\n\n const getCodeProps = () =>\n highlighted\n ? { dangerouslySetInnerHTML: { __html: highlightedCode } }\n : { children: code.trim() };\n\n useEffect(() => {\n if (highlightOnClient) {\n setHighlightedCode(getHighlightedCode());\n setHighlighted(true);\n }\n }, []);\n\n return getCodeProps;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,YAAY,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,iBAAiB,EAAE,EAAE;AACpE,EAAE,MAAM,kBAAkB,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC;AACnF,EAAE,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,CAAC,iBAAiB,CAAC,CAAC;AACrE,EAAE,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,GAAG,QAAQ,CAAC,iBAAiB,GAAG,IAAI,GAAG,kBAAkB,EAAE,CAAC,CAAC;AAC1G,EAAE,MAAM,YAAY,GAAG,MAAM,WAAW,GAAG,EAAE,uBAAuB,EAAE,EAAE,MAAM,EAAE,eAAe,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,EAAE,CAAC;AAChI,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,iBAAiB,EAAE;AAC3B,MAAM,kBAAkB,CAAC,kBAAkB,EAAE,CAAC,CAAC;AAC/C,MAAM,cAAc,CAAC,IAAI,CAAC,CAAC;AAC3B,KAAK;AACL,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,YAAY,CAAC;AACtB;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BoxProps, StylesApiProps, ElementProps, Factory } from '@mantine/core';
|
|
2
|
+
export type CodeHighlightStylesNames = 'root' | 'code' | 'pre' | 'copy';
|
|
3
|
+
export type CodeHighlightVariant = string;
|
|
4
|
+
export interface CodeHighlightProps extends BoxProps, StylesApiProps<CodeHighlightFactory>, ElementProps<'div'> {
|
|
5
|
+
/** Code to highlight */
|
|
6
|
+
code: string;
|
|
7
|
+
/** Code language, `'tsx'` by default */
|
|
8
|
+
language?: string;
|
|
9
|
+
/** Determines whether copy button should be displayed, `true` by default */
|
|
10
|
+
withCopyButton?: boolean;
|
|
11
|
+
/** Copy tooltip label, `'Copy code'` by default */
|
|
12
|
+
copyLabel?: string;
|
|
13
|
+
/** Copied tooltip label, `'Copied'` by default */
|
|
14
|
+
copiedLabel?: string;
|
|
15
|
+
/** Determines whether code should be highlighted only after component is mounted to the dom (disables code highlight on server), `false` by default */
|
|
16
|
+
highlightOnClient?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export type CodeHighlightFactory = Factory<{
|
|
19
|
+
props: CodeHighlightProps;
|
|
20
|
+
ref: HTMLDivElement;
|
|
21
|
+
stylesNames: CodeHighlightStylesNames;
|
|
22
|
+
variant: CodeHighlightVariant;
|
|
23
|
+
}>;
|
|
24
|
+
export declare const CodeHighlight: import("@mantine/core").MantineComponent<{
|
|
25
|
+
props: CodeHighlightProps;
|
|
26
|
+
ref: HTMLDivElement;
|
|
27
|
+
stylesNames: CodeHighlightStylesNames;
|
|
28
|
+
variant: CodeHighlightVariant;
|
|
29
|
+
}>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { BoxProps, StylesApiProps, ElementProps, Factory } from '@mantine/core';
|
|
3
|
+
export type CodeHighlightTabsStylesNames = 'root' | 'code' | 'codeWrapper' | 'showCodeButton' | 'pre' | 'controls' | 'control' | 'header' | 'file' | 'files';
|
|
4
|
+
export type CodeHighlightTabsVariant = string;
|
|
5
|
+
export type CodeHighlightTabsCssVariables = {
|
|
6
|
+
root: '--ch-max-collapsed-height';
|
|
7
|
+
};
|
|
8
|
+
export interface CodeHighlightTabsCode {
|
|
9
|
+
language?: string;
|
|
10
|
+
code: string;
|
|
11
|
+
fileName?: string;
|
|
12
|
+
icon?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
export interface CodeHighlightTabsProps extends BoxProps, StylesApiProps<CodeHighlightTabsFactory>, ElementProps<'div'> {
|
|
15
|
+
/** Code to highlight with meta data (file name and icon) */
|
|
16
|
+
code: CodeHighlightTabsCode | CodeHighlightTabsCode[];
|
|
17
|
+
/** Default active tab index */
|
|
18
|
+
defaultActiveTab?: number;
|
|
19
|
+
/** Index of controlled active tab state */
|
|
20
|
+
activeTab?: number;
|
|
21
|
+
/** Called when tab changes */
|
|
22
|
+
onTabChange?(tab: number): void;
|
|
23
|
+
/** Determines whether header with file names and copy button should be rendered, `true` by default */
|
|
24
|
+
withHeader?: boolean;
|
|
25
|
+
/** Copy tooltip label, `'Copy code'` by default */
|
|
26
|
+
copyLabel?: string;
|
|
27
|
+
/** Copied tooltip label, `'Copied'` by default */
|
|
28
|
+
copiedLabel?: string;
|
|
29
|
+
/** Function that returns icon based on file name */
|
|
30
|
+
getFileIcon?(fileName: string): React.ReactNode;
|
|
31
|
+
/** `max-height` of code in collapsed state, `'6rem'` by default */
|
|
32
|
+
maxCollapsedHeight?: React.CSSProperties['maxHeight'];
|
|
33
|
+
/** Controlled expanded state */
|
|
34
|
+
expanded?: boolean;
|
|
35
|
+
/** Uncontrolled expanded state initial value */
|
|
36
|
+
defaultExpanded?: boolean;
|
|
37
|
+
/** Called when expanded state changes */
|
|
38
|
+
onExpandedChange?(expanded: boolean): void;
|
|
39
|
+
/** Expand button label and tooltip, `'Expand code'` by default */
|
|
40
|
+
expandCodeLabel?: string;
|
|
41
|
+
/** Collapse button label and tooltip, `'Collapse code'` by default */
|
|
42
|
+
collapseCodeLabel?: string;
|
|
43
|
+
/** Determines whether to show the expand button, `false` by default */
|
|
44
|
+
withExpandButton?: boolean;
|
|
45
|
+
}
|
|
46
|
+
export type CodeHighlightTabsFactory = Factory<{
|
|
47
|
+
props: CodeHighlightTabsProps;
|
|
48
|
+
ref: HTMLDivElement;
|
|
49
|
+
stylesNames: CodeHighlightTabsStylesNames;
|
|
50
|
+
}>;
|
|
51
|
+
export declare const CodeHighlightTabs: import("@mantine/core").MantineComponent<{
|
|
52
|
+
props: CodeHighlightTabsProps;
|
|
53
|
+
ref: HTMLDivElement;
|
|
54
|
+
stylesNames: CodeHighlightTabsStylesNames;
|
|
55
|
+
}>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface CopyIconProps extends React.ComponentPropsWithoutRef<'svg'> {
|
|
3
|
+
copied: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function CopyIcon({ copied, style, ...others }: CopyIconProps): JSX.Element;
|
|
6
|
+
export declare namespace CopyIcon {
|
|
7
|
+
var displayName: string;
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface FileIconProps {
|
|
3
|
+
fileName: string | undefined;
|
|
4
|
+
getFileIcon?: ((fileName: string) => React.ReactNode) | undefined;
|
|
5
|
+
fileIcon: React.ReactNode | undefined;
|
|
6
|
+
}
|
|
7
|
+
export declare function FileIcon({ fileIcon, fileName, getFileIcon }: FileIconProps): JSX.Element | null;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { BoxProps, StylesApiProps, ElementProps, Factory } from '@mantine/core';
|
|
2
|
+
export type InlineCodeHighlightStylesNames = 'code';
|
|
3
|
+
export type InlineCodeHighlightVariant = string;
|
|
4
|
+
export interface InlineCodeHighlightProps extends BoxProps, StylesApiProps<InlineCodeHighlightFactory>, ElementProps<'div'> {
|
|
5
|
+
/** Code to highlight */
|
|
6
|
+
code: string;
|
|
7
|
+
/** Code language, `'tsx'` by default */
|
|
8
|
+
language?: string;
|
|
9
|
+
}
|
|
10
|
+
export type InlineCodeHighlightFactory = Factory<{
|
|
11
|
+
props: InlineCodeHighlightProps;
|
|
12
|
+
ref: HTMLElement;
|
|
13
|
+
stylesNames: InlineCodeHighlightStylesNames;
|
|
14
|
+
}>;
|
|
15
|
+
export declare const InlineCodeHighlight: import("@mantine/core").MantineComponent<{
|
|
16
|
+
props: InlineCodeHighlightProps;
|
|
17
|
+
ref: HTMLElement;
|
|
18
|
+
stylesNames: InlineCodeHighlightStylesNames;
|
|
19
|
+
}>;
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { CodeHighlightTabs } from './CodeHighlightTabs';
|
|
2
|
+
export { CodeHighlight } from './CodeHighlight';
|
|
3
|
+
export { InlineCodeHighlight } from './InlineCodeHighlight';
|
|
4
|
+
export type { CodeHighlightTabsFactory, CodeHighlightTabsStylesNames, CodeHighlightTabsProps, CodeHighlightTabsCode, CodeHighlightTabsVariant, CodeHighlightTabsCssVariables, } from './CodeHighlightTabs';
|
|
5
|
+
export type { CodeHighlightFactory, CodeHighlightProps, CodeHighlightStylesNames, CodeHighlightVariant, } from './CodeHighlight';
|
|
6
|
+
export type { InlineCodeHighlightFactory, InlineCodeHighlightProps, InlineCodeHighlightStylesNames, InlineCodeHighlightVariant, } from './InlineCodeHighlight';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
interface UseHighlightInput {
|
|
2
|
+
code: string;
|
|
3
|
+
language: string;
|
|
4
|
+
highlightOnClient: boolean | undefined;
|
|
5
|
+
}
|
|
6
|
+
export declare function useHighlight({ code, language, highlightOnClient }: UseHighlightInput): () => {
|
|
7
|
+
dangerouslySetInnerHTML: {
|
|
8
|
+
__html: string;
|
|
9
|
+
};
|
|
10
|
+
children?: undefined;
|
|
11
|
+
} | {
|
|
12
|
+
children: string;
|
|
13
|
+
dangerouslySetInnerHTML?: undefined;
|
|
14
|
+
};
|
|
15
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mantine/code-highlight",
|
|
3
|
+
"description": "Code highlight with Mantine theme",
|
|
4
|
+
"version": "7.0.0-alpha.1",
|
|
5
|
+
"main": "cjs/index.js",
|
|
6
|
+
"module": "esm/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"author": "Vitaly Rtishchev <rtivital@gmail.com>",
|
|
10
|
+
"sideEffects": false,
|
|
11
|
+
"homepage": "https://mantine.dev/others/prism/",
|
|
12
|
+
"repository": {
|
|
13
|
+
"url": "https://github.com/mantinedev/mantine.git",
|
|
14
|
+
"type": "git",
|
|
15
|
+
"directory": "src/mantine-prism"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"react",
|
|
19
|
+
"next",
|
|
20
|
+
"nextjs",
|
|
21
|
+
"ui",
|
|
22
|
+
"components",
|
|
23
|
+
"ui-kit",
|
|
24
|
+
"library",
|
|
25
|
+
"frontend",
|
|
26
|
+
"code",
|
|
27
|
+
"highlight",
|
|
28
|
+
"syntax",
|
|
29
|
+
"syntax-highlight"
|
|
30
|
+
],
|
|
31
|
+
"peerDependencies": {
|
|
32
|
+
"@mantine/core": "7.0.0-alpha.1",
|
|
33
|
+
"@mantine/hooks": "7.0.0-alpha.1",
|
|
34
|
+
"react": ">=16.8.0",
|
|
35
|
+
"react-dom": ">=16.8.0"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"highlight.js": "^11.7.0",
|
|
39
|
+
"clsx": "1.1.1"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {}
|
|
42
|
+
}
|