diff --git a/package.json b/package.json index 6ce5bec62..e868f23cd 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,7 @@ "@vueuse/core": "^8.2.5", "dayjs": "^1.10.7", "lodash": "^4.17.21", - "tdesign-icons-vue-next": "^0.1.3" + "tdesign-icons-vue-next": "^0.1.8" }, "peerDependencies": { "vue": "^3.2.6" @@ -159,7 +159,7 @@ "rollup-plugin-terser": "^7.0.2", "rollup-plugin-vue": "^6.0.0", "rollup-pluginutils": "^2.8.2", - "tdesign-icons-view": "^0.1.0", + "tdesign-icons-view": "^0.1.6", "tdesign-publish-cli": "^0.0.10", "tdesign-site-components": "^0.11.19", "tslib": "^2.3.1", diff --git a/src/checkbox/checkbox-group.en-US.md b/src/checkbox/checkbox-group.en-US.md new file mode 100644 index 000000000..b7e902094 --- /dev/null +++ b/src/checkbox/checkbox-group.en-US.md @@ -0,0 +1,21 @@ +:: BASE_DOC :: + +## API + +### CheckboxGroup Props + +name | type | default | description | required +-- | -- | -- | -- | -- +disabled | Boolean | - | \- | N +max | Number | undefined | \- | N +name | String | - | \- | N +options | Array | - | Typescript:`Array` `type CheckboxOption = string \| number \| CheckboxOptionObj` `interface CheckboxOptionObj { label?: string \| TNode; value?: string \| number; disabled?: boolean; name?: string; checkAll?: true }`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts)。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts) | N +value | Array | [] | `v-model` and `v-model:value` is supported。Typescript:`T` `type CheckboxGroupValue = Array`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts) | N +defaultValue | Array | [] | uncontrolled property。Typescript:`T` `type CheckboxGroupValue = Array`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts) | N +onChange | Function | | Typescript:`(value: T, context: CheckboxGroupChangeContext) => void`
[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts)。
`interface CheckboxGroupChangeContext { e: Event; current: string \| number; option: CheckboxOption \| TdCheckboxProps; type: 'check' \| 'uncheck' }`
| N + +### CheckboxGroup Events + +name | params | description +-- | -- | -- +change | `(value: T, context: CheckboxGroupChangeContext)` | [see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts)。
`interface CheckboxGroupChangeContext { e: Event; current: string \| number; option: CheckboxOption \| TdCheckboxProps; type: 'check' \| 'uncheck' }`
diff --git a/src/checkbox/checkbox-group.md b/src/checkbox/checkbox-group.md new file mode 100644 index 000000000..c203fa63f --- /dev/null +++ b/src/checkbox/checkbox-group.md @@ -0,0 +1,21 @@ +:: BASE_DOC :: + +## API + +### CheckboxGroup Props + +名称 | 类型 | 默认值 | 说明 | 必传 +-- | -- | -- | -- | -- +disabled | Boolean | - | 是否禁用组件,默认为 false。CheckboxGroup.disabled 优先级低于 Checkbox.disabled | N +max | Number | undefined | 支持最多选中的数量 | N +name | String | - | 统一设置内部复选框 HTML 属性 | N +options | Array | - | 以配置形式设置子元素。示例1:`['北京', '上海']` ,示例2: `[{ label: '全选', checkAll: true }, { label: '上海', value: 'shanghai' }]`。checkAll 值为 true 表示当前选项为「全选选项」。TS 类型:`Array` `type CheckboxOption = string \| number \| CheckboxOptionObj` `interface CheckboxOptionObj { label?: string \| TNode; value?: string \| number; disabled?: boolean; name?: string; checkAll?: true }`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts)。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts) | N +value | Array | [] | 选中值。支持语法糖 `v-model` 或 `v-model:value`。TS 类型:`T` `type CheckboxGroupValue = Array`。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts) | N +defaultValue | Array | [] | 选中值。非受控属性。TS 类型:`T` `type CheckboxGroupValue = Array`。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts) | N +onChange | Function | | TS 类型:`(value: T, context: CheckboxGroupChangeContext) => void`
值变化时触发。`context.current` 表示当前变化的数据项,如果是全选则为空;`context.type` 表示引起选中数据变化的是选中或是取消选中,`context.option` 表示当前变化的数据项。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts)。
`interface CheckboxGroupChangeContext { e: Event; current: string \| number; option: CheckboxOption \| TdCheckboxProps; type: 'check' \| 'uncheck' }`
| N + +### CheckboxGroup Events + +名称 | 参数 | 描述 +-- | -- | -- +change | `(value: T, context: CheckboxGroupChangeContext)` | 值变化时触发。`context.current` 表示当前变化的数据项,如果是全选则为空;`context.type` 表示引起选中数据变化的是选中或是取消选中,`context.option` 表示当前变化的数据项。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts)。
`interface CheckboxGroupChangeContext { e: Event; current: string \| number; option: CheckboxOption \| TdCheckboxProps; type: 'check' \| 'uncheck' }`
diff --git a/src/checkbox/group.vue b/src/checkbox/checkbox-group.vue similarity index 82% rename from src/checkbox/group.vue rename to src/checkbox/checkbox-group.vue index 5e9132225..e60cef3a5 100644 --- a/src/checkbox/group.vue +++ b/src/checkbox/checkbox-group.vue @@ -5,10 +5,21 @@ @@ -20,7 +31,7 @@ import config from '../config'; import CheckboxProps from './checkbox-group-props'; import Checkbox from './checkbox.vue'; import { CheckboxGroupValue, TdCheckboxGroupProps, TdCheckboxProps } from './type'; -import { useDefault } from '../shared'; +import { useDefault } from '@/shared'; import { getOptions, setCheckAllStatus } from './hooks'; const { prefix } = config; @@ -39,7 +50,7 @@ export default defineComponent({ emits: ['update:value', 'update:modelValue', 'change'], setup(props: any, context) { const { isArray } = Array; - const [innerValue, setinnerValue] = useDefault( + const [innerValue, setInnerValue] = useDefault( props, context.emit, 'value', @@ -80,7 +91,7 @@ export default defineComponent({ const i = val.indexOf(currentValue); val.splice(i, 1); } - setinnerValue(val, { + setInnerValue(val, { e: data.e, current: data.option.value, type: data.checked ? 'check' : 'uncheck', @@ -102,7 +113,7 @@ export default defineComponent({ }; const onCheckAllChange = (checked: boolean, context: { e: Event; source?: 't-checkbox' }) => { const value = checked ? getAllCheckboxValue() : []; - setinnerValue(value, { + setInnerValue(value, { e: context.e, type: checked ? 'check' : 'uncheck', current: undefined, diff --git a/src/checkbox/checkbox.en-US.md b/src/checkbox/checkbox.en-US.md index fd62f588b..97c9fb3e0 100644 --- a/src/checkbox/checkbox.en-US.md +++ b/src/checkbox/checkbox.en-US.md @@ -13,7 +13,7 @@ content | String / Slot / Function | - | Typescript:`string \| TNode`。[see m contentDisabled | Boolean | - | \- | N default | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N disabled | Boolean | undefined | \- | N -icon | Array | - | Typescript:`Array`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N +icon | String / Array | 'circle' | Typescript:`'circle' \| 'line' \| 'rectangle' \| Array`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N indeterminate | Boolean | false | \- | N label | String / Slot / Function | - | Typescript:`string \| TNode`。[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N maxContentRow | Number | 5 | \- | N diff --git a/src/checkbox/checkbox.md b/src/checkbox/checkbox.md index 0126a58c8..2cd8091f2 100644 --- a/src/checkbox/checkbox.md +++ b/src/checkbox/checkbox.md @@ -13,7 +13,7 @@ content | String / Slot / Function | - | 多选框内容。TS 类型:`string \ contentDisabled | Boolean | - | 是否禁用组件内容(content)触发选中 | N default | String / Slot / Function | - | 多选框内容,同 label。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N disabled | Boolean | undefined | 是否禁用组件。如果父组件存在 CheckboxGroup,默认值由 CheckboxGroup.disabled 控制。Checkbox.disabled 优先级高于 CheckboxGroup.disabled | N -icon | Array | - | 自定义选中图标和非选中图标。示例:[选中态图标,非选中态图标]。TS 类型:`Array`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N +icon | String / Array | 'circle' | 自定义选中图标和非选中图标。使用 Array 时表示:[选中态图标,非选中态图标]。使用 String 时,值为 circle 表示填充圆形图标、值为 line 表示描边型图标、值为 rectangle 表示填充矩形图标。。TS 类型:`'circle' \| 'line' \| 'rectangle' \| Array`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N indeterminate | Boolean | false | 是否为半选 | N label | String / Slot / Function | - | 主文案。TS 类型:`string \| TNode`。[通用类型定义](https://github.com/Tencent/tdesign-mobile-vue/blob/develop/src/common.ts) | N maxContentRow | Number | 5 | 内容最大行数限制 | N diff --git a/src/checkbox/checkbox.vue b/src/checkbox/checkbox.vue index 325c8e291..5fc0e122e 100644 --- a/src/checkbox/checkbox.vue +++ b/src/checkbox/checkbox.vue @@ -1,70 +1,81 @@ diff --git a/src/checkbox/demos/base.vue b/src/checkbox/demos/base.vue index 1efec42c8..369e998bd 100644 --- a/src/checkbox/demos/base.vue +++ b/src/checkbox/demos/base.vue @@ -1,44 +1,35 @@ - diff --git a/src/checkbox/demos/card.vue b/src/checkbox/demos/card.vue new file mode 100644 index 000000000..6a4e5ae0b --- /dev/null +++ b/src/checkbox/demos/card.vue @@ -0,0 +1,14 @@ + + diff --git a/src/checkbox/demos/disable.vue b/src/checkbox/demos/disable.vue deleted file mode 100644 index 4a8463641..000000000 --- a/src/checkbox/demos/disable.vue +++ /dev/null @@ -1,15 +0,0 @@ - - - diff --git a/src/checkbox/demos/group.vue b/src/checkbox/demos/group.vue deleted file mode 100644 index 9a3e33356..000000000 --- a/src/checkbox/demos/group.vue +++ /dev/null @@ -1,34 +0,0 @@ - - - diff --git a/src/checkbox/demos/horizontal.vue b/src/checkbox/demos/horizontal.vue new file mode 100644 index 000000000..ecd2bdcec --- /dev/null +++ b/src/checkbox/demos/horizontal.vue @@ -0,0 +1,25 @@ + + + diff --git a/src/checkbox/demos/icon.vue b/src/checkbox/demos/icon.vue deleted file mode 100644 index e9ff2dd83..000000000 --- a/src/checkbox/demos/icon.vue +++ /dev/null @@ -1,50 +0,0 @@ - - - diff --git a/src/checkbox/demos/indeterminate.vue b/src/checkbox/demos/indeterminate.vue deleted file mode 100644 index bdcbcfaa1..000000000 --- a/src/checkbox/demos/indeterminate.vue +++ /dev/null @@ -1,11 +0,0 @@ - - - diff --git a/src/checkbox/demos/max.vue b/src/checkbox/demos/max.vue deleted file mode 100644 index 9b641b80d..000000000 --- a/src/checkbox/demos/max.vue +++ /dev/null @@ -1,19 +0,0 @@ - - - diff --git a/src/checkbox/demos/mobile.vue b/src/checkbox/demos/mobile.vue index fd5a50e22..f8085c3af 100644 --- a/src/checkbox/demos/mobile.vue +++ b/src/checkbox/demos/mobile.vue @@ -2,37 +2,41 @@

Checkbox 多选框

-

描述文字

- +

用于预设的一组选项中执行多项选择,并呈现选择结果。

+ - - + + - + + + + - - + + - - + + - - + + - - + +
diff --git a/src/checkbox/demos/right.vue b/src/checkbox/demos/right.vue index f66a6f933..1dad33caa 100644 --- a/src/checkbox/demos/right.vue +++ b/src/checkbox/demos/right.vue @@ -1,37 +1,5 @@ - - diff --git a/src/checkbox/demos/size.vue b/src/checkbox/demos/size.vue deleted file mode 100644 index d2f60013c..000000000 --- a/src/checkbox/demos/size.vue +++ /dev/null @@ -1,26 +0,0 @@ - - - diff --git a/src/checkbox/demos/special.vue b/src/checkbox/demos/special.vue new file mode 100644 index 000000000..e1a2e21f2 --- /dev/null +++ b/src/checkbox/demos/special.vue @@ -0,0 +1,79 @@ + + + diff --git a/src/checkbox/demos/status.vue b/src/checkbox/demos/status.vue new file mode 100644 index 000000000..8ae782588 --- /dev/null +++ b/src/checkbox/demos/status.vue @@ -0,0 +1,6 @@ + diff --git a/src/checkbox/demos/type.vue b/src/checkbox/demos/type.vue new file mode 100644 index 000000000..fb32450dd --- /dev/null +++ b/src/checkbox/demos/type.vue @@ -0,0 +1,11 @@ + + diff --git a/src/checkbox/index.ts b/src/checkbox/index.ts index 363c3c6bd..8800e5795 100644 --- a/src/checkbox/index.ts +++ b/src/checkbox/index.ts @@ -1,5 +1,5 @@ import _CheckBox from './checkbox.vue'; -import _CheckBoxGroup from './group.vue'; +import _CheckBoxGroup from './checkbox-group.vue'; import { withInstall, WithInstallType } from '../shared'; import './style'; diff --git a/src/checkbox/props.ts b/src/checkbox/props.ts index f83f33568..8fcd43a6e 100644 --- a/src/checkbox/props.ts +++ b/src/checkbox/props.ts @@ -41,9 +41,10 @@ export default { type: Boolean, default: undefined, }, - /** 自定义选中图标和非选中图标。示例:[选中态图标,非选中态图标] */ + /** 自定义选中图标和非选中图标。使用 Array 时表示:[选中态图标,非选中态图标]。使用 String 时,值为 circle 表示填充圆形图标、值为 line 表示描边型图标、值为 rectangle 表示填充矩形图标。 */ icon: { - type: Array as PropType, + type: [String, Array] as PropType, + default: 'circle', }, /** 是否为半选 */ indeterminate: Boolean, diff --git a/src/checkbox/style/index.js b/src/checkbox/style/index.js index c137486ef..341027bae 100644 --- a/src/checkbox/style/index.js +++ b/src/checkbox/style/index.js @@ -1 +1 @@ -import '../../_common/style/mobile/components/checkbox/_index.less'; +import '../../_common/style/mobile/components/checkbox/v2/_index.less'; diff --git a/src/checkbox/type.ts b/src/checkbox/type.ts index f2b2e196a..219d090a2 100644 --- a/src/checkbox/type.ts +++ b/src/checkbox/type.ts @@ -49,9 +49,10 @@ export interface TdCheckboxProps { */ disabled?: boolean; /** - * 自定义选中图标和非选中图标。示例:[选中态图标,非选中态图标] + * 自定义选中图标和非选中图标。使用 Array 时表示:[选中态图标,非选中态图标]。使用 String 时,值为 circle 表示填充圆形图标、值为 line 表示描边型图标、值为 rectangle 表示填充矩形图标。 + * @default 'circle' */ - icon?: Array; + icon?: 'circle' | 'line' | 'rectangle' | Array; /** * 是否为半选 * @default false @@ -137,12 +138,8 @@ export interface TdCheckboxGroupProps { export type CheckboxOption = string | number | CheckboxOptionObj; -export interface CheckboxOptionObj { - label?: string | TNode; - value?: string | number; - disabled?: boolean; - name?: string; - checkAll?: true; +export interface CheckboxOptionObj extends TdCheckboxProps { + text?: string; } export type CheckboxGroupValue = Array;