@entur/datepicker 9.4.10 → 9.4.11
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/dist/datepicker.cjs.development.js +26 -12
- package/dist/datepicker.cjs.development.js.map +1 -1
- package/dist/datepicker.cjs.production.min.js +1 -1
- package/dist/datepicker.cjs.production.min.js.map +1 -1
- package/dist/datepicker.esm.js +27 -13
- package/dist/datepicker.esm.js.map +1 -1
- package/dist/styles.css +62 -62
- package/package.json +11 -11
package/dist/datepicker.esm.js
CHANGED
|
@@ -15,7 +15,7 @@ import { IconButton } from '@entur/button';
|
|
|
15
15
|
import { VisuallyHidden } from '@entur/a11y';
|
|
16
16
|
import { useFloating, autoUpdate, offset, flip, shift } from '@floating-ui/react-dom';
|
|
17
17
|
import FocusLock from 'react-focus-lock';
|
|
18
|
-
import { space, zIndexes } from '@entur/tokens';
|
|
18
|
+
import { space, zIndexes, timings } from '@entur/tokens';
|
|
19
19
|
import { Modal } from '@entur/modal';
|
|
20
20
|
|
|
21
21
|
function _extends() {
|
|
@@ -527,11 +527,12 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
527
527
|
var datePickerRef = useRef(null);
|
|
528
528
|
var calendarRef = useRef(null);
|
|
529
529
|
var dateFieldRef = useRef(null);
|
|
530
|
+
var _useState = useState(false),
|
|
531
|
+
showAnimations = _useState[0],
|
|
532
|
+
setShowAnimations = _useState[1];
|
|
530
533
|
var _useWindowDimensions = useWindowDimensions(),
|
|
531
534
|
width = _useWindowDimensions.width;
|
|
532
535
|
var handleOnChange = function handleOnChange(value) {
|
|
533
|
-
// console.log(value && value.compare(parseDate('1000-01-01')) < 0);
|
|
534
|
-
// if (value && value.compare(parseDate('1000-01-01')) < 0) return;
|
|
535
536
|
if (forcedReturnType !== undefined) {
|
|
536
537
|
return onChange(convertValueToType({
|
|
537
538
|
value: value,
|
|
@@ -559,7 +560,11 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
559
560
|
calendarProps = _useDatePicker.calendarProps;
|
|
560
561
|
// calculations for floating-UI popover position
|
|
561
562
|
var _useFloating = useFloating({
|
|
562
|
-
whileElementsMounted:
|
|
563
|
+
whileElementsMounted: function whileElementsMounted(ref, _float, update) {
|
|
564
|
+
return autoUpdate(ref, _float, update, {
|
|
565
|
+
elementResize: false
|
|
566
|
+
});
|
|
567
|
+
},
|
|
563
568
|
placement: 'bottom-start',
|
|
564
569
|
middleware: [offset(space.extraSmall), flip(), shift({
|
|
565
570
|
padding: space.extraSmall
|
|
@@ -567,9 +572,9 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
567
572
|
}),
|
|
568
573
|
x = _useFloating.x,
|
|
569
574
|
y = _useFloating.y,
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
575
|
+
refs = _useFloating.refs,
|
|
576
|
+
strategy = _useFloating.strategy,
|
|
577
|
+
update = _useFloating.update;
|
|
573
578
|
useOnClickOutside([calendarRef], function () {
|
|
574
579
|
state.setOpen(false);
|
|
575
580
|
});
|
|
@@ -592,17 +597,25 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
592
597
|
showWeekNumbers: showWeekNumbers,
|
|
593
598
|
weekNumberHeader: weekNumberHeader
|
|
594
599
|
});
|
|
600
|
+
// Initial position for popover is (0,0) before being moved to calculated position.
|
|
601
|
+
// To avoid animating this move we delay turning on animation by a few ms.
|
|
602
|
+
useEffect(function () {
|
|
603
|
+
setTimeout(function () {
|
|
604
|
+
return setShowAnimations(state.isOpen);
|
|
605
|
+
}, 10);
|
|
606
|
+
}, [state.isOpen]);
|
|
595
607
|
var useModal = typeof width !== 'undefined' && width <= CALENDAR_MODAL_MAX_SCREEN_WIDTH && !disableModal;
|
|
596
608
|
var popoverCalendar = React.createElement("div", {
|
|
597
609
|
// styling for floating-UI popover
|
|
598
610
|
style: {
|
|
599
611
|
position: strategy,
|
|
600
|
-
top: y
|
|
601
|
-
left: x
|
|
602
|
-
zIndex: zIndexes.popover
|
|
612
|
+
top: y,
|
|
613
|
+
left: x,
|
|
614
|
+
zIndex: zIndexes.popover,
|
|
615
|
+
transition: showAnimations ? "top " + timings.medium + " ease-in-out" : 'unset'
|
|
603
616
|
},
|
|
604
617
|
ref: function ref(node) {
|
|
605
|
-
|
|
618
|
+
refs.setFloating(node);
|
|
606
619
|
}
|
|
607
620
|
}, React.createElement(FocusLock, {
|
|
608
621
|
disabled: !state.isOpen || useModal,
|
|
@@ -629,7 +642,7 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
629
642
|
}, React.createElement("div", _extends({}, groupProps, {
|
|
630
643
|
ref: function ref(node) {
|
|
631
644
|
datePickerRef.current = node;
|
|
632
|
-
|
|
645
|
+
refs.setReference(node);
|
|
633
646
|
},
|
|
634
647
|
id: undefined,
|
|
635
648
|
className: "eds-datepicker__datefield__wrapper"
|
|
@@ -654,7 +667,8 @@ var DatePicker = function DatePicker(_ref) {
|
|
|
654
667
|
})
|
|
655
668
|
})), !disabled && React.createElement(CalendarButton, _extends({}, buttonProps, {
|
|
656
669
|
onPress: function onPress() {
|
|
657
|
-
|
|
670
|
+
state.setOpen(!state.isOpen);
|
|
671
|
+
update();
|
|
658
672
|
},
|
|
659
673
|
className: "eds-datepicker__open-calendar-button"
|
|
660
674
|
}), React.createElement(CalendarIcon, null)), useModal ? modalCalendar : popoverCalendar)));
|