@carbon/react 1.97.0-rc.0 → 1.98.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/.playwright/INTERNAL_AVT_REPORT_DO_NOT_USE.json +1010 -975
- package/es/components/ButtonSet/ButtonSet.d.ts +5 -0
- package/es/components/ButtonSet/ButtonSet.js +68 -4
- package/es/components/CodeSnippet/CodeSnippet.d.ts +1 -1
- package/es/components/ComposedModal/ComposedModal.js +3 -2
- package/es/components/Copy/Copy.d.ts +1 -1
- package/es/components/CopyButton/CopyButton.d.ts +1 -1
- package/es/components/DataTable/DataTable.d.ts +2 -1
- package/es/components/DataTable/TableContainer.d.ts +10 -2
- package/es/components/DataTable/TableContainer.js +15 -3
- package/es/components/DataTable/state/sorting.d.ts +2 -4
- package/es/components/DataTableSkeleton/DataTableSkeleton.d.ts +1 -1
- package/es/components/DataTableSkeleton/DataTableSkeleton.js +1 -1
- package/es/components/DatePicker/DatePicker.d.ts +3 -2
- package/es/components/DatePicker/DatePicker.js +18 -135
- package/es/components/DatePicker/DatePickerLocales.d.ts +12 -0
- package/es/components/DatePicker/DatePickerLocales.js +135 -0
- package/es/components/DatePickerInput/DatePickerInput.js +50 -28
- package/es/components/Dropdown/Dropdown.js +9 -1
- package/es/components/FileUploader/FileUploader.d.ts +23 -8
- package/es/components/FileUploader/FileUploader.js +53 -33
- package/es/components/FileUploader/FileUploaderButton.js +2 -2
- package/es/components/FileUploader/FileUploaderDropContainer.d.ts +13 -2
- package/es/components/FileUploader/FileUploaderDropContainer.js +15 -6
- package/es/components/FileUploader/FileUploaderItem.js +9 -6
- package/es/components/Menu/index.d.ts +4 -3
- package/es/components/Modal/Modal.js +3 -2
- package/es/components/Notification/Notification.js +3 -2
- package/es/components/Pagination/Pagination.js +5 -5
- package/es/components/Popover/index.js +2 -2
- package/es/components/Select/Select.js +27 -33
- package/es/components/Toggletip/index.d.ts +1 -0
- package/es/components/Toggletip/index.js +1 -1
- package/es/components/Tooltip/index.d.ts +3 -2
- package/es/internal/FloatingMenu.js +8 -6
- package/es/internal/OptimizedResize.js +4 -5
- package/es/internal/wrapFocus.d.ts +4 -2
- package/es/internal/wrapFocus.js +5 -4
- package/es/tools/events.d.ts +1 -1
- package/lib/components/ButtonSet/ButtonSet.d.ts +5 -0
- package/lib/components/ButtonSet/ButtonSet.js +67 -3
- package/lib/components/CodeSnippet/CodeSnippet.d.ts +1 -1
- package/lib/components/ComposedModal/ComposedModal.js +3 -2
- package/lib/components/Copy/Copy.d.ts +1 -1
- package/lib/components/CopyButton/CopyButton.d.ts +1 -1
- package/lib/components/DataTable/DataTable.d.ts +2 -1
- package/lib/components/DataTable/TableContainer.d.ts +10 -2
- package/lib/components/DataTable/TableContainer.js +15 -3
- package/lib/components/DataTable/state/sorting.d.ts +2 -4
- package/lib/components/DataTableSkeleton/DataTableSkeleton.d.ts +1 -1
- package/lib/components/DataTableSkeleton/DataTableSkeleton.js +1 -1
- package/lib/components/DatePicker/DatePicker.d.ts +3 -2
- package/lib/components/DatePicker/DatePicker.js +18 -135
- package/lib/components/DatePicker/DatePickerLocales.d.ts +12 -0
- package/lib/components/DatePicker/DatePickerLocales.js +137 -0
- package/lib/components/DatePickerInput/DatePickerInput.js +49 -27
- package/lib/components/Dropdown/Dropdown.js +9 -1
- package/lib/components/FileUploader/FileUploader.d.ts +23 -8
- package/lib/components/FileUploader/FileUploader.js +53 -33
- package/lib/components/FileUploader/FileUploaderButton.js +2 -2
- package/lib/components/FileUploader/FileUploaderDropContainer.d.ts +13 -2
- package/lib/components/FileUploader/FileUploaderDropContainer.js +15 -6
- package/lib/components/FileUploader/FileUploaderItem.js +9 -6
- package/lib/components/Menu/index.d.ts +4 -3
- package/lib/components/Modal/Modal.js +3 -2
- package/lib/components/Notification/Notification.js +3 -2
- package/lib/components/Pagination/Pagination.js +5 -5
- package/lib/components/Popover/index.js +2 -2
- package/lib/components/Select/Select.js +27 -33
- package/lib/components/Toggletip/index.d.ts +1 -0
- package/lib/components/Toggletip/index.js +3 -0
- package/lib/components/Tooltip/index.d.ts +3 -2
- package/lib/internal/FloatingMenu.js +8 -6
- package/lib/internal/OptimizedResize.js +4 -5
- package/lib/internal/wrapFocus.d.ts +4 -2
- package/lib/internal/wrapFocus.js +5 -4
- package/lib/tools/events.d.ts +1 -1
- package/package.json +20 -27
- package/telemetry.yml +2 -0
|
@@ -6,6 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
export interface ButtonSetProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
9
|
+
/**
|
|
10
|
+
* fluid: button set resize to the size of the container up to a maximum dependant on the
|
|
11
|
+
* number of buttons. Overrides `stacked` property.
|
|
12
|
+
*/
|
|
13
|
+
fluid?: boolean;
|
|
9
14
|
/**
|
|
10
15
|
* Specify the button arrangement of the set (vertically stacked or
|
|
11
16
|
* horizontal)
|
|
@@ -6,26 +6,85 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
|
|
9
|
-
import React, { forwardRef } from 'react';
|
|
9
|
+
import React, { forwardRef, useRef, useState, useEffect } from 'react';
|
|
10
10
|
import PropTypes from 'prop-types';
|
|
11
11
|
import cx from 'classnames';
|
|
12
12
|
import { usePrefix } from '../../internal/usePrefix.js';
|
|
13
|
+
import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
|
|
13
14
|
|
|
15
|
+
const buttonOrder = kind => ({
|
|
16
|
+
ghost: 1,
|
|
17
|
+
'danger--ghost': 2,
|
|
18
|
+
tertiary: 3,
|
|
19
|
+
danger: 5,
|
|
20
|
+
primary: 6
|
|
21
|
+
})[kind] ?? 4;
|
|
22
|
+
const getButtonKind = element => {
|
|
23
|
+
if (/*#__PURE__*/React.isValidElement(element) && element.props && typeof element.props === 'object') {
|
|
24
|
+
const props = element.props;
|
|
25
|
+
return props.kind ?? 'primary';
|
|
26
|
+
}
|
|
27
|
+
return 'primary';
|
|
28
|
+
};
|
|
14
29
|
const ButtonSet = /*#__PURE__*/forwardRef((props, ref) => {
|
|
15
30
|
const {
|
|
16
31
|
children,
|
|
17
32
|
className,
|
|
33
|
+
fluid,
|
|
18
34
|
stacked,
|
|
19
35
|
...rest
|
|
20
36
|
} = props;
|
|
21
37
|
const prefix = usePrefix();
|
|
38
|
+
const fluidInnerRef = useRef(null);
|
|
39
|
+
const [isStacked, setIsStacked] = useState(false);
|
|
40
|
+
const [sortedChildren, setSortedChildren] = useState(React.Children.toArray(children));
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Used to determine if the buttons are currently stacked
|
|
44
|
+
*/
|
|
45
|
+
useIsomorphicEffect(() => {
|
|
46
|
+
const checkStacking = () => {
|
|
47
|
+
let newIsStacked = stacked || false;
|
|
48
|
+
if (fluidInnerRef && fluidInnerRef.current) {
|
|
49
|
+
const computedStyle = window.getComputedStyle(fluidInnerRef.current);
|
|
50
|
+
newIsStacked = computedStyle?.getPropertyValue?.('--flex-direction') === 'column';
|
|
51
|
+
}
|
|
52
|
+
return newIsStacked;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/* initial value not dependant on observer */
|
|
56
|
+
setIsStacked(checkStacking());
|
|
57
|
+
if (!fluidInnerRef.current) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
61
|
+
setIsStacked(checkStacking());
|
|
62
|
+
});
|
|
63
|
+
resizeObserver.observe(fluidInnerRef.current);
|
|
64
|
+
return () => resizeObserver.disconnect();
|
|
65
|
+
}, [isStacked, stacked]);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
const newSortedChildren = React.Children.toArray(children);
|
|
68
|
+
newSortedChildren.sort((a, b) => {
|
|
69
|
+
return (buttonOrder(getButtonKind(a)) - buttonOrder(getButtonKind(b))) * (isStacked ? -1 : 1);
|
|
70
|
+
});
|
|
71
|
+
setSortedChildren(newSortedChildren);
|
|
72
|
+
|
|
73
|
+
// adding sortedChildren to deps causes an infinite loop
|
|
74
|
+
}, [children, isStacked]);
|
|
22
75
|
const buttonSetClasses = cx(className, `${prefix}--btn-set`, {
|
|
23
|
-
[`${prefix}--btn-set--stacked`]:
|
|
76
|
+
[`${prefix}--btn-set--stacked`]: isStacked,
|
|
77
|
+
[`${prefix}--btn-set--fluid`]: fluid
|
|
24
78
|
});
|
|
25
79
|
return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
|
|
26
80
|
className: buttonSetClasses,
|
|
27
81
|
ref: ref
|
|
28
|
-
}),
|
|
82
|
+
}), fluid ? /*#__PURE__*/React.createElement("div", {
|
|
83
|
+
ref: fluidInnerRef,
|
|
84
|
+
className: cx(`${prefix}--btn-set__fluid-inner`, {
|
|
85
|
+
[`${prefix}--btn-set__fluid-inner--auto-stack`]: true
|
|
86
|
+
})
|
|
87
|
+
}, sortedChildren) : children);
|
|
29
88
|
});
|
|
30
89
|
ButtonSet.displayName = 'ButtonSet';
|
|
31
90
|
ButtonSet.propTypes = {
|
|
@@ -37,9 +96,14 @@ ButtonSet.propTypes = {
|
|
|
37
96
|
* Specify an optional className to be added to your ButtonSet
|
|
38
97
|
*/
|
|
39
98
|
className: PropTypes.string,
|
|
99
|
+
/**
|
|
100
|
+
* fluid: button set resize to the size of the container up to a maximum dependant on the
|
|
101
|
+
* number of buttons.
|
|
102
|
+
*/
|
|
103
|
+
fluid: PropTypes.bool,
|
|
40
104
|
/**
|
|
41
105
|
* Specify the button arrangement of the set (vertically stacked or
|
|
42
|
-
* horizontal)
|
|
106
|
+
* horizontal) - ignored when fluid is true
|
|
43
107
|
*/
|
|
44
108
|
stacked: PropTypes.bool
|
|
45
109
|
};
|
|
@@ -111,7 +111,7 @@ declare namespace CodeSnippet {
|
|
|
111
111
|
/**
|
|
112
112
|
* Specify how the trigger should align with the tooltip
|
|
113
113
|
*/
|
|
114
|
-
align: PropTypes.Requireable<
|
|
114
|
+
align: PropTypes.Requireable<string> | PropTypes.Validator<string>;
|
|
115
115
|
/**
|
|
116
116
|
* Specify a label to be read by screen readers on the containing textbox
|
|
117
117
|
* node
|
|
@@ -206,7 +206,7 @@ const ComposedModalDialog = /*#__PURE__*/React.forwardRef(function ComposedModal
|
|
|
206
206
|
// behavior by explicitly setting preventCloseOnClickOutside to false,
|
|
207
207
|
// rather than just leaving it undefined.
|
|
208
208
|
!isPassive && preventCloseOnClickOutside === false;
|
|
209
|
-
if (shouldCloseOnOutsideClick && target instanceof Node && !elementOrParentIsFloatingMenu(target, selectorsFloatingMenus) && innerModal.current && !innerModal.current.contains(target) && !innerModal.current.contains(mouseDownTarget)) {
|
|
209
|
+
if (shouldCloseOnOutsideClick && target instanceof Node && !elementOrParentIsFloatingMenu(target, selectorsFloatingMenus, prefix) && innerModal.current && !innerModal.current.contains(target) && !innerModal.current.contains(mouseDownTarget)) {
|
|
210
210
|
closeModal(evt);
|
|
211
211
|
}
|
|
212
212
|
}
|
|
@@ -230,7 +230,8 @@ const ComposedModalDialog = /*#__PURE__*/React.forwardRef(function ComposedModal
|
|
|
230
230
|
endTrapNode: endSentinelNode,
|
|
231
231
|
currentActiveNode,
|
|
232
232
|
oldActiveNode,
|
|
233
|
-
selectorsFloatingMenus: selectorsFloatingMenus?.filter(Boolean)
|
|
233
|
+
selectorsFloatingMenus: selectorsFloatingMenus?.filter(Boolean),
|
|
234
|
+
prefix
|
|
234
235
|
});
|
|
235
236
|
}
|
|
236
237
|
|
|
@@ -50,7 +50,7 @@ declare namespace Copy {
|
|
|
50
50
|
/**
|
|
51
51
|
* Specify how the trigger should align with the tooltip
|
|
52
52
|
*/
|
|
53
|
-
align: PropTypes.Requireable<
|
|
53
|
+
align: PropTypes.Requireable<string> | PropTypes.Validator<string>;
|
|
54
54
|
/**
|
|
55
55
|
* **Experimental**: Will attempt to automatically align the tooltip. Requires
|
|
56
56
|
* React v17+
|
|
@@ -51,7 +51,7 @@ declare namespace CopyButton {
|
|
|
51
51
|
/**
|
|
52
52
|
* Specify how the trigger should align with the tooltip
|
|
53
53
|
*/
|
|
54
|
-
align: PropTypes.Requireable<
|
|
54
|
+
align: PropTypes.Requireable<string> | PropTypes.Validator<string>;
|
|
55
55
|
/**
|
|
56
56
|
* **Experimental**: Will attempt to automatically align the tooltip. Requires
|
|
57
57
|
* React v17+
|
|
@@ -282,11 +282,12 @@ export declare const DataTable: {
|
|
|
282
282
|
};
|
|
283
283
|
TableCell: React.ForwardRefExoticComponent<import("./TableCell").TableCellProps & React.RefAttributes<HTMLTableCellElement>>;
|
|
284
284
|
TableContainer: {
|
|
285
|
-
({ aiEnabled, className, children, title, description, stickyHeader, useStaticWidth, ...rest }: import("./TableContainer").TableContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
285
|
+
({ aiEnabled, className, children, decorator, title, description, stickyHeader, useStaticWidth, ...rest }: import("./TableContainer").TableContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
286
286
|
propTypes: {
|
|
287
287
|
aiEnabled: PropTypes.Requireable<boolean>;
|
|
288
288
|
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
289
289
|
className: PropTypes.Requireable<string>;
|
|
290
|
+
decorator: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
290
291
|
description: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
291
292
|
stickyHeader: PropTypes.Requireable<boolean>;
|
|
292
293
|
title: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
@@ -5,12 +5,16 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
import PropTypes from 'prop-types';
|
|
8
|
-
import React, { type HTMLAttributes } from 'react';
|
|
8
|
+
import React, { ReactNode, type HTMLAttributes } from 'react';
|
|
9
9
|
export interface TableContainerProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {
|
|
10
10
|
/**
|
|
11
11
|
* Specify if the entire table has AI generated contents
|
|
12
12
|
*/
|
|
13
13
|
aiEnabled?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableContainer` component
|
|
16
|
+
*/
|
|
17
|
+
decorator?: ReactNode;
|
|
14
18
|
/**
|
|
15
19
|
* Optional description text for the Table
|
|
16
20
|
*/
|
|
@@ -29,7 +33,7 @@ export interface TableContainerProps extends Omit<HTMLAttributes<HTMLDivElement>
|
|
|
29
33
|
title?: React.ReactNode;
|
|
30
34
|
}
|
|
31
35
|
declare const TableContainer: {
|
|
32
|
-
({ aiEnabled, className, children, title, description, stickyHeader, useStaticWidth, ...rest }: TableContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
36
|
+
({ aiEnabled, className, children, decorator, title, description, stickyHeader, useStaticWidth, ...rest }: TableContainerProps): import("react/jsx-runtime").JSX.Element;
|
|
33
37
|
propTypes: {
|
|
34
38
|
/**
|
|
35
39
|
* Specify if the entire table has AI generated contents
|
|
@@ -37,6 +41,10 @@ declare const TableContainer: {
|
|
|
37
41
|
aiEnabled: PropTypes.Requireable<boolean>;
|
|
38
42
|
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
39
43
|
className: PropTypes.Requireable<string>;
|
|
44
|
+
/**
|
|
45
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableContainer` component
|
|
46
|
+
*/
|
|
47
|
+
decorator: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
40
48
|
/**
|
|
41
49
|
* Optional description text for the Table
|
|
42
50
|
*/
|
|
@@ -18,6 +18,7 @@ const TableContainer = ({
|
|
|
18
18
|
aiEnabled,
|
|
19
19
|
className,
|
|
20
20
|
children,
|
|
21
|
+
decorator,
|
|
21
22
|
title,
|
|
22
23
|
description,
|
|
23
24
|
stickyHeader,
|
|
@@ -43,15 +44,22 @@ const TableContainer = ({
|
|
|
43
44
|
value: value
|
|
44
45
|
}, /*#__PURE__*/React.createElement(Section, _extends({}, rest, {
|
|
45
46
|
className: tableContainerClasses
|
|
46
|
-
}), (title || description) && /*#__PURE__*/React.createElement("div", {
|
|
47
|
-
className: `${prefix}--data-table-header
|
|
47
|
+
}), (title || description || decorator) && /*#__PURE__*/React.createElement("div", {
|
|
48
|
+
className: cx(`${prefix}--data-table-header`, {
|
|
49
|
+
[`${prefix}--data-table-header__with-decorator`]: decorator,
|
|
50
|
+
[`${prefix}--data-table-header__with-decorator--standalone`]: decorator && !title && !description
|
|
51
|
+
})
|
|
52
|
+
}, (title || description) && /*#__PURE__*/React.createElement("div", {
|
|
53
|
+
className: `${prefix}--data-table-header__content`
|
|
48
54
|
}, title && /*#__PURE__*/React.createElement(Heading, {
|
|
49
55
|
className: `${prefix}--data-table-header__title`,
|
|
50
56
|
id: titleId
|
|
51
57
|
}, title), description && /*#__PURE__*/React.createElement("p", {
|
|
52
58
|
className: `${prefix}--data-table-header__description`,
|
|
53
59
|
id: descriptionId
|
|
54
|
-
}, description)),
|
|
60
|
+
}, description)), decorator && /*#__PURE__*/React.createElement("div", {
|
|
61
|
+
className: `${prefix}--data-table-header__decorator`
|
|
62
|
+
}, decorator)), children));
|
|
55
63
|
};
|
|
56
64
|
TableContainer.propTypes = {
|
|
57
65
|
/**
|
|
@@ -60,6 +68,10 @@ TableContainer.propTypes = {
|
|
|
60
68
|
aiEnabled: PropTypes.bool,
|
|
61
69
|
children: PropTypes.node,
|
|
62
70
|
className: PropTypes.string,
|
|
71
|
+
/**
|
|
72
|
+
* **Experimental**: Provide a `decorator` component to be rendered inside the `TableContainer` component
|
|
73
|
+
*/
|
|
74
|
+
decorator: PropTypes.node,
|
|
63
75
|
/**
|
|
64
76
|
* Optional description text for the Table
|
|
65
77
|
*/
|
|
@@ -43,8 +43,7 @@ export declare const getNextSortDirection: (prevHeader: string, currentHeader: s
|
|
|
43
43
|
* @param state - Current table state.
|
|
44
44
|
* @param key - Header key to sort by.
|
|
45
45
|
*/
|
|
46
|
-
export declare const getNextSortState: <ColTypes extends any[]>(
|
|
47
|
-
props: Props, state: State<ColTypes>, { key }: {
|
|
46
|
+
export declare const getNextSortState: <ColTypes extends any[]>(props: Props, state: State<ColTypes>, { key }: {
|
|
48
47
|
key: string;
|
|
49
48
|
}) => Pick<State<ColTypes>, "sortHeaderKey" | "sortDirection" | "rowIds">;
|
|
50
49
|
/**
|
|
@@ -55,6 +54,5 @@ props: Props, state: State<ColTypes>, { key }: {
|
|
|
55
54
|
* @param key - Header key to sort by.
|
|
56
55
|
* @param sortDirection - Sort direction to apply.
|
|
57
56
|
*/
|
|
58
|
-
export declare const getSortedState: <ColTypes extends any[]>(
|
|
59
|
-
{ locale, sortRow }: Props, { rowIds, cellsById, initialRowOrder }: State<ColTypes>, key: string, sortDirection: DataTableSortState) => Pick<State<ColTypes>, "rowIds" | "sortDirection" | "sortHeaderKey">;
|
|
57
|
+
export declare const getSortedState: <ColTypes extends any[]>({ locale, sortRow }: Props, { rowIds, cellsById, initialRowOrder }: State<ColTypes>, key: string, sortDirection: DataTableSortState) => Pick<State<ColTypes>, "rowIds" | "sortDirection" | "sortHeaderKey">;
|
|
60
58
|
export {};
|
|
@@ -62,7 +62,7 @@ const DataTableSkeleton = ({
|
|
|
62
62
|
}, rest), /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, columnsArray.map(i => /*#__PURE__*/React.createElement("th", {
|
|
63
63
|
key: i
|
|
64
64
|
}, headers ? /*#__PURE__*/React.createElement("div", {
|
|
65
|
-
className:
|
|
65
|
+
className: `${prefix}--table-header-label`
|
|
66
66
|
}, headers[i]?.header) : _span2 || (_span2 = /*#__PURE__*/React.createElement("span", null)))))), /*#__PURE__*/React.createElement("tbody", null, rows)));
|
|
67
67
|
};
|
|
68
68
|
DataTableSkeleton.propTypes = {
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import React, { ReactNode } from 'react';
|
|
8
8
|
import flatpickr from 'flatpickr';
|
|
9
9
|
import { DateLimit, DateOption } from 'flatpickr/dist/types/options';
|
|
10
|
+
import { type SupportedLocale } from './DatePickerLocales';
|
|
10
11
|
export type DatePickerTypes = 'simple' | 'single' | 'range';
|
|
11
12
|
export interface DatePickerProps {
|
|
12
13
|
/**
|
|
@@ -69,7 +70,7 @@ export interface DatePickerProps {
|
|
|
69
70
|
/**
|
|
70
71
|
* The language locale used to format the days of the week, months, and numbers. The full list of supported locales can be found here https://github.com/flatpickr/flatpickr/tree/master/src/l10n
|
|
71
72
|
*/
|
|
72
|
-
locale?: string | any |
|
|
73
|
+
locale?: string | any | SupportedLocale | undefined;
|
|
73
74
|
/**
|
|
74
75
|
* The maximum date that a user can pick to.
|
|
75
76
|
*/
|
|
@@ -99,7 +100,7 @@ export interface DatePickerProps {
|
|
|
99
100
|
* if boolean applies to all inputs
|
|
100
101
|
* if array applies to each input in order
|
|
101
102
|
*/
|
|
102
|
-
readOnly?: boolean |
|
|
103
|
+
readOnly?: boolean | undefined;
|
|
103
104
|
/**
|
|
104
105
|
* `true` to use the short version.
|
|
105
106
|
*/
|
|
@@ -24,6 +24,7 @@ import '../FluidForm/FluidForm.js';
|
|
|
24
24
|
import { FormContext } from '../FluidForm/FormContext.js';
|
|
25
25
|
import { WarningFilled, WarningAltFilled } from '@carbon/icons-react';
|
|
26
26
|
import { datePartsOrder } from '@carbon/utilities';
|
|
27
|
+
import { SUPPORTED_LOCALES } from './DatePickerLocales.js';
|
|
27
28
|
|
|
28
29
|
// Weekdays shorthand for English locale
|
|
29
30
|
// Ensure localization exists before trying to access it
|
|
@@ -362,7 +363,6 @@ const DatePicker = /*#__PURE__*/React.forwardRef(function DatePicker({
|
|
|
362
363
|
const {
|
|
363
364
|
current: end
|
|
364
365
|
} = endInputField;
|
|
365
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- https://github.com/carbon-design-system/carbon/issues/20452
|
|
366
366
|
const flatpickerConfig = {
|
|
367
367
|
inline: inline ?? false,
|
|
368
368
|
onClose: onCalendarClose,
|
|
@@ -511,12 +511,11 @@ const DatePicker = /*#__PURE__*/React.forwardRef(function DatePicker({
|
|
|
511
511
|
|
|
512
512
|
// prevent a duplicate date selection when a default value is set
|
|
513
513
|
if (value) {
|
|
514
|
-
if (
|
|
515
|
-
|
|
514
|
+
if (start) {
|
|
515
|
+
start.value = '';
|
|
516
516
|
}
|
|
517
|
-
if (
|
|
518
|
-
|
|
519
|
-
endInputField.current.value = '';
|
|
517
|
+
if (end) {
|
|
518
|
+
end.value = '';
|
|
520
519
|
}
|
|
521
520
|
}
|
|
522
521
|
if (start) {
|
|
@@ -596,8 +595,7 @@ const DatePicker = /*#__PURE__*/React.forwardRef(function DatePicker({
|
|
|
596
595
|
endInputField.current.value = '';
|
|
597
596
|
}
|
|
598
597
|
}
|
|
599
|
-
|
|
600
|
-
}, [value]);
|
|
598
|
+
}, [value, startInputField]);
|
|
601
599
|
useEffect(() => {
|
|
602
600
|
const handleMouseDown = event => {
|
|
603
601
|
if (calendarRef.current && calendarRef.current.isOpen && !calendarRef.current.calendarContainer.contains(event.target) && !startInputField.current.contains(event.target) && !endInputField.current?.contains(event.target)) {
|
|
@@ -605,8 +603,7 @@ const DatePicker = /*#__PURE__*/React.forwardRef(function DatePicker({
|
|
|
605
603
|
closeCalendar();
|
|
606
604
|
}
|
|
607
605
|
};
|
|
608
|
-
|
|
609
|
-
const closeCalendar = event => {
|
|
606
|
+
const closeCalendar = () => {
|
|
610
607
|
calendarRef.current?.close();
|
|
611
608
|
// Remove focus from endDate calendar input
|
|
612
609
|
onCalendarClose(calendarRef.current?.selectedDates, '', calendarRef.current, {
|
|
@@ -621,15 +618,22 @@ const DatePicker = /*#__PURE__*/React.forwardRef(function DatePicker({
|
|
|
621
618
|
useEffect(() => {
|
|
622
619
|
if (calendarRef.current?.set) {
|
|
623
620
|
if (value !== undefined) {
|
|
624
|
-
calendarRef.current.setDate
|
|
621
|
+
// To make up for calendarRef.current.setDate not making provision for an empty string or array
|
|
622
|
+
if (value === '' || value === null || Array.isArray(value) && (value.length === 0 || value.every(element => !element))) {
|
|
623
|
+
// only clear if there are selected dates to avoid unnecessary operations
|
|
624
|
+
if (calendarRef.current.selectedDates.length > 0) {
|
|
625
|
+
calendarRef.current.clear();
|
|
626
|
+
}
|
|
627
|
+
} else {
|
|
628
|
+
calendarRef.current.setDate(value);
|
|
629
|
+
}
|
|
625
630
|
}
|
|
626
631
|
updateClassNames(calendarRef.current, prefix);
|
|
627
632
|
//for simple date picker w/o calendar; initial mount may not have value
|
|
628
633
|
} else if (!calendarRef.current && value) {
|
|
629
634
|
startInputField.current.value = value;
|
|
630
635
|
}
|
|
631
|
-
}, [value, prefix]);
|
|
632
|
-
|
|
636
|
+
}, [value, prefix, startInputField]);
|
|
633
637
|
let fluidError;
|
|
634
638
|
if (isFluid) {
|
|
635
639
|
if (invalid) {
|
|
@@ -718,128 +722,7 @@ DatePicker.propTypes = {
|
|
|
718
722
|
/**
|
|
719
723
|
* The language locale used to format the days of the week, months, and numbers. The full list of supported locales can be found here https://github.com/flatpickr/flatpickr/tree/master/src/l10n
|
|
720
724
|
*/
|
|
721
|
-
locale: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(
|
|
722
|
-
// Arabic
|
|
723
|
-
'at',
|
|
724
|
-
// Austria
|
|
725
|
-
'az',
|
|
726
|
-
// Azerbaijan
|
|
727
|
-
'be',
|
|
728
|
-
// Belarusian
|
|
729
|
-
'bg',
|
|
730
|
-
// Bulgarian
|
|
731
|
-
'bn',
|
|
732
|
-
// Bangla
|
|
733
|
-
'bs',
|
|
734
|
-
// Bosnia
|
|
735
|
-
'cat',
|
|
736
|
-
// Catalan
|
|
737
|
-
'cs',
|
|
738
|
-
// Czech
|
|
739
|
-
'cy',
|
|
740
|
-
// Welsh
|
|
741
|
-
'da',
|
|
742
|
-
// Danish
|
|
743
|
-
'de',
|
|
744
|
-
// German
|
|
745
|
-
'en',
|
|
746
|
-
// English
|
|
747
|
-
'eo',
|
|
748
|
-
// Esperanto
|
|
749
|
-
'es',
|
|
750
|
-
// Spanish
|
|
751
|
-
'et',
|
|
752
|
-
// Estonian
|
|
753
|
-
'fa',
|
|
754
|
-
// Persian
|
|
755
|
-
'fi',
|
|
756
|
-
// Finnish
|
|
757
|
-
'fo',
|
|
758
|
-
// Faroese
|
|
759
|
-
'fr',
|
|
760
|
-
// French
|
|
761
|
-
'ga',
|
|
762
|
-
// Gaelic
|
|
763
|
-
'gr',
|
|
764
|
-
// Greek
|
|
765
|
-
'he',
|
|
766
|
-
// Hebrew
|
|
767
|
-
'hi',
|
|
768
|
-
// Hindi
|
|
769
|
-
'hr',
|
|
770
|
-
// Croatian
|
|
771
|
-
'hu',
|
|
772
|
-
// Hungarian
|
|
773
|
-
'id',
|
|
774
|
-
// Indonesian
|
|
775
|
-
'is',
|
|
776
|
-
// Icelandic
|
|
777
|
-
'it',
|
|
778
|
-
// Italian
|
|
779
|
-
'ja',
|
|
780
|
-
// Japanese
|
|
781
|
-
'ka',
|
|
782
|
-
// Georgian
|
|
783
|
-
'km',
|
|
784
|
-
// Khmer
|
|
785
|
-
'ko',
|
|
786
|
-
// Korean
|
|
787
|
-
'kz',
|
|
788
|
-
// Kazakh
|
|
789
|
-
'lt',
|
|
790
|
-
// Lithuanian
|
|
791
|
-
'lv',
|
|
792
|
-
// Latvian
|
|
793
|
-
'mk',
|
|
794
|
-
// Macedonian
|
|
795
|
-
'mn',
|
|
796
|
-
// Mongolian
|
|
797
|
-
'ms',
|
|
798
|
-
// Malaysian
|
|
799
|
-
'my',
|
|
800
|
-
// Burmese
|
|
801
|
-
'nl',
|
|
802
|
-
// Dutch
|
|
803
|
-
'no',
|
|
804
|
-
// Norwegian
|
|
805
|
-
'pa',
|
|
806
|
-
// Punjabi
|
|
807
|
-
'pl',
|
|
808
|
-
// Polish
|
|
809
|
-
'pt',
|
|
810
|
-
// Portuguese
|
|
811
|
-
'ro',
|
|
812
|
-
// Romanian
|
|
813
|
-
'ru',
|
|
814
|
-
// Russian
|
|
815
|
-
'si',
|
|
816
|
-
// Sinhala
|
|
817
|
-
'sk',
|
|
818
|
-
// Slovak
|
|
819
|
-
'sl',
|
|
820
|
-
// Slovenian
|
|
821
|
-
'sq',
|
|
822
|
-
// Albanian
|
|
823
|
-
'sr',
|
|
824
|
-
// Serbian
|
|
825
|
-
'sv',
|
|
826
|
-
// Swedish
|
|
827
|
-
'th',
|
|
828
|
-
// Thai
|
|
829
|
-
'tr',
|
|
830
|
-
// Turkish
|
|
831
|
-
'uk',
|
|
832
|
-
// Ukrainian
|
|
833
|
-
'uz',
|
|
834
|
-
// Uzbek
|
|
835
|
-
'uz_latn',
|
|
836
|
-
// Uzbek Latin
|
|
837
|
-
'vn',
|
|
838
|
-
// Vietnamese
|
|
839
|
-
'zh_tw',
|
|
840
|
-
// Mandarin Traditional
|
|
841
|
-
'zh' // Mandarin
|
|
842
|
-
])]),
|
|
725
|
+
locale: PropTypes.oneOfType([PropTypes.object, PropTypes.oneOf(SUPPORTED_LOCALES)]),
|
|
843
726
|
/**
|
|
844
727
|
* The maximum date that a user can pick to.
|
|
845
728
|
*/
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2025
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* The full list of supported locales can be found here:
|
|
9
|
+
* https://github.com/flatpickr/flatpickr/tree/master/src/l10n
|
|
10
|
+
*/
|
|
11
|
+
export declare const SUPPORTED_LOCALES: readonly ["ar", "at", "az", "be", "bg", "bn", "bs", "cat", "cs", "cy", "da", "de", "en", "eo", "es", "et", "fa", "fi", "fo", "fr", "ga", "gr", "he", "hi", "hr", "hu", "id", "is", "it", "ja", "ka", "km", "ko", "kz", "lt", "lv", "mk", "mn", "ms", "my", "nl", "no", "pa", "pl", "pt", "ro", "ru", "si", "sk", "sl", "sq", "sr", "sv", "th", "tr", "uk", "uz", "uz_latn", "vn", "zh_tw", "zh"];
|
|
12
|
+
export type SupportedLocale = (typeof SUPPORTED_LOCALES)[number];
|