Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(checkbox-group): 新增keys可配置options的value和label的别名 #3154

Merged
merged 5 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/checkbox-group/checkbox-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default class CheckBoxGroup extends SuperComponent {
},

initWithOptions() {
const { options, value } = this.data;
const { options, value, keys } = this.data;

if (!options?.length || !Array.isArray(options)) return;

Expand All @@ -129,7 +129,12 @@ export default class CheckBoxGroup extends SuperComponent {
value: item,
checked: value?.includes(item),
}
: { ...item, checked: value?.includes(item.value) };
: {
...item,
label: item[keys?.label ?? 'label'],
value: item[keys?.value ?? 'value'],
checked: value?.includes(item[keys?.value ?? 'value']),
};
});

this.setData({
Expand Down
9 changes: 7 additions & 2 deletions src/checkbox-group/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ const props: TdCheckboxGroupProps = {
type: Boolean,
value: false,
},
/** 是否禁用组件,默认为 false。 CheckboxGroup.disabled < Checkbox.disabled ,后续新增 Form 组件后,Form.disabled 优先级最低 */
/** 是否禁用组件。优先级:Form.disabled < CheckboxGroup.disabled < Checkbox.disabled */
disabled: {
type: Boolean,
type: null,
value: undefined,
},
/** 用来定义 value / label 在 `options` 中对应的字段别名 */
keys: {
type: Object,
},
/** 支持最多选中的数量 */
max: {
Expand Down
11 changes: 10 additions & 1 deletion src/checkbox-group/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* 该文件为脚本自动生成文件,请勿随意修改。如需修改请联系 PMC
* */

import { KeysType } from '../common/common';

export interface TdCheckboxGroupProps<T = CheckboxGroupValue> {
/**
* 是否开启无边框模式
Expand All @@ -14,12 +16,19 @@ export interface TdCheckboxGroupProps<T = CheckboxGroupValue> {
value?: boolean;
};
/**
* 是否禁用组件,默认为 false。 CheckboxGroup.disabled < Checkbox.disabled ,后续新增 Form 组件后,Form.disabled 优先级最低
* 是否禁用组件。优先级:Form.disabled < CheckboxGroup.disabled < Checkbox.disabled
*/
disabled?: {
type: BooleanConstructor;
value?: boolean;
};
/**
* 用来定义 value / label 在 `options` 中对应的字段别名
*/
keys?: {
type: ObjectConstructor;
value?: KeysType;
};
/**
* 支持最多选中的数量
*/
Expand Down
3 changes: 3 additions & 0 deletions src/checkbox/README.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ value | String / Number / Boolean | - | value of checkbox。Typescript:`string
name | params | description
-- | -- | --
change | `(checked: boolean, context: { value: boolean\|number\|string, label: boolean\|number\|string })` | \-

### Checkbox External Classes

className | Description
Expand All @@ -49,6 +50,8 @@ name | type | default | description | required
style | Object | - | CSS(Cascading Style Sheets) | N
custom-style | Object | - | CSS(Cascading Style Sheets),used to set style on virtual component | N
borderless | Boolean | false | \- | N
disabled | Boolean | undefined | \- | N
keys | Object | - | Typescript:`KeysType`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | N
max | Number | undefined | \- | N
name | String | - | \- | N
options | Array | [] | Typescript:`Array<CheckboxOption>` `type CheckboxOption = string \| number \| CheckboxOptionObj` `interface CheckboxOptionObj { label?: string; value?: string \| number; disabled?: boolean; checkAll?: true }`。[see more ts definition](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/checkbox-group/type.ts) | N
Expand Down
4 changes: 3 additions & 1 deletion src/checkbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ value | String / Number / Boolean | - | 多选框的值。TS 类型:`string \|
名称 | 参数 | 描述
-- | -- | --
change | `(checked: boolean, context: { value: boolean\|number\|string, label: boolean\|number\|string })` | 值变化时触发。`context` 表示当前点击项内容。

### Checkbox External Classes

类名 | 描述
Expand All @@ -114,6 +115,8 @@ t-class-label | 标签样式类
style | Object | - | 样式 | N
custom-style | Object | - | 样式,一般用于开启虚拟化组件节点场景 | N
borderless | Boolean | false | 是否开启无边框模式 | N
disabled | Boolean | undefined | 是否禁用组件。优先级:Form.disabled < CheckboxGroup.disabled < Checkbox.disabled | N
keys | Object | - | 用来定义 value / label 在 `options` 中对应的字段别名。TS 类型:`KeysType`。[通用类型定义](https://github.com/Tencent/tdesign-miniprogram/blob/develop/src/common/common.ts) | 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 { label?: string; value?: string \| number; disabled?: boolean; checkAll?: true }`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/src/checkbox-group/type.ts) | N
Expand All @@ -125,7 +128,6 @@ default-value | Array | undefined | 选中值。非受控属性。TS 类型:`T
名称 | 参数 | 描述
-- | -- | --
change | `(value: CheckboxGroupValue, context: { value: boolean\|number\|string, label: boolean\|number\|string })` | 值变化时触发。`context` 表示当前点击项内容。

### CSS Variables

组件提供了下列 CSS 变量,可用于自定义样式。
Expand Down
4 changes: 0 additions & 4 deletions src/checkbox/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ const props: TdCheckboxProps = {
type: null,
value: undefined,
},
/** 组件类名,分别用于设置 组件外层、多选框图标、主文案、内容 等元素类名 */
externalClasses: {
type: Array,
},
/** 自定义选中图标和非选中图标。使用 Array 时表示:`[选中态图标,非选中态图标,半选中态图标]`。使用 String 时,值为 circle 表示填充圆形图标、值为 line 表示描边型图标、值为 rectangle 表示填充矩形图标 */
icon: {
type: null,
Expand Down
7 changes: 0 additions & 7 deletions src/checkbox/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ export interface TdCheckboxProps {
type: BooleanConstructor;
value?: boolean;
};
/**
* 组件类名,分别用于设置 组件外层、多选框图标、主文案、内容 等元素类名
*/
externalClasses?: {
type: ArrayConstructor;
value?: ['t-class', 't-class-icon', 't-class-label', 't-class-content', 't-class-border'];
};
/**
* 自定义选中图标和非选中图标。使用 Array 时表示:`[选中态图标,非选中态图标,半选中态图标]`。使用 String 时,值为 circle 表示填充圆形图标、值为 line 表示描边型图标、值为 rectangle 表示填充矩形图标
* @default 'circle'
Expand Down
Loading