@fibrae/semi-ui-svelte 0.9.0 → 0.10.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 +8 -4
- package/README.zh-CN.md +8 -4
- package/dist/components/anchor/interface.d.ts +14 -0
- package/dist/components/audio-player/interface.d.ts +5 -0
- package/dist/components/auto-complete/interface.d.ts +29 -0
- package/dist/components/avatar/interface.d.ts +24 -0
- package/dist/components/backtop/interface.d.ts +2 -0
- package/dist/components/badge/interface.d.ts +7 -0
- package/dist/components/banner/interface.d.ts +7 -0
- package/dist/components/breadcrumb/interface.d.ts +10 -0
- package/dist/components/button/interface.d.ts +18 -0
- package/dist/components/calendar/interface.d.ts +16 -0
- package/dist/components/card/interface.d.ts +18 -0
- package/dist/components/carousel/interface.d.ts +16 -0
- package/dist/components/cascader/cascader.svelte +1 -0
- package/dist/components/cascader/interface.d.ts +57 -0
- package/dist/components/checkbox/interface.d.ts +19 -0
- package/dist/components/code-highlight/interface.d.ts +3 -0
- package/dist/components/collapse/interface.d.ts +16 -0
- package/dist/components/collapsible/interface.d.ts +10 -0
- package/dist/components/color-picker/interface.d.ts +10 -0
- package/dist/components/config-provider/interface.d.ts +7 -0
- package/dist/components/cropper/interface.d.ts +11 -0
- package/dist/components/date-picker/interface.d.ts +47 -0
- package/dist/components/descriptions/interface.d.ts +6 -0
- package/dist/components/divider/interface.d.ts +4 -0
- package/dist/components/dropdown/interface.d.ts +8 -0
- package/dist/components/empty/interface.d.ts +7 -0
- package/dist/components/feedback/interface.d.ts +16 -0
- package/dist/components/float-button/interface.d.ts +14 -0
- package/dist/components/form/interface.d.ts +47 -0
- package/dist/components/form/label.svelte +2 -2
- package/dist/components/grid/interface.d.ts +13 -0
- package/dist/components/highlight/interface.d.ts +7 -0
- package/dist/components/hot-keys/interface.d.ts +3 -0
- package/dist/components/image/interface.d.ts +59 -0
- package/dist/components/input/interface.d.ts +67 -0
- package/dist/components/input-number/interface.d.ts +24 -0
- package/dist/components/json-viewer/interface.d.ts +7 -0
- package/dist/components/layout/interface.d.ts +3 -0
- package/dist/components/list/interface.d.ts +18 -0
- package/dist/components/locale/interface.d.ts +4 -0
- package/dist/components/lottie/interface.d.ts +2 -0
- package/dist/components/markdown-render/interface.d.ts +5 -0
- package/dist/components/modal/interface.d.ts +29 -0
- package/dist/components/navigation/interface.d.ts +47 -0
- package/dist/components/overflow-list/interface.d.ts +11 -0
- package/dist/components/pagination/interface.d.ts +12 -0
- package/dist/components/pincode/interface.d.ts +8 -0
- package/dist/components/popconfirm/interface.d.ts +12 -0
- package/dist/components/popover/interface.d.ts +30 -0
- package/dist/components/progress/interface.d.ts +13 -0
- package/dist/components/radio/interface.d.ts +22 -0
- package/dist/components/rating/interface.d.ts +12 -0
- package/dist/components/resizable/interface.d.ts +30 -0
- package/dist/components/scroll-list/interface.d.ts +6 -0
- package/dist/components/select/interface.d.ts +63 -0
- package/dist/components/side-sheet/interface.d.ts +19 -0
- package/dist/components/skeleton/interface.d.ts +7 -0
- package/dist/components/slider/interface.d.ts +23 -0
- package/dist/components/space/interface.d.ts +4 -0
- package/dist/components/spin/interface.d.ts +7 -0
- package/dist/components/steps/interface.d.ts +9 -0
- package/dist/components/switch/interface.d.ts +7 -0
- package/dist/components/table/interface.d.ts +48 -0
- package/dist/components/tabs/interface.d.ts +29 -0
- package/dist/components/tag/interface.d.ts +22 -0
- package/dist/components/tag-input/interface.d.ts +29 -0
- package/dist/components/time-picker/interface.d.ts +31 -0
- package/dist/components/timeline/interface.d.ts +5 -0
- package/dist/components/tooltip/interface.d.ts +20 -0
- package/dist/components/tooltip/tooltip.svelte +3 -0
- package/dist/components/transfer/interface.d.ts +18 -0
- package/dist/components/tree/interface.d.ts +45 -0
- package/dist/components/tree-select/interface.d.ts +55 -0
- package/dist/components/typography/interface.d.ts +33 -0
- package/dist/components/upload/interface.d.ts +64 -0
- package/dist/components/user-guide/interface.d.ts +15 -0
- package/dist/components/video-player/interface.d.ts +22 -0
- package/dist/styles.css +1 -1
- package/docs/advanced/dark-mode.md +288 -0
- package/docs/basic/button.md +605 -0
- package/docs/basic/divider.md +103 -0
- package/docs/basic/float-button.md +246 -0
- package/docs/basic/grid.md +427 -0
- package/docs/basic/layout.md +459 -0
- package/docs/basic/resizable.md +584 -0
- package/docs/basic/space.md +163 -0
- package/docs/basic/tokens.md +425 -0
- package/docs/basic/typography.md +615 -0
- package/docs/changes-from-semi.md +105 -0
- package/docs/ecosystem/tailwind.md +210 -0
- package/docs/experience/accessibility.md +82 -0
- package/docs/experience/content-guidelines.md +819 -0
- package/docs/experience/internationalization.md +7 -0
- package/docs/feedback/banner.md +198 -0
- package/docs/feedback/feedback.md +294 -0
- package/docs/feedback/notification.md +401 -0
- package/docs/feedback/popconfirm.md +243 -0
- package/docs/feedback/progress.md +389 -0
- package/docs/feedback/skeleton.md +388 -0
- package/docs/feedback/spin.md +172 -0
- package/docs/feedback/toast.md +393 -0
- package/docs/input/auto-complete.md +399 -0
- package/docs/input/cascader.md +1558 -0
- package/docs/input/checkbox.md +408 -0
- package/docs/input/color-picker.md +175 -0
- package/docs/input/date-picker.md +942 -0
- package/docs/input/form.md +2550 -0
- package/docs/input/input-number.md +451 -0
- package/docs/input/input.md +640 -0
- package/docs/input/pincode.md +191 -0
- package/docs/input/radio.md +337 -0
- package/docs/input/rating.md +214 -0
- package/docs/input/select.md +1230 -0
- package/docs/input/slider.md +347 -0
- package/docs/input/switch.md +206 -0
- package/docs/input/tag-input.md +465 -0
- package/docs/input/time-picker.md +358 -0
- package/docs/input/transfer.md +1061 -0
- package/docs/input/tree-select.md +1300 -0
- package/docs/input/upload.md +1811 -0
- package/docs/llms.txt +147 -0
- package/docs/navigation/anchor.md +377 -0
- package/docs/navigation/backtop.md +100 -0
- package/docs/navigation/breadcrumb.md +284 -0
- package/docs/navigation/navigation.md +851 -0
- package/docs/navigation/pagination.md +217 -0
- package/docs/navigation/steps.md +315 -0
- package/docs/navigation/tabs.md +754 -0
- package/docs/navigation/tree.md +1956 -0
- package/docs/other/config-provider.md +599 -0
- package/docs/other/locale.md +353 -0
- package/docs/plus/audio-player.md +155 -0
- package/docs/plus/code-highlight.md +150 -0
- package/docs/plus/drag-move.md +214 -0
- package/docs/plus/hot-keys.md +174 -0
- package/docs/plus/json-viewer.md +392 -0
- package/docs/plus/lottie.md +176 -0
- package/docs/plus/markdown-render.md +240 -0
- package/docs/plus/video-player.md +325 -0
- package/docs/show/avatar.md +475 -0
- package/docs/show/badge.md +276 -0
- package/docs/show/calendar.md +352 -0
- package/docs/show/card.md +485 -0
- package/docs/show/carousel.md +592 -0
- package/docs/show/collapse.md +289 -0
- package/docs/show/collapsible.md +216 -0
- package/docs/show/cropper.md +285 -0
- package/docs/show/descriptions.md +325 -0
- package/docs/show/dropdown.md +466 -0
- package/docs/show/empty.md +225 -0
- package/docs/show/highlight.md +144 -0
- package/docs/show/image.md +433 -0
- package/docs/show/list.md +927 -0
- package/docs/show/modal.md +517 -0
- package/docs/show/overflow-list.md +272 -0
- package/docs/show/popover.md +534 -0
- package/docs/show/scroll-list.md +156 -0
- package/docs/show/side-sheet.md +274 -0
- package/docs/show/table.md +5437 -0
- package/docs/show/tag.md +428 -0
- package/docs/show/timeline.md +277 -0
- package/docs/show/tooltip.md +442 -0
- package/docs/show/user-guide.md +419 -0
- package/docs/start/getting-started.md +234 -0
- package/docs/start/introduction.md +57 -0
- package/docs/start/overview.md +21 -0
- package/package.json +5 -4
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
# Empty
|
|
2
|
+
|
|
3
|
+
> Placeholder component when the page is empty.
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/show/empty/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Empty } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic usage
|
|
18
|
+
|
|
19
|
+
By setting a placeholder image with `image`, you can manually import the corresponding illustration from `@fibrae/semi-icons-svelte/illustrations` (the default width and height of the illustration is 200x200) and pass it as a snippet, or pass a snippet with any custom content. `image` also accepts an image URL string, or an SVG sprite symbol as `{ id }`.
|
|
20
|
+
|
|
21
|
+
A series of dark mode illustrations are added, and the illustrations that need to be used in dark mode can be passed in through `darkModeImage` to better adapt to the dark mode.
|
|
22
|
+
|
|
23
|
+
An empty string `image` counts as no image, and the title is laid out as if there were none.
|
|
24
|
+
|
|
25
|
+
```svelte
|
|
26
|
+
<script lang="ts">
|
|
27
|
+
import { IllustrationConstruction, IllustrationConstructionDark } from '@fibrae/semi-icons-svelte/illustrations';
|
|
28
|
+
import { Empty } from '@fibrae/semi-ui-svelte';
|
|
29
|
+
|
|
30
|
+
const imageStyle = 'width: 150px; height: 150px';
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
{#snippet image()}<IllustrationConstruction style={imageStyle} />{/snippet}
|
|
34
|
+
{#snippet darkModeImage()}<IllustrationConstructionDark style={imageStyle} />{/snippet}
|
|
35
|
+
|
|
36
|
+
<Empty {darkModeImage} {image} title="功能建设中">
|
|
37
|
+
{#snippet description()}当前功能暂未开放,敬请期待。{/snippet}
|
|
38
|
+
</Empty>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Custom content
|
|
42
|
+
|
|
43
|
+
Description content goes in the `description` snippet, and `children` is the actions area below it.
|
|
44
|
+
|
|
45
|
+
```svelte
|
|
46
|
+
<script lang="ts">
|
|
47
|
+
import { IllustrationNoContent, IllustrationNoContentDark } from '@fibrae/semi-icons-svelte/illustrations';
|
|
48
|
+
import { Button, Empty } from '@fibrae/semi-ui-svelte';
|
|
49
|
+
|
|
50
|
+
const imageStyle = 'width: 150px; height: 150px';
|
|
51
|
+
</script>
|
|
52
|
+
|
|
53
|
+
{#snippet image()}<IllustrationNoContent style={imageStyle} />{/snippet}
|
|
54
|
+
{#snippet darkModeImage()}<IllustrationNoContentDark style={imageStyle} />{/snippet}
|
|
55
|
+
|
|
56
|
+
<Empty {darkModeImage} {image} title="空状态标题">
|
|
57
|
+
{#snippet description()}开始创建你的第一个仪表盘吧!{/snippet}
|
|
58
|
+
<div>
|
|
59
|
+
<Button style="padding: 6px 24px; margin-inline-end: 12px" type="primary">二级按钮</Button>
|
|
60
|
+
<Button style="padding: 6px 24px" theme="solid" type="primary">一级按钮</Button>
|
|
61
|
+
</div>
|
|
62
|
+
</Empty>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
It is not necessary to use pictures.
|
|
66
|
+
|
|
67
|
+
```svelte
|
|
68
|
+
<script lang="ts">
|
|
69
|
+
import { Empty, Typography } from '@fibrae/semi-ui-svelte';
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<Empty title="暂未找到匹配的筛选结果">
|
|
73
|
+
{#snippet description()}
|
|
74
|
+
<span>
|
|
75
|
+
<Typography.Text>试试</Typography.Text>
|
|
76
|
+
<Typography.Text link>重置筛选条件</Typography.Text>
|
|
77
|
+
</span>
|
|
78
|
+
{/snippet}
|
|
79
|
+
</Empty>
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Different layout
|
|
83
|
+
|
|
84
|
+
Two types of layouts are supported: `vertical`, `horizontal`. The default is `vertical`.
|
|
85
|
+
|
|
86
|
+
```svelte
|
|
87
|
+
<script lang="ts">
|
|
88
|
+
import { IllustrationSuccess, IllustrationSuccessDark } from '@fibrae/semi-icons-svelte/illustrations';
|
|
89
|
+
import { Button, Empty } from '@fibrae/semi-ui-svelte';
|
|
90
|
+
|
|
91
|
+
const imageStyle = 'width: 150px; height: 150px';
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
{#snippet image()}<IllustrationSuccess style={imageStyle} />{/snippet}
|
|
95
|
+
{#snippet darkModeImage()}<IllustrationSuccessDark style={imageStyle} />{/snippet}
|
|
96
|
+
|
|
97
|
+
<Empty {darkModeImage} {image} layout="horizontal" style="width: 800px; margin: 0 auto" title="创建成功">
|
|
98
|
+
{#snippet description()}这是一段很长的描述文本,当文本过长的时候推荐使用这种布局形式。这是一段很长的描述文本,当文本过长的时候推荐使用这种布局形式。这是一段很长的描述文本,当文本过长的时候推荐使用这种布局形式。{/snippet}
|
|
99
|
+
<Button style="padding: 6px 24px" theme="solid" type="primary">开始操作</Button>
|
|
100
|
+
</Empty>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Placeholder illustration (under construction)
|
|
104
|
+
|
|
105
|
+
Currently the following illustrations are supported in `@fibrae/semi-icons-react/illustrations` (`@fibrae/semi-icons-vue/illustrations` for Vue, `@fibrae/semi-icons-svelte/illustrations` for Svelte).
|
|
106
|
+
|
|
107
|
+
```svelte
|
|
108
|
+
<script lang="ts">
|
|
109
|
+
import {
|
|
110
|
+
IllustrationConstruction,
|
|
111
|
+
IllustrationConstructionDark,
|
|
112
|
+
IllustrationFailure,
|
|
113
|
+
IllustrationFailureDark,
|
|
114
|
+
IllustrationIdle,
|
|
115
|
+
IllustrationIdleDark,
|
|
116
|
+
IllustrationNoAccess,
|
|
117
|
+
IllustrationNoAccessDark,
|
|
118
|
+
IllustrationNoContent,
|
|
119
|
+
IllustrationNoContentDark,
|
|
120
|
+
IllustrationNotFound,
|
|
121
|
+
IllustrationNotFoundDark,
|
|
122
|
+
IllustrationNoResult,
|
|
123
|
+
IllustrationNoResultDark,
|
|
124
|
+
IllustrationSuccess,
|
|
125
|
+
IllustrationSuccessDark,
|
|
126
|
+
} from '@fibrae/semi-icons-svelte/illustrations';
|
|
127
|
+
import { Empty } from '@fibrae/semi-ui-svelte';
|
|
128
|
+
|
|
129
|
+
const emptyStyle = 'padding: 30px';
|
|
130
|
+
const imageStyle = 'width: 150px; height: 150px';
|
|
131
|
+
</script>
|
|
132
|
+
|
|
133
|
+
<div style="display: flex; flex-wrap: wrap">
|
|
134
|
+
<Empty style={emptyStyle}>
|
|
135
|
+
{#snippet image()}<IllustrationSuccess style={imageStyle} />{/snippet}
|
|
136
|
+
{#snippet darkModeImage()}<IllustrationSuccessDark style={imageStyle} />{/snippet}
|
|
137
|
+
{#snippet description()}创建成功{/snippet}
|
|
138
|
+
</Empty>
|
|
139
|
+
<Empty style={emptyStyle}>
|
|
140
|
+
{#snippet image()}<IllustrationFailure style={imageStyle} />{/snippet}
|
|
141
|
+
{#snippet darkModeImage()}<IllustrationFailureDark style={imageStyle} />{/snippet}
|
|
142
|
+
{#snippet description()}加载失败{/snippet}
|
|
143
|
+
</Empty>
|
|
144
|
+
<Empty style={emptyStyle}>
|
|
145
|
+
{#snippet image()}<IllustrationNoAccess style={imageStyle} />{/snippet}
|
|
146
|
+
{#snippet darkModeImage()}<IllustrationNoAccessDark style={imageStyle} />{/snippet}
|
|
147
|
+
{#snippet description()}没有权限{/snippet}
|
|
148
|
+
</Empty>
|
|
149
|
+
<Empty style={emptyStyle}>
|
|
150
|
+
{#snippet image()}<IllustrationNoContent style={imageStyle} />{/snippet}
|
|
151
|
+
{#snippet darkModeImage()}<IllustrationNoContentDark style={imageStyle} />{/snippet}
|
|
152
|
+
{#snippet description()}暂无内容,请添加{/snippet}
|
|
153
|
+
</Empty>
|
|
154
|
+
<Empty style={emptyStyle}>
|
|
155
|
+
{#snippet image()}<IllustrationNotFound style={imageStyle} />{/snippet}
|
|
156
|
+
{#snippet darkModeImage()}<IllustrationNotFoundDark style={imageStyle} />{/snippet}
|
|
157
|
+
{#snippet description()}页面404{/snippet}
|
|
158
|
+
</Empty>
|
|
159
|
+
<Empty style={emptyStyle}>
|
|
160
|
+
{#snippet image()}<IllustrationNoResult style={imageStyle} />{/snippet}
|
|
161
|
+
{#snippet darkModeImage()}<IllustrationNoResultDark style={imageStyle} />{/snippet}
|
|
162
|
+
{#snippet description()}搜索无结果{/snippet}
|
|
163
|
+
</Empty>
|
|
164
|
+
<Empty style={emptyStyle}>
|
|
165
|
+
{#snippet image()}<IllustrationConstruction style={imageStyle} />{/snippet}
|
|
166
|
+
{#snippet darkModeImage()}<IllustrationConstructionDark style={imageStyle} />{/snippet}
|
|
167
|
+
{#snippet description()}建设中{/snippet}
|
|
168
|
+
</Empty>
|
|
169
|
+
<Empty style={emptyStyle}>
|
|
170
|
+
{#snippet image()}<IllustrationIdle style={imageStyle} />{/snippet}
|
|
171
|
+
{#snippet darkModeImage()}<IllustrationIdleDark style={imageStyle} />{/snippet}
|
|
172
|
+
{#snippet description()}神游四方{/snippet}
|
|
173
|
+
</Empty>
|
|
174
|
+
</div>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
## API reference
|
|
178
|
+
|
|
179
|
+
**Props**
|
|
180
|
+
|
|
181
|
+
| Property | Description | Type | Default |
|
|
182
|
+
| - | - | - | - |
|
|
183
|
+
| children | Actions below the description. | `Snippet` | - |
|
|
184
|
+
| classNames | Class names of the inner parts, keyed by image; values take anything class takes (string, array or object) and merge with the built-in classes. | `Partial<Record<EmptyPart, ClassValue>>` | - |
|
|
185
|
+
| darkModeImage | Placeholder image in dark mode, following the theme-mode attribute of document.body. Takes the same values as image. | `EmptyImage` | - |
|
|
186
|
+
| description | Description content. | `Snippet` | - |
|
|
187
|
+
| image | Placeholder image: an image URL, an in-page SVG sprite symbol as `{ id }`, or a snippet for any other content. An empty string counts as no image. | `EmptyImage` | - |
|
|
188
|
+
| layout | Layout mode: vertical or horizontal. | `EmptyLayout` | `"vertical"` |
|
|
189
|
+
| styles | Style strings of the inner parts, keyed like classNames. | `Partial<Record<EmptyPart, string>>` | - |
|
|
190
|
+
| title | Title, a string or a snippet. | `string \| Snippet` | - |
|
|
191
|
+
|
|
192
|
+
`class`, `style` and native attributes land on the root `div` element. `title`, `description`, `image`, `darkModeImage`, `classNames`, `styles` and `layout` are component props and do not land on the root element. In dark mode, only an Empty given a `darkModeImage` observes the `theme-mode` of `document.body` after mount; server rendering and hydration use the light image.
|
|
193
|
+
|
|
194
|
+
## Accessibility
|
|
195
|
+
|
|
196
|
+
### ARIA
|
|
197
|
+
|
|
198
|
+
- Empty illustrations are decorative: an SVG illustration has `aria-hidden="true"`, and an `img` rendered from an image URL has an empty `alt`
|
|
199
|
+
- `title` is styled as a heading but rendered as a `div` without heading semantics, so it does not disturb the page's heading levels
|
|
200
|
+
|
|
201
|
+
## Content Guidelines
|
|
202
|
+
|
|
203
|
+
- Title
|
|
204
|
+
- The title should be concise and easy to understand
|
|
205
|
+
- Text
|
|
206
|
+
- The specific reasons for displaying the empty state can be displayed, and the subsequent operation behavior can also be displayed to help the user eliminate the empty state
|
|
207
|
+
- Don't repeat the content on the title
|
|
208
|
+
- Try to keep the body text within 1-2 sentences
|
|
209
|
+
- Action button
|
|
210
|
+
- Button copy needs to be clear and easy to understand
|
|
211
|
+
- Use the verb + noun format
|
|
212
|
+
|
|
213
|
+
## Design Token
|
|
214
|
+
|
|
215
|
+
The design token table of this component is on the web page: <https://semi-design-next.pages.dev/en-US/svelte/show/empty/>
|
|
216
|
+
|
|
217
|
+
## FAQ
|
|
218
|
+
|
|
219
|
+
## Changes from Semi Design
|
|
220
|
+
|
|
221
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
222
|
+
|
|
223
|
+
- 破坏性:删除 `imageStyle`,改用 `classNames.image`、`styles.image`,落在占位图容器上。
|
|
224
|
+
- 破坏性(类型):`image`、`darkModeImage` 的对象形式只接受 `{ id: string }`;`image` 传空字符串视为无图片;插画 `alt` 为空,标题渲染为 `div`。Vue:`title`、`description`、`image`、`darkModeImage` 用同名插槽,默认插槽是底部操作区;暗色模式挂载后观察 `document.body` 的 `theme-mode`。
|
|
225
|
+
- Svelte:`title`、`image`、`darkModeImage` 是 `string | Snippet`(`image` 还可以是 `{ id }`),`description` 与 `children`(底部操作区)是 snippet;`styles` 的值只接受字符串;传了 snippet 就渲染,不过滤渲染为空的 snippet;只有传了 `darkModeImage` 的实例才在挂载后观察 `document.body` 的 `theme-mode`。
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# Highlight
|
|
2
|
+
|
|
3
|
+
> highlight specific content
|
|
4
|
+
|
|
5
|
+
Package: `@fibrae/semi-ui-svelte`. Web page: https://semi-design-next.pages.dev/en-US/svelte/show/highlight/
|
|
6
|
+
|
|
7
|
+
## Demos
|
|
8
|
+
|
|
9
|
+
### How to import
|
|
10
|
+
|
|
11
|
+
```svelte
|
|
12
|
+
<script lang="ts">
|
|
13
|
+
import { Highlight } from '@fibrae/semi-ui-svelte';
|
|
14
|
+
</script>
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic usage
|
|
18
|
+
|
|
19
|
+
You can specify keywords to be highlighted with `searchWords` and source text with `sourceString`
|
|
20
|
+
|
|
21
|
+
> **Attension**
|
|
22
|
+
>
|
|
23
|
+
> The Highlight component will split the text into multiple independent inline elements. Any CSS layout that splits the text flow (such as flex layout) may break the highlighted text. To prevent the highlighted content from being split into different rows or columns by the browser, please wrap the Highlight component
|
|
24
|
+
> with a wrapper element as needed.
|
|
25
|
+
|
|
26
|
+
```svelte
|
|
27
|
+
<script lang="ts">
|
|
28
|
+
import { Highlight } from '@fibrae/semi-ui-svelte';
|
|
29
|
+
|
|
30
|
+
const sourceString = '从 Semi Design 到 Any Design 快速定义你的设计系统,并应用在设计稿和代码中';
|
|
31
|
+
const searchWords = ['设计系统', 'Semi Design'];
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<h2>
|
|
35
|
+
<Highlight {searchWords} {sourceString} />
|
|
36
|
+
</h2>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Specify highlight style
|
|
40
|
+
|
|
41
|
+
By default, the highlighted text will have its own text style, the text color is black, and the background color is `--semi-yellow-4`.\
|
|
42
|
+
In dark mode, the text color is white, and the background color is `--semi-yellow-2`.\
|
|
43
|
+
When you need to customize different highlight styles, you can specify them through `classNames.highlight` and `styles.highlight`
|
|
44
|
+
|
|
45
|
+
`styles.highlight` is a CSS string, and a search word's `style` is a style object whose keys may be camelCase or kebab-case. Numbers get no `px`: write lengths as strings such as `'4px'`. Unitless properties such as `fontWeight: 600` still work.
|
|
46
|
+
|
|
47
|
+
```svelte
|
|
48
|
+
<script lang="ts">
|
|
49
|
+
import { Highlight } from '@fibrae/semi-ui-svelte';
|
|
50
|
+
|
|
51
|
+
const sourceString = '从 Semi Design 到 Any Design 快速定义你的设计系统,并应用在设计稿和代码中';
|
|
52
|
+
const searchWords = ['设计系统', 'Semi Design'];
|
|
53
|
+
|
|
54
|
+
const baseStyle = 'border-radius: 6px; margin-inline: 4px; padding-inline: 4px; color: var(--semi-white);';
|
|
55
|
+
const tealStyle = `${baseStyle} background-color: var(--semi-teal-7);`;
|
|
56
|
+
const primaryStyle = `${baseStyle} background-color: var(--semi-color-primary);`;
|
|
57
|
+
</script>
|
|
58
|
+
|
|
59
|
+
<h2>
|
|
60
|
+
<Highlight {searchWords} {sourceString} styles={{ highlight: tealStyle }} />
|
|
61
|
+
</h2>
|
|
62
|
+
<h2>
|
|
63
|
+
<Highlight {searchWords} {sourceString} styles={{ highlight: primaryStyle }} />
|
|
64
|
+
</h2>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Use Different Styles for Different Texts
|
|
68
|
+
|
|
69
|
+
It supports using different highlight styles for different highlighted texts. The `searchWords` is a string array by default. When an array of objects is passed in, the highlighted text can be specified through `text`, and the `className` and `style` can be specified separately at the same time.
|
|
70
|
+
|
|
71
|
+
The class field of an object item is `class`, as in Svelte templates.
|
|
72
|
+
|
|
73
|
+
```svelte
|
|
74
|
+
<script lang="ts">
|
|
75
|
+
import { Highlight } from '@fibrae/semi-ui-svelte';
|
|
76
|
+
|
|
77
|
+
const sourceString = '从 Semi Design 到 Any Design 快速定义你的设计系统,并应用在设计稿和代码中';
|
|
78
|
+
const searchWords = [
|
|
79
|
+
{
|
|
80
|
+
text: 'Semi',
|
|
81
|
+
style: { backgroundColor: 'var(--semi-teal-7)', color: 'var(--semi-white)', padding: '4px' },
|
|
82
|
+
class: 'keyword1',
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
text: '设计系统',
|
|
86
|
+
style: { backgroundColor: 'var(--semi-color-primary)', color: 'var(--semi-white)', padding: '4px' },
|
|
87
|
+
class: 'keyword2',
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
text: '设计稿和代码',
|
|
91
|
+
style: { backgroundColor: 'var(--semi-violet-5)', color: 'var(--semi-white)', padding: '4px' },
|
|
92
|
+
class: 'keyword3',
|
|
93
|
+
},
|
|
94
|
+
];
|
|
95
|
+
const highlightStyle = 'border-radius: 4px;';
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<h2>
|
|
99
|
+
<Highlight component="span" {searchWords} {sourceString} styles={{ highlight: highlightStyle }} />
|
|
100
|
+
</h2>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Specify the highlight tag
|
|
104
|
+
|
|
105
|
+
Semi will wrap the text matching searchWords in sourceString with mark tag by default, you can also re-specify the tag through `component`
|
|
106
|
+
|
|
107
|
+
```svelte
|
|
108
|
+
<script lang="ts">
|
|
109
|
+
import { Highlight } from '@fibrae/semi-ui-svelte';
|
|
110
|
+
|
|
111
|
+
const sourceString = '从 Semi Design 到 Any Design 快速定义你的设计系统,并应用在设计稿和代码中';
|
|
112
|
+
const searchWords = ['设计系统', 'Semi Design'];
|
|
113
|
+
</script>
|
|
114
|
+
|
|
115
|
+
<h2>
|
|
116
|
+
<Highlight component="strong" {searchWords} {sourceString} />
|
|
117
|
+
</h2>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## API Reference
|
|
121
|
+
|
|
122
|
+
### Highlight
|
|
123
|
+
|
|
124
|
+
**Props**
|
|
125
|
+
|
|
126
|
+
| Property | Description | Type | Default |
|
|
127
|
+
| - | - | - | - |
|
|
128
|
+
| autoEscape | Whether to escape regular expression characters in searchWords. | `boolean` | `true` |
|
|
129
|
+
| caseSensitive | Whether matching is case sensitive. | `boolean` | `false` |
|
|
130
|
+
| classNames | Class names of the highlight tag, keyed by highlight; values take anything class takes (string, array or object) and merge with the built-in classes. The class of a `searchWords` item is appended after them. | `Partial<Record<HighlightPart, ClassValue>>` | - |
|
|
131
|
+
| component | Tag name of the highlight element. | `string` | `"mark"` |
|
|
132
|
+
| searchWords | Text to highlight: a string, a string array, or an array of objects with text, class and style. | `string \| SearchWords` | `[]` |
|
|
133
|
+
| sourceString | Source text. | `string` | `""` |
|
|
134
|
+
| styles | Style string of the highlight tag, keyed by highlight. The style of a `searchWords` item is applied after it. | `Partial<Record<HighlightPart, string>>` | - |
|
|
135
|
+
|
|
136
|
+
Highlight has no root element and renders inline chunks, so undeclared attributes such as `class`, `style` and `id` have nowhere to land and are dropped, and `bind:this` cannot reach an element.
|
|
137
|
+
|
|
138
|
+
## Changes from Semi Design
|
|
139
|
+
|
|
140
|
+
From the project release notes (written in Chinese). Your knowledge of Semi Design does not cover these.
|
|
141
|
+
|
|
142
|
+
- 破坏性:删除 `highlightClassName`、`highlightStyle`,改用 `classNames.highlight`、`styles.highlight`,落在每个高亮标签上;`searchWords` 对象项的类名、样式字段不变。
|
|
143
|
+
- `searchWords` 中的 `undefined`、`null`、空字符串被忽略;相邻的不同样式搜索词不再合并成一个块,各自保留 `className` 与 `style`。
|
|
144
|
+
- Svelte:同 Vue,没有根元素,丢弃未声明属性,对象项的类名字段为 `class`;`styles.highlight` 是 CSS 字符串,对象项 `style` 是对象(键可用驼峰或 kebab-case),数字值不补 `px`。
|