Skip to content

refactor:checkbox #6248

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

Merged
merged 4 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
docs:update & refactor: checkbox type
  • Loading branch information
shifeng1993 committed Feb 12, 2023
commit a247a2f43a642e0952de767298579ae61b6db507
2 changes: 1 addition & 1 deletion components/checkbox/index.en-US.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
category: Components
type: Data Entry
title: Checkbox
cover: https://gw.alipayobjects.com/zos/alicdn/8nbVbHEm_/CheckBox.svg
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*DzgiRbW3khIAAAAAAAAAAAAADrJ8AQ/original
---

Checkbox component.
Expand Down
2 changes: 1 addition & 1 deletion components/checkbox/index.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ category: Components
subtitle: 多选框
type: 数据录入
title: Checkbox
cover: https://gw.alipayobjects.com/zos/alicdn/8nbVbHEm_/CheckBox.svg
cover: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*DzgiRbW3khIAAAAAAAAAAAAADrJ8AQ/original
---

多选框。
Expand Down
44 changes: 21 additions & 23 deletions components/checkbox/interface.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { ExtractPropTypes, InjectionKey, PropType, Ref } from 'vue';
import type { ExtractPropTypes, InjectionKey, Ref } from 'vue';
import type { MouseEventHandler } from '../_util/EventInterface';
import type { VueNode } from '../_util/type';
import PropTypes from '../_util/vue-types';
import { booleanType, functionType, stringType, arrayType } from '../_util/type';

export type CheckboxValueType = string | number | boolean;
export interface CheckboxOptionType {
Expand All @@ -27,10 +28,9 @@ export const abstractCheckboxGroupProps = () => {
return {
name: String,
prefixCls: String,
options: {
type: Array as PropType<Array<CheckboxOptionType | string | number>>,
default: () => [] as Array<CheckboxOptionType | string | number>,
},
options: arrayType<Array<CheckboxOptionType | string | number>>(
[] as Array<CheckboxOptionType | string | number>,
),
disabled: Boolean,
id: String,
};
Expand All @@ -39,12 +39,10 @@ export const abstractCheckboxGroupProps = () => {
export const checkboxGroupProps = () => {
return {
...abstractCheckboxGroupProps(),
defaultValue: { type: Array as PropType<Array<CheckboxValueType>> },
value: { type: Array as PropType<Array<CheckboxValueType>> },
onChange: { type: Function as PropType<(checkedValue: Array<CheckboxValueType>) => void> },
'onUpdate:value': {
type: Function as PropType<(checkedValue: Array<CheckboxValueType>) => void>,
},
defaultValue: arrayType<Array<CheckboxValueType>>(),
value: arrayType<Array<CheckboxValueType>>(),
onChange: functionType<(checkedValue: Array<CheckboxValueType>) => void>(),
'onUpdate:value': functionType<(checkedValue: Array<CheckboxValueType>) => void>(),
};
};

Expand All @@ -53,27 +51,27 @@ export type CheckboxGroupProps = Partial<ExtractPropTypes<ReturnType<typeof chec
export const abstractCheckboxProps = () => {
return {
prefixCls: String,
defaultChecked: { type: Boolean, default: undefined },
checked: { type: Boolean, default: undefined },
disabled: { type: Boolean, default: undefined },
isGroup: { type: Boolean, default: undefined },
defaultChecked: booleanType(),
checked: booleanType(),
disabled: booleanType(),
isGroup: booleanType(),
value: PropTypes.any,
name: String,
id: String,
indeterminate: { type: Boolean, default: undefined },
type: { type: String, default: 'checkbox' },
autofocus: { type: Boolean, default: undefined },
onChange: Function as PropType<(e: CheckboxChangeEvent) => void>,
'onUpdate:checked': Function as PropType<(checked: boolean) => void>,
onClick: Function as PropType<MouseEventHandler>,
skipGroup: { type: Boolean, default: false },
indeterminate: booleanType(),
type: stringType('checkbox'),
autofocus: booleanType(),
onChange: functionType<(e: CheckboxChangeEvent) => void>(),
'onUpdate:checked': functionType<(checked: boolean) => void>(),
onClick: functionType<MouseEventHandler>(),
skipGroup: booleanType(false),
};
};

export const checkboxProps = () => {
return {
...abstractCheckboxProps(),
indeterminate: { type: Boolean, default: false },
indeterminate: booleanType(false),
};
};

Expand Down