This repository has been archived by the owner on Dec 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Car 9534: new component "radioButtonGroupWithTitle" #573
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a931984
wip
09e2b7f
Merge branch 'master' into car-9534
49ff49e
feat: new component
f989663
feat: radioButtonGroup component
60f47ee
feat: radioButtonGroupWithTitle
e16c52e
feat: improved radio button group component
97e8427
feat: improved new component
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 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,93 @@ | ||
import React, { FC } from "react" | ||
|
||
import { action } from "@storybook/addon-actions" | ||
|
||
import { StoryProps } from "./storyProps" | ||
import RadioButtonGroupWithTitle, { RadioButtonGroupProps } from "../../src/components/radioButtonGroupWithTitle" | ||
|
||
const onChange = () => action("onChange") | ||
|
||
export default { | ||
title: "Radio Button Group with Title", | ||
component: RadioButtonGroupWithTitle, | ||
args: { | ||
storyName: "", | ||
title: "Radio Group", | ||
radioInputs: | ||
[ | ||
{ | ||
name: "radioButtonGroupWithTitle", | ||
value: "A", | ||
checked: false, | ||
onChange: (e) => { | ||
onChange()(e) | ||
}, | ||
renderLabel:() => "option 1", | ||
disabled: true, | ||
error: "test" | ||
}, | ||
{ | ||
name: "radioButtonGroupWithTitle", | ||
value: "B", | ||
checked: false, | ||
onChange: (e) => { | ||
onChange()(e) | ||
}, | ||
renderLabel:() => "option 2" | ||
}, | ||
{ | ||
name: "radioButtonGroupWithTitle", | ||
value: "C", | ||
checked: false, | ||
onChange: (e) => { | ||
onChange()(e) | ||
}, | ||
renderLabel:() => "option 3" | ||
} | ||
] | ||
}, | ||
argTypes: { | ||
storyName: { | ||
table: { | ||
disable: true, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
interface Props extends StoryProps<JSX.Element>, RadioButtonGroupProps {} | ||
|
||
const Template: FC<Props> = (args) => { | ||
return ( | ||
<> | ||
<div className="text-2xl mb-20">{args.storyName}</div> | ||
<RadioButtonGroupWithTitle | ||
{...args} | ||
/> | ||
</> | ||
|
||
) | ||
} | ||
|
||
export const Standard = Template.bind({}) | ||
Standard.args = { | ||
storyName: "Standard", | ||
} | ||
|
||
export const Disabled = Template.bind({}) | ||
Disabled.args = { | ||
storyName: "Disabled", | ||
disabled: true, | ||
} | ||
|
||
export const Required = Template.bind({}) | ||
Required.args = { | ||
storyName: "Required", | ||
required: true, | ||
} | ||
|
||
export const WithErrorMessage = Template.bind({}) | ||
WithErrorMessage.args = { | ||
storyName: "With error message", | ||
error: "Error message", | ||
} |
This file contains 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,47 @@ | ||
import React, { FC, ReactElement } from "react" | ||
|
||
import RadioButton, { RadioButtonProps } from "./radioButton" | ||
import WithValidationError from "./fieldHelpers/withValidationError" | ||
import Label from "./fieldHelpers/label" | ||
|
||
type RadioInputProps = Omit<RadioButtonProps, "error" | "disabled"> | ||
|
||
interface Props { | ||
title: string | ||
required?: boolean | ||
disabled?: boolean | ||
radioInputs: RadioInputProps[] | ||
error?: string | ||
} | ||
|
||
const RadioButtonGroup: FC<Props> = ({ | ||
title, | ||
required = false, | ||
disabled = false, | ||
radioInputs, | ||
error, | ||
}): ReactElement => { | ||
const renderInputs = (hasError) => ( | ||
<div className="w-12/12"> | ||
<Label fieldName={title} required={required} /> | ||
<div className="flex"> | ||
{radioInputs.map((radioInput, index) => ( | ||
<RadioButton | ||
key={index} | ||
{...radioInput} | ||
disabled={disabled} | ||
error={hasError} | ||
/> | ||
))} | ||
</div> | ||
</div> | ||
) | ||
return ( | ||
<WithValidationError error={error}> | ||
{(hasError) => renderInputs(hasError)} | ||
</WithValidationError> | ||
) | ||
} | ||
|
||
export default RadioButtonGroup | ||
export { Props as RadioButtonGroupProps } | ||
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. do you need this export somewhere? 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. Yes, we need it for the stories |
This file contains 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason why it's not part of the radioInput object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it's because I think we should be able to set it up globally to disable every
RadioButtons
at once