-
Notifications
You must be signed in to change notification settings - Fork 52
Enhance RadioGroup component
#1131
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
sungik-choi
merged 7 commits into
channel-io:next-v1
from
sungik-choi:enhance/radio-type
Feb 13, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
01fb1e7
refactor(radio-group): apply generic value type to component props
sungik-choi 48efeba
chore(legacy-radio): add deprecated comment
sungik-choi 82c004f
fix(radio-group): change children prop type to React.Node to support …
sungik-choi ee4c1ae
feat(radio): change to render children when their value is evaluated …
sungik-choi 5033736
chore(changeset): add changeset
sungik-choi ab28e50
chore(radio-group): fix jsdoc of Radio
sungik-choi 50bfcf5
refactor(components): use isValidElement function instead of type ass…
sungik-choi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@channel.io/bezier-react": patch | ||
| --- | ||
|
|
||
| Enhance the interface of `Radio` and `RadioGroup` components. Change `Radio` to render children when their value is evaluated as true. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,18 @@ | ||
| /* External dependencies */ | ||
| import React, { forwardRef } from 'react' | ||
| import React, { forwardRef, isValidElement } from 'react' | ||
| import * as RadioGroupPrimitive from '@radix-ui/react-radio-group' | ||
|
|
||
| /* Internal dependencies */ | ||
| import { Stack, StackItem } from 'Components/Stack' | ||
| import useFormFieldProps from 'Components/Forms/useFormFieldProps' | ||
| import { RadioGroupProps } from './RadioGroup.types' | ||
|
|
||
| /** | ||
| * `RadioGroup` is a set of checkable buttons, known as radio buttons. | ||
| * | ||
| * `RadioGroup` is a context of the `Radio` components. also, it renders an element which has the 'radiogroup' role. | ||
| * It controls all the parts of a radio group. | ||
| * | ||
| * @example | ||
| * | ||
| * ```tsx | ||
| * // Anatomy of the RadioGroup | ||
| * <RadioGroup> | ||
| * <Radio /> | ||
| * </RadioGroup> | ||
| * ``` | ||
| */ | ||
| export const RadioGroup = forwardRef(function RadioGroup({ | ||
| function RadioGroupImpl<Value extends string>({ | ||
| children, | ||
| spacing = 0, | ||
| direction = 'vertical', | ||
| ...rest | ||
| }: RadioGroupProps, forwardedRef: React.Ref<HTMLDivElement>) { | ||
| }: RadioGroupProps<Value>, forwardedRef: React.Ref<HTMLDivElement>) { | ||
| const formFieldProps = useFormFieldProps(rest) | ||
|
|
||
| return ( | ||
|
|
@@ -43,11 +28,30 @@ export const RadioGroup = forwardRef(function RadioGroup({ | |
| direction={direction} | ||
| > | ||
| { React.Children.map(children, (child, index) => ( | ||
| <StackItem key={child?.key ?? index}> | ||
| <StackItem key={isValidElement(child) ? child.key : index}> | ||
| { child } | ||
| </StackItem> | ||
| )) } | ||
| </Stack> | ||
| </RadioGroupPrimitive.Root> | ||
| ) | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * `RadioGroup` is a set of checkable buttons, known as radio buttons. | ||
| * | ||
| * `RadioGroup` is a context of the `Radio` components. also, it renders an element which has the 'radiogroup' role. | ||
| * It controls all the parts of a radio group. | ||
| * | ||
| * @example | ||
| * | ||
| * ```tsx | ||
| * // Anatomy of the RadioGroup | ||
| * <RadioGroup> | ||
| * <Radio /> | ||
| * </RadioGroup> | ||
| * ``` | ||
| */ | ||
| export const RadioGroup = forwardRef(RadioGroupImpl) as <Value extends string>( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 공유 감사합니다. 저도 꼼꼼히 확인해봐야할듯. |
||
| props: RadioGroupProps<Value> & { ref?: React.ForwardedRef<HTMLDivElement> } | ||
| ) => ReturnType<typeof RadioGroupImpl<Value>> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.