@tendaui/components 1.0.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/LICENSE +21 -0
- package/README.md +176 -0
- package/alert/Alert.tsx +147 -0
- package/alert/defaultProps.ts +3 -0
- package/alert/index.ts +9 -0
- package/alert/style/css.js +1 -0
- package/alert/style/index.js +1 -0
- package/alert/type.ts +44 -0
- package/badge/Badge.tsx +85 -0
- package/badge/defaultProps.ts +10 -0
- package/badge/index.ts +9 -0
- package/badge/style/css.js +1 -0
- package/badge/style/index.js +1 -0
- package/badge/type.ts +51 -0
- package/button/Button.tsx +95 -0
- package/button/defaultProps.ts +13 -0
- package/button/index.ts +7 -0
- package/button/style/css.js +1 -0
- package/button/style/index.js +1 -0
- package/button/type.ts +82 -0
- package/checkbox/Checkbox.tsx +19 -0
- package/checkbox/CheckboxGroup.tsx +207 -0
- package/checkbox/defaultProps.ts +14 -0
- package/checkbox/index.ts +10 -0
- package/checkbox/style/css.js +1 -0
- package/checkbox/style/index.js +1 -0
- package/checkbox/type.ts +117 -0
- package/common/Check.tsx +131 -0
- package/common/FakeArrow.tsx +36 -0
- package/common/PluginContainer.tsx +21 -0
- package/common/Portal.tsx +67 -0
- package/common.ts +76 -0
- package/config-provider/ConfigContext.tsx +21 -0
- package/config-provider/ConfigProvider.tsx +53 -0
- package/config-provider/index.ts +9 -0
- package/config-provider/type.ts +1062 -0
- package/dialog/Dialog.tsx +254 -0
- package/dialog/DialogCard.tsx +152 -0
- package/dialog/defaultProps.ts +25 -0
- package/dialog/hooks/useDialogDrag.ts +50 -0
- package/dialog/hooks/useDialogEsc.ts +31 -0
- package/dialog/hooks/useDialogPosition.ts +36 -0
- package/dialog/hooks/useLockStyle.ts +54 -0
- package/dialog/index.ts +13 -0
- package/dialog/plugin.tsx +78 -0
- package/dialog/style/css.js +1 -0
- package/dialog/style/index.js +1 -0
- package/dialog/type.ts +241 -0
- package/dialog/utils.ts +4 -0
- package/form/Form.tsx +136 -0
- package/form/FormContext.tsx +64 -0
- package/form/FormItem.tsx +554 -0
- package/form/FormList.tsx +303 -0
- package/form/const.ts +6 -0
- package/form/defaultProps.ts +26 -0
- package/form/formModel.ts +117 -0
- package/form/hooks/interface.ts +20 -0
- package/form/hooks/useForm.ts +122 -0
- package/form/hooks/useFormItemInitialData.ts +95 -0
- package/form/hooks/useFormItemStyle.tsx +122 -0
- package/form/hooks/useInstance.tsx +275 -0
- package/form/hooks/useWatch.ts +42 -0
- package/form/index.ts +11 -0
- package/form/style/css.js +1 -0
- package/form/style/index.js +1 -0
- package/form/type.ts +519 -0
- package/form/utils/index.ts +69 -0
- package/hooks/useAttach.ts +24 -0
- package/hooks/useCommonClassName.ts +45 -0
- package/hooks/useConfig.ts +3 -0
- package/hooks/useControlled.ts +39 -0
- package/hooks/useDefaultProps.ts +16 -0
- package/hooks/useDomCallback.ts +13 -0
- package/hooks/useDomRefCallback.ts +12 -0
- package/hooks/useDragSorter.tsx +151 -0
- package/hooks/useEventCallback.ts +47 -0
- package/hooks/useGlobalConfig.ts +14 -0
- package/hooks/useGlobalIcon.ts +14 -0
- package/hooks/useLastest.ts +13 -0
- package/hooks/useLayoutEffect.ts +7 -0
- package/hooks/useMouseEvent.ts +142 -0
- package/hooks/useMutationObserver.ts +56 -0
- package/hooks/usePopper.ts +189 -0
- package/hooks/useRipple.ts +0 -0
- package/hooks/useSetState.ts +25 -0
- package/hooks/useVirtualScroll.ts +246 -0
- package/hooks/useWindowSize.ts +31 -0
- package/index.ts +70 -0
- package/input/Input.tsx +383 -0
- package/input/InputGroup.tsx +29 -0
- package/input/defaultProps.ts +22 -0
- package/input/index.ts +11 -0
- package/input/style/css.js +1 -0
- package/input/style/index.js +1 -0
- package/input/type.ts +219 -0
- package/loading/Gradient.tsx +36 -0
- package/loading/Loading.tsx +169 -0
- package/loading/circleAdapter.ts +44 -0
- package/loading/defaultProps.ts +12 -0
- package/loading/index.ts +13 -0
- package/loading/style/css.js +1 -0
- package/loading/style/index.js +1 -0
- package/loading/type.ts +71 -0
- package/loading/utils/setStyle.ts +13 -0
- package/myform/index.ts +0 -0
- package/notification/Notify.ts +24 -0
- package/notification/NotifyContainer.tsx +90 -0
- package/notification/NotifyContext.tsx +173 -0
- package/notification/NotifyItem.tsx +121 -0
- package/notification/index.ts +3 -0
- package/notification/style/css.js +1 -0
- package/notification/style/index.js +1 -0
- package/notification/type.ts +23 -0
- package/package.json +52 -0
- package/popup/Popup.tsx +264 -0
- package/popup/defaultProps.ts +13 -0
- package/popup/hooks/useTrigger.ts +276 -0
- package/popup/index.ts +6 -0
- package/popup/style/css.js +1 -0
- package/popup/style/index.js +1 -0
- package/popup/type.ts +130 -0
- package/portal/Portal.tsx +63 -0
- package/portal/index.ts +1 -0
- package/select/Option.tsx +162 -0
- package/select/OptionGroup.tsx +30 -0
- package/select/PopupContent.tsx +271 -0
- package/select/Select.tsx +586 -0
- package/select/defaultProps.ts +27 -0
- package/select/hooks/useOptions.ts +120 -0
- package/select/hooks/usePanelVirtualScroll.ts +111 -0
- package/select/index.ts +9 -0
- package/select/style/css.js +1 -0
- package/select/style/index.js +2 -0
- package/select/type.ts +382 -0
- package/select/utils/helper.ts +256 -0
- package/select-input/SelectInput.tsx +98 -0
- package/select-input/defaultProps.ts +15 -0
- package/select-input/hook/useMultiple.tsx +100 -0
- package/select-input/hook/useOverlayInnerStyle.ts +84 -0
- package/select-input/hook/useSingle.tsx +112 -0
- package/select-input/index.ts +6 -0
- package/select-input/interface.ts +18 -0
- package/select-input/style/css.js +1 -0
- package/select-input/style/index.js +1 -0
- package/select-input/type.ts +280 -0
- package/space/defaultProps.ts +0 -0
- package/space/index.ts +0 -0
- package/space/type.ts +0 -0
- package/style/index.js +2 -0
- package/styles/_global.scss +39 -0
- package/styles/_vars.scss +386 -0
- package/styles/components/alert/_index.scss +175 -0
- package/styles/components/alert/_vars.scss +39 -0
- package/styles/components/badge/_index.scss +70 -0
- package/styles/components/badge/_vars.scss +25 -0
- package/styles/components/button/_index.scss +511 -0
- package/styles/components/button/_mixins.scss +39 -0
- package/styles/components/button/_vars.scss +122 -0
- package/styles/components/checkbox/_index.scss +158 -0
- package/styles/components/checkbox/_mixin.scss +0 -0
- package/styles/components/checkbox/_var.scss +60 -0
- package/styles/components/dialog/_animate.scss +135 -0
- package/styles/components/dialog/_index.scss +311 -0
- package/styles/components/dialog/_mixins.scss +0 -0
- package/styles/components/dialog/_vars.scss +59 -0
- package/styles/components/form/_index.scss +174 -0
- package/styles/components/form/_mixins.scss +76 -0
- package/styles/components/form/_vars.scss +100 -0
- package/styles/components/input/_index.scss +349 -0
- package/styles/components/input/_map.scss +0 -0
- package/styles/components/input/_mixins.scss +116 -0
- package/styles/components/input/_vars.scss +134 -0
- package/styles/components/loading/_index.scss +112 -0
- package/styles/components/loading/_vars.scss +39 -0
- package/styles/components/notification/_index.scss +160 -0
- package/styles/components/notification/_mixins.scss +12 -0
- package/styles/components/notification/_vars.scss +59 -0
- package/styles/components/popup/_index.scss +82 -0
- package/styles/components/popup/_mixin.scss +149 -0
- package/styles/components/popup/_var.scss +31 -0
- package/styles/components/select/_index.scss +290 -0
- package/styles/components/select/_var.scss +65 -0
- package/styles/components/select-input/_index.scss +5 -0
- package/styles/components/select-input/_var.scss +3 -0
- package/styles/components/switch/_index.scss +279 -0
- package/styles/components/switch/_mixins.scss +0 -0
- package/styles/components/switch/_vars.scss +61 -0
- package/styles/components/tag/_index.scss +316 -0
- package/styles/components/tag/_var.scss +85 -0
- package/styles/components/tag-input/_index.scss +163 -0
- package/styles/components/tag-input/_vars.scss +16 -0
- package/styles/globals.css +250 -0
- package/styles/mixins/_focus.scss +7 -0
- package/styles/mixins/_layout.scss +32 -0
- package/styles/mixins/_reset.scss +10 -0
- package/styles/mixins/_scrollbar.scss +31 -0
- package/styles/mixins/_text.scss +48 -0
- package/styles/rillple.css +16 -0
- package/styles/scrollbar.css +42 -0
- package/styles/themes/_dark.scss +191 -0
- package/styles/themes/_font.scss +79 -0
- package/styles/themes/_index.scss +5 -0
- package/styles/themes/_light.scss +190 -0
- package/styles/themes/_radius.scss +9 -0
- package/styles/themes/_size.scss +68 -0
- package/styles/themes.css +66 -0
- package/styles/utilities/_animation.scss +57 -0
- package/styles/utilities/_tips.scss +9 -0
- package/switch/Switch.tsx +120 -0
- package/switch/defaultProps.ts +3 -0
- package/switch/index.ts +7 -0
- package/switch/style/css.js +1 -0
- package/switch/style/index.js +1 -0
- package/switch/type.ts +46 -0
- package/tag/Tag.tsx +149 -0
- package/tag/defaultProps.ts +19 -0
- package/tag/index.ts +8 -0
- package/tag/style/css.js +1 -0
- package/tag/style/index.js +1 -0
- package/tag/type.ts +170 -0
- package/tag-input/TagInput.tsx +215 -0
- package/tag-input/defaultProps.ts +15 -0
- package/tag-input/hooks/useHover.ts +28 -0
- package/tag-input/hooks/useTagList.tsx +131 -0
- package/tag-input/hooks/useTagScroll.ts +105 -0
- package/tag-input/index.ts +9 -0
- package/tag-input/style/css.js +1 -0
- package/tag-input/style/index.js +1 -0
- package/tag-input/type.ts +224 -0
- package/tag-input/useTagList.tsx +131 -0
- package/utils/composeRefs.ts +14 -0
- package/utils/dom.ts +29 -0
- package/utils/forwardRefWithStatics.ts +12 -0
- package/utils/getScrollbarWidth.ts +11 -0
- package/utils/helper.ts +161 -0
- package/utils/isFragment.ts +22 -0
- package/utils/listener.ts +37 -0
- package/utils/noop.ts +3 -0
- package/utils/parentTNode.ts +38 -0
- package/utils/parseTNode.ts +38 -0
- package/utils/react-render.ts +108 -0
- package/utils/ref.ts +6 -0
- package/utils/refs.ts +81 -0
- package/utils/style.ts +60 -0
- package/utils/transition.ts +28 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// 字体相关token
|
|
2
|
+
:root {
|
|
3
|
+
// 字体family token
|
|
4
|
+
--td-font-family: PingFang SC, Microsoft YaHei, Arial Regular;
|
|
5
|
+
--td-font-family-medium: PingFang SC, Microsoft YaHei, Arial Medium;
|
|
6
|
+
|
|
7
|
+
// 字体大小 token
|
|
8
|
+
--td-font-size-link-small: 12px;
|
|
9
|
+
--td-font-size-link-medium: 14px;
|
|
10
|
+
--td-font-size-link-large: 16px;
|
|
11
|
+
--td-font-size-mark-small: 12px;
|
|
12
|
+
--td-font-size-mark-medium: 14px;
|
|
13
|
+
--td-font-size-body-small: 12px;
|
|
14
|
+
--td-font-size-body-medium: 14px;
|
|
15
|
+
--td-font-size-body-large: 16px;
|
|
16
|
+
--td-font-size-title-small: 14px;
|
|
17
|
+
--td-font-size-title-medium: 16px;
|
|
18
|
+
--td-font-size-title-large: 18px;
|
|
19
|
+
--td-font-size-title-extraLarge: 20px;
|
|
20
|
+
--td-font-size-headline-small: 24px;
|
|
21
|
+
--td-font-size-headline-medium: 28px;
|
|
22
|
+
--td-font-size-headline-large: 36px;
|
|
23
|
+
--td-font-size-display-medium: 48px;
|
|
24
|
+
--td-font-size-display-large: 64px;
|
|
25
|
+
|
|
26
|
+
// 字体行高 token
|
|
27
|
+
--td-line-height-link-small: 20px;
|
|
28
|
+
--td-line-height-link-medium: 22px;
|
|
29
|
+
--td-line-height-link-large: 24px;
|
|
30
|
+
--td-line-height-mark-small: 20px;
|
|
31
|
+
--td-line-height-mark-medium: 22px;
|
|
32
|
+
--td-line-height-body-small: 20px;
|
|
33
|
+
--td-line-height-body-medium: 22px;
|
|
34
|
+
--td-line-height-body-large: 24px;
|
|
35
|
+
--td-line-height-title-small: 22px;
|
|
36
|
+
--td-line-height-title-medium: 24px;
|
|
37
|
+
--td-line-height-title-large: 26px;
|
|
38
|
+
--td-line-height-title-extraLarge: 28px;
|
|
39
|
+
--td-line-height-headline-small: 32px;
|
|
40
|
+
--td-line-height-headline-medium: 36px;
|
|
41
|
+
--td-line-height-headline-large: 44px;
|
|
42
|
+
--td-line-height-display-medium: 56px;
|
|
43
|
+
--td-line-height-display-large: 72px;
|
|
44
|
+
// font token
|
|
45
|
+
--td-font-link-small: var(--td-font-size-link-small) /
|
|
46
|
+
var(--td-line-height-link-small) var(--td-font-family);
|
|
47
|
+
--td-font-link-medium: var(--td-font-size-link-medium) /
|
|
48
|
+
var(--td-line-height-link-medium) var(--td-font-family);
|
|
49
|
+
--td-font-link-large: var(--td-font-size-link-large) /
|
|
50
|
+
var(--td-line-height-link-large) var(--td-font-family);
|
|
51
|
+
--td-font-mark-small: 600 var(--td-font-size-mark-small) /
|
|
52
|
+
var(--td-line-height-mark-small) var(--td-font-family);
|
|
53
|
+
--td-font-mark-medium: 600 var(--td-font-size-mark-medium) /
|
|
54
|
+
var(--td-line-height-mark-medium) var(--td-font-family);
|
|
55
|
+
--td-font-body-small: var(--td-font-size-body-small) /
|
|
56
|
+
var(--td-line-height-body-small) var(--td-font-family);
|
|
57
|
+
--td-font-body-medium: var(--td-font-size-body-medium) /
|
|
58
|
+
var(--td-line-height-body-medium) var(--td-font-family);
|
|
59
|
+
--td-font-body-large: var(--td-font-size-body-large) /
|
|
60
|
+
var(--td-line-height-body-large) var(--td-font-family);
|
|
61
|
+
--td-font-title-small: 600 var(--td-font-size-title-small) /
|
|
62
|
+
var(--td-line-height-title-small) var(--td-font-family);
|
|
63
|
+
--td-font-title-medium: 600 var(--td-font-size-title-medium) /
|
|
64
|
+
var(--td-line-height-title-medium) var(--td-font-family);
|
|
65
|
+
--td-font-title-large: 600 var(--td-font-size-title-large) /
|
|
66
|
+
var(--td-line-height-title-large) var(--td-font-family);
|
|
67
|
+
--td-font-title-extraLarge: 600 var(--td-font-size-title-extraLarge) /
|
|
68
|
+
var(--td-line-height-title-extraLarge) var(--td-font-family);
|
|
69
|
+
--td-font-headline-small: 600 var(--td-font-size-headline-small) /
|
|
70
|
+
var(--td-line-height-headline-small) var(--td-font-family);
|
|
71
|
+
--td-font-headline-medium: 600 var(--td-font-size-headline-medium) /
|
|
72
|
+
var(--td-line-height-headline-medium) var(--td-font-family);
|
|
73
|
+
--td-font-headline-large: 600 var(--td-font-size-headline-large) /
|
|
74
|
+
var(--td-line-height-headline-large) var(--td-font-family);
|
|
75
|
+
--td-font-display-medium: 600 var(--td-font-size-display-medium) /
|
|
76
|
+
var(--td-line-height-display-medium) var(--td-font-family);
|
|
77
|
+
--td-font-display-large: 600 var(--td-font-size-display-large) /
|
|
78
|
+
var(--td-line-height-display-large) var(--td-font-family);
|
|
79
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
:root,
|
|
2
|
+
:root[theme-mode='light'] {
|
|
3
|
+
--td-brand-color-1: #f2f3ff;
|
|
4
|
+
--td-brand-color-2: #d9e1ff;
|
|
5
|
+
--td-brand-color-3: #b5c7ff;
|
|
6
|
+
--td-brand-color-4: #8eabff;
|
|
7
|
+
--td-brand-color-5: #618dff;
|
|
8
|
+
--td-brand-color-6: #366ef4;
|
|
9
|
+
--td-brand-color-7: #0052d9;
|
|
10
|
+
--td-brand-color-8: #003cab;
|
|
11
|
+
--td-brand-color-9: #002a7c;
|
|
12
|
+
--td-brand-color-10: #001a57;
|
|
13
|
+
--td-warning-color-1: #fff1e9;
|
|
14
|
+
--td-warning-color-2: #ffd9c2;
|
|
15
|
+
--td-warning-color-3: #ffb98c;
|
|
16
|
+
--td-warning-color-4: #fa9550;
|
|
17
|
+
--td-warning-color-5: #e37318;
|
|
18
|
+
--td-warning-color-6: #be5a00;
|
|
19
|
+
--td-warning-color-7: #954500;
|
|
20
|
+
--td-warning-color-8: #713300;
|
|
21
|
+
--td-warning-color-9: #532300;
|
|
22
|
+
--td-warning-color-10: #3b1700;
|
|
23
|
+
--td-error-color-1: #fff0ed;
|
|
24
|
+
--td-error-color-2: #ffd8d2;
|
|
25
|
+
--td-error-color-3: #ffb9b0;
|
|
26
|
+
--td-error-color-4: #ff9285;
|
|
27
|
+
--td-error-color-5: #f6685d;
|
|
28
|
+
--td-error-color-6: #d54941;
|
|
29
|
+
--td-error-color-7: #ad352f;
|
|
30
|
+
--td-error-color-8: #881f1c;
|
|
31
|
+
--td-error-color-9: #68070a;
|
|
32
|
+
--td-error-color-10: #490002;
|
|
33
|
+
--td-success-color-1: #e3f9e9;
|
|
34
|
+
--td-success-color-2: #c6f3d7;
|
|
35
|
+
--td-success-color-3: #92dab2;
|
|
36
|
+
--td-success-color-4: #56c08d;
|
|
37
|
+
--td-success-color-5: #2ba471;
|
|
38
|
+
--td-success-color-6: #008858;
|
|
39
|
+
--td-success-color-7: #006c45;
|
|
40
|
+
--td-success-color-8: #005334;
|
|
41
|
+
--td-success-color-9: #003b23;
|
|
42
|
+
--td-success-color-10: #002515;
|
|
43
|
+
--td-gray-color-1: #f3f3f3;
|
|
44
|
+
--td-gray-color-2: #eee;
|
|
45
|
+
--td-gray-color-3: #e8e8e8;
|
|
46
|
+
--td-gray-color-4: #ddd;
|
|
47
|
+
--td-gray-color-5: #c6c6c6;
|
|
48
|
+
--td-gray-color-6: #a6a6a6;
|
|
49
|
+
--td-gray-color-7: #8b8b8b;
|
|
50
|
+
--td-gray-color-8: #777;
|
|
51
|
+
--td-gray-color-9: #5e5e5e;
|
|
52
|
+
--td-gray-color-10: #4b4b4b;
|
|
53
|
+
--td-gray-color-11: #393939;
|
|
54
|
+
--td-gray-color-12: #2c2c2c;
|
|
55
|
+
--td-gray-color-13: #242424;
|
|
56
|
+
--td-gray-color-14: #181818;
|
|
57
|
+
|
|
58
|
+
// 文字 & 图标 颜色
|
|
59
|
+
--td-font-white-1: rgba(255, 255, 255, 100%);
|
|
60
|
+
--td-font-white-2: rgba(255, 255, 255, 55%);
|
|
61
|
+
--td-font-white-3: rgba(255, 255, 255, 35%);
|
|
62
|
+
--td-font-white-4: rgba(255, 255, 255, 22%);
|
|
63
|
+
--td-font-gray-1: rgba(0, 0, 0, 90%);
|
|
64
|
+
--td-font-gray-2: rgba(0, 0, 0, 60%);
|
|
65
|
+
--td-font-gray-3: rgba(0, 0, 0, 40%);
|
|
66
|
+
--td-font-gray-4: rgba(0, 0, 0, 26%);
|
|
67
|
+
|
|
68
|
+
// 基础颜色
|
|
69
|
+
--td-brand-color: var(--td-brand-color-7); // 色彩-品牌-可操作
|
|
70
|
+
--td-warning-color: var(--td-warning-color-5); // 色彩-功能-警告
|
|
71
|
+
--td-error-color: var(--td-error-color-6); // 色彩-功能-失败
|
|
72
|
+
--td-success-color: var(--td-success-color-5); // 色彩-功能-成功
|
|
73
|
+
|
|
74
|
+
// 基础颜色的扩展 用于 hover / 聚焦 / 禁用 / 点击 等状态
|
|
75
|
+
--td-brand-color-hover: var(--td-brand-color-6); // hover态
|
|
76
|
+
--td-brand-color-focus: var(--td-brand-color-2); // focus态,包括鼠标和键盘
|
|
77
|
+
--td-brand-color-active: var(--td-brand-color-8); // 点击态
|
|
78
|
+
--td-brand-color-disabled: var(--td-brand-color-3); // 禁用态
|
|
79
|
+
--td-brand-color-light: var(--td-brand-color-1); // 浅色的选中态
|
|
80
|
+
--td-brand-color-light-hover: var(--td-brand-color-2);
|
|
81
|
+
|
|
82
|
+
// 警告色扩展
|
|
83
|
+
--td-warning-color-hover: var(--td-warning-color-4);
|
|
84
|
+
--td-warning-color-focus: var(--td-warning-color-2);
|
|
85
|
+
--td-warning-color-active: var(--td-warning-color-6);
|
|
86
|
+
--td-warning-color-disabled: var(--td-warning-color-3);
|
|
87
|
+
--td-warning-color-light: var(--td-warning-color-1);
|
|
88
|
+
--td-warning-color-light-hover: var(--td-warning-color-2);
|
|
89
|
+
|
|
90
|
+
// 失败/错误色扩展
|
|
91
|
+
--td-error-color-hover: var(--td-error-color-5);
|
|
92
|
+
--td-error-color-focus: var(--td-error-color-2);
|
|
93
|
+
--td-error-color-active: var(--td-error-color-7);
|
|
94
|
+
--td-error-color-disabled: var(--td-error-color-3);
|
|
95
|
+
--td-error-color-light: var(--td-error-color-1);
|
|
96
|
+
--td-error-color-light-hover: var(--td-error-color-2);
|
|
97
|
+
|
|
98
|
+
// 成功色扩展
|
|
99
|
+
--td-success-color-hover: var(--td-success-color-4);
|
|
100
|
+
--td-success-color-focus: var(--td-success-color-2);
|
|
101
|
+
--td-success-color-active: var(--td-success-color-6);
|
|
102
|
+
--td-success-color-disabled: var(--td-success-color-3);
|
|
103
|
+
--td-success-color-light: var(--td-success-color-1);
|
|
104
|
+
--td-success-color-light-hover: var(--td-success-color-2);
|
|
105
|
+
|
|
106
|
+
// 遮罩
|
|
107
|
+
--td-mask-active: rgba(0, 0, 0, 60%); // 遮罩-弹出
|
|
108
|
+
--td-mask-disabled: rgba(255, 255, 255, 60%); // 遮罩-禁用
|
|
109
|
+
--td-mask-background: rgba(255, 255, 255, 96%); // 二维码遮罩
|
|
110
|
+
|
|
111
|
+
// 背景色
|
|
112
|
+
--td-bg-color-page: var(--td-gray-color-2); // 色彩 - page
|
|
113
|
+
--td-bg-color-container: #fff; // 色彩 - 容器
|
|
114
|
+
--td-bg-color-container-hover: var(--td-gray-color-1); // 色彩 - 容器 - hover
|
|
115
|
+
--td-bg-color-container-active: var(
|
|
116
|
+
--td-gray-color-3
|
|
117
|
+
); // 色彩 - 容器 - active
|
|
118
|
+
--td-bg-color-container-select: #fff; // 色彩 - 容器 - select
|
|
119
|
+
--td-bg-color-secondarycontainer: var(--td-gray-color-1); // 色彩 - 次级容器
|
|
120
|
+
--td-bg-color-secondarycontainer-hover: var(
|
|
121
|
+
--td-gray-color-2
|
|
122
|
+
); // 色彩 - 次级容器 - hover
|
|
123
|
+
--td-bg-color-secondarycontainer-active: var(
|
|
124
|
+
--td-gray-color-4
|
|
125
|
+
); // 色彩 - 次级容器 - active
|
|
126
|
+
--td-bg-color-component: var(--td-gray-color-3); // 色彩 - 组件
|
|
127
|
+
--td-bg-color-component-hover: var(--td-gray-color-4); // 色彩 - 组件 - hover
|
|
128
|
+
--td-bg-color-component-active: var(
|
|
129
|
+
--td-gray-color-6
|
|
130
|
+
); // 色彩 - 组件 - active
|
|
131
|
+
--td-bg-color-secondarycomponent: var(--td-gray-color-4); // 色彩 - 次级组件
|
|
132
|
+
--td-bg-color-secondarycomponent-hover: var(
|
|
133
|
+
--td-gray-color-5
|
|
134
|
+
); // 色彩 - 次级组件 - hover
|
|
135
|
+
--td-bg-color-secondarycomponent-active: var(
|
|
136
|
+
--td-gray-color-6
|
|
137
|
+
); // 色彩 - 次级组件 - active
|
|
138
|
+
--td-bg-color-component-disabled: var(
|
|
139
|
+
--td-gray-color-2
|
|
140
|
+
); // 色彩 - 组件 - disabled
|
|
141
|
+
|
|
142
|
+
// 特殊组件背景色,目前只用于 button、input 组件多主题场景,浅色主题下固定为白色,深色主题下为 transparent 适配背景颜色
|
|
143
|
+
--td-bg-color-specialcomponent: #fff;
|
|
144
|
+
|
|
145
|
+
// 文本颜色
|
|
146
|
+
--td-text-color-primary: var(--td-font-gray-1); // 色彩-文字-主要
|
|
147
|
+
--td-text-color-secondary: var(--td-font-gray-2); // 色彩-文字-次要
|
|
148
|
+
--td-text-color-placeholder: var(--td-font-gray-3); // 色彩-文字-占位符/说明
|
|
149
|
+
--td-text-color-disabled: var(--td-font-gray-4); // 色彩-文字-禁用
|
|
150
|
+
--td-text-color-anti: #fff; // 色彩-文字-反色
|
|
151
|
+
--td-text-color-brand: var(--td-brand-color-7); // 色彩-文字-品牌
|
|
152
|
+
--td-text-color-link: var(--td-brand-color-8); // 色彩-文字-链接
|
|
153
|
+
--td-text-color-watermark: rgba(0, 0, 0, 10%); // 色彩-文字-水印颜色
|
|
154
|
+
|
|
155
|
+
// 分割线
|
|
156
|
+
--td-border-level-1-color: var(--td-gray-color-3);
|
|
157
|
+
--td-component-stroke: var(--td-gray-color-3);
|
|
158
|
+
// 边框
|
|
159
|
+
--td-border-level-2-color: var(--td-gray-color-4);
|
|
160
|
+
--td-component-border: var(--td-gray-color-4);
|
|
161
|
+
|
|
162
|
+
// 基础/下层 投影 hover 使用的组件包括:表格 /
|
|
163
|
+
--td-shadow-1:
|
|
164
|
+
0 1px 10px rgba(0, 0, 0, 5%), 0 4px 5px rgba(0, 0, 0, 8%),
|
|
165
|
+
0 2px 4px -1px rgba(0, 0, 0, 12%);
|
|
166
|
+
// 中层投影 下拉 使用的组件包括:下拉菜单 / 气泡确认框 / 选择器 /
|
|
167
|
+
--td-shadow-2:
|
|
168
|
+
0 3px 14px 2px rgba(0, 0, 0, 5%), 0 8px 10px 1px rgba(0, 0, 0, 6%),
|
|
169
|
+
0 5px 5px -3px rgba(0, 0, 0, 10%);
|
|
170
|
+
// 上层投影(警示/弹窗)使用的组件包括:全局提示 / 消息通知
|
|
171
|
+
--td-shadow-3:
|
|
172
|
+
0 6px 30px 5px rgba(0, 0, 0, 5%), 0 16px 24px 2px rgba(0, 0, 0, 4%),
|
|
173
|
+
0 8px 10px -5px rgba(0, 0, 0, 8%);
|
|
174
|
+
|
|
175
|
+
// 内投影 用于弹窗类组件(气泡确认框 / 全局提示 / 消息通知)的内描边
|
|
176
|
+
--td-shadow-inset-top: inset 0 0.5px 0 #dcdcdc;
|
|
177
|
+
--td-shadow-inset-right: inset 0.5px 0 0 #dcdcdc;
|
|
178
|
+
--td-shadow-inset-bottom: inset 0 -0.5px 0 #dcdcdc;
|
|
179
|
+
--td-shadow-inset-left: inset -0.5px 0 0 #dcdcdc;
|
|
180
|
+
|
|
181
|
+
// table 特定阴影
|
|
182
|
+
--td-table-shadow-color: rgba(0, 0, 0, 8%);
|
|
183
|
+
|
|
184
|
+
// 滚动条颜色
|
|
185
|
+
--td-scrollbar-color: rgba(0, 0, 0, 10%);
|
|
186
|
+
// 滚动条悬浮颜色( hover )
|
|
187
|
+
--td-scrollbar-hover-color: rgba(0, 0, 0, 30%);
|
|
188
|
+
// 滚动条轨道颜色,不能是带透明度,否则纵向滚动时,横向滚动条会穿透
|
|
189
|
+
--td-scroll-track-color: #fff;
|
|
190
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// size/margin/padding相关 token
|
|
2
|
+
:root {
|
|
3
|
+
--td-size-1: 2px;
|
|
4
|
+
--td-size-2: 4px;
|
|
5
|
+
--td-size-3: 6px;
|
|
6
|
+
--td-size-4: 8px;
|
|
7
|
+
--td-size-5: 12px;
|
|
8
|
+
--td-size-6: 16px;
|
|
9
|
+
--td-size-7: 20px;
|
|
10
|
+
--td-size-8: 24px;
|
|
11
|
+
--td-size-9: 28px;
|
|
12
|
+
--td-size-10: 32px;
|
|
13
|
+
--td-size-11: 36px;
|
|
14
|
+
--td-size-12: 40px;
|
|
15
|
+
--td-size-13: 48px;
|
|
16
|
+
--td-size-14: 56px;
|
|
17
|
+
--td-size-15: 64px;
|
|
18
|
+
--td-size-16: 72px;
|
|
19
|
+
|
|
20
|
+
//全局 component 组件尺寸高度相关 token
|
|
21
|
+
--td-comp-size-xxxs: var(--td-size-6);
|
|
22
|
+
--td-comp-size-xxs: var(--td-size-7);
|
|
23
|
+
--td-comp-size-xs: var(--td-size-8);
|
|
24
|
+
--td-comp-size-s: var(--td-size-9);
|
|
25
|
+
--td-comp-size-m: var(--td-size-10);
|
|
26
|
+
--td-comp-size-l: var(--td-size-11);
|
|
27
|
+
--td-comp-size-xl: var(--td-size-12);
|
|
28
|
+
--td-comp-size-xxl: var(--td-size-13);
|
|
29
|
+
--td-comp-size-xxxl: var(--td-size-14);
|
|
30
|
+
--td-comp-size-xxxxl: var(--td-size-15);
|
|
31
|
+
--td-comp-size-xxxxxl: var(--td-size-16);
|
|
32
|
+
|
|
33
|
+
//全局 popup 弹出层整体边距 token
|
|
34
|
+
--td-pop-padding-s: var(--td-size-2);
|
|
35
|
+
--td-pop-padding-m: var(--td-size-3);
|
|
36
|
+
--td-pop-padding-l: var(--td-size-4);
|
|
37
|
+
--td-pop-padding-xl: var(--td-size-5);
|
|
38
|
+
--td-pop-padding-xxl: var(--td-size-6);
|
|
39
|
+
|
|
40
|
+
//全局 component 组件左右边距 token
|
|
41
|
+
--td-comp-paddingLR-xxs: var(--td-size-1);
|
|
42
|
+
--td-comp-paddingLR-xs: var(--td-size-2);
|
|
43
|
+
--td-comp-paddingLR-s: var(--td-size-4);
|
|
44
|
+
--td-comp-paddingLR-m: var(--td-size-5);
|
|
45
|
+
--td-comp-paddingLR-l: var(--td-size-6);
|
|
46
|
+
--td-comp-paddingLR-xl: var(--td-size-8);
|
|
47
|
+
--td-comp-paddingLR-xxl: var(--td-size-10);
|
|
48
|
+
|
|
49
|
+
//全局 component 组件上下边距 token
|
|
50
|
+
--td-comp-paddingTB-xxs: var(--td-size-1);
|
|
51
|
+
--td-comp-paddingTB-xs: var(--td-size-2);
|
|
52
|
+
--td-comp-paddingTB-s: var(--td-size-4);
|
|
53
|
+
--td-comp-paddingTB-m: var(--td-size-5);
|
|
54
|
+
--td-comp-paddingTB-l: var(--td-size-6);
|
|
55
|
+
--td-comp-paddingTB-xl: var(--td-size-8);
|
|
56
|
+
--td-comp-paddingTB-xxl: var(--td-size-10);
|
|
57
|
+
|
|
58
|
+
//全局 component 组件间距 token
|
|
59
|
+
--td-comp-margin-xxs: var(--td-size-1);
|
|
60
|
+
--td-comp-margin-xs: var(--td-size-2);
|
|
61
|
+
--td-comp-margin-s: var(--td-size-4);
|
|
62
|
+
--td-comp-margin-m: var(--td-size-5);
|
|
63
|
+
--td-comp-margin-l: var(--td-size-6);
|
|
64
|
+
--td-comp-margin-xl: var(--td-size-7);
|
|
65
|
+
--td-comp-margin-xxl: var(--td-size-8);
|
|
66
|
+
--td-comp-margin-xxxl: var(--td-size-10);
|
|
67
|
+
--td-comp-margin-xxxxl: var(--td-size-12);
|
|
68
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
.theme-blue {
|
|
4
|
+
--primary: var(--color-blue-600);
|
|
5
|
+
--primary-foreground: var(--color-blue-50);
|
|
6
|
+
--ring: var(--color-blue-400);
|
|
7
|
+
--sidebar-primary: var(--color-blue-600);
|
|
8
|
+
--sidebar-primary-foreground: var(--color-blue-50);
|
|
9
|
+
--sidebar-ring: var(--color-blue-400);
|
|
10
|
+
--chart-1: var(--color-blue-300);
|
|
11
|
+
--chart-2: var(--color-blue-500);
|
|
12
|
+
--chart-3: var(--color-blue-600);
|
|
13
|
+
--chart-4: var(--color-blue-700);
|
|
14
|
+
--chart-5: var(--color-blue-800);
|
|
15
|
+
}
|
|
16
|
+
.theme-blue.dark {
|
|
17
|
+
--primary: var(--color-blue-500);
|
|
18
|
+
--primary-foreground: var(--color-blue-50);
|
|
19
|
+
--ring: var(--color-blue-900);
|
|
20
|
+
--sidebar-primary: var(--color-blue-500);
|
|
21
|
+
--sidebar-primary-foreground: var(--color-blue-50);
|
|
22
|
+
--sidebar-ring: var(--color-blue-900);
|
|
23
|
+
}
|
|
24
|
+
@media (prefers-color-scheme: dark) {
|
|
25
|
+
.theme-blue {
|
|
26
|
+
--primary: var(--color-blue-500);
|
|
27
|
+
--primary-foreground: var(--color-blue-50);
|
|
28
|
+
--ring: var(--color-blue-900);
|
|
29
|
+
--sidebar-primary: var(--color-blue-500);
|
|
30
|
+
--sidebar-primary-foreground: var(--color-blue-50);
|
|
31
|
+
--sidebar-ring: var(--color-blue-900);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.theme-green {
|
|
36
|
+
--primary: var(--color-lime-600);
|
|
37
|
+
--primary-foreground: var(--color-lime-50);
|
|
38
|
+
--ring: var(--color-lime-400);
|
|
39
|
+
--chart-1: var(--color-green-300);
|
|
40
|
+
--chart-2: var(--color-green-500);
|
|
41
|
+
--chart-3: var(--color-green-600);
|
|
42
|
+
--chart-4: var(--color-green-700);
|
|
43
|
+
--chart-5: var(--color-green-800);
|
|
44
|
+
--sidebar-primary: var(--color-lime-600);
|
|
45
|
+
--sidebar-primary-foreground: var(--color-lime-50);
|
|
46
|
+
--sidebar-ring: var(--color-lime-400);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.theme-green.dark {
|
|
50
|
+
--primary: var(--color-lime-600);
|
|
51
|
+
--primary-foreground: var(--color-lime-50);
|
|
52
|
+
--ring: var(--color-lime-900);
|
|
53
|
+
--sidebar-primary: var(--color-lime-500);
|
|
54
|
+
--sidebar-primary-foreground: var(--color-lime-50);
|
|
55
|
+
--sidebar-ring: var(--color-lime-900);
|
|
56
|
+
}
|
|
57
|
+
@media (prefers-color-scheme: dark) {
|
|
58
|
+
.theme-green {
|
|
59
|
+
--primary: var(--color-lime-500);
|
|
60
|
+
--primary-foreground: var(--color-lime-50);
|
|
61
|
+
--ring: var(--color-lime-900);
|
|
62
|
+
--sidebar-primary: var(--color-lime-500);
|
|
63
|
+
--sidebar-primary-foreground: var(--color-lime-50);
|
|
64
|
+
--sidebar-ring: var(--color-lime-900);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
@import '../_vars.scss';
|
|
2
|
+
|
|
3
|
+
@keyframes t-fade-in {
|
|
4
|
+
from {
|
|
5
|
+
opacity: 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
to {
|
|
9
|
+
opacity: 1;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@keyframes t-fade-out {
|
|
14
|
+
from {
|
|
15
|
+
opacity: 1;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
to {
|
|
19
|
+
opacity: 0;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@keyframes t-spin {
|
|
24
|
+
from {
|
|
25
|
+
transform: rotate(0deg);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
to {
|
|
29
|
+
transform: rotate(360deg);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.#{$prefix}-icon-loading {
|
|
34
|
+
animation: t-spin 1s linear infinite;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// 动态生成 keyframes 动画
|
|
38
|
+
@mixin anim-g-attr-change($name, $attr, $from, $to) {
|
|
39
|
+
@keyframes #{$name} {
|
|
40
|
+
from {
|
|
41
|
+
#{$attr}: #{$from};
|
|
42
|
+
}
|
|
43
|
+
to {
|
|
44
|
+
#{$attr}: #{$to};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@keyframes t-zoom-out {
|
|
50
|
+
from {
|
|
51
|
+
transform: scale(0.2);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
to {
|
|
55
|
+
transform: scale(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import classNames from "classnames";
|
|
3
|
+
import Loading from "../loading";
|
|
4
|
+
import useConfig from "../hooks/useConfig";
|
|
5
|
+
import { StyledProps } from "../common";
|
|
6
|
+
import useCommonClassName from "../hooks/useCommonClassName";
|
|
7
|
+
import { SwitchValue, TdSwitchProps } from "./type";
|
|
8
|
+
import { switchDefaultProps } from "./defaultProps";
|
|
9
|
+
import parseTNode from "../utils/parentTNode";
|
|
10
|
+
import useDefaultProps from "../hooks/useDefaultProps";
|
|
11
|
+
|
|
12
|
+
export type SwitchChangeEventHandler = (value: boolean, event: React.MouseEvent<HTMLButtonElement>) => void;
|
|
13
|
+
export type SwitchClickEventHandler = SwitchChangeEventHandler;
|
|
14
|
+
|
|
15
|
+
export interface SwitchProps<T extends SwitchValue = SwitchValue> extends TdSwitchProps<T>, StyledProps {}
|
|
16
|
+
|
|
17
|
+
const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>((originalProps, ref) => {
|
|
18
|
+
const { classPrefix } = useConfig();
|
|
19
|
+
const props = useDefaultProps<SwitchProps<SwitchValue>>(originalProps, switchDefaultProps);
|
|
20
|
+
const {
|
|
21
|
+
className,
|
|
22
|
+
value,
|
|
23
|
+
defaultValue,
|
|
24
|
+
disabled,
|
|
25
|
+
loading,
|
|
26
|
+
size,
|
|
27
|
+
label,
|
|
28
|
+
customValue,
|
|
29
|
+
onChange,
|
|
30
|
+
beforeChange,
|
|
31
|
+
...restProps
|
|
32
|
+
} = props;
|
|
33
|
+
const [activeValue = true, inactiveValue = false] = customValue || [];
|
|
34
|
+
|
|
35
|
+
const isControlled = typeof value !== "undefined";
|
|
36
|
+
const initChecked = defaultValue === activeValue || value === activeValue;
|
|
37
|
+
const [innerChecked, setInnerChecked] = useState(initChecked);
|
|
38
|
+
|
|
39
|
+
const contentNode = React.useMemo<React.ReactNode>(() => {
|
|
40
|
+
if (Array.isArray(label)) {
|
|
41
|
+
const [activeContent = "", inactiveContent = ""] = label;
|
|
42
|
+
const content = innerChecked ? activeContent : inactiveContent;
|
|
43
|
+
return parseTNode(content, { value });
|
|
44
|
+
}
|
|
45
|
+
return parseTNode(label, { value });
|
|
46
|
+
}, [label, innerChecked, value]);
|
|
47
|
+
|
|
48
|
+
const handleChange = (e: React.MouseEvent) => {
|
|
49
|
+
if (!isControlled) {
|
|
50
|
+
setInnerChecked(!innerChecked);
|
|
51
|
+
}
|
|
52
|
+
const changedValue = !innerChecked ? activeValue : inactiveValue;
|
|
53
|
+
onChange?.(changedValue, { e });
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const onInternalClick: React.MouseEventHandler<HTMLButtonElement> = (e) => {
|
|
57
|
+
if (disabled) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (!beforeChange) {
|
|
62
|
+
handleChange(e);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
Promise.resolve(beforeChange())
|
|
66
|
+
.then((v) => {
|
|
67
|
+
if (v) {
|
|
68
|
+
handleChange(e);
|
|
69
|
+
}
|
|
70
|
+
})
|
|
71
|
+
.catch((e) => {
|
|
72
|
+
console.error("Switch", `some error occurred: ${e}`);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
if (Array.isArray(customValue) && !customValue.includes(value)) {
|
|
78
|
+
console.error("Switch", `value is not in customValue: ${JSON.stringify(customValue)}`);
|
|
79
|
+
}
|
|
80
|
+
if (isControlled) {
|
|
81
|
+
// Use setTimeout to avoid calling setState synchronously within an effect
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
setInnerChecked(value === activeValue);
|
|
84
|
+
}, 0);
|
|
85
|
+
}
|
|
86
|
+
}, [value, customValue, activeValue, isControlled]);
|
|
87
|
+
|
|
88
|
+
const { SIZE, STATUS } = useCommonClassName();
|
|
89
|
+
const switchClassName = classNames(
|
|
90
|
+
`${classPrefix}-switch`,
|
|
91
|
+
className,
|
|
92
|
+
{
|
|
93
|
+
[STATUS.checked]: innerChecked,
|
|
94
|
+
[STATUS.disabled]: disabled,
|
|
95
|
+
[STATUS.loading]: loading
|
|
96
|
+
},
|
|
97
|
+
SIZE[size]
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
return (
|
|
101
|
+
<button
|
|
102
|
+
{...restProps}
|
|
103
|
+
type="button"
|
|
104
|
+
role="switch"
|
|
105
|
+
disabled={disabled || loading}
|
|
106
|
+
className={switchClassName}
|
|
107
|
+
ref={ref}
|
|
108
|
+
onClick={onInternalClick}
|
|
109
|
+
>
|
|
110
|
+
<span className={`${classPrefix}-switch__handle`}>{loading && <Loading loading size="small" />}</span>
|
|
111
|
+
<div className={`${classPrefix}-switch__content`}>{contentNode}</div>
|
|
112
|
+
</button>
|
|
113
|
+
);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
Switch.displayName = "Switch";
|
|
117
|
+
|
|
118
|
+
export default Switch as <T extends SwitchValue = SwitchValue>(
|
|
119
|
+
props: SwitchProps<T> & React.RefAttributes<HTMLButtonElement>
|
|
120
|
+
) => React.ReactElement;
|
package/switch/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./index.css";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "../../styles/components/switch/_index.scss";
|
package/switch/type.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { TNode } from "../common";
|
|
2
|
+
import { MouseEvent } from "react";
|
|
3
|
+
|
|
4
|
+
export interface TdSwitchProps<T = SwitchValue> {
|
|
5
|
+
/**
|
|
6
|
+
* Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。
|
|
7
|
+
*/
|
|
8
|
+
beforeChange?: () => boolean | Promise<boolean>;
|
|
9
|
+
/**
|
|
10
|
+
* 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]、['open', 'close']
|
|
11
|
+
*/
|
|
12
|
+
customValue?: Array<SwitchValue>;
|
|
13
|
+
/**
|
|
14
|
+
* 是否禁用组件,默认为 false
|
|
15
|
+
*/
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
/**
|
|
18
|
+
* 开关内容,[开启时内容,关闭时内容]。示例:['开', '关'] 或 (value) => value ? '开' : '关'
|
|
19
|
+
* @default []
|
|
20
|
+
*/
|
|
21
|
+
label?: Array<string | TNode> | TNode<{ value: SwitchValue }>;
|
|
22
|
+
/**
|
|
23
|
+
* 是否处于加载中状态
|
|
24
|
+
* @default false
|
|
25
|
+
*/
|
|
26
|
+
loading?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* 开关尺寸
|
|
29
|
+
* @default medium
|
|
30
|
+
*/
|
|
31
|
+
size?: "small" | "medium" | "large";
|
|
32
|
+
/**
|
|
33
|
+
* 开关值
|
|
34
|
+
*/
|
|
35
|
+
value?: T;
|
|
36
|
+
/**
|
|
37
|
+
* 开关值,非受控属性
|
|
38
|
+
*/
|
|
39
|
+
defaultValue?: T;
|
|
40
|
+
/**
|
|
41
|
+
* 数据发生变化时触发
|
|
42
|
+
*/
|
|
43
|
+
onChange?: (value: T, context: { e: MouseEvent }) => void;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export type SwitchValue = string | number | boolean;
|