Skip to content

Commit 5f57b6c

Browse files
docs: add AutoLink component reference (#24)
Co-authored-by: meteorlxy <[email protected]>
1 parent 161e56f commit 5f57b6c

File tree

2 files changed

+158
-2
lines changed

2 files changed

+158
-2
lines changed

docs/reference/components.md

+79-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,83 @@
11
# Built-in Components
22

3+
## AutoLink
4+
5+
- Props:
6+
7+
- config
8+
- Type: `AutoLinkConfig`
9+
- Required: `true`
10+
11+
```ts
12+
interface AutoLinkConfig {
13+
/**
14+
* Pattern to determine if the link should be active, which has higher priority than `exact`
15+
*/
16+
activeMatch?: string | RegExp
17+
18+
/**
19+
* The `aria-label` attribute
20+
*/
21+
ariaLabel?: string
22+
23+
/**
24+
* Whether the link should be active only if the url is an exact match
25+
*/
26+
exact?: boolean
27+
28+
/**
29+
* URL of the auto link
30+
*/
31+
link: string
32+
33+
/**
34+
* The `rel` attribute
35+
*/
36+
rel?: string
37+
38+
/**
39+
* The `target` attribute
40+
*/
41+
target?: string
42+
43+
/**
44+
* Text of the auto link
45+
*/
46+
text: string
47+
}
48+
```
49+
50+
- Usage:
51+
52+
```md
53+
<AutoLink :config="autoLinkConfig" />
54+
55+
<AutoLink :config="autoLinkConfig">
56+
default slot
57+
</AutoLink>
58+
59+
<AutoLink :config="autoLinkConfig">
60+
<template #before>before slot</template>
61+
<template #after>after slot</template>
62+
</AutoLink>
63+
64+
<AutoLink :config="autoLinkConfig">
65+
<template v-slot="config">{{ config.text }}</template>
66+
</AutoLink>
67+
68+
<AutoLink :config="autoLinkConfig">
69+
<template #before="config">{{ config.text }}</template>
70+
</AutoLink>
71+
```
72+
73+
- Details:
74+
75+
This component will automatically render internal link as `<RouteLink>`, and render external link as `<a>`. It will also add necessary attributes correspondingly.
76+
77+
You can make use of the `before` and `after` slots to render content before and after the text. Also, you can use the `default` slot to render the text (default text is `config.text`).
78+
79+
This component is mainly for developing themes. Users won't need it in most cases. For theme authors, it's recommended to use this component to render links that could be either internal or external.
80+
381
## ClientOnly
482

583
- Usage:
@@ -73,4 +151,4 @@
73151

74152
If the `active` prop is set to `true`, the link will have an extra `activeClass`. Notice that the active status won't be updated automatically when the route changes.
75153

76-
This component is mainly for developing themes. You won't need it in most cases. For theme authors, it's recommended to use this component instead of the `<RouterLink>` component from `vue-router`.
154+
This component is mainly for developing themes. Users won't need it in most cases. For theme authors, it's recommended to use this component to render internal links instead of the `<RouterLink>` component from `vue-router`.

docs/zh/reference/components.md

+79-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,83 @@
11
# 内置组件
22

3+
## AutoLink
4+
5+
- Props:
6+
7+
- config
8+
- 类型:`AutoLinkConfig`
9+
- 是否必须:`true`
10+
11+
```ts
12+
interface AutoLinkConfig {
13+
/**
14+
* 判断该链接是否被激活的模式,优先级高于 `exact`
15+
*/
16+
activeMatch?: string | RegExp
17+
18+
/**
19+
* `aria-label` 属性
20+
*/
21+
ariaLabel?: string
22+
23+
/**
24+
* 该链接是否只有在 URL 完全匹配时才激活
25+
*/
26+
exact?: boolean
27+
28+
/**
29+
* 自动链接的 URL
30+
*/
31+
link: string
32+
33+
/**
34+
* `rel` 属性
35+
*/
36+
rel?: string
37+
38+
/**
39+
* `target` 属性
40+
*/
41+
target?: string
42+
43+
/**
44+
* 自动链接的文本
45+
*/
46+
text: string
47+
}
48+
```
49+
50+
- 使用:
51+
52+
```md
53+
<AutoLink :config="autoLinkConfig" />
54+
55+
<AutoLink :config="autoLinkConfig">
56+
default 插槽
57+
</AutoLink>
58+
59+
<AutoLink :config="autoLinkConfig">
60+
<template #before>before 插槽</template>
61+
<template #after>after 插槽</template>
62+
</AutoLink>
63+
64+
<AutoLink :config="autoLinkConfig">
65+
<template v-slot="config">{{ config.text }}</template>
66+
</AutoLink>
67+
68+
<AutoLink :config="autoLinkConfig">
69+
<template #before="config">{{ config.text }}</template>
70+
</AutoLink>
71+
```
72+
73+
- 详情:
74+
75+
该组件将会自动将内部链接渲染为 `<RouteLink>` ,将外部链接渲染为 `<a>` ,并添加必要的属性。
76+
77+
你可以通过 `before``after` 插槽,在文本之前和之后渲染内容。也可以通过 `default` 插槽,直接渲染文本(默认文本是 `config.text`)。
78+
79+
该组件主要是为了开发主题时使用,普通用户在绝大多数情况下并不会用到它。对于主题作者来说,我们建议你在不确定链接是内部链接还是外部链接时,尽量使用这个组件。
80+
381
## ClientOnly
482

583
- 使用:
@@ -73,4 +151,4 @@
73151

74152
如果 `active` Prop 被设置为 `true` ,那么这个链接会被额外添加一个 `activeClass` 类名。需要注意的是,这里的 active 状态并不会根据当前路由自动更新。
75153

76-
该组件主要是为了开发主题时使用。在绝大多数情况下你不会用到它。对于主题作者来说,我们建议你尽可能使用这个组件,而不是使用 `vue-router``<RouterLink>` 组件。
154+
该组件主要是为了开发主题时使用,普通用户在绝大多数情况下并不会用到它。对于主题作者来说,我们建议你在渲染内部链接时尽量使用这个组件,而不是使用 `vue-router``<RouterLink>` 组件。

0 commit comments

Comments
 (0)