diff --git a/src/app/[name]/page.tsx b/src/app/[name]/page.tsx index 50a1d68..33ba382 100644 --- a/src/app/[name]/page.tsx +++ b/src/app/[name]/page.tsx @@ -13,11 +13,11 @@ import React from "react"; import MenuItem from "@/components/listview/MenuItem"; import Button from "@/components/button/PrimaryButton"; import AnimatedBottomSheet from "@/components/bottomsheet/AnimatedBottomSheet"; -import MultiOption from "@/components/combobox/MultiOption"; +import SearchComboBox from "@/components/combobox/SearchComboBox"; import { DropdownOption } from "@/components/combobox/Combobox"; import { Switch } from "@/components/ui/switch"; -import { LucideMedal, Medal, MedalIcon, StarHalf, StarIcon, Stars, TicketPercentIcon } from "lucide-react"; -import TicketDiscountIcon from "@/components/icons/TickerDiscountIcon"; +import { TicketPercentIcon } from "lucide-react"; +import { MedalStar } from 'iconsax-react' const categories = new Array(13).fill({ title: "خوراک", icon: "" }); @@ -236,12 +236,12 @@ const MenuIndex = () => {
- - { className="flex w-full mt-[23px] h-11 items-center justify-between gap-2 px-3 py-4 relative bg-white/29 rounded-xl border border-solid border-neutral-200 cursor-pointer focus:outline-none focus:ring-2 focus:ring-black" > - + دارای امتیاز پس از خرید diff --git a/src/components/combobox/Combobox.tsx b/src/components/combobox/Combobox.tsx new file mode 100644 index 0000000..b7e8d25 --- /dev/null +++ b/src/components/combobox/Combobox.tsx @@ -0,0 +1,91 @@ +"use client" + +import * as React from "react" +import { Check } from "lucide-react" + +import { cn } from "@/lib/utils" +import { Button } from "@/components/ui/button" +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList, +} from "@/components/ui/command" +import { + Popover, + PopoverContent, + PopoverTrigger, +} from "@/components/ui/popover" +import ArrowDownIcon from "../icons/ArrowDownIcon" + +export interface DropdownOption { + id: string; + label?: string; + title: string; +} + +type Props = { + title: string; + options: Array; + value: string; + setValue: React.Dispatch> +} & React.HTMLAttributes + +export function Combobox({ options, value, title, setValue, }: Props) { + const [open, setOpen] = React.useState(false) + + return ( + + + + + + + + + نتیجه ای یافت نشد + + {options.map((option) => ( + { + setValue(currentValue === value ? "" : currentValue) + setOpen(false) + }} + > + + {option.label} + + ))} + + + + + + ) +} diff --git a/src/components/combobox/MultiOption.tsx b/src/components/combobox/MultiOption.tsx deleted file mode 100644 index d9f3d01..0000000 --- a/src/components/combobox/MultiOption.tsx +++ /dev/null @@ -1,79 +0,0 @@ -import React, { useState } from 'react' -import ArrowDownIcon from '../icons/ArrowDownIcon'; - -export interface DropdownOption { - id: string; - title: string; -} - -type Props = { - title: string; - options: Array; - expanded?: boolean; - selectedId: string; - onSelectionChange: (e: React.MouseEvent, index: number) => void, -} & React.HTMLAttributes - -function MultiOption({ title, options, expanded, selectedId, onSelectionChange, ...props }: Props) { - const [expand, setExpand] = useState(expanded); - const toggleExpand = () => { - setExpand((state) => !state); - } - - return ( -
-
- - - -
- {options.filter(x => x.id === selectedId)[0]?.title ?? ''} -
- - -
- - {expand && -
- {options.map((v, i) => { - return ( -
{setExpand(() => false); onSelectionChange(e, i) }} - key={v.id} - data-selected={v.id === selectedId} - className='flex items-center justify-end px-3 py-3 cursor-pointer hover:bg-gray-50 first:rounded-t-xl last:rounded-b-xl' - tabIndex={0} - role='option' - aria-selected> - - {v.title} - -
- ) - })} -
- } -
- ) -} - -export default MultiOption \ No newline at end of file diff --git a/src/components/combobox/SearchComboBox.tsx b/src/components/combobox/SearchComboBox.tsx new file mode 100644 index 0000000..559cdf8 --- /dev/null +++ b/src/components/combobox/SearchComboBox.tsx @@ -0,0 +1,94 @@ +import React, { useState } from 'react' +import ArrowDownIcon from '../icons/ArrowDownIcon'; + +export interface DropdownOption { + id: string; + title: string; + label?: string; +} + +type Props = { + title: string; + options: Array; + expanded?: boolean; + selectedId: string; + onSelectionChange: (e: React.MouseEvent, index: number) => void, +} & React.HTMLAttributes + +function SearchComboBox({ title, options, expanded, selectedId, onSelectionChange, ...props }: Props) { + const [expand, setExpand] = useState(expanded); + const [searchValue, setSearchValue] = useState(''); + const toggleExpand = () => { + setExpand((state) => !state); + setSearchValue(() => ''); + } + const searchChanged = (e: React.ChangeEvent | undefined) => { + setSearchValue((state) => e?.target.value ?? state); + } + const setSelection = (e: React.MouseEvent, index: number) => { + onSelectionChange(e, index) + setExpand(() => false); + } + + return ( +
+
+ + +
+ {options.filter(x => x.id === selectedId)[0]?.title ?? ''} +
+ + + +
+
+ +
+
+ {options + .filter((v) => v.title?.includes(searchValue)) + .map((v, i) => { + return ( +
{setSelection(e, i)}} + key={v.id} + data-selected={v.id === selectedId} + className='flex items-center justify-end px-3 py-3 cursor-pointer hover:bg-gray-50 first:rounded-t-xl last:rounded-b-xl' + tabIndex={0} + role='option' + aria-selected> + + {v.title} + +
+ ) + })} +
+
+
+ ) +} + +export default SearchComboBox \ No newline at end of file