1 import { type FC } from 'react';
3 import { c } from 'ttag';
5 import { Button } from '@proton/atoms';
6 import { Dropdown, DropdownMenu, Icon, usePopperAnchor } from '@proton/components';
7 import { DropdownMenuButton } from '@proton/pass/components/Layout/Dropdown/DropdownMenuButton';
8 import type { ExtraFieldType } from '@proton/pass/types';
10 import { getExtraFieldOptions } from './ExtraField';
12 type CustomFieldsDropdownProps = { onAdd: (type: ExtraFieldType) => void };
14 export const AddExtraFieldDropdown: FC<CustomFieldsDropdownProps> = ({ onAdd }) => {
15 const { anchorRef, isOpen, close, toggle } = usePopperAnchor<HTMLButtonElement>();
17 const handleAddClick = (type: ExtraFieldType) => {
19 setTimeout(() => anchorRef?.current?.scrollIntoView({ behavior: 'smooth' }), 50);
24 <Button pill className="flex items-center mb-2" color="norm" onClick={toggle} ref={anchorRef} shape="ghost">
25 <Icon className="mr-2" name="plus" />
26 <span className="line-height-1">{c('Action').t`Add more`}</span>
28 <Dropdown anchorRef={anchorRef} isOpen={isOpen} onClose={close} originalPlacement="top-start">
30 {Object.entries(getExtraFieldOptions()).map(([type, { icon, label }]) => (
33 onClick={() => handleAddClick(type as ExtraFieldType)}