@mtes-mct/monitor-ui 2.7.2 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtes-mct/monitor-ui",
3
3
  "description": "Common React UI components and styles for Monitorfish and Monitorenv.",
4
- "version": "2.7.2",
4
+ "version": "2.8.0",
5
5
  "license": "AGPL-3.0",
6
6
  "engines": {
7
7
  "node": ">=18"
@@ -1,15 +1,21 @@
1
1
  import type { HTMLAttributes } from 'react';
2
2
  import type { Promisable } from 'type-fest';
3
- export type DatePickerProps = Omit<HTMLAttributes<HTMLFieldSetElement>, 'defaultValue' | 'onChange'> & {
3
+ /**
4
+ * This type should not be exposed in the final library. It's only exported to be reused in <FormikDatePicker />.
5
+ *
6
+ * @private
7
+ */
8
+ export interface DatePickerProps extends Omit<HTMLAttributes<HTMLFieldSetElement>, 'defaultValue' | 'onChange'> {
4
9
  /** Used to pass something else than `window.document` as a base container to attach global events listeners. */
5
10
  baseContainer?: Document | HTMLDivElement | null;
6
- defaultValue?: Date;
11
+ defaultValue?: Date | string;
7
12
  disabled?: boolean;
8
13
  isCompact?: boolean;
9
14
  /** Only allow past dates until today. */
10
15
  isHistorical?: boolean;
11
16
  isLabelHidden?: boolean;
12
17
  isLight?: boolean;
18
+ isStringDate?: boolean;
13
19
  label: string;
14
20
  /**
15
21
  * Range of minutes used to generate the time picker list.
@@ -23,7 +29,16 @@ export type DatePickerProps = Omit<HTMLAttributes<HTMLFieldSetElement>, 'default
23
29
  *
24
30
  * @param nextUtcDateRange - A utcized date to be used as is to interact with the API.
25
31
  */
26
- onChange?: (nextUtcDate: Date) => Promisable<void>;
32
+ onChange?: ((nextUtcDate: Date) => Promisable<void>) | ((nextUtcDate: string) => Promisable<void>);
27
33
  withTime?: boolean;
28
- };
29
- export declare function DatePicker({ baseContainer, defaultValue, disabled, isCompact, isHistorical, isLabelHidden, isLight, label, minutesRange, onChange, withTime, ...nativeProps }: DatePickerProps): JSX.Element;
34
+ }
35
+ export interface DatePickerWithDateDateProps extends DatePickerProps {
36
+ isStringDate?: false;
37
+ onChange?: (nextUtcDate: Date) => Promisable<void>;
38
+ }
39
+ export interface DatePickerWithStringDateProps extends DatePickerProps {
40
+ isStringDate: true;
41
+ onChange?: (nextUtcDate: string) => Promisable<void>;
42
+ }
43
+ export declare function DatePicker(props: DatePickerWithDateDateProps): JSX.Element;
44
+ export declare function DatePicker(props: DatePickerWithStringDateProps): JSX.Element;
@@ -1,16 +1,22 @@
1
- import type { DateRange } from '../../types';
1
+ import type { DateAsStringRange, DateRange } from '../../types';
2
2
  import type { HTMLAttributes } from 'react';
3
3
  import type { Promisable } from 'type-fest';
4
- export type DateRangePickerProps = Omit<HTMLAttributes<HTMLFieldSetElement>, 'defaultValue' | 'onChange'> & {
4
+ /**
5
+ * This type should not be exposed in the final library. It's only exported to be reused in <FormikDateRangePicker />.
6
+ *
7
+ * @private
8
+ */
9
+ export interface DateRangePickerProps extends Omit<HTMLAttributes<HTMLFieldSetElement>, 'defaultValue' | 'onChange'> {
5
10
  /** Used to pass something else than `window.document` as a base container to attach global events listeners. */
6
11
  baseContainer?: Document | HTMLDivElement | null;
7
- defaultValue?: DateRange;
12
+ defaultValue?: DateRange | DateAsStringRange;
8
13
  disabled?: boolean;
9
14
  isCompact?: boolean;
10
15
  /** Only allow past dates until today. */
11
16
  isHistorical?: boolean;
12
17
  isLabelHidden?: boolean;
13
18
  isLight?: boolean;
19
+ isStringDate?: boolean;
14
20
  label: string;
15
21
  /**
16
22
  * Range of minutes used to generate the time picker list.
@@ -24,7 +30,16 @@ export type DateRangePickerProps = Omit<HTMLAttributes<HTMLFieldSetElement>, 'de
24
30
  *
25
31
  * @param nextUtcDateRange - A utcized date to be used as is to interact with the API.
26
32
  */
27
- onChange?: (nextUtcDateRange: DateRange) => Promisable<void>;
33
+ onChange?: ((nextUtcDateRange: DateRange) => Promisable<void>) | ((nextUtcDateRange: DateAsStringRange) => Promisable<void>);
28
34
  withTime?: boolean;
29
- };
30
- export declare function DateRangePicker({ baseContainer, defaultValue, disabled, isCompact, isHistorical, isLabelHidden, isLight, label, minutesRange, onChange, withTime, ...nativeProps }: DateRangePickerProps): JSX.Element;
35
+ }
36
+ export interface DateRangePickerWithDateDateProps extends DateRangePickerProps {
37
+ isStringDate?: false;
38
+ onChange?: (nextUtcDateRange: DateRange) => Promisable<void>;
39
+ }
40
+ export interface DateRangePickerWithStringDateProps extends DateRangePickerProps {
41
+ isStringDate: true;
42
+ onChange?: (nextUtcDateRange: DateAsStringRange) => Promisable<void>;
43
+ }
44
+ export declare function DateRangePicker(props: DateRangePickerWithDateDateProps): JSX.Element;
45
+ export declare function DateRangePicker(props: DateRangePickerWithStringDateProps): JSX.Element;
@@ -1,5 +1,9 @@
1
- import type { DatePickerProps } from '../fields/DatePicker';
2
- export type FormikDatePickerProps = Omit<DatePickerProps, 'onChange'> & {
1
+ import type { DatePickerWithDateDateProps, DatePickerWithStringDateProps } from '../fields/DatePicker';
2
+ export interface FormikDatePickerWithDateDateProps extends Omit<DatePickerWithDateDateProps, 'onChange'> {
3
3
  name: string;
4
- };
5
- export declare function FormikDatePicker({ name, ...originalProps }: FormikDatePickerProps): JSX.Element;
4
+ }
5
+ export interface FormikDatePickerWithStringDateProps extends Omit<DatePickerWithStringDateProps, 'onChange'> {
6
+ name: string;
7
+ }
8
+ export declare function FormikDatePicker(props: FormikDatePickerWithDateDateProps): JSX.Element;
9
+ export declare function FormikDatePicker(props: FormikDatePickerWithStringDateProps): JSX.Element;
@@ -1,5 +1,9 @@
1
- import type { DateRangePickerProps } from '../fields/DateRangePicker';
2
- export type FormikDateRangePickerProps = Omit<DateRangePickerProps, 'onChange'> & {
1
+ import type { DateRangePickerWithDateDateProps, DateRangePickerWithStringDateProps } from '../fields/DateRangePicker';
2
+ export interface FormikDateRangePickerWithDateDateProps extends Omit<DateRangePickerWithDateDateProps, 'onChange'> {
3
3
  name: string;
4
- };
5
- export declare function FormikDateRangePicker({ name, ...originalProps }: FormikDateRangePickerProps): JSX.Element;
4
+ }
5
+ export interface FormikDateRangePickerWithStringDateProps extends Omit<DateRangePickerWithStringDateProps, 'onChange'> {
6
+ name: string;
7
+ }
8
+ export declare function FormikDateRangePicker(props: FormikDateRangePickerWithDateDateProps): JSX.Element;
9
+ export declare function FormikDateRangePicker(props: FormikDateRangePickerWithStringDateProps): JSX.Element;
package/src/index.d.ts CHANGED
@@ -40,7 +40,7 @@ export * as Icon from './icons';
40
40
  export { useClickOutside } from './hooks/useClickOutside';
41
41
  export { useForceUpdate } from './hooks/useForceUpdate';
42
42
  export type { PartialTheme, Theme } from './theme';
43
- export type { DateRange, IconProps, Option } from './types';
43
+ export type { DateAsStringRange, DateRange, IconProps, Option } from './types';
44
44
  export type { DropdownProps, DropdownItemProps } from './components/Dropdown';
45
45
  export type { ButtonProps } from './elements/Button';
46
46
  export type { FieldProps } from './elements/Field';
@@ -52,8 +52,8 @@ export type { TagProps } from './elements/Tag';
52
52
  export type { TagGroupProps } from './elements/TagGroup';
53
53
  export type { AutoCompleteProps } from './fields/AutoComplete';
54
54
  export type { CheckboxProps } from './fields/Checkbox';
55
- export type { DatePickerProps } from './fields/DatePicker';
56
- export type { DateRangePickerProps } from './fields/DateRangePicker';
55
+ export type { DatePickerWithDateDateProps, DatePickerWithStringDateProps } from './fields/DatePicker';
56
+ export type { DateRangePickerWithDateDateProps, DateRangePickerWithStringDateProps } from './fields/DateRangePicker';
57
57
  export type { MultiCheckboxProps } from './fields/MultiCheckbox';
58
58
  export type { MultiSelectProps } from './fields/MultiSelect';
59
59
  export type { MultiRadioProps } from './fields/MultiRadio';
@@ -64,8 +64,8 @@ export type { TextareaProps } from './fields/Textarea';
64
64
  export type { TextInputProps } from './fields/TextInput';
65
65
  export type { FormikAutoCompleteProps } from './formiks/FormikAutoComplete';
66
66
  export type { FormikCheckboxProps } from './formiks/FormikCheckbox';
67
- export type { FormikDatePickerProps } from './formiks/FormikDatePicker';
68
- export type { FormikDateRangePickerProps } from './formiks/FormikDateRangePicker';
67
+ export type { FormikDatePickerWithDateDateProps, FormikDatePickerWithStringDateProps } from './formiks/FormikDatePicker';
68
+ export type { FormikDateRangePickerWithDateDateProps, FormikDateRangePickerWithStringDateProps } from './formiks/FormikDateRangePicker';
69
69
  export type { FormikEffectProps } from './formiks/FormikEffect';
70
70
  export type { FormikMultiCheckboxProps } from './formiks/FormikMultiCheckbox';
71
71
  export type { FormikMultiSelectProps } from './formiks/FormikMultiSelect';
package/src/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { SVGProps } from 'react';
2
2
  export type DateRange = [Date, Date];
3
+ export type DateAsStringRange = [string, string];
3
4
  export type DeepPartial<T> = T extends object ? {
4
5
  [P in keyof T]?: DeepPartial<T[P]>;
5
6
  } : T;
@@ -5,4 +5,4 @@ import type { Dayjs } from 'dayjs';
5
5
  * @example
6
6
  * `2022-01-02T03:04:05.006Z` => `2022-01-02T03:04:05.006+01:00` (or `+02:00` during DST) in Europe/Paris timezone.
7
7
  */
8
- export declare function getLocalizedDayjs(utcDate: Date): Dayjs;
8
+ export declare function getLocalizedDayjs(utcDate: Date | string): Dayjs;