From 55cc864077ba1ba0a22cfc29fc47f0c83a6c8d71 Mon Sep 17 00:00:00 2001 From: Bang <15622356989@163.com> Date: Wed, 4 Jan 2023 09:21:37 +0800 Subject: [PATCH 1/2] =?UTF-8?q?chore:=20=E4=BF=AE=E6=94=B9switch=20props?= =?UTF-8?q?=20=E5=86=99=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/docs/switch.md | 43 +- packages/opendesign/package.json | 1 - .../src/components/_shared/utils.ts | 25 +- .../src/components/switch/OSwitch.vue | 37 +- .../switch/__demo__/SwitchBeforeChange.vue | 16 +- .../__demo__/SwitchDisabledAndLoading.vue | 6 +- .../switch/__demo__/SwitchShape.vue | 6 +- .../components/switch/__demo__/SwitchSize.vue | 14 +- .../switch/__demo__/SwitchSlots.vue | 10 +- .../opendesign/src/components/switch/types.ts | 5 - pnpm-lock.yaml | 2042 +---------------- 11 files changed, 128 insertions(+), 2077 deletions(-) delete mode 100644 packages/opendesign/src/components/switch/types.ts diff --git a/packages/docs/switch.md b/packages/docs/switch.md index fa5638c7..656d82e1 100644 --- a/packages/docs/switch.md +++ b/packages/docs/switch.md @@ -1,38 +1,25 @@ # Switch 开关 -# props +## props -| name | type | 默认值 | 说明 | -| :----------- | :------------------------------------------ | :------------ | ------------------------------------------------------------ | -| model:value | Boolean | false | 开关状态 | -| shape | ShapeT | ShapeT.NORMAL | 形状 | -| size | SizeT | SizeT.NORMAL | 尺寸 | -| disabled | Boolean | false | 是否禁用 | -| loading | Boolean | false | 加载状态 | -| beforeChange | (val: boolean): Promise\\|boolean | - | return Promise.resolve(true)继续切换,resolve(false)阻止切换 | +| name | type | 默认值 | 说明 | +| :----------- | :------------------------------------------ | :----------- | ------------------------------------------------------------ | +| model:value | boolean | false | 开关状态 | +| shape | Shape | Shape.NORMAL | 开关形状 | +| size | Size | Size.NORMAL | 开关尺寸 | +| disabled | boolean | false | 是否禁用 | +| loading | boolean | false | 加载状态 | +| beforeChange | (val: boolean): Promise\\|boolean | - | return Promise.resolve(true)继续切换,resolve(false)阻止切换 | -``` -enum SizeT { - LARGE = 'large', - NORMAL = 'normal', - SMALL = 'small' -} +## event -enum ShapeT { - ROUND = 'round', - NORMAL = 'normal' -} -``` +| name | 参数 | 说明 | +| :----- | :-------------- | :------------- | +| change | value: boolean; | 状态切换后触发 | -# event +## expose -| name | 参数 | 说明 | -| :----- | :------------------------ | :------------- | -| change | value: boolean; ev: Event | 状态切换后触发 | - -# expose - -# slot +## slot | name | 说明 | | :--- | :------- | diff --git a/packages/opendesign/package.json b/packages/opendesign/package.json index 24cb1ca2..19323c5c 100644 --- a/packages/opendesign/package.json +++ b/packages/opendesign/package.json @@ -32,7 +32,6 @@ "vue-tsc": "^1.0.13" }, "dependencies": { - "@vue/shared": "^3.2.45", "intersection-observer-polyfill": "^0.1.0", "lodash-es": "^4.17.21", "resize-observer-polyfill": "^1.5.1" diff --git a/packages/opendesign/src/components/_shared/utils.ts b/packages/opendesign/src/components/_shared/utils.ts index 3e1e96c1..c471a595 100644 --- a/packages/opendesign/src/components/_shared/utils.ts +++ b/packages/opendesign/src/components/_shared/utils.ts @@ -1,9 +1,28 @@ import { throttle as _throttle, debounce as _debounce } from 'lodash-es'; import type { ThrottleSettings, DebounceSettings } from 'lodash-es'; -export function isFunction(fn: unknown) { - return typeof fn === 'function'; +export function isBoolean(val: unknown): val is boolean { + return typeof val === 'boolean'; } +export function isString(val: unknown): val is string { + return typeof val === 'string'; +} +export function isNumber(val: unknown): val is number { + return typeof val === 'string'; +} +export function isFunction(val: unknown): val is Function { + return typeof val === 'function'; +} +export function isObject(val: unknown): val is Record { + return val !== null && typeof val === 'object'; +} +export function isPlainObject(val: unknown): val is object { + return Object.prototype.toString.call(val) === '[object Object]'; +} +export function isPromise(val: unknown): val is Promise { + return isObject(val) && isFunction(val.then) && isFunction(val.catch); +} + // 防抖 export function debounce) => unknown>(fn: T, wait?: number, ctx?: unknown | null, opts?: ThrottleSettings) { return _debounce.apply(ctx, [fn, wait, opts]); @@ -47,4 +66,4 @@ export function throttleRAF) => unknown>(fn: handle = 0; }; return rlt; -} \ No newline at end of file +} diff --git a/packages/opendesign/src/components/switch/OSwitch.vue b/packages/opendesign/src/components/switch/OSwitch.vue index 3ef1d678..b8193e15 100644 --- a/packages/opendesign/src/components/switch/OSwitch.vue +++ b/packages/opendesign/src/components/switch/OSwitch.vue @@ -1,20 +1,26 @@ diff --git a/packages/opendesign/src/components/switch/__demo__/SwitchShape.vue b/packages/opendesign/src/components/switch/__demo__/SwitchShape.vue index d0aa90f9..ee40f473 100644 --- a/packages/opendesign/src/components/switch/__demo__/SwitchShape.vue +++ b/packages/opendesign/src/components/switch/__demo__/SwitchShape.vue @@ -1,13 +1,13 @@ diff --git a/packages/opendesign/src/components/switch/__demo__/SwitchSize.vue b/packages/opendesign/src/components/switch/__demo__/SwitchSize.vue index 83f4ac2d..788ee383 100644 --- a/packages/opendesign/src/components/switch/__demo__/SwitchSize.vue +++ b/packages/opendesign/src/components/switch/__demo__/SwitchSize.vue @@ -1,17 +1,17 @@ diff --git a/packages/opendesign/src/components/switch/__demo__/SwitchSlots.vue b/packages/opendesign/src/components/switch/__demo__/SwitchSlots.vue index 28a72ccc..133e81b0 100644 --- a/packages/opendesign/src/components/switch/__demo__/SwitchSlots.vue +++ b/packages/opendesign/src/components/switch/__demo__/SwitchSlots.vue @@ -1,6 +1,6 @@