Skip to content

Commit

Permalink
feat(checkbox): new checkbox
Browse files Browse the repository at this point in the history
  • Loading branch information
jarmywang committed Mar 22, 2023
1 parent 25274e7 commit 57eee61
Show file tree
Hide file tree
Showing 35 changed files with 619 additions and 488 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down
20 changes: 20 additions & 0 deletions src/checkbox-group/checkbox-group.en-US.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
:: BASE_DOC ::

## API
### CheckboxGroup Props

name | type | default | description | required
-- | -- | -- | -- | --
disabled | Boolean | - | \- | N
max | Number | undefined | \- | N
name | String | - | \- | N
options | Array | - | Typescript:`Array<CheckboxOption>` `type CheckboxOption = string \| number \| CheckboxOptionObj` `interface CheckboxOptionObj extends TdCheckboxProps { text?: string; }`[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<string \| number \| boolean>`[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<string \| number \| boolean>`[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`<br/>[see more ts definition](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts)。<br/>`interface CheckboxGroupChangeContext { e: Event; current: string \| number; option: CheckboxOption \| TdCheckboxProps; type: 'check' \| 'uncheck' }`<br/> | 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)。<br/>`interface CheckboxGroupChangeContext { e: Event; current: string \| number; option: CheckboxOption \| TdCheckboxProps; type: 'check' \| 'uncheck' }`<br/>
20 changes: 20 additions & 0 deletions src/checkbox-group/checkbox-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
:: 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<CheckboxOption>` `type CheckboxOption = string \| number \| CheckboxOptionObj` `interface CheckboxOptionObj extends TdCheckboxProps { text?: string; }`[详细类型定义](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<string \| number \| boolean>`[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts) | N
defaultValue | Array | [] | 选中值。非受控属性。TS 类型:`T` `type CheckboxGroupValue = Array<string \| number \| boolean>`[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts) | N
onChange | Function | | TS 类型:`(value: T, context: CheckboxGroupChangeContext) => void`<br/>值变化时触发。`context.current` 表示当前变化的数据项,如果是全选则为空;`context.type` 表示引起选中数据变化的是选中或是取消选中,`context.option` 表示当前变化的数据项。[详细类型定义](https://github.com/Tencent/tdesign-mobile-vue/tree/develop/src/checkbox/type.ts)。<br/>`interface CheckboxGroupChangeContext { e: Event; current: string \| number; option: CheckboxOption \| TdCheckboxProps; type: 'check' \| 'uncheck' }`<br/> | 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)。<br/>`interface CheckboxGroupChangeContext { e: Event; current: string \| number; option: CheckboxOption \| TdCheckboxProps; type: 'check' \| 'uncheck' }`<br/>
68 changes: 34 additions & 34 deletions src/checkbox/__test__/__snapshots__/demo.test.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ exports[`Checkbox > Checkbox baseVue demo works fine 1`] = `
class="t-checkbox-group checkbox-group-demo"
data-v-11729813=""
>
<div
class="t-checkbox"
data-v-11729813=""
Expand Down Expand Up @@ -252,7 +252,7 @@ exports[`Checkbox > Checkbox baseVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--left"
/>
</div>
</div>
</div>
`;
Expand Down Expand Up @@ -513,7 +513,7 @@ exports[`Checkbox > Checkbox groupVue demo works fine 1`] = `
data-v-336087ad=""
>
<span>
<div
class="t-checkbox t-is-indeterminate"
>
Expand Down Expand Up @@ -700,7 +700,7 @@ exports[`Checkbox > Checkbox groupVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--left"
/>
</div>
</span>
</div>
</div>
Expand All @@ -714,7 +714,7 @@ exports[`Checkbox > Checkbox iconVue demo works fine 1`] = `
class="t-checkbox-group checkbox-group-demo"
data-v-4c12b9bb=""
>
<div
class="t-checkbox"
data-v-4c12b9bb=""
Expand Down Expand Up @@ -856,7 +856,7 @@ exports[`Checkbox > Checkbox iconVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--left"
/>
</div>
</div>
</div>
`;
Expand Down Expand Up @@ -925,7 +925,7 @@ exports[`Checkbox > Checkbox maxVue demo works fine 1`] = `
class="t-checkbox-group checkbox-group-demo"
data-v-cd906cdc=""
>
<div
class="t-checkbox t-is-checked"
data-v-cd906cdc=""
Expand Down Expand Up @@ -1069,7 +1069,7 @@ exports[`Checkbox > Checkbox maxVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--left"
/>
</div>
</div>
</div>
`;
Expand Down Expand Up @@ -1102,15 +1102,15 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
>
基础多选框
</p>
<div
data-v-11729813=""
>
<div
class="t-checkbox-group checkbox-group-demo"
data-v-11729813=""
>
<div
class="t-checkbox"
data-v-11729813=""
Expand Down Expand Up @@ -1354,10 +1354,10 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--left"
/>
</div>
</div>
</div>
</div>
<div
class="tdesign-mobile-demo-block"
Expand All @@ -1368,15 +1368,15 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
>
右侧多选框
</p>
<div
data-v-2e3e3cca=""
>
<div
class="t-checkbox-group checkbox-group-demo"
data-v-2e3e3cca=""
>
<div
class="t-checkbox"
data-v-2e3e3cca=""
Expand Down Expand Up @@ -1567,10 +1567,10 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--right"
/>
</div>
</div>
</div>
</div>
<div
class="tdesign-mobile-demo-block"
Expand All @@ -1581,7 +1581,7 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
>
带全选多选框
</p>
<div
data-v-336087ad=""
>
Expand All @@ -1590,7 +1590,7 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
data-v-336087ad=""
>
<span>
<div
class="t-checkbox t-is-indeterminate"
>
Expand Down Expand Up @@ -1777,11 +1777,11 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--left"
/>
</div>
</span>
</div>
</div>
</div>
<div
class="tdesign-mobile-demo-block"
Expand All @@ -1792,15 +1792,15 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
>
限制最多可选数量
</p>
<div
data-v-cd906cdc=""
>
<div
class="t-checkbox-group checkbox-group-demo"
data-v-cd906cdc=""
>
<div
class="t-checkbox t-is-checked"
data-v-cd906cdc=""
Expand Down Expand Up @@ -1944,10 +1944,10 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--left"
/>
</div>
</div>
</div>
</div>
<div
class="tdesign-mobile-demo-block"
Expand All @@ -1962,7 +1962,7 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
>
多选框禁用态
</p>
<div
class="checkbox-demo"
data-v-3fba2a16=""
Expand Down Expand Up @@ -2207,7 +2207,7 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
/>
</div>
</div>
</div>
<div
class="tdesign-mobile-demo-block"
Expand All @@ -2222,15 +2222,15 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
>
自定义图标多选框
</p>
<div
data-v-4c12b9bb=""
>
<div
class="t-checkbox-group checkbox-group-demo"
data-v-4c12b9bb=""
>
<div
class="t-checkbox"
data-v-4c12b9bb=""
Expand Down Expand Up @@ -2372,10 +2372,10 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--left"
/>
</div>
</div>
</div>
</div>
<div
class="tdesign-mobile-demo-block"
Expand All @@ -2390,7 +2390,7 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
>
多选框尺寸规格
</p>
<div
data-v-aaeb4d7a=""
>
Expand Down Expand Up @@ -2489,7 +2489,7 @@ exports[`Checkbox > Checkbox mobileVue demo works fine 1`] = `
/>
</div>
</div>
</div>
</div>
</div>
Expand All @@ -2503,7 +2503,7 @@ exports[`Checkbox > Checkbox rightVue demo works fine 1`] = `
class="t-checkbox-group checkbox-group-demo"
data-v-2e3e3cca=""
>
<div
class="t-checkbox"
data-v-2e3e3cca=""
Expand Down Expand Up @@ -2694,7 +2694,7 @@ exports[`Checkbox > Checkbox rightVue demo works fine 1`] = `
class="t-checkbox__border t-checkbox__border--right"
/>
</div>
</div>
</div>
`;
Expand Down
24 changes: 12 additions & 12 deletions src/checkbox/__test__/demo.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@
*/

import { mount } from '@vue/test-utils';
import allVue from '@/checkbox/demos/all.vue';
import baseVue from '@/checkbox/demos/base.vue';
import disableVue from '@/checkbox/demos/disable.vue';
import groupVue from '@/checkbox/demos/group.vue';
import iconVue from '@/checkbox/demos/icon.vue';
import indeterminateVue from '@/checkbox/demos/indeterminate.vue';
import maxVue from '@/checkbox/demos/max.vue';
import cardVue from '@/checkbox/demos/card.vue';
import horizontalVue from '@/checkbox/demos/horizontal.vue';
import mobileVue from '@/checkbox/demos/mobile.vue';
import rightVue from '@/checkbox/demos/right.vue';
import sizeVue from '@/checkbox/demos/size.vue';
import specialVue from '@/checkbox/demos/special.vue';
import statusVue from '@/checkbox/demos/status.vue';
import typeVue from '@/checkbox/demos/type.vue';

const mapper = {
allVue,
baseVue,
disableVue,
groupVue,
iconVue,
indeterminateVue,
maxVue,
cardVue,
horizontalVue,
mobileVue,
rightVue,
sizeVue,
specialVue,
statusVue,
typeVue,
};

describe('Checkbox', () => {
Expand Down
Loading

0 comments on commit 57eee61

Please sign in to comment.