|
| 1 | +import { Button, Icon, Text } from 'opub-ui'; |
| 2 | + |
| 3 | +import { Icons } from '@/components/icons'; |
| 4 | +import CustomCombobox from './CustomCombobox'; |
| 5 | + |
| 6 | +type Option = { label: string; value: string }; |
| 7 | + |
| 8 | +type EntitySectionProps = { |
| 9 | + title: string; |
| 10 | + label: string; |
| 11 | + placeholder: string; |
| 12 | + options: Option[]; |
| 13 | + selectedValues: Option[]; |
| 14 | + onChange: (values: Option[]) => void; |
| 15 | + onRemove: (value: Option) => void; |
| 16 | +}; |
| 17 | + |
| 18 | +const EntitySection = ({ |
| 19 | + title, |
| 20 | + label, |
| 21 | + placeholder, |
| 22 | + options, |
| 23 | + selectedValues, |
| 24 | + onChange, |
| 25 | + onRemove, |
| 26 | +}: EntitySectionProps) => ( |
| 27 | + <div> |
| 28 | + <Text variant="headingMd">{title}</Text> |
| 29 | + <div className="mt-5 flex flex-wrap items-start gap-5 lg:flex-nowrap"> |
| 30 | + <div className="flex w-full flex-wrap items-end gap-5 lg:flex-nowrap"> |
| 31 | + <div className="w-full lg:w-2/6"> |
| 32 | + <Text>{label}</Text> |
| 33 | + <CustomCombobox |
| 34 | + options={options} |
| 35 | + selectedValue={selectedValues} |
| 36 | + placeholder={placeholder} |
| 37 | + onChange={(value: Option[]) => |
| 38 | + onChange([ |
| 39 | + ...selectedValues, |
| 40 | + ...value.filter( |
| 41 | + (val) => |
| 42 | + !selectedValues.some((item) => item.value === val.value) |
| 43 | + ), |
| 44 | + ]) |
| 45 | + } |
| 46 | + /> |
| 47 | + </div> |
| 48 | + <div className="mt-3 flex flex-wrap gap-3 lg:mt-0"> |
| 49 | + {selectedValues.map((item) => ( |
| 50 | + <Button |
| 51 | + key={item.value} |
| 52 | + kind="tertiary" |
| 53 | + onClick={() => onRemove(item)} |
| 54 | + > |
| 55 | + <div className="flex items-center gap-2 rounded-2 p-2"> |
| 56 | + <Text>{item.label}</Text> |
| 57 | + <Icon source={Icons.cross} size={18} /> |
| 58 | + </div> |
| 59 | + </Button> |
| 60 | + ))} |
| 61 | + </div> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | +); |
| 66 | + |
| 67 | +export default EntitySection; |
0 commit comments