From ebff0d09965d603fa30fad4ddd57ed6c025ed047 Mon Sep 17 00:00:00 2001 From: coderwelsch Date: Tue, 13 Feb 2024 15:34:42 +0100 Subject: [PATCH] feat: added disabled listbox state --- .../form-field/listbox/listbox-option.tsx | 24 ++++++++++++++++--- .../form-field/listbox/listbox.stories.tsx | 9 +++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/components/form-field/listbox/listbox-option.tsx b/src/components/form-field/listbox/listbox-option.tsx index c3242387..86249d47 100644 --- a/src/components/form-field/listbox/listbox-option.tsx +++ b/src/components/form-field/listbox/listbox-option.tsx @@ -2,16 +2,34 @@ import { Listbox } from "@headlessui/react"; import React, { Fragment } from "react"; import { ListboxBadgeOption } from "./listbox-badge-option"; import { ListboxTextOption } from "./listbox-text-option"; +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", +}; export interface ListboxOptionProps { value: TValue; children: React.ReactNode; + disabled?: boolean; } -const ListboxOption = ({ value, children }: ListboxOptionProps) => { +const ListboxOption = ({ value, disabled, children }: ListboxOptionProps) => { return ( - -
  • + +
  • {children}
  • diff --git a/src/components/form-field/listbox/listbox.stories.tsx b/src/components/form-field/listbox/listbox.stories.tsx index dfb48b46..798ed1d3 100644 --- a/src/components/form-field/listbox/listbox.stories.tsx +++ b/src/components/form-field/listbox/listbox.stories.tsx @@ -15,10 +15,11 @@ type Story = StoryObj; interface Person { id: number; name: string; + isDead?: boolean; } const people: Person[] = [ - { id: 1, name: "Durward Reynolds" }, + { id: 1, name: "John Lennon", isDead: true }, { id: 2, name: "Kenton Towne" }, { id: 3, name: "Therese Wunsch" }, { id: 4, name: "Benedict Kessler" }, @@ -43,7 +44,11 @@ const ListboxTextWithHooks = () => { {people.map((person) => ( - + {person.name}