@lumx/react 3.20.1-alpha.36 → 3.20.1-alpha.37
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/index.js +13990 -64
- package/index.js.map +1 -0
- package/package.json +3 -3
- package/utils/index.js +159 -3
- package/utils/index.js.map +1 -0
- package/_internal/035c132d.js +0 -314
- package/_internal/0b9c76cb.js +0 -5
- package/_internal/0ea95af1.js +0 -819
- package/_internal/230173a8.js +0 -12
- package/_internal/2a3d237c.js +0 -11
- package/_internal/2c2b6a89.js +0 -51
- package/_internal/3181f000.js +0 -13
- package/_internal/36bd7352.js +0 -218
- package/_internal/3864a6c1.js +0 -436
- package/_internal/3a1facc0.js +0 -17
- package/_internal/49bbeed3.js +0 -5
- package/_internal/4daccdd5.js +0 -24
- package/_internal/4f4c0582.js +0 -2169
- package/_internal/5cef5e8c.js +0 -74
- package/_internal/6a60381c.js +0 -117
- package/_internal/6f084a40.js +0 -111
- package/_internal/76ddefd4.js +0 -61
- package/_internal/78df9309.js +0 -19
- package/_internal/7ad474e4.js +0 -98
- package/_internal/7b293665.js +0 -19
- package/_internal/7daf0f24.js +0 -76
- package/_internal/825ac334.js +0 -129
- package/_internal/827b804a.js +0 -5
- package/_internal/8bce732e.js +0 -8
- package/_internal/9d1336a1.js +0 -18
- package/_internal/a38bdcd0.js +0 -49
- package/_internal/b326655a.js +0 -682
- package/_internal/b83e864b.js +0 -76
- package/_internal/bace1bf1.js +0 -103
- package/_internal/c57190eb.js +0 -146
- package/_internal/components/alert-dialog/index-284fed80.js +0 -163
- package/_internal/components/autocomplete/__mockData__/index-96fc7ea7.js +0 -27
- package/_internal/components/autocomplete/index-27a49d5d.js +0 -261
- package/_internal/components/avatar/index-b8bc3cae.js +0 -83
- package/_internal/components/badge/index-9880f056.js +0 -81
- package/_internal/components/button/index-d919f96d.js +0 -47
- package/_internal/components/checkbox/index-dd478de9.js +0 -143
- package/_internal/components/chip/index-7f84cdbd.js +0 -102
- package/_internal/components/comment-block/index-e942de30.js +0 -138
- package/_internal/components/date-picker/index-a258d3ce.js +0 -596
- package/_internal/components/dialog/index-c7066813.js +0 -238
- package/_internal/components/divider/index-b6934baf.js +0 -50
- package/_internal/components/drag-handle/index-80e5af6c.js +0 -52
- package/_internal/components/dropdown/index-cebfc268.js +0 -147
- package/_internal/components/expansion-panel/index-9d45a211.js +0 -167
- package/_internal/components/flag/index-33e9d909.js +0 -59
- package/_internal/components/flex-box/index-0d6b6b43.js +0 -56
- package/_internal/components/generic-block/index-836c4352.js +0 -124
- package/_internal/components/grid/index-8c16a4f1.js +0 -104
- package/_internal/components/grid-column/index-4a2f56bb.js +0 -59
- package/_internal/components/heading/index-fd558a9a.js +0 -53
- package/_internal/components/icon/index-e7b9b40e.js +0 -1
- package/_internal/components/image-block/index-7021c2f1.js +0 -110
- package/_internal/components/image-lightbox/index-27017547.js +0 -759
- package/_internal/components/inline-list/index-52efec7f.js +0 -74
- package/_internal/components/input-helper/index-5a837e7c.js +0 -71
- package/_internal/components/input-label/index-0113f382.js +0 -59
- package/_internal/components/lightbox/index-fad5a9f2.js +0 -155
- package/_internal/components/link/index-008bae4b.js +0 -72
- package/_internal/components/link-preview/index-3e9c32f2.js +0 -117
- package/_internal/components/list/index-da88c6e9.js +0 -71
- package/_internal/components/message/index-17b568f2.js +0 -98
- package/_internal/components/mosaic/index-2d40e01c.js +0 -95
- package/_internal/components/navigation/index-dc17c639.js +0 -225
- package/_internal/components/notification/index-a1101015.js +0 -146
- package/_internal/components/popover/index-dbca63f1.js +0 -2
- package/_internal/components/popover-dialog/index-654d2abc.js +0 -66
- package/_internal/components/post-block/index-4b6b4dcb.js +0 -109
- package/_internal/components/progress/index-6f578c31.js +0 -182
- package/_internal/components/progress-tracker/index-700bc4c2.js +0 -309
- package/_internal/components/radio-button/index-89b725af.js +0 -149
- package/_internal/components/select/index-2755aa32.js +0 -458
- package/_internal/components/side-navigation/index-0bbe1fdd.js +0 -165
- package/_internal/components/skeleton/index-b2f8501c.js +0 -166
- package/_internal/components/slider/index-4f9b891b.js +0 -311
- package/_internal/components/slideshow/index-d4604589.js +0 -150
- package/_internal/components/switch/index-58fe0f0c.js +0 -122
- package/_internal/components/table/index-d541aa88.js +0 -297
- package/_internal/components/tabs/index-af1538d6.js +0 -298
- package/_internal/components/text/index-5bfc6d5e.js +0 -1
- package/_internal/components/text-field/index-47c98d09.js +0 -360
- package/_internal/components/thumbnail/index-71545d95.js +0 -41
- package/_internal/components/toolbar/index-7041a5a6.js +0 -61
- package/_internal/components/tooltip/index-8bb97e60.js +0 -327
- package/_internal/components/uploader/index-8f6f55de.js +0 -153
- package/_internal/components/user-block/index-70d4ce8f.js +0 -145
- package/_internal/d0e3f49e.js +0 -23
- package/_internal/de24f857.js +0 -3
- package/_internal/e806b848.js +0 -8
- package/_internal/e913a3af.js +0 -117
- package/_internal/ea04260d.js +0 -28
- package/_internal/eaf6c45a.js +0 -3
- package/_internal/ebdcb0c7.js +0 -60
- package/_internal/ef5d1aac.js +0 -3
- package/_internal/f0d7d6ea.js +0 -29
- package/_internal/utils/ClickAwayProvider/index-1234ce76.js +0 -94
- package/_internal/utils/MaterialThemeSwitcher/index-8d22de5a.js +0 -48
- package/_internal/utils/Portal/index-6e0a7404.js +0 -44
- package/_internal/utils/disabled/index-075b99c3.js +0 -36
- package/_internal/utils/type/index-ea9fc197.js +0 -2
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import ReactDOM from 'react-dom';
|
|
2
|
-
import React__default, { useReducer, useEffect, useCallback } from 'react';
|
|
3
|
-
import { I as INIT_STATE, r as reducer, T as TabProviderContext, a as useTabProviderContext } from '../../825ac334.js';
|
|
4
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
-
import classNames from 'classnames';
|
|
6
|
-
import '../../d0e3f49e.js';
|
|
7
|
-
import { handleBasicClasses } from '@lumx/core/js/utils/className';
|
|
8
|
-
import { m as mergeRefs } from '../../f0d7d6ea.js';
|
|
9
|
-
import { f as forwardRef } from '../../8bce732e.js';
|
|
10
|
-
import { u as useTheme } from '../../3181f000.js';
|
|
11
|
-
import { u as useRovingTabIndex } from '../../7daf0f24.js';
|
|
12
|
-
import { Alignment, Theme, CSS_PREFIX, Size } from '@lumx/core/js/constants';
|
|
13
|
-
import { useDisableStateProps } from '../../utils/disabled/index-075b99c3.js';
|
|
14
|
-
import { I as Icon } from '../../bace1bf1.js';
|
|
15
|
-
import { T as Text } from '../../e913a3af.js';
|
|
16
|
-
|
|
17
|
-
const DEFAULT_PROPS$3 = {
|
|
18
|
-
isLazy: INIT_STATE.isLazy,
|
|
19
|
-
shouldActivateOnFocus: INIT_STATE.shouldActivateOnFocus
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* This component provides a context in which tabs can be defined and linked to their tab panel.
|
|
24
|
-
*
|
|
25
|
-
* It does not produce any markup so you can wrap it around any React elements and then split the TabList and TabPanel
|
|
26
|
-
* components in the react tree.
|
|
27
|
-
*
|
|
28
|
-
* @param props React component props.
|
|
29
|
-
* @return React element.
|
|
30
|
-
*/
|
|
31
|
-
const TabProvider = props => {
|
|
32
|
-
const {
|
|
33
|
-
children,
|
|
34
|
-
onChange,
|
|
35
|
-
...propState
|
|
36
|
-
} = props;
|
|
37
|
-
const [state, dispatch] = useReducer(reducer, INIT_STATE);
|
|
38
|
-
|
|
39
|
-
// On prop state change => dispatch update.
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
dispatch({
|
|
42
|
-
type: 'update',
|
|
43
|
-
payload: {
|
|
44
|
-
...DEFAULT_PROPS$3,
|
|
45
|
-
...propState
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
},
|
|
49
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
50
|
-
[dispatch, ...Object.values(propState)]);
|
|
51
|
-
|
|
52
|
-
// On active tab index state change => send update to the onChange.
|
|
53
|
-
useEffect(() => {
|
|
54
|
-
if (state === INIT_STATE || !onChange || propState.activeTabIndex === state.activeTabIndex) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// Escape rendering/useEffect context
|
|
59
|
-
queueMicrotask(() => {
|
|
60
|
-
// Wait for React to commit last state changes (avoid looping state update)
|
|
61
|
-
ReactDOM.flushSync(() => {
|
|
62
|
-
onChange(state.activeTabIndex);
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
},
|
|
66
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
67
|
-
[onChange, state.activeTabIndex]);
|
|
68
|
-
return /*#__PURE__*/jsx(TabProviderContext.Provider, {
|
|
69
|
-
value: [state, dispatch],
|
|
70
|
-
children: children
|
|
71
|
-
});
|
|
72
|
-
};
|
|
73
|
-
TabProvider.defaultProps = DEFAULT_PROPS$3;
|
|
74
|
-
|
|
75
|
-
let TabListLayout = /*#__PURE__*/function (TabListLayout) {
|
|
76
|
-
TabListLayout["clustered"] = "clustered";
|
|
77
|
-
TabListLayout["fixed"] = "fixed";
|
|
78
|
-
return TabListLayout;
|
|
79
|
-
}({});
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Defines the props of the component.
|
|
83
|
-
*/
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Component display name.
|
|
87
|
-
*/
|
|
88
|
-
const COMPONENT_NAME$2 = 'TabList';
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Component default class name and class prefix.
|
|
92
|
-
*/
|
|
93
|
-
const CLASSNAME$2 = `${CSS_PREFIX}-tabs`;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Component default props.
|
|
97
|
-
*/
|
|
98
|
-
const DEFAULT_PROPS$2 = {
|
|
99
|
-
layout: TabListLayout.fixed,
|
|
100
|
-
position: Alignment.left
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* TabList component.
|
|
105
|
-
*
|
|
106
|
-
* Implements WAI-ARIA `tablist` role {@see https://www.w3.org/TR/wai-aria-practices-1.1/examples/tabs/tabs-1/tabs.html#rps_label}
|
|
107
|
-
*
|
|
108
|
-
* @param props Component props.
|
|
109
|
-
* @param ref Component ref.
|
|
110
|
-
* @return React element.
|
|
111
|
-
*/
|
|
112
|
-
const TabList = forwardRef((props, ref) => {
|
|
113
|
-
const defaultTheme = useTheme() || Theme.light;
|
|
114
|
-
const {
|
|
115
|
-
'aria-label': ariaLabel,
|
|
116
|
-
children,
|
|
117
|
-
className,
|
|
118
|
-
layout = DEFAULT_PROPS$2.layout,
|
|
119
|
-
position = DEFAULT_PROPS$2.position,
|
|
120
|
-
theme = defaultTheme,
|
|
121
|
-
...forwardedProps
|
|
122
|
-
} = props;
|
|
123
|
-
const tabListRef = React__default.useRef(null);
|
|
124
|
-
useRovingTabIndex({
|
|
125
|
-
parentRef: tabListRef,
|
|
126
|
-
elementSelector: '[role="tab"]',
|
|
127
|
-
keepTabIndex: false,
|
|
128
|
-
extraDependencies: [children]
|
|
129
|
-
});
|
|
130
|
-
return /*#__PURE__*/jsx("div", {
|
|
131
|
-
ref: mergeRefs(ref, tabListRef),
|
|
132
|
-
...forwardedProps,
|
|
133
|
-
className: classNames(className, handleBasicClasses({
|
|
134
|
-
prefix: CLASSNAME$2,
|
|
135
|
-
layout,
|
|
136
|
-
position,
|
|
137
|
-
theme
|
|
138
|
-
})),
|
|
139
|
-
children: /*#__PURE__*/jsx("div", {
|
|
140
|
-
className: `${CLASSNAME$2}__links`,
|
|
141
|
-
role: "tablist",
|
|
142
|
-
"aria-label": ariaLabel,
|
|
143
|
-
children: children
|
|
144
|
-
})
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
TabList.displayName = COMPONENT_NAME$2;
|
|
148
|
-
TabList.className = CLASSNAME$2;
|
|
149
|
-
TabList.defaultProps = DEFAULT_PROPS$2;
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Component display name.
|
|
153
|
-
*/
|
|
154
|
-
const COMPONENT_NAME$1 = 'Tab';
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Component default class name and class prefix.
|
|
158
|
-
*/
|
|
159
|
-
const CLASSNAME$1 = `${CSS_PREFIX}-tabs__link`;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Component default props.
|
|
163
|
-
*/
|
|
164
|
-
const DEFAULT_PROPS$1 = {};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Tab component.
|
|
168
|
-
*
|
|
169
|
-
* Implements WAI-ARIA `tab` role {@see https://www.w3.org/TR/wai-aria-practices-1.1/examples/tabs/tabs-1/tabs.html#rps_label}
|
|
170
|
-
*
|
|
171
|
-
* @param props Component props.
|
|
172
|
-
* @param ref Component ref.
|
|
173
|
-
* @return React element.
|
|
174
|
-
*/
|
|
175
|
-
const Tab = forwardRef((props, ref) => {
|
|
176
|
-
const {
|
|
177
|
-
isAnyDisabled,
|
|
178
|
-
otherProps
|
|
179
|
-
} = useDisableStateProps(props);
|
|
180
|
-
const {
|
|
181
|
-
className,
|
|
182
|
-
icon,
|
|
183
|
-
iconProps = {},
|
|
184
|
-
id,
|
|
185
|
-
isActive: propIsActive,
|
|
186
|
-
label,
|
|
187
|
-
onFocus,
|
|
188
|
-
onKeyPress,
|
|
189
|
-
tabIndex = -1,
|
|
190
|
-
...forwardedProps
|
|
191
|
-
} = otherProps;
|
|
192
|
-
const state = useTabProviderContext('tab', id);
|
|
193
|
-
const isActive = propIsActive || state?.isActive;
|
|
194
|
-
const changeToCurrentTab = useCallback(() => {
|
|
195
|
-
if (isAnyDisabled) {
|
|
196
|
-
return;
|
|
197
|
-
}
|
|
198
|
-
state?.changeToTab();
|
|
199
|
-
}, [isAnyDisabled, state]);
|
|
200
|
-
const handleFocus = useCallback(event => {
|
|
201
|
-
onFocus?.(event);
|
|
202
|
-
if (state?.shouldActivateOnFocus) {
|
|
203
|
-
changeToCurrentTab();
|
|
204
|
-
}
|
|
205
|
-
}, [changeToCurrentTab, onFocus, state?.shouldActivateOnFocus]);
|
|
206
|
-
const handleKeyPress = useCallback(event => {
|
|
207
|
-
onKeyPress?.(event);
|
|
208
|
-
if (event.key !== 'Enter' || isAnyDisabled) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
changeToCurrentTab();
|
|
212
|
-
}, [changeToCurrentTab, isAnyDisabled, onKeyPress]);
|
|
213
|
-
return /*#__PURE__*/jsxs("button", {
|
|
214
|
-
ref: ref,
|
|
215
|
-
...forwardedProps,
|
|
216
|
-
type: "button",
|
|
217
|
-
id: state?.tabId,
|
|
218
|
-
className: classNames(className, handleBasicClasses({
|
|
219
|
-
prefix: CLASSNAME$1,
|
|
220
|
-
isActive,
|
|
221
|
-
isDisabled: isAnyDisabled
|
|
222
|
-
})),
|
|
223
|
-
onClick: changeToCurrentTab,
|
|
224
|
-
onKeyPress: handleKeyPress,
|
|
225
|
-
onFocus: handleFocus,
|
|
226
|
-
role: "tab",
|
|
227
|
-
tabIndex: isActive ? 0 : tabIndex,
|
|
228
|
-
"aria-disabled": isAnyDisabled,
|
|
229
|
-
"aria-selected": isActive,
|
|
230
|
-
"aria-controls": state?.tabPanelId,
|
|
231
|
-
children: [icon && /*#__PURE__*/jsx(Icon, {
|
|
232
|
-
icon: icon,
|
|
233
|
-
size: Size.xs,
|
|
234
|
-
...iconProps
|
|
235
|
-
}), label && /*#__PURE__*/jsx(Text, {
|
|
236
|
-
as: "span",
|
|
237
|
-
truncate: true,
|
|
238
|
-
children: label
|
|
239
|
-
})]
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
Tab.displayName = COMPONENT_NAME$1;
|
|
243
|
-
Tab.className = CLASSNAME$1;
|
|
244
|
-
Tab.defaultProps = DEFAULT_PROPS$1;
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Component display name.
|
|
248
|
-
*/
|
|
249
|
-
const COMPONENT_NAME = 'TabPanel';
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Component default class name and class prefix.
|
|
253
|
-
*/
|
|
254
|
-
const CLASSNAME = `${CSS_PREFIX}-tab-panel`;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Component default props.
|
|
258
|
-
*/
|
|
259
|
-
const DEFAULT_PROPS = {};
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* TabPanel component.
|
|
263
|
-
*
|
|
264
|
-
* Implements WAI-ARIA `tabpanel` role {@see https://www.w3.org/TR/wai-aria-practices-1.1/examples/tabs/tabs-1/tabs.html#rps_label}
|
|
265
|
-
*
|
|
266
|
-
* @param props Component props.
|
|
267
|
-
* @param ref Component ref.
|
|
268
|
-
* @return React element.
|
|
269
|
-
*/
|
|
270
|
-
const TabPanel = forwardRef((props, ref) => {
|
|
271
|
-
const {
|
|
272
|
-
children,
|
|
273
|
-
id,
|
|
274
|
-
className,
|
|
275
|
-
isActive: propIsActive,
|
|
276
|
-
...forwardedProps
|
|
277
|
-
} = props;
|
|
278
|
-
const state = useTabProviderContext('tabPanel', id);
|
|
279
|
-
const isActive = propIsActive || state?.isActive;
|
|
280
|
-
return /*#__PURE__*/jsx("div", {
|
|
281
|
-
ref: ref,
|
|
282
|
-
...forwardedProps,
|
|
283
|
-
id: state?.tabPanelId,
|
|
284
|
-
className: classNames(className, handleBasicClasses({
|
|
285
|
-
prefix: CLASSNAME,
|
|
286
|
-
isActive
|
|
287
|
-
})),
|
|
288
|
-
role: "tabpanel",
|
|
289
|
-
tabIndex: isActive ? 0 : -1,
|
|
290
|
-
"aria-labelledby": state?.tabId,
|
|
291
|
-
children: (!state?.isLazy || isActive) && children
|
|
292
|
-
});
|
|
293
|
-
});
|
|
294
|
-
TabPanel.displayName = COMPONENT_NAME;
|
|
295
|
-
TabPanel.className = CLASSNAME;
|
|
296
|
-
TabPanel.defaultProps = DEFAULT_PROPS;
|
|
297
|
-
|
|
298
|
-
export { Tab, TabList, TabListLayout, TabPanel, TabProvider };
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { T as Text } from '../../e913a3af.js';
|
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
import { useRef, useState, useEffect } from 'react';
|
|
2
|
-
import classNames from 'classnames';
|
|
3
|
-
import get from 'lodash/get';
|
|
4
|
-
import { getRootClassName, handleBasicClasses } from '@lumx/core/js/utils/className';
|
|
5
|
-
import { m as mergeRefs } from '../../f0d7d6ea.js';
|
|
6
|
-
import { u as useId } from '../../3a1facc0.js';
|
|
7
|
-
import { u as useTheme } from '../../3181f000.js';
|
|
8
|
-
import { f as forwardRef } from '../../8bce732e.js';
|
|
9
|
-
import { useDisableStateProps } from '../../utils/disabled/index-075b99c3.js';
|
|
10
|
-
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
11
|
-
import { Theme, Size, Emphasis, Kind } from '@lumx/core/js/constants';
|
|
12
|
-
import { InputLabel } from '../input-label/index-0113f382.js';
|
|
13
|
-
import { I as Icon, m as mdiAlertCircle } from '../../bace1bf1.js';
|
|
14
|
-
import { m as mdiCheckCircle } from '../../de24f857.js';
|
|
15
|
-
import { I as IconButton } from '../../b83e864b.js';
|
|
16
|
-
import { m as mdiCloseCircle } from '../../ef5d1aac.js';
|
|
17
|
-
import { InputHelper } from '../input-helper/index-5a837e7c.js';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Component display name.
|
|
21
|
-
*/
|
|
22
|
-
const COMPONENT_NAME = 'TextField';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Component default class name and class prefix.
|
|
26
|
-
*/
|
|
27
|
-
const CLASSNAME = getRootClassName(COMPONENT_NAME);
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Default minimum number of rows in the multiline mode.
|
|
31
|
-
*/
|
|
32
|
-
const DEFAULT_MIN_ROWS = 2;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Component default props.
|
|
36
|
-
*/
|
|
37
|
-
const DEFAULT_PROPS = {
|
|
38
|
-
type: 'text'
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Hook that allows to calculate the number of rows needed for a text area.
|
|
43
|
-
* @param minimumRows Minimum number of rows that we want to display.
|
|
44
|
-
* @return rows to be used and a callback to recalculate
|
|
45
|
-
*/
|
|
46
|
-
const useComputeNumberOfRows = minimumRows => {
|
|
47
|
-
const [rows, setRows] = useState(minimumRows);
|
|
48
|
-
const recompute = target => {
|
|
49
|
-
/**
|
|
50
|
-
* HEAD's UP! This part is a little bit tricky. The idea here is to only
|
|
51
|
-
* display the necessary rows on the textarea. In order to dynamically adjust
|
|
52
|
-
* the height on that field, we need to:
|
|
53
|
-
* 1. Set the current amount of rows to the minimum. That will make the scroll appear.
|
|
54
|
-
* 2. With that, we will have the `scrollHeight`, meaning the height of the container adjusted to the current content
|
|
55
|
-
* 3. With the scroll height, we can figure out how many rows we need to use by dividing the scroll height
|
|
56
|
-
* by the line height.
|
|
57
|
-
* 4. With that number, we can readjust the number of rows on the text area. We need to do that here, if we leave that to
|
|
58
|
-
* the state change through React, there are some scenarios (resize, hitting ENTER or BACKSPACE which add or remove lines)
|
|
59
|
-
* when we will not see the update and the rows will be resized to the minimum.
|
|
60
|
-
* 5. In case there is any other update on the component that changes the UI, we need to keep the number of rows
|
|
61
|
-
* on the state in order to allow React to re-render. Therefore, we save them using `useState`
|
|
62
|
-
*/
|
|
63
|
-
// eslint-disable-next-line no-param-reassign
|
|
64
|
-
target.rows = minimumRows;
|
|
65
|
-
let currentRows = target.scrollHeight / (target.clientHeight / minimumRows);
|
|
66
|
-
currentRows = currentRows >= minimumRows ? currentRows : minimumRows;
|
|
67
|
-
// eslint-disable-next-line no-param-reassign
|
|
68
|
-
target.rows = currentRows;
|
|
69
|
-
setRows(currentRows);
|
|
70
|
-
};
|
|
71
|
-
return {
|
|
72
|
-
recomputeNumberOfRows: recompute,
|
|
73
|
-
rows
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
const renderInputNative = props => {
|
|
77
|
-
const {
|
|
78
|
-
id,
|
|
79
|
-
isRequired,
|
|
80
|
-
placeholder,
|
|
81
|
-
multiline,
|
|
82
|
-
value,
|
|
83
|
-
setFocus,
|
|
84
|
-
onChange,
|
|
85
|
-
onFocus,
|
|
86
|
-
onBlur,
|
|
87
|
-
inputRef,
|
|
88
|
-
rows,
|
|
89
|
-
recomputeNumberOfRows,
|
|
90
|
-
type,
|
|
91
|
-
name,
|
|
92
|
-
hasError,
|
|
93
|
-
describedById,
|
|
94
|
-
...forwardedProps
|
|
95
|
-
} = props;
|
|
96
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
97
|
-
const ref = useRef(null);
|
|
98
|
-
|
|
99
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
// Recompute the number of rows for the first rendering
|
|
102
|
-
if (multiline && ref && ref.current) {
|
|
103
|
-
recomputeNumberOfRows(ref.current);
|
|
104
|
-
}
|
|
105
|
-
}, [ref, multiline, recomputeNumberOfRows, value]);
|
|
106
|
-
const onTextFieldFocus = event => {
|
|
107
|
-
onFocus?.(event);
|
|
108
|
-
setFocus(true);
|
|
109
|
-
};
|
|
110
|
-
const onTextFieldBlur = event => {
|
|
111
|
-
onBlur?.(event);
|
|
112
|
-
setFocus(false);
|
|
113
|
-
};
|
|
114
|
-
const handleChange = event => {
|
|
115
|
-
onChange(get(event, 'target.value'), name, event);
|
|
116
|
-
};
|
|
117
|
-
const Component = multiline ? 'textarea' : 'input';
|
|
118
|
-
const inputProps = {
|
|
119
|
-
...forwardedProps,
|
|
120
|
-
id,
|
|
121
|
-
className: multiline ? `${CLASSNAME}__input-native ${CLASSNAME}__input-native--textarea` : `${CLASSNAME}__input-native ${CLASSNAME}__input-native--text`,
|
|
122
|
-
placeholder,
|
|
123
|
-
value,
|
|
124
|
-
name,
|
|
125
|
-
required: isRequired,
|
|
126
|
-
onFocus: onTextFieldFocus,
|
|
127
|
-
onBlur: onTextFieldBlur,
|
|
128
|
-
onChange: handleChange,
|
|
129
|
-
'aria-invalid': hasError ? 'true' : undefined,
|
|
130
|
-
'aria-describedby': describedById,
|
|
131
|
-
readOnly: forwardedProps.readOnly || forwardedProps['aria-disabled'],
|
|
132
|
-
ref: mergeRefs(inputRef, ref)
|
|
133
|
-
};
|
|
134
|
-
if (multiline) {
|
|
135
|
-
inputProps.rows = rows;
|
|
136
|
-
} else {
|
|
137
|
-
inputProps.type = type;
|
|
138
|
-
}
|
|
139
|
-
return /*#__PURE__*/jsx(Component, {
|
|
140
|
-
...inputProps
|
|
141
|
-
});
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* TextField component.
|
|
146
|
-
*
|
|
147
|
-
* @param props Component props.
|
|
148
|
-
* @param ref Component ref.
|
|
149
|
-
* @return React element.
|
|
150
|
-
*/
|
|
151
|
-
const TextField = forwardRef((props, ref) => {
|
|
152
|
-
const {
|
|
153
|
-
isAnyDisabled,
|
|
154
|
-
disabledStateProps,
|
|
155
|
-
otherProps
|
|
156
|
-
} = useDisableStateProps(props);
|
|
157
|
-
const defaultTheme = useTheme() || Theme.light;
|
|
158
|
-
const {
|
|
159
|
-
chips,
|
|
160
|
-
className,
|
|
161
|
-
clearButtonProps,
|
|
162
|
-
error,
|
|
163
|
-
forceFocusStyle,
|
|
164
|
-
hasError,
|
|
165
|
-
helper,
|
|
166
|
-
icon,
|
|
167
|
-
id,
|
|
168
|
-
inputRef: inputRefProps,
|
|
169
|
-
isRequired,
|
|
170
|
-
isValid,
|
|
171
|
-
label,
|
|
172
|
-
labelProps,
|
|
173
|
-
maxLength,
|
|
174
|
-
minimumRows,
|
|
175
|
-
multiline,
|
|
176
|
-
name,
|
|
177
|
-
onBlur,
|
|
178
|
-
onChange,
|
|
179
|
-
onClear,
|
|
180
|
-
onFocus,
|
|
181
|
-
placeholder,
|
|
182
|
-
textFieldRef,
|
|
183
|
-
theme = defaultTheme,
|
|
184
|
-
type = DEFAULT_PROPS.type,
|
|
185
|
-
value,
|
|
186
|
-
afterElement,
|
|
187
|
-
...forwardedProps
|
|
188
|
-
} = otherProps;
|
|
189
|
-
const generatedTextFieldId = useId();
|
|
190
|
-
const textFieldId = id || generatedTextFieldId;
|
|
191
|
-
/** Keep a clean local input ref to manage focus */
|
|
192
|
-
const localInputRef = useRef(null);
|
|
193
|
-
/** Merge prop input ref and local input ref */
|
|
194
|
-
const inputRef = mergeRefs(localInputRef, inputRefProps);
|
|
195
|
-
/**
|
|
196
|
-
* Generate unique ids for both the helper and error texts, in order to
|
|
197
|
-
* later on add them to the input native as aria-describedby. If both the error and the helper are present,
|
|
198
|
-
* we want to first use the most important one, which is the errorId. That way, screen readers will read first
|
|
199
|
-
* the error and then the helper
|
|
200
|
-
*/
|
|
201
|
-
const helperId = helper ? `text-field-helper-${generatedTextFieldId}` : undefined;
|
|
202
|
-
const errorId = error ? `text-field-error-${generatedTextFieldId}` : undefined;
|
|
203
|
-
const describedByIds = [errorId, helperId, forwardedProps['aria-describedby']].filter(Boolean);
|
|
204
|
-
const describedById = describedByIds.length === 0 ? undefined : describedByIds.join(' ');
|
|
205
|
-
const [isFocus, setFocus] = useState(false);
|
|
206
|
-
const {
|
|
207
|
-
rows,
|
|
208
|
-
recomputeNumberOfRows
|
|
209
|
-
} = useComputeNumberOfRows(multiline ? minimumRows || DEFAULT_MIN_ROWS : 0);
|
|
210
|
-
const valueLength = (value || '').length;
|
|
211
|
-
const isNotEmpty = valueLength > 0;
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Function triggered when the Clear Button is clicked.
|
|
215
|
-
* The idea is to execute the `onChange` callback with an empty string
|
|
216
|
-
* and remove focus from the clear button.
|
|
217
|
-
* @param evt On clear event.
|
|
218
|
-
*/
|
|
219
|
-
const handleClear = evt => {
|
|
220
|
-
evt.nativeEvent.preventDefault();
|
|
221
|
-
evt.nativeEvent.stopPropagation();
|
|
222
|
-
evt.currentTarget.blur();
|
|
223
|
-
onChange('');
|
|
224
|
-
if (onClear) {
|
|
225
|
-
onClear(evt);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
/** Use local inputRef in case the prop input ref is a `mergeRefs` function. */
|
|
229
|
-
const inputElement = localInputRef;
|
|
230
|
-
if (inputElement && inputElement.current) {
|
|
231
|
-
inputElement.current.focus();
|
|
232
|
-
}
|
|
233
|
-
};
|
|
234
|
-
return /*#__PURE__*/jsxs("div", {
|
|
235
|
-
ref: ref,
|
|
236
|
-
className: classNames(className, handleBasicClasses({
|
|
237
|
-
hasChips: Boolean(chips),
|
|
238
|
-
hasError: !isValid && hasError,
|
|
239
|
-
hasIcon: Boolean(icon),
|
|
240
|
-
hasInput: !multiline,
|
|
241
|
-
hasInputClear: clearButtonProps && isNotEmpty,
|
|
242
|
-
hasLabel: Boolean(label),
|
|
243
|
-
hasPlaceholder: Boolean(placeholder),
|
|
244
|
-
hasTextarea: multiline,
|
|
245
|
-
hasValue: Boolean(value),
|
|
246
|
-
isDisabled: isAnyDisabled,
|
|
247
|
-
isFocus: isFocus || forceFocusStyle,
|
|
248
|
-
isValid,
|
|
249
|
-
prefix: CLASSNAME,
|
|
250
|
-
theme
|
|
251
|
-
})),
|
|
252
|
-
children: [(label || maxLength) && /*#__PURE__*/jsxs("div", {
|
|
253
|
-
className: `${CLASSNAME}__header`,
|
|
254
|
-
children: [label && /*#__PURE__*/jsx(InputLabel, {
|
|
255
|
-
...labelProps,
|
|
256
|
-
htmlFor: textFieldId,
|
|
257
|
-
className: `${CLASSNAME}__label`,
|
|
258
|
-
isRequired: isRequired,
|
|
259
|
-
theme: theme,
|
|
260
|
-
children: label
|
|
261
|
-
}), maxLength && /*#__PURE__*/jsxs("div", {
|
|
262
|
-
className: `${CLASSNAME}__char-counter`,
|
|
263
|
-
children: [/*#__PURE__*/jsx("span", {
|
|
264
|
-
children: maxLength - valueLength
|
|
265
|
-
}), maxLength - valueLength === 0 && /*#__PURE__*/jsx(Icon, {
|
|
266
|
-
icon: mdiAlertCircle,
|
|
267
|
-
size: Size.xxs
|
|
268
|
-
})]
|
|
269
|
-
})]
|
|
270
|
-
}), /*#__PURE__*/jsxs("div", {
|
|
271
|
-
className: `${CLASSNAME}__wrapper`,
|
|
272
|
-
ref: textFieldRef,
|
|
273
|
-
children: [icon && /*#__PURE__*/jsx(Icon, {
|
|
274
|
-
className: `${CLASSNAME}__input-icon`,
|
|
275
|
-
color: theme === Theme.dark ? 'light' : undefined,
|
|
276
|
-
icon: icon,
|
|
277
|
-
size: Size.xs
|
|
278
|
-
}), chips && /*#__PURE__*/jsxs("div", {
|
|
279
|
-
className: `${CLASSNAME}__chips`,
|
|
280
|
-
children: [chips, renderInputNative({
|
|
281
|
-
id: textFieldId,
|
|
282
|
-
inputRef,
|
|
283
|
-
...disabledStateProps,
|
|
284
|
-
isRequired,
|
|
285
|
-
maxLength,
|
|
286
|
-
multiline,
|
|
287
|
-
onBlur,
|
|
288
|
-
onChange,
|
|
289
|
-
onFocus,
|
|
290
|
-
placeholder,
|
|
291
|
-
recomputeNumberOfRows,
|
|
292
|
-
rows,
|
|
293
|
-
setFocus,
|
|
294
|
-
type,
|
|
295
|
-
value,
|
|
296
|
-
name,
|
|
297
|
-
hasError,
|
|
298
|
-
describedById,
|
|
299
|
-
...forwardedProps
|
|
300
|
-
})]
|
|
301
|
-
}), !chips && /*#__PURE__*/jsx("div", {
|
|
302
|
-
className: `${CLASSNAME}__input-wrapper`,
|
|
303
|
-
children: renderInputNative({
|
|
304
|
-
id: textFieldId,
|
|
305
|
-
inputRef,
|
|
306
|
-
...disabledStateProps,
|
|
307
|
-
isRequired,
|
|
308
|
-
maxLength,
|
|
309
|
-
multiline,
|
|
310
|
-
onBlur,
|
|
311
|
-
onChange,
|
|
312
|
-
onFocus,
|
|
313
|
-
placeholder,
|
|
314
|
-
recomputeNumberOfRows,
|
|
315
|
-
rows,
|
|
316
|
-
setFocus,
|
|
317
|
-
type,
|
|
318
|
-
value,
|
|
319
|
-
name,
|
|
320
|
-
hasError,
|
|
321
|
-
describedById,
|
|
322
|
-
...forwardedProps
|
|
323
|
-
})
|
|
324
|
-
}), (isValid || hasError) && /*#__PURE__*/jsx(Icon, {
|
|
325
|
-
className: `${CLASSNAME}__input-validity`,
|
|
326
|
-
color: theme === Theme.dark ? 'light' : undefined,
|
|
327
|
-
icon: isValid ? mdiCheckCircle : mdiAlertCircle,
|
|
328
|
-
size: Size.xxs
|
|
329
|
-
}), clearButtonProps && isNotEmpty && !isAnyDisabled && /*#__PURE__*/jsx(IconButton, {
|
|
330
|
-
...clearButtonProps,
|
|
331
|
-
className: `${CLASSNAME}__input-clear`,
|
|
332
|
-
icon: mdiCloseCircle,
|
|
333
|
-
emphasis: Emphasis.low,
|
|
334
|
-
size: Size.s,
|
|
335
|
-
theme: theme,
|
|
336
|
-
onClick: handleClear,
|
|
337
|
-
type: "button"
|
|
338
|
-
}), afterElement && /*#__PURE__*/jsx("div", {
|
|
339
|
-
className: `${CLASSNAME}__after-element`,
|
|
340
|
-
children: afterElement
|
|
341
|
-
})]
|
|
342
|
-
}), hasError && error && /*#__PURE__*/jsx(InputHelper, {
|
|
343
|
-
className: `${CLASSNAME}__helper`,
|
|
344
|
-
kind: Kind.error,
|
|
345
|
-
theme: theme,
|
|
346
|
-
id: errorId,
|
|
347
|
-
children: error
|
|
348
|
-
}), helper && /*#__PURE__*/jsx(InputHelper, {
|
|
349
|
-
className: `${CLASSNAME}__helper`,
|
|
350
|
-
theme: theme,
|
|
351
|
-
id: helperId,
|
|
352
|
-
children: helper
|
|
353
|
-
})]
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
TextField.displayName = COMPONENT_NAME;
|
|
357
|
-
TextField.className = CLASSNAME;
|
|
358
|
-
TextField.defaultProps = DEFAULT_PROPS;
|
|
359
|
-
|
|
360
|
-
export { TextField };
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
export { T as Thumbnail, u as useFocusPointStyle } from '../../035c132d.js';
|
|
2
|
-
import { AspectRatio } from '@lumx/core/js/constants';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Focal point using vertical alignment, horizontal alignment or coordinates (from -1 to 1).
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Loading attribute is not yet supported in typescript, so we need
|
|
10
|
-
* to add it in order to avoid a ts error.
|
|
11
|
-
* https://github.com/typescript-cheatsheets/react-typescript-cheatsheet/blob/master/ADVANCED.md#adding-non-standard-attributes
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* All available aspect ratios.
|
|
16
|
-
* @deprecated
|
|
17
|
-
*/
|
|
18
|
-
const ThumbnailAspectRatio = {
|
|
19
|
-
...AspectRatio
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Thumbnail sizes.
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Thumbnail variants.
|
|
28
|
-
*/
|
|
29
|
-
const ThumbnailVariant = {
|
|
30
|
-
squared: 'squared',
|
|
31
|
-
rounded: 'rounded'
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Thumbnail object fit.
|
|
35
|
-
*/
|
|
36
|
-
const ThumbnailObjectFit = {
|
|
37
|
-
cover: 'cover',
|
|
38
|
-
contain: 'contain'
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export { ThumbnailAspectRatio, ThumbnailObjectFit, ThumbnailVariant };
|