carbon-react 144.12.1 → 144.14.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/components/date/__internal__/date-fns-fp/index.d.ts +2 -0
- package/esm/components/date/__internal__/date-fns-fp/index.js +2 -0
- package/esm/components/date/__internal__/date-picker/date-picker.component.d.ts +5 -11
- package/esm/components/date/__internal__/date-picker/date-picker.component.js +82 -78
- package/esm/components/date/__internal__/date-picker/day-picker.style.js +306 -166
- package/esm/components/date/__internal__/navbar/navbar.component.d.ts +2 -1
- package/esm/components/date/__internal__/navbar/navbar.component.js +4 -2
- package/esm/components/date/__internal__/navbar/navbar.style.js +1 -1
- package/esm/components/date/__internal__/utils.d.ts +3 -2
- package/esm/components/date/__internal__/utils.js +10 -1
- package/esm/components/date/__internal__/weekday/weekday.style.d.ts +1 -1
- package/esm/components/date/__internal__/weekday/weekday.style.js +3 -2
- package/esm/components/date/date.component.js +11 -214
- package/esm/components/step-sequence/index.d.ts +4 -0
- package/esm/components/step-sequence/index.js +2 -0
- package/esm/components/step-sequence/step-sequence-item/index.d.ts +2 -0
- package/esm/components/step-sequence/step-sequence-item/index.js +1 -0
- package/esm/components/step-sequence/step-sequence-item/step-sequence-item.component.d.ts +19 -0
- package/esm/components/step-sequence/step-sequence-item/step-sequence-item.component.js +43 -0
- package/esm/components/step-sequence/step-sequence-item/step-sequence-item.style.d.ts +6 -0
- package/esm/components/step-sequence/step-sequence-item/step-sequence-item.style.js +96 -0
- package/esm/components/step-sequence/step-sequence.component.d.ts +13 -0
- package/esm/components/step-sequence/step-sequence.component.js +23 -0
- package/esm/components/step-sequence/step-sequence.style.d.ts +4 -0
- package/esm/components/step-sequence/step-sequence.style.js +21 -0
- package/lib/components/date/__internal__/date-fns-fp/index.d.ts +2 -0
- package/lib/components/date/__internal__/date-fns-fp/index.js +14 -0
- package/lib/components/date/__internal__/date-picker/date-picker.component.d.ts +5 -11
- package/lib/components/date/__internal__/date-picker/date-picker.component.js +82 -77
- package/lib/components/date/__internal__/date-picker/day-picker.style.js +306 -166
- package/lib/components/date/__internal__/navbar/navbar.component.d.ts +2 -1
- package/lib/components/date/__internal__/navbar/navbar.component.js +4 -2
- package/lib/components/date/__internal__/navbar/navbar.style.js +1 -1
- package/lib/components/date/__internal__/utils.d.ts +3 -2
- package/lib/components/date/__internal__/utils.js +10 -0
- package/lib/components/date/__internal__/weekday/weekday.style.d.ts +1 -1
- package/lib/components/date/__internal__/weekday/weekday.style.js +3 -2
- package/lib/components/date/date.component.js +10 -213
- package/lib/components/step-sequence/index.d.ts +4 -0
- package/lib/components/step-sequence/index.js +20 -0
- package/lib/components/step-sequence/package.json +6 -0
- package/lib/components/step-sequence/step-sequence-item/index.d.ts +2 -0
- package/lib/components/step-sequence/step-sequence-item/index.js +13 -0
- package/lib/components/step-sequence/step-sequence-item/package.json +6 -0
- package/lib/components/step-sequence/step-sequence-item/step-sequence-item.component.d.ts +19 -0
- package/lib/components/step-sequence/step-sequence-item/step-sequence-item.component.js +53 -0
- package/lib/components/step-sequence/step-sequence-item/step-sequence-item.style.d.ts +6 -0
- package/lib/components/step-sequence/step-sequence-item/step-sequence-item.style.js +105 -0
- package/lib/components/step-sequence/step-sequence.component.d.ts +13 -0
- package/lib/components/step-sequence/step-sequence.component.js +31 -0
- package/lib/components/step-sequence/step-sequence.style.d.ts +4 -0
- package/lib/components/step-sequence/step-sequence.style.js +29 -0
- package/package.json +2 -2
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { default as format } from "date-fns/fp/format";
|
|
2
2
|
export { default as formatISO } from "date-fns/fp/formatISO";
|
|
3
3
|
export { default as isMatch } from "date-fns/fp/isMatch";
|
|
4
|
+
export { default as isValid } from "date-fns/fp/isValid";
|
|
4
5
|
export { default as parse } from "date-fns/fp/parse";
|
|
6
|
+
export { default as parseWithOptions } from "date-fns/fp/parseWithOptions";
|
|
5
7
|
export { default as parseISO } from "date-fns/fp/parseISO";
|
|
@@ -3,5 +3,7 @@
|
|
|
3
3
|
export { default as format } from "date-fns/fp/format";
|
|
4
4
|
export { default as formatISO } from "date-fns/fp/formatISO";
|
|
5
5
|
export { default as isMatch } from "date-fns/fp/isMatch";
|
|
6
|
+
export { default as isValid } from "date-fns/fp/isValid";
|
|
6
7
|
export { default as parse } from "date-fns/fp/parse";
|
|
8
|
+
export { default as parseWithOptions } from "date-fns/fp/parseWithOptions";
|
|
7
9
|
export { default as parseISO } from "date-fns/fp/parseISO";
|
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { DayPickerProps,
|
|
2
|
+
import { DayPickerProps, Modifiers } from "react-day-picker";
|
|
3
3
|
declare type CustomRefObject<T> = {
|
|
4
4
|
current?: T | null;
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
today: NonNullable<Modifier> | NonNullable<Modifier>[];
|
|
9
|
-
outside: NonNullable<Modifier> | NonNullable<Modifier>[];
|
|
10
|
-
[other: string]: NonNullable<Modifier> | NonNullable<Modifier>[];
|
|
11
|
-
}
|
|
12
|
-
export interface PickerProps extends Omit<DayPickerProps, "disabledDays" | "modifiers" | "selectedDays"> {
|
|
13
|
-
disabledDays?: NonNullable<Modifier> | NonNullable<Modifier>[] | undefined[];
|
|
6
|
+
export interface PickerProps extends Omit<DayPickerProps, "mode" | "disabledDays" | "modifiers" | "selectedDays"> {
|
|
7
|
+
disabledDays?: NonNullable<Date> | NonNullable<Date>[] | undefined[];
|
|
14
8
|
modifiers?: Partial<Modifiers>;
|
|
15
|
-
selectedDays?: NonNullable<
|
|
9
|
+
selectedDays?: NonNullable<Date> | NonNullable<Date>[] | undefined[];
|
|
16
10
|
}
|
|
17
11
|
export interface DatePickerProps {
|
|
18
12
|
/** Boolean to toggle where DatePicker is rendered in relation to the Date Input */
|
|
@@ -26,7 +20,7 @@ export interface DatePickerProps {
|
|
|
26
20
|
/** Element that the DatePicker will be displayed under */
|
|
27
21
|
inputElement: CustomRefObject<HTMLElement>;
|
|
28
22
|
/** Currently selected date */
|
|
29
|
-
selectedDays?: Date;
|
|
23
|
+
selectedDays?: Date | undefined;
|
|
30
24
|
/** Callback to handle mousedown event on picker container */
|
|
31
25
|
pickerMouseDown?: () => void;
|
|
32
26
|
/** Sets whether the picker should be displayed */
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
2
|
-
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
|
-
import PropTypes from "prop-types";
|
|
4
|
-
import DayPicker from "react-day-picker";
|
|
5
2
|
import { flip, offset } from "@floating-ui/dom";
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
3
|
+
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import PropTypes from "prop-types";
|
|
5
|
+
import { DayPicker, defaultLocale } from "react-day-picker";
|
|
8
6
|
import useLocale from "../../../../hooks/__internal__/useLocale";
|
|
7
|
+
import Popover from "../../../../__internal__/popover";
|
|
9
8
|
import Navbar from "../navbar";
|
|
10
9
|
import Weekday from "../weekday";
|
|
11
|
-
import
|
|
12
|
-
import Events from "../../../../__internal__/utils/helpers/events";
|
|
10
|
+
import { getDisabledDays } from "../utils";
|
|
13
11
|
import { defaultFocusableSelectors } from "../../../../__internal__/focus-trap/focus-trap-utils";
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
import Events from "../../../../__internal__/utils/helpers/events";
|
|
13
|
+
import StyledDayPicker from "./day-picker.style";
|
|
17
14
|
const popoverMiddleware = [offset(3), flip({
|
|
18
15
|
fallbackStrategy: "initialPlacement"
|
|
19
16
|
})];
|
|
@@ -31,6 +28,7 @@ export const DatePicker = ({
|
|
|
31
28
|
pickerTabGuardId,
|
|
32
29
|
onPickerClose
|
|
33
30
|
}) => {
|
|
31
|
+
const [focusedMonth, setFocusedMonth] = useState(selectedDays || new Date());
|
|
34
32
|
const locale = useLocale();
|
|
35
33
|
const {
|
|
36
34
|
localize,
|
|
@@ -45,11 +43,6 @@ export const DatePicker = ({
|
|
|
45
43
|
const month = localize?.month(i);
|
|
46
44
|
return month[0].toUpperCase() + month.slice(1);
|
|
47
45
|
}), [localize]);
|
|
48
|
-
const monthsShort = useMemo(() => Array.from({
|
|
49
|
-
length: 12
|
|
50
|
-
}).map((_, i) => localize?.month(i, {
|
|
51
|
-
width: "abbreviated"
|
|
52
|
-
}).substring(0, 3)), [localize]);
|
|
53
46
|
const weekdaysLong = useMemo(() => Array.from({
|
|
54
47
|
length: 7
|
|
55
48
|
}).map((_, i) => localize?.day(i)), [localize]);
|
|
@@ -64,54 +57,24 @@ export const DatePicker = ({
|
|
|
64
57
|
}).substring(0, isGivenLocale("de") ? 2 : 3));
|
|
65
58
|
}, [locale, localize]);
|
|
66
59
|
const ref = useRef(null);
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
/* istanbul ignore else */
|
|
72
|
-
if (captionElement) {
|
|
73
|
-
captionElement.removeAttribute("role");
|
|
74
|
-
captionElement.removeAttribute("aria-live");
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// focus the selected or today's date first
|
|
78
|
-
const selectedDay = ref.current?.querySelector(".DayPicker-Day--selected") || ref.current?.querySelector(".DayPicker-Day--today");
|
|
79
|
-
const firstDay = ref.current?.querySelector(".DayPicker-Day[tabindex='0']");
|
|
80
|
-
|
|
81
|
-
/* istanbul ignore else */
|
|
82
|
-
if (selectedDay && firstDay !== selectedDay) {
|
|
83
|
-
selectedDay?.setAttribute("tabindex", "0");
|
|
84
|
-
firstDay?.setAttribute("tabindex", "-1");
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}, [open]);
|
|
88
|
-
const handleDayClick = (date, modifiers, ev) => {
|
|
89
|
-
if (!modifiers.disabled) {
|
|
90
|
-
const {
|
|
91
|
-
id,
|
|
92
|
-
name
|
|
93
|
-
} = inputElement?.current?.firstChild;
|
|
94
|
-
ev.target = {
|
|
95
|
-
...ev.target,
|
|
96
|
-
id,
|
|
97
|
-
name
|
|
98
|
-
};
|
|
99
|
-
onDayClick?.(date, ev);
|
|
100
|
-
onPickerClose?.();
|
|
101
|
-
}
|
|
60
|
+
const handleDayClick = (date, e) => {
|
|
61
|
+
/* istanbul ignore else */
|
|
62
|
+
if (date) onDayClick?.(date, e);
|
|
63
|
+
onPickerClose?.();
|
|
102
64
|
};
|
|
103
65
|
const handleKeyUp = useCallback(ev => {
|
|
104
66
|
/* istanbul ignore else */
|
|
105
67
|
if (open && Events.isEscKey(ev)) {
|
|
68
|
+
setFocusedMonth(selectedDays);
|
|
106
69
|
inputElement.current?.querySelector("input")?.focus();
|
|
107
70
|
setOpen(false);
|
|
108
71
|
onPickerClose?.();
|
|
109
72
|
ev.stopPropagation();
|
|
110
73
|
}
|
|
111
|
-
}, [inputElement, onPickerClose, open, setOpen]);
|
|
74
|
+
}, [inputElement, onPickerClose, open, selectedDays, setOpen]);
|
|
112
75
|
const handleOnKeyDown = ev => {
|
|
113
76
|
/* istanbul ignore else */
|
|
114
|
-
if (ref.current?.querySelector(".
|
|
77
|
+
if (ref.current?.querySelector(".rdp-nav button") === document.activeElement && Events.isTabKey(ev) && Events.isShiftKey(ev)) {
|
|
115
78
|
ev.preventDefault();
|
|
116
79
|
setOpen(false);
|
|
117
80
|
onPickerClose?.();
|
|
@@ -137,22 +100,31 @@ export const DatePicker = ({
|
|
|
137
100
|
}
|
|
138
101
|
}
|
|
139
102
|
};
|
|
140
|
-
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
if (selectedDays) {
|
|
105
|
+
setFocusedMonth(selectedDays);
|
|
106
|
+
}
|
|
107
|
+
}, [selectedDays]);
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (!open && selectedDays) {
|
|
110
|
+
const fMonth = focusedMonth?.getMonth();
|
|
111
|
+
const sMonth = selectedDays?.getMonth();
|
|
112
|
+
if (fMonth !== sMonth) setFocusedMonth(selectedDays);
|
|
113
|
+
}
|
|
114
|
+
}, [focusedMonth, open, selectedDays]);
|
|
141
115
|
if (!open) {
|
|
142
116
|
return null;
|
|
143
117
|
}
|
|
144
|
-
const localeUtils = {
|
|
145
|
-
formatDay
|
|
146
|
-
};
|
|
147
118
|
const handleTabGuardFocus = () => {
|
|
148
119
|
ref.current?.querySelector("button")?.focus();
|
|
149
120
|
};
|
|
150
|
-
return /*#__PURE__*/React.createElement(Popover, {
|
|
121
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Popover, {
|
|
151
122
|
placement: "bottom-start",
|
|
152
123
|
reference: inputElement,
|
|
153
124
|
middleware: popoverMiddleware,
|
|
154
125
|
disablePortal: disablePortal
|
|
155
126
|
}, /*#__PURE__*/React.createElement(StyledDayPicker, {
|
|
127
|
+
id: "styled-day-picker",
|
|
156
128
|
ref: ref,
|
|
157
129
|
onMouseDown: pickerMouseDown,
|
|
158
130
|
onKeyUp: handleKeyUp,
|
|
@@ -164,29 +136,61 @@ export const DatePicker = ({
|
|
|
164
136
|
tabIndex: 0,
|
|
165
137
|
onFocus: handleTabGuardFocus
|
|
166
138
|
}), /*#__PURE__*/React.createElement(DayPicker, _extends({
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
}
|
|
139
|
+
formatters: {
|
|
140
|
+
formatCaption: month => `${localize?.month(month.getMonth())} ${month.getFullYear()}`
|
|
141
|
+
},
|
|
142
|
+
required: false,
|
|
143
|
+
weekStartsOn: weekStartsOn,
|
|
144
|
+
onMonthChange: setFocusedMonth,
|
|
145
|
+
disabled: getDisabledDays(minDate, maxDate),
|
|
146
|
+
locale: {
|
|
147
|
+
localize: {
|
|
148
|
+
...defaultLocale.localize,
|
|
149
|
+
months: monthsLong,
|
|
150
|
+
weekdaysLong,
|
|
151
|
+
weekdaysShort
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
selected: focusedMonth,
|
|
155
|
+
month: focusedMonth || /* istanbul ignore next */new Date(),
|
|
156
|
+
onDayClick: (d, _, e) => {
|
|
157
|
+
const date = d;
|
|
158
|
+
handleDayClick(date, e);
|
|
159
|
+
},
|
|
160
|
+
components: {
|
|
161
|
+
Nav: props => {
|
|
162
|
+
return /*#__PURE__*/React.createElement(Navbar, props);
|
|
163
|
+
},
|
|
164
|
+
Weekday: props => {
|
|
165
|
+
const fixedDays = {
|
|
166
|
+
Sunday: 0,
|
|
167
|
+
Monday: 1,
|
|
168
|
+
Tuesday: 2,
|
|
169
|
+
Wednesday: 3,
|
|
170
|
+
Thursday: 4,
|
|
171
|
+
Friday: 5,
|
|
172
|
+
Saturday: 6
|
|
173
|
+
};
|
|
174
|
+
const {
|
|
175
|
+
className,
|
|
176
|
+
"aria-label": ariaLabel
|
|
177
|
+
} = props;
|
|
178
|
+
const dayIndex = fixedDays[ariaLabel];
|
|
179
|
+
return /*#__PURE__*/React.createElement(Weekday, {
|
|
180
|
+
className: className,
|
|
181
|
+
title: weekdaysLong[dayIndex]
|
|
182
|
+
}, weekdaysShort[dayIndex]);
|
|
183
|
+
}
|
|
181
184
|
},
|
|
182
|
-
navbarElement: /*#__PURE__*/React.createElement(Navbar, null),
|
|
183
185
|
fixedWeeks: true,
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
186
|
+
defaultMonth: selectedDays || undefined,
|
|
187
|
+
onDayKeyDown: (date, modifiers, e) => {
|
|
188
|
+
handleOnDayKeyDown(date, modifiers, e);
|
|
189
|
+
}
|
|
190
|
+
}, pickerProps, {
|
|
191
|
+
showOutsideDays: true,
|
|
192
|
+
mode: "single"
|
|
193
|
+
})))));
|
|
190
194
|
};
|
|
191
195
|
DatePicker.displayName = "DatePicker";
|
|
192
196
|
export default DatePicker;
|