@kaizen/components 0.0.0-canary-v2-20250901045936 → 0.0.0-canary-alpha-release-20250918043833
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/alpha/README.md +28 -0
- package/alpha/package.json +5 -0
- package/dist/cjs/alpha.cjs +1 -0
- package/dist/cjs/src/Modal/GenericModal/GenericModal.cjs +33 -65
- package/dist/cjs/src/Modal/GenericModal/GenericModal.module.scss.cjs +1 -3
- package/dist/cjs/src/Notification/InlineNotification/InlineNotification.cjs +1 -1
- package/dist/cjs/src/__alpha__/SingleSelect/SingleSelect.cjs +35 -74
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/ComboBox/ComboBox.cjs +105 -0
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/ComboBox/ComboBox.module.css.cjs +11 -0
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/ComboBoxTrigger.cjs +112 -0
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/ComboBoxTrigger.module.css.cjs +16 -0
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/List/List.cjs +35 -10
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/ListItem/ListItem.cjs +61 -8
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/ListItem/ListItem.module.css.cjs +10 -1
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/ListSection/ListSection.cjs +38 -9
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/ListSection/ListSection.module.css.cjs +4 -1
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/Popover/Popover.cjs +60 -30
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/Popover/Popover.module.css.cjs +2 -1
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/Popover/utils/usePopoverPositioning.cjs +2 -1
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/Popover/utils/usePositioningStyles.cjs +4 -2
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/Select/Select.cjs +87 -0
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/Select/Select.module.css.cjs +11 -0
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/SelectTrigger/SelectTrigger.cjs +52 -0
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/SelectTrigger/SelectTrigger.module.css.cjs +13 -0
- package/dist/esm/alpha.mjs +1 -1
- package/dist/esm/src/Modal/GenericModal/GenericModal.mjs +34 -65
- package/dist/esm/src/Modal/GenericModal/GenericModal.module.scss.mjs +1 -3
- package/dist/esm/src/Notification/InlineNotification/InlineNotification.mjs +1 -1
- package/dist/esm/src/__alpha__/SingleSelect/SingleSelect.mjs +39 -73
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/ComboBox/ComboBox.mjs +96 -0
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/ComboBox/ComboBox.module.css.mjs +9 -0
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/ComboBoxTrigger.mjs +103 -0
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/ComboBoxTrigger.module.css.mjs +14 -0
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/List/List.mjs +37 -14
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/ListItem/ListItem.mjs +63 -13
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/ListItem/ListItem.module.css.mjs +10 -1
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/ListSection/ListSection.mjs +41 -15
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/ListSection/ListSection.module.css.mjs +4 -1
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/Popover/Popover.mjs +69 -43
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/Popover/Popover.module.css.mjs +2 -1
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/Popover/utils/usePopoverPositioning.mjs +2 -1
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/Popover/utils/usePositioningStyles.mjs +4 -2
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/Select/Select.mjs +78 -0
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/Select/Select.module.css.mjs +9 -0
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/SelectTrigger/SelectTrigger.mjs +43 -0
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/SelectTrigger/SelectTrigger.module.css.mjs +11 -0
- package/dist/styles.css +385 -21
- package/dist/types/__alpha__/SingleSelect/SingleSelect.d.ts +14 -19
- package/dist/types/__alpha__/SingleSelect/_docs/mockData.d.ts +3 -0
- package/dist/types/__alpha__/SingleSelect/context/SingleSelectContext.d.ts +15 -7
- package/dist/types/__alpha__/SingleSelect/subcomponents/ComboBox/ComboBox.d.ts +2 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/ComboBox/index.d.ts +1 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/ComboBoxTrigger.d.ts +2 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/index.d.ts +1 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/List/List.d.ts +2 -7
- package/dist/types/__alpha__/SingleSelect/subcomponents/ListItem/ListItem.d.ts +2 -7
- package/dist/types/__alpha__/SingleSelect/subcomponents/ListSection/ListSection.d.ts +2 -9
- package/dist/types/__alpha__/SingleSelect/subcomponents/Popover/Popover.d.ts +3 -6
- package/dist/types/__alpha__/SingleSelect/subcomponents/Popover/utils/index.d.ts +1 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/Popover/utils/usePopoverPositioning.d.ts +1 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/Popover/utils/usePositioningStyles.d.ts +1 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/Select/Select.d.ts +2 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/Select/index.d.ts +1 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/SelectTrigger/SelectTrigger.d.ts +2 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/SelectTrigger/index.d.ts +1 -0
- package/dist/types/__alpha__/SingleSelect/subcomponents/index.d.ts +4 -1
- package/dist/types/__alpha__/SingleSelect/types.d.ts +68 -11
- package/locales/en.json +9 -1
- package/package.json +10 -3
- package/src/Modal/GenericModal/GenericModal.spec.tsx +1 -1
- package/src/Modal/GenericModal/GenericModal.tsx +38 -70
- package/src/Notification/InlineNotification/InlineNotification.tsx +1 -1
- package/src/RichTextEditor/RichTextEditor/RichTextEditor.spec.stories.tsx +10 -3
- package/src/__alpha__/SingleSelect/SingleSelect.tsx +35 -88
- package/src/__alpha__/SingleSelect/_docs/SingleSelect.mdx +96 -6
- package/src/__alpha__/SingleSelect/_docs/SingleSelect.spec.stories.tsx +22 -24
- package/src/__alpha__/SingleSelect/_docs/SingleSelect.stickersheet.stories.tsx +389 -33
- package/src/__alpha__/SingleSelect/_docs/SingleSelect.stories.tsx +41 -22
- package/src/__alpha__/SingleSelect/_docs/mockData.ts +20 -14
- package/src/__alpha__/SingleSelect/context/SingleSelectContext.tsx +18 -7
- package/src/__alpha__/SingleSelect/subcomponents/ComboBox/ComboBox.module.css +35 -0
- package/src/__alpha__/SingleSelect/subcomponents/ComboBox/ComboBox.tsx +106 -0
- package/src/__alpha__/SingleSelect/subcomponents/ComboBox/index.ts +1 -0
- package/src/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/ComboBoxTrigger.module.css +130 -0
- package/src/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/ComboBoxTrigger.tsx +121 -0
- package/src/__alpha__/SingleSelect/subcomponents/ComboBoxTrigger/index.ts +1 -0
- package/src/__alpha__/SingleSelect/subcomponents/List/List.module.css +5 -0
- package/src/__alpha__/SingleSelect/subcomponents/List/List.tsx +36 -13
- package/src/__alpha__/SingleSelect/subcomponents/ListItem/ListItem.module.css +84 -3
- package/src/__alpha__/SingleSelect/subcomponents/ListItem/ListItem.tsx +67 -11
- package/src/__alpha__/SingleSelect/subcomponents/ListSection/ListSection.module.css +20 -5
- package/src/__alpha__/SingleSelect/subcomponents/ListSection/ListSection.tsx +46 -19
- package/src/__alpha__/SingleSelect/subcomponents/Popover/Popover.module.css +7 -5
- package/src/__alpha__/SingleSelect/subcomponents/Popover/Popover.tsx +90 -37
- package/src/__alpha__/SingleSelect/subcomponents/Popover/utils/index.ts +1 -0
- package/src/__alpha__/SingleSelect/subcomponents/Popover/utils/usePopoverPositioning.ts +2 -2
- package/src/__alpha__/SingleSelect/subcomponents/Popover/utils/usePositioningStyles.ts +9 -8
- package/src/__alpha__/SingleSelect/subcomponents/Select/Select.module.css +35 -0
- package/src/__alpha__/SingleSelect/subcomponents/Select/Select.tsx +84 -0
- package/src/__alpha__/SingleSelect/subcomponents/Select/index.ts +1 -0
- package/src/__alpha__/SingleSelect/subcomponents/SelectTrigger/SelectTrigger.module.css +77 -0
- package/src/__alpha__/SingleSelect/subcomponents/SelectTrigger/SelectTrigger.tsx +52 -0
- package/src/__alpha__/SingleSelect/subcomponents/SelectTrigger/index.ts +1 -0
- package/src/__alpha__/SingleSelect/subcomponents/index.ts +4 -1
- package/src/__alpha__/SingleSelect/types.ts +94 -14
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/Trigger/Trigger.cjs +0 -57
- package/dist/cjs/src/__alpha__/SingleSelect/subcomponents/Trigger/Trigger.module.css.cjs +0 -6
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/Trigger/Trigger.mjs +0 -49
- package/dist/esm/src/__alpha__/SingleSelect/subcomponents/Trigger/Trigger.module.css.mjs +0 -4
- package/dist/types/__alpha__/SingleSelect/subcomponents/Trigger/Trigger.d.ts +0 -2
- package/dist/types/__alpha__/SingleSelect/subcomponents/Trigger/index.d.ts +0 -1
- package/src/__alpha__/SingleSelect/subcomponents/Trigger/Trigger.module.css +0 -19
- package/src/__alpha__/SingleSelect/subcomponents/Trigger/Trigger.tsx +0 -35
- package/src/__alpha__/SingleSelect/subcomponents/Trigger/index.ts +0 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { useId,
|
|
1
|
+
import React, { useId, useRef } from 'react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
import { Transition } from '@headlessui/react';
|
|
4
4
|
import classnames from 'classnames';
|
|
5
|
-
import
|
|
5
|
+
import { FocusOn } from 'react-focus-on';
|
|
6
6
|
import { useIsClientReady } from '../../utils/useIsClientReady/useIsClientReady.mjs';
|
|
7
7
|
import { warn } from '../util/console.mjs';
|
|
8
8
|
import { ModalContext } from './context/ModalContext.mjs';
|
|
@@ -24,87 +24,60 @@ const GenericModal = /*#__PURE__*/function () {
|
|
|
24
24
|
var labelledByID = useId();
|
|
25
25
|
var describedByID = useId();
|
|
26
26
|
var isClientReady = useIsClientReady();
|
|
27
|
-
var
|
|
28
|
-
|
|
29
|
-
setScrollLayer = _c[1];
|
|
30
|
-
var _d = useState(null),
|
|
31
|
-
modalLayer = _d[0],
|
|
32
|
-
setModalLayer = _d[1];
|
|
27
|
+
var scrollLayerRef = useRef(null);
|
|
28
|
+
var modalLayerRef = useRef(null);
|
|
33
29
|
var scrollModalToTop = function () {
|
|
34
30
|
// If we have a really long modal, the autofocus could land on an element down below
|
|
35
31
|
// causing the modal to scroll down and skipping over the content near the modal's top.
|
|
36
32
|
// Ensure that when the modal opens, we are at the top of its content.
|
|
37
33
|
requestAnimationFrame(function () {
|
|
38
|
-
|
|
39
|
-
|
|
34
|
+
var scrollElement = scrollLayerRef.current;
|
|
35
|
+
// This little verbose of a check but this ensures that the element is attached to the DOM as it animates in. This additional check aims to avoid race conditions
|
|
36
|
+
if (!(scrollElement === null || scrollElement === void 0 ? void 0 : scrollElement.isConnected)) return;
|
|
37
|
+
scrollElement.scrollTop = 0;
|
|
40
38
|
});
|
|
41
39
|
};
|
|
42
|
-
var
|
|
43
|
-
if (
|
|
44
|
-
|
|
40
|
+
var a11yWarn = function () {
|
|
41
|
+
if (!isClientReady) return;
|
|
42
|
+
// Ensure that consumers have provided an element that labels the modal
|
|
43
|
+
// to meet ARIA accessibility guidelines.
|
|
44
|
+
if (!document.getElementById(labelledByID)) {
|
|
45
|
+
warn("When using the Modal component, you must provide a label for the modal.\n Make sure you have a <ModalAccessibleLabel /> component with content that labels the modal.");
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
48
|
var focusOnAccessibleLabel = function () {
|
|
48
49
|
if (!isClientReady) return;
|
|
50
|
+
var modalElement = modalLayerRef.current;
|
|
51
|
+
if (!(modalElement === null || modalElement === void 0 ? void 0 : modalElement.isConnected)) return;
|
|
49
52
|
// Check if focus already exists within the modal
|
|
50
|
-
if (
|
|
53
|
+
if (modalElement.contains(document.activeElement)) {
|
|
51
54
|
return;
|
|
52
55
|
}
|
|
53
56
|
var labelElement = document.getElementById(labelledByID);
|
|
54
|
-
labelElement === null || labelElement === void 0 ? void 0 : labelElement.
|
|
55
|
-
|
|
56
|
-
var a11yWarn = function () {
|
|
57
|
-
if (!isClientReady) return;
|
|
58
|
-
// Ensure that consumers have provided an element that labels the modal
|
|
59
|
-
// to meet ARIA accessibility guidelines.
|
|
60
|
-
if (!document.getElementById(labelledByID)) {
|
|
61
|
-
warn("When using the Modal component, you must provide a label for the modal.\n Make sure you have a <ModalAccessibleLabel /> component with content that labels the modal.");
|
|
57
|
+
if (labelElement === null || labelElement === void 0 ? void 0 : labelElement.isConnected) {
|
|
58
|
+
labelElement.focus();
|
|
62
59
|
}
|
|
63
60
|
};
|
|
64
|
-
var
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var hasScrollbar = window.innerWidth > document.documentElement.clientWidth;
|
|
68
|
-
var scrollStyles = [styles.unscrollable];
|
|
69
|
-
if (hasScrollbar) {
|
|
70
|
-
scrollStyles.push(styles.pseudoScrollbar);
|
|
61
|
+
var onEscapeKeyHandler = function (e) {
|
|
62
|
+
if (e instanceof KeyboardEvent) {
|
|
63
|
+
onEscapeKeyup === null || onEscapeKeyup === void 0 ? void 0 : onEscapeKeyup(e);
|
|
71
64
|
}
|
|
72
|
-
(_a = document.documentElement.classList).add.apply(_a, scrollStyles);
|
|
73
65
|
};
|
|
74
66
|
var onAfterEnterHandler = function () {
|
|
75
67
|
scrollModalToTop();
|
|
76
|
-
|
|
68
|
+
var modalElement = modalLayerRef.current;
|
|
69
|
+
if (modalElement) {
|
|
77
70
|
onAfterEnter === null || onAfterEnter === void 0 ? void 0 : onAfterEnter();
|
|
78
71
|
focusOnAccessibleLabel();
|
|
79
72
|
a11yWarn();
|
|
80
73
|
}
|
|
81
74
|
};
|
|
82
|
-
var
|
|
83
|
-
if (
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
}, [onEscapeKeyup]);
|
|
87
|
-
var onBeforeEnterHandler = function () {
|
|
88
|
-
preventBodyScroll();
|
|
89
|
-
if (onEscapeKeyup && isClientReady) {
|
|
90
|
-
document.addEventListener('keyup', escapeKeyHandler);
|
|
75
|
+
var outsideModalClickHandler = function (e) {
|
|
76
|
+
if (e.target === scrollLayerRef.current || e.target === modalLayerRef.current) {
|
|
77
|
+
onOutsideModalClick === null || onOutsideModalClick === void 0 ? void 0 : onOutsideModalClick(e);
|
|
91
78
|
}
|
|
92
79
|
};
|
|
93
|
-
var cleanUpAfterClose = useCallback(function () {
|
|
94
|
-
if (!isClientReady) return;
|
|
95
|
-
document.documentElement.classList.remove(styles.unscrollable, styles.pseudoScrollbar);
|
|
96
|
-
if (onEscapeKeyup) {
|
|
97
|
-
document.removeEventListener('keyup', escapeKeyHandler);
|
|
98
|
-
}
|
|
99
|
-
}, [escapeKeyHandler, onEscapeKeyup, isClientReady]);
|
|
100
|
-
/* Ensure sure add-on styles (e.g. unscrollable) and key event is cleaned up when the modal is unmounted*/
|
|
101
|
-
useEffect(function () {
|
|
102
|
-
return function () {
|
|
103
|
-
return cleanUpAfterClose();
|
|
104
|
-
};
|
|
105
|
-
}, [cleanUpAfterClose]);
|
|
106
80
|
var onAfterLeaveHandler = function () {
|
|
107
|
-
cleanUpAfterClose();
|
|
108
81
|
propsOnAfterLeave === null || propsOnAfterLeave === void 0 ? void 0 : propsOnAfterLeave();
|
|
109
82
|
};
|
|
110
83
|
// Don't render portal during SSR
|
|
@@ -114,7 +87,6 @@ const GenericModal = /*#__PURE__*/function () {
|
|
|
114
87
|
return /*#__PURE__*/createPortal(/*#__PURE__*/React.createElement(Transition, {
|
|
115
88
|
appear: true,
|
|
116
89
|
show: isOpen,
|
|
117
|
-
beforeEnter: onBeforeEnterHandler,
|
|
118
90
|
afterEnter: onAfterEnterHandler,
|
|
119
91
|
afterLeave: onAfterLeaveHandler,
|
|
120
92
|
"data-generic-modal-transition-wrapper": true,
|
|
@@ -122,9 +94,10 @@ const GenericModal = /*#__PURE__*/function () {
|
|
|
122
94
|
leave: styles.animatingLeave,
|
|
123
95
|
as: "div",
|
|
124
96
|
className: classnames(styles.transitionLayer, className)
|
|
125
|
-
}, /*#__PURE__*/React.createElement(
|
|
126
|
-
|
|
97
|
+
}, /*#__PURE__*/React.createElement(FocusOn, {
|
|
98
|
+
focusLock: focusLockDisabled,
|
|
127
99
|
returnFocus: true,
|
|
100
|
+
onEscapeKey: onEscapeKeyHandler,
|
|
128
101
|
// Disabling false positive
|
|
129
102
|
// eslint-disable-next-line jsx-a11y/no-autofocus
|
|
130
103
|
autoFocus: false
|
|
@@ -132,11 +105,9 @@ const GenericModal = /*#__PURE__*/function () {
|
|
|
132
105
|
className: styles.backdropLayer
|
|
133
106
|
}), /*#__PURE__*/React.createElement("div", {
|
|
134
107
|
className: styles.scrollLayer,
|
|
135
|
-
ref:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
onClick: outsideModalClickHandler,
|
|
139
|
-
"data-testid": "".concat(id, "-scrollLayer")
|
|
108
|
+
ref: scrollLayerRef,
|
|
109
|
+
"data-testid": "".concat(id, "-scrollLayer"),
|
|
110
|
+
onClick: outsideModalClickHandler
|
|
140
111
|
}, /*#__PURE__*/React.createElement(ModalContext.Provider, {
|
|
141
112
|
value: {
|
|
142
113
|
labelledByID: labelledByID,
|
|
@@ -147,9 +118,7 @@ const GenericModal = /*#__PURE__*/function () {
|
|
|
147
118
|
className: styles.modalLayer,
|
|
148
119
|
"aria-labelledby": labelledByID,
|
|
149
120
|
"aria-describedby": describedByID,
|
|
150
|
-
ref:
|
|
151
|
-
return setModalLayer(modalLayerRef);
|
|
152
|
-
},
|
|
121
|
+
ref: modalLayerRef,
|
|
153
122
|
"data-testid": id
|
|
154
123
|
}, children))))), document.body);
|
|
155
124
|
};
|
|
@@ -4,8 +4,6 @@ var styles = {
|
|
|
4
4
|
"modalLayer": "GenericModal-module_modalLayer__WfD1U",
|
|
5
5
|
"transitionLayer": "GenericModal-module_transitionLayer__zTH-C",
|
|
6
6
|
"animatingEnter": "GenericModal-module_animatingEnter__P3wuk",
|
|
7
|
-
"animatingLeave": "GenericModal-module_animatingLeave__rNkKX"
|
|
8
|
-
"unscrollable": "GenericModal-module_unscrollable__HjRaW",
|
|
9
|
-
"pseudoScrollbar": "GenericModal-module_pseudoScrollbar__BhRqh"
|
|
7
|
+
"animatingLeave": "GenericModal-module_animatingLeave__rNkKX"
|
|
10
8
|
};
|
|
11
9
|
export { styles as default };
|
|
@@ -19,7 +19,7 @@ const InlineNotification = /*#__PURE__*/function () {
|
|
|
19
19
|
otherProps = __rest(_a, ["isSubtle", "hideCloseIcon", "persistent", "classNameOverride"]);
|
|
20
20
|
return /*#__PURE__*/React.createElement(GenericNotification, __assign({
|
|
21
21
|
style: "inline",
|
|
22
|
-
persistent: persistent
|
|
22
|
+
persistent: persistent || hideCloseIcon,
|
|
23
23
|
classNameOverride: classnames(classNameOverride, [isSubtle && styles.subtle]),
|
|
24
24
|
ref: ref
|
|
25
25
|
}, otherProps));
|
|
@@ -1,77 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import React
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
1
|
+
import { __assign, __rest } from 'tslib';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Item as Item$1, Section } from '@react-stately/collections';
|
|
4
|
+
import 'react-aria';
|
|
5
|
+
import 'classnames';
|
|
6
|
+
import '../../Radio/Radio/Radio.mjs';
|
|
7
|
+
import '../../Radio/RadioField/RadioField.mjs';
|
|
8
|
+
import '../../Radio/RadioGroup/RadioGroup.mjs';
|
|
9
|
+
import '../../Divider/Divider.mjs';
|
|
10
|
+
import '../../Text/Text.mjs';
|
|
11
|
+
import './context/SingleSelectContext.mjs';
|
|
12
|
+
import '@cultureamp/i18n-react-intl';
|
|
13
|
+
import '../../VisuallyHidden/VisuallyHidden.mjs';
|
|
14
|
+
import '@react-aria/i18n';
|
|
15
|
+
import { Select } from './subcomponents/Select/Select.mjs';
|
|
16
|
+
import { ComboBox } from './subcomponents/ComboBox/ComboBox.mjs';
|
|
11
17
|
const SingleSelect = /*#__PURE__*/function () {
|
|
12
|
-
const SingleSelect = function (
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var uniqueId = useId();
|
|
21
|
-
var anchorName = "--trigger-".concat(uniqueId);
|
|
22
|
-
var state = useSelectState({
|
|
23
|
-
items: items
|
|
24
|
-
});
|
|
25
|
-
var handleOnSelectionChange = React.useCallback(function (keys) {
|
|
26
|
-
var key = null;
|
|
27
|
-
if (keys instanceof Set && keys.size > 0) {
|
|
28
|
-
key = Array.from(keys)[0];
|
|
29
|
-
}
|
|
30
|
-
state.setSelectedKey(key);
|
|
31
|
-
if (onSelectionChange) {
|
|
32
|
-
onSelectionChange(key);
|
|
33
|
-
}
|
|
34
|
-
}, [state, onSelectionChange]);
|
|
35
|
-
// Cloning children here to allow users to pass in a custom ListItem or ListSection
|
|
36
|
-
// and still have the SingleSelect handle selection state
|
|
37
|
-
var injectedChildren = useMemo(function () {
|
|
38
|
-
if (! /*#__PURE__*/isValidElement(children)) return null;
|
|
39
|
-
var selectedKeys = state.selectedKey ? new Set([state.selectedKey]) : new Set();
|
|
40
|
-
return /*#__PURE__*/cloneElement(children, {
|
|
41
|
-
selectionMode: 'single',
|
|
42
|
-
selectedKeys: selectedKeys,
|
|
43
|
-
onSelectionChange: handleOnSelectionChange,
|
|
44
|
-
autoFocus: 'first'
|
|
45
|
-
});
|
|
46
|
-
}, [children, handleOnSelectionChange, state.selectedKey]);
|
|
47
|
-
return /*#__PURE__*/React.createElement(SingleSelectContext.Provider, {
|
|
48
|
-
value: {
|
|
49
|
-
isOpen: state.isOpen,
|
|
50
|
-
setOpen: state.setOpen,
|
|
51
|
-
selectedKey: state.selectedKey,
|
|
52
|
-
items: items,
|
|
53
|
-
anchorName: anchorName
|
|
54
|
-
}
|
|
55
|
-
}, /*#__PURE__*/React.createElement(Select
|
|
56
|
-
// TODO: allow user to pass in label
|
|
57
|
-
, __assign({
|
|
58
|
-
"aria-label": 'single-select',
|
|
59
|
-
onSelectionChange: function (key) {
|
|
60
|
-
return handleOnSelectionChange(key != null ? new Set([key]) : new Set());
|
|
61
|
-
},
|
|
62
|
-
placeholder: ""
|
|
63
|
-
}, restProps), /*#__PURE__*/React.createElement(Trigger, {
|
|
64
|
-
buttonRef: buttonRef
|
|
65
|
-
}), state.isOpen && (/*#__PURE__*/React.createElement(Popover, {
|
|
66
|
-
buttonRef: buttonRef,
|
|
67
|
-
popoverRef: popoverRef,
|
|
68
|
-
racPopoverRef: racPopoverRef
|
|
69
|
-
}, injectedChildren))));
|
|
18
|
+
const SingleSelect = function (props) {
|
|
19
|
+
var isComboBox = props.isComboBox,
|
|
20
|
+
children = props.children,
|
|
21
|
+
rest = __rest(props, ["isComboBox", "children"]);
|
|
22
|
+
if (isComboBox) {
|
|
23
|
+
return /*#__PURE__*/React.createElement(ComboBox, __assign({}, rest), children);
|
|
24
|
+
}
|
|
25
|
+
return /*#__PURE__*/React.createElement(Select, __assign({}, rest), children);
|
|
70
26
|
};
|
|
71
|
-
SingleSelect.
|
|
72
|
-
SingleSelect.
|
|
73
|
-
SingleSelect.ListItem = ListItem;
|
|
74
|
-
SingleSelect.ListSection = ListSection;
|
|
27
|
+
SingleSelect.Item = Item;
|
|
28
|
+
SingleSelect.Section = Section;
|
|
75
29
|
return SingleSelect;
|
|
76
30
|
}();
|
|
77
|
-
|
|
31
|
+
const Item = /*#__PURE__*/function () {
|
|
32
|
+
const Item = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
33
|
+
// @ts-expect-error: StatelyItem doesn't know about our internal item props
|
|
34
|
+
return /*#__PURE__*/React.createElement(Item$1, __assign({}, props, {
|
|
35
|
+
ref: ref
|
|
36
|
+
}));
|
|
37
|
+
});
|
|
38
|
+
// @ts-expect-error: doesn't know that the Item can have this static property
|
|
39
|
+
Item.getCollectionNode = Item$1.getCollectionNode;
|
|
40
|
+
Item.displayName = 'SingleSelectItem';
|
|
41
|
+
return Item;
|
|
42
|
+
}();
|
|
43
|
+
export { Item, SingleSelect };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import React, { useRef, useId } from 'react';
|
|
3
|
+
import { useComboBoxState } from '@react-stately/combobox';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { useFilter, useComboBox } from 'react-aria';
|
|
6
|
+
import { FieldMessage } from '../../../../FieldMessage/FieldMessage.mjs';
|
|
7
|
+
import { Label } from '../../../../Label/Label.mjs';
|
|
8
|
+
import { SingleSelectContext } from '../../context/SingleSelectContext.mjs';
|
|
9
|
+
import { ComboBoxTrigger } from '../ComboBoxTrigger/ComboBoxTrigger.mjs';
|
|
10
|
+
import { List } from '../List/List.mjs';
|
|
11
|
+
import { Popover } from '../Popover/Popover.mjs';
|
|
12
|
+
import styles from './ComboBox.module.css.mjs';
|
|
13
|
+
var ComboBox = function (props) {
|
|
14
|
+
var _a;
|
|
15
|
+
var items = props.items,
|
|
16
|
+
children = props.children,
|
|
17
|
+
label = props.label,
|
|
18
|
+
description = props.description,
|
|
19
|
+
labelHidden = props.labelHidden,
|
|
20
|
+
_b = props.labelPosition,
|
|
21
|
+
labelPosition = _b === void 0 ? 'top' : _b,
|
|
22
|
+
isReadOnly = props.isReadOnly,
|
|
23
|
+
isDisabled = props.isDisabled,
|
|
24
|
+
_c = props.size,
|
|
25
|
+
size = _c === void 0 ? 'medium' : _c,
|
|
26
|
+
_d = props.variant,
|
|
27
|
+
variant = _d === void 0 ? 'primary' : _d;
|
|
28
|
+
var contains = useFilter({
|
|
29
|
+
sensitivity: 'base'
|
|
30
|
+
}).contains;
|
|
31
|
+
var state = useComboBoxState(__assign(__assign({}, props), {
|
|
32
|
+
items: items,
|
|
33
|
+
defaultFilter: contains,
|
|
34
|
+
children: children,
|
|
35
|
+
menuTrigger: 'focus'
|
|
36
|
+
}));
|
|
37
|
+
var inputRef = useRef(null);
|
|
38
|
+
var popoverRef = useRef(null);
|
|
39
|
+
var listBoxRef = useRef(null);
|
|
40
|
+
var buttonRef = useRef(null);
|
|
41
|
+
var clearButtonRef = useRef(null);
|
|
42
|
+
var triggerWrapperRef = useRef(null);
|
|
43
|
+
var _e = useComboBox(__assign(__assign({}, props), {
|
|
44
|
+
'aria-label': labelHidden ? label : undefined,
|
|
45
|
+
inputRef: inputRef,
|
|
46
|
+
buttonRef: buttonRef,
|
|
47
|
+
popoverRef: popoverRef,
|
|
48
|
+
listBoxRef: listBoxRef
|
|
49
|
+
}), state),
|
|
50
|
+
labelProps = _e.labelProps,
|
|
51
|
+
descriptionProps = _e.descriptionProps,
|
|
52
|
+
inputProps = _e.inputProps,
|
|
53
|
+
listBoxProps = _e.listBoxProps,
|
|
54
|
+
buttonProps = _e.buttonProps;
|
|
55
|
+
var uniqueId = useId();
|
|
56
|
+
var anchorName = "--trigger-".concat(uniqueId);
|
|
57
|
+
return /*#__PURE__*/React.createElement(SingleSelectContext.Provider, {
|
|
58
|
+
value: {
|
|
59
|
+
anchorName: anchorName,
|
|
60
|
+
state: state,
|
|
61
|
+
isComboBox: true,
|
|
62
|
+
isDisabled: isDisabled !== null && isDisabled !== void 0 ? isDisabled : false,
|
|
63
|
+
isReadOnly: isReadOnly !== null && isReadOnly !== void 0 ? isReadOnly : false,
|
|
64
|
+
secondary: variant === 'secondary',
|
|
65
|
+
size: size,
|
|
66
|
+
fieldLabel: label
|
|
67
|
+
}
|
|
68
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
69
|
+
className: labelPosition === 'top' ? styles.topLabel : styles.sideLabel
|
|
70
|
+
}, !labelHidden && (/*#__PURE__*/React.createElement("div", {
|
|
71
|
+
className: classnames(styles.label, (_a = {}, _a[styles.labelTop] = labelPosition === 'top', _a))
|
|
72
|
+
}, /*#__PURE__*/React.createElement(Label, __assign({}, labelProps), label))), /*#__PURE__*/React.createElement("div", {
|
|
73
|
+
className: styles.comboBoxTrigger
|
|
74
|
+
}, /*#__PURE__*/React.createElement(ComboBoxTrigger, {
|
|
75
|
+
inputProps: inputProps,
|
|
76
|
+
inputRef: inputRef,
|
|
77
|
+
buttonRef: buttonRef,
|
|
78
|
+
buttonProps: buttonProps,
|
|
79
|
+
clearButtonRef: clearButtonRef,
|
|
80
|
+
triggerWrapperRef: triggerWrapperRef
|
|
81
|
+
})), description && (/*#__PURE__*/React.createElement("div", {
|
|
82
|
+
className: styles.description
|
|
83
|
+
}, /*#__PURE__*/React.createElement(FieldMessage, __assign({
|
|
84
|
+
message: description
|
|
85
|
+
}, descriptionProps))))), /*#__PURE__*/React.createElement(Popover, {
|
|
86
|
+
state: state,
|
|
87
|
+
triggerRef: triggerWrapperRef,
|
|
88
|
+
popoverRef: popoverRef,
|
|
89
|
+
clearButtonRef: clearButtonRef
|
|
90
|
+
}, /*#__PURE__*/React.createElement(List, {
|
|
91
|
+
listBoxOptions: listBoxProps,
|
|
92
|
+
state: state,
|
|
93
|
+
listBoxRef: listBoxRef
|
|
94
|
+
})));
|
|
95
|
+
};
|
|
96
|
+
export { ComboBox };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
var styles = {
|
|
2
|
+
"topLabel": "ComboBox-module_topLabel__a2t80",
|
|
3
|
+
"sideLabel": "ComboBox-module_sideLabel__B-jX4",
|
|
4
|
+
"label": "ComboBox-module_label__eTnD9",
|
|
5
|
+
"labelTop": "ComboBox-module_labelTop__h6r-z",
|
|
6
|
+
"comboBoxTrigger": "ComboBox-module_comboBoxTrigger__yvqGb",
|
|
7
|
+
"description": "ComboBox-module_description__MDKJ7"
|
|
8
|
+
};
|
|
9
|
+
export { styles as default };
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { useIntl } from '@cultureamp/i18n-react-intl';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { useButton } from 'react-aria';
|
|
6
|
+
import { Icon } from '../../../../Icon/Icon.mjs';
|
|
7
|
+
import { VisuallyHidden } from '../../../../VisuallyHidden/VisuallyHidden.mjs';
|
|
8
|
+
import { useSingleSelectContext } from '../../context/SingleSelectContext.mjs';
|
|
9
|
+
import styles from './ComboBoxTrigger.module.css.mjs';
|
|
10
|
+
var ClearButton = function (_a) {
|
|
11
|
+
var _b;
|
|
12
|
+
var clearButtonRef = _a.clearButtonRef,
|
|
13
|
+
inputRef = _a.inputRef;
|
|
14
|
+
var _c = useSingleSelectContext(),
|
|
15
|
+
state = _c.state,
|
|
16
|
+
isComboBox = _c.isComboBox,
|
|
17
|
+
fieldLabel = _c.fieldLabel;
|
|
18
|
+
var formatMessage = useIntl().formatMessage;
|
|
19
|
+
var clearButtonAlt = formatMessage({
|
|
20
|
+
id: 'singleSelect.clearButtonAlt',
|
|
21
|
+
defaultMessage: 'Clear {field} selection',
|
|
22
|
+
description: 'Alt text for the clear selection button'
|
|
23
|
+
}, {
|
|
24
|
+
field: fieldLabel
|
|
25
|
+
});
|
|
26
|
+
var buttonProps = useButton({
|
|
27
|
+
onPress: function () {
|
|
28
|
+
var _a;
|
|
29
|
+
if (isComboBox) {
|
|
30
|
+
state.setSelectedKey(null);
|
|
31
|
+
}
|
|
32
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
|
|
33
|
+
}
|
|
34
|
+
}, clearButtonRef).buttonProps;
|
|
35
|
+
return /*#__PURE__*/React.createElement("button", __assign({}, buttonProps, {
|
|
36
|
+
ref: clearButtonRef,
|
|
37
|
+
type: "button",
|
|
38
|
+
className: classnames(styles.clearButton, (_b = {}, _b[styles.hidden] = !state.selectedKey, _b)),
|
|
39
|
+
tabIndex: 0
|
|
40
|
+
}), /*#__PURE__*/React.createElement(Icon, {
|
|
41
|
+
name: "cancel",
|
|
42
|
+
isPresentational: true,
|
|
43
|
+
isFilled: true
|
|
44
|
+
}), /*#__PURE__*/React.createElement(VisuallyHidden, null, clearButtonAlt));
|
|
45
|
+
};
|
|
46
|
+
var ChevronButton = function (props) {
|
|
47
|
+
var _a = useSingleSelectContext(),
|
|
48
|
+
state = _a.state,
|
|
49
|
+
fieldLabel = _a.fieldLabel;
|
|
50
|
+
var formatMessage = useIntl().formatMessage;
|
|
51
|
+
var chevronButton = formatMessage({
|
|
52
|
+
id: 'singleSelect.chevronButton',
|
|
53
|
+
defaultMessage: 'Show suggestions for {field}',
|
|
54
|
+
description: 'Aria label text for the SingleSelect button to open and close suggestions list'
|
|
55
|
+
}, {
|
|
56
|
+
field: fieldLabel
|
|
57
|
+
});
|
|
58
|
+
var buttonProps = useButton(__assign(__assign({}, props), {
|
|
59
|
+
'aria-label': String(chevronButton),
|
|
60
|
+
'aria-labelledby': undefined
|
|
61
|
+
}), props.buttonRef).buttonProps;
|
|
62
|
+
return /*#__PURE__*/React.createElement("button", __assign({
|
|
63
|
+
type: "button"
|
|
64
|
+
}, buttonProps, {
|
|
65
|
+
ref: props.buttonRef,
|
|
66
|
+
className: styles.chevronButton,
|
|
67
|
+
tabIndex: -1
|
|
68
|
+
}), /*#__PURE__*/React.createElement(Icon, {
|
|
69
|
+
isPresentational: true,
|
|
70
|
+
name: state.isOpen ? 'keyboard_arrow_up' : 'keyboard_arrow_down'
|
|
71
|
+
}));
|
|
72
|
+
};
|
|
73
|
+
var ComboBoxTrigger = function (_a) {
|
|
74
|
+
var _b, _c;
|
|
75
|
+
var inputProps = _a.inputProps,
|
|
76
|
+
inputRef = _a.inputRef,
|
|
77
|
+
buttonProps = _a.buttonProps,
|
|
78
|
+
buttonRef = _a.buttonRef,
|
|
79
|
+
triggerWrapperRef = _a.triggerWrapperRef,
|
|
80
|
+
clearButtonRef = _a.clearButtonRef;
|
|
81
|
+
var _d = useSingleSelectContext(),
|
|
82
|
+
anchorName = _d.anchorName,
|
|
83
|
+
isDisabled = _d.isDisabled,
|
|
84
|
+
isReadOnly = _d.isReadOnly,
|
|
85
|
+
secondary = _d.secondary,
|
|
86
|
+
size = _d.size;
|
|
87
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
88
|
+
style: {
|
|
89
|
+
'--anchor-name': anchorName
|
|
90
|
+
},
|
|
91
|
+
ref: triggerWrapperRef,
|
|
92
|
+
className: classnames(styles.trigger, (_b = {}, _b[styles.disabled] = isDisabled, _b[styles.readOnly] = isReadOnly, _b[styles.secondary] = secondary, _b[styles.small] = size === 'small', _b[styles.large] = size === 'large', _b))
|
|
93
|
+
}, /*#__PURE__*/React.createElement("input", __assign({}, inputProps, {
|
|
94
|
+
ref: inputRef,
|
|
95
|
+
className: classnames(styles.input, (_c = {}, _c[styles.smallText] = size === 'small', _c))
|
|
96
|
+
})), !isDisabled && !isReadOnly && (/*#__PURE__*/React.createElement(ClearButton, {
|
|
97
|
+
clearButtonRef: clearButtonRef,
|
|
98
|
+
inputRef: inputRef
|
|
99
|
+
})), !isReadOnly && /*#__PURE__*/React.createElement(ChevronButton, __assign({}, buttonProps, {
|
|
100
|
+
buttonRef: buttonRef
|
|
101
|
+
}))));
|
|
102
|
+
};
|
|
103
|
+
export { ComboBoxTrigger };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var styles = {
|
|
2
|
+
"trigger": "ComboBoxTrigger-module_trigger__p6pcn",
|
|
3
|
+
"smallText": "ComboBoxTrigger-module_smallText__Vj2Ya",
|
|
4
|
+
"secondary": "ComboBoxTrigger-module_secondary__TvNTK",
|
|
5
|
+
"disabled": "ComboBoxTrigger-module_disabled__BkFJy",
|
|
6
|
+
"readOnly": "ComboBoxTrigger-module_readOnly__g6-fB",
|
|
7
|
+
"input": "ComboBoxTrigger-module_input__TkoLg",
|
|
8
|
+
"small": "ComboBoxTrigger-module_small__-225Z",
|
|
9
|
+
"large": "ComboBoxTrigger-module_large__kj1vw",
|
|
10
|
+
"clearButton": "ComboBoxTrigger-module_clearButton__PlsuZ",
|
|
11
|
+
"chevronButton": "ComboBoxTrigger-module_chevronButton__rzv2v",
|
|
12
|
+
"hidden": "ComboBoxTrigger-module_hidden__zC13w"
|
|
13
|
+
};
|
|
14
|
+
export { styles as default };
|
|
@@ -1,18 +1,41 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { __assign } from 'tslib';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import { useListBox } from 'react-aria';
|
|
4
|
+
import { ListItem } from '../ListItem/ListItem.mjs';
|
|
5
|
+
import { ListSection } from '../ListSection/ListSection.mjs';
|
|
5
6
|
import styles from './List.module.css.mjs';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
7
|
+
var List = function (_a) {
|
|
8
|
+
var state = _a.state,
|
|
9
|
+
listBoxOptions = _a.listBoxOptions,
|
|
10
|
+
listBoxRef = _a.listBoxRef;
|
|
11
|
+
var listBoxProps = useListBox(__assign(__assign({}, listBoxOptions), {
|
|
12
|
+
autoFocus: 'first'
|
|
13
|
+
}), state, listBoxRef).listBoxProps;
|
|
14
|
+
var renderNode = function (node) {
|
|
15
|
+
if (node.type === 'section') {
|
|
16
|
+
return node.rendered ? (/*#__PURE__*/React.createElement(ListSection, {
|
|
17
|
+
key: String(node.key),
|
|
18
|
+
section: node,
|
|
19
|
+
state: state
|
|
20
|
+
})) : null;
|
|
21
|
+
} else {
|
|
22
|
+
var _a = node.props,
|
|
23
|
+
selectedIcon = _a.selectedIcon,
|
|
24
|
+
selectedPosition = _a.selectedPosition,
|
|
25
|
+
className = _a.className;
|
|
26
|
+
return /*#__PURE__*/React.createElement(ListItem, {
|
|
27
|
+
key: String(node.key),
|
|
28
|
+
item: node,
|
|
29
|
+
state: state,
|
|
30
|
+
selectedIcon: selectedIcon,
|
|
31
|
+
selectedPosition: selectedPosition,
|
|
32
|
+
className: className
|
|
33
|
+
});
|
|
34
|
+
}
|
|
14
35
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
36
|
+
return /*#__PURE__*/React.createElement("ul", __assign({}, listBoxProps, {
|
|
37
|
+
ref: listBoxRef,
|
|
38
|
+
className: styles.list
|
|
39
|
+
}), Array.from(state.collection).map(renderNode));
|
|
40
|
+
};
|
|
18
41
|
export { List };
|