Skip to content

Commit

Permalink
feat(switch): support before change
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Oct 29, 2024
1 parent c7b1412 commit 1cf99a9
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 0 deletions.
Binary file modified db/TDesign.db
Binary file not shown.
1 change: 1 addition & 0 deletions packages/products/tdesign-react/src/switch/switch.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ name | type | default | description | required
-- | -- | -- | -- | --
className | String | - | className of component | N
style | Object | - | CSS(Cascading Style Sheets),Typescript:`React.CSSProperties` | N
beforeChange | Function | - | stop one of files to upload。Typescript:`() => boolean \| Promise<boolean>` | N
customValue | Array | - | Typescript:`Array<SwitchValue>` | N
disabled | Boolean | undefined | \- | N
label | TNode | [] | Typescript:`Array<string \| TNode> \| TNode<{ value: SwitchValue }>`[see more ts definition](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N
Expand Down
1 change: 1 addition & 0 deletions packages/products/tdesign-react/src/switch/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-- | -- | -- | -- | --
className | String | - | 类名 | N
style | Object | - | 样式,TS 类型:`React.CSSProperties` | N
beforeChange | Function | - | Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。。TS 类型:`() => boolean \| Promise<boolean>` | N
customValue | Array | - | 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]['open', 'close']。TS 类型:`Array<SwitchValue>` | N
disabled | Boolean | undefined | 是否禁用组件。优先级:Switch.disabled > Form.disabled | N
label | TNode | [] | 开关内容,[开启时内容,关闭时内容]。示例:['开', '关'] 或 (value) => value ? '开' : '关'。TS 类型:`Array<string \| TNode> \| TNode<{ value: SwitchValue }>`[通用类型定义](https://github.com/Tencent/tdesign-react/blob/develop/src/common.ts) | N
Expand Down
4 changes: 4 additions & 0 deletions packages/products/tdesign-react/src/switch/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { TNode } from '../common';
import { MouseEvent } from 'react';

export interface TdSwitchProps<T = SwitchValue> {
/**
* Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。
*/
beforeChange?: () => boolean | Promise<boolean>;
/**
* 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]、['open', 'close']
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/products/tdesign-vue-next/src/switch/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { TdSwitchProps } from './type';
import { PropType } from 'vue';

export default {
/** Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。 */
beforeChange: {
type: Function as PropType<TdSwitchProps['beforeChange']>,
},
/** 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]、['open', 'close'] */
customValue: {
type: Array as PropType<TdSwitchProps['customValue']>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

name | type | default | description | required
-- | -- | -- | -- | --
beforeChange | Function | - | stop one of files to upload。Typescript:`() => boolean \| Promise<boolean>` | N
customValue | Array | - | Typescript:`Array<SwitchValue>` | N
disabled | Boolean | undefined | \- | N
label | Array / Slot / Function | [] | Typescript:`Array<string \| TNode> \| TNode<{ value: SwitchValue }>`[see more ts definition](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
Expand Down
1 change: 1 addition & 0 deletions packages/products/tdesign-vue-next/src/switch/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

名称 | 类型 | 默认值 | 描述 | 必传
-- | -- | -- | -- | --
beforeChange | Function | - | Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。。TS 类型:`() => boolean \| Promise<boolean>` | N
customValue | Array | - | 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]['open', 'close']。TS 类型:`Array<SwitchValue>` | N
disabled | Boolean | undefined | 是否禁用组件。优先级:Switch.disabled > Form.disabled | N
label | Array / Slot / Function | [] | 开关内容,[开启时内容,关闭时内容]。示例:['开', '关'] 或 (value) => value ? '开' : '关'。TS 类型:`Array<string \| TNode> \| TNode<{ value: SwitchValue }>`[通用类型定义](https://github.com/Tencent/tdesign-vue-next/blob/develop/src/common.ts) | N
Expand Down
4 changes: 4 additions & 0 deletions packages/products/tdesign-vue-next/src/switch/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import { TNode } from '../common';

export interface TdSwitchProps<T = SwitchValue> {
/**
* Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。
*/
beforeChange?: () => boolean | Promise<boolean>;
/**
* 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]、['open', 'close']
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/products/tdesign-vue/src/switch/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { TdSwitchProps } from './type';
import { PropType } from 'vue';

export default {
/** Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。 */
beforeChange: {
type: Function as PropType<TdSwitchProps['beforeChange']>,
},
/** 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]、['open', 'close'] */
customValue: {
type: Array as PropType<TdSwitchProps['customValue']>,
Expand Down
1 change: 1 addition & 0 deletions packages/products/tdesign-vue/src/switch/switch.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

name | type | default | description | required
-- | -- | -- | -- | --
beforeChange | Function | - | stop one of files to upload。Typescript:`() => boolean \| Promise<boolean>` | N
customValue | Array | - | Typescript:`Array<SwitchValue>` | N
disabled | Boolean | undefined | \- | N
label | Array / Slot / Function | [] | Typescript:`Array<string \| TNode> \| TNode<{ value: SwitchValue }>`[see more ts definition](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
Expand Down
1 change: 1 addition & 0 deletions packages/products/tdesign-vue/src/switch/switch.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

名称 | 类型 | 默认值 | 描述 | 必传
-- | -- | -- | -- | --
beforeChange | Function | - | Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。。TS 类型:`() => boolean \| Promise<boolean>` | N
customValue | Array | - | 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]['open', 'close']。TS 类型:`Array<SwitchValue>` | N
disabled | Boolean | undefined | 是否禁用组件。优先级:Switch.disabled > Form.disabled | N
label | Array / Slot / Function | [] | 开关内容,[开启时内容,关闭时内容]。示例:['开', '关'] 或 (value) => value ? '开' : '关'。TS 类型:`Array<string \| TNode> \| TNode<{ value: SwitchValue }>`[通用类型定义](https://github.com/Tencent/tdesign-vue/blob/develop/src/common.ts) | N
Expand Down
4 changes: 4 additions & 0 deletions packages/products/tdesign-vue/src/switch/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
import { TNode } from '../common';

export interface TdSwitchProps<T = SwitchValue> {
/**
* Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。
*/
beforeChange?: () => boolean | Promise<boolean>;
/**
* 用于自定义开关的值,[打开时的值,关闭时的值]。默认为 [true, false]。示例:[1, 0]、['open', 'close']
*/
Expand Down
41 changes: 41 additions & 0 deletions packages/scripts/api.json
Original file line number Diff line number Diff line change
Expand Up @@ -109834,6 +109834,47 @@
"String"
]
},
{
"id": 1730199095,
"platform_framework": [
"1",
"2",
"4"
],
"component": "Switch",
"field_category": 1,
"field_name": "beforeChange",
"field_type": [
"32"
],
"field_default_value": "",
"field_enum": "",
"field_desc_zh": "Switch 切换状态前的回调方法,常用于需要发起异步请求的场景,回到返回值支持布尔和 Promise 类型,返回`false`或 Promise reject不继续执行change,否则则继续执行。",
"field_desc_en": "stop one of files to upload",
"field_required": 0,
"event_input": "",
"create_time": "2024-10-29 10:51:35",
"update_time": "2024-10-29 10:51:35",
"event_output": null,
"custom_field_type": "() => boolean | Promise<boolean>",
"syntactic_sugar": null,
"readonly": 1,
"html_attribute": 0,
"trigger_elements": "",
"deprecated": 0,
"version": "",
"test_description": null,
"support_default_value": 0,
"field_category_text": "Props",
"platform_framework_text": [
"Vue(PC)",
"React(PC)",
"Angular(PC)"
],
"field_type_text": [
"Function"
]
},
{
"id": 1537,
"platform_framework": [
Expand Down

0 comments on commit 1cf99a9

Please sign in to comment.