@mezzanine-ui/react 0.14.5 → 0.14.6
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.
|
@@ -2,16 +2,21 @@ import { DateType } from '@mezzanine-ui/core/calendar';
|
|
|
2
2
|
import { RangePickerPickingValue, RangePickerValue } from '@mezzanine-ui/core/picker';
|
|
3
3
|
import { ChangeEventHandler, KeyboardEventHandler } from 'react';
|
|
4
4
|
import { UseRangePickerValueProps } from '../Picker/useRangePickerValue';
|
|
5
|
+
import { DateRangePickerCalendarProps } from './DateRangePickerCalendar';
|
|
5
6
|
export interface UseDateRangePickerValueProps extends Omit<UseRangePickerValueProps, 'onChange'> {
|
|
7
|
+
mode?: DateRangePickerCalendarProps['mode'];
|
|
6
8
|
onChange?: (value?: RangePickerValue) => void;
|
|
7
9
|
}
|
|
8
|
-
export declare function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, onChange: onChangeProp, value: valueProp, }: UseDateRangePickerValueProps): {
|
|
10
|
+
export declare function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, mode, onChange: onChangeProp, value: valueProp, }: UseDateRangePickerValueProps): {
|
|
9
11
|
calendarValue: string[] | undefined;
|
|
10
12
|
inputFromValue: string;
|
|
11
13
|
inputToValue: string;
|
|
12
14
|
onCalendarChange: (val?: DateType) => void;
|
|
13
15
|
onCalendarHover: import("react").Dispatch<import("react").SetStateAction<string | undefined>> | undefined;
|
|
14
|
-
onChange: (target?: RangePickerPickingValue | undefined
|
|
16
|
+
onChange: (target?: RangePickerPickingValue | undefined, callback?: {
|
|
17
|
+
from: (date?: string | undefined) => string | undefined;
|
|
18
|
+
to: (date?: string | undefined) => string | undefined;
|
|
19
|
+
}) => RangePickerPickingValue | undefined;
|
|
15
20
|
onClear: () => void;
|
|
16
21
|
onFromBlur: import("react").FocusEventHandler<HTMLInputElement>;
|
|
17
22
|
onFromKeyDown: KeyboardEventHandler<HTMLInputElement>;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useState, useMemo } from 'react';
|
|
2
2
|
import { useRangePickerValue } from '../Picker/useRangePickerValue.js';
|
|
3
|
+
import { useCalendarContext } from '../Calendar/CalendarContext.js';
|
|
3
4
|
|
|
4
|
-
function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, onChange: onChangeProp, value: valueProp, }) {
|
|
5
|
+
function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, mode, onChange: onChangeProp, value: valueProp, }) {
|
|
6
|
+
const { addDay, } = useCalendarContext();
|
|
5
7
|
const { inputFromValue, inputToValue, onChange, onFromBlur, onFromKeyDown, onInputFromChange, onInputToChange, onToBlur, onToKeyDown, value, } = useRangePickerValue({
|
|
6
8
|
format,
|
|
7
9
|
formats,
|
|
@@ -25,7 +27,15 @@ function useDateRangePickerValue({ format, formats, inputFromRef, inputToRef, on
|
|
|
25
27
|
? [val, undefined]
|
|
26
28
|
: [firstVal, val];
|
|
27
29
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
28
|
-
const [sortedFrom, sortedTo] = onChange(newValue
|
|
30
|
+
const [sortedFrom, sortedTo] = onChange(newValue, {
|
|
31
|
+
from: (nextFrom) => nextFrom,
|
|
32
|
+
to: (nextTo) => {
|
|
33
|
+
if (!nextTo)
|
|
34
|
+
return nextTo;
|
|
35
|
+
/** week mode should use the last day of the week (default is the first day) */
|
|
36
|
+
return mode === 'week' ? addDay(nextTo, 6) : nextTo;
|
|
37
|
+
},
|
|
38
|
+
});
|
|
29
39
|
if (sortedFrom && sortedTo) {
|
|
30
40
|
onChangeProp === null || onChangeProp === void 0 ? void 0 : onChangeProp([sortedFrom, sortedTo]);
|
|
31
41
|
}
|
|
@@ -9,7 +9,10 @@ export interface UseRangePickerValueProps extends Pick<UsePickerValueProps, 'for
|
|
|
9
9
|
export declare function useRangePickerValue({ format, formats, inputFromRef, inputToRef, value: valueProp, }: UseRangePickerValueProps): {
|
|
10
10
|
inputFromValue: string;
|
|
11
11
|
inputToValue: string;
|
|
12
|
-
onChange: (target?: RangePickerPickingValue
|
|
12
|
+
onChange: (target?: RangePickerPickingValue, callback?: {
|
|
13
|
+
from: (date?: string) => string | undefined;
|
|
14
|
+
to: (date?: string) => string | undefined;
|
|
15
|
+
}) => RangePickerPickingValue | undefined;
|
|
13
16
|
onFromBlur: import("react").FocusEventHandler<HTMLInputElement>;
|
|
14
17
|
onFromKeyDown: KeyboardEventHandler<HTMLInputElement>;
|
|
15
18
|
onInputFromChange: ChangeEventHandler<HTMLInputElement>;
|
|
@@ -23,16 +23,21 @@ function useRangePickerValue({ format, formats, inputFromRef, inputToRef, value:
|
|
|
23
23
|
inputRef: inputToRef,
|
|
24
24
|
});
|
|
25
25
|
const value = [from, to];
|
|
26
|
-
const onChange = (target
|
|
26
|
+
const onChange = (target, callback = {
|
|
27
|
+
from: (date) => date,
|
|
28
|
+
to: (date) => date,
|
|
29
|
+
}) => {
|
|
27
30
|
const [newFrom, newTo] = target || [];
|
|
28
31
|
if (newFrom && newTo) {
|
|
29
32
|
const sortedVal = sortValues([newFrom, newTo]);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
const resolvedFrom = callback.from(sortedVal[0]);
|
|
34
|
+
const resolvedTo = callback.to(sortedVal[1]);
|
|
35
|
+
onFromChange(resolvedFrom);
|
|
36
|
+
onToChange(resolvedTo);
|
|
37
|
+
return [resolvedFrom, resolvedTo];
|
|
33
38
|
}
|
|
34
|
-
onFromChange(target === null || target === void 0 ? void 0 : target[0]);
|
|
35
|
-
onToChange(target === null || target === void 0 ? void 0 : target[1]);
|
|
39
|
+
onFromChange(callback.from(target === null || target === void 0 ? void 0 : target[0]));
|
|
40
|
+
onToChange(callback.to(target === null || target === void 0 ? void 0 : target[1]));
|
|
36
41
|
return target;
|
|
37
42
|
};
|
|
38
43
|
const onOrderGuardedInputFromChange = (event) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mezzanine-ui/react",
|
|
3
|
-
"version": "0.14.
|
|
3
|
+
"version": "0.14.6",
|
|
4
4
|
"description": "React components for mezzanine-ui",
|
|
5
5
|
"author": "Mezzanine",
|
|
6
6
|
"repository": {
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"react-dom": "^18.2.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@mezzanine-ui/core": "^0.14.
|
|
32
|
-
"@mezzanine-ui/icons": "^0.14.
|
|
33
|
-
"@mezzanine-ui/system": "^0.14.
|
|
31
|
+
"@mezzanine-ui/core": "^0.14.6",
|
|
32
|
+
"@mezzanine-ui/icons": "^0.14.6",
|
|
33
|
+
"@mezzanine-ui/system": "^0.14.6",
|
|
34
34
|
"@popperjs/core": "^2.11.6",
|
|
35
35
|
"@types/react-transition-group": "^4.4.8",
|
|
36
36
|
"clsx": "^2.0.0",
|