Skip to content

Commit 93a18b0

Browse files
authored
docs(auto-tip): [directives] updateauto-tip and highlight-query docs and demos (#2406)
* fix(auto-tip): add auto-tip demo and description * docs(highlightQuery): update highlightQuery's docs * fix(highlightQuery): fix e2e test
1 parent bd087b8 commit 93a18b0

File tree

8 files changed

+100
-37
lines changed

8 files changed

+100
-37
lines changed

examples/sites/demos/pc/app/directives/auto-tip/always-show-composition-api.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,33 @@
88
is_disabled: item.disabled,
99
list: true
1010
}"
11-
v-auto-tip="item.disabled ? { always: true, content: item.tip } : false"
11+
v-auto-tip="item.disabled ? { always: true, content: item.disabledReason, effect: 'dark' } : false"
1212
>
1313
{{ item.text }}
1414
</div>
1515
</div>
1616
</template>
1717

18-
<script setup>
18+
<script setup lang="jsx">
1919
import { AutoTip } from '@opentiny/vue-directive'
2020
2121
const VAutoTip = AutoTip
2222
2323
const options = [
2424
{ text: '去游泳馆游泳', disabled: false },
25-
{ text: '去羽毛球馆打羽毛球', disabled: true, tip: '自定义提示内容' }
25+
{ text: '去羽毛球馆打羽毛球', disabled: true, disabledReason: '羽毛球拍坏了' },
26+
{
27+
text: '去爬山/海边沙滩',
28+
disabled: true,
29+
disabledReason: (
30+
<span>
31+
还没有选择项目,现在去{' '}
32+
<a href="javascript:void(0)" style="color:#f80">
33+
选择
34+
</a>
35+
</span>
36+
)
37+
}
2638
]
2739
</script>
2840

@@ -41,5 +53,6 @@ const options = [
4153
}
4254
.is_disabled {
4355
cursor: not-allowed;
56+
text-decoration: line-through;
4457
}
4558
</style>

examples/sites/demos/pc/app/directives/auto-tip/always-show.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ test('常显提示', async ({ page }) => {
55
await page.goto('directives-auto-tip#auto-tip-always-show')
66

77
await page.getByText('去游泳馆游泳').hover()
8-
await expect(page.getByRole('tooltip', { name: '自定义提示内容' })).not.toBeVisible()
8+
await expect(page.getByRole('tooltip', { name: '羽毛球拍坏了' })).not.toBeVisible()
99

1010
await page.getByText('去羽毛球馆打羽毛球').hover()
11-
await expect(page.getByRole('tooltip', { name: '自定义提示内容' })).toBeVisible()
11+
await expect(page.getByRole('tooltip', { name: '羽毛球拍坏了' })).toBeVisible()
1212
})

examples/sites/demos/pc/app/directives/auto-tip/always-show.vue

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@
88
is_disabled: item.disabled,
99
list: true
1010
}"
11-
v-auto-tip="item.disabled ? { always: true, content: item.tip } : false"
11+
v-auto-tip="item.disabled ? { always: true, content: item.disabledReason, effect: 'dark' } : false"
1212
>
1313
{{ item.text }}
1414
</div>
1515
</div>
1616
</template>
1717

18-
<script>
18+
<script lang="jsx">
1919
import { AutoTip } from '@opentiny/vue-directive'
2020
2121
export default {
@@ -24,7 +24,19 @@ export default {
2424
return {
2525
options: [
2626
{ text: '去游泳馆游泳', disabled: false },
27-
{ text: '去羽毛球馆打羽毛球', disabled: true, tip: '自定义提示内容' }
27+
{ text: '去羽毛球馆打羽毛球', disabled: true, disabledReason: '羽毛球拍坏了' },
28+
{
29+
text: '去爬山/海边沙滩',
30+
disabled: true,
31+
disabledReason: (
32+
<span>
33+
还没有选择项目,现在去
34+
<a href="javascript:void(0)" style="color:#f80">
35+
选择
36+
</a>
37+
</span>
38+
)
39+
}
2840
]
2941
}
3042
}
@@ -46,5 +58,6 @@ export default {
4658
}
4759
.is_disabled {
4860
cursor: not-allowed;
61+
text-decoration: line-through;
4962
}
5063
</style>

examples/sites/demos/pc/app/directives/highlight-query/avoid-composition-api.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
<div>
33
<div>
44
关键字:<tiny-input v-model="query" placeholder="输入关键字,观察下面的高亮"></tiny-input> &nbsp;
5-
<tiny-button @click="changeList">修改内容</tiny-button>
5+
<tiny-button @click="changeList">修改诗的内容</tiny-button>
66
</div>
77

8-
<div>避免场景1: 直接包含文字节点</div>
8+
<div class="title">避免场景1: 直接包含文字节点,无法动态更新</div>
99
<div v-highlight-query="query">
1010
{{ list.join(',') }}
1111
</div>
1212
<br />
13-
<div>避免场景2:文字节点与其它组件混合</div>
13+
<div class="title">避免场景2:文字节点与其它组件混合,无法动态更新</div>
1414
<div v-highlight-query="query">
1515
{{ list.join(',') }}
16-
<tiny-input></tiny-input>
16+
<tiny-button>混入的按钮</tiny-button>
1717
</div>
1818
<br />
19-
<div>正确的场景1</div>
19+
<div class="title">正确的场景1</div>
2020
<div v-highlight-query="query">
2121
<span> {{ list.join(',') }}</span>
2222
</div>
2323
<br />
24-
<div>正确的场景2</div>
24+
<div class="title">正确的场景2</div>
2525
<div v-highlight-query="query">
2626
<span> {{ list.join(',') }}</span>
27-
<tiny-input></tiny-input>
27+
<tiny-button>混入的按钮</tiny-button>
2828
</div>
2929
</div>
3030
</template>
@@ -51,4 +51,13 @@ const changeList = () => (list.value = ['江上一笼统', '井上黑窟窿', '
5151
div {
5252
line-height: 2;
5353
}
54+
55+
.title {
56+
font-size: 18px;
57+
font-weight: bold;
58+
}
59+
60+
.tiny-button {
61+
margin-left: 20px;
62+
}
5463
</style>

examples/sites/demos/pc/app/directives/highlight-query/avoid.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ test('避免用法', async ({ page }) => {
44
page.on('pageerror', (exception) => expect(exception).toBeNull())
55
await page.goto('directives-highlight-query#avoid')
66

7-
const input = page.locator('.pc-demo-container .tiny-input-inner').first()
87
const hlNode = page.locator('.pc-demo-container .tiny-hl-query-node')
9-
const button = page.locator('.pc-demo-container .tiny-button')
8+
const button = page.locator('.pc-demo-container .tiny-button').first()
109

1110
await expect(hlNode).toHaveCount(12)
1211

examples/sites/demos/pc/app/directives/highlight-query/avoid.vue

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,29 @@
22
<div>
33
<div>
44
关键字:<tiny-input v-model="query" placeholder="输入关键字,观察下面的高亮"></tiny-input> &nbsp;
5-
<tiny-button @click="changeList">修改内容</tiny-button>
5+
<tiny-button @click="changeList">修改诗的内容</tiny-button>
66
</div>
77

8-
<div>避免场景1: 直接包含文字节点</div>
8+
<div class="title">避免场景1: 直接包含文字节点,无法动态更新</div>
99
<div v-highlight-query="query">
1010
{{ list.join(',') }}
1111
</div>
1212
<br />
13-
<div>避免场景2:文字节点与其它组件混合</div>
13+
<div class="title">避免场景2:文字节点与其它组件混合,无法动态更新</div>
1414
<div v-highlight-query="query">
1515
{{ list.join(',') }}
16-
<tiny-input></tiny-input>
16+
<tiny-button>混入的按钮</tiny-button>
1717
</div>
1818
<br />
19-
<div>正确的场景1</div>
19+
<div class="title">正确的场景1</div>
2020
<div v-highlight-query="query">
2121
<span> {{ list.join(',') }}</span>
2222
</div>
2323
<br />
24-
<div>正确的场景2</div>
24+
<div class="title">正确的场景2</div>
2525
<div v-highlight-query="query">
2626
<span> {{ list.join(',') }}</span>
27-
<tiny-input></tiny-input>
27+
<tiny-button>混入的按钮</tiny-button>
2828
</div>
2929
</div>
3030
</template>
@@ -62,4 +62,13 @@ export default {
6262
div {
6363
line-height: 2;
6464
}
65+
66+
.title {
67+
font-size: 18px;
68+
font-weight: bold;
69+
}
70+
71+
.tiny-button {
72+
margin-left: 20px;
73+
}
6574
</style>

examples/sites/demos/pc/app/directives/webdoc/directives-auto-tip.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@ export default {
1212
'en-US': 'Basic Usage'
1313
},
1414
desc: {
15-
'zh-CN':
16-
'通过配置 <code>v-auto-tip</code> 自定义指令可以在鼠标移入时自动添加tip提示,注意:需要用户自己写超出省略隐藏相关样式。',
17-
'en-US':
18-
'You can configure the <code>v-auto-tip</code> custom command to automatically add a tip when you move the cursor. Note: You need to write the style beyond or omit to hide the style.'
15+
'zh-CN': `
16+
通过 <code>v-auto-tip</code> 自定义指令,可以在鼠标移入<code>Dom</code>元素时探测文本是否超长,当超长时自动添加<code>tooltip</code>提示。
17+
<div class="tip custom-block">
18+
需要用户给<code>Dom</code>元素添加超出省略的样式,详见示例!
19+
</div>
20+
`,
21+
'en-US': `
22+
With the <code>v-auto-tip</code> custom command, you can detect if the text is too long when the mouse moves over the <code>Dom</code> element, and automatically add a <code>tooltip</code> prompt when it is too long.
23+
<div class="tip custom-block">
24+
Requires the user to add more than omitted styles to the <code>Dom</code> element, see the example!
25+
</div>
26+
`
1927
},
2028
codeFiles: ['auto-tip/basic-usage.vue']
2129
},
@@ -27,14 +35,26 @@ export default {
2735
},
2836
desc: {
2937
'zh-CN': `
30-
通过配置 <code>v-auto-tip</code> 自定义指令的值可以分为以下两种情况:
31-
<p>如果配置为 <code>{ always: true, content: '自定义内容', effect: 'dark' }</code> ,<code>always: true</code> 可以正常触发提示无论是否超出隐藏省略;<code>content</code> 可以定义提示内容;<code>effect</code> 可以配置主题,可选值有: <code>light</code> 和 <code>dark</code> ,默认是亮色主题。</p>
32-
<p>如果配置为 <code>false</code> 则不处理任何 <code>tip</code> 相关逻辑。</p>
38+
指令 <code>v-auto-tip</code> 可以接收一个指令参数,用法如下: <br>
39+
1、如果参数为对象,其类型声明为<code>{always:boolean; content:string | VNode | Vnode[]; effect: string; placement: string }</code> <br>
40+
<ul>
41+
<li><code>always</code>属性,指定显示方式。 值为<code>true</code>时,表示无论内容是否超长,都自动显示<code>tooltip</code>。 默认值为<code>false</code>, 表示自动探测超长。 </li>
42+
<li><code>content</code>属性,指定提示的内容,支持传入<code>string</code>,<code>VNode</code> 或<code>VNode数组</code>。不传入值时,使用当前<code>Dom</code>元素的内容。 </li>
43+
<li><code>effect</code> 属性,指定提示的效果,支持 <code>light</code> 和 <code>dark</code> ,默认是<code>light</code>亮色主题 </li>
44+
<li><code>placement</code> 属性,指定提示的位置,默认值为<code>top</code> 。参见<code>tooltip</code> 组件的<code>placement</code> 属性。 </li>
45+
</ul>
46+
2、如果参数为 <code>false</code>,表示禁止自动提示。 <br>
3347
`,
3448
'en-US': `
35-
You can configure <code>v-auto-tip</code> to customize the command value to:
36-
<p>If this parameter is set to {always: true, content:'customized content'}</code> ,<code>always: true</code>, the prompt is displayed long regardless of whether the value exceeds the threshold or not. <code>content</code> can define the prompt content. </p>
37-
<p>If this parameter is set to <code>false</code>, no <code>tip</code> logic is processed. </p>
49+
The <code>v-auto-tip</code> command can receive an instruction parameter as follows: <br>
50+
1. If the parameter is an object, its type is declared as <code>{always:boolean; content:string | VNode | Vnode[]; effect: string; placement: string }</code> <br>
51+
<ul>
52+
<li><code>always</code> property specifies the display mode. If the value is <code>true</code>, the <code>tooltip</code> is automatically displayed regardless of whether the content is too long. The default value is <code>false</code>, indicating that the automatic detection length is too long. </li>
53+
<li><code>content</code> property specifies the content of the prompt, which can be passed to <code>string</code>, <code>VNode</code>, or the <code>VNode array </code>. When no value is passed, the contents of the current <code>Dom</code> element are used. </li>
54+
<li><code>effect</code> property, specify the effect of the prompt, support <code>light</code> and <code>dark</code>, default is <code>light</code> bright color theme </li>
55+
<li><code>placement</code> property specifies the placement of the tip. The default value is <code>top</code>. See the <code>placement</code> property of the <code>tooltip</code> component. </li>
56+
</ul>
57+
2. If the parameter is <code>false</code>, the automatic prompt is disabled. <br>
3858
`
3959
},
4060
codeFiles: ['auto-tip/always-show.vue']

examples/sites/demos/pc/app/directives/webdoc/directives-highlight-query.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export default {
1212
'en-US': 'Basic Usage'
1313
},
1414
desc: {
15-
'zh-CN': '通过自动高亮搜索字指令,可以自动高亮某个节点下,所有匹配的字符。',
15+
'zh-CN': '通过自动高亮搜索字指令,可以自动搜索某个<code>Dom</code>元素内所有匹配的字符,将其高亮。',
1616
'en-US':
17-
'You can use the automatic highlight search word command to automatically highlight all matched characters under a node.'
17+
'With the Auto Highlight search word command, you can automatically search for all matching characters in a <code>Dom</code> element and highlight them.'
1818
},
1919
codeFiles: ['highlight-query/basic-usage.vue']
2020
},
@@ -26,7 +26,7 @@ export default {
2626
},
2727
desc: {
2828
'zh-CN':
29-
'纯文字节点在<code>Vue</code> 编译时有特殊处理。自动高亮搜索字的指令是直接处理<code>Dom</code>节点的内容,所以要避免纯文本节点。以下2个场景会造成<code>Vue</code> 更新机制失败。',
29+
'纯文字节点在<code>Vue</code> 编译时有特殊处理。自动高亮搜索字的指令是直接操作<code>Dom</code>节点的内容,所以要避免纯文本节点。以下2个场景会造成<code>Vue</code> 更新机制失败。',
3030
'en-US':
3131
'Plain text nodes are specially processed during <code>Vue</code> compilation. The instruction for automatically highlighting search words is to directly process the contents of the <code>Dom</code> node, so avoid plain text nodes. The <code>Vue</code> update mechanism fails in the following scenarios:'
3232
},

0 commit comments

Comments
 (0)