From 4f0161b0fab583a07c440e2e821ad771993f855d Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Thu, 23 Feb 2023 17:49:04 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=84=20SelectBox=20Component?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/components/filter.tsx | 265 ------------------ .../ui/components/selectBox/SelectBox.tsx | 86 ++++++ packages/ui/components/selectBox/index.ts | 1 + packages/ui/index.ts | 1 + 4 files changed, 88 insertions(+), 265 deletions(-) delete mode 100644 apps/web/components/filter.tsx create mode 100644 packages/ui/components/selectBox/SelectBox.tsx create mode 100644 packages/ui/components/selectBox/index.ts diff --git a/apps/web/components/filter.tsx b/apps/web/components/filter.tsx deleted file mode 100644 index bed25decb..000000000 --- a/apps/web/components/filter.tsx +++ /dev/null @@ -1,265 +0,0 @@ -import { Fragment, useState } from "react"; -import { - Dialog, - Disclosure, - Menu, - Popover, - Transition, -} from "@headlessui/react"; -import { XMarkIcon } from "@heroicons/react/24/outline"; -import { ChevronDownIcon } from "@heroicons/react/20/solid"; -import { classNames } from "@documenso/lib"; - -const sortOptions = [ - { name: "Most Popular", href: "#" }, - { name: "Best Rating", href: "#" }, - { name: "Newest", href: "#" }, -]; -const filters = [ - { - id: "status", - name: "Status", - options: [ - { value: "draft", label: "Draft" }, - { value: "pending", label: "Pending" }, - { value: "comppleted", label: "Comppleted" }, - ], - }, -]; - -export default function Example() { - const [open, setOpen] = useState(false); - - return ( -
- {/* Mobile filter dialog */} - - - -
- - -
- - -
-

Filters

- -
- - {/* Filters */} -
- {filters.map((section) => ( - - {({ open }) => ( - <> -

- - - {section.name} - - - - -

- -
- {section.options.map((option, optionIdx) => ( -
- - -
- ))} -
-
- - )} -
- ))} -
-
-
-
-
-
- -
-
-

- New Arrivals -

-

- Thoughtfully designed objects for the workspace, home, and travel. -

-
- -
-

- Product filters -

- -
- -
- - Sort - -
- - - -
- {sortOptions.map((option) => ( - - {({ active }) => ( - - {option.name} - - )} - - ))} -
-
-
-
- - - - - {filters.map((section, sectionIdx) => ( - -
- - {section.name} - {sectionIdx === 0 ? ( - - 1 - - ) : null} - -
- - - -
- {section.options.map((option, optionIdx) => ( -
- - -
- ))} -
-
-
-
- ))} -
-
-
-
-
- ); -} diff --git a/packages/ui/components/selectBox/SelectBox.tsx b/packages/ui/components/selectBox/SelectBox.tsx new file mode 100644 index 000000000..91f5e3b13 --- /dev/null +++ b/packages/ui/components/selectBox/SelectBox.tsx @@ -0,0 +1,86 @@ +import { classNames } from "@documenso/lib"; +import { Listbox, Transition } from "@headlessui/react"; +import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/24/outline"; +import React, { Fragment, useState } from "react"; + +export function SelectBox(props: any) { + return ( +
+ { + props.onChange(e); + }} + > + {({ open }) => ( + <> + + {props.label} + +
+ + {props?.value?.label} + + + + + + + {props.options.map((option: any) => ( + + classNames( + active ? "text-white bg-neon" : "text-gray-900", + "relative cursor-default select-none py-2 pl-3 pr-9" + ) + } + value={option} + > + {({ selected, active }) => ( + <> + + {option.label} + + + {option.value === props.value.value ? ( + + + ) : null} + + )} + + ))} + + +
+ + )} +
+
+ ); +} diff --git a/packages/ui/components/selectBox/index.ts b/packages/ui/components/selectBox/index.ts new file mode 100644 index 000000000..0b9a0cc57 --- /dev/null +++ b/packages/ui/components/selectBox/index.ts @@ -0,0 +1 @@ +export { SelectBox } from "./SelectBox"; diff --git a/packages/ui/index.ts b/packages/ui/index.ts index 22983b785..24d9cef03 100644 --- a/packages/ui/index.ts +++ b/packages/ui/index.ts @@ -1,2 +1,3 @@ export { Button, IconButton } from "./components/button/index"; +export { SelectBox } from "./components/selectBox/index"; export { Breadcrumb } from "./components/breadcrumb/index";