Skip to content

Commit f393a86

Browse files
authored
feat(ui): DOMA-12433 allow Checkbox to receive value and export Checkbox.Group, to make it all work in forms (#6776)
* feat(ui): DOMA-12433 allow Checkbox to receive value and export Checkbox.Group, to make it all work in forms * refactor(ui): DOMA-12433 move CheckboxGroup to another file and disable unneded props for it * chore(ui): DOMA-12433 fix typos * chore(resident-app): DOMA-12433 remove "key" prop * chore(resident-app): DOMA-12433 add Radio.Group, add id, className in his props, deprecate old export RadioGroup * chore(ui): DOMA-12433 fighting with sonarcloud
1 parent 57b8e8f commit f393a86

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

packages/ui/src/components/Checkbox/checkbox.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export type CheckboxProps = Pick<DefaultCheckboxProps,
2525
| 'className'
2626
| 'onMouseLeave'
2727
| 'onMouseEnter'
28-
| 'tabIndex'> & CondoCheckboxProps
28+
| 'tabIndex'
29+
| 'value'> & CondoCheckboxProps
2930

3031
const Checkbox: React.FC<CheckboxProps> = (props) => {
3132
const {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Checkbox as DefaultCheckbox } from 'antd'
2+
import React from 'react'
3+
4+
import type { ComponentProps } from 'react'
5+
6+
const DefaultCheckboxGroup = DefaultCheckbox.Group
7+
type DefaultCheckboxGroupProps = ComponentProps<typeof DefaultCheckboxGroup>
8+
9+
export type CheckboxGroupProps = Pick<DefaultCheckboxGroupProps,
10+
'children'
11+
| 'className'
12+
| 'name'
13+
| 'disabled'
14+
| 'onChange'
15+
| 'defaultValue'
16+
| 'value'>
17+
18+
const CheckboxGroup = React.forwardRef<HTMLDivElement, CheckboxGroupProps>((props, ref) => {
19+
return <DefaultCheckboxGroup ref={ref} {...props}>{props.children}</DefaultCheckboxGroup>
20+
})
21+
22+
CheckboxGroup.displayName = 'CheckboxGroup'
23+
24+
export {
25+
CheckboxGroup,
26+
}
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { Checkbox } from './checkbox'
1+
import { Checkbox as CheckboxComponent } from './checkbox'
2+
import { CheckboxGroup } from './checkboxGroup'
23
import './style.less'
34

5+
type CheckboxType = typeof CheckboxComponent & {
6+
Group: typeof CheckboxGroup
7+
}
8+
9+
const Checkbox = CheckboxComponent as CheckboxType
10+
Checkbox.Group = CheckboxGroup
11+
412
export type { CheckboxProps } from './checkbox'
513
export { Checkbox }
Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1-
import { Radio } from './radio'
1+
import { Radio as RadioComponent } from './radio'
22
import { RadioGroup } from './radiogroup'
33
import './style.less'
44

5+
type RadioType = typeof RadioComponent & {
6+
Group: typeof RadioGroup
7+
}
8+
9+
const Radio = RadioComponent as RadioType
10+
Radio.Group = RadioGroup
11+
12+
/** @deprecated we will remove this import in next major release, use {@link Radio.Group} instead */
13+
const DeprecatedRadioGroup = RadioGroup
14+
515
export type { RadioProps } from './radio'
616
export type { RadioGroupProps, ItemGroupProps } from './radiogroup'
7-
export { Radio, RadioGroup }
17+
18+
export {
19+
Radio,
20+
DeprecatedRadioGroup as RadioGroup,
21+
}
822

packages/ui/src/components/Radio/radio.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,7 @@ type CondoRadioProps = {
1818
export type RadioProps = Pick<DefaultRadioProps, 'autoFocus' | 'defaultChecked' | 'disabled' | 'onChange' | 'checked' | 'value' | 'children' | 'id'>
1919
& CondoRadioProps
2020

21-
export interface IRadio {
22-
(props: RadioProps): React.ReactElement
23-
}
24-
25-
const Radio: IRadio = (props) => {
21+
const Radio: React.FC<RadioProps> = (props) => {
2622
const { label, icon, labelProps, disabled, onChange, children, id, ...rest } = props
2723

2824
const handleChange = useCallback((event: RadioChangeEvent) => {

packages/ui/src/components/Radio/radiogroup.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export type ItemGroupProps = {
1919
options: Array<ItemGroupOptionType>
2020
}
2121

22-
export type RadioGroupProps = Pick<DefaultRadioGroupProps, 'value' | 'onChange' | 'disabled' | 'children' | 'optionType' | 'defaultValue'>
22+
export type RadioGroupProps = Pick<DefaultRadioGroupProps, 'id' | 'className' | 'value' | 'onChange' | 'disabled' | 'children' | 'optionType' | 'defaultValue'>
2323

2424
type CompoundedComponent = React.FC<RadioGroupProps> & {
2525
ItemGroup: React.FC<ItemGroupProps>

0 commit comments

Comments
 (0)