draft-components 0.61.0 → 0.61.1
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/components/date-preset-picker-popover/date-preset-picker-popover.js +2 -1
- package/components/date-range-picker/date-range-picker.js +2 -2
- package/components/datetime-input/date-components.js +7 -12
- package/components/datetime-input/datetime-input.js +1 -1
- package/components/dialog/dialog.js +2 -1
- package/components/inline-message/inline-message.js +2 -1
- package/components/number-input/number-input.js +2 -1
- package/components/table/table-sort-button.js +2 -1
- package/components/tabs/tabs-state.js +2 -1
- package/components/toaster/toaster.js +1 -1
- package/hooks/use-capture-focus.js +6 -4
- package/hooks/use-close-on-click-outside.js +3 -2
- package/hooks/use-close-on-esc-press.js +2 -1
- package/lib/plain-date-range.js +6 -8
- package/lib/plain-date.js +7 -8
- package/lib/stack.js +0 -1
- package/lib/util.js +1 -1
- package/package.json +1 -1
|
@@ -6,6 +6,7 @@ const react_1 = require("react");
|
|
|
6
6
|
const popover_1 = require("../popover");
|
|
7
7
|
const date_preset_picker_1 = require("./date-preset-picker");
|
|
8
8
|
exports.DatePresetPickerPopover = (0, react_1.forwardRef)(function DatePresetPickerPopover({ locale, timeZone, defaultIsOpen = false, hideSelectedRange = false, position = 'bottom', alignment = 'start', cancelButtonLabel, confirmButtonLabel, customDatePresetLabel, disableActionButtons, showLoadingIndicator, options, value, onChangeValue, children: render, }, ref) {
|
|
9
|
+
var _a;
|
|
9
10
|
const [isShown, setIsShown] = (0, react_1.useState)(defaultIsOpen);
|
|
10
11
|
const confirmButtonRef = (0, react_1.useRef)(null);
|
|
11
12
|
const [selectionState, setSelectionState] = (0, react_1.useState)(valueToSelectionState);
|
|
@@ -100,7 +101,7 @@ exports.DatePresetPickerPopover = (0, react_1.forwardRef)(function DatePresetPic
|
|
|
100
101
|
openPopover();
|
|
101
102
|
}
|
|
102
103
|
}
|
|
103
|
-
return ((0, jsx_runtime_1.jsx)(popover_1.Popover, Object.assign({ ref: ref, className: "dc-date-preset-picker-popover", isShown: isShown, position: position, alignment: alignment, content: (0, jsx_runtime_1.jsx)(date_preset_picker_1.DatePresetPicker, { confirmButtonRef: confirmButtonRef, locale: locale, formattedDateRange: hideSelectedRange ? null : formattedDateRange, formattedTimeZone: formattedTimeZone, cancelButtonLabel: cancelButtonLabel, confirmButtonLabel: confirmButtonLabel, customDatePresetLabel: customDatePresetLabel, disableActionButtons: disableActionButtons, showLoadingIndicator: showLoadingIndicator, options: options, datePreset: selectionState.option
|
|
104
|
+
return ((0, jsx_runtime_1.jsx)(popover_1.Popover, Object.assign({ ref: ref, className: "dc-date-preset-picker-popover", isShown: isShown, position: position, alignment: alignment, content: (0, jsx_runtime_1.jsx)(date_preset_picker_1.DatePresetPicker, { confirmButtonRef: confirmButtonRef, locale: locale, formattedDateRange: hideSelectedRange ? null : formattedDateRange, formattedTimeZone: formattedTimeZone, cancelButtonLabel: cancelButtonLabel, confirmButtonLabel: confirmButtonLabel, customDatePresetLabel: customDatePresetLabel, disableActionButtons: disableActionButtons, showLoadingIndicator: showLoadingIndicator, options: options, datePreset: ((_a = selectionState.option) === null || _a === void 0 ? void 0 : _a.datePreset) || '', dateRange: selectionState.dateRange, onChangeDatePreset: handleChangeDatePreset, onChangeDateRange: handleChangeDateRange, onCancel: closePopover, onConfirm: handleConfirm }, void 0), focusElementRefAfterOpen: confirmButtonRef, onClose: closePopover }, { children: render({
|
|
104
105
|
isShown,
|
|
105
106
|
openPopover,
|
|
106
107
|
closePopover,
|
|
@@ -87,12 +87,12 @@ function DateRangePicker({ locale, nextYearButtonLabel, nextMonthButtonLabel, pr
|
|
|
87
87
|
renderedWeeks.push((0, jsx_runtime_1.jsx)(calendar_row_1.CalendarRow, { children: renderedDays }, `week-${w}`));
|
|
88
88
|
}
|
|
89
89
|
(0, react_1.useEffect)(() => {
|
|
90
|
-
if (value
|
|
90
|
+
if (value === null || value === void 0 ? void 0 : value.start) {
|
|
91
91
|
setFocusDate((focusDate) => focusDate.toISOString() !== value.start
|
|
92
92
|
? plain_date_1.PlainDate.fromISODate(value.start)
|
|
93
93
|
: focusDate);
|
|
94
94
|
}
|
|
95
|
-
}, [value
|
|
95
|
+
}, [value === null || value === void 0 ? void 0 : value.start]);
|
|
96
96
|
return ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "dc-date-picker" }, { children: [(0, jsx_runtime_1.jsx)(calendar_1.Calendar, Object.assign({ locale: locale, nextYearButtonLabel: nextYearButtonLabel, nextMonthButtonLabel: nextMonthButtonLabel, prevYearButtonLabel: prevYearButtonLabel, prevMonthButtonLabel: prevMonthButtonLabel, focusDate: focusDate, onChangeFocusDate: (focusDate) => {
|
|
97
97
|
setFocusDate(focusDate);
|
|
98
98
|
if (start) {
|
|
@@ -2,11 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DateComponents = void 0;
|
|
4
4
|
class DateComponents {
|
|
5
|
-
year;
|
|
6
|
-
month;
|
|
7
|
-
day;
|
|
8
|
-
hour;
|
|
9
|
-
minute;
|
|
10
5
|
constructor(values) {
|
|
11
6
|
if (values) {
|
|
12
7
|
for (const [key, value] of Object.entries(values)) {
|
|
@@ -14,13 +9,6 @@ class DateComponents {
|
|
|
14
9
|
}
|
|
15
10
|
}
|
|
16
11
|
}
|
|
17
|
-
static options = {
|
|
18
|
-
year: { min: 1, max: 9999, digits: 4 },
|
|
19
|
-
month: { min: 1, max: 12, digits: 2 },
|
|
20
|
-
day: { min: 1, max: 31, digits: 2 },
|
|
21
|
-
hour: { min: 0, max: 23, digits: 2 },
|
|
22
|
-
minute: { min: 0, max: 59, digits: 2 },
|
|
23
|
-
};
|
|
24
12
|
static makeFormDatetimeISO(dateString) {
|
|
25
13
|
const dateTimeRegex = /^\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}$/;
|
|
26
14
|
const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
|
|
@@ -106,3 +94,10 @@ class DateComponents {
|
|
|
106
94
|
}
|
|
107
95
|
}
|
|
108
96
|
exports.DateComponents = DateComponents;
|
|
97
|
+
DateComponents.options = {
|
|
98
|
+
year: { min: 1, max: 9999, digits: 4 },
|
|
99
|
+
month: { min: 1, max: 12, digits: 2 },
|
|
100
|
+
day: { min: 1, max: 31, digits: 2 },
|
|
101
|
+
hour: { min: 0, max: 23, digits: 2 },
|
|
102
|
+
minute: { min: 0, max: 59, digits: 2 },
|
|
103
|
+
};
|
|
@@ -137,7 +137,7 @@ exports.DatetimeInput = (0, react_1.forwardRef)(function DatetimeInput({ size =
|
|
|
137
137
|
if (index) {
|
|
138
138
|
children.push((0, jsx_runtime_1.jsx)("span", Object.assign({ className: "dc-datetime-input__separator" }, { children: separator }), `separator-${index}`));
|
|
139
139
|
}
|
|
140
|
-
children.push((0, jsx_runtime_1.jsx)(date_component_input_1.DateComponentInput, { id: ids
|
|
140
|
+
children.push((0, jsx_runtime_1.jsx)(date_component_input_1.DateComponentInput, { id: ids === null || ids === void 0 ? void 0 : ids[dateComponent], label: (ariaLabels === null || ariaLabels === void 0 ? void 0 : ariaLabels[dateComponent]) || dateComponent, placeholder: placeholders === null || placeholders === void 0 ? void 0 : placeholders[dateComponent], disabled: disabled, readOnly: readOnly, name: dateComponent, value: dateComponents.getDisplayedValue(dateComponent), onChange: handleChange }, dateComponent));
|
|
141
141
|
});
|
|
142
142
|
return (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "dc-datetime-input__group" }, { children: children }), void 0);
|
|
143
143
|
}
|
|
@@ -36,7 +36,8 @@ function Dialog({ style, className, isOpen, onClose = util_1.noop, shouldShowClo
|
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
return ((0, jsx_runtime_1.jsx)(portal_1.Portal, { children: (0, jsx_runtime_1.jsxs)("div", Object.assign({ "data-testid": "dialog-container", className: "dc-dialog-container", onClick: (event) => {
|
|
39
|
-
|
|
39
|
+
var _a;
|
|
40
|
+
if (!((_a = dialogRef.current) === null || _a === void 0 ? void 0 : _a.contains(event.target))) {
|
|
40
41
|
onClose();
|
|
41
42
|
}
|
|
42
43
|
} }, { children: [(0, jsx_runtime_1.jsx)("div", { tabIndex: 0 }, void 0), (0, jsx_runtime_1.jsxs)(box_1.Box, Object.assign({}, props, { ref: dialogRef, style: { ...style, width: widthInPx }, className: (0, react_helpers_1.classNames)(className, 'dc-dialog'), borderRadius: "lg", padding: "none", elevation: "lg", role: "dialog", "aria-modal": true }, { children: [(0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "dc-dialog__header" }, { children: [(heading || description) && ((0, jsx_runtime_1.jsxs)("div", Object.assign({ className: "dc-dialog__header-content" }, { children: [heading && (0, jsx_runtime_1.jsx)(formatted_content_1.Headline, Object.assign({ as: "h2" }, { children: heading }), void 0), description && ((0, jsx_runtime_1.jsx)(formatted_content_1.Subheadline, Object.assign({ as: "div", className: "dc-dialog__description" }, { children: description }), void 0))] }), void 0)), shouldShowCloseButton && ((0, jsx_runtime_1.jsx)(button_1.Button, { "data-testid": "dialog-close-button", className: "dc-dialog__close-btn", appearance: "minimal", size: "sm", noPadding: true, leadingIcon: closeIcon, onClick: onClose }, void 0))] }), void 0), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "dc-dialog__content" }, { children: children }), void 0), actions && (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "dc-dialog__actions" }, { children: actions }), void 0)] }), void 0), (0, jsx_runtime_1.jsx)("div", { tabIndex: 0 }, void 0)] }), void 0) }, void 0));
|
|
@@ -17,6 +17,7 @@ const inlineMessageIcons = {
|
|
|
17
17
|
default: info_circle_fill_1.infoCircleFill,
|
|
18
18
|
};
|
|
19
19
|
function InlineMessage({ appearance = 'default', shouldShowIcon = false, className, children, ...props }) {
|
|
20
|
-
|
|
20
|
+
var _a;
|
|
21
|
+
return ((0, jsx_runtime_1.jsxs)(formatted_content_1.Footnote, Object.assign({}, props, { className: (0, react_helpers_1.classNames)(className, 'dc-inline-message', `dc-inline-message_${appearance}`) }, { children: [shouldShowIcon ? ((0, jsx_runtime_1.jsx)(svg_icon_1.SvgIcon, { className: "dc-inline-message__icon", "data-testid": "inline-message-icon", icon: (_a = inlineMessageIcons[appearance]) !== null && _a !== void 0 ? _a : inlineMessageIcons.default, width: 16, height: 16 }, void 0)) : null, children] }), void 0));
|
|
21
22
|
}
|
|
22
23
|
exports.InlineMessage = InlineMessage;
|
|
@@ -80,7 +80,8 @@ exports.NumberInput = (0, react_1.forwardRef)(function NumberInput({ style, clas
|
|
|
80
80
|
}) }, { children: [(0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ appearance: "secondary", size: size, noPadding: true, disabled: disabled, onClick: () => !readOnly && decrement(step) }, { children: decrementButtonLabel }), void 0), (0, jsx_runtime_1.jsx)(text_input_1.TextInput, Object.assign({}, props, { ref: ref, className: "dc-number-input__text-input", size: size, disabled: disabled, readOnly: readOnly, fullWidth: fullWidth, type: "text", value: value, onKeyDown: handleKeyDown, onChangeValue: handleChangeValue }), void 0), (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ appearance: "secondary", size: size, noPadding: true, disabled: disabled, onClick: () => !readOnly && increment(step) }, { children: incrementButtonLabel }), void 0)] }), void 0));
|
|
81
81
|
});
|
|
82
82
|
function getFractionDigits(n) {
|
|
83
|
-
|
|
83
|
+
var _a;
|
|
84
|
+
const fraction = (_a = String(n).split(/[.,]/)[1]) !== null && _a !== void 0 ? _a : '';
|
|
84
85
|
return fraction.length;
|
|
85
86
|
}
|
|
86
87
|
function formatFloat(n, fractionDigits) {
|
|
@@ -40,7 +40,8 @@ const displayedOrders = {
|
|
|
40
40
|
desc: 'descending',
|
|
41
41
|
};
|
|
42
42
|
function TableSortButton({ column, order, onSort, renderLabel = renderDefaultLabel, className, ...props }) {
|
|
43
|
-
|
|
43
|
+
var _a;
|
|
44
|
+
const nextOrder = (_a = orderSequence[order]) !== null && _a !== void 0 ? _a : 'asc';
|
|
44
45
|
return ((0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({}, props, { className: (0, react_helpers_1.classNames)(className, 'dc-table-sort-btn'), appearance: "minimal", noPadding: true, size: "xs", leadingIcon: (0, jsx_runtime_1.jsx)(svg_icon_1.SvgIcon, { icon: orderIcons[order], size: 14 }, void 0), onClick: () => {
|
|
45
46
|
(0, guards_1.isFunction)(onSort) && onSort(nextOrder);
|
|
46
47
|
} }, { children: renderLabel(column, nextOrder) }), void 0));
|
|
@@ -32,8 +32,9 @@ function TabsStateProvider({ children, selectedTabKey, onSelectTab, }) {
|
|
|
32
32
|
setFocusedTabKey(tabKey);
|
|
33
33
|
}
|
|
34
34
|
function focusTab(tabKey) {
|
|
35
|
+
var _a;
|
|
35
36
|
setFocusedTabKey(tabKey);
|
|
36
|
-
document.getElementById(getTabId(tabKey))
|
|
37
|
+
(_a = document.getElementById(getTabId(tabKey))) === null || _a === void 0 ? void 0 : _a.focus();
|
|
37
38
|
}
|
|
38
39
|
return {
|
|
39
40
|
tabsOrder,
|
|
@@ -15,7 +15,7 @@ function Toaster({ className, position = 'top-center', toastGap = 16, ...props }
|
|
|
15
15
|
if (!listElement) {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
|
-
const toastAppearsOnBottom = position
|
|
18
|
+
const toastAppearsOnBottom = position === null || position === void 0 ? void 0 : position.startsWith('bottom');
|
|
19
19
|
const items = listElement.children;
|
|
20
20
|
let offset = 0;
|
|
21
21
|
for (let i = 0; i < items.length; i += 1) {
|
|
@@ -10,8 +10,8 @@ function useCaptureFocus({ modalRef, isEnabled = true, shouldFocusFirstDescendan
|
|
|
10
10
|
const releaseFocus = captureFocus(modal, {
|
|
11
11
|
shouldFocusFirstDescendant,
|
|
12
12
|
shouldRestoreFocusAfterRelease,
|
|
13
|
-
focusElementAfterCapture: focusElementRefAfterCapture
|
|
14
|
-
focusElementAfterRelease: focusElementRefAfterRelease
|
|
13
|
+
focusElementAfterCapture: (focusElementRefAfterCapture === null || focusElementRefAfterCapture === void 0 ? void 0 : focusElementRefAfterCapture.current) || null,
|
|
14
|
+
focusElementAfterRelease: (focusElementRefAfterRelease === null || focusElementRefAfterRelease === void 0 ? void 0 : focusElementRefAfterRelease.current) || null,
|
|
15
15
|
});
|
|
16
16
|
return () => {
|
|
17
17
|
releaseFocus();
|
|
@@ -93,11 +93,13 @@ function getFocusElements(parent) {
|
|
|
93
93
|
return Array.from(parent.querySelectorAll(FOCUS_ELEMENTS_SELECTOR));
|
|
94
94
|
}
|
|
95
95
|
function getFirstFocusableElement(parent) {
|
|
96
|
-
|
|
96
|
+
var _a;
|
|
97
|
+
return (_a = getFocusElements(parent)[0]) !== null && _a !== void 0 ? _a : parent;
|
|
97
98
|
}
|
|
98
99
|
function getLastFocusableElement(parent) {
|
|
100
|
+
var _a;
|
|
99
101
|
const focusableElements = getFocusElements(parent);
|
|
100
|
-
return focusableElements[focusableElements.length - 1]
|
|
102
|
+
return (_a = focusableElements[focusableElements.length - 1]) !== null && _a !== void 0 ? _a : parent;
|
|
101
103
|
}
|
|
102
104
|
function attemptFocus(element) {
|
|
103
105
|
if (element instanceof HTMLElement) {
|
|
@@ -5,8 +5,9 @@ const react_1 = require("react");
|
|
|
5
5
|
const guards_1 = require("../lib/guards");
|
|
6
6
|
function useCloseOnClickOutside(onClose, ref, params) {
|
|
7
7
|
(0, react_1.useEffect)(() => {
|
|
8
|
-
|
|
9
|
-
const
|
|
8
|
+
var _a, _b;
|
|
9
|
+
const isEnabled = (_a = params === null || params === void 0 ? void 0 : params.isEnabled) !== null && _a !== void 0 ? _a : true;
|
|
10
|
+
const ignoreElements = ((_b = params === null || params === void 0 ? void 0 : params.ignoreElements) !== null && _b !== void 0 ? _b : []).filter(guards_1.isHTMLElement);
|
|
10
11
|
const container = ref.current;
|
|
11
12
|
if (!isEnabled || !(0, guards_1.isFunction)(onClose) || !(0, guards_1.isHTMLElement)(container)) {
|
|
12
13
|
return;
|
|
@@ -21,7 +21,8 @@ function useCloseOnEscPress(onClose, isEnabled = true) {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
function onEscPress(event) {
|
|
24
|
-
|
|
24
|
+
var _a;
|
|
25
|
+
const close = (_a = callbackStack.last) === null || _a === void 0 ? void 0 : _a.current;
|
|
25
26
|
if (event.code === keyboard_helpers_1.KeyCode.escape && close) {
|
|
26
27
|
close();
|
|
27
28
|
}
|
package/lib/plain-date-range.js
CHANGED
|
@@ -3,14 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.PlainDateRange = void 0;
|
|
4
4
|
const plain_date_1 = require("./plain-date");
|
|
5
5
|
class PlainDateRange {
|
|
6
|
-
start;
|
|
7
|
-
end;
|
|
8
|
-
static create() {
|
|
9
|
-
return new PlainDateRange(plain_date_1.PlainDate.now(), plain_date_1.PlainDate.now());
|
|
10
|
-
}
|
|
11
|
-
static fromISODateRange(isoDateRange) {
|
|
12
|
-
return new PlainDateRange(plain_date_1.PlainDate.fromISODate(isoDateRange.start), plain_date_1.PlainDate.fromISODate(isoDateRange.end));
|
|
13
|
-
}
|
|
14
6
|
constructor(start, end) {
|
|
15
7
|
if (start.isAfter(end)) {
|
|
16
8
|
this.start = end;
|
|
@@ -21,6 +13,12 @@ class PlainDateRange {
|
|
|
21
13
|
this.end = end;
|
|
22
14
|
}
|
|
23
15
|
}
|
|
16
|
+
static create() {
|
|
17
|
+
return new PlainDateRange(plain_date_1.PlainDate.now(), plain_date_1.PlainDate.now());
|
|
18
|
+
}
|
|
19
|
+
static fromISODateRange(isoDateRange) {
|
|
20
|
+
return new PlainDateRange(plain_date_1.PlainDate.fromISODate(isoDateRange.start), plain_date_1.PlainDate.fromISODate(isoDateRange.end));
|
|
21
|
+
}
|
|
24
22
|
contains(date) {
|
|
25
23
|
return this.start.isBeforeOrEqual(date) && this.end.isAfterOrEqual(date);
|
|
26
24
|
}
|
package/lib/plain-date.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PlainDate = void 0;
|
|
4
4
|
class PlainDate {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
static DAYS_IN_WEEK = 7;
|
|
9
|
-
static MONTHS_IN_YEAR = 12;
|
|
5
|
+
constructor(year, monthIndex, day) {
|
|
6
|
+
this._date = new Date(year, monthIndex, day);
|
|
7
|
+
}
|
|
10
8
|
static now() {
|
|
11
9
|
const date = new Date();
|
|
12
10
|
return new PlainDate(date.getFullYear(), date.getMonth(), date.getDate());
|
|
@@ -15,9 +13,6 @@ class PlainDate {
|
|
|
15
13
|
const date = new Date(isoDate);
|
|
16
14
|
return new PlainDate(date.getFullYear(), date.getMonth(), date.getDate());
|
|
17
15
|
}
|
|
18
|
-
constructor(year, monthIndex, day) {
|
|
19
|
-
this._date = new Date(year, monthIndex, day);
|
|
20
|
-
}
|
|
21
16
|
get year() {
|
|
22
17
|
return this._date.getFullYear();
|
|
23
18
|
}
|
|
@@ -102,3 +97,7 @@ class PlainDate {
|
|
|
102
97
|
}
|
|
103
98
|
}
|
|
104
99
|
exports.PlainDate = PlainDate;
|
|
100
|
+
PlainDate.FIRST_WEEKDAY = 0;
|
|
101
|
+
PlainDate.LAST_WEEKDAY = 6;
|
|
102
|
+
PlainDate.DAYS_IN_WEEK = 7;
|
|
103
|
+
PlainDate.MONTHS_IN_YEAR = 12;
|
package/lib/stack.js
CHANGED
package/lib/util.js
CHANGED
|
@@ -35,6 +35,6 @@ function randomString(size) {
|
|
|
35
35
|
}
|
|
36
36
|
exports.randomString = randomString;
|
|
37
37
|
function uniqueId(prefix) {
|
|
38
|
-
return (prefix
|
|
38
|
+
return (prefix !== null && prefix !== void 0 ? prefix : '') + randomString(5);
|
|
39
39
|
}
|
|
40
40
|
exports.uniqueId = uniqueId;
|