@heymantle/litho 0.0.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/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/cjs/components/ActionList.js +267 -0
- package/dist/cjs/components/AnnouncementBar.js +73 -0
- package/dist/cjs/components/AppProvider.js +245 -0
- package/dist/cjs/components/Autocomplete.js +351 -0
- package/dist/cjs/components/Badge.js +234 -0
- package/dist/cjs/components/Banner.js +264 -0
- package/dist/cjs/components/Box.js +247 -0
- package/dist/cjs/components/Button.js +1018 -0
- package/dist/cjs/components/ButtonGroup.js +196 -0
- package/dist/cjs/components/Card.js +593 -0
- package/dist/cjs/components/Checkbox.js +175 -0
- package/dist/cjs/components/ChoiceList.js +160 -0
- package/dist/cjs/components/Collapsible.js +42 -0
- package/dist/cjs/components/ColorField.js +159 -0
- package/dist/cjs/components/ContextualSaveBar.js +53 -0
- package/dist/cjs/components/DatePicker.js +547 -0
- package/dist/cjs/components/Divider.js +50 -0
- package/dist/cjs/components/DropZone.js +547 -0
- package/dist/cjs/components/EmptyState.js +111 -0
- package/dist/cjs/components/Filters.js +874 -0
- package/dist/cjs/components/FooterHelp.js +48 -0
- package/dist/cjs/components/Form.js +44 -0
- package/dist/cjs/components/Frame.js +386 -0
- package/dist/cjs/components/FrameSaveBar.js +239 -0
- package/dist/cjs/components/Grid.js +151 -0
- package/dist/cjs/components/HorizontalStack.js +180 -0
- package/dist/cjs/components/Icon.js +346 -0
- package/dist/cjs/components/Image.js +191 -0
- package/dist/cjs/components/InlineError.js +57 -0
- package/dist/cjs/components/Label.js +78 -0
- package/dist/cjs/components/Layout.js +228 -0
- package/dist/cjs/components/LayoutSection.js +133 -0
- package/dist/cjs/components/Link.js +128 -0
- package/dist/cjs/components/List.js +69 -0
- package/dist/cjs/components/Listbox.js +211 -0
- package/dist/cjs/components/Loading.js +103 -0
- package/dist/cjs/components/Modal.js +449 -0
- package/dist/cjs/components/Navigation.js +331 -0
- package/dist/cjs/components/Page.js +529 -0
- package/dist/cjs/components/Pagination.js +109 -0
- package/dist/cjs/components/Pane.js +128 -0
- package/dist/cjs/components/Popover.js +365 -0
- package/dist/cjs/components/PopoverManager.js +34 -0
- package/dist/cjs/components/ProgressBar.js +124 -0
- package/dist/cjs/components/RadioButton.js +172 -0
- package/dist/cjs/components/RadioButtonCard.js +193 -0
- package/dist/cjs/components/RangeSlider.js +235 -0
- package/dist/cjs/components/ResourceList.js +105 -0
- package/dist/cjs/components/Select.js +300 -0
- package/dist/cjs/components/SkeletonText.js +130 -0
- package/dist/cjs/components/Spinner.js +72 -0
- package/dist/cjs/components/Table.js +1184 -0
- package/dist/cjs/components/Tabs.js +421 -0
- package/dist/cjs/components/Tag.js +165 -0
- package/dist/cjs/components/Text.js +274 -0
- package/dist/cjs/components/TextField.js +584 -0
- package/dist/cjs/components/Thumbnail.js +73 -0
- package/dist/cjs/components/TimePicker.js +23 -0
- package/dist/cjs/components/Tip.js +220 -0
- package/dist/cjs/components/Tooltip.js +431 -0
- package/dist/cjs/components/TopBar.js +210 -0
- package/dist/cjs/components/VerticalStack.js +161 -0
- package/dist/cjs/index.js +308 -0
- package/dist/cjs/styles/Table.js +591 -0
- package/dist/cjs/utilities/dates.js +339 -0
- package/dist/cjs/utilities/useIndexResourceState.js +175 -0
- package/dist/cjs/utilities/useMounted.js +67 -0
- package/dist/cjs/utilities/useTableScrollState.js +142 -0
- package/dist/esm/components/ActionList.js +216 -0
- package/dist/esm/components/AnnouncementBar.js +63 -0
- package/dist/esm/components/AppProvider.js +185 -0
- package/dist/esm/components/Autocomplete.js +300 -0
- package/dist/esm/components/Badge.js +225 -0
- package/dist/esm/components/Banner.js +254 -0
- package/dist/esm/components/Box.js +238 -0
- package/dist/esm/components/Button.js +967 -0
- package/dist/esm/components/ButtonGroup.js +137 -0
- package/dist/esm/components/Card.js +537 -0
- package/dist/esm/components/Checkbox.js +165 -0
- package/dist/esm/components/ChoiceList.js +145 -0
- package/dist/esm/components/Collapsible.js +32 -0
- package/dist/esm/components/ColorField.js +149 -0
- package/dist/esm/components/ContextualSaveBar.js +43 -0
- package/dist/esm/components/DatePicker.js +532 -0
- package/dist/esm/components/Divider.js +41 -0
- package/dist/esm/components/DropZone.js +537 -0
- package/dist/esm/components/EmptyState.js +101 -0
- package/dist/esm/components/Filters.js +823 -0
- package/dist/esm/components/FooterHelp.js +38 -0
- package/dist/esm/components/Form.js +35 -0
- package/dist/esm/components/Frame.js +376 -0
- package/dist/esm/components/FrameSaveBar.js +229 -0
- package/dist/esm/components/Grid.js +142 -0
- package/dist/esm/components/HorizontalStack.js +171 -0
- package/dist/esm/components/Icon.js +296 -0
- package/dist/esm/components/Image.js +141 -0
- package/dist/esm/components/InlineError.js +43 -0
- package/dist/esm/components/Label.js +63 -0
- package/dist/esm/components/Layout.js +164 -0
- package/dist/esm/components/LayoutSection.js +82 -0
- package/dist/esm/components/Link.js +119 -0
- package/dist/esm/components/List.js +61 -0
- package/dist/esm/components/Listbox.js +201 -0
- package/dist/esm/components/Loading.js +93 -0
- package/dist/esm/components/Modal.js +390 -0
- package/dist/esm/components/Navigation.js +321 -0
- package/dist/esm/components/Page.js +473 -0
- package/dist/esm/components/Pagination.js +99 -0
- package/dist/esm/components/Pane.js +118 -0
- package/dist/esm/components/Popover.js +350 -0
- package/dist/esm/components/PopoverManager.js +24 -0
- package/dist/esm/components/ProgressBar.js +114 -0
- package/dist/esm/components/RadioButton.js +157 -0
- package/dist/esm/components/RadioButtonCard.js +178 -0
- package/dist/esm/components/RangeSlider.js +225 -0
- package/dist/esm/components/ResourceList.js +95 -0
- package/dist/esm/components/Select.js +285 -0
- package/dist/esm/components/SkeletonText.js +120 -0
- package/dist/esm/components/Spinner.js +63 -0
- package/dist/esm/components/Table.js +1129 -0
- package/dist/esm/components/Tabs.js +366 -0
- package/dist/esm/components/Tag.js +151 -0
- package/dist/esm/components/Text.js +265 -0
- package/dist/esm/components/TextField.js +533 -0
- package/dist/esm/components/Thumbnail.js +63 -0
- package/dist/esm/components/TimePicker.js +13 -0
- package/dist/esm/components/Tip.js +169 -0
- package/dist/esm/components/Tooltip.js +380 -0
- package/dist/esm/components/TopBar.js +200 -0
- package/dist/esm/components/VerticalStack.js +152 -0
- package/dist/esm/index.js +61 -0
- package/dist/esm/styles/Table.js +581 -0
- package/dist/esm/utilities/dates.js +289 -0
- package/dist/esm/utilities/useIndexResourceState.js +158 -0
- package/dist/esm/utilities/useMounted.js +57 -0
- package/dist/esm/utilities/useTableScrollState.js +132 -0
- package/index.css +1137 -0
- package/package.json +53 -0
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
function _export(target, all) {
|
|
7
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
_export(exports, {
|
|
13
|
+
get DarkModeContext () {
|
|
14
|
+
return DarkModeContext;
|
|
15
|
+
},
|
|
16
|
+
get FormContext () {
|
|
17
|
+
return FormContext;
|
|
18
|
+
},
|
|
19
|
+
get FrameContext () {
|
|
20
|
+
return FrameContext;
|
|
21
|
+
},
|
|
22
|
+
get default () {
|
|
23
|
+
return _default;
|
|
24
|
+
},
|
|
25
|
+
get useDarkMode () {
|
|
26
|
+
return useDarkMode;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
var _jsxruntime = require("react/jsx-runtime");
|
|
30
|
+
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
31
|
+
function _array_like_to_array(arr, len) {
|
|
32
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
33
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
34
|
+
return arr2;
|
|
35
|
+
}
|
|
36
|
+
function _array_with_holes(arr) {
|
|
37
|
+
if (Array.isArray(arr)) return arr;
|
|
38
|
+
}
|
|
39
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
40
|
+
if (typeof WeakMap !== "function") return null;
|
|
41
|
+
var cacheBabelInterop = new WeakMap();
|
|
42
|
+
var cacheNodeInterop = new WeakMap();
|
|
43
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
44
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
45
|
+
})(nodeInterop);
|
|
46
|
+
}
|
|
47
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
48
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
49
|
+
return obj;
|
|
50
|
+
}
|
|
51
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
52
|
+
return {
|
|
53
|
+
default: obj
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
57
|
+
if (cache && cache.has(obj)) {
|
|
58
|
+
return cache.get(obj);
|
|
59
|
+
}
|
|
60
|
+
var newObj = {
|
|
61
|
+
__proto__: null
|
|
62
|
+
};
|
|
63
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
64
|
+
for(var key in obj){
|
|
65
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
66
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
67
|
+
if (desc && (desc.get || desc.set)) {
|
|
68
|
+
Object.defineProperty(newObj, key, desc);
|
|
69
|
+
} else {
|
|
70
|
+
newObj[key] = obj[key];
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
newObj.default = obj;
|
|
75
|
+
if (cache) {
|
|
76
|
+
cache.set(obj, newObj);
|
|
77
|
+
}
|
|
78
|
+
return newObj;
|
|
79
|
+
}
|
|
80
|
+
function _iterable_to_array_limit(arr, i) {
|
|
81
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
82
|
+
if (_i == null) return;
|
|
83
|
+
var _arr = [];
|
|
84
|
+
var _n = true;
|
|
85
|
+
var _d = false;
|
|
86
|
+
var _s, _e;
|
|
87
|
+
try {
|
|
88
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
89
|
+
_arr.push(_s.value);
|
|
90
|
+
if (i && _arr.length === i) break;
|
|
91
|
+
}
|
|
92
|
+
} catch (err) {
|
|
93
|
+
_d = true;
|
|
94
|
+
_e = err;
|
|
95
|
+
} finally{
|
|
96
|
+
try {
|
|
97
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
98
|
+
} finally{
|
|
99
|
+
if (_d) throw _e;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return _arr;
|
|
103
|
+
}
|
|
104
|
+
function _non_iterable_rest() {
|
|
105
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
106
|
+
}
|
|
107
|
+
function _sliced_to_array(arr, i) {
|
|
108
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
109
|
+
}
|
|
110
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
111
|
+
if (!o) return;
|
|
112
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
113
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
114
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
115
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
116
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
117
|
+
}
|
|
118
|
+
var DarkModeContext = /*#__PURE__*/ (0, _react.createContext)(null);
|
|
119
|
+
var useDarkMode = function() {
|
|
120
|
+
return (0, _react.useContext)(DarkModeContext);
|
|
121
|
+
};
|
|
122
|
+
var FrameContext = /*#__PURE__*/ (0, _react.createContext)({
|
|
123
|
+
embedded: false,
|
|
124
|
+
paneIsOpen: false,
|
|
125
|
+
setPaneIsOpen: function() {},
|
|
126
|
+
modalIsOpen: false,
|
|
127
|
+
setModalIsOpen: function() {},
|
|
128
|
+
showMobileNavigation: false,
|
|
129
|
+
contentIsInIframe: false,
|
|
130
|
+
contentIsFullPage: false,
|
|
131
|
+
setShowMobileNavigation: function() {},
|
|
132
|
+
setContentIsInIframe: function() {},
|
|
133
|
+
setContentIsFullPage: function() {}
|
|
134
|
+
});
|
|
135
|
+
var FormContext = /*#__PURE__*/ (0, _react.createContext)(null);
|
|
136
|
+
var screenSizes = typeof window !== "undefined" ? {
|
|
137
|
+
sm: parseInt(getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-sm"), 10),
|
|
138
|
+
md: parseInt(getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-md"), 10),
|
|
139
|
+
lg: parseInt(getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-lg"), 10),
|
|
140
|
+
xl: parseInt(getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-xl"), 10),
|
|
141
|
+
"2xl": parseInt(getComputedStyle(document.documentElement).getPropertyValue("--breakpoint-2xl"), 10)
|
|
142
|
+
} : {};
|
|
143
|
+
/**
|
|
144
|
+
* Provider component for managing global application state.
|
|
145
|
+
* @param {Object} props
|
|
146
|
+
* @param {React.ReactNode} props.children - The child components.
|
|
147
|
+
* @param {boolean} props.embedded - Whether the app is embedded.
|
|
148
|
+
* @param {boolean} props.darkModeAvailable - Whether dark mode is enabled.
|
|
149
|
+
* @param {string} props.darkModeStorageKey - Local storage key for dark mode preference.
|
|
150
|
+
* @param {(darkMode: boolean) => void} props.onDarkModeChange - Callback when dark mode changes.
|
|
151
|
+
* @returns {JSX.Element}
|
|
152
|
+
*/ function AppProvider(param) {
|
|
153
|
+
var children = param.children, _param_embedded = param.embedded, embedded = _param_embedded === void 0 ? false : _param_embedded, tmp = param.darkModeAvailable, _darkModeAvailable = tmp === void 0 ? false : tmp, darkModeStorageKey = param.darkModeStorageKey, onDarkModeChange = param.onDarkModeChange;
|
|
154
|
+
var _useState = _sliced_to_array((0, _react.useState)(false), 2), showMobileNavigation = _useState[0], setShowMobileNavigation = _useState[1];
|
|
155
|
+
var _useState1 = _sliced_to_array((0, _react.useState)(_darkModeAvailable), 2), darkModeAvailable = _useState1[0], setDarkModeAvailable = _useState1[1];
|
|
156
|
+
var _useState2 = _sliced_to_array((0, _react.useState)(false), 2), contentIsInIframe = _useState2[0], setContentIsInIframe = _useState2[1];
|
|
157
|
+
var _useState3 = _sliced_to_array((0, _react.useState)(false), 2), contentIsFullPage = _useState3[0], setContentIsFullPage = _useState3[1];
|
|
158
|
+
var _useState4 = _sliced_to_array((0, _react.useState)(false), 2), modalIsOpen = _useState4[0], setModalIsOpen = _useState4[1];
|
|
159
|
+
var _useState5 = _sliced_to_array((0, _react.useState)(false), 2), paneIsOpen = _useState5[0], setPaneIsOpen = _useState5[1];
|
|
160
|
+
var _useState6 = _sliced_to_array((0, _react.useState)(false), 2), showGlobalContextualSaveBar = _useState6[0], setShowGlobalContextualSaveBar = _useState6[1];
|
|
161
|
+
var _useState7 = _sliced_to_array((0, _react.useState)(null), 2), message = _useState7[0], setMessage = _useState7[1];
|
|
162
|
+
var _useState8 = _sliced_to_array((0, _react.useState)(null), 2), saveAction = _useState8[0], setSaveAction = _useState8[1];
|
|
163
|
+
var _useState9 = _sliced_to_array((0, _react.useState)(null), 2), discardAction = _useState9[0], setDiscardAction = _useState9[1];
|
|
164
|
+
var _useState10 = _sliced_to_array((0, _react.useState)(false), 2), darkMode = _useState10[0], setDarkMode = _useState10[1];
|
|
165
|
+
var _useState11 = _sliced_to_array((0, _react.useState)(false), 2), isClient = _useState11[0], setIsClient = _useState11[1];
|
|
166
|
+
(0, _react.useEffect)(function() {
|
|
167
|
+
setIsClient(true);
|
|
168
|
+
if (darkModeAvailable) {
|
|
169
|
+
var storedPreference = localStorage.getItem(darkModeStorageKey);
|
|
170
|
+
if (storedPreference !== null) {
|
|
171
|
+
setDarkMode(JSON.parse(storedPreference));
|
|
172
|
+
} else {
|
|
173
|
+
setDarkMode(window.matchMedia("(prefers-color-scheme: dark)").matches);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}, [
|
|
177
|
+
darkModeAvailable,
|
|
178
|
+
darkModeStorageKey
|
|
179
|
+
]);
|
|
180
|
+
(0, _react.useEffect)(function() {
|
|
181
|
+
if (!darkModeAvailable || !isClient) return;
|
|
182
|
+
if (darkMode) {
|
|
183
|
+
document.documentElement.setAttribute("data-theme", "dark");
|
|
184
|
+
} else {
|
|
185
|
+
document.documentElement.removeAttribute("data-theme");
|
|
186
|
+
}
|
|
187
|
+
if (onDarkModeChange) {
|
|
188
|
+
onDarkModeChange(darkMode);
|
|
189
|
+
}
|
|
190
|
+
}, [
|
|
191
|
+
darkMode,
|
|
192
|
+
onDarkModeChange,
|
|
193
|
+
darkModeAvailable,
|
|
194
|
+
isClient
|
|
195
|
+
]);
|
|
196
|
+
var toggleDarkMode = function() {
|
|
197
|
+
return setDarkMode(function(prevMode) {
|
|
198
|
+
if (!darkModeAvailable) return false;
|
|
199
|
+
var newMode = !prevMode;
|
|
200
|
+
localStorage.setItem(darkModeStorageKey, JSON.stringify(newMode));
|
|
201
|
+
return newMode;
|
|
202
|
+
});
|
|
203
|
+
};
|
|
204
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(DarkModeContext.Provider, {
|
|
205
|
+
value: {
|
|
206
|
+
darkModeAvailable: darkModeAvailable,
|
|
207
|
+
darkMode: darkMode,
|
|
208
|
+
toggleDarkMode: toggleDarkMode,
|
|
209
|
+
setDarkModeAvailable: setDarkModeAvailable
|
|
210
|
+
},
|
|
211
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(FrameContext.Provider, {
|
|
212
|
+
value: {
|
|
213
|
+
embedded: embedded,
|
|
214
|
+
contentIsInIframe: contentIsInIframe,
|
|
215
|
+
setContentIsInIframe: setContentIsInIframe,
|
|
216
|
+
showMobileNavigation: showMobileNavigation,
|
|
217
|
+
setShowMobileNavigation: setShowMobileNavigation,
|
|
218
|
+
contentIsFullPage: contentIsFullPage,
|
|
219
|
+
setContentIsFullPage: setContentIsFullPage,
|
|
220
|
+
modalIsOpen: modalIsOpen,
|
|
221
|
+
setModalIsOpen: setModalIsOpen,
|
|
222
|
+
paneIsOpen: paneIsOpen,
|
|
223
|
+
setPaneIsOpen: setPaneIsOpen,
|
|
224
|
+
screenSizes: screenSizes
|
|
225
|
+
},
|
|
226
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(FormContext.Provider, {
|
|
227
|
+
value: {
|
|
228
|
+
showGlobalContextualSaveBar: showGlobalContextualSaveBar,
|
|
229
|
+
setShowGlobalContextualSaveBar: setShowGlobalContextualSaveBar,
|
|
230
|
+
message: message,
|
|
231
|
+
setMessage: setMessage,
|
|
232
|
+
saveAction: saveAction,
|
|
233
|
+
setSaveAction: setSaveAction,
|
|
234
|
+
discardAction: discardAction,
|
|
235
|
+
setDiscardAction: setDiscardAction
|
|
236
|
+
},
|
|
237
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
238
|
+
className: "app-wrapper ".concat(embedded ? "@container" : ""),
|
|
239
|
+
children: children
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
var _default = AppProvider;
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function() {
|
|
9
|
+
return _default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _jsxruntime = require("react/jsx-runtime");
|
|
13
|
+
var _react = /*#__PURE__*/ _interop_require_wildcard(require("react"));
|
|
14
|
+
var _tailwindvariants = require("tailwind-variants");
|
|
15
|
+
var _index = require("../index");
|
|
16
|
+
var _polarisicons = require("@shopify/polaris-icons");
|
|
17
|
+
function _array_like_to_array(arr, len) {
|
|
18
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
19
|
+
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
20
|
+
return arr2;
|
|
21
|
+
}
|
|
22
|
+
function _array_with_holes(arr) {
|
|
23
|
+
if (Array.isArray(arr)) return arr;
|
|
24
|
+
}
|
|
25
|
+
function _array_without_holes(arr) {
|
|
26
|
+
if (Array.isArray(arr)) return _array_like_to_array(arr);
|
|
27
|
+
}
|
|
28
|
+
function _define_property(obj, key, value) {
|
|
29
|
+
if (key in obj) {
|
|
30
|
+
Object.defineProperty(obj, key, {
|
|
31
|
+
value: value,
|
|
32
|
+
enumerable: true,
|
|
33
|
+
configurable: true,
|
|
34
|
+
writable: true
|
|
35
|
+
});
|
|
36
|
+
} else {
|
|
37
|
+
obj[key] = value;
|
|
38
|
+
}
|
|
39
|
+
return obj;
|
|
40
|
+
}
|
|
41
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
42
|
+
if (typeof WeakMap !== "function") return null;
|
|
43
|
+
var cacheBabelInterop = new WeakMap();
|
|
44
|
+
var cacheNodeInterop = new WeakMap();
|
|
45
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
46
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
47
|
+
})(nodeInterop);
|
|
48
|
+
}
|
|
49
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
50
|
+
if (!nodeInterop && obj && obj.__esModule) {
|
|
51
|
+
return obj;
|
|
52
|
+
}
|
|
53
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
|
|
54
|
+
return {
|
|
55
|
+
default: obj
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
59
|
+
if (cache && cache.has(obj)) {
|
|
60
|
+
return cache.get(obj);
|
|
61
|
+
}
|
|
62
|
+
var newObj = {
|
|
63
|
+
__proto__: null
|
|
64
|
+
};
|
|
65
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
66
|
+
for(var key in obj){
|
|
67
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
68
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
69
|
+
if (desc && (desc.get || desc.set)) {
|
|
70
|
+
Object.defineProperty(newObj, key, desc);
|
|
71
|
+
} else {
|
|
72
|
+
newObj[key] = obj[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
newObj.default = obj;
|
|
77
|
+
if (cache) {
|
|
78
|
+
cache.set(obj, newObj);
|
|
79
|
+
}
|
|
80
|
+
return newObj;
|
|
81
|
+
}
|
|
82
|
+
function _iterable_to_array(iter) {
|
|
83
|
+
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
|
84
|
+
}
|
|
85
|
+
function _iterable_to_array_limit(arr, i) {
|
|
86
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
87
|
+
if (_i == null) return;
|
|
88
|
+
var _arr = [];
|
|
89
|
+
var _n = true;
|
|
90
|
+
var _d = false;
|
|
91
|
+
var _s, _e;
|
|
92
|
+
try {
|
|
93
|
+
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
94
|
+
_arr.push(_s.value);
|
|
95
|
+
if (i && _arr.length === i) break;
|
|
96
|
+
}
|
|
97
|
+
} catch (err) {
|
|
98
|
+
_d = true;
|
|
99
|
+
_e = err;
|
|
100
|
+
} finally{
|
|
101
|
+
try {
|
|
102
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
103
|
+
} finally{
|
|
104
|
+
if (_d) throw _e;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return _arr;
|
|
108
|
+
}
|
|
109
|
+
function _non_iterable_rest() {
|
|
110
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
111
|
+
}
|
|
112
|
+
function _non_iterable_spread() {
|
|
113
|
+
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
114
|
+
}
|
|
115
|
+
function _object_spread(target) {
|
|
116
|
+
for(var i = 1; i < arguments.length; i++){
|
|
117
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
118
|
+
var ownKeys = Object.keys(source);
|
|
119
|
+
if (typeof Object.getOwnPropertySymbols === "function") {
|
|
120
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
121
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
124
|
+
ownKeys.forEach(function(key) {
|
|
125
|
+
_define_property(target, key, source[key]);
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
return target;
|
|
129
|
+
}
|
|
130
|
+
function ownKeys(object, enumerableOnly) {
|
|
131
|
+
var keys = Object.keys(object);
|
|
132
|
+
if (Object.getOwnPropertySymbols) {
|
|
133
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
134
|
+
if (enumerableOnly) {
|
|
135
|
+
symbols = symbols.filter(function(sym) {
|
|
136
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
keys.push.apply(keys, symbols);
|
|
140
|
+
}
|
|
141
|
+
return keys;
|
|
142
|
+
}
|
|
143
|
+
function _object_spread_props(target, source) {
|
|
144
|
+
source = source != null ? source : {};
|
|
145
|
+
if (Object.getOwnPropertyDescriptors) {
|
|
146
|
+
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
|
147
|
+
} else {
|
|
148
|
+
ownKeys(Object(source)).forEach(function(key) {
|
|
149
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
return target;
|
|
153
|
+
}
|
|
154
|
+
function _sliced_to_array(arr, i) {
|
|
155
|
+
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
156
|
+
}
|
|
157
|
+
function _to_consumable_array(arr) {
|
|
158
|
+
return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
|
|
159
|
+
}
|
|
160
|
+
function _unsupported_iterable_to_array(o, minLen) {
|
|
161
|
+
if (!o) return;
|
|
162
|
+
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
163
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
164
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
165
|
+
if (n === "Map" || n === "Set") return Array.from(n);
|
|
166
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
167
|
+
}
|
|
168
|
+
var styles = (0, _tailwindvariants.tv)({
|
|
169
|
+
base: "Litho-Autocomplete flex flex-col"
|
|
170
|
+
});
|
|
171
|
+
function attachPropToTextField(children, prop) {
|
|
172
|
+
return _react.default.Children.map(children, function(child) {
|
|
173
|
+
if (/*#__PURE__*/ (0, _react.isValidElement)(child)) {
|
|
174
|
+
var _child_type, _child_props;
|
|
175
|
+
if (((_child_type = child.type) === null || _child_type === void 0 ? void 0 : _child_type.displayName) === "Autocomplete.TextField") {
|
|
176
|
+
return /*#__PURE__*/ (0, _react.cloneElement)(child, prop);
|
|
177
|
+
}
|
|
178
|
+
if ((_child_props = child.props) === null || _child_props === void 0 ? void 0 : _child_props.children) {
|
|
179
|
+
return /*#__PURE__*/ (0, _react.cloneElement)(child, {
|
|
180
|
+
children: attachPropToTextField(child.props.children, prop)
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return child;
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Autocomplete component that provides a flexible dropdown menu with search and selection capabilities.
|
|
189
|
+
*
|
|
190
|
+
* @component
|
|
191
|
+
* @param {Object} props - The props for the Autocomplete component.
|
|
192
|
+
* @param {Array<Object>} props.options - The options to display in the dropdown. Each option should have a `label` and a `value`.
|
|
193
|
+
* @param {Array<string>} props.selected - The currently selected option values.
|
|
194
|
+
* @param {"below"|"above"} [props.preferredPosition="below"] - The preferred position of the dropdown relative to the activator.
|
|
195
|
+
* @param {"left"|"center"|"right"} [props.preferredAlignment="left"] - The preferred alignment of the dropdown.
|
|
196
|
+
* @param {boolean} [props.allowMultiple=false] - Whether multiple options can be selected.
|
|
197
|
+
* @param {boolean} [props.loading=false] - Whether to show a loading spinner in the dropdown.
|
|
198
|
+
* @param {Object} [props.emptyState] - The content to display when there are no options.
|
|
199
|
+
* @param {React.ReactNode} [props.emptyState.icon] - An optional icon to display in the empty state.
|
|
200
|
+
* @param {function(Array<string>)} props.onSelect - Callback fired when the selection changes. Receives the new selected values.
|
|
201
|
+
* @param {React.ReactNode} props.textField - The activator for the dropdown, typically a `TextField` component.
|
|
202
|
+
* @param {string} [props.className] - Additional class names to apply to the component.
|
|
203
|
+
* @param {function} [props.onClose] - Callback fired when the dropdown closes.
|
|
204
|
+
* @param {number} [props.zIndexOverride] - Custom z-index for the dropdown.
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* <Autocomplete
|
|
208
|
+
* options={[{ label: "Option 1", value: "1" }, { label: "Option 2", value: "2" }]}
|
|
209
|
+
* selected={["1"]}
|
|
210
|
+
* allowMultiple
|
|
211
|
+
* onSelect={(selected) => console.log(selected)}
|
|
212
|
+
* textField={<Autocomplete.TextField placeholder="Search..." />}
|
|
213
|
+
* />
|
|
214
|
+
*/ function Autocomplete() {
|
|
215
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
216
|
+
var options = props.options, selected = props.selected, _props_preferredPosition = props.preferredPosition, preferredPosition = _props_preferredPosition === void 0 ? "below" : _props_preferredPosition, _props_preferredAlignment = props.preferredAlignment, preferredAlignment = _props_preferredAlignment === void 0 ? "left" : _props_preferredAlignment, allowMultiple = props.allowMultiple, loading = props.loading, emptyState = props.emptyState, onSelect = props.onSelect, textField = props.textField, className = props.className, zIndexOverride = props.zIndexOverride;
|
|
217
|
+
var classes = styles();
|
|
218
|
+
var _useState = _sliced_to_array((0, _react.useState)(false), 2), showOptionsPopover = _useState[0], setShowOptionsPopover = _useState[1];
|
|
219
|
+
var onTextFieldFocus = function() {
|
|
220
|
+
if (!showOptionsPopover) {
|
|
221
|
+
setShowOptionsPopover(true);
|
|
222
|
+
}
|
|
223
|
+
};
|
|
224
|
+
var showEmptyState = options.length === 0 && !!(emptyState === null || emptyState === void 0 ? void 0 : emptyState.content);
|
|
225
|
+
var OptionItem = function(param) {
|
|
226
|
+
var option = param.option, allowMultiple = param.allowMultiple, selected = param.selected, onSelect = param.onSelect, setShowOptionsPopover = param.setShowOptionsPopover;
|
|
227
|
+
var isChecked = selected.includes(option.value);
|
|
228
|
+
if (allowMultiple) {
|
|
229
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Checkbox, {
|
|
230
|
+
label: option.label,
|
|
231
|
+
checked: isChecked,
|
|
232
|
+
onChange: function() {
|
|
233
|
+
onSelect(isChecked ? selected.filter(function(v) {
|
|
234
|
+
return v !== option.value;
|
|
235
|
+
}) : _to_consumable_array(selected).concat([
|
|
236
|
+
option.value
|
|
237
|
+
]));
|
|
238
|
+
},
|
|
239
|
+
className: "px-2 py-1.5 cursor-pointer rounded-md hover-dark"
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
243
|
+
className: "flex py-1.5 px-3 cursor-pointer rounded-md hover-dark",
|
|
244
|
+
onClick: function() {
|
|
245
|
+
onSelect([
|
|
246
|
+
option.value
|
|
247
|
+
]);
|
|
248
|
+
setShowOptionsPopover && setShowOptionsPopover(false);
|
|
249
|
+
},
|
|
250
|
+
children: option.label
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
254
|
+
className: "".concat(classes).concat(className ? " ".concat(className) : ""),
|
|
255
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Popover, {
|
|
256
|
+
active: showOptionsPopover,
|
|
257
|
+
preferredPosition: preferredPosition,
|
|
258
|
+
preferredAlignment: preferredAlignment,
|
|
259
|
+
activator: attachPropToTextField(textField, {
|
|
260
|
+
onTextFieldFocus: onTextFieldFocus
|
|
261
|
+
}),
|
|
262
|
+
activatorDisplayType: "block",
|
|
263
|
+
matchActivatorWidth: true,
|
|
264
|
+
onClose: function() {
|
|
265
|
+
setShowOptionsPopover(false);
|
|
266
|
+
if (props.onClose) {
|
|
267
|
+
props.onClose();
|
|
268
|
+
}
|
|
269
|
+
},
|
|
270
|
+
zIndexOverride: zIndexOverride,
|
|
271
|
+
children: loading ? /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
272
|
+
className: "py-4 flex justify-center items-center",
|
|
273
|
+
children: /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Spinner, {
|
|
274
|
+
size: "small"
|
|
275
|
+
})
|
|
276
|
+
}) : showEmptyState ? /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
277
|
+
className: "py-4 flex flex-col gap-1 justify-center items-center",
|
|
278
|
+
children: [
|
|
279
|
+
emptyState.icon && /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Icon, {
|
|
280
|
+
source: _polarisicons.SearchMinor,
|
|
281
|
+
color: "subdued"
|
|
282
|
+
}),
|
|
283
|
+
/*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Text, {
|
|
284
|
+
children: emptyState.content
|
|
285
|
+
})
|
|
286
|
+
]
|
|
287
|
+
}) : options.length > 0 ? /*#__PURE__*/ (0, _jsxruntime.jsx)("div", {
|
|
288
|
+
className: "p-2",
|
|
289
|
+
children: options.map(function(option, index) {
|
|
290
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsxs)("div", {
|
|
291
|
+
children: [
|
|
292
|
+
option.title && /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.Text, {
|
|
293
|
+
variant: "bodyMd",
|
|
294
|
+
color: "subdued",
|
|
295
|
+
className: "pb-1",
|
|
296
|
+
children: option.title
|
|
297
|
+
}),
|
|
298
|
+
option.options ? option.options.map(function(subOption, subIndex) {
|
|
299
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(OptionItem, {
|
|
300
|
+
option: subOption,
|
|
301
|
+
allowMultiple: allowMultiple,
|
|
302
|
+
selected: selected,
|
|
303
|
+
onSelect: onSelect,
|
|
304
|
+
setShowOptionsPopover: setShowOptionsPopover
|
|
305
|
+
}, "".concat(index, "-").concat(subIndex));
|
|
306
|
+
}) : /*#__PURE__*/ (0, _jsxruntime.jsx)(OptionItem, {
|
|
307
|
+
option: option,
|
|
308
|
+
allowMultiple: allowMultiple,
|
|
309
|
+
selected: selected,
|
|
310
|
+
onSelect: onSelect,
|
|
311
|
+
setShowOptionsPopover: setShowOptionsPopover
|
|
312
|
+
}, index)
|
|
313
|
+
]
|
|
314
|
+
}, index);
|
|
315
|
+
})
|
|
316
|
+
}) : undefined
|
|
317
|
+
})
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
Autocomplete.displayName = "Autocomplete";
|
|
321
|
+
/**
|
|
322
|
+
* Autocomplete TextField component used as an activator for the Autocomplete dropdown.
|
|
323
|
+
*
|
|
324
|
+
* @component
|
|
325
|
+
* @param {Object} props - The props for the AutocompleteTextField component.
|
|
326
|
+
* @param {function} [props.onTextFieldFocus] - Callback fired when the TextField gains focus.
|
|
327
|
+
* @param {function} [props.onFocus] - Callback fired when the TextField gains focus (native TextField event).
|
|
328
|
+
* @param {string} [props.placeholder] - Placeholder text for the TextField.
|
|
329
|
+
* @param {string} [props.value] - The current value of the TextField.
|
|
330
|
+
* @param {function} [props.onChange] - Callback fired when the TextField value changes.
|
|
331
|
+
*
|
|
332
|
+
* @example
|
|
333
|
+
* <Autocomplete.TextField
|
|
334
|
+
* placeholder="Search..."
|
|
335
|
+
* onTextFieldFocus={() => console.log("Focused")}
|
|
336
|
+
* />
|
|
337
|
+
*/ Autocomplete.TextField = function AutocompleteTextField() {
|
|
338
|
+
var props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
339
|
+
return /*#__PURE__*/ (0, _jsxruntime.jsx)(_index.TextField, _object_spread_props(_object_spread({}, props), {
|
|
340
|
+
onFocus: function() {
|
|
341
|
+
if (props.onTextFieldFocus) {
|
|
342
|
+
props.onTextFieldFocus();
|
|
343
|
+
}
|
|
344
|
+
if (props.onFocus) {
|
|
345
|
+
props.onFocus();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}));
|
|
349
|
+
};
|
|
350
|
+
Autocomplete.TextField.displayName = "Autocomplete.TextField";
|
|
351
|
+
var _default = Autocomplete;
|