@ceed/ads 1.35.1 → 1.37.0
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 +85 -95
- package/dist/components/Accordions/Accordions.d.ts +1 -0
- package/dist/components/Alert/Alert.d.ts +5 -5
- package/dist/components/Autocomplete/Autocomplete.d.ts +2 -2
- package/dist/components/Avatar/Avatar.d.ts +7 -17
- package/dist/components/Box/Box.d.ts +1 -0
- package/dist/components/Breadcrumbs/Breadcrumbs.d.ts +6 -5
- package/dist/components/Button/Button.d.ts +3 -2
- package/dist/components/Calendar/Calendar.d.ts +1 -0
- package/dist/components/Card/Card.d.ts +1 -0
- package/dist/components/Checkbox/Checkbox.d.ts +1 -0
- package/dist/components/Chip/Chip.d.ts +1 -0
- package/dist/components/Container/Container.d.ts +6 -1
- package/dist/components/DialogActions/DialogActions.d.ts +1 -0
- package/dist/components/DialogContent/DialogContent.d.ts +1 -0
- package/dist/components/DialogFrame/DialogFrame.d.ts +1 -1
- package/dist/components/DialogTitle/DialogTitle.d.ts +1 -0
- package/dist/components/Divider/Divider.d.ts +1 -0
- package/dist/components/Dropdown/Dropdown.d.ts +28 -1
- package/dist/components/FilterMenu/components/MonthRange.d.ts +11 -0
- package/dist/components/FilterMenu/types.d.ts +5 -1
- package/dist/components/FormControl/FormControl.d.ts +1 -0
- package/dist/components/FormHelperText/FormHelperText.d.ts +1 -0
- package/dist/components/FormLabel/FormLabel.d.ts +1 -0
- package/dist/components/Grid/Grid.d.ts +1 -0
- package/dist/components/IconButton/IconButton.d.ts +3 -2
- package/dist/components/IconMenuButton/IconMenuButton.d.ts +7 -6
- package/dist/components/InfoSign/InfoSign.d.ts +3 -2
- package/dist/components/Input/Input.d.ts +8 -22
- package/dist/components/InsetDrawer/InsetDrawer.d.ts +1 -0
- package/dist/components/Markdown/Markdown.d.ts +9 -24
- package/dist/components/Menu/Menu.d.ts +2 -1
- package/dist/components/MenuButton/MenuButton.d.ts +10 -8
- package/dist/components/Modal/Modal.d.ts +4 -2
- package/dist/components/NavigationGroup/NavigationGroup.d.ts +3 -2
- package/dist/components/NavigationItem/NavigationItem.d.ts +3 -2
- package/dist/components/Navigator/Navigator.d.ts +5 -4
- package/dist/components/Pagination/Pagination.d.ts +1 -1
- package/dist/components/ProfileMenu/ProfileMenu.d.ts +2 -2
- package/dist/components/Radio/Radio.d.ts +1 -0
- package/dist/components/RadioList/RadioList.d.ts +3 -2
- package/dist/components/Select/Select.d.ts +20 -10
- package/dist/components/Sheet/Sheet.d.ts +1 -0
- package/dist/components/Stack/Stack.d.ts +1 -0
- package/dist/components/Stepper/Stepper.d.ts +2 -1
- package/dist/components/Switch/Switch.d.ts +1 -0
- package/dist/components/Table/Table.d.ts +7 -5
- package/dist/components/Tabs/Tabs.d.ts +1 -0
- package/dist/components/Textarea/Textarea.d.ts +8 -20
- package/dist/components/ThemeProvider/ThemeProvider.d.ts +4 -2
- package/dist/components/Tooltip/Tooltip.d.ts +1 -0
- package/dist/components/Typography/Typography.d.ts +1 -0
- package/dist/components/Uploader/Uploader.d.ts +18 -17
- package/dist/components/data-display/Avatar.md +60 -72
- package/dist/components/data-display/Badge.md +197 -181
- package/dist/components/data-display/Chip.md +164 -142
- package/dist/components/data-display/DataTable.md +843 -338
- package/dist/components/data-display/InfoSign.md +1 -3
- package/dist/components/data-display/Markdown.md +93 -125
- package/dist/components/data-display/Table.md +1453 -1007
- package/dist/components/data-display/Typography.md +101 -104
- package/dist/components/feedback/Alert.md +80 -86
- package/dist/components/feedback/CircularProgress.md +32 -36
- package/dist/components/feedback/Dialog.md +25 -17
- package/dist/components/feedback/Modal.md +296 -265
- package/dist/components/feedback/Skeleton.md +125 -89
- package/dist/components/index.d.ts +60 -1
- package/dist/components/inputs/Autocomplete.md +191 -95
- package/dist/components/inputs/Button.md +83 -83
- package/dist/components/inputs/ButtonGroup.md +195 -185
- package/dist/components/inputs/Calendar.md +25 -28
- package/dist/components/inputs/Checkbox.md +11 -29
- package/dist/components/inputs/CurrencyInput.md +4 -4
- package/dist/components/inputs/DatePicker.md +229 -110
- package/dist/components/inputs/DateRangePicker.md +248 -137
- package/dist/components/inputs/FilterMenu.md +138 -8
- package/dist/components/inputs/FilterableCheckboxGroup.md +115 -55
- package/dist/components/inputs/FormControl.md +75 -69
- package/dist/components/inputs/IconButton.md +229 -205
- package/dist/components/inputs/Input.md +131 -98
- package/dist/components/inputs/MonthPicker.md +186 -84
- package/dist/components/inputs/MonthRangePicker.md +73 -49
- package/dist/components/inputs/PercentageInput.md +15 -31
- package/dist/components/inputs/RadioButton.md +320 -256
- package/dist/components/inputs/RadioList.md +66 -50
- package/dist/components/inputs/RadioTileGroup.md +287 -170
- package/dist/components/inputs/SearchBar.md +82 -60
- package/dist/components/inputs/Select.md +181 -115
- package/dist/components/inputs/Slider.md +153 -102
- package/dist/components/inputs/Switch.md +193 -138
- package/dist/components/inputs/Textarea.md +15 -20
- package/dist/components/inputs/Uploader/Uploader.md +68 -39
- package/dist/components/layout/Box.md +841 -662
- package/dist/components/layout/Container.md +3 -11
- package/dist/components/layout/Grid.md +480 -394
- package/dist/components/layout/Stack.md +739 -566
- package/dist/components/navigation/Breadcrumbs.md +182 -116
- package/dist/components/navigation/Dropdown.md +732 -391
- package/dist/components/navigation/IconMenuButton.md +14 -6
- package/dist/components/navigation/InsetDrawer.md +550 -378
- package/dist/components/navigation/Link.md +104 -94
- package/dist/components/navigation/Menu.md +623 -502
- package/dist/components/navigation/MenuButton.md +18 -10
- package/dist/components/navigation/NavigationGroup.md +19 -50
- package/dist/components/navigation/NavigationItem.md +6 -6
- package/dist/components/navigation/Navigator.md +26 -28
- package/dist/components/navigation/Pagination.md +86 -75
- package/dist/components/navigation/ProfileMenu.md +65 -43
- package/dist/components/navigation/Stepper.md +2 -12
- package/dist/components/navigation/Tabs.md +209 -183
- package/dist/components/surfaces/Accordions.md +89 -172
- package/dist/components/surfaces/Card.md +1094 -709
- package/dist/components/surfaces/Divider.md +562 -412
- package/dist/components/surfaces/Sheet.md +700 -518
- package/dist/guides/ThemeProvider.md +65 -40
- package/dist/index.browser.js +4 -4
- package/dist/index.browser.js.map +4 -4
- package/dist/index.cjs +1655 -1548
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1314 -1199
- package/framer/index.js +1 -1
- package/package.json +32 -35
|
@@ -26,9 +26,7 @@ function MyComponent() {
|
|
|
26
26
|
return (
|
|
27
27
|
<label>
|
|
28
28
|
Complex Setting
|
|
29
|
-
<InfoSign
|
|
30
|
-
message="This setting affects overall system performance. Consult an administrator before making changes."
|
|
31
|
-
/>
|
|
29
|
+
<InfoSign message="This setting affects overall system performance. Consult an administrator before making changes." />
|
|
32
30
|
</label>
|
|
33
31
|
);
|
|
34
32
|
}
|
|
@@ -33,13 +33,7 @@ Markdown is a component that renders markdown-formatted text as styled React com
|
|
|
33
33
|
import { Markdown } from '@ceed/ads';
|
|
34
34
|
|
|
35
35
|
function ArticleContent({ content }) {
|
|
36
|
-
return
|
|
37
|
-
<Markdown
|
|
38
|
-
content={content}
|
|
39
|
-
defaultLevel="body-md"
|
|
40
|
-
defaultLinkAction="_blank"
|
|
41
|
-
/>
|
|
42
|
-
);
|
|
36
|
+
return <Markdown content={content} defaultLevel="body-md" defaultLinkAction="_blank" />;
|
|
43
37
|
}
|
|
44
38
|
```
|
|
45
39
|
|
|
@@ -59,14 +53,14 @@ Control the base typography level for the content.
|
|
|
59
53
|
|
|
60
54
|
```tsx
|
|
61
55
|
<Stack spacing={2}>
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
</Stack>
|
|
56
|
+
<Markdown {...args} defaultLevel="title-lg" />
|
|
57
|
+
<Markdown {...args} defaultLevel="title-md" />
|
|
58
|
+
<Markdown {...args} defaultLevel="title-sm" />
|
|
59
|
+
<Markdown {...args} defaultLevel="body-lg" />
|
|
60
|
+
<Markdown {...args} defaultLevel="body-md" />
|
|
61
|
+
<Markdown {...args} defaultLevel="body-sm" />
|
|
62
|
+
<Markdown {...args} defaultLevel="body-xs" />
|
|
63
|
+
</Stack>
|
|
70
64
|
```
|
|
71
65
|
|
|
72
66
|
## Text Alignment
|
|
@@ -86,12 +80,12 @@ Apply different color themes to the markdown content.
|
|
|
86
80
|
|
|
87
81
|
```tsx
|
|
88
82
|
<div>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
</div>
|
|
83
|
+
<Markdown {...args} color="primary" />
|
|
84
|
+
<Markdown {...args} color="danger" />
|
|
85
|
+
<Markdown {...args} color="neutral" />
|
|
86
|
+
<Markdown {...args} color="success" />
|
|
87
|
+
<Markdown {...args} color="warning" />
|
|
88
|
+
</div>
|
|
95
89
|
```
|
|
96
90
|
|
|
97
91
|
## Text Color
|
|
@@ -100,10 +94,10 @@ Use specific text colors from the theme palette.
|
|
|
100
94
|
|
|
101
95
|
```tsx
|
|
102
96
|
<Stack>
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
</Stack>
|
|
97
|
+
<Markdown {...args} textColor="common.black" />
|
|
98
|
+
<Markdown {...args} textColor="danger.400" />
|
|
99
|
+
<Markdown {...args} textColor="primary.500" />
|
|
100
|
+
</Stack>
|
|
107
101
|
```
|
|
108
102
|
|
|
109
103
|
## Accent Color
|
|
@@ -112,9 +106,9 @@ Highlight text with custom accent color using `||text||` syntax.
|
|
|
112
106
|
|
|
113
107
|
```tsx
|
|
114
108
|
<Stack spacing={2}>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
</Stack>
|
|
109
|
+
<Markdown {...args} />
|
|
110
|
+
<Markdown {...args} fontWeight={600} />
|
|
111
|
+
</Stack>
|
|
118
112
|
```
|
|
119
113
|
|
|
120
114
|
## Bold Font Weight
|
|
@@ -123,18 +117,18 @@ Customize the weight of bold text.
|
|
|
123
117
|
|
|
124
118
|
```tsx
|
|
125
119
|
<Stack spacing={2}>
|
|
126
|
-
|
|
127
|
-
|
|
120
|
+
<Typography fontWeight="normal">Normal:</Typography>
|
|
121
|
+
<Markdown {...args} />
|
|
128
122
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
</Stack>
|
|
123
|
+
<Typography fontWeight="sm">SM:</Typography>
|
|
124
|
+
<Markdown {...args} boldFontWeight="sm" />
|
|
125
|
+
<Typography fontWeight="md">MD:</Typography>
|
|
126
|
+
<Markdown {...args} boldFontWeight="md" />
|
|
127
|
+
<Typography fontWeight="lg">LG:</Typography>
|
|
128
|
+
<Markdown {...args} boldFontWeight="lg" />
|
|
129
|
+
<Typography fontWeight="xl">XL:</Typography>
|
|
130
|
+
<Markdown {...args} boldFontWeight="xl" />
|
|
131
|
+
</Stack>
|
|
138
132
|
```
|
|
139
133
|
|
|
140
134
|
## Strikethrough
|
|
@@ -210,28 +204,41 @@ Full demonstration of all GFM features.
|
|
|
210
204
|
Override the built-in anchor renderer via `markdownOptions.components.a` to detect external links by origin comparison, open them in a new tab, and prepend an `OpenInNew` icon so users can tell external links apart at a glance. Internal links keep `defaultLinkAction` behavior and render without the icon.
|
|
211
205
|
|
|
212
206
|
```tsx
|
|
213
|
-
<Markdown
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
207
|
+
<Markdown
|
|
208
|
+
{...args}
|
|
209
|
+
markdownOptions={{
|
|
210
|
+
components: {
|
|
211
|
+
a: ({ href, children }) => {
|
|
212
|
+
const isExternal = (() => {
|
|
213
|
+
if (!href || typeof window === "undefined") return false;
|
|
214
|
+
try {
|
|
215
|
+
return new URL(href, window.location.href).origin !== window.location.origin;
|
|
216
|
+
} catch {
|
|
217
|
+
return false;
|
|
218
|
+
}
|
|
219
|
+
})();
|
|
220
|
+
return (
|
|
221
|
+
<Link
|
|
222
|
+
href={href}
|
|
223
|
+
target={isExternal ? "_blank" : "_self"}
|
|
224
|
+
rel={isExternal ? "noopener noreferrer" : undefined}
|
|
225
|
+
startDecorator={
|
|
226
|
+
isExternal ? (
|
|
227
|
+
<OpenInNew
|
|
228
|
+
sx={{
|
|
229
|
+
fontSize: "1em"
|
|
230
|
+
}}
|
|
231
|
+
/>
|
|
232
|
+
) : undefined
|
|
233
|
+
}
|
|
234
|
+
>
|
|
235
|
+
{children}
|
|
236
|
+
</Link>
|
|
237
|
+
);
|
|
225
238
|
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}} /> : undefined}>
|
|
230
|
-
{children}
|
|
231
|
-
</Link>;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}} />
|
|
239
|
+
}
|
|
240
|
+
}}
|
|
241
|
+
/>
|
|
235
242
|
```
|
|
236
243
|
|
|
237
244
|
```tsx
|
|
@@ -264,7 +271,7 @@ import { Markdown, Link } from '@ceed/ads';
|
|
|
264
271
|
},
|
|
265
272
|
},
|
|
266
273
|
}}
|
|
267
|
-
|
|
274
|
+
/>;
|
|
268
275
|
```
|
|
269
276
|
|
|
270
277
|
## When to Use
|
|
@@ -305,11 +312,7 @@ function ArticlePage({ article }) {
|
|
|
305
312
|
</Typography>
|
|
306
313
|
</Stack>
|
|
307
314
|
<Divider sx={{ mb: 3 }} />
|
|
308
|
-
<Markdown
|
|
309
|
-
content={article.body}
|
|
310
|
-
defaultLevel="body-md"
|
|
311
|
-
defaultLinkAction="_blank"
|
|
312
|
-
/>
|
|
315
|
+
<Markdown content={article.body} defaultLevel="body-md" defaultLinkAction="_blank" />
|
|
313
316
|
</Box>
|
|
314
317
|
);
|
|
315
318
|
}
|
|
@@ -331,10 +334,7 @@ function Comment({ comment }) {
|
|
|
331
334
|
</Typography>
|
|
332
335
|
</Box>
|
|
333
336
|
</Stack>
|
|
334
|
-
<Markdown
|
|
335
|
-
content={comment.body}
|
|
336
|
-
defaultLevel="body-sm"
|
|
337
|
-
/>
|
|
337
|
+
<Markdown content={comment.body} defaultLevel="body-sm" />
|
|
338
338
|
</CardContent>
|
|
339
339
|
</Card>
|
|
340
340
|
);
|
|
@@ -350,11 +350,7 @@ function ReleaseNotes({ version, notes }) {
|
|
|
350
350
|
<Typography level="h2" sx={{ mb: 2 }}>
|
|
351
351
|
Version {version}
|
|
352
352
|
</Typography>
|
|
353
|
-
<Markdown
|
|
354
|
-
content={notes}
|
|
355
|
-
defaultLevel="body-md"
|
|
356
|
-
accentColor="success.500"
|
|
357
|
-
/>
|
|
353
|
+
<Markdown content={notes} defaultLevel="body-md" accentColor="success.500" />
|
|
358
354
|
</Box>
|
|
359
355
|
);
|
|
360
356
|
}
|
|
@@ -388,11 +384,7 @@ function HelpArticle({ title, content }) {
|
|
|
388
384
|
<Typography level="h1" sx={{ mb: 3 }}>
|
|
389
385
|
{title}
|
|
390
386
|
</Typography>
|
|
391
|
-
<Markdown
|
|
392
|
-
content={content}
|
|
393
|
-
defaultLevel="body-md"
|
|
394
|
-
defaultLinkAction="_blank"
|
|
395
|
-
/>
|
|
387
|
+
<Markdown content={content} defaultLevel="body-md" defaultLinkAction="_blank" />
|
|
396
388
|
</Container>
|
|
397
389
|
);
|
|
398
390
|
}
|
|
@@ -437,10 +429,7 @@ function TaskDetails({ task }) {
|
|
|
437
429
|
<Typography level="title-lg" sx={{ mb: 2 }}>
|
|
438
430
|
{task.title}
|
|
439
431
|
</Typography>
|
|
440
|
-
<Markdown
|
|
441
|
-
content={task.description}
|
|
442
|
-
defaultLevel="body-sm"
|
|
443
|
-
/>
|
|
432
|
+
<Markdown content={task.description} defaultLevel="body-sm" />
|
|
444
433
|
</CardContent>
|
|
445
434
|
</Card>
|
|
446
435
|
);
|
|
@@ -469,10 +458,7 @@ Make sure to follow the ||coding standards|| and add proper error handling.
|
|
|
469
458
|
```tsx
|
|
470
459
|
function NotificationDetail({ notification }) {
|
|
471
460
|
return (
|
|
472
|
-
<Alert
|
|
473
|
-
color={notification.type}
|
|
474
|
-
sx={{ mb: 2 }}
|
|
475
|
-
>
|
|
461
|
+
<Alert color={notification.type} sx={{ mb: 2 }}>
|
|
476
462
|
<Markdown
|
|
477
463
|
content={notification.message}
|
|
478
464
|
defaultLevel="body-sm"
|
|
@@ -500,11 +486,7 @@ function EmailPreview({ subject, body }) {
|
|
|
500
486
|
{subject}
|
|
501
487
|
</Typography>
|
|
502
488
|
<Divider sx={{ mb: 2 }} />
|
|
503
|
-
<Markdown
|
|
504
|
-
content={body}
|
|
505
|
-
defaultLevel="body-md"
|
|
506
|
-
defaultLinkAction="_blank"
|
|
507
|
-
/>
|
|
489
|
+
<Markdown content={body} defaultLevel="body-md" defaultLinkAction="_blank" />
|
|
508
490
|
</CardContent>
|
|
509
491
|
</Card>
|
|
510
492
|
);
|
|
@@ -521,10 +503,7 @@ function APIDocumentation({ endpoint }) {
|
|
|
521
503
|
<Chip color="primary" sx={{ mb: 2 }}>
|
|
522
504
|
{endpoint.method}
|
|
523
505
|
</Chip>
|
|
524
|
-
<Markdown
|
|
525
|
-
content={endpoint.description}
|
|
526
|
-
defaultLevel="body-md"
|
|
527
|
-
/>
|
|
506
|
+
<Markdown content={endpoint.description} defaultLevel="body-md" />
|
|
528
507
|
</Box>
|
|
529
508
|
);
|
|
530
509
|
}
|
|
@@ -580,7 +559,7 @@ curl -X POST https://api.example.com/users \\
|
|
|
580
559
|
## Text Formatting
|
|
581
560
|
|
|
582
561
|
**Bold text** using `**text**`
|
|
583
|
-
|
|
562
|
+
_Italic text_ using `*text*`
|
|
584
563
|
~Strikethrough~ using `~text~`
|
|
585
564
|
`Inline code` using backticks
|
|
586
565
|
||Accent color|| using `||text||`
|
|
@@ -588,7 +567,9 @@ curl -X POST https://api.example.com/users \\
|
|
|
588
567
|
## Headings
|
|
589
568
|
|
|
590
569
|
# Heading 1
|
|
570
|
+
|
|
591
571
|
## Heading 2
|
|
572
|
+
|
|
592
573
|
### Heading 3
|
|
593
574
|
|
|
594
575
|
## Links
|
|
@@ -599,16 +580,19 @@ https://auto-linked-url.com
|
|
|
599
580
|
## Lists
|
|
600
581
|
|
|
601
582
|
### Unordered
|
|
583
|
+
|
|
602
584
|
- Item 1
|
|
603
585
|
- Item 2
|
|
604
586
|
- Nested item
|
|
605
587
|
|
|
606
588
|
### Ordered
|
|
589
|
+
|
|
607
590
|
1. First
|
|
608
591
|
2. Second
|
|
609
592
|
3. Third
|
|
610
593
|
|
|
611
594
|
### Task List
|
|
595
|
+
|
|
612
596
|
- [x] Completed
|
|
613
597
|
- [ ] Pending
|
|
614
598
|
|
|
@@ -621,6 +605,7 @@ https://auto-linked-url.com
|
|
|
621
605
|
|
|
622
606
|
```javascript
|
|
623
607
|
const code = 'highlighted';
|
|
608
|
+
```
|
|
624
609
|
````
|
|
625
610
|
|
|
626
611
|
## Tables
|
|
@@ -705,10 +690,7 @@ Markdown renders semantic HTML elements with proper accessibility:
|
|
|
705
690
|
```tsx
|
|
706
691
|
// Links opening in new tabs should have proper attributes
|
|
707
692
|
// The component handles rel="noopener noreferrer" automatically
|
|
708
|
-
<Markdown
|
|
709
|
-
content="[External link](https://example.com)"
|
|
710
|
-
defaultLinkAction="_blank"
|
|
711
|
-
/>
|
|
693
|
+
<Markdown content="[External link](https://example.com)" defaultLinkAction="_blank" />
|
|
712
694
|
```
|
|
713
695
|
|
|
714
696
|
### Screen Reader Considerations
|
|
@@ -723,7 +705,7 @@ Markdown renders semantic HTML elements with proper accessibility:
|
|
|
723
705
|
// Ensure sufficient contrast with text colors
|
|
724
706
|
<Markdown
|
|
725
707
|
content="..."
|
|
726
|
-
textColor="neutral.800"
|
|
708
|
+
textColor="neutral.800" // Good contrast
|
|
727
709
|
/>
|
|
728
710
|
```
|
|
729
711
|
|
|
@@ -737,7 +719,7 @@ Markdown renders semantic HTML elements with proper accessibility:
|
|
|
737
719
|
// ✅ Good: Sanitize before rendering
|
|
738
720
|
import sanitize from 'sanitize-html';
|
|
739
721
|
|
|
740
|
-
<Markdown content={sanitize(userContent)}
|
|
722
|
+
<Markdown content={sanitize(userContent)} />;
|
|
741
723
|
```
|
|
742
724
|
|
|
743
725
|
2. **Match typography to context**: Use appropriate levels for the content type
|
|
@@ -752,20 +734,14 @@ import sanitize from 'sanitize-html';
|
|
|
752
734
|
|
|
753
735
|
```tsx
|
|
754
736
|
// ✅ Good: External links in new tab
|
|
755
|
-
<Markdown
|
|
756
|
-
content={externalContent}
|
|
757
|
-
defaultLinkAction="_blank"
|
|
758
|
-
/>
|
|
737
|
+
<Markdown content={externalContent} defaultLinkAction="_blank" />
|
|
759
738
|
```
|
|
760
739
|
|
|
761
740
|
4. **Use accent colors meaningfully**: Highlight important information
|
|
762
741
|
|
|
763
742
|
```tsx
|
|
764
743
|
// ✅ Good: Highlight key information
|
|
765
|
-
<Markdown
|
|
766
|
-
content="Your balance is ||$1,234.56||"
|
|
767
|
-
accentColor="success.500"
|
|
768
|
-
/>
|
|
744
|
+
<Markdown content="Your balance is ||$1,234.56||" accentColor="success.500" />
|
|
769
745
|
```
|
|
770
746
|
|
|
771
747
|
### ❌ Don't
|
|
@@ -820,9 +796,7 @@ import sanitize from 'sanitize-html';
|
|
|
820
796
|
For frequently re-rendering parents, memoize the Markdown component:
|
|
821
797
|
|
|
822
798
|
```tsx
|
|
823
|
-
const MemoizedMarkdown = memo(({ content, ...props }) =>
|
|
824
|
-
<Markdown content={content} {...props} />
|
|
825
|
-
));
|
|
799
|
+
const MemoizedMarkdown = memo(({ content, ...props }) => <Markdown content={content} {...props} />);
|
|
826
800
|
|
|
827
801
|
function ParentComponent({ content }) {
|
|
828
802
|
return (
|
|
@@ -850,7 +824,7 @@ function LazyMarkdown({ content }) {
|
|
|
850
824
|
observer.disconnect();
|
|
851
825
|
}
|
|
852
826
|
},
|
|
853
|
-
{ threshold: 0.1 }
|
|
827
|
+
{ threshold: 0.1 },
|
|
854
828
|
);
|
|
855
829
|
|
|
856
830
|
if (ref.current) {
|
|
@@ -861,13 +835,7 @@ function LazyMarkdown({ content }) {
|
|
|
861
835
|
}, []);
|
|
862
836
|
|
|
863
837
|
return (
|
|
864
|
-
<Box ref={ref}>
|
|
865
|
-
{isVisible ? (
|
|
866
|
-
<Markdown content={content} />
|
|
867
|
-
) : (
|
|
868
|
-
<Skeleton variant="rectangular" height={200} />
|
|
869
|
-
)}
|
|
870
|
-
</Box>
|
|
838
|
+
<Box ref={ref}>{isVisible ? <Markdown content={content} /> : <Skeleton variant="rectangular" height={200} />}</Box>
|
|
871
839
|
);
|
|
872
840
|
}
|
|
873
841
|
```
|
|
@@ -897,11 +865,11 @@ Keep content stable when possible:
|
|
|
897
865
|
|
|
898
866
|
```tsx
|
|
899
867
|
// ❌ Bad: Creating new string on each render
|
|
900
|
-
<Markdown content={`Hello, ${name}!`}
|
|
868
|
+
<Markdown content={`Hello, ${name}!`} />;
|
|
901
869
|
|
|
902
870
|
// ✅ Good: Memoize dynamic content
|
|
903
871
|
const content = useMemo(() => `Hello, ${name}!`, [name]);
|
|
904
|
-
<Markdown content={content}
|
|
872
|
+
<Markdown content={content} />;
|
|
905
873
|
```
|
|
906
874
|
|
|
907
875
|
Markdown provides a powerful way to render formatted text content in your application. Use it for documentation, user-generated content, and any scenario requiring rich text display. Always sanitize untrusted content, match typography levels to your context, and consider performance for large documents.
|