diff --git a/packages/bezier-react/src/components/Forms/FormControl/FormControl.tsx b/packages/bezier-react/src/components/Forms/FormControl/FormControl.tsx index 4734837ba6..056fb3bfcb 100644 --- a/packages/bezier-react/src/components/Forms/FormControl/FormControl.tsx +++ b/packages/bezier-react/src/components/Forms/FormControl/FormControl.tsx @@ -28,7 +28,7 @@ import { type HelperTextPropsGetter, type LabelPropsGetter, } from './FormControl.types' -import { FormControlContext } from './FormControlContext' +import { FormControlContextProvider } from './FormControlContext' import * as Styled from './FormControl.styled' @@ -203,7 +203,7 @@ export const FormControl = forwardRef(function Fo if (!children) { return null } return ( - + (function Fo > { children } - + ) }) diff --git a/packages/bezier-react/src/components/Forms/FormControl/FormControlContext.ts b/packages/bezier-react/src/components/Forms/FormControl/FormControlContext.ts index 69c5546c1f..5b83b71956 100644 --- a/packages/bezier-react/src/components/Forms/FormControl/FormControlContext.ts +++ b/packages/bezier-react/src/components/Forms/FormControl/FormControlContext.ts @@ -1,5 +1,8 @@ -import { createContext } from 'react' +import { createContext } from '~/src/utils/reactUtils' import { type FormControlContextValue } from '~/src/components/Forms/FormControl' -export const FormControlContext = createContext(undefined) +export const [ + FormControlContextProvider, + useFormControlContext, +] = createContext(undefined) diff --git a/packages/bezier-react/src/components/Forms/FormControl/index.ts b/packages/bezier-react/src/components/Forms/FormControl/index.ts index 3d5ab0e603..b03edace25 100644 --- a/packages/bezier-react/src/components/Forms/FormControl/index.ts +++ b/packages/bezier-react/src/components/Forms/FormControl/index.ts @@ -1,6 +1,6 @@ export { FormControl } from './FormControl' -export { FormControlContext } from './FormControlContext' +export { useFormControlContext } from './FormControlContext' export type { FormControlProps, diff --git a/packages/bezier-react/src/components/Forms/FormGroup/FormGroup.tsx b/packages/bezier-react/src/components/Forms/FormGroup/FormGroup.tsx index 14b665e860..6acf489dd8 100644 --- a/packages/bezier-react/src/components/Forms/FormGroup/FormGroup.tsx +++ b/packages/bezier-react/src/components/Forms/FormGroup/FormGroup.tsx @@ -3,7 +3,7 @@ import React, { forwardRef } from 'react' import useMergeRefs from '~/src/hooks/useMergeRefs' import { noop } from '~/src/utils/functionUtils' -import useFormControlContext from '~/src/components/Forms/useFormControlContext' +import { useFormControlContext } from '~/src/components/Forms/FormControl' import type FormGroupProps from './FormGroup.types' diff --git a/packages/bezier-react/src/components/Forms/FormHelperText/FormHelperText.tsx b/packages/bezier-react/src/components/Forms/FormHelperText/FormHelperText.tsx index 3ffb475e50..04ec23f013 100644 --- a/packages/bezier-react/src/components/Forms/FormHelperText/FormHelperText.tsx +++ b/packages/bezier-react/src/components/Forms/FormHelperText/FormHelperText.tsx @@ -9,7 +9,7 @@ import useMergeRefs from '~/src/hooks/useMergeRefs' import { noop } from '~/src/utils/functionUtils' import { isEmpty } from '~/src/utils/typeUtils' -import useFormControlContext from '~/src/components/Forms/useFormControlContext' +import { useFormControlContext } from '~/src/components/Forms/FormControl' import type { BaseHelperTextProps, diff --git a/packages/bezier-react/src/components/Forms/FormLabel/FormLabel.tsx b/packages/bezier-react/src/components/Forms/FormLabel/FormLabel.tsx index 526ea6a9a3..e6b38b2178 100644 --- a/packages/bezier-react/src/components/Forms/FormLabel/FormLabel.tsx +++ b/packages/bezier-react/src/components/Forms/FormLabel/FormLabel.tsx @@ -7,7 +7,7 @@ import { Typography } from '~/src/foundation' import { isEmpty } from '~/src/utils/typeUtils' -import useFormControlContext from '~/src/components/Forms/useFormControlContext' +import { useFormControlContext } from '~/src/components/Forms/FormControl' import { Help } from '~/src/components/Help' import { HELP_DISPLAY_NAME } from '~/src/components/Help/Help' import { diff --git a/packages/bezier-react/src/components/Forms/SegmentedControl/SegmentedControlContext.ts b/packages/bezier-react/src/components/Forms/SegmentedControl/SegmentedControlContext.ts index 13d78d89bc..92c144f4c4 100644 --- a/packages/bezier-react/src/components/Forms/SegmentedControl/SegmentedControlContext.ts +++ b/packages/bezier-react/src/components/Forms/SegmentedControl/SegmentedControlContext.ts @@ -1,39 +1,16 @@ -import React from 'react' +import { createContext } from '~/src/utils/reactUtils' import { type SegmentedControlProps, type SegmentedControlType, } from './SegmentedControl.types' -// TODO: (@ed) Evolve it into a commonly reusable function -function createContext( - providerName: string, - defaultValue: ContextValue, -) { - const Context = React.createContext(defaultValue) - - function useContext(consumerName: string) { - const contextValue = React.useContext(Context) - - if (!contextValue) { - throw new Error(`'${consumerName}' must be used within '${providerName}'`) - } - - return contextValue - } - - return [ - Context.Provider, - useContext, - ] as const -} - type SegmentedControlContextValue = Required, 'type' | 'size' | 'width'>> export const [ SegmentedControlContextProvider, useSegmentedControlContext, -] = createContext('SegmentedControl', null) +] = createContext(null, 'SegmentedControl') interface SegmentedControlItemListContextValue { setSelectedElement: (node: HTMLButtonElement | null) => void @@ -42,4 +19,4 @@ interface SegmentedControlItemListContextValue { export const [ SegmentedControlItemListContextProvider, useSegmentedControlItemListContext, -] = createContext('SegmentedControlItemList', null) +] = createContext(null, 'SegmentedControlItemList') diff --git a/packages/bezier-react/src/components/Forms/index.ts b/packages/bezier-react/src/components/Forms/index.ts index 165f64ca75..684ee08cfd 100644 --- a/packages/bezier-react/src/components/Forms/index.ts +++ b/packages/bezier-react/src/components/Forms/index.ts @@ -1,6 +1,5 @@ import type { FormComponentProps } from './Form.types' import FormFieldSize from './FormFieldSize' -import useFormControlContext from './useFormControlContext' import useFormFieldProps from './useFormFieldProps' import useKeyboardActionLockerWhileComposing from './useKeyboardActionLockerWhileComposing' @@ -8,7 +7,6 @@ export type { FormComponentProps } export * from './Inputs/constants/CommonImeControlKeys' export { FormFieldSize, - useFormControlContext, useFormFieldProps, useKeyboardActionLockerWhileComposing, } diff --git a/packages/bezier-react/src/components/Forms/useFormControlContext.ts b/packages/bezier-react/src/components/Forms/useFormControlContext.ts deleted file mode 100644 index 208f8857f3..0000000000 --- a/packages/bezier-react/src/components/Forms/useFormControlContext.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { useContext } from 'react' - -import { FormControlContext } from '~/src/components/Forms/FormControl' - -function useFormControlContext() { - return useContext(FormControlContext) -} - -export default useFormControlContext diff --git a/packages/bezier-react/src/components/Forms/useFormFieldProps.ts b/packages/bezier-react/src/components/Forms/useFormFieldProps.ts index 1a275fa52f..ecb8113d22 100644 --- a/packages/bezier-react/src/components/Forms/useFormFieldProps.ts +++ b/packages/bezier-react/src/components/Forms/useFormFieldProps.ts @@ -3,8 +3,7 @@ import { useMemo } from 'react' import { ariaAttr } from '~/src/utils/domUtils' import type { FormComponentProps } from '~/src/components/Forms/Form.types' - -import useFormControlContext from './useFormControlContext' +import { useFormControlContext } from '~/src/components/Forms/FormControl' // TODO: 테스트 추가 function useFormFieldProps(props?: Props) { diff --git a/packages/bezier-react/src/components/Modals/Modal/Modal.stories.tsx b/packages/bezier-react/src/components/Modals/Modal/Modal.stories.tsx index 0885ceca9e..b5f0e78e8f 100644 --- a/packages/bezier-react/src/components/Modals/Modal/Modal.stories.tsx +++ b/packages/bezier-react/src/components/Modals/Modal/Modal.stories.tsx @@ -85,7 +85,7 @@ function ModalComposition({ - Name + Name