Skip to content
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

Fix Radio Box Issues #90

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions src/components/form-field/radio-box/radio-box-option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,28 @@ export interface RadioBoxOptionProps {
value: string;
disabled?: boolean;
recommendationText?: string;
className?: string;
}

export const radioBoxContainerStyles = {
base: "group relative flex items-center gap-3 rounded-lg bg-neutral-0 border p-4 border-neutral-300 hover:border-primary-500 hover:bg-primary-50",
checked: "border-primary-500 bg-primary-500 hover:bg-primary-500 hover:text-neutral-0",
disabled:
"border-neutral-400 bg-neutral-100 group-hover:border-neutral-400 group-hover:bg-neutral-100 hover:border-neutral-400 hover:bg-neutral-100",
};

export const radioBoxCircleStyles = {
base: "relative inline-block h-4 w-4 shrink-0 rounded-full bg-neutral-0 border border-neutral-400",
unchecked: "group-hover:border-primary-500 group-hover:bg-neutral-0",
disabled: "bg-neutral-100 group-hover:border-neutral-400 group-hover:bg-neutral-100",
};

export const RadioBoxOption = ({
children,
value,
disabled,
recommendationText,
className,
}: RadioBoxOptionProps) => {
return (
<RadioGroup.Option
Expand All @@ -25,46 +40,42 @@ export const RadioBoxOption = ({
{({ checked, disabled: optionDisabled }) => (
<div
className={classNames(
"group relative flex items-center gap-3 rounded-lg border p-4",
checked
? "border-primary-500 bg-primary-500"
: "border-neutral-300 hover:border-primary-500 hover:bg-primary-50",
optionDisabled &&
"cursor-not-allowed bg-neutral-100 hover:border-neutral-300 hover:bg-neutral-100"
radioBoxContainerStyles.base,
checked && radioBoxContainerStyles.checked,
optionDisabled && radioBoxContainerStyles.disabled
)}
>
{recommendationText && (
<RecommendationTag>{recommendationText}</RecommendationTag>
)}

<span
<div
className={classNames(
"relative inline-block h-4 w-4 shrink-0 rounded-full bg-neutral-0",
!checked &&
"border border-neutral-400 group-hover:border-primary-500 group-hover:bg-neutral-0",
optionDisabled &&
"border border-neutral-400 bg-neutral-100 group-hover:border-neutral-400 group-hover:bg-neutral-100"
radioBoxCircleStyles.base,
!checked && radioBoxCircleStyles.unchecked,
optionDisabled && radioBoxCircleStyles.disabled
)}
>
{checked && (
<span
<div
className={classNames(
"absolute inset-0 m-auto block h-2 w-2 rounded-full bg-primary-500",
optionDisabled && "bg-neutral-500"
)}
/>
)}
</span>
</div>

<p
<div
className={classNames(
"paragraph-200",
"flex flex-col gap-2",
checked && "text-neutral-0",
optionDisabled && "text-neutral-600"
optionDisabled && "text-neutral-600",
className
)}
>
{children}
</p>
</div>
</div>
)}
</RadioGroup.Option>
Expand Down
6 changes: 3 additions & 3 deletions src/components/form-field/radio-box/radio-box.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const RadioBoxWithHooks = () => {
<FormField.RadioBox.Option value="value_1" recommendationText="Recommended">
<div className="flex flex-col gap-2">
<h2 className="headline-500">Option 1</h2>
<p>
<p className="paragraph-200">
To be, or not to be, that is the question: Whether ’tis nobler in the
mind to suffer The slings and arrows of outrageous fortune, …
</p>
Expand All @@ -31,7 +31,7 @@ const RadioBoxWithHooks = () => {
<FormField.RadioBox.Option value="value_2">
<div className="flex flex-col gap-2">
<h2 className="headline-500">Option 2</h2>
<p>
<p className="paragraph-200">
To be, or not to be, that is the question: Whether ’tis nobler in the
mind to suffer The slings and arrows of outrageous fortune, …
</p>
Expand All @@ -41,7 +41,7 @@ const RadioBoxWithHooks = () => {
<FormField.RadioBox.Option value="value_3" disabled>
<div className="flex flex-col gap-2">
<h2 className="headline-500">Option 3</h2>
<p>
<p className="paragraph-200">
To be, or not to be, that is the question: Whether ’tis nobler in the
mind to suffer The slings and arrows of outrageous fortune, …
</p>
Expand Down
Loading