From 387a94e91804622ef8ba8cfd67893c20433db8aa Mon Sep 17 00:00:00 2001 From: Alihaghighattalab Date: Wed, 21 Aug 2024 10:50:50 +0330 Subject: [PATCH] edit combo box dynamic items --- src/components/common/combo-box.tsx | 25 +++++++++---------------- src/types/index.ts | 5 +++++ 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/components/common/combo-box.tsx b/src/components/common/combo-box.tsx index e167977..1b79ac1 100644 --- a/src/components/common/combo-box.tsx +++ b/src/components/common/combo-box.tsx @@ -1,33 +1,27 @@ import { Combobox, ComboboxButton, ComboboxInput, ComboboxOption, ComboboxOptions } from '@headlessui/react' import { ArrowDown2 } from 'iconsax-react' import { FC, useState } from 'react' - -const value = [ - { id: 1, name: 'تهران' }, - { id: 2, name: 'شیراز' }, - { id: 3, name: 'اصفهان' }, - { id: 4, name: 'اراک' }, - { id: 5, name: 'تبریز' }, -] +import { ComboBoxItems } from '../../types' type Props = { field?: any placeholder?: string - className?: string + className?: string, + data?: ComboBoxItems[] | [] } -export const ComboBox: FC = ({ field, placeholder, className }) => { +export const ComboBox: FC = ({ field, placeholder, className, data = [] }) => { const [query, setQuery] = useState('') const filteredValue = query === '' - ? value - : value?.filter((value) => { + ? data + : data?.filter((value) => { return value.name.toLowerCase().includes(query.toLowerCase()) }) return ( - setQuery('')}> + setQuery('')} disabled={data?.length <= 0}>
= ({ field, placeholder, className }) => {
- - 0 && = ({ field, placeholder, className }) => {
{value?.name}
))} -
+
}
) } diff --git a/src/types/index.ts b/src/types/index.ts index 1993dcc..45ec9d0 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -275,4 +275,9 @@ export interface ScoreResponse { data: ScoreData[] | [] score: number, total: number +} + +export interface ComboBoxItems { + name: string, + id: string | number } \ No newline at end of file