diff --git a/packages/docs/switch.md b/packages/docs/switch.md index fa5638c73e3626f9f9755680aa343a255f2dc91b..e76d4a838d408da0909e0a8850946aa7debd1cb7 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 | 加载状态 | +| 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)阻止切换 | -``` -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 24cb1ca243fec7ae65470dc00e932d3205f360e0..19323c5c435bee9e8d56cc3895176e8901d1267e 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 3e1e96c1aa47f9cbc97e2ec74d9f1baa848f6917..c471a595c039d39eba14df78af54fcdf6a11ac4b 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 3ef1d678b7e2945defcd1436dcb489afcc7c6eba..b8193e159c379804644c77e082816459d581a92e 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 d0aa90f9ebee01c18a29c9ed98f2676a3111b823..ee40f473b27fc54078279a889ffa8acbd20513c3 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 83f4ac2dd054ac08739b248304baf3b633beddb0..788ee383f171cee539320468c14b3edbb9412c8f 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 28a72ccc3305ab23a8c6059ac36f82b570e97dae..133e81b00c52dd86c7f2f6fee5d34baf8409b7f3 100644 --- a/packages/opendesign/src/components/switch/__demo__/SwitchSlots.vue +++ b/packages/opendesign/src/components/switch/__demo__/SwitchSlots.vue @@ -1,6 +1,6 @@