-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from abusix/pla-991-fix-radio-box-styling-issues
Pla 991 fix radio box styling issues
- Loading branch information
Showing
4 changed files
with
69 additions
and
73 deletions.
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
6 changes: 3 additions & 3 deletions
6
...recommendation-tag/recommendation-tag.tsx → src/components/featured-tag/featured-tag.tsx
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
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 |
---|---|---|
@@ -1,83 +1,79 @@ | ||
import { RadioGroup } from "@headlessui/react"; | ||
import React from "react"; | ||
import React, { Fragment } from "react"; | ||
import { classNames } from "../../../util/class-names"; | ||
import { RecommendationTag } from "../../recommendation-tag/recommendation-tag"; | ||
|
||
export interface RadioBoxOptionProps { | ||
children: React.ReactNode; | ||
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", | ||
const radioBoxContainerStyles = { | ||
base: "group relative flex items-center gap-3 rounded-lg bg-neutral-0 border p-4 border-neutral-300 hover:border-primary-600 hover:bg-primary-50 cursor-pointer focus:outline-none", | ||
checked: "border-primary-600 bg-primary-600 hover:bg-primary-600 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", | ||
"bg-neutral-100 group-hover:border-neutral-300 group-hover:bg-neutral-100 hover:border-neutral-300 hover:bg-neutral-100 cursor-not-allowed", | ||
active: "ring-2 ring-primary-200", | ||
}; | ||
|
||
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", | ||
const radioBoxCircleStyles = { | ||
base: "relative inline-block h-4 w-4 shrink-0 rounded-full bg-neutral-0 border border-neutral-300", | ||
unchecked: "group-hover:border-primary-600 group-hover:bg-neutral-0", | ||
checked: "border-transparent", | ||
disabled: | ||
"bg-neutral-200 border-neutral-200 group-hover:border-neutral-200 group-hover:bg-neutral-200", | ||
}; | ||
|
||
export const RadioBoxOption = ({ | ||
children, | ||
value, | ||
disabled, | ||
recommendationText, | ||
className, | ||
}: RadioBoxOptionProps) => { | ||
const Title = ({ children }: { children: React.ReactNode }) => ( | ||
<h2 className="headline-500 text-neutral-900 group-[.is-checked]:text-neutral-0 group-[.is-disabled]:text-neutral-500"> | ||
{children} | ||
</h2> | ||
); | ||
|
||
const Description = ({ children }: { children: React.ReactNode }) => ( | ||
<p className="paragraph-200 text-neutral-800 group-[.is-checked]:text-neutral-0 group-[.is-disabled]:text-neutral-500"> | ||
{children} | ||
</p> | ||
); | ||
|
||
export const RadioBoxOption = ({ children, value, disabled, className }: RadioBoxOptionProps) => { | ||
return ( | ||
<RadioGroup.Option | ||
value={value} | ||
className="w-full cursor-pointer focus:outline-none" | ||
disabled={disabled} | ||
> | ||
{({ checked, disabled: optionDisabled }) => ( | ||
<RadioGroup.Option value={value} disabled={disabled} as={Fragment}> | ||
{({ checked, disabled: optionDisabled, active }) => ( | ||
<div | ||
className={classNames( | ||
radioBoxContainerStyles.base, | ||
checked && radioBoxContainerStyles.checked, | ||
optionDisabled && radioBoxContainerStyles.disabled | ||
checked && classNames("is-checked", radioBoxContainerStyles.checked), | ||
optionDisabled && | ||
classNames("is-disabled", radioBoxContainerStyles.disabled), | ||
active && radioBoxContainerStyles.active | ||
)} | ||
> | ||
{recommendationText && ( | ||
<RecommendationTag>{recommendationText}</RecommendationTag> | ||
)} | ||
|
||
<div | ||
className={classNames( | ||
radioBoxCircleStyles.base, | ||
!checked && radioBoxCircleStyles.unchecked, | ||
checked && radioBoxCircleStyles.checked, | ||
optionDisabled && radioBoxCircleStyles.disabled | ||
)} | ||
> | ||
{checked && ( | ||
<div | ||
className={classNames( | ||
"absolute inset-0 m-auto block h-2 w-2 rounded-full bg-primary-500", | ||
"absolute inset-0 m-auto block h-2 w-2 rounded-full bg-primary-600", | ||
optionDisabled && "bg-neutral-500" | ||
)} | ||
/> | ||
)} | ||
</div> | ||
|
||
<div | ||
className={classNames( | ||
"flex flex-col gap-2", | ||
checked && "text-neutral-0", | ||
optionDisabled && "text-neutral-600", | ||
className | ||
)} | ||
> | ||
{children} | ||
</div> | ||
<div className={classNames("flex flex-col gap-2", className)}>{children}</div> | ||
</div> | ||
)} | ||
</RadioGroup.Option> | ||
); | ||
}; | ||
|
||
RadioBoxOption.Title = Title; | ||
RadioBoxOption.Description = Description; |
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