diff --git a/README.md b/README.md index 87f3079..e5c3cb3 100755 --- a/README.md +++ b/README.md @@ -187,6 +187,13 @@ CronProps { */ readOnly?: boolean + /** + * Show clear button for each dropdown. + * + * Default: true + */ + allowClear?: boolean + /** * Define if empty should trigger an error. * @@ -203,6 +210,8 @@ CronProps { /** * Define the clock format. + * + * Default: undefined */ clockFormat?: '12-hour-clock' | '24-hour-clock' @@ -255,7 +264,7 @@ CronProps { periodicityOnDoubleClick?: boolean /** - * Define if it's possible to select only one or multiple values for each select. + * Define if it's possible to select only one or multiple values for each dropdown. * * Even in single mode, if you want to disable the double click on a dropdown option that * automatically select / unselect a periodicity, set 'periodicityOnDoubleClick' @@ -289,6 +298,137 @@ CronProps { */ allowedPeriods?: ['year', 'month', 'week', 'day', 'hour', 'minute', 'reboot'] + /** + * Define a configuration that is used for each dropdown specifically. + * Configuring a dropdown will override any global configuration for the same property. + * + * Configurations available: + * + * // See global configuration + * // For 'months' and 'week-days' + * humanizeLabels?: boolean + * + * // See global configuration + * // For 'months' and 'week-days' + * humanizeValue?: boolean + * + * // See global configuration + * // For 'month-days', 'hours' and 'minutes' + * leadingZero?: boolean + * + * // See global configuration + * For 'period', 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * disabled?: boolean + * + * // See global configuration + * For 'period', 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * readOnly?: boolean + * + * // See global configuration + * // For 'period', 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * allowClear?: boolean + * + * // See global configuration + * // For 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * periodicityOnDoubleClick?: boolean + * + * // See global configuration + * // For 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * mode?: Mode + * + * // The function will receive one argument, an object with value and label. + * // If the function returns true, the option will be included in the filtered set. + * // Otherwise, it will be excluded. + * // For 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * filterOption?: FilterOption + * + * Default: undefined + */ + dropdownsConfig?: { + 'period'?: { + disabled?: boolean + readOnly?: boolean + allowClear?: boolean + } + 'months'?: { + humanizeLabels?: boolean + humanizeValue?: boolean + disabled?: boolean + readOnly?: boolean + allowClear?: boolean + periodicityOnDoubleClick?: boolean + mode?: 'multiple' | 'single' + filterOption?: ({ + value, + label, + }: { + value: string + label: string + }) => boolean + } + 'month-days'?: { + leadingZero?: boolean + disabled?: boolean + readOnly?: boolean + allowClear?: boolean + periodicityOnDoubleClick?: boolean + mode?: 'multiple' | 'single' + filterOption?: ({ + value, + label, + }: { + value: string + label: string + }) => boolean + } + 'week-days'?: { + humanizeLabels?: boolean + humanizeValue?: boolean + disabled?: boolean + readOnly?: boolean + allowClear?: boolean + periodicityOnDoubleClick?: boolean + mode?: 'multiple' | 'single' + filterOption?: ({ + value, + label, + }: { + value: string + label: string + }) => boolean + } + 'hours'?: { + leadingZero?: boolean + disabled?: boolean + readOnly?: boolean + allowClear?: boolean + periodicityOnDoubleClick?: boolean + mode?: 'multiple' | 'single' + filterOption?: ({ + value, + label, + }: { + value: string + label: string + }) => boolean + } + 'minutes'?: { + leadingZero?: boolean + disabled?: boolean + readOnly?: boolean + allowClear?: boolean + periodicityOnDoubleClick?: boolean + mode?: 'multiple' | 'single' + filterOption?: ({ + value, + label, + }: { + value: string + label: string + }) => boolean + } + } + /** * Change the component language. * Can also be used to remove prefix and suffix. diff --git a/src/Cron.tsx b/src/Cron.tsx index 1de9875..28187e3 100644 --- a/src/Cron.tsx +++ b/src/Cron.tsx @@ -59,6 +59,8 @@ export default function Cron(props: CronProps) { 'minute', 'reboot', ], + allowClear, + dropdownsConfig, } = props const internalValueRef = useRef(value) const defaultPeriodRef = useRef(defaultPeriod) @@ -138,7 +140,8 @@ export default function Cron(props: CronProps) { weekDays, hours, minutes, - humanizeValue + humanizeValue, + dropdownsConfig ) setValue(cron, { selectedPeriod }) @@ -160,6 +163,7 @@ export default function Cron(props: CronProps) { minutes, humanizeValue, valueCleared, + dropdownsConfig, ] ) @@ -189,6 +193,8 @@ export default function Cron(props: CronProps) { undefined, undefined, undefined, + undefined, + undefined, undefined ) @@ -281,10 +287,11 @@ export default function Cron(props: CronProps) { setValue={setPeriod} locale={locale} className={className} - disabled={disabled} - readOnly={readOnly} + disabled={dropdownsConfig?.period?.disabled ?? disabled} + readOnly={dropdownsConfig?.period?.readOnly ?? readOnly} shortcuts={shortcuts} allowedPeriods={allowedPeriods} + allowClear={dropdownsConfig?.period?.allowClear ?? allowClear} /> )} @@ -299,12 +306,19 @@ export default function Cron(props: CronProps) { setValue={setMonths} locale={locale} className={className} - humanizeLabels={humanizeLabels} - disabled={disabled} - readOnly={readOnly} + humanizeLabels={ + dropdownsConfig?.months?.humanizeLabels ?? humanizeLabels + } + disabled={dropdownsConfig?.months?.disabled ?? disabled} + readOnly={dropdownsConfig?.months?.readOnly ?? readOnly} period={periodForRender} - periodicityOnDoubleClick={periodicityOnDoubleClick} - mode={mode} + periodicityOnDoubleClick={ + dropdownsConfig?.months?.periodicityOnDoubleClick ?? + periodicityOnDoubleClick + } + mode={dropdownsConfig?.months?.mode ?? mode} + allowClear={dropdownsConfig?.months?.allowClear ?? allowClear} + filterOption={dropdownsConfig?.months?.filterOption} /> )} @@ -316,12 +330,21 @@ export default function Cron(props: CronProps) { locale={locale} className={className} weekDays={weekDays} - disabled={disabled} - readOnly={readOnly} - leadingZero={leadingZero} + disabled={dropdownsConfig?.['month-days']?.disabled ?? disabled} + readOnly={dropdownsConfig?.['month-days']?.readOnly ?? readOnly} + leadingZero={ + dropdownsConfig?.['month-days']?.leadingZero ?? leadingZero + } period={periodForRender} - periodicityOnDoubleClick={periodicityOnDoubleClick} - mode={mode} + periodicityOnDoubleClick={ + dropdownsConfig?.['month-days']?.periodicityOnDoubleClick ?? + periodicityOnDoubleClick + } + mode={dropdownsConfig?.['month-days']?.mode ?? mode} + allowClear={ + dropdownsConfig?.['month-days']?.allowClear ?? allowClear + } + filterOption={dropdownsConfig?.['month-days']?.filterOption} /> )} @@ -334,13 +357,23 @@ export default function Cron(props: CronProps) { setValue={setWeekDays} locale={locale} className={className} - humanizeLabels={humanizeLabels} + humanizeLabels={ + dropdownsConfig?.['week-days']?.humanizeLabels ?? + humanizeLabels + } monthDays={monthDays} - disabled={disabled} - readOnly={readOnly} + disabled={dropdownsConfig?.['week-days']?.disabled ?? disabled} + readOnly={dropdownsConfig?.['week-days']?.readOnly ?? readOnly} period={periodForRender} - periodicityOnDoubleClick={periodicityOnDoubleClick} - mode={mode} + periodicityOnDoubleClick={ + dropdownsConfig?.['week-days']?.periodicityOnDoubleClick ?? + periodicityOnDoubleClick + } + mode={dropdownsConfig?.['week-days']?.mode ?? mode} + allowClear={ + dropdownsConfig?.['week-days']?.allowClear ?? allowClear + } + filterOption={dropdownsConfig?.['week-days']?.filterOption} /> )} @@ -353,13 +386,20 @@ export default function Cron(props: CronProps) { setValue={setHours} locale={locale} className={className} - disabled={disabled} - readOnly={readOnly} - leadingZero={leadingZero} + disabled={dropdownsConfig?.hours?.disabled ?? disabled} + readOnly={dropdownsConfig?.hours?.readOnly ?? readOnly} + leadingZero={ + dropdownsConfig?.hours?.leadingZero ?? leadingZero + } clockFormat={clockFormat} period={periodForRender} - periodicityOnDoubleClick={periodicityOnDoubleClick} - mode={mode} + periodicityOnDoubleClick={ + dropdownsConfig?.hours?.periodicityOnDoubleClick ?? + periodicityOnDoubleClick + } + mode={dropdownsConfig?.hours?.mode ?? mode} + allowClear={dropdownsConfig?.hours?.allowClear ?? allowClear} + filterOption={dropdownsConfig?.hours?.filterOption} /> )} @@ -371,12 +411,21 @@ export default function Cron(props: CronProps) { locale={locale} period={periodForRender} className={className} - disabled={disabled} - readOnly={readOnly} - leadingZero={leadingZero} + disabled={dropdownsConfig?.minutes?.disabled ?? disabled} + readOnly={dropdownsConfig?.minutes?.readOnly ?? readOnly} + leadingZero={ + dropdownsConfig?.minutes?.leadingZero ?? leadingZero + } clockFormat={clockFormat} - periodicityOnDoubleClick={periodicityOnDoubleClick} - mode={mode} + periodicityOnDoubleClick={ + dropdownsConfig?.minutes?.periodicityOnDoubleClick ?? + periodicityOnDoubleClick + } + mode={dropdownsConfig?.minutes?.mode ?? mode} + allowClear={ + dropdownsConfig?.minutes?.allowClear ?? allowClear + } + filterOption={dropdownsConfig?.minutes?.filterOption} /> )} diff --git a/src/components/CustomSelect.tsx b/src/components/CustomSelect.tsx index 42f5896..3609e3e 100644 --- a/src/components/CustomSelect.tsx +++ b/src/components/CustomSelect.tsx @@ -23,6 +23,8 @@ export default function CustomSelect(props: CustomSelectProps) { unit, periodicityOnDoubleClick, mode, + allowClear, + filterOption = () => true, ...otherProps } = props @@ -45,20 +47,22 @@ export default function CustomSelect(props: CustomSelectProps) { }) } - return [...Array(unit.total)].map((e, index) => { - const number = unit.min === 0 ? index : index + 1 + return [...Array(unit.total)] + .map((e, index) => { + const number = unit.min === 0 ? index : index + 1 - return { - value: number.toString(), - label: formatValue( - number, - unit, - humanizeLabels, - leadingZero, - clockFormat - ), - } - }) + return { + value: number.toString(), + label: formatValue( + number, + unit, + humanizeLabels, + leadingZero, + clockFormat + ), + } + }) + .filter(filterOption) }, // eslint-disable-next-line react-hooks/exhaustive-deps [optionsList, leadingZero, humanizeLabels, clockFormat] @@ -250,7 +254,7 @@ export default function CustomSelect(props: CustomSelectProps) { mode={ mode === 'single' && !periodicityOnDoubleClick ? undefined : 'multiple' } - allowClear={!readOnly} + allowClear={allowClear ?? !readOnly} virtual={false} open={readOnly ? false : undefined} value={stringValue} diff --git a/src/converter.ts b/src/converter.ts index 3fef825..fcd2061 100644 --- a/src/converter.ts +++ b/src/converter.ts @@ -4,6 +4,8 @@ import { SUPPORTED_SHORTCUTS, UNITS } from './constants' import { AllowEmpty, ClockFormat, + DropdownConfig, + DropdownsConfig, LeadingZero, Locale, OnError, @@ -106,7 +108,8 @@ export function getCronStringFromValues( weekDays: number[] | undefined, hours: number[] | undefined, minutes: number[] | undefined, - humanizeValue?: boolean + humanizeValue: boolean | undefined, + dropdownsConfig: DropdownsConfig | undefined ) { if (period === 'reboot') { return '@reboot' @@ -125,7 +128,8 @@ export function getCronStringFromValues( const parsedArray = parseCronArray( [newMinutes, newHours, newMonthDays, newMonths, newWeekDays], - humanizeValue + humanizeValue, + dropdownsConfig ) return cronToString(parsedArray) @@ -252,12 +256,22 @@ export function parsePartArray(arr: number[], unit: Unit) { /** * Parses a 2-dimensional array of integers as a cron schedule */ -function parseCronArray(cronArr: number[][], humanizeValue?: boolean) { +function parseCronArray( + cronArr: number[][], + humanizeValue: boolean | undefined, + dropdownsConfig: DropdownsConfig | undefined +) { return cronArr.map((partArr, idx) => { const unit = UNITS[idx] const parsedArray = parsePartArray(partArr, unit) + const dropdownOption: DropdownConfig | undefined = + dropdownsConfig?.[unit.type] - return partToString(parsedArray, unit, humanizeValue) + return partToString( + parsedArray, + unit, + dropdownOption?.humanizeValue ?? humanizeValue + ) }) } diff --git a/src/fields/Hours.tsx b/src/fields/Hours.tsx index 67e25cf..3a281e4 100644 --- a/src/fields/Hours.tsx +++ b/src/fields/Hours.tsx @@ -19,6 +19,8 @@ export default function Hours(props: HoursProps) { period, periodicityOnDoubleClick, mode, + allowClear, + filterOption, } = props const internalClassName = useMemo( () => @@ -51,6 +53,8 @@ export default function Hours(props: HoursProps) { period={period} periodicityOnDoubleClick={periodicityOnDoubleClick} mode={mode} + allowClear={allowClear} + filterOption={filterOption} /> ) diff --git a/src/fields/Minutes.tsx b/src/fields/Minutes.tsx index 8373ffa..f0f41da 100644 --- a/src/fields/Minutes.tsx +++ b/src/fields/Minutes.tsx @@ -19,6 +19,8 @@ export default function Minutes(props: MinutesProps) { period, periodicityOnDoubleClick, mode, + allowClear, + filterOption, } = props const internalClassName = useMemo( () => @@ -65,6 +67,8 @@ export default function Minutes(props: MinutesProps) { period={period} periodicityOnDoubleClick={periodicityOnDoubleClick} mode={mode} + allowClear={allowClear} + filterOption={filterOption} /> {period === 'hour' && locale.suffixMinutesForHourPeriod !== '' && ( diff --git a/src/fields/MonthDays.tsx b/src/fields/MonthDays.tsx index 2e0ddd5..1941ccc 100644 --- a/src/fields/MonthDays.tsx +++ b/src/fields/MonthDays.tsx @@ -19,6 +19,8 @@ export default function MonthDays(props: MonthDaysProps) { period, periodicityOnDoubleClick, mode, + allowClear, + filterOption, } = props const noWeekDays = !weekDays || weekDays.length === 0 @@ -73,6 +75,8 @@ export default function MonthDays(props: MonthDaysProps) { period={period} periodicityOnDoubleClick={periodicityOnDoubleClick} mode={mode} + allowClear={allowClear} + filterOption={filterOption} /> ) : null diff --git a/src/fields/Months.tsx b/src/fields/Months.tsx index 59d5b40..19e6c4f 100644 --- a/src/fields/Months.tsx +++ b/src/fields/Months.tsx @@ -18,6 +18,8 @@ export default function Months(props: MonthsProps) { period, periodicityOnDoubleClick, mode, + allowClear, + filterOption, } = props const optionsList = locale.months || DEFAULT_LOCALE_EN.months @@ -58,6 +60,8 @@ export default function Months(props: MonthsProps) { period={period} periodicityOnDoubleClick={periodicityOnDoubleClick} mode={mode} + allowClear={allowClear} + filterOption={filterOption} /> ) diff --git a/src/fields/Period.tsx b/src/fields/Period.tsx index b9baecd..944af15 100644 --- a/src/fields/Period.tsx +++ b/src/fields/Period.tsx @@ -16,6 +16,7 @@ export default function Period(props: PeriodProps) { readOnly, shortcuts, allowedPeriods, + allowClear, } = props const options: BaseOptionType[] = [] @@ -131,6 +132,7 @@ export default function Period(props: PeriodProps) { showArrow={!readOnly} open={readOnly ? false : undefined} data-testid='select-period' + allowClear={allowClear} /> ) diff --git a/src/fields/WeekDays.tsx b/src/fields/WeekDays.tsx index c863d2c..d5f8845 100644 --- a/src/fields/WeekDays.tsx +++ b/src/fields/WeekDays.tsx @@ -19,6 +19,8 @@ export default function WeekDays(props: WeekDaysProps) { period, periodicityOnDoubleClick, mode, + allowClear, + filterOption, } = props const optionsList = locale.weekDays || DEFAULT_LOCALE_EN.weekDays const noMonthDays = period === 'week' || !monthDays || monthDays.length === 0 @@ -97,6 +99,8 @@ export default function WeekDays(props: WeekDaysProps) { period={period} periodicityOnDoubleClick={periodicityOnDoubleClick} mode={mode} + allowClear={allowClear} + filterOption={filterOption} /> ) : null diff --git a/src/stories/index.stories.tsx b/src/stories/index.stories.tsx index 348d6fb..0f334d3 100644 --- a/src/stories/index.stories.tsx +++ b/src/stories/index.stories.tsx @@ -1709,6 +1709,62 @@ export function NoPrefixAndSuffix() { ) } +export function DropdownsConfig() { + const defaultValue = '8 5 2,3 6 1,6' + const [value, setValue] = useState(defaultValue) + + return ( +
+

Default value: {defaultValue}

+

Value: {value}

+

"period" allowClear: false

+

"months" periodicityOnDoubleClick: false

+

"months" mode: "single"

+

"month-days" disabled: true

+

"week-days" humanizeLabels: false

+

"week-days" humanizeValue: true

+

"hours" readOnly: true

+

"minutes" leadingZero: true

+

"minutes" filterOption: 0, 1, 2, 3, 4, 5, 6, 6, 8, 9

+ + Number(value) < 10, + }, + }} + /> + +
+ + + You can configure each dropdown individually + +
+
+ ) +} + export function CustomStyle() { const defaultValue = '30 14 22 * *' const [values, dispatchValues] = useCronReducer(defaultValue) diff --git a/src/tests/Cron.defaultValue.test.tsx b/src/tests/Cron.defaultValue.test.tsx index e2fc0cf..8b47d27 100644 --- a/src/tests/Cron.defaultValue.test.tsx +++ b/src/tests/Cron.defaultValue.test.tsx @@ -6,6 +6,7 @@ import { ClockFormat, CronError, CronType, + DropdownsConfig, LeadingZero, PeriodType, Shortcuts, @@ -36,6 +37,7 @@ describe('Cron defaultValue test suite', () => { weekDaysSelect: string | undefined hoursSelect: string | undefined minutesSelect: string | undefined + dropdownsConfig?: DropdownsConfig error?: CronError }[] = [ { @@ -214,6 +216,26 @@ describe('Cron defaultValue test suite', () => { hoursSelect: '03AM,06PM', minutesSelect: '01', }, + { + title: 'dropdowns config is allowed', + defaultValue: '1 * * * MON-WED,sat', + expectedValue: '1 * * * MON-WED,SAT', + dropdownsConfig: { + 'week-days': { + humanizeLabels: true, + humanizeValue: true, + }, + 'minutes': { + leadingZero: true, + }, + }, + periodSelect: 'week', + monthsSelect: undefined, + monthDaysSelect: undefined, + weekDaysSelect: 'MON-WED,SAT', + hoursSelect: 'every hour', + minutesSelect: '01', + }, { title: 'that default period can be override when default value is empty', defaultValue: '', @@ -730,6 +752,7 @@ describe('Cron defaultValue test suite', () => { weekDaysSelect, hoursSelect, minutesSelect, + dropdownsConfig, error, }) => { const setValue = jest.fn() @@ -748,6 +771,7 @@ describe('Cron defaultValue test suite', () => { clockFormat={clockFormat} allowedDropdowns={allowedDropdowns} defaultPeriod={defaultPeriod} + dropdownsConfig={dropdownsConfig} /> ) diff --git a/src/tests/Cron.updateValue.test.tsx b/src/tests/Cron.updateValue.test.tsx index 9288e16..465b383 100644 --- a/src/tests/Cron.updateValue.test.tsx +++ b/src/tests/Cron.updateValue.test.tsx @@ -56,21 +56,7 @@ describe('Cron update value test suite', () => { await waitFor(() => user.click(screen.getByText('59'))) // Check dropdowns values - await waitFor(() => - expect(screen.getByTestId('custom-select-minutes').textContent).toContain( - '1,4,59' - ) - ) - - // Select another minute value - await waitFor(() => user.click(screen.getByText('8'))) - - // Check dropdowns values - await waitFor(() => - expect(screen.getByTestId('custom-select-minutes').textContent).toContain( - '1,4,8,59' - ) - ) + expect(await screen.findByText('1,4,59')).toBeVisible() }) it("should check that it's possible to select a periodicity with double click", async () => { diff --git a/src/types.ts b/src/types.ts index 2d8f1cf..d97c463 100644 --- a/src/types.ts +++ b/src/types.ts @@ -5,7 +5,7 @@ import { Dispatch, SetStateAction } from 'react' export interface CronProps { /** - * Cron value, the component is by design a controled component. + * Cron value, the component is by design a controlled component. * The first value will be the default value. * * required @@ -68,6 +68,13 @@ export interface CronProps { */ readOnly?: boolean + /** + * Show clear button for each dropdown. + * + * Default: true + */ + allowClear?: boolean + /** * Define if empty should trigger an error. * @@ -84,6 +91,8 @@ export interface CronProps { /** * Define the clock format. + * + * Default: undefined */ clockFormat?: ClockFormat @@ -127,7 +136,7 @@ export interface CronProps { periodicityOnDoubleClick?: boolean /** - * Define if it's possible to select only one or multiple values for each select. + * Define if it's possible to select only one or multiple values for each dropdowns. * * Even in single mode, if you want to disable the double click on a dropdown option that * automatically select / unselect a periodicity, set 'periodicityOnDoubleClick' @@ -154,6 +163,54 @@ export interface CronProps { */ allowedPeriods?: PeriodType[] + /** + * Define specific configuration that is used for each dropdown specifically. + * Configuring a dropdown will override any global configuration for the same property. + * + * Configuration available: + * + * // See global configuration + * // For 'months' and 'week-days' + * humanizeLabels?: boolean + * + * // See global configuration + * // For 'months' and 'week-days' + * humanizeValue?: boolean + * + * // See global configuration + * // For 'month-days', 'hours' and 'minutes' + * leadingZero?: boolean + * + * // See global configuration + * For 'period', 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * disabled?: boolean + * + * // See global configuration + * For 'period', 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * readOnly?: boolean + * + * // See global configuration + * // For 'period', 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * allowClear?: boolean + * + * // See global configuration + * // For 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * periodicityOnDoubleClick?: boolean + * + * // See global configuration + * // For 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * mode?: Mode + * + * // The function will receive one argument, an object with value and label. + * // If the function returns true, the option will be included in the filtered set. + * // Otherwise, it will be excluded. + * // For 'months', 'month-days', 'week-days', 'hours' and 'minutes' + * filterOption?: FilterOption + * + * Default: undefined + */ + dropdownsConfig?: DropdownsConfig + /** * Change the component language. * Can also be used to remove prefix and suffix. @@ -164,7 +221,7 @@ export interface CronProps { * The order of the 'locale' properties 'weekDays', 'months', 'altMonths' * and 'altWeekDays' is important! The index will be used as value. * - * Default './locale.ts' + * Default './src/locale.ts' */ locale?: Locale } @@ -252,6 +309,25 @@ export type ShortcutsType = | '@reboot' export type Shortcuts = boolean | ShortcutsType[] export type Mode = 'multiple' | 'single' +export type DropdownConfig = { + humanizeLabels?: boolean + humanizeValue?: boolean + leadingZero?: boolean + disabled?: boolean + readOnly?: boolean + allowClear?: boolean + periodicityOnDoubleClick?: boolean + mode?: Mode + filterOption?: FilterOption +} +export type DropdownsConfig = { + 'period'?: Pick + 'months'?: Omit + 'month-days'?: Omit + 'week-days'?: Omit + 'hours'?: Omit + 'minutes'?: Omit +} // Internal props @@ -265,11 +341,18 @@ export interface FieldProps { period: PeriodType periodicityOnDoubleClick: boolean mode: Mode + allowClear?: boolean + filterOption?: FilterOption } export interface PeriodProps extends Omit< FieldProps, - 'value' | 'setValue' | 'period' | 'periodicityOnDoubleClick' | 'mode' + | 'value' + | 'setValue' + | 'period' + | 'periodicityOnDoubleClick' + | 'mode' + | 'filterOption' > { value: PeriodType setValue: SetValuePeriod @@ -300,7 +383,6 @@ export interface CustomSelectProps SelectProps, | 'mode' | 'tokenSeparators' - | 'allowClear' | 'virtual' | 'onClick' | 'onBlur' @@ -313,6 +395,7 @@ export interface CustomSelectProps | 'options' | 'onSelect' | 'onDeselect' + | 'filterOption' > { grid?: boolean setValue: SetValueNumbersOrUndefined @@ -328,6 +411,7 @@ export interface CustomSelectProps unit: Unit periodicityOnDoubleClick: boolean mode: Mode + filterOption?: FilterOption } export type SetValueNumbersOrUndefined = Dispatch< SetStateAction @@ -385,3 +469,11 @@ export interface Clicks { time: number value: number } + +export type FilterOption = ({ + value, + label, +}: { + value: string + label: string +}) => boolean