aboutsummaryrefslogtreecommitdiff
path: root/src/components/input/CurrencySelect.tsx
blob: 2b6045b459a82d0908428093b0292cac304dd9f9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { ListItem, Select } from '@umami/react-zen';
import { useState } from 'react';
import { useMessages } from '@/components/hooks';
import { CURRENCIES } from '@/lib/constants';

export function CurrencySelect({ value, onChange }) {
  const { formatMessage, labels } = useMessages();
  const [search, setSearch] = useState('');

  return (
    <Select
      items={CURRENCIES}
      label={formatMessage(labels.currency)}
      value={value}
      defaultValue={value}
      onChange={onChange}
      listProps={{ style: { maxHeight: 300 } }}
      onSearch={setSearch}
      allowSearch
    >
      {CURRENCIES.map(({ id, name }) => {
        if (search && !`${id}${name}`.toLowerCase().includes(search)) {
          return null;
        }

        return (
          <ListItem key={id} id={id}>
            {id} &mdash; {name}
          </ListItem>
        );
      }).filter(n => n)}
    </Select>
  );
}