返回 slidev
components.md
根目录 / docs / builtin / components.md
1 # Components
2
3 This page lists all the built-in components provided by Slidev. These components can be **directly** used in your slides.
4
5 Note that <LinkInline link="guide/theme-addon" /> can provide additional components. To add your own components, see <LinkInline link="guide/component#write" />.
6
7 ## `Arrow`
8
9 Draw an arrow.
10
11 ### Usage
12
13 ```md
14 <Arrow x1="10" y1="20" x2="100" y2="200" />
15 ```
16
17 Or:
18
19 ```md
20 <Arrow v-bind="{ x1:10, y1:10, x2:200, y2:200 }" />
21 ```
22
23 Props:
24
25 - `x1` (`string | number`, required): start point x position
26 - `y1` (`string | number`, required): start point y position
27 - `x2` (`string | number`, required): end point x position
28 - `y2` (`string | number`, required): end point y position
29 - `width` (`string | number`, default: `2`): line width
30 - `color` (`string`, default: `'currentColor'`): line color
31 - `two-way` (`boolean`, default: `false`): draw a two-way arrow
32
33 ## `VDragArrow`
34
35 An `Arrow` component that can be dragged.
36
37 ### Usage
38
39 <LinkCard link="features/draggable#draggable-arrow" />
40
41 Props not related to position are the same as [the `Arrow` component](#arrow).
42
43 ## `AutoFitText`
44
45 Box inside which the font size will automatically adapt to fit the content, powered by [fitty](https://github.com/rikschennink/fitty). Similar to PowerPoint or Keynote TextBox.
46
47 ### Usage
48
49 ```md
50 <AutoFitText :max="200" :min="100" modelValue="Some text"/>
51 ```
52
53 Props:
54
55 - `max` (`number`, default `100`): Maximum font size in pixels
56 - `min` (`number`, default `30`): Minimum font size in pixels
57 - `modelValue` (`string`, default `''`): Text content (alternatively, use the default slot)
58 - `multiLine` (`boolean`, default `true`): Allow the text to wrap when the minimum font size is reached
59
60 ## `LightOrDark`
61
62 Use it to display one thing or another depending on the active light or dark theme.
63
64 ### Usage
65
66 Use it with the two named Slots `#dark` and `#light`:
67
68 ```md
69 <LightOrDark>
70 <template #dark>Dark mode is on</template>
71 <template #light>Light mode is on</template>
72 </LightOrDark>
73 ```
74
75 Provided props on `LightOrDark` component will be available using scoped slot props:
76
77 ```md
78 <LightOrDark width="100" alt="some image">
79 <template #dark="props">
80 <img src="/dark.png" v-bind="props"/>
81 </template>
82 <template #light="props">
83 <img src="/light.png" v-bind="props"/>
84 </template>
85 </LightOrDark>
86 ```
87
88 You can provide markdown in the slots, but you will need to surround the content with blank lines:
89
90 ```md
91 <LightOrDark>
92 <template #dark>
93
94 ![dark](/dark.png)
95
96 </template>
97 <template #light>
98
99 ![light](/light.png)
100
101 </template>
102 </LightOrDark>
103 ```
104
105 ## `Link`
106
107 Insert a link you can use to navigate to a given slide.
108
109 ### Usage
110
111 ```md
112 <Link to="42">Go to slide 42</Link>
113 <Link to="42" title="Go to slide 42"/>
114 <Link to="solutions" title="Go to solutions"/>
115 ```
116
117 Props:
118
119 - `to` (`string | number`): The path of the slide to navigate to (slides path starts from `1`)
120 - `title` (`string`): The title to display
121
122 One can use a string as `to`, provided the corresponding route exists, e.g.
123
124 ```md
125 ---
126 routeAlias: solutions
127 ---
128
129 # Now some solutions!
130 ```
131
132 ## `PoweredBySlidev`
133
134 Renders "Powered by Slidev" with a link to the Slidev website.
135
136 ## `RenderWhen`
137
138 Render slots depend on whether the context matches (for example whether we are in presenter view).
139
140 ### Usage
141
142 ```md
143 <RenderWhen context="presenter">This will only be rendered in presenter view.</RenderWhen>
144 ```
145
146 Context type: `'main' | 'visible' | 'print' | 'slide' | 'overview' | 'presenter' | 'previewNext'`
147
148 Props:
149
150 - `context` (`Context | Context[]`): a context or array of contexts you want to check for
151 - `'main'`: Render in slides and presenter view (equivalent to ['slide', 'presenter']),
152 - `'visible'`: Render the content if it is visible
153 - `'print'`: Render in print mode
154 - `'slide'`: Render in slides
155 - `'overview'`: Render in overview
156 - `'presenter'`: Render in presenter view
157 - `'previewNext'`: Render in presenter's next slide view
158
159 Slots:
160
161 - `#default`: Rendered when the context matches
162 - `#fallback`: Rendered when the context does not match
163
164 ## `SlideCurrentNo`
165
166 Current slide number.
167
168 ### Usage
169
170 ```md
171 <SlideCurrentNo />
172 ```
173
174 ## `SlidesTotal`
175
176 Total number of slides.
177
178 ### Usage
179
180 ```md
181 <SlidesTotal />
182 ```
183
184 ## `TitleRenderer`
185
186 Insert the main title from a slide parsed as HTML.
187
188 Titles and title levels get automatically retrieved from the first title element of each slide.
189
190 You can override this automatic behavior for a slide by using the front matter syntax:
191
192 ```yml
193 ---
194 title: Amazing slide title
195 level: 2
196 ---
197 ```
198
199 ### Usage
200
201 The `<TitleRenderer>` component is a virtual component you can import with:
202
203 ```js
204 import TitleRenderer from '#slidev/title-renderer'
205 ```
206
207 Then you can use it with:
208
209 ```md
210 <TitleRenderer no="42" />
211 ```
212
213 Props:
214
215 - `no` (`string | number`): The number of the slide to display the title from (slides starts from `1`)
216
217 ## `Toc`
218
219 Insert a Table Of Content.
220
221 If you want a slide to not appear in the `<Toc>` component, you can use the `hideInToc` option in the frontmatter of the slide:
222
223 ```yml
224 ---
225 hideInToc: true
226 ---
227 ```
228
229 Titles are displayed using the [`<Titles>` component](#titles)
230
231 ### Usage
232
233 ```md
234 <Toc />
235 ```
236
237 Props:
238
239 - `columns` (`string | number`, default: `1`): The number of columns of the display
240 - `listClass` (`string | string[]`, default: `''`): Classes to apply to the table of contents list
241 - `maxDepth` (`string | number`, default: `Infinity`): The maximum depth level of title to display
242 - `minDepth` (`string | number`, default: `1`): The minimum depth level of title to display
243 - `mode` (`'all' | 'onlyCurrentTree'| 'onlySiblings'`, default: `'all'`):
244 - `'all'`: Display all items
245 - `'onlyCurrentTree'`: Display only items that are in current tree (active item, parents and children of active item)
246 - `'onlySiblings'`: Display only items that are in current tree and their direct siblings
247
248 ## `Transform`
249
250 Apply scaling or transforming to elements.
251
252 ### Usage
253
254 ```md
255 <Transform :scale="0.5" origin="top center">
256 <YourElements />
257 </Transform>
258 ```
259
260 Props:
261
262 - `scale` (`number | string`, default `1`): transform scale value
263 - `origin` (`string`, default `'top left'`): transform origin value
264
265 ## `Tweet`
266
267 Embed a tweet.
268
269 ### Usage
270
271 ```md
272 <Tweet id="20" />
273 ```
274
275 Props:
276
277 - `id` (`number | string`, required): id of the tweet
278 - `scale` (`number | string`, default `1`): transform scale value
279 - `conversation` (`string`, default `'none'`): [tweet embed parameter](https://developer.twitter.com/en/docs/twitter-for-websites/embedded-tweets/guides/embedded-tweet-parameter-reference)
280 - `cards` (`'hidden' | 'visible'`, default `'visible'`): [tweet embed parameter](https://developer.twitter.com/en/docs/twitter-for-websites/embedded-tweets/guides/embedded-tweet-parameter-reference)
281
282 ## `BlueSky`
283
284 Embed a Bluesky post.
285
286 ### Usage
287
288 ```md
289 <BlueSky uri="https://bsky.app/profile/sli.dev/post/3la7gcgfwpe2n" />
290 <BlueSky uri="at://did:plc:432mbsu2xucyvxl6sluohidu/app.bsky.feed.post/3la7gcgfwpe2n" />
291 ```
292
293 Props:
294
295 - `uri` (`string`, required): AT-URI of the Bluesky post, or a `https://bsky.app/profile/.../post/...` URL
296 - `scale` (`number | string`, default `1`): transform scale value
297
298 ## `VAfter`, `VClick` and `VClicks`
299
300 <LinkCard link="guide/animations#click-animation" />
301
302 ## `VSwitch`
303
304 Switch between multiple slots based on clicks.
305
306 <LinkCard link="guide/animations#enter-leave" />
307
308 - If the `unmount` prop is set to `true`, the previous slot will be unmounted when switching to the next slot. Default is `false`.
309 - Use the `tag` and `childTag` props to change the default tag of the component and its children. Default is `div`.
310 - Use the `transition` prop to change the transition effect. Default is `false` (disabled).
311
312 ## `VDrag`
313
314 <LinkCard link="features/draggable" />
315
316 ## `SlidevVideo`
317
318 Embed a video.
319
320 ### Usage
321
322 ```md
323 <SlidevVideo v-click autoplay controls>
324 <!-- Anything that can go in an HTML video element. -->
325 <source src="/myMovie.mp4" type="video/mp4" />
326 <source src="/myMovie.webm" type="video/webm" />
327 <p>
328 Your browser does not support videos. You may download it
329 <a href="/myMovie.mp4">here</a>.
330 </p>
331 </SlidevVideo>
332 ```
333
334 Check [HTML video element's doc](https://developer.mozilla.org/docs/Web/HTML/Element/Video) to see what can be included in this component's slot.
335
336 Props:
337
338 - `controls` (`boolean`, default: `false`): show the video controls
339 - `autoplay` (`boolean | 'once'`, default: `false`):
340 - `true` or `'once'`: start the video only once and does not restart it once ended or paused
341 - `false`: never automatically start the video (rely on `controls` instead)
342 - `autoreset` (`'slide' | 'click'`, default: `undefined`):
343 - `'slide'`: go back to the start of the video when going back to the slide
344 - `'click'`: go back to the start of the video when going back to the component's click turn
345 - `poster` (`string | undefined`, default: `undefined`):
346 - The source of the image to print when the video is not playing.
347 - `printPoster` (`string | undefined`, default: `undefined`):
348 - The override for `poster` when printing.
349 - `timestamp` (`string | number`, default: `0`):
350 - The starting time of the video in seconds.
351 - `printTimestamp` (`string | number | 'last' | undefined`, default: `undefined`):
352 - The override for `timestamp` when printing.
353
354 ::: warning
355 When exporting, the video may fail to load because Chromium does not support some video formats. In this case, you can specify the executable path of the browser. See [Chromium executable path](/guide/exporting.html#executable-path) for more information.
356 :::
357
358 ## `Youtube`
359
360 Embed a YouTube video.
361
362 ### Usage
363
364 ```md
365 <Youtube id="luoMHjh-XcQ" />
366 ```
367
368 Props:
369
370 - `id` (`string`, required): id of the YouTube video
371 - `width` (`number`): width of the video
372 - `height` (`number`): height of the video
373
374 You can also make the video start at a specific time if you add `?start=1234` to the id value (where `1234` is seconds),
375
375 lines MARKDOWN