@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.
@@ -5,7 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { inherits as _inherits, createSuper as _createSuper, classCallCheck as _classCallCheck, defineProperty as _defineProperty, assertThisInitialized as _assertThisInitialized, createClass as _createClass, objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
8
+ import { defineProperty as _defineProperty, inherits as _inherits, createSuper as _createSuper, classCallCheck as _classCallCheck, assertThisInitialized as _assertThisInitialized, createClass as _createClass, objectWithoutProperties as _objectWithoutProperties, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import React__default, { PureComponent } from 'react';
10
10
  import PropTypes from 'prop-types';
11
11
  import cx from 'classnames';
@@ -59,6 +59,16 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
59
59
  isValid: true
60
60
  });
61
61
 
62
+ _defineProperty(_assertThisInitialized(_this), "thumbRef", void 0);
63
+
64
+ _defineProperty(_assertThisInitialized(_this), "filledTrackRef", void 0);
65
+
66
+ _defineProperty(_assertThisInitialized(_this), "element", null);
67
+
68
+ _defineProperty(_assertThisInitialized(_this), "inputId", '');
69
+
70
+ _defineProperty(_assertThisInitialized(_this), "track", void 0);
71
+
62
72
  _defineProperty(_assertThisInitialized(_this), "onDragStart", function (evt) {
63
73
  // Do nothing if component is disabled
64
74
  if (_this.props.disabled || _this.props.readOnly) {
@@ -67,11 +77,15 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
67
77
 
68
78
 
69
79
  DRAG_STOP_EVENT_TYPES.forEach(function (element) {
70
- _this.element.ownerDocument.addEventListener(element, _this.onDragStop);
80
+ var _this$element;
81
+
82
+ (_this$element = _this.element) === null || _this$element === void 0 ? void 0 : _this$element.ownerDocument.addEventListener(element, _this.onDragStop);
71
83
  }); // Register drag handlers
72
84
 
73
85
  DRAG_EVENT_TYPES.forEach(function (element) {
74
- _this.element.ownerDocument.addEventListener(element, _this.onDrag);
86
+ var _this$element2;
87
+
88
+ (_this$element2 = _this.element) === null || _this$element2 === void 0 ? void 0 : _this$element2.ownerDocument.addEventListener(element, _this.onDrag);
75
89
  }); // Perform first recalculation since we probably didn't click exactly in the
76
90
  // middle of the thumb
77
91
 
@@ -86,11 +100,15 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
86
100
 
87
101
 
88
102
  DRAG_STOP_EVENT_TYPES.forEach(function (element) {
89
- _this.element.ownerDocument.removeEventListener(element, _this.onDragStop);
103
+ var _this$element3;
104
+
105
+ (_this$element3 = _this.element) === null || _this$element3 === void 0 ? void 0 : _this$element3.ownerDocument.removeEventListener(element, _this.onDragStop);
90
106
  }); // Remove drag handlers
91
107
 
92
108
  DRAG_EVENT_TYPES.forEach(function (element) {
93
- _this.element.ownerDocument.removeEventListener(element, _this.onDrag);
109
+ var _this$element4;
110
+
111
+ (_this$element4 = _this.element) === null || _this$element4 === void 0 ? void 0 : _this$element4.ownerDocument.removeEventListener(element, _this.onDrag);
94
112
  }); // Set needsOnRelease flag so event fires on next update
95
113
 
96
114
  _this.setState({
@@ -135,18 +153,23 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
135
153
  }));
136
154
 
137
155
  _defineProperty(_assertThisInitialized(_this), "onKeyDown", function (evt) {
156
+ var _this$props$step3, _this$props$step4, _this$props$step5, _this$props$step6;
157
+
138
158
  // Do nothing if component is disabled or we don't have a valid event
139
159
  if (_this.props.disabled || _this.props.readOnly || !('which' in evt)) {
140
160
  return;
141
161
  }
142
162
 
143
- var which = Number.parseInt(evt.which);
144
163
  var delta = 0;
145
164
 
146
- if (matches(which, [ArrowDown, ArrowLeft])) {
147
- delta = -_this.props.step;
148
- } else if (matches(which, [ArrowUp, ArrowRight])) {
149
- delta = _this.props.step;
165
+ if (matches(evt.which, [ArrowDown, ArrowLeft])) {
166
+ var _this$props$step;
167
+
168
+ delta = -((_this$props$step = _this.props.step) !== null && _this$props$step !== void 0 ? _this$props$step : Slider.defaultProps.step);
169
+ } else if (matches(evt.which, [ArrowUp, ArrowRight])) {
170
+ var _this$props$step2;
171
+
172
+ delta = (_this$props$step2 = _this.props.step) !== null && _this$props$step2 !== void 0 ? _this$props$step2 : Slider.defaultProps.step;
150
173
  } else {
151
174
  // Ignore keys we don't want to handle
152
175
  return;
@@ -155,15 +178,15 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
155
178
 
156
179
  if (evt.shiftKey) {
157
180
  var stepMultiplier = _this.props.stepMultiplier;
158
- delta *= stepMultiplier;
181
+ delta *= stepMultiplier !== null && stepMultiplier !== void 0 ? stepMultiplier : Slider.defaultProps.stepMultiplier;
159
182
  }
160
183
 
161
- Math.floor(_this.state.value / _this.props.step) * _this.props.step;
184
+ 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);
162
185
 
163
186
  var _this$calcValue2 = _this.calcValue({
164
187
  // Ensures custom value from `<input>` won't cause skipping next stepping point with right arrow key,
165
188
  // e.g. Typing 51 in `<input>`, moving focus onto the thumb and the hitting right arrow key should yield 52 instead of 54
166
- value: (delta > 0 ? Math.floor(_this.state.value / _this.props.step) * _this.props.step : _this.state.value) + delta
189
+ 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
167
190
  }),
168
191
  value = _this$calcValue2.value,
169
192
  left = _this$calcValue2.left;
@@ -197,11 +220,11 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
197
220
  value: targetValue,
198
221
  useRawValue: true
199
222
  }),
200
- value = _this$calcValue3.value,
223
+ _value = _this$calcValue3.value,
201
224
  left = _this$calcValue3.left;
202
225
 
203
226
  _this.setState({
204
- value: value,
227
+ value: _value,
205
228
  left: left
206
229
  });
207
230
  }
@@ -229,18 +252,16 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
229
252
  });
230
253
 
231
254
  _defineProperty(_assertThisInitialized(_this), "calcValue", function (_ref) {
232
- var _ref$clientX = _ref.clientX,
233
- clientX = _ref$clientX === void 0 ? null : _ref$clientX,
234
- _ref$value = _ref.value,
235
- value = _ref$value === void 0 ? null : _ref$value,
255
+ var _this$element5, _this$element5$getBou, _this$props$step7, _this$props$step8;
256
+
257
+ var clientX = _ref.clientX,
258
+ value = _ref.value,
236
259
  _ref$useRawValue = _ref.useRawValue,
237
260
  useRawValue = _ref$useRawValue === void 0 ? false : _ref$useRawValue;
238
261
  var range = _this.props.max - _this.props.min;
239
-
240
- var boundingRect = _this.element.getBoundingClientRect();
241
-
242
- var totalSteps = range / _this.props.step;
243
- var width = boundingRect.right - boundingRect.left; // Enforce a minimum width of at least 1 for calculations
262
+ 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);
263
+ var totalSteps = range / ((_this$props$step7 = _this.props.step) !== null && _this$props$step7 !== void 0 ? _this$props$step7 : Slider.defaultProps.step);
264
+ var width = boundingRect ? boundingRect.right - boundingRect.left : 0; // Enforce a minimum width of at least 1 for calculations
244
265
 
245
266
  if (width <= 0) {
246
267
  width = 1;
@@ -251,7 +272,9 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
251
272
  var leftPercent;
252
273
 
253
274
  if (clientX != null) {
254
- var leftOffset = clientX - boundingRect.left;
275
+ var _boundingRect$left;
276
+
277
+ var leftOffset = clientX - ((_boundingRect$left = boundingRect === null || boundingRect === void 0 ? void 0 : boundingRect.left) !== null && _boundingRect$left !== void 0 ? _boundingRect$left : 0);
255
278
  leftPercent = leftOffset / width;
256
279
  } else {
257
280
  if (value == null) {
@@ -270,7 +293,7 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
270
293
  };
271
294
  }
272
295
 
273
- var steppedValue = Math.round(leftPercent * totalSteps) * _this.props.step;
296
+ var steppedValue = Math.round(leftPercent * totalSteps) * ((_this$props$step8 = _this.props.step) !== null && _this$props$step8 !== void 0 ? _this$props$step8 : Slider.defaultProps.step);
274
297
 
275
298
  var steppedPercent = _this.clamp(steppedValue / range, 0, 1);
276
299
 
@@ -297,11 +320,11 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
297
320
  var _this$calcValue4 = this.calcValue({
298
321
  useRawValue: true
299
322
  }),
300
- value = _this$calcValue4.value,
323
+ _value2 = _this$calcValue4.value,
301
324
  left = _this$calcValue4.left;
302
325
 
303
326
  this.setState({
304
- value: value,
327
+ value: _value2,
305
328
  left: left
306
329
  });
307
330
  }
@@ -320,10 +343,15 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
320
343
  value: function componentDidUpdate(prevProps, prevState) {
321
344
  // Fire onChange event handler if present, if there's a usable value, and
322
345
  // if the value is different from the last one
323
- this.thumbRef.current.style.left = "".concat(this.state.left, "%");
324
- this.filledTrackRef.current.style.transform = "translate(0%, -50%) scaleX(".concat(this.state.left / 100, ")");
346
+ if (this.thumbRef.current) {
347
+ this.thumbRef.current.style.left = "".concat(this.state.left, "%");
348
+ }
349
+
350
+ if (this.filledTrackRef.current) {
351
+ this.filledTrackRef.current.style.transform = "translate(0%, -50%) scaleX(".concat(this.state.left / 100, ")");
352
+ }
325
353
 
326
- if (this.state.value !== '' && prevState.value !== this.state.value && typeof this.props.onChange === 'function') {
354
+ if (prevState.value !== this.state.value && typeof this.props.onChange === 'function') {
327
355
  this.props.onChange({
328
356
  value: this.state.value
329
357
  });
@@ -468,8 +496,8 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
468
496
  name: name,
469
497
  className: inputClasses,
470
498
  value: value,
471
- "aria-labelledby": !ariaLabelInput ? labelId : null,
472
- "aria-label": ariaLabelInput ? ariaLabelInput : null,
499
+ "aria-labelledby": !ariaLabelInput ? labelId : undefined,
500
+ "aria-label": ariaLabelInput ? ariaLabelInput : undefined,
473
501
  disabled: disabled,
474
502
  required: required,
475
503
  min: min,
@@ -477,9 +505,9 @@ var Slider = /*#__PURE__*/function (_PureComponent) {
477
505
  step: step,
478
506
  onChange: _this2.onChange,
479
507
  onBlur: _this2.onBlur,
480
- onKeyUp: _this2.onInputKeyUp,
508
+ onKeyUp: _this2.props.onInputKeyUp,
481
509
  "data-invalid": isValid ? null : true,
482
- "aria-invalid": isValid ? null : true,
510
+ "aria-invalid": isValid ? undefined : true,
483
511
  readOnly: readOnly
484
512
  })));
485
513
  });
@@ -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;
@@ -61,7 +61,7 @@ var TextInput = /*#__PURE__*/React__default.forwardRef(function TextInput(_ref,
61
61
  var defaultValue = rest.defaultValue,
62
62
  value = rest.value;
63
63
 
64
- var _useState = useState((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.length) || (value === null || value === void 0 ? void 0 : value.length) || 0),
64
+ var _useState = useState((defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.toString().length) || (value === null || value === void 0 ? void 0 : value.toString().length) || 0),
65
65
  _useState2 = _slicedToArray(_useState, 2),
66
66
  textCount = _useState2[0],
67
67
  setTextCount = _useState2[1];
@@ -139,6 +139,7 @@ var TextInput = /*#__PURE__*/React__default.forwardRef(function TextInput(_ref,
139
139
  isFluid = _useContext.isFluid;
140
140
 
141
141
  var ariaAnnouncement = useAnnouncer(textCount, maxCount);
142
+ var Icon = normalizedProps.icon;
142
143
  return /*#__PURE__*/React__default.createElement("div", {
143
144
  className: inputWrapperClasses
144
145
  }, !inline ? labelWrapper : /*#__PURE__*/React__default.createElement("div", {
@@ -148,7 +149,7 @@ var TextInput = /*#__PURE__*/React__default.forwardRef(function TextInput(_ref,
148
149
  }, /*#__PURE__*/React__default.createElement("div", {
149
150
  className: fieldWrapperClasses,
150
151
  "data-invalid": normalizedProps.invalid || null
151
- }, normalizedProps.icon && /*#__PURE__*/React__default.createElement(normalizedProps.icon, {
152
+ }, Icon && /*#__PURE__*/React__default.createElement(Icon, {
152
153
  className: iconClasses
153
154
  }), input, /*#__PURE__*/React__default.createElement("span", {
154
155
  className: "".concat(prefix, "--text-input__counter-alert"),
@@ -0,0 +1,13 @@
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 { Ref, ForwardedRef } from 'react';
8
+ /**
9
+ * Combine multiple refs into a single ref. This use useful when you have two
10
+ * refs from both `React.forwardRef` and `useRef` that you would like to add to
11
+ * the same node.
12
+ */
13
+ export declare const useMergedRefs: <T>(refs: ForwardedRef<T>[]) => Ref<T>;
@@ -11,12 +11,9 @@ import { useCallback } from 'react';
11
11
  * Combine multiple refs into a single ref. This use useful when you have two
12
12
  * refs from both `React.forwardRef` and `useRef` that you would like to add to
13
13
  * the same node.
14
- *
15
- * @param {Array} refs
16
- * @returns {Function}
17
14
  */
18
15
 
19
- function useMergedRefs(refs) {
16
+ var useMergedRefs = function useMergedRefs(refs) {
20
17
  return useCallback(function (node) {
21
18
  refs.forEach(function (ref) {
22
19
  if (typeof ref === 'function') {
@@ -26,6 +23,6 @@ function useMergedRefs(refs) {
26
23
  }
27
24
  }); // eslint-disable-next-line react-hooks/exhaustive-deps
28
25
  }, refs);
29
- }
26
+ };
30
27
 
31
28
  export { useMergedRefs };
@@ -25,6 +25,7 @@ import { usePrefix } from './usePrefix.js';
25
25
  * @property {boolean} disabled - Whether the input is disabled
26
26
  * @property {boolean} invalid - Whether the input is invalid (takes precedence over warn)
27
27
  * @property {string} invalidId - The invalid message's id
28
+ * @property {string} helperId - id used for helper text
28
29
  * @property {boolean} warn - Whether the input is in warning state
29
30
  * @property {string} warnId - The warning message's id
30
31
  * @property {React.ReactNode | null} validation – React node rendering the appropriate validation message (if any)
@@ -16,9 +16,9 @@ export interface ListBoxMenuItemProps extends ReactAttr<HTMLDivElement> {
16
16
  */
17
17
  isHighlighted?: boolean;
18
18
  }
19
- export type ListBoxMenuItemForwardedRef = ForwardedRef<HTMLDivElement> & {
19
+ export type ListBoxMenuItemForwardedRef = (ForwardedRef<HTMLDivElement> & {
20
20
  menuItemOptionRef?: React.Ref<HTMLDivElement>;
21
- } | null;
21
+ }) | null;
22
22
  export type ListBoxMenuItemComponent = ForwardRefReturn<ListBoxMenuItemForwardedRef, ListBoxMenuItemProps>;
23
23
  declare const _default: ListBoxMenuItemComponent;
24
24
  export default _default;
@@ -107,10 +107,6 @@ var Menu = /*#__PURE__*/React__default["default"].forwardRef(function Menu(_ref,
107
107
  returnFocus();
108
108
  }
109
109
 
110
- childDispatch({
111
- type: 'clearRegisteredItems'
112
- });
113
-
114
110
  if (onClose) {
115
111
  onClose();
116
112
  }
@@ -33,12 +33,9 @@ function menuReducer(state, action) {
33
33
 
34
34
  case 'registerItem':
35
35
  return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state), {}, {
36
- items: [].concat(_rollupPluginBabelHelpers.toConsumableArray(state.items), [action.payload])
37
- });
38
-
39
- case 'clearRegisteredItems':
40
- return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state), {}, {
41
- items: []
36
+ items: [].concat(_rollupPluginBabelHelpers.toConsumableArray(state.items), [action.payload]).filter(function (item) {
37
+ return item.ref.current !== null;
38
+ })
42
39
  });
43
40
  }
44
41
  }
@@ -0,0 +1,51 @@
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 from 'react';
8
+ import { PolymorphicProps } from '../../types/common';
9
+ export type PopoverAlignment = 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | 'left' | 'left-bottom' | 'left-top' | 'right' | 'right-bottom' | 'right-top';
10
+ interface PopoverBaseProps {
11
+ /**
12
+ * Specify how the popover should align with the trigger element
13
+ */
14
+ align?: PopoverAlignment;
15
+ /**
16
+ * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to futurue changes.
17
+ */
18
+ autoAlign?: boolean;
19
+ /**
20
+ * Specify whether a caret should be rendered
21
+ */
22
+ caret?: boolean;
23
+ /**
24
+ * Provide elements to be rendered inside of the component
25
+ */
26
+ children?: React.ReactNode;
27
+ /**
28
+ * Provide a custom class name to be added to the outermost node in the
29
+ * component
30
+ */
31
+ className?: string;
32
+ /**
33
+ * Specify whether a drop shadow should be rendered on the popover
34
+ */
35
+ dropShadow?: boolean;
36
+ /**
37
+ * Render the component using the high-contrast variant
38
+ */
39
+ highContrast?: boolean;
40
+ /**
41
+ * Specify whether the component is currently open or closed
42
+ */
43
+ open: boolean;
44
+ }
45
+ export type PopoverProps<T extends React.ElementType> = PolymorphicProps<T, PopoverBaseProps>;
46
+ declare const Popover: React.ForwardRefExoticComponent<Pick<PopoverBaseProps & Omit<any, "as"> & {
47
+ as?: React.ElementType<any> | undefined;
48
+ }, string | number | symbol> & React.RefAttributes<Element>>;
49
+ export type PopoverContentProps = React.HTMLAttributes<HTMLSpanElement>;
50
+ declare const PopoverContent: React.ForwardRefExoticComponent<PopoverContentProps & React.RefAttributes<HTMLSpanElement>>;
51
+ export { Popover, PopoverContent };
@@ -30,29 +30,28 @@ var PopoverContext = /*#__PURE__*/React__default["default"].createContext({
30
30
  current: null
31
31
  }
32
32
  });
33
- var Popover = /*#__PURE__*/React__default["default"].forwardRef(function Popover(props, forwardRef) {
33
+ var Popover = /*#__PURE__*/React__default["default"].forwardRef(function (_ref, forwardRef) {
34
34
  var _cx;
35
35
 
36
- var _props$align = props.align,
37
- align = _props$align === void 0 ? 'bottom' : _props$align,
38
- _props$as = props.as,
39
- BaseComponent = _props$as === void 0 ? 'span' : _props$as,
40
- _props$autoAlign = props.autoAlign,
41
- autoAlign = _props$autoAlign === void 0 ? false : _props$autoAlign,
42
- _props$caret = props.caret,
43
- caret = _props$caret === void 0 ? true : _props$caret,
44
- customClassName = props.className,
45
- children = props.children,
46
- _props$dropShadow = props.dropShadow,
47
- dropShadow = _props$dropShadow === void 0 ? true : _props$dropShadow,
48
- _props$highContrast = props.highContrast,
49
- highContrast = _props$highContrast === void 0 ? false : _props$highContrast,
50
- open = props.open,
51
- rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
36
+ var _ref$align = _ref.align,
37
+ align = _ref$align === void 0 ? 'bottom' : _ref$align,
38
+ as = _ref.as,
39
+ _ref$autoAlign = _ref.autoAlign,
40
+ autoAlign = _ref$autoAlign === void 0 ? false : _ref$autoAlign,
41
+ _ref$caret = _ref.caret,
42
+ caret = _ref$caret === void 0 ? true : _ref$caret,
43
+ customClassName = _ref.className,
44
+ children = _ref.children,
45
+ _ref$dropShadow = _ref.dropShadow,
46
+ dropShadow = _ref$dropShadow === void 0 ? true : _ref$dropShadow,
47
+ _ref$highContrast = _ref.highContrast,
48
+ highContrast = _ref$highContrast === void 0 ? false : _ref$highContrast,
49
+ open = _ref.open,
50
+ rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
52
51
 
53
52
  var prefix = usePrefix.usePrefix();
54
- var floating = React.useRef();
55
- var popover = React.useRef();
53
+ var floating = React.useRef(null);
54
+ var popover = React.useRef(null);
56
55
  var value = React.useMemo(function () {
57
56
  return {
58
57
  floating: floating
@@ -70,7 +69,7 @@ var Popover = /*#__PURE__*/React__default["default"].forwardRef(function Popover
70
69
  autoAlignment = _useState4[0],
71
70
  setAutoAlignment = _useState4[1];
72
71
 
73
- var className = cx__default["default"]((_cx = {}, _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover-container"), true), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--caret"), caret), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--drop-shadow"), dropShadow), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--high-contrast"), highContrast), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--open"), open), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--").concat(autoAlignment), autoAligned), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--").concat(align), !autoAligned), _rollupPluginBabelHelpers.defineProperty(_cx, customClassName, !!customClassName), _cx));
72
+ var className = cx__default["default"]((_cx = {}, _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover-container"), true), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--caret"), caret), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--drop-shadow"), dropShadow), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--high-contrast"), highContrast), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--open"), open), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--").concat(autoAlignment), autoAligned), _rollupPluginBabelHelpers.defineProperty(_cx, "".concat(prefix, "--popover--").concat(align), !autoAligned), _cx), customClassName);
74
73
  useIsomorphicEffect["default"](function () {
75
74
  if (!open) {
76
75
  return;
@@ -118,6 +117,10 @@ var Popover = /*#__PURE__*/React__default["default"].forwardRef(function Popover
118
117
  }
119
118
 
120
119
  function isVisible(alignment) {
120
+ if (!popover.current || !floating.current) {
121
+ return false;
122
+ }
123
+
121
124
  popover.current.classList.add("".concat(prefix, "--popover--").concat(alignment));
122
125
  var rect = floating.current.getBoundingClientRect(); // Check if popover is not visible to the left of the screen
123
126
 
@@ -164,6 +167,7 @@ var Popover = /*#__PURE__*/React__default["default"].forwardRef(function Popover
164
167
  setAutoAlignment(alignment);
165
168
  }
166
169
  }, [autoAligned, align, autoAlign, prefix, open]);
170
+ var BaseComponent = as !== null && as !== void 0 ? as : 'span';
167
171
  return /*#__PURE__*/React__default["default"].createElement(PopoverContext.Provider, {
168
172
  value: value
169
173
  }, /*#__PURE__*/React__default["default"].createElement(BaseComponent, _rollupPluginBabelHelpers["extends"]({}, rest, {
@@ -225,10 +229,10 @@ Popover.propTypes = {
225
229
  */
226
230
  open: PropTypes__default["default"].bool.isRequired
227
231
  };
228
- var PopoverContent = /*#__PURE__*/React__default["default"].forwardRef(function PopoverContent(_ref, forwardRef) {
229
- var className = _ref.className,
230
- children = _ref.children,
231
- rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded2);
232
+ var PopoverContent = /*#__PURE__*/React__default["default"].forwardRef(function PopoverContent(_ref2, forwardRef) {
233
+ var className = _ref2.className,
234
+ children = _ref2.children,
235
+ rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref2, _excluded2);
232
236
 
233
237
  var prefix = usePrefix.usePrefix();
234
238
 
@@ -8,8 +8,8 @@ import PropTypes from 'prop-types';
8
8
  import { HTMLAttributes } from 'react';
9
9
  export interface SliderSkeletonProps extends HTMLAttributes<HTMLDivElement> {
10
10
  /**
11
- * Specify an optional className to add to the form item wrapper.
12
- */
11
+ * Specify an optional className to add to the form item wrapper.
12
+ */
13
13
  className?: string;
14
14
  /**
15
15
  * Specify whether the label should be hidden, or not