Skip to content

Commit

Permalink
fix: update ListboxOption component to use render prop for dynamic st…
Browse files Browse the repository at this point in the history
…yling
  • Loading branch information
mnlfischer committed Feb 27, 2024
1 parent 8f51baa commit b6296ea
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/components/form-field/listbox/listbox-option.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ import { classNames } from "../../../util/class-names";
const listboxOptionStyles = {
base: "relative cursor-pointer px-3 py-2 ",
selected:
"ui-selected:bg-primary-100 ui-selected:text-primary-500 ui-selected:before:absolute ui-selected:before:bottom-0 ui-selected:before:left-0 ui-selected:before:top-0 ui-selected:before:block ui-selected:before:w-[2px] ui-selected:before:rounded-r-md ui-selected:before:bg-primary-400",
active: "ui-active:bg-neutral-50 ui-active:ui-selected:bg-primary-100",
disabled:
"ui-disabled:cursor-not-allowed ui-disabled:bg-neutral-50 ui-disabled:text-neutral-400",
"bg-primary-100 text-primary-500 before:absolute before:bottom-0 before:left-0 before:top-0 before:block before:w-[2px] before:rounded-r-md before:bg-primary-400",
active: "bg-neutral-50 bg-primary-100",
disabled: "cursor-not-allowed bg-neutral-50 text-neutral-400",
};

export interface ListboxOptionProps<TValue> {
Expand All @@ -22,16 +21,18 @@ export interface ListboxOptionProps<TValue> {
const ListboxOption = <TValue,>({ value, disabled, children }: ListboxOptionProps<TValue>) => {
return (
<Listbox.Option value={value} as={Fragment} disabled={disabled}>
<li
className={classNames(
listboxOptionStyles.base,
listboxOptionStyles.selected,
listboxOptionStyles.active,
listboxOptionStyles.disabled
)}
>
{children}
</li>
{({ active, selected }) => (
<li
className={classNames(
listboxOptionStyles.base,
active && listboxOptionStyles.active,
selected && listboxOptionStyles.selected,
disabled && listboxOptionStyles.disabled
)}
>
{children}
</li>
)}
</Listbox.Option>
);
};
Expand Down

0 comments on commit b6296ea

Please sign in to comment.