@mtes-mct/monitor-ui 2.7.0 → 2.7.2
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/CHANGELOG.md +14 -0
- package/index.js +7 -19
- package/index.js.map +1 -1
- package/package.json +1 -1
- package/src/fields/DateRangePicker/TimeInput.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
## [2.7.1](https://github.com/MTES-MCT/monitor-ui/compare/v2.7.0...v2.7.1) (2023-01-13)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **fields:** handle detached click outside for time in DatePicker & DateRangePicker ([afa0a13](https://github.com/MTES-MCT/monitor-ui/commit/afa0a13394f650b0d26a5cf868a325cc79335dcb))
|
|
7
|
+
|
|
8
|
+
# [2.7.0](https://github.com/MTES-MCT/monitor-ui/compare/v2.6.0...v2.7.0) (2023-01-12)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **fields:** add baseContainer prop to fields with global event listeners ([ebbb874](https://github.com/MTES-MCT/monitor-ui/commit/ebbb874be7352ce8830e94b7654fe27bbd00e544))
|
|
14
|
+
|
|
1
15
|
# [2.6.0](https://github.com/MTES-MCT/monitor-ui/compare/v2.5.1...v2.6.0) (2023-01-10)
|
|
2
16
|
|
|
3
17
|
|
package/index.js
CHANGED
|
@@ -1955,9 +1955,9 @@ const Dropdown = Object.assign(RawDropdown, {
|
|
|
1955
1955
|
});
|
|
1956
1956
|
|
|
1957
1957
|
const ICON_SIZE = {
|
|
1958
|
-
[Size.LARGE]:
|
|
1959
|
-
[Size.NORMAL]:
|
|
1960
|
-
[Size.SMALL]:
|
|
1958
|
+
[Size.LARGE]: 20,
|
|
1959
|
+
[Size.NORMAL]: 20,
|
|
1960
|
+
[Size.SMALL]: 12
|
|
1961
1961
|
};
|
|
1962
1962
|
function Button({ accent = Accent.PRIMARY, children, Icon, isFullWidth = false, size = Size.NORMAL, type = 'button', ...nativeProps }) {
|
|
1963
1963
|
const commonChildren = useMemo(() => (jsxs(Fragment, { children: [Icon && jsx(Icon, { size: ICON_SIZE[size] }), children] })), [children, Icon, size]);
|
|
@@ -4143,7 +4143,7 @@ const Option = styled.div `
|
|
|
4143
4143
|
}
|
|
4144
4144
|
`;
|
|
4145
4145
|
|
|
4146
|
-
function TimeInputWithRef({ defaultValue,
|
|
4146
|
+
function TimeInputWithRef({ baseContainer, defaultValue,
|
|
4147
4147
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
4148
4148
|
disabled = false, isCompact, isEndDate = false, isLight, isStartDate = false, minutesRange = 15, onBack, onChange, onFocus, onNext, onPrevious }, ref) {
|
|
4149
4149
|
const boxRef = useRef();
|
|
@@ -4181,13 +4181,6 @@ disabled = false, isCompact, isEndDate = false, isLight, isStartDate = false, mi
|
|
|
4181
4181
|
const handleBlur = useCallback(() => {
|
|
4182
4182
|
setIsFocused(false);
|
|
4183
4183
|
}, []);
|
|
4184
|
-
const handleClickOutside = useCallback((event) => {
|
|
4185
|
-
const target = event.target;
|
|
4186
|
-
if (hourInputRef.current.contains(target) || minuteInputRef.current.contains(target)) {
|
|
4187
|
-
return;
|
|
4188
|
-
}
|
|
4189
|
-
closeRangedTimePicker();
|
|
4190
|
-
}, [closeRangedTimePicker]);
|
|
4191
4184
|
const handleFocus = useCallback(() => {
|
|
4192
4185
|
setIsFocused(true);
|
|
4193
4186
|
if (onFocus) {
|
|
@@ -4211,12 +4204,6 @@ disabled = false, isCompact, isEndDate = false, isLight, isStartDate = false, mi
|
|
|
4211
4204
|
isRangedTimePickerOpenRef.current = true;
|
|
4212
4205
|
forceUpdate();
|
|
4213
4206
|
}, [forceUpdate]);
|
|
4214
|
-
useEffect(() => {
|
|
4215
|
-
window.document.addEventListener('click', handleClickOutside);
|
|
4216
|
-
return () => {
|
|
4217
|
-
window.document.removeEventListener('click', handleClickOutside);
|
|
4218
|
-
};
|
|
4219
|
-
}, [handleClickOutside]);
|
|
4220
4207
|
const submit = useCallback(() => {
|
|
4221
4208
|
setHasValidationError(false);
|
|
4222
4209
|
if (window.document.activeElement === hourInputRef.current) {
|
|
@@ -4232,6 +4219,7 @@ disabled = false, isCompact, isEndDate = false, isLight, isStartDate = false, mi
|
|
|
4232
4219
|
const nextTimeTuple = [hourInputRef.current.value, minuteInputRef.current.value];
|
|
4233
4220
|
onChange(nextTimeTuple);
|
|
4234
4221
|
}, [closeRangedTimePicker, onChange]);
|
|
4222
|
+
useClickOutside(boxRef, closeRangedTimePicker, baseContainer);
|
|
4235
4223
|
return (jsxs(Box$6, { ref: boxRef, "$hasError": hasFormatError || hasValidationError, "$isCompact": isCompact, "$isDisabled": disabled, "$isFocused": isFocused, "$isLight": isLight, children: [jsxs(InputGroup, { children: [jsxs("div", { children: [jsx(NumberInput$1, { ref: hourInputRef, "aria-label": `Heure${isStartDate ? ' de début' : ''}${isEndDate ? ' de fin' : ''}`, defaultValue: controlledDefaultValue && controlledDefaultValue[0], disabled: disabled, isLight: isLight, max: 23, min: 0, onBack: handleBack, onBlur: handleBlur, onClick: openRangedTimePicker, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onInput: handleHourInput, onNext: () => minuteInputRef.current.focus(), onPrevious: onPrevious, size: 2 }), ":", jsx(NumberInput$1, { ref: minuteInputRef, "aria-label": `Minute${isStartDate ? ' de début' : ''}${isEndDate ? ' de fin' : ''}`, defaultValue: controlledDefaultValue && controlledDefaultValue[1], disabled: disabled, isLight: isLight, max: 59, min: 0, onBack: () => hourInputRef.current.focus(), onBlur: handleBlur, onClick: openRangedTimePicker, onFilled: submit, onFocus: handleFocus, onFormatError: handleFormatError, onNext: onNext, onPrevious: () => hourInputRef.current.focus(), size: 2 })] }), !isCompact && jsx(Clock, {})] }), isRangedTimePickerOpenRef.current && (jsx(RangedTimePicker, { filter: rangedTimePickerFilter, minutesRange: minutesRange, onChange: handleRangedTimePickedChange }))] }));
|
|
4236
4224
|
}
|
|
4237
4225
|
const TimeInput = forwardRef(TimeInputWithRef);
|
|
@@ -4558,7 +4546,7 @@ disabled = false, isCompact = false, isHistorical = false, isLabelHidden = false
|
|
|
4558
4546
|
forceUpdate();
|
|
4559
4547
|
}, [forceUpdate]);
|
|
4560
4548
|
useClickOutside(boxRef, closeCalendarPicker, baseContainer);
|
|
4561
|
-
return (jsxs(Fieldset, { disabled: disabled, ...nativeProps, children: [jsx(Legend, { isDisabled: disabled, isHidden: isLabelHidden, children: label }), jsxs(Box$4, { ref: boxRef, children: [jsx(Field$1, { children: jsx(DateInput, { ref: dateInputRef, defaultValue: selectedDateTupleRef.current, disabled: disabled, isCompact: isCompact, isForcedFocused: isCalendarPickerOpenRef.current, isLight: isLight, onChange: handleDateInputChange, onClick: openCalendarPicker, onNext: handleDateInputNext }) }), withTime && (jsx(Field$1, { "$isTimeField": true, children: jsx(TimeInput, { ref: timeInputRef, defaultValue: selectedTimeTupleRef.current, disabled: disabled, isCompact: isCompact, isLight: isLight, minutesRange: minutesRange, onBack: () => dateInputRef.current.focus(true), onChange: handleTimeInputFilled, onFocus: closeCalendarPicker, onPrevious: () => dateInputRef.current.focus(true) }) }))] }), jsx(CalendarPicker, { defaultValue: rangeCalendarPickerDefaultValue, isHistorical: isHistorical, isOpen: isCalendarPickerOpenRef.current, onChange: handleCalendarPickerChange })] }));
|
|
4549
|
+
return (jsxs(Fieldset, { disabled: disabled, ...nativeProps, children: [jsx(Legend, { isDisabled: disabled, isHidden: isLabelHidden, children: label }), jsxs(Box$4, { ref: boxRef, children: [jsx(Field$1, { children: jsx(DateInput, { ref: dateInputRef, defaultValue: selectedDateTupleRef.current, disabled: disabled, isCompact: isCompact, isForcedFocused: isCalendarPickerOpenRef.current, isLight: isLight, onChange: handleDateInputChange, onClick: openCalendarPicker, onNext: handleDateInputNext }) }), withTime && (jsx(Field$1, { "$isTimeField": true, children: jsx(TimeInput, { ref: timeInputRef, baseContainer: baseContainer, defaultValue: selectedTimeTupleRef.current, disabled: disabled, isCompact: isCompact, isLight: isLight, minutesRange: minutesRange, onBack: () => dateInputRef.current.focus(true), onChange: handleTimeInputFilled, onFocus: closeCalendarPicker, onPrevious: () => dateInputRef.current.focus(true) }) }))] }), jsx(CalendarPicker, { defaultValue: rangeCalendarPickerDefaultValue, isHistorical: isHistorical, isOpen: isCalendarPickerOpenRef.current, onChange: handleCalendarPickerChange })] }));
|
|
4562
4550
|
}
|
|
4563
4551
|
const Box$4 = styled.div `
|
|
4564
4552
|
* {
|
|
@@ -4922,7 +4910,7 @@ disabled = false, isCompact = false, isHistorical = false, isLabelHidden = false
|
|
|
4922
4910
|
forceUpdate();
|
|
4923
4911
|
}, [forceUpdate]);
|
|
4924
4912
|
useClickOutside([endDateInputRef, startDateInputRef], closeRangeCalendarPicker, baseContainer);
|
|
4925
|
-
return (jsxs(Fieldset, { ...nativeProps, children: [jsx(Legend, { isDisabled: disabled, isHidden: isLabelHidden, children: label }), jsxs(Box$2, { isDisabled: disabled, children: [jsx(Field, { children: jsx(DateInput, { ref: startDateInputRef, defaultValue: selectedStartDateTupleRef.current, disabled: disabled, isCompact: isCompact, isForcedFocused: isRangeCalendarPickerOpenRef.current, isLight: isLight, isStartDate: true, onChange: (nextDateTuple, isFilled) => handleDateInputChange(DateRangePosition.START, nextDateTuple, isFilled), onClick: openRangeCalendarPicker, onNext: handleStartDateInputNext }) }), withTime && (jsx(Field, { isTimeField: true, children: jsx(TimeInput, { ref: startTimeInputRef, defaultValue: selectedStartTimeTupleRef.current, disabled: disabled, isCompact: isCompact, isLight: isLight, isStartDate: true, minutesRange: minutesRange, onBack: () => startDateInputRef.current.focus(true), onChange: nextTimeTuple => handleTimeInputFilled(DateRangePosition.START, nextTimeTuple), onFocus: closeRangeCalendarPicker, onNext: () => endDateInputRef.current.focus(), onPrevious: () => startDateInputRef.current.focus(true) }) })), jsx(Field, { isEndDateField: true, children: jsx(DateInput, { ref: endDateInputRef, defaultValue: selectedEndDateTupleRef.current, disabled: disabled, isCompact: isCompact, isEndDate: true, isForcedFocused: isRangeCalendarPickerOpenRef.current, isLight: isLight, onBack: handleEndDateInputPrevious, onChange: (nextDateTuple, isFilled) => handleDateInputChange(DateRangePosition.END, nextDateTuple, isFilled), onClick: openRangeCalendarPicker, onNext: handleEndDateInputNext, onPrevious: handleEndDateInputPrevious }) }), withTime && (jsx(Field, { isTimeField: true, children: jsx(TimeInput, { ref: endTimeInputRef, defaultValue: selectedEndTimeTupleRef.current, disabled: disabled, isCompact: isCompact, isEndDate: true, isLight: isLight, minutesRange: minutesRange, onBack: () => endDateInputRef.current.focus(true), onChange: nextTimeTuple => handleTimeInputFilled(DateRangePosition.END, nextTimeTuple), onFocus: closeRangeCalendarPicker, onPrevious: () => endDateInputRef.current.focus(true) }) }))] }), jsx(RangeCalendarPicker, { defaultValue: rangeCalendarPickerDefaultValue, isHistorical: isHistorical, isOpen: isRangeCalendarPickerOpenRef.current, onChange: handleRangeCalendarPickerChange })] }));
|
|
4913
|
+
return (jsxs(Fieldset, { ...nativeProps, children: [jsx(Legend, { isDisabled: disabled, isHidden: isLabelHidden, children: label }), jsxs(Box$2, { isDisabled: disabled, children: [jsx(Field, { children: jsx(DateInput, { ref: startDateInputRef, defaultValue: selectedStartDateTupleRef.current, disabled: disabled, isCompact: isCompact, isForcedFocused: isRangeCalendarPickerOpenRef.current, isLight: isLight, isStartDate: true, onChange: (nextDateTuple, isFilled) => handleDateInputChange(DateRangePosition.START, nextDateTuple, isFilled), onClick: openRangeCalendarPicker, onNext: handleStartDateInputNext }) }), withTime && (jsx(Field, { isTimeField: true, children: jsx(TimeInput, { ref: startTimeInputRef, baseContainer: baseContainer, defaultValue: selectedStartTimeTupleRef.current, disabled: disabled, isCompact: isCompact, isLight: isLight, isStartDate: true, minutesRange: minutesRange, onBack: () => startDateInputRef.current.focus(true), onChange: nextTimeTuple => handleTimeInputFilled(DateRangePosition.START, nextTimeTuple), onFocus: closeRangeCalendarPicker, onNext: () => endDateInputRef.current.focus(), onPrevious: () => startDateInputRef.current.focus(true) }) })), jsx(Field, { isEndDateField: true, children: jsx(DateInput, { ref: endDateInputRef, defaultValue: selectedEndDateTupleRef.current, disabled: disabled, isCompact: isCompact, isEndDate: true, isForcedFocused: isRangeCalendarPickerOpenRef.current, isLight: isLight, onBack: handleEndDateInputPrevious, onChange: (nextDateTuple, isFilled) => handleDateInputChange(DateRangePosition.END, nextDateTuple, isFilled), onClick: openRangeCalendarPicker, onNext: handleEndDateInputNext, onPrevious: handleEndDateInputPrevious }) }), withTime && (jsx(Field, { isTimeField: true, children: jsx(TimeInput, { ref: endTimeInputRef, baseContainer: baseContainer, defaultValue: selectedEndTimeTupleRef.current, disabled: disabled, isCompact: isCompact, isEndDate: true, isLight: isLight, minutesRange: minutesRange, onBack: () => endDateInputRef.current.focus(true), onChange: nextTimeTuple => handleTimeInputFilled(DateRangePosition.END, nextTimeTuple), onFocus: closeRangeCalendarPicker, onPrevious: () => endDateInputRef.current.focus(true) }) }))] }), jsx(RangeCalendarPicker, { defaultValue: rangeCalendarPickerDefaultValue, isHistorical: isHistorical, isOpen: isRangeCalendarPickerOpenRef.current, onChange: handleRangeCalendarPickerChange })] }));
|
|
4926
4914
|
}
|
|
4927
4915
|
const Box$2 = styled.div `
|
|
4928
4916
|
* {
|