carbon-react 125.0.1 → 125.1.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/esm/__internal__/popover/popover.component.d.ts +2 -1
- package/esm/__internal__/popover/popover.component.js +4 -2
- package/esm/components/numeral-date/numeral-date.component.js +49 -17
- package/esm/components/popover-container/popover-container.component.d.ts +3 -1
- package/esm/components/popover-container/popover-container.component.js +6 -1
- package/esm/components/popover-container/popover-container.style.d.ts +1 -0
- package/esm/components/popover-container/popover-container.style.js +28 -25
- package/esm/locales/__internal__/pl-pl.js +6 -1
- package/esm/locales/en-gb.js +6 -1
- package/esm/locales/locale.d.ts +1 -1
- package/lib/__internal__/popover/popover.component.d.ts +2 -1
- package/lib/__internal__/popover/popover.component.js +4 -2
- package/lib/components/numeral-date/numeral-date.component.js +49 -17
- package/lib/components/popover-container/popover-container.component.d.ts +3 -1
- package/lib/components/popover-container/popover-container.component.js +6 -1
- package/lib/components/popover-container/popover-container.style.d.ts +1 -0
- package/lib/components/popover-container/popover-container.style.js +28 -25
- package/lib/locales/__internal__/pl-pl.js +6 -1
- package/lib/locales/en-gb.js +6 -1
- package/lib/locales/locale.d.ts +1 -1
- package/package.json +1 -1
|
@@ -12,6 +12,7 @@ export interface PopoverProps {
|
|
|
12
12
|
reference: CustomRefObject<HTMLElement>;
|
|
13
13
|
isOpen?: boolean;
|
|
14
14
|
animationFrame?: boolean;
|
|
15
|
+
popoverStrategy?: "absolute" | "fixed";
|
|
15
16
|
}
|
|
16
|
-
declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, }: PopoverProps) => React.JSX.Element;
|
|
17
|
+
declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, popoverStrategy, }: PopoverProps) => React.JSX.Element;
|
|
17
18
|
export default Popover;
|
|
@@ -17,7 +17,8 @@ const Popover = ({
|
|
|
17
17
|
middleware = defaultMiddleware,
|
|
18
18
|
disableBackgroundUI,
|
|
19
19
|
isOpen = true,
|
|
20
|
-
animationFrame
|
|
20
|
+
animationFrame,
|
|
21
|
+
popoverStrategy = "absolute"
|
|
21
22
|
}) => {
|
|
22
23
|
const elementDOM = useRef(null);
|
|
23
24
|
const {
|
|
@@ -46,7 +47,8 @@ const Popover = ({
|
|
|
46
47
|
floating: floatingReference,
|
|
47
48
|
placement,
|
|
48
49
|
middleware,
|
|
49
|
-
animationFrame
|
|
50
|
+
animationFrame,
|
|
51
|
+
strategy: popoverStrategy
|
|
50
52
|
});
|
|
51
53
|
useEffect(() => {
|
|
52
54
|
return () => {
|
|
@@ -22,13 +22,52 @@ import Logger from "../../__internal__/utils/logger";
|
|
|
22
22
|
let deprecateUncontrolledWarnTriggered = false;
|
|
23
23
|
export const ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["yyyy", "mm", "dd"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
|
|
24
24
|
const incorrectDateFormatMessage = "Forbidden prop dateFormat supplied to NumeralDate. " + "Only one of these date formats is allowed: " + "['dd', 'mm', 'yyyy'], " + "['mm', 'dd', 'yyyy'], " + "['yyyy', 'mm', 'dd'], " + "['dd', 'mm'], " + "['mm', 'dd'], " + "['mm', 'yyyy']";
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
25
|
+
const getMonthsForLocale = localeName => {
|
|
26
|
+
const year = new Date().getFullYear();
|
|
27
|
+
const {
|
|
28
|
+
format
|
|
29
|
+
} = new Intl.DateTimeFormat(localeName, {
|
|
30
|
+
month: "long"
|
|
31
|
+
});
|
|
32
|
+
return [...Array(12).keys()].map(m => format(new Date(Date.UTC(year, m))));
|
|
33
|
+
};
|
|
34
|
+
const validationMessages = (locale, month, daysInMonth) => ({
|
|
35
|
+
dd: locale.numeralDate.validation.day(month ? getMonthsForLocale(locale.locale())[+month - 1] : undefined, daysInMonth),
|
|
36
|
+
mm: locale.numeralDate.validation.month(),
|
|
37
|
+
yyyy: locale.numeralDate.validation.year()
|
|
38
|
+
});
|
|
39
|
+
const getDaysInMonth = (month, year) => {
|
|
40
|
+
if (month && (+month > 12 || +month < 1)) {
|
|
41
|
+
return 31;
|
|
42
|
+
}
|
|
43
|
+
const currentDate = new Date();
|
|
44
|
+
const computedYear = +(year || currentDate.getFullYear());
|
|
45
|
+
const computedMonth = +(month || currentDate.getMonth() + 1);
|
|
46
|
+
|
|
47
|
+
// passing 0 as the third argument ensures we handle for months being 0 indexed
|
|
48
|
+
return new Date(computedYear, computedMonth, 0).getDate();
|
|
49
|
+
};
|
|
50
|
+
const validate = (locale, {
|
|
51
|
+
dd,
|
|
52
|
+
mm,
|
|
53
|
+
yyyy
|
|
54
|
+
}) => {
|
|
55
|
+
const failed = {
|
|
56
|
+
dd: "",
|
|
57
|
+
mm: "",
|
|
58
|
+
yyyy: ""
|
|
59
|
+
};
|
|
60
|
+
const daysInMonth = getDaysInMonth(mm, yyyy);
|
|
61
|
+
if (dd && (+dd > daysInMonth || +dd < 1)) {
|
|
62
|
+
failed.dd = validationMessages(locale, mm, String(daysInMonth)).dd;
|
|
63
|
+
}
|
|
64
|
+
if (mm && (+mm > 12 || +mm < 1)) {
|
|
65
|
+
failed.mm = validationMessages(locale).mm;
|
|
66
|
+
}
|
|
67
|
+
if (yyyy && (+yyyy < 1800 || +yyyy > 2200)) {
|
|
68
|
+
failed.yyyy = validationMessages(locale).yyyy;
|
|
69
|
+
}
|
|
70
|
+
return failed;
|
|
32
71
|
};
|
|
33
72
|
const getDateLabel = (datePart, locale) => {
|
|
34
73
|
switch (datePart) {
|
|
@@ -99,11 +138,6 @@ export const NumeralDate = ({
|
|
|
99
138
|
const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
|
|
100
139
|
!(isControlled.current === (value !== undefined)) ? process.env.NODE_ENV !== "production" ? invariant(false, modeSwitchedMessage) : invariant(false) : void 0;
|
|
101
140
|
}, [value]);
|
|
102
|
-
const validationMessages = {
|
|
103
|
-
dd: locale.numeralDate.validation.day(),
|
|
104
|
-
mm: locale.numeralDate.validation.month(),
|
|
105
|
-
yyyy: locale.numeralDate.validation.year()
|
|
106
|
-
};
|
|
107
141
|
const [dateValue, setDateValue] = useState({
|
|
108
142
|
...(initialValue || Object.fromEntries(dateFormat.map(datePart => [datePart, ""])))
|
|
109
143
|
});
|
|
@@ -137,15 +171,13 @@ export const NumeralDate = ({
|
|
|
137
171
|
}
|
|
138
172
|
}
|
|
139
173
|
};
|
|
140
|
-
const handleBlur =
|
|
174
|
+
const handleBlur = () => {
|
|
141
175
|
const internalValidationEnabled = enableInternalError || enableInternalWarning;
|
|
142
176
|
/* istanbul ignore else */
|
|
143
177
|
if (internalValidationEnabled) {
|
|
144
|
-
const newDatePart = dateValue[datePart];
|
|
145
|
-
const errorMessage = validations[datePart](newDatePart) ? "" : validationMessages[datePart];
|
|
146
178
|
setInternalMessages(prev => ({
|
|
147
179
|
...prev,
|
|
148
|
-
|
|
180
|
+
...validate(locale, dateValue)
|
|
149
181
|
}));
|
|
150
182
|
}
|
|
151
183
|
setTimeout(() => {
|
|
@@ -239,6 +271,7 @@ export const NumeralDate = ({
|
|
|
239
271
|
readOnly: readOnly,
|
|
240
272
|
value: dateValue[datePart],
|
|
241
273
|
onChange: e => handleChange(e, datePart),
|
|
274
|
+
onBlur: handleBlur,
|
|
242
275
|
ref: element => {
|
|
243
276
|
refs.current[index] = element;
|
|
244
277
|
if (!inputRef) {
|
|
@@ -250,7 +283,6 @@ export const NumeralDate = ({
|
|
|
250
283
|
inputRef.current = element;
|
|
251
284
|
}
|
|
252
285
|
},
|
|
253
|
-
onBlur: () => handleBlur(datePart),
|
|
254
286
|
error: !!internalError,
|
|
255
287
|
warning: !!internalWarning,
|
|
256
288
|
info: !!info
|
|
@@ -55,6 +55,8 @@ export interface PopoverContainerProps extends PaddingProps {
|
|
|
55
55
|
closeButtonAriaLabel?: string;
|
|
56
56
|
/** Container aria label */
|
|
57
57
|
containerAriaLabel?: string;
|
|
58
|
+
/** Disables the animation for the component */
|
|
59
|
+
disableAnimation?: boolean;
|
|
58
60
|
}
|
|
59
|
-
export declare const PopoverContainer: ({ children, title, position, open, onOpen, onClose, renderOpenComponent, renderCloseComponent, shouldCoverButton, ariaDescribedBy, openButtonAriaLabel, closeButtonAriaLabel, containerAriaLabel, ...rest }: PopoverContainerProps) => React.JSX.Element;
|
|
61
|
+
export declare const PopoverContainer: ({ children, title, position, open, onOpen, onClose, renderOpenComponent, renderCloseComponent, shouldCoverButton, ariaDescribedBy, openButtonAriaLabel, closeButtonAriaLabel, containerAriaLabel, disableAnimation, ...rest }: PopoverContainerProps) => React.JSX.Element;
|
|
60
62
|
export default PopoverContainer;
|
|
@@ -3,6 +3,7 @@ import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
|
3
3
|
import PropTypes from "prop-types";
|
|
4
4
|
import { Transition } from "react-transition-group";
|
|
5
5
|
import { flip, offset } from "@floating-ui/dom";
|
|
6
|
+
import useMediaQuery from "../../hooks/useMediaQuery";
|
|
6
7
|
import { PopoverContainerWrapperStyle, PopoverContainerHeaderStyle, PopoverContainerContentStyle, PopoverContainerCloseIcon, PopoverContainerTitleStyle, PopoverContainerOpenIcon } from "./popover-container.style";
|
|
7
8
|
import Icon from "../icon";
|
|
8
9
|
import Popover from "../../__internal__/popover";
|
|
@@ -67,6 +68,7 @@ export const PopoverContainer = ({
|
|
|
67
68
|
openButtonAriaLabel,
|
|
68
69
|
closeButtonAriaLabel = "close",
|
|
69
70
|
containerAriaLabel,
|
|
71
|
+
disableAnimation = false,
|
|
70
72
|
...rest
|
|
71
73
|
}) => {
|
|
72
74
|
const isControlled = open !== undefined;
|
|
@@ -78,6 +80,7 @@ export const PopoverContainer = ({
|
|
|
78
80
|
const popoverContentNodeRef = useRef(null);
|
|
79
81
|
const popoverContainerId = title ? `PopoverContainer_${guid.current}` : undefined;
|
|
80
82
|
const isOpen = isControlled ? open : isOpenInternal;
|
|
83
|
+
const reduceMotion = !useMediaQuery("screen and (prefers-reduced-motion: no-preference)");
|
|
81
84
|
useEffect(() => {
|
|
82
85
|
if (isOpen && closeButtonRef.current) setTimeout(() => closeButtonRef.current?.focus(), 0);
|
|
83
86
|
}, [isOpen]);
|
|
@@ -147,6 +150,7 @@ export const PopoverContainer = ({
|
|
|
147
150
|
unmountOnExit: true,
|
|
148
151
|
nodeRef: popoverContentNodeRef
|
|
149
152
|
}, state => isOpen && /*#__PURE__*/React.createElement(Popover, _extends({
|
|
153
|
+
popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute",
|
|
150
154
|
reference: popoverReference,
|
|
151
155
|
placement: position === "right" ? "bottom-start" : "bottom-end"
|
|
152
156
|
}, shouldCoverButton && {
|
|
@@ -159,7 +163,8 @@ export const PopoverContainer = ({
|
|
|
159
163
|
"aria-label": containerAriaLabel,
|
|
160
164
|
"aria-describedby": ariaDescribedBy,
|
|
161
165
|
p: "16px 24px",
|
|
162
|
-
ref: popoverContentNodeRef
|
|
166
|
+
ref: popoverContentNodeRef,
|
|
167
|
+
disableAnimation: disableAnimation || reduceMotion
|
|
163
168
|
}, filterStyledSystemPaddingProps(rest)), /*#__PURE__*/React.createElement(PopoverContainerHeaderStyle, null, /*#__PURE__*/React.createElement(PopoverContainerTitleStyle, {
|
|
164
169
|
id: popoverContainerId,
|
|
165
170
|
"data-element": "popover-container-title"
|
|
@@ -4,6 +4,7 @@ declare const PopoverContainerWrapperStyle: import("styled-components").StyledCo
|
|
|
4
4
|
declare const PopoverContainerHeaderStyle: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
5
|
declare type PopoverContainerContentStyleProps = {
|
|
6
6
|
animationState?: TransitionStatus;
|
|
7
|
+
disableAnimation?: boolean;
|
|
7
8
|
};
|
|
8
9
|
declare const PopoverContainerContentStyle: import("styled-components").StyledComponent<"div", any, PopoverContainerContentStyleProps, never>;
|
|
9
10
|
declare type AdditionalIconButtonProps = {
|
|
@@ -3,6 +3,33 @@ import { padding } from "styled-system";
|
|
|
3
3
|
import { baseTheme } from "../../style/themes";
|
|
4
4
|
import IconButton from "../icon-button";
|
|
5
5
|
import StyledIcon from "../icon/icon.style";
|
|
6
|
+
function animationToRender({
|
|
7
|
+
animationState,
|
|
8
|
+
disableAnimation
|
|
9
|
+
}) {
|
|
10
|
+
if (disableAnimation) return "opacity: 1;";
|
|
11
|
+
switch (animationState) {
|
|
12
|
+
case "entering":
|
|
13
|
+
return `
|
|
14
|
+
opacity: 0;
|
|
15
|
+
transform: translateY(-8px);
|
|
16
|
+
`;
|
|
17
|
+
case "entered":
|
|
18
|
+
return `
|
|
19
|
+
opacity: 1;
|
|
20
|
+
transform: translateY(0);
|
|
21
|
+
transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
|
|
22
|
+
`;
|
|
23
|
+
case "exiting":
|
|
24
|
+
return `
|
|
25
|
+
opacity: 0;
|
|
26
|
+
transform: translateY(-8px);
|
|
27
|
+
transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
|
|
28
|
+
`;
|
|
29
|
+
default:
|
|
30
|
+
return "opacity: 0;";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
6
33
|
const PopoverContainerWrapperStyle = styled.div`
|
|
7
34
|
position: relative;
|
|
8
35
|
display: inline-block;
|
|
@@ -25,31 +52,7 @@ const PopoverContainerContentStyle = styled.div`
|
|
|
25
52
|
theme
|
|
26
53
|
}) => theme.zIndex.popover};
|
|
27
54
|
|
|
28
|
-
${
|
|
29
|
-
animationState
|
|
30
|
-
}) => {
|
|
31
|
-
switch (animationState) {
|
|
32
|
-
case "entering":
|
|
33
|
-
return `
|
|
34
|
-
opacity: 0;
|
|
35
|
-
transform: translateY(-8px);
|
|
36
|
-
`;
|
|
37
|
-
case "entered":
|
|
38
|
-
return `
|
|
39
|
-
opacity: 1;
|
|
40
|
-
transform: translateY(0);
|
|
41
|
-
transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
|
|
42
|
-
`;
|
|
43
|
-
case "exiting":
|
|
44
|
-
return `
|
|
45
|
-
opacity: 0;
|
|
46
|
-
transform: translateY(-8px);
|
|
47
|
-
transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
|
|
48
|
-
`;
|
|
49
|
-
default:
|
|
50
|
-
return "opacity: 0";
|
|
51
|
-
}
|
|
52
|
-
}}
|
|
55
|
+
${animationToRender}
|
|
53
56
|
`;
|
|
54
57
|
const PopoverContainerOpenIcon = styled(IconButton)`
|
|
55
58
|
${StyledIcon} {
|
|
@@ -126,7 +126,12 @@ const plPL = {
|
|
|
126
126
|
},
|
|
127
127
|
numeralDate: {
|
|
128
128
|
validation: {
|
|
129
|
-
day: () =>
|
|
129
|
+
day: (month, daysInMonth) => {
|
|
130
|
+
if (month && daysInMonth) {
|
|
131
|
+
return `Dzień W ${month} musi być liczbą zakresie 1-${daysInMonth}.`;
|
|
132
|
+
}
|
|
133
|
+
return "Dzień musi być liczbą w zakresie 1-31.";
|
|
134
|
+
},
|
|
130
135
|
month: () => "Miesiąć musi być liczbą w zakresie 1-12.",
|
|
131
136
|
year: () => "Rok musi być liczbą w zakresie 1800-2200."
|
|
132
137
|
},
|
package/esm/locales/en-gb.js
CHANGED
|
@@ -91,7 +91,12 @@ const enGB = {
|
|
|
91
91
|
},
|
|
92
92
|
numeralDate: {
|
|
93
93
|
validation: {
|
|
94
|
-
day: () =>
|
|
94
|
+
day: (month, daysInMonth) => {
|
|
95
|
+
if (month && daysInMonth) {
|
|
96
|
+
return `Day in ${month} should be a number within 1-${daysInMonth}.`;
|
|
97
|
+
}
|
|
98
|
+
return "Day should be a number within a 1-31 range.";
|
|
99
|
+
},
|
|
95
100
|
month: () => "Month should be a number within a 1-12 range.",
|
|
96
101
|
year: () => "Year should be a number within a 1800-2200 range."
|
|
97
102
|
},
|
package/esm/locales/locale.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface PopoverProps {
|
|
|
12
12
|
reference: CustomRefObject<HTMLElement>;
|
|
13
13
|
isOpen?: boolean;
|
|
14
14
|
animationFrame?: boolean;
|
|
15
|
+
popoverStrategy?: "absolute" | "fixed";
|
|
15
16
|
}
|
|
16
|
-
declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, }: PopoverProps) => React.JSX.Element;
|
|
17
|
+
declare const Popover: ({ children, placement, disablePortal, reference, middleware, disableBackgroundUI, isOpen, animationFrame, popoverStrategy, }: PopoverProps) => React.JSX.Element;
|
|
17
18
|
export default Popover;
|
|
@@ -26,7 +26,8 @@ const Popover = ({
|
|
|
26
26
|
middleware = defaultMiddleware,
|
|
27
27
|
disableBackgroundUI,
|
|
28
28
|
isOpen = true,
|
|
29
|
-
animationFrame
|
|
29
|
+
animationFrame,
|
|
30
|
+
popoverStrategy = "absolute"
|
|
30
31
|
}) => {
|
|
31
32
|
const elementDOM = (0, _react.useRef)(null);
|
|
32
33
|
const {
|
|
@@ -55,7 +56,8 @@ const Popover = ({
|
|
|
55
56
|
floating: floatingReference,
|
|
56
57
|
placement,
|
|
57
58
|
middleware,
|
|
58
|
-
animationFrame
|
|
59
|
+
animationFrame,
|
|
60
|
+
strategy: popoverStrategy
|
|
59
61
|
});
|
|
60
62
|
(0, _react.useEffect)(() => {
|
|
61
63
|
return () => {
|
|
@@ -31,13 +31,52 @@ function _extends() { _extends = Object.assign ? Object.assign.bind() : function
|
|
|
31
31
|
let deprecateUncontrolledWarnTriggered = false;
|
|
32
32
|
const ALLOWED_DATE_FORMATS = exports.ALLOWED_DATE_FORMATS = [["dd", "mm", "yyyy"], ["mm", "dd", "yyyy"], ["yyyy", "mm", "dd"], ["dd", "mm"], ["mm", "dd"], ["mm", "yyyy"]];
|
|
33
33
|
const incorrectDateFormatMessage = "Forbidden prop dateFormat supplied to NumeralDate. " + "Only one of these date formats is allowed: " + "['dd', 'mm', 'yyyy'], " + "['mm', 'dd', 'yyyy'], " + "['yyyy', 'mm', 'dd'], " + "['dd', 'mm'], " + "['mm', 'dd'], " + "['mm', 'yyyy']";
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const getMonthsForLocale = localeName => {
|
|
35
|
+
const year = new Date().getFullYear();
|
|
36
|
+
const {
|
|
37
|
+
format
|
|
38
|
+
} = new Intl.DateTimeFormat(localeName, {
|
|
39
|
+
month: "long"
|
|
40
|
+
});
|
|
41
|
+
return [...Array(12).keys()].map(m => format(new Date(Date.UTC(year, m))));
|
|
42
|
+
};
|
|
43
|
+
const validationMessages = (locale, month, daysInMonth) => ({
|
|
44
|
+
dd: locale.numeralDate.validation.day(month ? getMonthsForLocale(locale.locale())[+month - 1] : undefined, daysInMonth),
|
|
45
|
+
mm: locale.numeralDate.validation.month(),
|
|
46
|
+
yyyy: locale.numeralDate.validation.year()
|
|
47
|
+
});
|
|
48
|
+
const getDaysInMonth = (month, year) => {
|
|
49
|
+
if (month && (+month > 12 || +month < 1)) {
|
|
50
|
+
return 31;
|
|
51
|
+
}
|
|
52
|
+
const currentDate = new Date();
|
|
53
|
+
const computedYear = +(year || currentDate.getFullYear());
|
|
54
|
+
const computedMonth = +(month || currentDate.getMonth() + 1);
|
|
55
|
+
|
|
56
|
+
// passing 0 as the third argument ensures we handle for months being 0 indexed
|
|
57
|
+
return new Date(computedYear, computedMonth, 0).getDate();
|
|
58
|
+
};
|
|
59
|
+
const validate = (locale, {
|
|
60
|
+
dd,
|
|
61
|
+
mm,
|
|
62
|
+
yyyy
|
|
63
|
+
}) => {
|
|
64
|
+
const failed = {
|
|
65
|
+
dd: "",
|
|
66
|
+
mm: "",
|
|
67
|
+
yyyy: ""
|
|
68
|
+
};
|
|
69
|
+
const daysInMonth = getDaysInMonth(mm, yyyy);
|
|
70
|
+
if (dd && (+dd > daysInMonth || +dd < 1)) {
|
|
71
|
+
failed.dd = validationMessages(locale, mm, String(daysInMonth)).dd;
|
|
72
|
+
}
|
|
73
|
+
if (mm && (+mm > 12 || +mm < 1)) {
|
|
74
|
+
failed.mm = validationMessages(locale).mm;
|
|
75
|
+
}
|
|
76
|
+
if (yyyy && (+yyyy < 1800 || +yyyy > 2200)) {
|
|
77
|
+
failed.yyyy = validationMessages(locale).yyyy;
|
|
78
|
+
}
|
|
79
|
+
return failed;
|
|
41
80
|
};
|
|
42
81
|
const getDateLabel = (datePart, locale) => {
|
|
43
82
|
switch (datePart) {
|
|
@@ -108,11 +147,6 @@ const NumeralDate = ({
|
|
|
108
147
|
const modeSwitchedMessage = "Input elements should not switch from uncontrolled to controlled (or vice versa). " + "Decide between using a controlled or uncontrolled input element for the lifetime of the component";
|
|
109
148
|
!(isControlled.current === (value !== undefined)) ? process.env.NODE_ENV !== "production" ? (0, _invariant.default)(false, modeSwitchedMessage) : (0, _invariant.default)(false) : void 0;
|
|
110
149
|
}, [value]);
|
|
111
|
-
const validationMessages = {
|
|
112
|
-
dd: locale.numeralDate.validation.day(),
|
|
113
|
-
mm: locale.numeralDate.validation.month(),
|
|
114
|
-
yyyy: locale.numeralDate.validation.year()
|
|
115
|
-
};
|
|
116
150
|
const [dateValue, setDateValue] = (0, _react.useState)({
|
|
117
151
|
...(initialValue || Object.fromEntries(dateFormat.map(datePart => [datePart, ""])))
|
|
118
152
|
});
|
|
@@ -146,15 +180,13 @@ const NumeralDate = ({
|
|
|
146
180
|
}
|
|
147
181
|
}
|
|
148
182
|
};
|
|
149
|
-
const handleBlur =
|
|
183
|
+
const handleBlur = () => {
|
|
150
184
|
const internalValidationEnabled = enableInternalError || enableInternalWarning;
|
|
151
185
|
/* istanbul ignore else */
|
|
152
186
|
if (internalValidationEnabled) {
|
|
153
|
-
const newDatePart = dateValue[datePart];
|
|
154
|
-
const errorMessage = validations[datePart](newDatePart) ? "" : validationMessages[datePart];
|
|
155
187
|
setInternalMessages(prev => ({
|
|
156
188
|
...prev,
|
|
157
|
-
|
|
189
|
+
...validate(locale, dateValue)
|
|
158
190
|
}));
|
|
159
191
|
}
|
|
160
192
|
setTimeout(() => {
|
|
@@ -248,6 +280,7 @@ const NumeralDate = ({
|
|
|
248
280
|
readOnly: readOnly,
|
|
249
281
|
value: dateValue[datePart],
|
|
250
282
|
onChange: e => handleChange(e, datePart),
|
|
283
|
+
onBlur: handleBlur,
|
|
251
284
|
ref: element => {
|
|
252
285
|
refs.current[index] = element;
|
|
253
286
|
if (!inputRef) {
|
|
@@ -259,7 +292,6 @@ const NumeralDate = ({
|
|
|
259
292
|
inputRef.current = element;
|
|
260
293
|
}
|
|
261
294
|
},
|
|
262
|
-
onBlur: () => handleBlur(datePart),
|
|
263
295
|
error: !!internalError,
|
|
264
296
|
warning: !!internalWarning,
|
|
265
297
|
info: !!info
|
|
@@ -55,6 +55,8 @@ export interface PopoverContainerProps extends PaddingProps {
|
|
|
55
55
|
closeButtonAriaLabel?: string;
|
|
56
56
|
/** Container aria label */
|
|
57
57
|
containerAriaLabel?: string;
|
|
58
|
+
/** Disables the animation for the component */
|
|
59
|
+
disableAnimation?: boolean;
|
|
58
60
|
}
|
|
59
|
-
export declare const PopoverContainer: ({ children, title, position, open, onOpen, onClose, renderOpenComponent, renderCloseComponent, shouldCoverButton, ariaDescribedBy, openButtonAriaLabel, closeButtonAriaLabel, containerAriaLabel, ...rest }: PopoverContainerProps) => React.JSX.Element;
|
|
61
|
+
export declare const PopoverContainer: ({ children, title, position, open, onOpen, onClose, renderOpenComponent, renderCloseComponent, shouldCoverButton, ariaDescribedBy, openButtonAriaLabel, closeButtonAriaLabel, containerAriaLabel, disableAnimation, ...rest }: PopoverContainerProps) => React.JSX.Element;
|
|
60
62
|
export default PopoverContainer;
|
|
@@ -8,6 +8,7 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
8
8
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
9
9
|
var _reactTransitionGroup = require("react-transition-group");
|
|
10
10
|
var _dom = require("@floating-ui/dom");
|
|
11
|
+
var _useMediaQuery = _interopRequireDefault(require("../../hooks/useMediaQuery"));
|
|
11
12
|
var _popoverContainer = require("./popover-container.style");
|
|
12
13
|
var _icon = _interopRequireDefault(require("../icon"));
|
|
13
14
|
var _popover = _interopRequireDefault(require("../../__internal__/popover"));
|
|
@@ -78,6 +79,7 @@ const PopoverContainer = ({
|
|
|
78
79
|
openButtonAriaLabel,
|
|
79
80
|
closeButtonAriaLabel = "close",
|
|
80
81
|
containerAriaLabel,
|
|
82
|
+
disableAnimation = false,
|
|
81
83
|
...rest
|
|
82
84
|
}) => {
|
|
83
85
|
const isControlled = open !== undefined;
|
|
@@ -89,6 +91,7 @@ const PopoverContainer = ({
|
|
|
89
91
|
const popoverContentNodeRef = (0, _react.useRef)(null);
|
|
90
92
|
const popoverContainerId = title ? `PopoverContainer_${guid.current}` : undefined;
|
|
91
93
|
const isOpen = isControlled ? open : isOpenInternal;
|
|
94
|
+
const reduceMotion = !(0, _useMediaQuery.default)("screen and (prefers-reduced-motion: no-preference)");
|
|
92
95
|
(0, _react.useEffect)(() => {
|
|
93
96
|
if (isOpen && closeButtonRef.current) setTimeout(() => closeButtonRef.current?.focus(), 0);
|
|
94
97
|
}, [isOpen]);
|
|
@@ -158,6 +161,7 @@ const PopoverContainer = ({
|
|
|
158
161
|
unmountOnExit: true,
|
|
159
162
|
nodeRef: popoverContentNodeRef
|
|
160
163
|
}, state => isOpen && /*#__PURE__*/_react.default.createElement(_popover.default, _extends({
|
|
164
|
+
popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute",
|
|
161
165
|
reference: popoverReference,
|
|
162
166
|
placement: position === "right" ? "bottom-start" : "bottom-end"
|
|
163
167
|
}, shouldCoverButton && {
|
|
@@ -170,7 +174,8 @@ const PopoverContainer = ({
|
|
|
170
174
|
"aria-label": containerAriaLabel,
|
|
171
175
|
"aria-describedby": ariaDescribedBy,
|
|
172
176
|
p: "16px 24px",
|
|
173
|
-
ref: popoverContentNodeRef
|
|
177
|
+
ref: popoverContentNodeRef,
|
|
178
|
+
disableAnimation: disableAnimation || reduceMotion
|
|
174
179
|
}, (0, _utils.filterStyledSystemPaddingProps)(rest)), /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerHeaderStyle, null, /*#__PURE__*/_react.default.createElement(_popoverContainer.PopoverContainerTitleStyle, {
|
|
175
180
|
id: popoverContainerId,
|
|
176
181
|
"data-element": "popover-container-title"
|
|
@@ -4,6 +4,7 @@ declare const PopoverContainerWrapperStyle: import("styled-components").StyledCo
|
|
|
4
4
|
declare const PopoverContainerHeaderStyle: import("styled-components").StyledComponent<"div", any, {}, never>;
|
|
5
5
|
declare type PopoverContainerContentStyleProps = {
|
|
6
6
|
animationState?: TransitionStatus;
|
|
7
|
+
disableAnimation?: boolean;
|
|
7
8
|
};
|
|
8
9
|
declare const PopoverContainerContentStyle: import("styled-components").StyledComponent<"div", any, PopoverContainerContentStyleProps, never>;
|
|
9
10
|
declare type AdditionalIconButtonProps = {
|
|
@@ -10,6 +10,33 @@ var _themes = require("../../style/themes");
|
|
|
10
10
|
var _iconButton = _interopRequireDefault(require("../icon-button"));
|
|
11
11
|
var _icon = _interopRequireDefault(require("../icon/icon.style"));
|
|
12
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
function animationToRender({
|
|
14
|
+
animationState,
|
|
15
|
+
disableAnimation
|
|
16
|
+
}) {
|
|
17
|
+
if (disableAnimation) return "opacity: 1;";
|
|
18
|
+
switch (animationState) {
|
|
19
|
+
case "entering":
|
|
20
|
+
return `
|
|
21
|
+
opacity: 0;
|
|
22
|
+
transform: translateY(-8px);
|
|
23
|
+
`;
|
|
24
|
+
case "entered":
|
|
25
|
+
return `
|
|
26
|
+
opacity: 1;
|
|
27
|
+
transform: translateY(0);
|
|
28
|
+
transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
|
|
29
|
+
`;
|
|
30
|
+
case "exiting":
|
|
31
|
+
return `
|
|
32
|
+
opacity: 0;
|
|
33
|
+
transform: translateY(-8px);
|
|
34
|
+
transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
|
|
35
|
+
`;
|
|
36
|
+
default:
|
|
37
|
+
return "opacity: 0;";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
13
40
|
const PopoverContainerWrapperStyle = exports.PopoverContainerWrapperStyle = _styledComponents.default.div`
|
|
14
41
|
position: relative;
|
|
15
42
|
display: inline-block;
|
|
@@ -32,31 +59,7 @@ const PopoverContainerContentStyle = exports.PopoverContainerContentStyle = _sty
|
|
|
32
59
|
theme
|
|
33
60
|
}) => theme.zIndex.popover};
|
|
34
61
|
|
|
35
|
-
${
|
|
36
|
-
animationState
|
|
37
|
-
}) => {
|
|
38
|
-
switch (animationState) {
|
|
39
|
-
case "entering":
|
|
40
|
-
return `
|
|
41
|
-
opacity: 0;
|
|
42
|
-
transform: translateY(-8px);
|
|
43
|
-
`;
|
|
44
|
-
case "entered":
|
|
45
|
-
return `
|
|
46
|
-
opacity: 1;
|
|
47
|
-
transform: translateY(0);
|
|
48
|
-
transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
|
|
49
|
-
`;
|
|
50
|
-
case "exiting":
|
|
51
|
-
return `
|
|
52
|
-
opacity: 0;
|
|
53
|
-
transform: translateY(-8px);
|
|
54
|
-
transition: all 0.3s cubic-bezier(0.25, 0.25, 0, 1.5);
|
|
55
|
-
`;
|
|
56
|
-
default:
|
|
57
|
-
return "opacity: 0";
|
|
58
|
-
}
|
|
59
|
-
}}
|
|
62
|
+
${animationToRender}
|
|
60
63
|
`;
|
|
61
64
|
const PopoverContainerOpenIcon = exports.PopoverContainerOpenIcon = (0, _styledComponents.default)(_iconButton.default)`
|
|
62
65
|
${_icon.default} {
|
|
@@ -133,7 +133,12 @@ const plPL = {
|
|
|
133
133
|
},
|
|
134
134
|
numeralDate: {
|
|
135
135
|
validation: {
|
|
136
|
-
day: () =>
|
|
136
|
+
day: (month, daysInMonth) => {
|
|
137
|
+
if (month && daysInMonth) {
|
|
138
|
+
return `Dzień W ${month} musi być liczbą zakresie 1-${daysInMonth}.`;
|
|
139
|
+
}
|
|
140
|
+
return "Dzień musi być liczbą w zakresie 1-31.";
|
|
141
|
+
},
|
|
137
142
|
month: () => "Miesiąć musi być liczbą w zakresie 1-12.",
|
|
138
143
|
year: () => "Rok musi być liczbą w zakresie 1800-2200."
|
|
139
144
|
},
|
package/lib/locales/en-gb.js
CHANGED
|
@@ -97,7 +97,12 @@ const enGB = {
|
|
|
97
97
|
},
|
|
98
98
|
numeralDate: {
|
|
99
99
|
validation: {
|
|
100
|
-
day: () =>
|
|
100
|
+
day: (month, daysInMonth) => {
|
|
101
|
+
if (month && daysInMonth) {
|
|
102
|
+
return `Day in ${month} should be a number within 1-${daysInMonth}.`;
|
|
103
|
+
}
|
|
104
|
+
return "Day should be a number within a 1-31 range.";
|
|
105
|
+
},
|
|
101
106
|
month: () => "Month should be a number within a 1-12 range.",
|
|
102
107
|
year: () => "Year should be a number within a 1800-2200 range."
|
|
103
108
|
},
|
package/lib/locales/locale.d.ts
CHANGED