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
parent
commit
e74661f509
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      components/checkbox/Checkbox.tsx
  2. 15
      components/checkbox/Group.tsx
  3. 15
      components/checkbox/GroupContext.ts

6
components/checkbox/Checkbox.tsx

@ -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';

15
components/checkbox/Group.tsx

@ -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);

15
components/checkbox/GroupContext.ts

@ -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;
Loading…
Cancel
Save