1 import type { ReactNode } from 'react';
3 import { c } from 'ttag';
5 import { Button, Kbd } from '@proton/atoms';
6 import { Icon, Tooltip } from '@proton/components';
7 import { itemTypeToSubThemeClassName } from '@proton/pass/components/Layout/Theme/types';
8 import { useSaveShortcut } from '@proton/pass/hooks/useSaveShortcut';
9 import type { ItemType, MaybeNull } from '@proton/pass/types';
10 import { metaKey } from '@proton/shared/lib/helpers/browser';
12 import { DiscardableModalPanel, type DiscardableModalProps } from './DiscardableModalPanel';
13 import { Panel } from './Panel';
14 import { PanelHeader } from './PanelHeader';
20 handleCancelClick: () => void;
21 submitButton?: ReactNode;
23 } & Omit<DiscardableModalProps, 'onDiscard'>;
25 function getItemTypeSubmitButtonLabel(type: ItemType) {
28 return c('Action').t`Create login`;
30 return c('Action').t`Create alias`;
32 return c('Action').t`Create note`;
34 return c('Action').t`Create card`;
36 return c('Action').t`Create identity`;
38 return c('Action').t`Create`;
42 export const ItemCreatePanel = ({
52 useSaveShortcut(() => {
53 if (valid && !discardable) {
54 const form = document.getElementById(formId) as MaybeNull<HTMLFormElement>;
55 form?.requestSubmit();
60 <DiscardableModalPanel onDiscard={handleCancelClick} discardable={discardable}>
63 className={itemTypeToSubThemeClassName[type]}
74 onClick={() => (discardable ? handleCancelClick() : props.confirm())}
75 title={c('Action').t`Cancel`}
77 <Icon name="cross" alt={c('Action').t`Cancel`} />
79 <div key="actions" className="flex flex-nowrap gap-2">
85 originalPlacement={'bottom'}
88 <Kbd shortcut={metaKey} /> + <Kbd shortcut="S" />
93 className="text-sm shrink-0"
101 {getItemTypeSubmitButtonLabel(type)}
113 </DiscardableModalPanel>