@king-design/intact 3.5.2 → 3.6.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/components/.DS_Store +0 -0
- package/components/button/index.md +1 -0
- package/components/cascader/index.spec.ts +7 -6
- package/components/datepicker/basepicker.ts +26 -267
- package/components/datepicker/calendar.ts +8 -2
- package/components/datepicker/calendar.vdt +23 -6
- package/components/datepicker/dayjs.ts +8 -2
- package/components/datepicker/demos/multiple.md +1 -1
- package/components/datepicker/demos/yearMonth.md +1 -1
- package/components/datepicker/helpers.ts +10 -12
- package/components/datepicker/index.md +2 -2
- package/components/datepicker/index.spec.ts +619 -190
- package/components/datepicker/index.ts +22 -21
- package/components/datepicker/index.vdt +47 -42
- package/components/datepicker/shortcuts.ts +1 -1
- package/components/datepicker/styles.ts +112 -4
- package/components/datepicker/useConfirm.ts +82 -0
- package/components/datepicker/useDisabled.ts +31 -33
- package/components/datepicker/useFormats.ts +10 -4
- package/components/datepicker/useHighlight.ts +81 -0
- package/components/datepicker/useKeyboards.ts +2 -1
- package/components/datepicker/useMergeRange.ts +54 -0
- package/components/datepicker/useMonths.ts +6 -3
- package/components/datepicker/usePanel.ts +19 -19
- package/components/datepicker/useQuarters.ts +47 -0
- package/components/datepicker/useShowDate.ts +14 -3
- package/components/datepicker/useStatus.ts +34 -15
- package/components/datepicker/useValue.ts +41 -39
- package/components/datepicker/useValueBase.ts +309 -0
- package/components/datepicker/useWeeks.ts +58 -0
- package/components/datepicker/useYears.ts +7 -3
- package/components/descriptions/.DS_Store +0 -0
- package/components/dialog/useFixBody.ts +7 -64
- package/components/dropdown/dropdown.ts +5 -4
- package/components/dropdown/index.md +1 -0
- package/components/dropdown/item.ts +1 -1
- package/components/dropdown/useKeyboard.ts +0 -1
- package/components/ellipsis/styles.ts +4 -0
- package/components/form/styles.ts +1 -0
- package/components/input/index.spec.ts +42 -0
- package/components/input/index.ts +8 -0
- package/components/input/index.vdt +3 -4
- package/components/input/useAutoWidth.ts +19 -1
- package/components/menu/.DS_Store +0 -0
- package/components/menu/demos/.DS_Store +0 -0
- package/components/scrollSelect/index.spec.ts +3 -3
- package/components/scrollSelect/useMouseEvents.ts +24 -10
- package/components/select/base.ts +3 -2
- package/components/select/base.vdt +3 -1
- package/components/select/demos/creatable.md +13 -0
- package/components/select/index.md +1 -0
- package/components/select/index.spec.ts +225 -6
- package/components/select/option.ts +10 -1
- package/components/select/select.ts +3 -0
- package/components/select/styles.ts +3 -1
- package/components/select/useFilterable.ts +1 -1
- package/components/select/useInput.ts +7 -9
- package/components/select/useSearchable.ts +2 -2
- package/components/table/.DS_Store +0 -0
- package/components/table/index.spec.ts +69 -1
- package/components/table/useStickyHeader.ts +1 -1
- package/components/timepicker/demos/step.md +1 -1
- package/components/timepicker/index.spec.ts +145 -27
- package/components/timepicker/panelPicker.ts +10 -4
- package/components/timepicker/panelPicker.vdt +5 -3
- package/components/timepicker/useConfirm.ts +33 -0
- package/components/timepicker/useDefaultValue.ts +30 -0
- package/components/timepicker/useDisabled.ts +17 -4
- package/components/timepicker/useFormats.ts +1 -1
- package/components/timepicker/useValue.ts +22 -19
- package/components/tour/.DS_Store +0 -0
- package/components/tour/demos/basic.md +73 -0
- package/components/tour/demos/beforeChange.md +109 -0
- package/components/tour/demos/closable.md +70 -0
- package/components/tour/demos/custom.md +98 -0
- package/components/tour/demos/customText.md +94 -0
- package/components/tour/demos/declarative.md +72 -0
- package/components/tour/demos/events.md +101 -0
- package/components/tour/demos/maskClosable.md +76 -0
- package/components/tour/demos/notarget.md +59 -0
- package/components/tour/index.md +48 -0
- package/components/tour/index.spec.ts +259 -0
- package/components/tour/index.ts +2 -0
- package/components/tour/step.ts +55 -0
- package/components/tour/step.vdt +75 -0
- package/components/tour/styles.ts +283 -0
- package/components/tour/tour.ts +107 -0
- package/components/tour/tour.vdt +83 -0
- package/components/tour/useArrow.ts +46 -0
- package/components/tour/useFixBody.ts +22 -0
- package/components/tour/useHighlight.ts +36 -0
- package/components/tour/useMaskClosable.ts +26 -0
- package/components/tour/useNavigation.ts +46 -0
- package/components/tour/usePosition.ts +91 -0
- package/components/tour/useSteps.ts +80 -0
- package/components/virtualList/.DS_Store +0 -0
- package/components/virtualList/demos/.DS_Store +0 -0
- package/es/components/cascader/index.spec.js +18 -19
- package/es/components/datepicker/basepicker.d.ts +6 -25
- package/es/components/datepicker/basepicker.js +22 -234
- package/es/components/datepicker/calendar.d.ts +36 -6
- package/es/components/datepicker/calendar.js +4 -0
- package/es/components/datepicker/calendar.vdt.js +21 -5
- package/es/components/datepicker/dayjs.d.ts +2 -2
- package/es/components/datepicker/dayjs.js +6 -0
- package/es/components/datepicker/helpers.d.ts +8 -7
- package/es/components/datepicker/helpers.js +2 -3
- package/es/components/datepicker/index.d.ts +26 -19
- package/es/components/datepicker/index.js +21 -13
- package/es/components/datepicker/index.spec.js +1389 -633
- package/es/components/datepicker/index.vdt.js +43 -46
- package/es/components/datepicker/shortcuts.d.ts +1 -1
- package/es/components/datepicker/styles.d.ts +22 -0
- package/es/components/datepicker/styles.js +26 -4
- package/es/components/datepicker/useConfirm.d.ts +6 -0
- package/es/components/datepicker/useConfirm.js +65 -0
- package/es/components/datepicker/useDisabled.d.ts +7 -5
- package/es/components/datepicker/useDisabled.js +22 -27
- package/es/components/datepicker/useFormats.d.ts +2 -2
- package/es/components/datepicker/useFormats.js +9 -3
- package/es/components/datepicker/useHighlight.d.ts +14 -0
- package/es/components/datepicker/useHighlight.js +60 -0
- package/es/components/datepicker/useKeyboards.js +2 -1
- package/es/components/datepicker/useMergeRange.d.ts +5 -0
- package/es/components/datepicker/useMergeRange.js +45 -0
- package/es/components/datepicker/useMonths.js +5 -3
- package/es/components/datepicker/usePanel.d.ts +1 -10
- package/es/components/datepicker/usePanel.js +19 -32
- package/es/components/datepicker/useQuarters.d.ts +15 -0
- package/es/components/datepicker/useQuarters.js +36 -0
- package/es/components/datepicker/useShowDate.js +10 -2
- package/es/components/datepicker/useStatus.d.ts +1 -1
- package/es/components/datepicker/useStatus.js +33 -16
- package/es/components/datepicker/useValue.d.ts +12 -6
- package/es/components/datepicker/useValue.js +49 -45
- package/es/components/datepicker/useValueBase.d.ts +28 -0
- package/es/components/datepicker/useValueBase.js +277 -0
- package/es/components/datepicker/useWeeks.d.ts +19 -0
- package/es/components/datepicker/useWeeks.js +48 -0
- package/es/components/datepicker/useYears.js +6 -3
- package/es/components/dialog/useFixBody.js +6 -58
- package/es/components/dropdown/dropdown.d.ts +1 -0
- package/es/components/dropdown/dropdown.js +7 -4
- package/es/components/ellipsis/styles.js +1 -1
- package/es/components/form/styles.js +1 -1
- package/es/components/input/index.d.ts +2 -0
- package/es/components/input/index.js +6 -0
- package/es/components/input/index.spec.js +45 -0
- package/es/components/input/index.vdt.js +4 -3
- package/es/components/input/useAutoWidth.d.ts +2 -0
- package/es/components/input/useAutoWidth.js +19 -1
- package/es/components/scrollSelect/index.spec.js +4 -6
- package/es/components/scrollSelect/useMouseEvents.js +22 -9
- package/es/components/select/base.d.ts +1 -1
- package/es/components/select/base.js +3 -2
- package/es/components/select/base.vdt.js +5 -2
- package/es/components/select/index.spec.js +329 -82
- package/es/components/select/option.d.ts +1 -0
- package/es/components/select/option.js +10 -2
- package/es/components/select/select.d.ts +1 -0
- package/es/components/select/select.js +4 -2
- package/es/components/select/styles.d.ts +79 -0
- package/es/components/select/styles.js +1 -0
- package/es/components/select/useFilterable.js +2 -1
- package/es/components/select/useInput.d.ts +1 -1
- package/es/components/select/useInput.js +7 -4
- package/es/components/select/useSearchable.js +1 -0
- package/es/components/table/index.spec.js +84 -6
- package/es/components/table/useStickyHeader.js +1 -1
- package/es/components/timepicker/index.spec.js +298 -128
- package/es/components/timepicker/panelPicker.d.ts +23 -17
- package/es/components/timepicker/panelPicker.js +7 -4
- package/es/components/timepicker/panelPicker.vdt.js +8 -4
- package/es/components/timepicker/selectPicker.d.ts +5 -4
- package/es/components/timepicker/useConfirm.d.ts +6 -0
- package/es/components/timepicker/useConfirm.js +19 -0
- package/es/components/timepicker/useDefaultValue.d.ts +4 -0
- package/es/components/timepicker/useDefaultValue.js +27 -0
- package/es/components/timepicker/useDisabled.d.ts +7 -4
- package/es/components/timepicker/useDisabled.js +13 -4
- package/es/components/timepicker/useFormats.d.ts +1 -1
- package/es/components/timepicker/useValue.d.ts +14 -8
- package/es/components/timepicker/useValue.js +14 -15
- package/es/components/tour/index.d.ts +2 -0
- package/es/components/tour/index.js +2 -0
- package/es/components/tour/index.spec.d.ts +1 -0
- package/es/components/tour/index.spec.js +356 -0
- package/es/components/tour/step.d.ts +23 -0
- package/es/components/tour/step.js +46 -0
- package/es/components/tour/step.vdt.js +74 -0
- package/es/components/tour/styles.d.ts +7 -0
- package/es/components/tour/styles.js +84 -0
- package/es/components/tour/tour.d.ts +73 -0
- package/es/components/tour/tour.js +70 -0
- package/es/components/tour/tour.vdt.js +66 -0
- package/es/components/tour/useArrow.d.ts +4 -0
- package/es/components/tour/useArrow.js +40 -0
- package/es/components/tour/useFixBody.d.ts +4 -0
- package/es/components/tour/useFixBody.js +17 -0
- package/es/components/tour/useHighlight.d.ts +4 -0
- package/es/components/tour/useHighlight.js +31 -0
- package/es/components/tour/useMaskClosable.d.ts +1 -0
- package/es/components/tour/useMaskClosable.js +25 -0
- package/es/components/tour/useNavigation.d.ts +5 -0
- package/es/components/tour/useNavigation.js +103 -0
- package/es/components/tour/usePosition.d.ts +6 -0
- package/es/components/tour/usePosition.js +93 -0
- package/es/components/tour/useSteps.d.ts +6 -0
- package/es/components/tour/useSteps.js +68 -0
- package/es/hooks/useFixBody.d.ts +11 -0
- package/es/hooks/useFixBody.js +72 -0
- package/es/index.d.ts +3 -2
- package/es/index.js +3 -2
- package/es/site/data/components/datepicker/demos/multiple/react.js +2 -2
- package/es/site/data/components/select/demos/creatable/index.d.ts +1 -0
- package/es/site/data/components/select/demos/creatable/index.js +2 -1
- package/es/site/data/components/select/demos/creatable/react.d.ts +1 -0
- package/es/site/data/components/select/demos/creatable/react.js +31 -2
- package/es/site/data/components/tour/demos/basic/index.d.ts +17 -0
- package/es/site/data/components/tour/demos/basic/index.js +46 -0
- package/es/site/data/components/tour/demos/basic/react.d.ts +16 -0
- package/es/site/data/components/tour/demos/basic/react.js +82 -0
- package/es/site/data/components/tour/demos/beforeChange/index.d.ts +20 -0
- package/es/site/data/components/tour/demos/beforeChange/index.js +69 -0
- package/es/site/data/components/tour/demos/beforeChange/react.d.ts +19 -0
- package/es/site/data/components/tour/demos/beforeChange/react.js +129 -0
- package/es/site/data/components/tour/demos/closable/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/closable/index.js +42 -0
- package/es/site/data/components/tour/demos/closable/react.d.ts +17 -0
- package/es/site/data/components/tour/demos/closable/react.js +85 -0
- package/es/site/data/components/tour/demos/custom/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/custom/index.js +35 -0
- package/es/site/data/components/tour/demos/custom/react.d.ts +11 -0
- package/es/site/data/components/tour/demos/custom/react.js +108 -0
- package/es/site/data/components/tour/demos/customText/index.d.ts +33 -0
- package/es/site/data/components/tour/demos/customText/index.js +55 -0
- package/es/site/data/components/tour/demos/customText/react.d.ts +33 -0
- package/es/site/data/components/tour/demos/customText/react.js +99 -0
- package/es/site/data/components/tour/demos/declarative/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/declarative/index.js +36 -0
- package/es/site/data/components/tour/demos/declarative/react.d.ts +10 -0
- package/es/site/data/components/tour/demos/declarative/react.js +80 -0
- package/es/site/data/components/tour/demos/events/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/events/index.js +58 -0
- package/es/site/data/components/tour/demos/events/react.d.ts +18 -0
- package/es/site/data/components/tour/demos/events/react.js +101 -0
- package/es/site/data/components/tour/demos/maskClosable/index.d.ts +18 -0
- package/es/site/data/components/tour/demos/maskClosable/index.js +47 -0
- package/es/site/data/components/tour/demos/maskClosable/react.d.ts +17 -0
- package/es/site/data/components/tour/demos/maskClosable/react.js +95 -0
- package/es/site/data/components/tour/demos/notarget/index.d.ts +11 -0
- package/es/site/data/components/tour/demos/notarget/index.js +35 -0
- package/es/site/data/components/tour/demos/notarget/react.d.ts +10 -0
- package/es/site/data/components/tour/demos/notarget/react.js +61 -0
- package/es/site/data/components/tour/index.d.ts +57 -0
- package/es/site/data/components/tour/index.js +32 -0
- package/hooks/useFixBody.ts +87 -0
- package/index.ts +3 -2
- package/package.json +2 -2
- package/styles/.DS_Store +0 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: 引导式导航
|
|
3
|
+
category: 组件
|
|
4
|
+
order: 99
|
|
5
|
+
sidebar: doc
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# 属性
|
|
9
|
+
|
|
10
|
+
## Tour
|
|
11
|
+
|
|
12
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
13
|
+
| --- | --- | --- | --- |
|
|
14
|
+
| value | 当前显示的步骤索引,从0开始,可通过`v-model`双向绑定 | `number` | `0` |
|
|
15
|
+
| visible | 是否展示引导组件 | `boolean` | `true` |
|
|
16
|
+
| data | 步骤数据数组,用于数据驱动方式 | `TourStepData[]` | `undefined` |
|
|
17
|
+
| beforeChange | 步骤切换前的回调函数,返回false可阻止切换 | `(current: number) => boolean \| Promise<boolean>` | `undefined` |
|
|
18
|
+
| maskClosable | 点击遮罩层是否可关闭 | `boolean` | `false` |
|
|
19
|
+
| closable | 是否展示关闭图标 | `boolean` | `true` |
|
|
20
|
+
| doneText | 完成按钮文本 | `string` | `"完成"` |
|
|
21
|
+
|
|
22
|
+
## TourStep
|
|
23
|
+
|
|
24
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
25
|
+
| --- | --- | --- | --- |
|
|
26
|
+
| target | 目标元素,可以是CSS选择器或DOM元素 | `string \| HTMLElement` | `undefined` |
|
|
27
|
+
| title | 步骤标题 | `string \| VNode` | `undefined` |
|
|
28
|
+
| content | 步骤内容 | `string \| VNode` | `undefined` |
|
|
29
|
+
| nextText | 下一步按钮文本 | `string` | `"下一步"` |
|
|
30
|
+
| prevText | 上一步按钮文本 | `string` | `"上一步"` |
|
|
31
|
+
| position | 弹出位置,可选值:`top`、`right`、`bottom`、`left` | `string` | `"bottom"` |
|
|
32
|
+
|
|
33
|
+
# 事件
|
|
34
|
+
|
|
35
|
+
| 事件名 | 说明 | 参数 |
|
|
36
|
+
| --- | --- | --- |
|
|
37
|
+
| prev | 点击上一步按钮时触发 | `(index: number)` |
|
|
38
|
+
| next | 点击下一步按钮时触发 | `(index: number)` |
|
|
39
|
+
| finish | 引导完成时触发 | - |
|
|
40
|
+
|
|
41
|
+
# 扩展点
|
|
42
|
+
|
|
43
|
+
## TourStep
|
|
44
|
+
|
|
45
|
+
| 名称 | 说明 |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| title | 自定义标题内容 |
|
|
48
|
+
| footer | 自定义底部内容 |
|
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { Component } from 'intact';
|
|
2
|
+
import BasicDemo from '~/components/tour/demos/basic';
|
|
3
|
+
import DeclarativeDemo from '~/components/tour/demos/declarative';
|
|
4
|
+
import ClosableDemo from '~/components/tour/demos/closable';
|
|
5
|
+
import CustomTextDemo from '~/components/tour/demos/customText';
|
|
6
|
+
import BeforeChangeDemo from '~/components/tour/demos/beforeChange';
|
|
7
|
+
import EventsDemo from '~/components/tour/demos/events';
|
|
8
|
+
import MaskClosableDemo from '~/components/tour/demos/maskClosable';
|
|
9
|
+
import NotargetDemo from '~/components/tour/demos/notarget';
|
|
10
|
+
import { mount, unmount, dispatchEvent, getElement, wait } from '../../test/utils';
|
|
11
|
+
import { Tour, TourStep } from './';
|
|
12
|
+
|
|
13
|
+
describe('Tour', () => {
|
|
14
|
+
afterEach(() => {unmount()});
|
|
15
|
+
|
|
16
|
+
it('should show and hide tour correctly', async () => {
|
|
17
|
+
const [instance, element] = mount(BasicDemo);
|
|
18
|
+
|
|
19
|
+
let tourContent = getElement('.k-tour-step');
|
|
20
|
+
expect(tourContent).to.be.undefined;
|
|
21
|
+
|
|
22
|
+
const buttons = element.querySelectorAll('.k-btn');
|
|
23
|
+
const startBtn = Array.from(buttons).find(btn => btn.textContent?.includes('启动引导')) as HTMLElement;
|
|
24
|
+
startBtn.click();
|
|
25
|
+
await wait();
|
|
26
|
+
|
|
27
|
+
tourContent = getElement('.k-tour-step');
|
|
28
|
+
expect(tourContent).to.exist;
|
|
29
|
+
|
|
30
|
+
expect(tourContent!.querySelector('.k-tour-step-title')!.textContent).to.eql('第一步');
|
|
31
|
+
|
|
32
|
+
const indicator = tourContent!.querySelector('.k-tour-step-indicator');
|
|
33
|
+
expect(indicator!.textContent!.trim()).to.eql('1 / 2');
|
|
34
|
+
|
|
35
|
+
const nextBtn = tourContent!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
36
|
+
nextBtn.click();
|
|
37
|
+
await wait();
|
|
38
|
+
|
|
39
|
+
const updatedContent = getElement('.k-tour-step');
|
|
40
|
+
expect(updatedContent!.querySelector('.k-tour-step-title')!.textContent).to.eql('第二步');
|
|
41
|
+
|
|
42
|
+
const doneBtn = updatedContent!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
43
|
+
doneBtn.click();
|
|
44
|
+
await wait();
|
|
45
|
+
|
|
46
|
+
expect(getElement('.k-tour-step')).to.be.undefined;
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should work with declarative TourStep components', async () => {
|
|
50
|
+
const [instance, element] = mount(DeclarativeDemo);
|
|
51
|
+
|
|
52
|
+
const buttons = element.querySelectorAll('.k-btn');
|
|
53
|
+
const startBtn = Array.from(buttons).find(btn => btn.textContent?.includes('启动引导')) as HTMLElement;
|
|
54
|
+
startBtn.click();
|
|
55
|
+
await wait(50);
|
|
56
|
+
|
|
57
|
+
const tourContent = getElement('.k-tour-step');
|
|
58
|
+
expect(tourContent).to.exist;
|
|
59
|
+
|
|
60
|
+
expect(tourContent!.querySelector('.k-tour-step-title')!.textContent).to.eql('第一步');
|
|
61
|
+
expect(tourContent!.querySelector('.k-tour-step-body')!.textContent).to.include('子组件方式的第一步');
|
|
62
|
+
|
|
63
|
+
const nextBtn = tourContent!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
64
|
+
nextBtn.click();
|
|
65
|
+
await wait(50);
|
|
66
|
+
|
|
67
|
+
const updatedContent = getElement('.k-tour-step');
|
|
68
|
+
expect(updatedContent!.querySelector('.k-tour-step-title')!.textContent).to.eql('第二步');
|
|
69
|
+
expect(updatedContent!.querySelector('.k-tour-step-body')!.textContent).to.include('子组件方式的第二步');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should handle closable property correctly', async () => {
|
|
73
|
+
const [instance, element] = mount(ClosableDemo);
|
|
74
|
+
|
|
75
|
+
const buttons = element.querySelectorAll('.k-btn');
|
|
76
|
+
const startBtn = Array.from(buttons).find(btn => btn.textContent?.includes('启动引导')) as HTMLElement;
|
|
77
|
+
startBtn.click();
|
|
78
|
+
await wait(50);
|
|
79
|
+
|
|
80
|
+
(instance as any).set('closable', true);
|
|
81
|
+
await wait(50);
|
|
82
|
+
const tourContent = getElement('.k-tour-step');
|
|
83
|
+
expect(tourContent).to.exist;
|
|
84
|
+
|
|
85
|
+
const closeIcon = tourContent!.querySelector('.k-tour-step-close');
|
|
86
|
+
expect(closeIcon).to.be.null;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('should handle beforeChange correctly', async () => {
|
|
90
|
+
const [instance, element] = mount(BeforeChangeDemo);
|
|
91
|
+
|
|
92
|
+
const buttons = element.querySelectorAll('.k-btn');
|
|
93
|
+
const startBtn = Array.from(buttons).find(btn => btn.textContent?.includes('启动引导')) as HTMLElement;
|
|
94
|
+
startBtn.click();
|
|
95
|
+
await wait();
|
|
96
|
+
|
|
97
|
+
expect((instance as any).get('currentStep')).to.eql(0);
|
|
98
|
+
|
|
99
|
+
let tourContent = getElement('.k-tour-step');
|
|
100
|
+
let nextBtn = tourContent!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
101
|
+
nextBtn.click();
|
|
102
|
+
await wait();
|
|
103
|
+
|
|
104
|
+
expect((instance as any).get('currentStep')).to.eql(1);
|
|
105
|
+
|
|
106
|
+
tourContent = getElement('.k-tour-step');
|
|
107
|
+
nextBtn = tourContent!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
108
|
+
nextBtn.click();
|
|
109
|
+
await wait();
|
|
110
|
+
|
|
111
|
+
expect((instance as any).get('currentStep')).to.eql(2);
|
|
112
|
+
|
|
113
|
+
tourContent = getElement('.k-tour-step');
|
|
114
|
+
nextBtn = tourContent!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
115
|
+
nextBtn.click();
|
|
116
|
+
await wait();
|
|
117
|
+
|
|
118
|
+
const input = element.querySelector('.step3-input .k-input-inner') as HTMLInputElement;
|
|
119
|
+
input.value = 'next';
|
|
120
|
+
dispatchEvent(input, 'input');
|
|
121
|
+
await wait();
|
|
122
|
+
|
|
123
|
+
tourContent = getElement('.k-tour-step');
|
|
124
|
+
nextBtn = tourContent!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
125
|
+
nextBtn.click();
|
|
126
|
+
await wait();
|
|
127
|
+
console.log('currentStep', (instance as any).get('currentStep'));
|
|
128
|
+
expect((instance as any).get('currentStep')).to.eql(3);
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
it('should trigger events correctly', async () => {
|
|
132
|
+
const [instance, element] = mount(EventsDemo);
|
|
133
|
+
|
|
134
|
+
const prevSpy = sinon.spy(instance, 'handlePrev');
|
|
135
|
+
const nextSpy = sinon.spy(instance, 'handleNext');
|
|
136
|
+
const finishSpy = sinon.spy(instance, 'handleFinish');
|
|
137
|
+
|
|
138
|
+
const buttons = element.querySelectorAll('.k-btn');
|
|
139
|
+
const startBtn = Array.from(buttons).find(btn => btn.textContent?.includes('开始引导')) as HTMLElement;
|
|
140
|
+
startBtn.click();
|
|
141
|
+
await wait();
|
|
142
|
+
|
|
143
|
+
const tourContent = getElement('.k-tour-step');
|
|
144
|
+
const nextBtn = tourContent!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
145
|
+
nextBtn.click();
|
|
146
|
+
await wait();
|
|
147
|
+
|
|
148
|
+
expect(nextSpy.callCount).to.eql(1);
|
|
149
|
+
|
|
150
|
+
const prevBtn = getElement('.k-tour-step')!.querySelector('.k-tour-step-buttons .k-btn:not(.k-primary)') as HTMLElement;
|
|
151
|
+
prevBtn.click();
|
|
152
|
+
await wait();
|
|
153
|
+
|
|
154
|
+
expect(prevSpy.callCount).to.eql(1);
|
|
155
|
+
|
|
156
|
+
nextBtn.click();
|
|
157
|
+
await wait();
|
|
158
|
+
nextBtn.click();
|
|
159
|
+
await wait();
|
|
160
|
+
const doneBtn = getElement('.k-tour-step')!.querySelector('.k-tour-step-buttons .k-primary') as HTMLElement;
|
|
161
|
+
doneBtn.click();
|
|
162
|
+
await wait();
|
|
163
|
+
|
|
164
|
+
console.log('finishSpy.callCount', finishSpy.callCount);
|
|
165
|
+
expect(finishSpy.callCount).to.eql(0);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('should handle maskClosable correctly', async () => {
|
|
169
|
+
const [instance, element] = mount(MaskClosableDemo);
|
|
170
|
+
|
|
171
|
+
const buttons = element.querySelectorAll('.k-btn');
|
|
172
|
+
const startBtn = Array.from(buttons).find(btn => btn.textContent?.includes('启动引导')) as HTMLElement;
|
|
173
|
+
startBtn.click();
|
|
174
|
+
await wait(50);
|
|
175
|
+
|
|
176
|
+
const highlight = getElement('.k-tour-target-highlight');
|
|
177
|
+
expect(highlight).to.exist;
|
|
178
|
+
|
|
179
|
+
dispatchEvent(document, 'click');
|
|
180
|
+
await wait(50);
|
|
181
|
+
|
|
182
|
+
expect(getElement('.k-tour-step')).to.be.undefined;
|
|
183
|
+
|
|
184
|
+
startBtn.click();
|
|
185
|
+
await wait(50);
|
|
186
|
+
(instance as any).set('maskClosable', false);
|
|
187
|
+
await wait(50);
|
|
188
|
+
|
|
189
|
+
dispatchEvent(document, 'click');
|
|
190
|
+
await wait(50);
|
|
191
|
+
|
|
192
|
+
expect(getElement('.k-tour-step')).to.exist;
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('should handle custom text correctly', async () => {
|
|
196
|
+
const [instance, element] = mount(CustomTextDemo);
|
|
197
|
+
|
|
198
|
+
const buttons = element.querySelectorAll('.k-btn');
|
|
199
|
+
const startBtn = Array.from(buttons).find(btn => btn.textContent?.includes('开始自定义按钮引导')) as HTMLElement;
|
|
200
|
+
startBtn.click();
|
|
201
|
+
await wait(50);
|
|
202
|
+
|
|
203
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it('should handle target correctly', async () => {
|
|
207
|
+
const [instance, element] = mount(NotargetDemo);
|
|
208
|
+
|
|
209
|
+
const btn = element.querySelector('.k-btn') as HTMLElement;
|
|
210
|
+
btn.click();
|
|
211
|
+
await wait(50);
|
|
212
|
+
|
|
213
|
+
expect(element.innerHTML).to.matchSnapshot();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// it('should handle theme correctly', async () => {
|
|
217
|
+
// interface DemoProps {
|
|
218
|
+
// theme: string;
|
|
219
|
+
// tourData: any[];
|
|
220
|
+
// }
|
|
221
|
+
|
|
222
|
+
// class Demo extends Component<DemoProps> {
|
|
223
|
+
// static template = `
|
|
224
|
+
// const { Tour } = this;
|
|
225
|
+
// <div>
|
|
226
|
+
// <Tour
|
|
227
|
+
// data={this.get('tourData')}
|
|
228
|
+
// visible={true}
|
|
229
|
+
// theme={this.get('theme')}
|
|
230
|
+
// />
|
|
231
|
+
// </div>
|
|
232
|
+
// `;
|
|
233
|
+
// Tour = Tour;
|
|
234
|
+
|
|
235
|
+
// static defaults() {
|
|
236
|
+
// return {
|
|
237
|
+
// theme: 'dark',
|
|
238
|
+
// tourData: [
|
|
239
|
+
// {
|
|
240
|
+
// target: 'body',
|
|
241
|
+
// title: '主题测试',
|
|
242
|
+
// content: '测试深色主题'
|
|
243
|
+
// }
|
|
244
|
+
// ]
|
|
245
|
+
// } as DemoProps;
|
|
246
|
+
// }
|
|
247
|
+
// }
|
|
248
|
+
|
|
249
|
+
// const [instance, element] = mount(Demo);
|
|
250
|
+
// await wait(50);
|
|
251
|
+
|
|
252
|
+
// expect(element.innerHTML).to.matchSnapshot();
|
|
253
|
+
|
|
254
|
+
// instance.set('theme', 'light');
|
|
255
|
+
// await wait(50);
|
|
256
|
+
|
|
257
|
+
// expect(element.innerHTML).to.matchSnapshot();
|
|
258
|
+
// });
|
|
259
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import {Component, TypeDefs, VNode, Children} from 'intact';
|
|
2
|
+
import template from './step.vdt';
|
|
3
|
+
import { useConfigContext } from '../config';
|
|
4
|
+
import type {Events} from '../types';
|
|
5
|
+
|
|
6
|
+
export interface TourStepProps {
|
|
7
|
+
title?: string | VNode;
|
|
8
|
+
content?: Children;
|
|
9
|
+
target?: string | HTMLElement;
|
|
10
|
+
position?: string | any;
|
|
11
|
+
nextText?: string;
|
|
12
|
+
prevText?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TourStepEvents { }
|
|
16
|
+
|
|
17
|
+
export interface TourStepBlocks {
|
|
18
|
+
header: null;
|
|
19
|
+
content: null;
|
|
20
|
+
footer: null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const typeDefs: Required<TypeDefs<TourStepProps>> = {
|
|
24
|
+
title: [String, VNode],
|
|
25
|
+
content: [String, VNode, Array],
|
|
26
|
+
target: [String, Object],
|
|
27
|
+
position: [String, Object],
|
|
28
|
+
nextText: String,
|
|
29
|
+
prevText: String,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const defaults = (): Partial<TourStepProps> => ({
|
|
33
|
+
position: 'bottom',
|
|
34
|
+
nextText: '下一步',
|
|
35
|
+
prevText: '上一步',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export class TourStep extends Component<TourStepProps, TourStepEvents, TourStepBlocks> {
|
|
39
|
+
static template = template;
|
|
40
|
+
static typeDefs = typeDefs;
|
|
41
|
+
static defaults = defaults;
|
|
42
|
+
|
|
43
|
+
private config = useConfigContext();
|
|
44
|
+
|
|
45
|
+
getTarget(): HTMLElement | null {
|
|
46
|
+
const target = this.get('target');
|
|
47
|
+
if (!target) return null;
|
|
48
|
+
|
|
49
|
+
if (typeof target === 'string') {
|
|
50
|
+
return document.querySelector(target);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return target as HTMLElement;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import {Button} from '../button';
|
|
2
|
+
import {Icon} from '../icon';
|
|
3
|
+
import {makeStyles} from './styles';
|
|
4
|
+
import {TourContext} from './tour';
|
|
5
|
+
import {getRestProps} from '../utils';
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
title,
|
|
9
|
+
content,
|
|
10
|
+
className,
|
|
11
|
+
children,
|
|
12
|
+
nextText,
|
|
13
|
+
prevText
|
|
14
|
+
} = this.get();
|
|
15
|
+
|
|
16
|
+
const { k } = this.config;
|
|
17
|
+
|
|
18
|
+
const classNameObj = {
|
|
19
|
+
[`${k}-tour-step`]: true,
|
|
20
|
+
[className]: className,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
<TourContext.Consumer>
|
|
24
|
+
{({value, total, doneText, onPrev, onNext, onFinish, closable}) => {
|
|
25
|
+
const isFirst = value === 0;
|
|
26
|
+
const isLast = value === total - 1;
|
|
27
|
+
const showHeader = !!title;
|
|
28
|
+
const displayIndex = value + 1;
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<div class={classNameObj} {...getRestProps(this)}>
|
|
32
|
+
{/* 头部区域 */}
|
|
33
|
+
<div class={`${k}-tour-step-header`} v-if={!!title || $blocks.header}>
|
|
34
|
+
<div class={`${k}-tour-step-title`}>
|
|
35
|
+
<b:header>{title}</b:header>
|
|
36
|
+
</div>
|
|
37
|
+
<div v-if={!closable} class={`${k}-tour-step-close`} ev-click={onFinish}>
|
|
38
|
+
<Icon class={`${k}-icon-close`} />
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
{/* 内容区域 */}
|
|
43
|
+
<div class={`${k}-tour-step-body`}>
|
|
44
|
+
{ children || content}
|
|
45
|
+
</div>
|
|
46
|
+
|
|
47
|
+
{/* 底部区域 */}
|
|
48
|
+
<div class={`${k}-tour-step-footer`}>
|
|
49
|
+
<b:footer>
|
|
50
|
+
<div class={`${k}-tour-step-indicator`}>
|
|
51
|
+
{displayIndex} / {total}
|
|
52
|
+
</div>
|
|
53
|
+
<div class={`${k}-tour-step-buttons`}>
|
|
54
|
+
<Button
|
|
55
|
+
v-if={!isFirst}
|
|
56
|
+
size="small"
|
|
57
|
+
type="secondary"
|
|
58
|
+
ev-click={onPrev}
|
|
59
|
+
>
|
|
60
|
+
{prevText}
|
|
61
|
+
</Button>
|
|
62
|
+
<Button
|
|
63
|
+
size="small"
|
|
64
|
+
type="primary"
|
|
65
|
+
ev-click={isLast ? onFinish : onNext}
|
|
66
|
+
>
|
|
67
|
+
{isLast ? doneText : nextText}
|
|
68
|
+
</Button>
|
|
69
|
+
</div>
|
|
70
|
+
</b:footer>
|
|
71
|
+
</div>
|
|
72
|
+
</div>
|
|
73
|
+
);
|
|
74
|
+
}}
|
|
75
|
+
</TourContext.Consumer>
|