@carbon/react 1.24.0-rc.0 → 1.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/components/ListBox/ListBoxMenuItem.d.ts +2 -2
- package/es/components/Menu/Menu.js +0 -4
- package/es/components/Menu/MenuContext.js +3 -6
- package/es/components/Popover/index.d.ts +51 -0
- package/es/components/Popover/index.js +28 -24
- package/es/components/Slider/Slider.Skeleton.d.ts +2 -2
- package/es/components/Slider/Slider.d.ts +355 -0
- package/es/components/Slider/Slider.js +63 -35
- package/es/components/TextInput/TextInput.d.ts +106 -0
- package/es/components/TextInput/TextInput.js +3 -2
- package/es/internal/useMergedRefs.d.ts +13 -0
- package/es/internal/useMergedRefs.js +2 -5
- package/es/internal/useNormalizedInputProps.js +1 -0
- package/lib/components/ListBox/ListBoxMenuItem.d.ts +2 -2
- package/lib/components/Menu/Menu.js +0 -4
- package/lib/components/Menu/MenuContext.js +3 -6
- package/lib/components/Popover/index.d.ts +51 -0
- package/lib/components/Popover/index.js +28 -24
- package/lib/components/Slider/Slider.Skeleton.d.ts +2 -2
- package/lib/components/Slider/Slider.d.ts +355 -0
- package/lib/components/Slider/Slider.js +62 -34
- package/lib/components/TextInput/TextInput.d.ts +106 -0
- package/lib/components/TextInput/TextInput.js +3 -2
- package/lib/internal/useMergedRefs.d.ts +13 -0
- package/lib/internal/useMergedRefs.js +2 -5
- package/lib/internal/useNormalizedInputProps.js +1 -0
- package/package.json +10 -10
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { KeyboardEventHandler, PureComponent } from 'react';
|
|
8
|
+
import PropTypes, { ReactNodeLike } from 'prop-types';
|
|
9
|
+
type ExcludedAttributes = 'onChange' | 'onBlur';
|
|
10
|
+
export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
|
|
11
|
+
/**
|
|
12
|
+
* The `ariaLabel` for the `<input>`.
|
|
13
|
+
*/
|
|
14
|
+
ariaLabelInput?: string;
|
|
15
|
+
/**
|
|
16
|
+
* The child nodes.
|
|
17
|
+
*/
|
|
18
|
+
children?: ReactNodeLike;
|
|
19
|
+
/**
|
|
20
|
+
* The CSS class name for the slider.
|
|
21
|
+
*/
|
|
22
|
+
className?: string;
|
|
23
|
+
/**
|
|
24
|
+
* `true` to disable this slider.
|
|
25
|
+
*/
|
|
26
|
+
disabled?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* The callback to format the label associated with the minimum/maximum value.
|
|
29
|
+
*/
|
|
30
|
+
formatLabel?: (value: number, label: string | undefined) => string;
|
|
31
|
+
/**
|
|
32
|
+
* `true` to hide the number input box.
|
|
33
|
+
*/
|
|
34
|
+
hideTextInput?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The ID of the `<input>`.
|
|
37
|
+
*/
|
|
38
|
+
id?: string;
|
|
39
|
+
/**
|
|
40
|
+
* The `type` attribute of the `<input>`.
|
|
41
|
+
*/
|
|
42
|
+
inputType?: string;
|
|
43
|
+
/**
|
|
44
|
+
* `true` to specify if the control is invalid.
|
|
45
|
+
*/
|
|
46
|
+
invalid?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The label for the slider.
|
|
49
|
+
*/
|
|
50
|
+
labelText?: ReactNodeLike;
|
|
51
|
+
/**
|
|
52
|
+
* @deprecated
|
|
53
|
+
* `true` to use the light version.
|
|
54
|
+
*/
|
|
55
|
+
light?: boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The maximum value.
|
|
58
|
+
*/
|
|
59
|
+
max: number;
|
|
60
|
+
/**
|
|
61
|
+
* The label associated with the maximum value.
|
|
62
|
+
*/
|
|
63
|
+
maxLabel?: string;
|
|
64
|
+
/**
|
|
65
|
+
* The minimum value.
|
|
66
|
+
*/
|
|
67
|
+
min: number;
|
|
68
|
+
/**
|
|
69
|
+
* The label associated with the minimum value.
|
|
70
|
+
*/
|
|
71
|
+
minLabel?: string;
|
|
72
|
+
/**
|
|
73
|
+
* The `name` attribute of the `<input>`.
|
|
74
|
+
*/
|
|
75
|
+
name?: string;
|
|
76
|
+
/**
|
|
77
|
+
* Provide an optional function to be called when the input element
|
|
78
|
+
* loses focus
|
|
79
|
+
*/
|
|
80
|
+
onBlur?: (data: {
|
|
81
|
+
value: string;
|
|
82
|
+
}) => void;
|
|
83
|
+
/**
|
|
84
|
+
* The callback to get notified of change in value.
|
|
85
|
+
* `({ value}) => void`
|
|
86
|
+
// * @param {{ value }}
|
|
87
|
+
*/
|
|
88
|
+
onChange?: (data: {
|
|
89
|
+
value: SliderProps['value'];
|
|
90
|
+
}) => void;
|
|
91
|
+
/**
|
|
92
|
+
* Provide an optional function to be called when a key is pressed in the number input
|
|
93
|
+
*/
|
|
94
|
+
onInputKeyUp?: KeyboardEventHandler<HTMLInputElement>;
|
|
95
|
+
/**
|
|
96
|
+
* The callback to get notified of value on handle release.
|
|
97
|
+
*/
|
|
98
|
+
onRelease?: (data: {
|
|
99
|
+
value: SliderProps['value'];
|
|
100
|
+
}) => void;
|
|
101
|
+
/**
|
|
102
|
+
* Whether the slider should be read-only
|
|
103
|
+
*/
|
|
104
|
+
readOnly?: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* `true` to specify if the control is required.
|
|
107
|
+
*/
|
|
108
|
+
required?: boolean;
|
|
109
|
+
/**
|
|
110
|
+
* A value determining how much the value should increase/decrease by moving the thumb by mouse. If a value other than 1 is provided and the input is *not* hidden, the new step requirement should be added to a visible label. Values outside of the `step` increment will be considered invalid.
|
|
111
|
+
*/
|
|
112
|
+
step?: number;
|
|
113
|
+
/**
|
|
114
|
+
* A value determining how much the value should increase/decrease by Shift+arrow keys,
|
|
115
|
+
* which will be `(max - min) / stepMultiplier`.
|
|
116
|
+
*/
|
|
117
|
+
stepMultiplier?: number;
|
|
118
|
+
/**
|
|
119
|
+
* The value.
|
|
120
|
+
*/
|
|
121
|
+
value: number;
|
|
122
|
+
}
|
|
123
|
+
interface CalcValueProps {
|
|
124
|
+
clientX?: number;
|
|
125
|
+
value?: number;
|
|
126
|
+
useRawValue?: boolean;
|
|
127
|
+
}
|
|
128
|
+
export default class Slider extends PureComponent<SliderProps> {
|
|
129
|
+
static propTypes: {
|
|
130
|
+
/**
|
|
131
|
+
* The `ariaLabel` for the `<input>`.
|
|
132
|
+
*/
|
|
133
|
+
ariaLabelInput: PropTypes.Requireable<string>;
|
|
134
|
+
/**
|
|
135
|
+
* The child nodes.
|
|
136
|
+
*/
|
|
137
|
+
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
138
|
+
/**
|
|
139
|
+
* The CSS class name for the slider.
|
|
140
|
+
*/
|
|
141
|
+
className: PropTypes.Requireable<string>;
|
|
142
|
+
/**
|
|
143
|
+
* `true` to disable this slider.
|
|
144
|
+
*/
|
|
145
|
+
disabled: PropTypes.Requireable<boolean>;
|
|
146
|
+
/**
|
|
147
|
+
* The callback to format the label associated with the minimum/maximum value.
|
|
148
|
+
*/
|
|
149
|
+
formatLabel: PropTypes.Requireable<(...args: any[]) => any>;
|
|
150
|
+
/**
|
|
151
|
+
* `true` to hide the number input box.
|
|
152
|
+
*/
|
|
153
|
+
hideTextInput: PropTypes.Requireable<boolean>;
|
|
154
|
+
/**
|
|
155
|
+
* The ID of the `<input>`.
|
|
156
|
+
*/
|
|
157
|
+
id: PropTypes.Requireable<string>;
|
|
158
|
+
/**
|
|
159
|
+
* The `type` attribute of the `<input>`.
|
|
160
|
+
*/
|
|
161
|
+
inputType: PropTypes.Requireable<string>;
|
|
162
|
+
/**
|
|
163
|
+
* `true` to specify if the control is invalid.
|
|
164
|
+
*/
|
|
165
|
+
invalid: PropTypes.Requireable<boolean>;
|
|
166
|
+
/**
|
|
167
|
+
* The label for the slider.
|
|
168
|
+
*/
|
|
169
|
+
labelText: PropTypes.Requireable<PropTypes.ReactNodeLike>;
|
|
170
|
+
/**
|
|
171
|
+
* `true` to use the light version.
|
|
172
|
+
*/
|
|
173
|
+
light: (props: any, propName: any, componentName: any, ...rest: any[]) => any;
|
|
174
|
+
/**
|
|
175
|
+
* The maximum value.
|
|
176
|
+
*/
|
|
177
|
+
max: PropTypes.Validator<number>;
|
|
178
|
+
/**
|
|
179
|
+
* The label associated with the maximum value.
|
|
180
|
+
*/
|
|
181
|
+
maxLabel: PropTypes.Requireable<string>;
|
|
182
|
+
/**
|
|
183
|
+
* The minimum value.
|
|
184
|
+
*/
|
|
185
|
+
min: PropTypes.Validator<number>;
|
|
186
|
+
/**
|
|
187
|
+
* The label associated with the minimum value.
|
|
188
|
+
*/
|
|
189
|
+
minLabel: PropTypes.Requireable<string>;
|
|
190
|
+
/**
|
|
191
|
+
* The `name` attribute of the `<input>`.
|
|
192
|
+
*/
|
|
193
|
+
name: PropTypes.Requireable<string>;
|
|
194
|
+
/**
|
|
195
|
+
* Provide an optional function to be called when the input element
|
|
196
|
+
* loses focus
|
|
197
|
+
*/
|
|
198
|
+
onBlur: PropTypes.Requireable<(...args: any[]) => any>;
|
|
199
|
+
/**
|
|
200
|
+
* The callback to get notified of change in value.
|
|
201
|
+
*/
|
|
202
|
+
onChange: PropTypes.Requireable<(...args: any[]) => any>;
|
|
203
|
+
/**
|
|
204
|
+
* Provide an optional function to be called when a key is pressed in the number input
|
|
205
|
+
*/
|
|
206
|
+
onInputKeyUp: PropTypes.Requireable<(...args: any[]) => any>;
|
|
207
|
+
/**
|
|
208
|
+
* The callback to get notified of value on handle release.
|
|
209
|
+
*/
|
|
210
|
+
onRelease: PropTypes.Requireable<(...args: any[]) => any>;
|
|
211
|
+
/**
|
|
212
|
+
* Whether the slider should be read-only
|
|
213
|
+
*/
|
|
214
|
+
readOnly: PropTypes.Requireable<boolean>;
|
|
215
|
+
/**
|
|
216
|
+
* `true` to specify if the control is required.
|
|
217
|
+
*/
|
|
218
|
+
required: PropTypes.Requireable<boolean>;
|
|
219
|
+
/**
|
|
220
|
+
* A value determining how much the value should increase/decrease by moving the thumb by mouse. If a value other than 1 is provided and the input is *not* hidden, the new step requirement should be added to a visible label. Values outside of the `step` increment will be considered invalid.
|
|
221
|
+
*/
|
|
222
|
+
step: PropTypes.Requireable<number>;
|
|
223
|
+
/**
|
|
224
|
+
* A value determining how much the value should increase/decrease by Shift+arrow keys,
|
|
225
|
+
* which will be `(max - min) / stepMultiplier`.
|
|
226
|
+
*/
|
|
227
|
+
stepMultiplier: PropTypes.Requireable<number>;
|
|
228
|
+
/**
|
|
229
|
+
* The value.
|
|
230
|
+
*/
|
|
231
|
+
value: PropTypes.Validator<number>;
|
|
232
|
+
};
|
|
233
|
+
static defaultProps: {
|
|
234
|
+
hideTextInput: boolean;
|
|
235
|
+
step: number;
|
|
236
|
+
stepMultiplier: number;
|
|
237
|
+
disabled: boolean;
|
|
238
|
+
minLabel: string;
|
|
239
|
+
maxLabel: string;
|
|
240
|
+
inputType: string;
|
|
241
|
+
ariaLabelInput: string | undefined;
|
|
242
|
+
readOnly: boolean;
|
|
243
|
+
};
|
|
244
|
+
static contextType: React.Context<any>;
|
|
245
|
+
state: {
|
|
246
|
+
value: number;
|
|
247
|
+
left: number;
|
|
248
|
+
needsOnRelease: boolean;
|
|
249
|
+
isValid: boolean;
|
|
250
|
+
};
|
|
251
|
+
thumbRef: React.RefObject<HTMLDivElement>;
|
|
252
|
+
filledTrackRef: React.RefObject<HTMLDivElement>;
|
|
253
|
+
element: HTMLDivElement | null;
|
|
254
|
+
inputId: string;
|
|
255
|
+
track: HTMLDivElement | null | undefined;
|
|
256
|
+
constructor(props: any);
|
|
257
|
+
/**
|
|
258
|
+
* Sets up initial slider position and value in response to component mount.
|
|
259
|
+
*/
|
|
260
|
+
componentDidMount(): void;
|
|
261
|
+
/**
|
|
262
|
+
* Handles firing of `onChange` and `onRelease` callbacks to parent in
|
|
263
|
+
* response to state changes.
|
|
264
|
+
*
|
|
265
|
+
* @param {*} prevProps prevProps
|
|
266
|
+
* @param {*} prevState The previous Slider state, used to see if callbacks
|
|
267
|
+
* should be called.
|
|
268
|
+
*/
|
|
269
|
+
componentDidUpdate(prevProps: any, prevState: any): void;
|
|
270
|
+
/**
|
|
271
|
+
* Synonymous to ECMA2017+ `Math.clamp`.
|
|
272
|
+
*
|
|
273
|
+
* @param {number} val
|
|
274
|
+
* @param {number} min
|
|
275
|
+
* @param {number} max
|
|
276
|
+
*
|
|
277
|
+
* @returns `val` if `max>=val>=min`; `min` if `val<min`; `max` if `val>max`.
|
|
278
|
+
*/
|
|
279
|
+
clamp(val: any, min: any, max: any): number;
|
|
280
|
+
/**
|
|
281
|
+
* Sets up "drag" event handlers and calls `this.onDrag` in case dragging
|
|
282
|
+
* started on somewhere other than the thumb without a corresponding "move"
|
|
283
|
+
* event.
|
|
284
|
+
*
|
|
285
|
+
* @param {Event} evt The event.
|
|
286
|
+
*/
|
|
287
|
+
onDragStart: (evt: any) => void;
|
|
288
|
+
/**
|
|
289
|
+
* Unregisters "drag" and "drag stop" event handlers and calls sets the flag
|
|
290
|
+
* indicating that the `onRelease` callback should be called.
|
|
291
|
+
*/
|
|
292
|
+
onDragStop: () => void;
|
|
293
|
+
/**
|
|
294
|
+
* Handles a "drag" event by recalculating the value/thumb and setting state
|
|
295
|
+
* accordingly.
|
|
296
|
+
*
|
|
297
|
+
* @param {Event} evt The event.
|
|
298
|
+
*/
|
|
299
|
+
_onDrag: (evt: any) => void;
|
|
300
|
+
/**
|
|
301
|
+
* Throttles calls to `this._onDrag` by limiting events to being processed at
|
|
302
|
+
* most once every `EVENT_THROTTLE` milliseconds.
|
|
303
|
+
*/
|
|
304
|
+
onDrag: any;
|
|
305
|
+
/**
|
|
306
|
+
* Handles a `keydown` event by recalculating the value/thumb and setting
|
|
307
|
+
* state accordingly.
|
|
308
|
+
*
|
|
309
|
+
* @param {Event} evt The event.
|
|
310
|
+
*/
|
|
311
|
+
onKeyDown: (evt: any) => void;
|
|
312
|
+
/**
|
|
313
|
+
* Provides the two-way binding for the input field of the Slider. It also
|
|
314
|
+
* Handles a change to the input field by recalculating the value/thumb and
|
|
315
|
+
* setting state accordingly.
|
|
316
|
+
*
|
|
317
|
+
* @param {Event} evt The event.
|
|
318
|
+
*/
|
|
319
|
+
onChange: (evt: any) => void;
|
|
320
|
+
/**
|
|
321
|
+
* Checks for validity of input value after clicking out of the input. It also
|
|
322
|
+
* Handles state change to isValid state.
|
|
323
|
+
*
|
|
324
|
+
* @param {Event} evt The event.
|
|
325
|
+
*/
|
|
326
|
+
onBlur: (evt: React.FocusEvent<HTMLInputElement>) => void;
|
|
327
|
+
/**
|
|
328
|
+
* Calculates a new Slider `value` and `left` (thumb offset) given a `clientX`,
|
|
329
|
+
* `value`, or neither of those.
|
|
330
|
+
* - If `clientX` is specified, it will be used in
|
|
331
|
+
* conjunction with the Slider's bounding rectangle to calculate the new
|
|
332
|
+
* values.
|
|
333
|
+
* - If `clientX` is not specified and `value` is, it will be used to
|
|
334
|
+
* calculate new values as though it were the current value of the Slider.
|
|
335
|
+
* - If neither `clientX` nor `value` are specified, `this.props.value` will
|
|
336
|
+
* be used to calculate the new values as though it were the current value
|
|
337
|
+
* of the Slider.
|
|
338
|
+
*
|
|
339
|
+
* @param {object} params
|
|
340
|
+
* @param {number} [params.clientX] Optional clientX value expected to be from
|
|
341
|
+
* an event fired by one of the Slider's `DRAG_EVENT_TYPES` events.
|
|
342
|
+
* @param {number} [params.value] Optional value use during calculations if
|
|
343
|
+
* clientX is not provided.
|
|
344
|
+
* @param {boolean} [params.useRawValue=false] `true` to use the given value as-is.
|
|
345
|
+
*/
|
|
346
|
+
calcValue: ({ clientX, value, useRawValue }: CalcValueProps) => {
|
|
347
|
+
value: number | undefined;
|
|
348
|
+
left: number;
|
|
349
|
+
};
|
|
350
|
+
static getDerivedStateFromProps(props: any, state: any): {
|
|
351
|
+
isValid: boolean;
|
|
352
|
+
} | null;
|
|
353
|
+
render(): JSX.Element;
|
|
354
|
+
}
|
|
355
|
+
export {};
|
|
@@ -89,6 +89,16 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
89
89
|
isValid: true
|
|
90
90
|
});
|
|
91
91
|
|
|
92
|
+
_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.assertThisInitialized(_this), "thumbRef", void 0);
|
|
93
|
+
|
|
94
|
+
_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.assertThisInitialized(_this), "filledTrackRef", void 0);
|
|
95
|
+
|
|
96
|
+
_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.assertThisInitialized(_this), "element", null);
|
|
97
|
+
|
|
98
|
+
_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.assertThisInitialized(_this), "inputId", '');
|
|
99
|
+
|
|
100
|
+
_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.assertThisInitialized(_this), "track", void 0);
|
|
101
|
+
|
|
92
102
|
_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.assertThisInitialized(_this), "onDragStart", function (evt) {
|
|
93
103
|
// Do nothing if component is disabled
|
|
94
104
|
if (_this.props.disabled || _this.props.readOnly) {
|
|
@@ -97,11 +107,15 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
97
107
|
|
|
98
108
|
|
|
99
109
|
DRAG_STOP_EVENT_TYPES.forEach(function (element) {
|
|
100
|
-
_this
|
|
110
|
+
var _this$element;
|
|
111
|
+
|
|
112
|
+
(_this$element = _this.element) === null || _this$element === void 0 ? void 0 : _this$element.ownerDocument.addEventListener(element, _this.onDragStop);
|
|
101
113
|
}); // Register drag handlers
|
|
102
114
|
|
|
103
115
|
DRAG_EVENT_TYPES.forEach(function (element) {
|
|
104
|
-
|
|
116
|
+
var _this$element2;
|
|
117
|
+
|
|
118
|
+
(_this$element2 = _this.element) === null || _this$element2 === void 0 ? void 0 : _this$element2.ownerDocument.addEventListener(element, _this.onDrag);
|
|
105
119
|
}); // Perform first recalculation since we probably didn't click exactly in the
|
|
106
120
|
// middle of the thumb
|
|
107
121
|
|
|
@@ -116,11 +130,15 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
116
130
|
|
|
117
131
|
|
|
118
132
|
DRAG_STOP_EVENT_TYPES.forEach(function (element) {
|
|
119
|
-
|
|
133
|
+
var _this$element3;
|
|
134
|
+
|
|
135
|
+
(_this$element3 = _this.element) === null || _this$element3 === void 0 ? void 0 : _this$element3.ownerDocument.removeEventListener(element, _this.onDragStop);
|
|
120
136
|
}); // Remove drag handlers
|
|
121
137
|
|
|
122
138
|
DRAG_EVENT_TYPES.forEach(function (element) {
|
|
123
|
-
|
|
139
|
+
var _this$element4;
|
|
140
|
+
|
|
141
|
+
(_this$element4 = _this.element) === null || _this$element4 === void 0 ? void 0 : _this$element4.ownerDocument.removeEventListener(element, _this.onDrag);
|
|
124
142
|
}); // Set needsOnRelease flag so event fires on next update
|
|
125
143
|
|
|
126
144
|
_this.setState({
|
|
@@ -165,18 +183,23 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
165
183
|
}));
|
|
166
184
|
|
|
167
185
|
_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.assertThisInitialized(_this), "onKeyDown", function (evt) {
|
|
186
|
+
var _this$props$step3, _this$props$step4, _this$props$step5, _this$props$step6;
|
|
187
|
+
|
|
168
188
|
// Do nothing if component is disabled or we don't have a valid event
|
|
169
189
|
if (_this.props.disabled || _this.props.readOnly || !('which' in evt)) {
|
|
170
190
|
return;
|
|
171
191
|
}
|
|
172
192
|
|
|
173
|
-
var which = Number.parseInt(evt.which);
|
|
174
193
|
var delta = 0;
|
|
175
194
|
|
|
176
|
-
if (match.matches(which, [keys.ArrowDown, keys.ArrowLeft])) {
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
delta = _this.props.step;
|
|
195
|
+
if (match.matches(evt.which, [keys.ArrowDown, keys.ArrowLeft])) {
|
|
196
|
+
var _this$props$step;
|
|
197
|
+
|
|
198
|
+
delta = -((_this$props$step = _this.props.step) !== null && _this$props$step !== void 0 ? _this$props$step : Slider.defaultProps.step);
|
|
199
|
+
} else if (match.matches(evt.which, [keys.ArrowUp, keys.ArrowRight])) {
|
|
200
|
+
var _this$props$step2;
|
|
201
|
+
|
|
202
|
+
delta = (_this$props$step2 = _this.props.step) !== null && _this$props$step2 !== void 0 ? _this$props$step2 : Slider.defaultProps.step;
|
|
180
203
|
} else {
|
|
181
204
|
// Ignore keys we don't want to handle
|
|
182
205
|
return;
|
|
@@ -185,15 +208,15 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
185
208
|
|
|
186
209
|
if (evt.shiftKey) {
|
|
187
210
|
var stepMultiplier = _this.props.stepMultiplier;
|
|
188
|
-
delta *= stepMultiplier;
|
|
211
|
+
delta *= stepMultiplier !== null && stepMultiplier !== void 0 ? stepMultiplier : Slider.defaultProps.stepMultiplier;
|
|
189
212
|
}
|
|
190
213
|
|
|
191
|
-
Math.floor(_this.state.value / _this.props.step) * _this.props.step;
|
|
214
|
+
Math.floor(_this.state.value / ((_this$props$step3 = _this.props.step) !== null && _this$props$step3 !== void 0 ? _this$props$step3 : Slider.defaultProps.step)) * ((_this$props$step4 = _this.props.step) !== null && _this$props$step4 !== void 0 ? _this$props$step4 : Slider.defaultProps.step);
|
|
192
215
|
|
|
193
216
|
var _this$calcValue2 = _this.calcValue({
|
|
194
217
|
// Ensures custom value from `<input>` won't cause skipping next stepping point with right arrow key,
|
|
195
218
|
// e.g. Typing 51 in `<input>`, moving focus onto the thumb and the hitting right arrow key should yield 52 instead of 54
|
|
196
|
-
value: (delta > 0 ? Math.floor(_this.state.value / _this.props.step) * _this.props.step : _this.state.value) + delta
|
|
219
|
+
value: (delta > 0 ? Math.floor(_this.state.value / ((_this$props$step5 = _this.props.step) !== null && _this$props$step5 !== void 0 ? _this$props$step5 : Slider.defaultProps.step)) * ((_this$props$step6 = _this.props.step) !== null && _this$props$step6 !== void 0 ? _this$props$step6 : Slider.defaultProps.step) : _this.state.value) + delta
|
|
197
220
|
}),
|
|
198
221
|
value = _this$calcValue2.value,
|
|
199
222
|
left = _this$calcValue2.left;
|
|
@@ -227,11 +250,11 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
227
250
|
value: targetValue,
|
|
228
251
|
useRawValue: true
|
|
229
252
|
}),
|
|
230
|
-
|
|
253
|
+
_value = _this$calcValue3.value,
|
|
231
254
|
left = _this$calcValue3.left;
|
|
232
255
|
|
|
233
256
|
_this.setState({
|
|
234
|
-
value:
|
|
257
|
+
value: _value,
|
|
235
258
|
left: left
|
|
236
259
|
});
|
|
237
260
|
}
|
|
@@ -259,18 +282,16 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
259
282
|
});
|
|
260
283
|
|
|
261
284
|
_rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.assertThisInitialized(_this), "calcValue", function (_ref) {
|
|
262
|
-
var
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
value = _ref
|
|
285
|
+
var _this$element5, _this$element5$getBou, _this$props$step7, _this$props$step8;
|
|
286
|
+
|
|
287
|
+
var clientX = _ref.clientX,
|
|
288
|
+
value = _ref.value,
|
|
266
289
|
_ref$useRawValue = _ref.useRawValue,
|
|
267
290
|
useRawValue = _ref$useRawValue === void 0 ? false : _ref$useRawValue;
|
|
268
291
|
var range = _this.props.max - _this.props.min;
|
|
269
|
-
|
|
270
|
-
var
|
|
271
|
-
|
|
272
|
-
var totalSteps = range / _this.props.step;
|
|
273
|
-
var width = boundingRect.right - boundingRect.left; // Enforce a minimum width of at least 1 for calculations
|
|
292
|
+
var boundingRect = (_this$element5 = _this.element) === null || _this$element5 === void 0 ? void 0 : (_this$element5$getBou = _this$element5.getBoundingClientRect) === null || _this$element5$getBou === void 0 ? void 0 : _this$element5$getBou.call(_this$element5);
|
|
293
|
+
var totalSteps = range / ((_this$props$step7 = _this.props.step) !== null && _this$props$step7 !== void 0 ? _this$props$step7 : Slider.defaultProps.step);
|
|
294
|
+
var width = boundingRect ? boundingRect.right - boundingRect.left : 0; // Enforce a minimum width of at least 1 for calculations
|
|
274
295
|
|
|
275
296
|
if (width <= 0) {
|
|
276
297
|
width = 1;
|
|
@@ -281,7 +302,9 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
281
302
|
var leftPercent;
|
|
282
303
|
|
|
283
304
|
if (clientX != null) {
|
|
284
|
-
var
|
|
305
|
+
var _boundingRect$left;
|
|
306
|
+
|
|
307
|
+
var leftOffset = clientX - ((_boundingRect$left = boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.left) !== null && _boundingRect$left !== void 0 ? _boundingRect$left : 0);
|
|
285
308
|
leftPercent = leftOffset / width;
|
|
286
309
|
} else {
|
|
287
310
|
if (value == null) {
|
|
@@ -300,7 +323,7 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
300
323
|
};
|
|
301
324
|
}
|
|
302
325
|
|
|
303
|
-
var steppedValue = Math.round(leftPercent * totalSteps) * _this.props.step;
|
|
326
|
+
var steppedValue = Math.round(leftPercent * totalSteps) * ((_this$props$step8 = _this.props.step) !== null && _this$props$step8 !== void 0 ? _this$props$step8 : Slider.defaultProps.step);
|
|
304
327
|
|
|
305
328
|
var steppedPercent = _this.clamp(steppedValue / range, 0, 1);
|
|
306
329
|
|
|
@@ -327,11 +350,11 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
327
350
|
var _this$calcValue4 = this.calcValue({
|
|
328
351
|
useRawValue: true
|
|
329
352
|
}),
|
|
330
|
-
|
|
353
|
+
_value2 = _this$calcValue4.value,
|
|
331
354
|
left = _this$calcValue4.left;
|
|
332
355
|
|
|
333
356
|
this.setState({
|
|
334
|
-
value:
|
|
357
|
+
value: _value2,
|
|
335
358
|
left: left
|
|
336
359
|
});
|
|
337
360
|
}
|
|
@@ -350,10 +373,15 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
350
373
|
value: function componentDidUpdate(prevProps, prevState) {
|
|
351
374
|
// Fire onChange event handler if present, if there's a usable value, and
|
|
352
375
|
// if the value is different from the last one
|
|
353
|
-
this.thumbRef.current
|
|
354
|
-
|
|
376
|
+
if (this.thumbRef.current) {
|
|
377
|
+
this.thumbRef.current.style.left = "".concat(this.state.left, "%");
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (this.filledTrackRef.current) {
|
|
381
|
+
this.filledTrackRef.current.style.transform = "translate(0%, -50%) scaleX(".concat(this.state.left / 100, ")");
|
|
382
|
+
}
|
|
355
383
|
|
|
356
|
-
if (
|
|
384
|
+
if (prevState.value !== this.state.value && typeof this.props.onChange === 'function') {
|
|
357
385
|
this.props.onChange({
|
|
358
386
|
value: this.state.value
|
|
359
387
|
});
|
|
@@ -498,8 +526,8 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
498
526
|
name: name,
|
|
499
527
|
className: inputClasses,
|
|
500
528
|
value: value,
|
|
501
|
-
"aria-labelledby": !ariaLabelInput ? labelId :
|
|
502
|
-
"aria-label": ariaLabelInput ? ariaLabelInput :
|
|
529
|
+
"aria-labelledby": !ariaLabelInput ? labelId : undefined,
|
|
530
|
+
"aria-label": ariaLabelInput ? ariaLabelInput : undefined,
|
|
503
531
|
disabled: disabled,
|
|
504
532
|
required: required,
|
|
505
533
|
min: min,
|
|
@@ -507,9 +535,9 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
|
|
|
507
535
|
step: step,
|
|
508
536
|
onChange: _this2.onChange,
|
|
509
537
|
onBlur: _this2.onBlur,
|
|
510
|
-
onKeyUp: _this2.onInputKeyUp,
|
|
538
|
+
onKeyUp: _this2.props.onInputKeyUp,
|
|
511
539
|
"data-invalid": isValid ? null : true,
|
|
512
|
-
"aria-invalid": isValid ?
|
|
540
|
+
"aria-invalid": isValid ? undefined : true,
|
|
513
541
|
readOnly: readOnly
|
|
514
542
|
})));
|
|
515
543
|
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright IBM Corp. 2016, 2023
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the Apache-2.0 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
import React, { ReactNode } from 'react';
|
|
8
|
+
type ExcludedAttributes = 'defaultValue' | 'id' | 'size' | 'value';
|
|
9
|
+
export interface TextInputProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, ExcludedAttributes> {
|
|
10
|
+
/**
|
|
11
|
+
* Specify an optional className to be applied to the `<input>` node
|
|
12
|
+
*/
|
|
13
|
+
className?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Optionally provide the default value of the `<input>`
|
|
16
|
+
*/
|
|
17
|
+
defaultValue?: string | number;
|
|
18
|
+
/**
|
|
19
|
+
* Specify whether the `<input>` should be disabled
|
|
20
|
+
*/
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Specify whether to display the character counter
|
|
24
|
+
*/
|
|
25
|
+
enableCounter?: boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Provide text that is used alongside the control label for additional help
|
|
28
|
+
*/
|
|
29
|
+
helperText?: ReactNode;
|
|
30
|
+
/**
|
|
31
|
+
* Specify whether you want the underlying label to be visually hidden
|
|
32
|
+
*/
|
|
33
|
+
hideLabel?: boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Specify a custom `id` for the `<input>`
|
|
36
|
+
*/
|
|
37
|
+
id: string;
|
|
38
|
+
/**
|
|
39
|
+
* `true` to use the inline version.
|
|
40
|
+
*/
|
|
41
|
+
inline?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Specify whether the control is currently invalid
|
|
44
|
+
*/
|
|
45
|
+
invalid?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Provide the text that is displayed when the control is in an invalid state
|
|
48
|
+
*/
|
|
49
|
+
invalidText?: ReactNode;
|
|
50
|
+
/**
|
|
51
|
+
* Provide the text that will be read by a screen reader when visiting this
|
|
52
|
+
* control
|
|
53
|
+
*/
|
|
54
|
+
labelText: ReactNode;
|
|
55
|
+
/**
|
|
56
|
+
* `true` to use the light version. For use on $ui-01 backgrounds only.
|
|
57
|
+
* Don't use this to make tile background color same as container background color.
|
|
58
|
+
* 'The `light` prop for `TextInput` has ' +
|
|
59
|
+
'been deprecated in favor of the new `Layer` component. It will be removed in the next major release.'
|
|
60
|
+
*/
|
|
61
|
+
light?: boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Max character count allowed for the input. This is needed in order for enableCounter to display
|
|
64
|
+
*/
|
|
65
|
+
maxCount?: number;
|
|
66
|
+
/**
|
|
67
|
+
* Optionally provide an `onChange` handler that is called whenever `<input>`
|
|
68
|
+
* is updated
|
|
69
|
+
*/
|
|
70
|
+
onChange?: (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
71
|
+
/**
|
|
72
|
+
* Optionally provide an `onClick` handler that is called whenever the
|
|
73
|
+
* `<input>` is clicked
|
|
74
|
+
*/
|
|
75
|
+
onClick?: (event: React.MouseEvent<HTMLElement>) => void;
|
|
76
|
+
/**
|
|
77
|
+
* Specify the placeholder attribute for the `<input>`
|
|
78
|
+
*/
|
|
79
|
+
placeholder?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Whether the input should be read-only
|
|
82
|
+
*/
|
|
83
|
+
readOnly?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Specify the size of the Text Input. Currently supports the following:
|
|
86
|
+
*/
|
|
87
|
+
size?: 'sm' | 'md' | 'lg' | 'xl';
|
|
88
|
+
/**
|
|
89
|
+
* Specify the type of the `<input>`
|
|
90
|
+
*/
|
|
91
|
+
type?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Specify the value of the `<input>`
|
|
94
|
+
*/
|
|
95
|
+
value?: string | number | undefined;
|
|
96
|
+
/**
|
|
97
|
+
* Specify whether the control is currently in warning state
|
|
98
|
+
*/
|
|
99
|
+
warn?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Provide the text that is displayed when the control is in warning state
|
|
102
|
+
*/
|
|
103
|
+
warnText?: ReactNode;
|
|
104
|
+
}
|
|
105
|
+
declare const TextInput: React.ForwardRefExoticComponent<TextInputProps & React.RefAttributes<unknown>>;
|
|
106
|
+
export default TextInput;
|