-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
/
MarkdownElement.tsx
857 lines (846 loc) · 31.8 KB
/
MarkdownElement.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
import * as React from 'react';
import clsx from 'clsx';
import { alpha, darken, styled } from '@mui/material/styles';
import useForkRef from '@mui/utils/useForkRef';
import { brandingDarkTheme as darkTheme, brandingLightTheme as lightTheme } from '../branding';
const Root = styled('div')(
({ theme }) => ({
...lightTheme.typography.body1,
lineHeight: 1.625, // Rounds up to 26px-increased compared to the 1.5 default to make the docs easier to read.
color: `var(--muidocs-palette-text-primary, ${lightTheme.palette.text.primary})`,
'& :focus-visible': {
outline: `3px solid ${alpha(lightTheme.palette.primary[500], 0.5)}`,
outlineOffset: 2,
},
'& strong': {
color: `var(--muidocs-palette-text-primary, ${lightTheme.palette.text.primary})`,
},
wordBreak: 'break-word',
'& pre': {
lineHeight: 1.5, // Developers like when the code is dense.
margin: theme.spacing(2, 'auto'),
padding: theme.spacing(2),
backgroundColor: 'hsl(210, 25%, 9%)', // a special, one-off, color tailored for the code blocks using MUI's branding theme blue palette as the starting point. It has a less saturaded color but still maintaining a bit of the blue tint.
color: 'hsl(60, 30%, 96%)',
colorScheme: 'dark',
borderRadius: `var(--muidocs-shape-borderRadius, ${
theme.shape?.borderRadius ?? lightTheme.shape.borderRadius
}px)`,
border: '1px solid',
borderColor: `var(--muidocs-palette-primaryDark-700, ${lightTheme.palette.primaryDark[700]})`,
overflow: 'auto',
WebkitOverflowScrolling: 'touch',
fontSize: lightTheme.typography.pxToRem(13),
maxWidth: 'calc(100vw - 32px)',
maxHeight: '400px',
[lightTheme.breakpoints.up('md')]: {
maxWidth: 'calc(100vw - 32px - 16px)',
},
},
'& code': {
...lightTheme.typography.body2,
fontFamily: lightTheme.typography.fontFamilyCode,
fontWeight: 400,
WebkitFontSmoothing: 'subpixel-antialiased',
},
'& pre > code': {
// Reset for Safari
// https://github.com/necolas/normalize.css/blob/master/normalize.css#L102
fontSize: 'inherit',
},
// inline code block
'& :not(pre) > code': {
padding: '2px 4px',
color: `var(--muidocs-palette-text-primary, ${lightTheme.palette.text.primary})`,
backgroundColor: `var(--muidocs-palette-grey-50, ${lightTheme.palette.grey[50]})`,
border: '1px solid',
borderColor: `var(--muidocs-palette-grey-200, ${lightTheme.palette.grey[200]})`,
borderRadius: 6,
fontSize: lightTheme.typography.pxToRem(13),
direction: 'ltr /*! @noflip */',
boxDecorationBreak: 'clone',
},
'& h1': {
...lightTheme.typography.h3,
fontSize: lightTheme.typography.pxToRem(36),
fontFamily: `"General Sans", ${lightTheme.typography.fontFamilySystem}`,
margin: '10px 0',
color: `var(--muidocs-palette-primaryDark-900, ${lightTheme.palette.primaryDark[900]})`,
fontWeight: 600,
letterSpacing: -0.2,
},
'& .description': {
...lightTheme.typography.subtitle1,
fontWeight: 400,
margin: '0 0 24px',
},
'& .component-tabs': {
margin: '0 0 40px',
},
'& h2': {
...lightTheme.typography.h5,
fontFamily: `"General Sans", ${lightTheme.typography.fontFamilySystem}`,
fontSize: theme.typography.pxToRem(26),
fontWeight: lightTheme.typography.fontWeightSemiBold,
color: `var(--muidocs-palette-grey-900, ${lightTheme.palette.grey[900]})`,
margin: '40px 0 4px',
},
'& h3': {
...lightTheme.typography.h6,
fontFamily: `"General Sans", ${lightTheme.typography.fontFamilySystem}`,
fontSize: theme.typography.pxToRem(20),
fontWeight: lightTheme.typography.fontWeightSemiBold,
color: `var(--muidocs-palette-grey-900, ${lightTheme.palette.grey[900]})`,
margin: '24px 0 4px',
},
'& h4': {
...lightTheme.typography.subtitle1,
fontFamily: `"General Sans", ${lightTheme.typography.fontFamilySystem}`,
fontWeight: lightTheme.typography.fontWeightSemiBold,
color: `var(--muidocs-palette-grey-900, ${lightTheme.palette.grey[900]})`,
margin: '20px 0 6px',
},
'& h5': {
...lightTheme.typography.subtitle2,
fontFamily: `"General Sans", ${lightTheme.typography.fontFamilySystem}`,
fontWeight: lightTheme.typography.fontWeightSemiBold,
color: `var(--muidocs-palette-grey-900, ${lightTheme.palette.grey[900]})`,
margin: '20px 0 8px',
},
'& p': {
marginTop: 0,
marginBottom: 16,
color: `var(--muidocs-palette-grey-900, ${lightTheme.palette.grey[900]})`,
},
'& ul, & ol': {
paddingLeft: 30,
marginTop: 0,
marginBottom: 16,
'& ul, & ol': {
marginBottom: 6,
},
},
'& a[target="_blank"]::after': {
content: '""',
maskImage: `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' focusable='false' aria-hidden='true' viewBox='0 0 24 24' fill='currentColor'%3E%3Cpath d='M6 6v2h8.59L5 17.59 6.41 19 16 9.41V18h2V6z'%3E%3C/path%3E%3C/svg%3E")`,
display: 'inline-flex',
width: '1em',
height: '1em',
color: 'inherit',
backgroundColor: 'currentColor',
transform: 'translate(0, 2px)',
transition: 'transform 0.3s cubic-bezier(0.1, 0.8, 0.3, 1)', // bounce effect
opacity: 0.8,
},
'& a[target="_blank"]:hover::after': {
opacity: 1,
transform: 'translate(1px, 0)',
},
'& a.remove-link-arrow::after': {
// Allows to remove link arrows for images
display: 'none',
},
'& .Ad-root a::after': {
// Remove link arrow for ads
display: 'none',
},
'& a': {
// Style taken from the Link component
color: `var(--muidocs-palette-primary-600, ${lightTheme.palette.primary[600]})`,
fontWeight: theme.typography.fontWeightMedium,
textDecoration: 'underline',
textDecorationColor: alpha(lightTheme.palette.primary.main, 0.4),
'&:hover': {
textDecorationColor: 'inherit',
},
},
'& a code': {
color: darken(lightTheme.palette.primary.main, 0.2),
},
'& h1, & h2, & h3, & h4': {
display: 'flex',
alignItems: 'center',
gap: 6,
'& code': {
fontSize: 'inherit',
lineHeight: 'inherit',
// Remove scroll on small screens.
wordBreak: 'break-all',
},
'& .title-link-to-anchor': {
color: 'inherit',
textDecoration: 'none',
boxShadow: 'none',
fontWeight: 'inherit',
position: 'relative',
userSelect: 'text',
},
'& .anchor-icon': {
// To prevent the link to get the focus.
display: 'inline-flex',
alignItems: 'center',
visibility: 'hidden',
},
'& .anchor-icon, & .comment-link': {
padding: 0,
cursor: 'pointer',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
textAlign: 'center',
marginLeft: 8,
height: 26,
width: 26,
color: `var(--muidocs-palette-grey-600, ${lightTheme.palette.grey[600]})`,
backgroundColor: 'transparent',
border: '1px solid transparent',
borderRadius: 8,
transition: theme.transitions.create(
['visibility', 'background-color', 'color', 'border-color'],
{
duration: theme.transitions.duration.shortest,
},
),
'&:hover': {
backgroundColor: alpha(lightTheme.palette.primary[100], 0.4),
borderColor: `var(--muidocs-palette-primary-100, ${lightTheme.palette.primary[100]})`,
color: `var(--muidocs-palette-primary-main, ${lightTheme.palette.primary.main})`,
},
'& svg': {
height: 14,
width: 14,
fill: 'currentColor',
pointerEvents: 'none',
verticalAlign: 'middle',
},
},
'&:hover .anchor-icon': {
visibility: 'visible',
},
'& .comment-link': {
display: 'none', // So we can have the comment button opt-in.
marginLeft: 'auto',
transition: theme.transitions.create(['background-color', 'color', 'border-color'], {
duration: theme.transitions.duration.shortest,
}),
'& svg': {
fill: 'currentColor',
marginRight: 1.5,
},
},
},
'& h1 code, & h2 code, & h3 code': {
color: `var(--muidocs-palette-grey-900, ${lightTheme.palette.grey[900]})`,
},
'& h1 code': {
fontWeight: lightTheme.typography.fontWeightSemiBold,
},
'& h2 code': {
fontSize: lightTheme.typography.pxToRem(24),
fontWeight: lightTheme.typography.fontWeightSemiBold,
},
'& h3 code': {
fontSize: lightTheme.typography.pxToRem(18),
},
'& table': {
// Trade display table for scroll overflow
display: 'block',
wordBreak: 'normal',
overflowX: 'auto',
WebkitOverflowScrolling: 'touch',
borderCollapse: 'collapse',
marginBottom: '20px',
borderSpacing: 0,
'& .prop-name, & .prop-type, & .prop-default, & .slot-name, & .slot-defaultClass, & .slot-default':
{
fontWeight: 400,
fontFamily: lightTheme.typography.fontFamilyCode,
WebkitFontSmoothing: 'subpixel-antialiased',
fontSize: lightTheme.typography.pxToRem(13),
},
'& .required': {
color: '#006500',
},
'& .optional': {
color: '#45529f',
},
'& .prop-type, & .slot-defaultClass': {
color: '#932981',
},
'& .prop-default, & .slot-default': {
borderBottom: `1px dotted var(--muidocs-palette-divider, ${lightTheme.palette.divider})`,
},
},
'& td': {
...theme.typography.body2,
borderBottom: `1px solid var(--muidocs-palette-divider, ${lightTheme.palette.divider})`,
paddingRight: 20,
paddingTop: 16,
paddingBottom: 16,
color: `var(--muidocs-palette-text-secondary, ${lightTheme.palette.text.secondary})`,
},
'& td code': {
lineHeight: 1.6,
},
'& th': {
fontSize: theme.typography.pxToRem(14),
lineHeight: theme.typography.pxToRem(24),
fontWeight: 500,
color: `var(--muidocs-palette-text-primary, ${lightTheme.palette.text.primary})`,
whiteSpace: 'pre',
borderBottom: `1px solid var(--muidocs-palette-divider, ${lightTheme.palette.divider})`,
paddingRight: 20,
paddingTop: 12,
paddingBottom: 12,
},
'& blockquote': {
position: 'relative',
padding: '0 16px',
margin: 0,
borderLeft: '1.5px solid',
borderColor: `var(--muidocs-palette-grey-200, ${lightTheme.palette.grey[200]})`,
'& p': {
fontSize: theme.typography.pxToRem(12.5),
fontFamily: lightTheme.typography.fontFamilyCode,
fontWeight: lightTheme.typography.fontWeightMedium,
lineHeight: theme.typography.pxToRem(24),
textIndent: 20,
},
'&::before': {
position: 'absolute',
// eslint-disable-next-line material-ui/straight-quotes
content: '"“"',
color: `var(--muidocs-palette-grey-300, ${lightTheme.palette.grey[300]})`,
fontSize: '2.5rem',
top: 8,
marginLeft: -6,
lineHeight: 0.5,
},
},
'& .MuiCallout-root': {
display: 'flex',
gap: '8px',
padding: '12px',
margin: '16px 0',
border: '1px solid',
color: `var(--muidocs-palette-text-secondary, ${lightTheme.palette.text.secondary})`,
borderColor: `var(--muidocs-palette-grey-100, ${lightTheme.palette.grey[100]})`,
borderRadius: `var(--muidocs-shape-borderRadius, ${
theme.shape?.borderRadius ?? lightTheme.shape.borderRadius
}px)`,
'& .MuiCallout-content': {
minWidth: 0, // Allows content to shrink. Useful when callout contains code block
flexGrow: 1,
},
'& code': {
height: 'fit-content',
backgroundColor: `var(--muidocs-palette-grey-100, ${lightTheme.palette.grey[100]})`,
borderColor: `var(--muidocs-palette-grey-300, ${lightTheme.palette.grey[300]})`,
},
'& p': {
marginBottom: '8px',
'& > p:last-child, & > ul:last-child': {
// Avoid margin on last child
marginBottom: 0,
},
'& > ul': {
// Because of the gap left by the icon, we visually need less padding
paddingLeft: 22,
},
},
'& .MuiCode-root': {
'& pre': {
margin: '4px 0 0 0',
borderRadius: '12px 12px 6px 12px',
borderColor: alpha(lightTheme.palette.primaryDark[600], 0.6),
'& code': {
backgroundColor: 'transparent',
},
},
},
'& .MuiCallout-icon-container': {
width: 26, // to match text's line-height
height: 26,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
flexShrink: 0,
'& svg': {
width: 18,
height: 18,
},
},
'& ul, & p': {
'&:last-child': {
margin: 0,
},
},
'& ul, li, p': {
color: 'inherit',
},
'&.MuiCallout-error': {
color: `var(--muidocs-palette-error-900, ${lightTheme.palette.error[900]})`,
backgroundColor: `var(--muidocs-palette-error-50, ${lightTheme.palette.error[50]})`,
borderColor: `var(--muidocs-palette-error-100, ${lightTheme.palette.error[100]})`,
'& strong': {
color: `var(--muidocs-palette-error-800, ${lightTheme.palette.error[800]})`,
},
'& svg': {
fill: `var(--muidocs-palette-error-500, ${lightTheme.palette.error[600]})`,
},
'& a': {
color: `var(--muidocs-palette-error-800, ${lightTheme.palette.error[800]})`,
textDecorationColor: alpha(lightTheme.palette.error.main, 0.4),
'&:hover': {
textDecorationColor: 'inherit',
},
},
},
'&.MuiCallout-info': {
color: `var(--muidocs-palette-grey-900, ${lightTheme.palette.grey[900]})`,
backgroundColor: `var(--muidocs-palette-grey-50, ${lightTheme.palette.grey[50]})`,
borderColor: `var(--muidocs-palette-grey-100, ${lightTheme.palette.grey[100]})`,
'& strong': {
color: `var(--muidocs-palette-primary-800, ${lightTheme.palette.primary[800]})`,
},
'& svg': {
fill: `var(--muidocs-palette-grey-600, ${lightTheme.palette.grey[600]})`,
},
},
'&.MuiCallout-success': {
color: `var(--muidocs-palette-success-900, ${lightTheme.palette.success[900]})`,
backgroundColor: `var(--muidocs-palette-success-50, ${lightTheme.palette.success[50]})`,
borderColor: `var(--muidocs-palette-success-100, ${lightTheme.palette.success[100]})`,
'& strong': {
color: `var(--muidocs-palette-success-900, ${lightTheme.palette.success[900]})`,
},
'& svg': {
fill: `var(--muidocs-palette-success-600, ${lightTheme.palette.success[600]})`,
},
'& a': {
color: `var(--muidocs-palette-success-900, ${lightTheme.palette.success[900]})`,
textDecorationColor: alpha(lightTheme.palette.success.main, 0.4),
'&:hover': {
textDecorationColor: 'inherit',
},
},
},
'&.MuiCallout-warning': {
color: `var(--muidocs-palette-grey-900, ${lightTheme.palette.grey[900]})`,
backgroundColor: alpha(lightTheme.palette.warning[50], 0.5),
borderColor: alpha(lightTheme.palette.warning[700], 0.15),
'& strong': {
color: `var(--muidocs-palette-warning-800, ${lightTheme.palette.warning[800]})`,
},
'& svg': {
fill: `var(--muidocs-palette-warning-600, ${lightTheme.palette.warning[600]})`,
},
'& a': {
color: `var(--muidocs-palette-warning-800, ${lightTheme.palette.warning[800]})`,
textDecorationColor: alpha(lightTheme.palette.warning.main, 0.4),
'&:hover': {
textDecorationColor: 'inherit',
},
},
},
},
'& img, & video': {
// Use !important so that inline style on <img> or <video> can't win.
// This avoid horizontal overflows on mobile.
maxWidth: '100% !important',
// Avoid the image to be fixed height, so it can respect the aspect ratio.
height: 'auto',
},
'& img': {
// Avoid layout jump
display: 'inline-block',
// Avoid very sharp edges
borderRadius: 2,
},
'& hr': {
height: 1,
margin: theme.spacing(5, 0),
border: 0,
flexShrink: 0,
backgroundColor: `var(--muidocs-palette-divider, ${lightTheme.palette.divider})`,
},
'& kbd.key': {
padding: 6,
display: 'inline-block',
whiteSpace: 'nowrap',
margin: '0 1px',
fontFamily: lightTheme.typography.fontFamilyCode,
fontSize: lightTheme.typography.pxToRem(11),
color: `var(--muidocs-palette-text-primary, ${lightTheme.palette.text.primary})`,
lineHeight: '10px',
verticalAlign: 'middle',
borderRadius: 6,
border: `1px solid var(--muidocs-palette-grey-300, ${lightTheme.palette.grey[300]})`,
backgroundColor: `var(--muidocs-palette-grey-50, ${lightTheme.palette.grey[50]})`,
boxShadow: `inset 0 -2px 0 var(--muidocs-palette-grey-200, ${lightTheme.palette.grey[200]})`,
},
'& details': {
width: '100%',
padding: theme.spacing(1),
marginBottom: theme.spacing(1.5),
border: '1px solid',
borderColor: `var(--muidocs-palette-divider, ${lightTheme.palette.divider})`,
borderRadius: `var(--muidocs-shape-borderRadius, ${
theme.shape?.borderRadius ?? lightTheme.shape.borderRadius
}px)`,
'& pre': {
marginTop: theme.spacing(1),
},
},
'& summary': {
cursor: 'pointer',
padding: theme.spacing(1),
borderRadius: 6,
listStyleType: 'none',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
transition: theme.transitions.create(['background'], {
duration: theme.transitions.duration.shortest,
}),
':after': {
content: '""',
maskImage: `url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M4 6L8 10L12 6' stroke='black' stroke-width='1.66667' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A")`,
display: 'inline-flex',
width: '1em',
height: '1em',
color: 'inherit',
backgroundColor: 'currentColor',
},
'&:hover': {
backgroundColor: `var(--muidocs-palette-grey-100, ${lightTheme.palette.grey[50]})`,
},
},
'& details[open] > summary::after': {
content: '""',
maskImage: `url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M12 10L8 6L4 10' stroke='black' stroke-width='1.66667' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E%0A")`,
},
'& .MuiCode-root': {
direction: 'ltr /*! @noflip */',
position: 'relative',
// Font size reset to fix a bug with Safari 16.0 when letterSpacing is set
fontSize: 10,
'&:has(.MuiCode-title)': {
margin: theme.spacing(2, 'auto'),
border: `1px solid var(--muidocs-palette-primaryDark-700, ${lightTheme.palette.primaryDark[700]})`,
borderRadius: theme.shape.borderRadius,
overflow: 'clip',
'& .MuiCode-copy': {
top: '56px',
},
},
},
'& .MuiCode-copy-container': {
// This container is only used in demo and highlight code
position: 'sticky',
zIndex: 1,
top: 0,
},
'& .MuiCode-copy': {
cursor: 'pointer',
position: 'absolute',
top: 12,
right: 12,
display: 'inline-flex',
flexDirection: 'row-reverse',
alignItems: 'center',
padding: theme.spacing(0.5),
paddingBottom: '5px', // optical alignment
fontFamily: lightTheme.typography.fontFamily,
fontWeight: lightTheme.typography.fontWeightMedium,
fontSize: lightTheme.typography.pxToRem(12),
borderRadius: 6,
border: '1px solid',
borderColor: alpha(lightTheme.palette.primaryDark[600], 0.5),
backgroundColor: alpha(lightTheme.palette.primaryDark[800], 0.5),
color: `var(--muidocs-palette-grey-300, ${lightTheme.palette.grey[300]})`,
transition: theme.transitions.create(['background', 'borderColor', 'display'], {
duration: theme.transitions.duration.shortest,
}),
'& .MuiCode-copied-label': {
display: 'none',
},
'&:hover, &:focus': {
borderColor: `var(--muidocs-palette-primaryDark-400, ${lightTheme.palette.primaryDark[400]})`,
backgroundColor: `var(--muidocs-palette-primaryDark-700, ${lightTheme.palette.primaryDark[700]})`,
color: '#FFF',
'& .MuiCode-copyKeypress': {
display: 'block',
// Approximate no hover capabilities with no keyboard
// https://github.com/w3c/csswg-drafts/issues/3871
'@media (any-hover: none)': {
display: 'none',
},
},
},
'& .MuiCode-copyKeypress': {
display: 'none',
position: 'absolute',
right: 34,
},
'&[data-copied]': {
borderColor: `var(--muidocs-palette-primaryDark-400, ${lightTheme.palette.primaryDark[400]})`,
backgroundColor: `var(--muidocs-palette-primaryDark-700, ${lightTheme.palette.primaryDark[700]})`,
color: '#fff',
'& .MuiCode-copyKeypress': {
opacity: 0,
},
'& .MuiCode-copy-label': {
display: 'none',
},
'& .MuiCode-copied-label': {
display: 'block',
},
},
},
'& .MuiCode-copyKeypress': {
pointerEvents: 'none',
userSelect: 'none',
marginRight: theme.spacing(1.2),
marginBottom: theme.spacing(0.2),
whiteSpace: 'nowrap',
opacity: 0.6,
},
'& li': {
// tight lists https://spec.commonmark.org/0.30/#tight
marginBottom: 4,
'& pre': {
marginTop: theme.spacing(1),
},
// loose lists https://spec.commonmark.org/0.30/#loose
'& > p': {
marginBottom: theme.spacing(1),
},
},
'& .feature-list': {
padding: 0,
listStyle: 'none',
'& li': {
marginBottom: 6,
display: 'flex',
alignItems: 'center',
gap: 12,
'::before': {
content: `url('/static/branding/pricing/yes-light.svg')`,
width: '18px',
height: '18px',
},
},
},
'& .MuiCode-title': {
padding: theme.spacing(1.5),
display: 'flex',
alignItems: 'center',
gap: theme.spacing(1.5),
borderBottom: `1px solid var(--muidocs-palette-primaryDark-700, ${lightTheme.palette.primaryDark[700]})`,
backgroundColor: `var(--muidocs-palette-primaryDark-900, ${lightTheme.palette.primaryDark[900]})`,
fontFamily: theme.typography.fontFamilyCode,
fontSize: theme.typography.pxToRem(12),
fontWeight: theme.typography.fontWeightBold,
color: `var(--muidocs-palette-grey-200, ${lightTheme.palette.grey[200]})`,
'::before': {
content: `url("data:image/svg+xml,%3Csvg width='16' height='16' viewBox='0 0 16 16' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M13.3333 3.99996H8L7.06 3.05996C6.80667 2.80663 6.46667 2.66663 6.11334 2.66663H2.66667C1.93334 2.66663 1.34 3.26663 1.34 3.99996L1.33334 12C1.33334 12.7333 1.93334 13.3333 2.66667 13.3333H13.3333C14.0667 13.3333 14.6667 12.7333 14.6667 12V5.33329C14.6667 4.59996 14.0667 3.99996 13.3333 3.99996ZM12.6667 12H3.33334C2.96667 12 2.66667 11.7 2.66667 11.3333V5.99996C2.66667 5.63329 2.96667 5.33329 3.33334 5.33329H12.6667C13.0333 5.33329 13.3333 5.63329 13.3333 5.99996V11.3333C13.3333 11.7 13.0333 12 12.6667 12Z' fill='%2399CCF3'/%3E%3C/svg%3E%0A");`,
width: '16px',
height: '16px',
},
'& + pre': {
margin: 0,
border: 'none',
borderRadius: 0,
},
},
}),
({ theme }) => ({
[`:where(${theme.vars ? '[data-mui-color-scheme="dark"]' : '.mode-dark'}) &`]: {
color: 'rgb(255, 255, 255)',
'& :not(pre) > code': {
// inline code block
color: `var(--muidocs-palette-text-primary, ${darkTheme.palette.text.primary})`,
borderColor: alpha(darkTheme.palette.primaryDark[600], 0.6),
backgroundColor: `var(--muidocs-palette-grey-900, ${darkTheme.palette.grey[900]})`,
},
'& strong': {
color: `var(--muidocs-palette-grey-200, ${darkTheme.palette.grey[200]})`,
},
'& hr': {
backgroundColor: `var(--muidocs-palette-divider, ${darkTheme.palette.divider})`,
},
'& a': {
color: `var(--muidocs-palette-primary-300, ${darkTheme.palette.primary[300]})`,
},
'& a code': {
color: `var(--muidocs-palette-primary-light, ${darkTheme.palette.primary.light})`,
},
'& h1, & h2, & h3, & h4, & h5': {
color: `var(--muidocs-palette-grey-50, ${darkTheme.palette.grey[50]})`,
'& .anchor-icon, & .comment-link': {
color: `var(--muidocs-palette-primary-300, ${darkTheme.palette.primaryDark[400]})`,
'&:hover': {
color: `var(--muidocs-palette-primary-100, ${darkTheme.palette.primary[100]})`,
borderColor: `var(--muidocs-palette-primary-900, ${darkTheme.palette.primary[900]})`,
backgroundColor: alpha(darkTheme.palette.primary[900], 0.6),
},
},
},
'& p, & ul, & ol': {
color: `var(--muidocs-palette-grey-400, ${darkTheme.palette.grey[400]})`,
},
'& h1 code, & h2 code, & h3 code': {
color: `var(--muidocs-palette-grey-100, ${darkTheme.palette.grey[100]})`,
},
'& table': {
'& .required': {
color: '#a5ffa5',
},
'& .optional': {
color: '#a5b3ff',
},
'& .prop-type, & .slot-defaultClass': {
color: '#ffb6ec',
},
'& .prop-default, & .slot-default': {
borderColor: `var(--muidocs-palette-divider, ${darkTheme.palette.divider})`,
},
},
'& td': {
color: `var(--muidocs-palette-text-secondary, ${darkTheme.palette.text.secondary})`,
borderColor: `var(--muidocs-palette-divider, ${darkTheme.palette.divider})`,
},
'& th': {
color: `var(--muidocs-palette-text-primary, ${darkTheme.palette.text.primary})`,
borderColor: `var(--muidocs-palette-divider, ${darkTheme.palette.divider})`,
},
'& blockquote': {
borderColor: `var(--muidocs-palette-primaryDark-700, ${darkTheme.palette.primaryDark[700]})`,
'&::before': {
color: `var(--muidocs-palette-primaryDark-500, ${darkTheme.palette.primaryDark[500]})`,
},
},
'& .MuiCallout-root': {
borderColor: `var(--muidocs-palette-primaryDark-700, ${darkTheme.palette.primaryDark[700]})`,
'& code': {
backgroundColor: `var(--muidocs-palette-primaryDark-600, ${darkTheme.palette.primaryDark[600]})`,
borderColor: `var(--muidocs-palette-primaryDark-500, ${darkTheme.palette.primaryDark[500]})`,
},
'&.MuiCallout-error': {
color: `var(--muidocs-palette-error-50, ${darkTheme.palette.error[50]})`,
backgroundColor: alpha(darkTheme.palette.error[700], 0.15),
borderColor: alpha(darkTheme.palette.error[400], 0.1),
'& strong': {
color: `var(--muidocs-palette-error-300, ${darkTheme.palette.error[300]})`,
},
'& svg': {
fill: `var(--muidocs-palette-error-500, ${darkTheme.palette.error[500]})`,
},
'& a': {
color: `var(--muidocs-palette-error-200, ${darkTheme.palette.error[200]})`,
},
},
'&.MuiCallout-info': {
color: `var(--muidocs-palette-grey-50, ${darkTheme.palette.grey[50]})`,
backgroundColor: alpha(darkTheme.palette.grey[700], 0.15),
borderColor: alpha(darkTheme.palette.grey[800], 0.5),
'& strong': {
color: `var(--muidocs-palette-primary-200, ${darkTheme.palette.primary[200]})`,
},
'& svg': {
fill: `var(--muidocs-palette-grey-400, ${darkTheme.palette.grey[400]})`,
},
},
'&.MuiCallout-success': {
color: `var(--muidocs-palette-success-50, ${darkTheme.palette.success[50]})`,
backgroundColor: alpha(darkTheme.palette.success[700], 0.12),
borderColor: alpha(lightTheme.palette.success[400], 0.1),
'& strong': {
color: `var(--muidocs-palette-success-200, ${darkTheme.palette.success[200]})`,
},
'& svg': {
fill: `var(--muidocs-palette-success-500, ${darkTheme.palette.success[500]})`,
},
'& a': {
color: `var(--muidocs-palette-success-100, ${darkTheme.palette.success[100]})`,
},
},
'&.MuiCallout-warning': {
color: `var(--muidocs-palette-warning-50, ${darkTheme.palette.warning[50]})`,
backgroundColor: alpha(darkTheme.palette.warning[700], 0.12),
borderColor: alpha(darkTheme.palette.warning[400], 0.1),
'& strong': {
color: `var(--muidocs-palette-warning-200, ${darkTheme.palette.warning[200]})`,
},
'& svg': {
fill: `var(--muidocs-palette-warning-400, ${darkTheme.palette.warning[400]})`,
},
'& a': {
color: `var(--muidocs-palette-warning-100, ${darkTheme.palette.warning[100]})`,
},
},
},
'& kbd.key': {
color: `var(--muidocs-palette-text-primary, ${darkTheme.palette.text.primary})`,
backgroundColor: `var(--muidocs-palette-primaryDark-800, ${darkTheme.palette.primaryDark[800]})`,
border: `1px solid var(--muidocs-palette-primaryDark-600, ${darkTheme.palette.primaryDark[600]})`,
boxShadow: `inset 0 -2px 0 var(--muidocs-palette-primaryDark-700, ${darkTheme.palette.primaryDark[700]})`,
},
'& details': {
borderColor: `var(--muidocs-palette-divider, ${darkTheme.palette.divider})`,
},
'& summary': {
'&:hover': {
backgroundColor: `var(--muidocs-palette-primaryDark-800, ${darkTheme.palette.primaryDark[800]})`,
},
},
'& .feature-list': {
'& li': {
'::before': {
content: `url('/static/branding/pricing/yes-dark.svg')`,
},
},
},
},
}),
);
function handleHeaderClick(event: Event) {
const selection = document.getSelection();
if (selection === null) {
return;
}
if (selection.type === 'Range') {
// Disable the <a> behavior to be able to select text.
event.preventDefault();
}
}
export interface MarkdownElementProps {
className?: string;
renderedMarkdown?: string;
children?: React.ReactNode;
}
export const MarkdownElement = React.forwardRef<HTMLDivElement, MarkdownElementProps>(
function MarkdownElement(props, ref) {
const { className, renderedMarkdown, ...other } = props;
const rootRef = React.useRef<HTMLElement>(null);
const handleRef = useForkRef(rootRef, ref);
React.useEffect(() => {
const elements = rootRef.current!.getElementsByClassName('title-link-to-anchor');
for (let i = 0; i < elements.length; i += 1) {
// More reliable than `-webkit-user-drag` (https://caniuse.com/webkit-user-drag)
elements[i].setAttribute('draggable', 'false');
elements[i].addEventListener('click', handleHeaderClick);
}
}, []);
const more: React.ComponentProps<typeof Root> = {};
if (typeof renderedMarkdown === 'string') {
// workaround for https://github.com/facebook/react/issues/17170
// otherwise we could just set `dangerouslySetInnerHTML={undefined}`
more.dangerouslySetInnerHTML = { __html: renderedMarkdown };
}
return (
<Root className={clsx('markdown-body', className)} {...more} {...other} ref={handleRef} />
);
},
);