Browse Source
refactor: resolve circular reference of Checkbox (#42803)
* refactor: resolve circular reference of Checkbox
* chore: add export
pull/43176/head
Zack Chang
1 year ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with
22 additions and
14 deletions
-
components/checkbox/Checkbox.tsx
-
components/checkbox/Group.tsx
-
components/checkbox/GroupContext.ts
|
|
@ -2,11 +2,11 @@ import classNames from 'classnames'; |
|
|
|
import type { CheckboxRef } from 'rc-checkbox'; |
|
|
|
import RcCheckbox from 'rc-checkbox'; |
|
|
|
import * as React from 'react'; |
|
|
|
import { ConfigContext } from '../config-provider'; |
|
|
|
import { FormItemInputContext } from '../form/context'; |
|
|
|
import warning from '../_util/warning'; |
|
|
|
import { GroupContext } from './Group'; |
|
|
|
import { ConfigContext } from '../config-provider'; |
|
|
|
import DisabledContext from '../config-provider/DisabledContext'; |
|
|
|
import { FormItemInputContext } from '../form/context'; |
|
|
|
import GroupContext from './GroupContext'; |
|
|
|
|
|
|
|
import useStyle from './style'; |
|
|
|
|
|
|
|
|
|
@ -4,6 +4,7 @@ import * as React from 'react'; |
|
|
|
import { ConfigContext } from '../config-provider'; |
|
|
|
import type { CheckboxChangeEvent } from './Checkbox'; |
|
|
|
import Checkbox from './Checkbox'; |
|
|
|
import GroupContext from './GroupContext'; |
|
|
|
|
|
|
|
import useStyle from './style'; |
|
|
|
|
|
|
@ -34,17 +35,6 @@ export interface CheckboxGroupProps extends AbstractCheckboxGroupProps { |
|
|
|
children?: React.ReactNode; |
|
|
|
} |
|
|
|
|
|
|
|
export interface CheckboxGroupContext { |
|
|
|
name?: string; |
|
|
|
toggleOption?: (option: CheckboxOptionType) => void; |
|
|
|
value?: any; |
|
|
|
disabled?: boolean; |
|
|
|
registerValue: (val: string) => void; |
|
|
|
cancelValue: (val: string) => void; |
|
|
|
} |
|
|
|
|
|
|
|
export const GroupContext = React.createContext<CheckboxGroupContext | null>(null); |
|
|
|
|
|
|
|
const InternalCheckboxGroup: React.ForwardRefRenderFunction<HTMLDivElement, CheckboxGroupProps> = ( |
|
|
|
{ |
|
|
|
defaultValue, |
|
|
@ -164,6 +154,9 @@ const InternalCheckboxGroup: React.ForwardRefRenderFunction<HTMLDivElement, Chec |
|
|
|
); |
|
|
|
}; |
|
|
|
|
|
|
|
export type { CheckboxGroupContext } from './GroupContext'; |
|
|
|
export { GroupContext }; |
|
|
|
|
|
|
|
const CheckboxGroup = React.forwardRef<HTMLDivElement, CheckboxGroupProps>(InternalCheckboxGroup); |
|
|
|
|
|
|
|
export default React.memo(CheckboxGroup); |
|
|
|
|
|
@ -0,0 +1,15 @@ |
|
|
|
import React from 'react'; |
|
|
|
import type { CheckboxOptionType } from './Group'; |
|
|
|
|
|
|
|
export interface CheckboxGroupContext { |
|
|
|
name?: string; |
|
|
|
toggleOption?: (option: CheckboxOptionType) => void; |
|
|
|
value?: any; |
|
|
|
disabled?: boolean; |
|
|
|
registerValue: (val: string) => void; |
|
|
|
cancelValue: (val: string) => void; |
|
|
|
} |
|
|
|
|
|
|
|
const GroupContext = React.createContext<CheckboxGroupContext | null>(null); |
|
|
|
|
|
|
|
export default GroupContext; |