1 import { c } from 'ttag';
11 } from '@proton/components';
12 import type { SelectTwoProps } from '@proton/components/components/selectTwo/SelectTwo';
13 import { FREQUENCY } from '@proton/shared/lib/calendar/constants';
15 const { ONCE, DAILY, WEEKLY, MONTHLY, YEARLY, CUSTOM } = FREQUENCY;
17 interface Props extends Omit<SelectTwoProps<FREQUENCY>, 'onChange' | 'children'> {
19 frequencyInputType?: 'dropdown' | 'select';
20 onChange: (value: FREQUENCY) => void;
23 const FrequencyInput = ({ value, frequencyInputType = 'select', onChange, ...rest }: Props) => {
25 { text: c('Option').t`Does not repeat`, value: ONCE },
26 { text: c('Option').t`Every day`, value: DAILY },
27 { text: c('Option').t`Every week`, value: WEEKLY },
28 { text: c('Option').t`Every month`, value: MONTHLY },
29 { text: c('Option').t`Every year`, value: YEARLY },
30 { text: c('Option').t`Custom`, value: CUSTOM },
33 const { anchorRef, isOpen, toggle, close } = usePopperAnchor<HTMLButtonElement>();
35 const selectedOption = frequencies.find((item) => item.value === value);
37 if (frequencyInputType === 'dropdown') {
38 const handleClick = () => {
52 <span>{selectedOption?.text}</span> <Icon name="arrows-rotate" />
54 <Dropdown autoClose autoCloseOutside isOpen={isOpen} anchorRef={anchorRef} onClose={close}>
55 {frequencies.map(({ value, text }) => (
57 className="text-left flex flex-nowrap items-center"
58 onClick={() => onChange(value)}
59 aria-pressed={selectedOption?.value === value}
62 <span className="flex-1 pr-4">{text}</span>
63 {selectedOption?.value === value && (
64 <span className="ml-auto flex color-primary">
65 <Icon name="checkmark" />
78 onChange={({ value }) => {
79 onChange(value as FREQUENCY);
83 {frequencies.map(({ value, text }) => (
84 <Option key={value} value={value} title={text} />
90 export default FrequencyInput;