@carbon/react 1.6.0 → 1.7.0-rc.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.
@@ -22,7 +22,7 @@ var Form = function Form(_ref) {
22
22
  var classNames = cx("".concat(prefix, "--form"), className);
23
23
  return /*#__PURE__*/React__default.createElement("form", _extends({
24
24
  className: classNames
25
- }, other), ' ', children, ' ');
25
+ }, other), children);
26
26
  };
27
27
 
28
28
  Form.propTypes = {
@@ -21,7 +21,7 @@ var FormGroup = function FormGroup(_ref) {
21
21
  className = _ref.className,
22
22
  message = _ref.message,
23
23
  messageText = _ref.messageText,
24
- other = _objectWithoutProperties(_ref, _excluded);
24
+ rest = _objectWithoutProperties(_ref, _excluded);
25
25
 
26
26
  var prefix = usePrefix();
27
27
  var classNamesFieldset = cx("".concat(prefix, "--fieldset"), className);
@@ -29,11 +29,11 @@ var FormGroup = function FormGroup(_ref) {
29
29
  'data-invalid': ''
30
30
  }, {
31
31
  className: classNamesFieldset
32
- }, other, {
33
- "aria-labelledby": other['aria-labelledby'] || legendId
32
+ }, rest, {
33
+ "aria-labelledby": rest['aria-labelledby'] || legendId
34
34
  }), /*#__PURE__*/React__default.createElement("legend", {
35
35
  className: "".concat(prefix, "--label"),
36
- id: legendId || other['aria-labelledby']
36
+ id: legendId || rest['aria-labelledby']
37
37
  }, legendText), children, message ? /*#__PURE__*/React__default.createElement("div", {
38
38
  className: "".concat(prefix, "--form__requirements")
39
39
  }, messageText) : null);
@@ -13,17 +13,17 @@ import { usePrefix } from '../../internal/usePrefix.js';
13
13
 
14
14
  var _excluded = ["className", "children"];
15
15
 
16
- var FormItem = function FormItem(_ref) {
16
+ function FormItem(_ref) {
17
17
  var className = _ref.className,
18
18
  children = _ref.children,
19
- other = _objectWithoutProperties(_ref, _excluded);
19
+ rest = _objectWithoutProperties(_ref, _excluded);
20
20
 
21
21
  var prefix = usePrefix();
22
22
  var classNames = cx("".concat(prefix, "--form-item"), className);
23
23
  return /*#__PURE__*/React__default.createElement("div", _extends({
24
24
  className: classNames
25
- }, other), children);
26
- };
25
+ }, rest), children);
26
+ }
27
27
 
28
28
  FormItem.propTypes = {
29
29
  /**
@@ -36,6 +36,5 @@ FormItem.propTypes = {
36
36
  */
37
37
  className: PropTypes.string
38
38
  };
39
- var FormItem$1 = FormItem;
40
39
 
41
- export { FormItem$1 as default };
40
+ export { FormItem as default };
@@ -5,21 +5,30 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import { objectWithoutProperties as _objectWithoutProperties, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
8
+ import { objectWithoutProperties as _objectWithoutProperties, slicedToArray as _slicedToArray, defineProperty as _defineProperty, extends as _extends } from '../../_virtual/_rollupPluginBabelHelpers.js';
9
9
  import cx from 'classnames';
10
10
  import PropTypes from 'prop-types';
11
- import React__default from 'react';
11
+ import React__default, { useRef, useMemo, useState } from 'react';
12
+ import useIsomorphicEffect from '../../internal/useIsomorphicEffect.js';
13
+ import { useMergedRefs } from '../../internal/useMergedRefs.js';
12
14
  import { usePrefix } from '../../internal/usePrefix.js';
13
15
 
14
- var _excluded = ["align", "as", "caret", "className", "children", "dropShadow", "highContrast", "open"],
16
+ var _excluded = ["align", "as", "autoAlign", "caret", "className", "children", "dropShadow", "highContrast", "open"],
15
17
  _excluded2 = ["className", "children"];
16
- var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, ref) {
18
+ var PopoverContext = /*#__PURE__*/React__default.createContext({
19
+ floating: {
20
+ current: null
21
+ }
22
+ });
23
+ var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, forwardRef) {
17
24
  var _cx;
18
25
 
19
26
  var _props$align = props.align,
20
27
  align = _props$align === void 0 ? 'bottom' : _props$align,
21
28
  _props$as = props.as,
22
29
  BaseComponent = _props$as === void 0 ? 'span' : _props$as,
30
+ _props$autoAlign = props.autoAlign,
31
+ autoAlign = _props$autoAlign === void 0 ? false : _props$autoAlign,
23
32
  _props$caret = props.caret,
24
33
  caret = _props$caret === void 0 ? true : _props$caret,
25
34
  customClassName = props.className,
@@ -32,11 +41,121 @@ var Popover = /*#__PURE__*/React__default.forwardRef(function Popover(props, ref
32
41
  rest = _objectWithoutProperties(props, _excluded);
33
42
 
34
43
  var prefix = usePrefix();
35
- var className = cx((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--popover-container"), true), _defineProperty(_cx, "".concat(prefix, "--popover--caret"), caret), _defineProperty(_cx, "".concat(prefix, "--popover--drop-shadow"), dropShadow), _defineProperty(_cx, "".concat(prefix, "--popover--high-contrast"), highContrast), _defineProperty(_cx, "".concat(prefix, "--popover--open"), open), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(align), true), _defineProperty(_cx, customClassName, !!customClassName), _cx));
36
- return /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
44
+ var floating = useRef();
45
+ var popover = useRef();
46
+ var value = useMemo(function () {
47
+ return {
48
+ floating: floating
49
+ };
50
+ }, []);
51
+ var ref = useMergedRefs([forwardRef, popover]);
52
+
53
+ var _useState = useState(false),
54
+ _useState2 = _slicedToArray(_useState, 2),
55
+ autoAligned = _useState2[0],
56
+ setAutoAligned = _useState2[1];
57
+
58
+ var _useState3 = useState(align),
59
+ _useState4 = _slicedToArray(_useState3, 2),
60
+ autoAlignment = _useState4[0],
61
+ setAutoAlignment = _useState4[1];
62
+
63
+ var className = cx((_cx = {}, _defineProperty(_cx, "".concat(prefix, "--popover-container"), true), _defineProperty(_cx, "".concat(prefix, "--popover--caret"), caret), _defineProperty(_cx, "".concat(prefix, "--popover--drop-shadow"), dropShadow), _defineProperty(_cx, "".concat(prefix, "--popover--high-contrast"), highContrast), _defineProperty(_cx, "".concat(prefix, "--popover--open"), open), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(autoAlignment), autoAligned), _defineProperty(_cx, "".concat(prefix, "--popover--").concat(align), !autoAligned), _defineProperty(_cx, customClassName, !!customClassName), _cx));
64
+ useIsomorphicEffect(function () {
65
+ if (!autoAlign) {
66
+ setAutoAligned(false);
67
+ return;
68
+ }
69
+
70
+ if (!floating.current) {
71
+ return;
72
+ }
73
+
74
+ if (autoAligned === true) {
75
+ return;
76
+ }
77
+
78
+ var rect = floating.current.getBoundingClientRect(); // The conditions, per side, of when the popover is not visible, excluding the popover's internal padding(16)
79
+
80
+ var conditions = {
81
+ left: rect.x < -16,
82
+ top: rect.y < -16,
83
+ right: rect.x + (rect.width - 16) > document.documentElement.clientWidth,
84
+ bottom: rect.y + (rect.height - 16) > document.documentElement.clientHeight
85
+ };
86
+
87
+ if (!conditions.left && !conditions.top && !conditions.right && !conditions.bottom) {
88
+ setAutoAligned(false);
89
+ return;
90
+ }
91
+
92
+ var alignments = ['top', 'top-left', 'right-bottom', 'right', 'right-top', 'bottom-left', 'bottom', 'bottom-right', 'left-top', 'left', 'left-bottom', 'top-right']; // Creates the prioritized list of options depending on ideal alignment coming from `align`
93
+
94
+ var options = [align];
95
+ var option = alignments[(alignments.indexOf(align) + 1) % alignments.length];
96
+
97
+ while (option) {
98
+ if (options.includes(option)) {
99
+ break;
100
+ }
101
+
102
+ options.push(option);
103
+ option = alignments[(alignments.indexOf(option) + 1) % alignments.length];
104
+ }
105
+
106
+ function isVisible(alignment) {
107
+ popover.current.classList.add("".concat(prefix, "--popover--").concat(alignment));
108
+ var rect = floating.current.getBoundingClientRect(); // Check if popover is not visible to the left of the screen
109
+
110
+ if (rect.x < -16) {
111
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
112
+ return false;
113
+ } // Check if popover is not visible at the top of the screen
114
+
115
+
116
+ if (rect.y < -16) {
117
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
118
+ return false;
119
+ } // Check if popover is not visible to right of screen
120
+
121
+
122
+ if (rect.x + (rect.width - 16) > document.documentElement.clientWidth) {
123
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
124
+ return false;
125
+ } // Check if popover is not visible to bottom of screen
126
+
127
+
128
+ if (rect.y + (rect.height - 16) > document.documentElement.clientHeight) {
129
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
130
+ return false;
131
+ }
132
+
133
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
134
+ return true;
135
+ }
136
+
137
+ var alignment = null;
138
+
139
+ for (var i = 0; i < options.length; i++) {
140
+ var _option = options[i];
141
+
142
+ if (isVisible(_option)) {
143
+ alignment = _option;
144
+ break;
145
+ }
146
+ }
147
+
148
+ if (alignment) {
149
+ setAutoAligned(true);
150
+ setAutoAlignment(alignment);
151
+ }
152
+ }, [autoAligned, align, autoAlign, prefix]);
153
+ return /*#__PURE__*/React__default.createElement(PopoverContext.Provider, {
154
+ value: value
155
+ }, /*#__PURE__*/React__default.createElement(BaseComponent, _extends({}, rest, {
37
156
  className: className,
38
157
  ref: ref
39
- }), children);
158
+ }), children));
40
159
  }); // Note: this displayName is temporarily set so that Storybook ArgTable
41
160
  // correctly displays the name of this component
42
161
 
@@ -56,6 +175,11 @@ Popover.propTypes = {
56
175
  */
57
176
  as: PropTypes.oneOfType([PropTypes.string, PropTypes.elementType]),
58
177
 
178
+ /**
179
+ * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to futurue changes.
180
+ */
181
+ autoAlign: PropTypes.bool,
182
+
59
183
  /**
60
184
  * Specify whether a caret should be rendered
61
185
  */
@@ -87,12 +211,17 @@ Popover.propTypes = {
87
211
  */
88
212
  open: PropTypes.bool.isRequired
89
213
  };
90
- var PopoverContent = /*#__PURE__*/React__default.forwardRef(function PopoverContent(_ref, ref) {
214
+ var PopoverContent = /*#__PURE__*/React__default.forwardRef(function PopoverContent(_ref, forwardRef) {
91
215
  var className = _ref.className,
92
216
  children = _ref.children,
93
217
  rest = _objectWithoutProperties(_ref, _excluded2);
94
218
 
95
219
  var prefix = usePrefix();
220
+
221
+ var _React$useContext = React__default.useContext(PopoverContext),
222
+ floating = _React$useContext.floating;
223
+
224
+ var ref = useMergedRefs([floating, forwardRef]);
96
225
  return /*#__PURE__*/React__default.createElement("span", _extends({}, rest, {
97
226
  className: "".concat(prefix, "--popover")
98
227
  }), /*#__PURE__*/React__default.createElement("span", {
@@ -20,18 +20,25 @@ var Select = /*#__PURE__*/React__default.forwardRef(function Select(_ref, ref) {
20
20
 
21
21
  var className = _ref.className,
22
22
  id = _ref.id,
23
- inline = _ref.inline,
23
+ _ref$inline = _ref.inline,
24
+ inline = _ref$inline === void 0 ? false : _ref$inline,
24
25
  labelText = _ref.labelText,
25
- disabled = _ref.disabled,
26
+ _ref$disabled = _ref.disabled,
27
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
26
28
  children = _ref.children,
27
- noLabel = _ref.noLabel,
28
- hideLabel = _ref.hideLabel,
29
- invalid = _ref.invalid,
29
+ _ref$noLabel = _ref.noLabel,
30
+ noLabel = _ref$noLabel === void 0 ? false : _ref$noLabel,
31
+ _ref$hideLabel = _ref.hideLabel,
32
+ hideLabel = _ref$hideLabel === void 0 ? false : _ref$hideLabel,
33
+ _ref$invalid = _ref.invalid,
34
+ invalid = _ref$invalid === void 0 ? false : _ref$invalid,
30
35
  invalidText = _ref.invalidText,
31
36
  helperText = _ref.helperText,
32
- light = _ref.light,
37
+ _ref$light = _ref.light,
38
+ light = _ref$light === void 0 ? false : _ref$light,
33
39
  size = _ref.size,
34
- warn = _ref.warn,
40
+ _ref$warn = _ref.warn,
41
+ warn = _ref$warn === void 0 ? false : _ref$warn,
35
42
  warnText = _ref.warnText,
36
43
  other = _objectWithoutProperties(_ref, _excluded);
37
44
 
@@ -32,7 +32,7 @@ var Form = function Form(_ref) {
32
32
  var classNames = cx__default["default"]("".concat(prefix, "--form"), className);
33
33
  return /*#__PURE__*/React__default["default"].createElement("form", _rollupPluginBabelHelpers["extends"]({
34
34
  className: classNames
35
- }, other), ' ', children, ' ');
35
+ }, other), children);
36
36
  };
37
37
 
38
38
  Form.propTypes = {
@@ -31,7 +31,7 @@ var FormGroup = function FormGroup(_ref) {
31
31
  className = _ref.className,
32
32
  message = _ref.message,
33
33
  messageText = _ref.messageText,
34
- other = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
34
+ rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
35
35
 
36
36
  var prefix = usePrefix.usePrefix();
37
37
  var classNamesFieldset = cx__default["default"]("".concat(prefix, "--fieldset"), className);
@@ -39,11 +39,11 @@ var FormGroup = function FormGroup(_ref) {
39
39
  'data-invalid': ''
40
40
  }, {
41
41
  className: classNamesFieldset
42
- }, other, {
43
- "aria-labelledby": other['aria-labelledby'] || legendId
42
+ }, rest, {
43
+ "aria-labelledby": rest['aria-labelledby'] || legendId
44
44
  }), /*#__PURE__*/React__default["default"].createElement("legend", {
45
45
  className: "".concat(prefix, "--label"),
46
- id: legendId || other['aria-labelledby']
46
+ id: legendId || rest['aria-labelledby']
47
47
  }, legendText), children, message ? /*#__PURE__*/React__default["default"].createElement("div", {
48
48
  className: "".concat(prefix, "--form__requirements")
49
49
  }, messageText) : null);
@@ -23,17 +23,17 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
23
23
 
24
24
  var _excluded = ["className", "children"];
25
25
 
26
- var FormItem = function FormItem(_ref) {
26
+ function FormItem(_ref) {
27
27
  var className = _ref.className,
28
28
  children = _ref.children,
29
- other = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
29
+ rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
30
30
 
31
31
  var prefix = usePrefix.usePrefix();
32
32
  var classNames = cx__default["default"]("".concat(prefix, "--form-item"), className);
33
33
  return /*#__PURE__*/React__default["default"].createElement("div", _rollupPluginBabelHelpers["extends"]({
34
34
  className: classNames
35
- }, other), children);
36
- };
35
+ }, rest), children);
36
+ }
37
37
 
38
38
  FormItem.propTypes = {
39
39
  /**
@@ -46,6 +46,5 @@ FormItem.propTypes = {
46
46
  */
47
47
  className: PropTypes__default["default"].string
48
48
  };
49
- var FormItem$1 = FormItem;
50
49
 
51
- exports["default"] = FormItem$1;
50
+ exports["default"] = FormItem;
@@ -13,6 +13,8 @@ var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelper
13
13
  var cx = require('classnames');
14
14
  var PropTypes = require('prop-types');
15
15
  var React = require('react');
16
+ var useIsomorphicEffect = require('../../internal/useIsomorphicEffect.js');
17
+ var useMergedRefs = require('../../internal/useMergedRefs.js');
16
18
  var usePrefix = require('../../internal/usePrefix.js');
17
19
 
18
20
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
@@ -21,15 +23,22 @@ var cx__default = /*#__PURE__*/_interopDefaultLegacy(cx);
21
23
  var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
22
24
  var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
23
25
 
24
- var _excluded = ["align", "as", "caret", "className", "children", "dropShadow", "highContrast", "open"],
26
+ var _excluded = ["align", "as", "autoAlign", "caret", "className", "children", "dropShadow", "highContrast", "open"],
25
27
  _excluded2 = ["className", "children"];
26
- var Popover = /*#__PURE__*/React__default["default"].forwardRef(function Popover(props, ref) {
28
+ var PopoverContext = /*#__PURE__*/React__default["default"].createContext({
29
+ floating: {
30
+ current: null
31
+ }
32
+ });
33
+ var Popover = /*#__PURE__*/React__default["default"].forwardRef(function Popover(props, forwardRef) {
27
34
  var _cx;
28
35
 
29
36
  var _props$align = props.align,
30
37
  align = _props$align === void 0 ? 'bottom' : _props$align,
31
38
  _props$as = props.as,
32
39
  BaseComponent = _props$as === void 0 ? 'span' : _props$as,
40
+ _props$autoAlign = props.autoAlign,
41
+ autoAlign = _props$autoAlign === void 0 ? false : _props$autoAlign,
33
42
  _props$caret = props.caret,
34
43
  caret = _props$caret === void 0 ? true : _props$caret,
35
44
  customClassName = props.className,
@@ -42,11 +51,121 @@ var Popover = /*#__PURE__*/React__default["default"].forwardRef(function Popover
42
51
  rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
43
52
 
44
53
  var prefix = usePrefix.usePrefix();
45
- 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(align), true), _rollupPluginBabelHelpers.defineProperty(_cx, customClassName, !!customClassName), _cx));
46
- return /*#__PURE__*/React__default["default"].createElement(BaseComponent, _rollupPluginBabelHelpers["extends"]({}, rest, {
54
+ var floating = React.useRef();
55
+ var popover = React.useRef();
56
+ var value = React.useMemo(function () {
57
+ return {
58
+ floating: floating
59
+ };
60
+ }, []);
61
+ var ref = useMergedRefs.useMergedRefs([forwardRef, popover]);
62
+
63
+ var _useState = React.useState(false),
64
+ _useState2 = _rollupPluginBabelHelpers.slicedToArray(_useState, 2),
65
+ autoAligned = _useState2[0],
66
+ setAutoAligned = _useState2[1];
67
+
68
+ var _useState3 = React.useState(align),
69
+ _useState4 = _rollupPluginBabelHelpers.slicedToArray(_useState3, 2),
70
+ autoAlignment = _useState4[0],
71
+ setAutoAlignment = _useState4[1];
72
+
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));
74
+ useIsomorphicEffect["default"](function () {
75
+ if (!autoAlign) {
76
+ setAutoAligned(false);
77
+ return;
78
+ }
79
+
80
+ if (!floating.current) {
81
+ return;
82
+ }
83
+
84
+ if (autoAligned === true) {
85
+ return;
86
+ }
87
+
88
+ var rect = floating.current.getBoundingClientRect(); // The conditions, per side, of when the popover is not visible, excluding the popover's internal padding(16)
89
+
90
+ var conditions = {
91
+ left: rect.x < -16,
92
+ top: rect.y < -16,
93
+ right: rect.x + (rect.width - 16) > document.documentElement.clientWidth,
94
+ bottom: rect.y + (rect.height - 16) > document.documentElement.clientHeight
95
+ };
96
+
97
+ if (!conditions.left && !conditions.top && !conditions.right && !conditions.bottom) {
98
+ setAutoAligned(false);
99
+ return;
100
+ }
101
+
102
+ var alignments = ['top', 'top-left', 'right-bottom', 'right', 'right-top', 'bottom-left', 'bottom', 'bottom-right', 'left-top', 'left', 'left-bottom', 'top-right']; // Creates the prioritized list of options depending on ideal alignment coming from `align`
103
+
104
+ var options = [align];
105
+ var option = alignments[(alignments.indexOf(align) + 1) % alignments.length];
106
+
107
+ while (option) {
108
+ if (options.includes(option)) {
109
+ break;
110
+ }
111
+
112
+ options.push(option);
113
+ option = alignments[(alignments.indexOf(option) + 1) % alignments.length];
114
+ }
115
+
116
+ function isVisible(alignment) {
117
+ popover.current.classList.add("".concat(prefix, "--popover--").concat(alignment));
118
+ var rect = floating.current.getBoundingClientRect(); // Check if popover is not visible to the left of the screen
119
+
120
+ if (rect.x < -16) {
121
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
122
+ return false;
123
+ } // Check if popover is not visible at the top of the screen
124
+
125
+
126
+ if (rect.y < -16) {
127
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
128
+ return false;
129
+ } // Check if popover is not visible to right of screen
130
+
131
+
132
+ if (rect.x + (rect.width - 16) > document.documentElement.clientWidth) {
133
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
134
+ return false;
135
+ } // Check if popover is not visible to bottom of screen
136
+
137
+
138
+ if (rect.y + (rect.height - 16) > document.documentElement.clientHeight) {
139
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
140
+ return false;
141
+ }
142
+
143
+ popover.current.classList.remove("".concat(prefix, "--popover--").concat(alignment));
144
+ return true;
145
+ }
146
+
147
+ var alignment = null;
148
+
149
+ for (var i = 0; i < options.length; i++) {
150
+ var _option = options[i];
151
+
152
+ if (isVisible(_option)) {
153
+ alignment = _option;
154
+ break;
155
+ }
156
+ }
157
+
158
+ if (alignment) {
159
+ setAutoAligned(true);
160
+ setAutoAlignment(alignment);
161
+ }
162
+ }, [autoAligned, align, autoAlign, prefix]);
163
+ return /*#__PURE__*/React__default["default"].createElement(PopoverContext.Provider, {
164
+ value: value
165
+ }, /*#__PURE__*/React__default["default"].createElement(BaseComponent, _rollupPluginBabelHelpers["extends"]({}, rest, {
47
166
  className: className,
48
167
  ref: ref
49
- }), children);
168
+ }), children));
50
169
  }); // Note: this displayName is temporarily set so that Storybook ArgTable
51
170
  // correctly displays the name of this component
52
171
 
@@ -66,6 +185,11 @@ Popover.propTypes = {
66
185
  */
67
186
  as: PropTypes__default["default"].oneOfType([PropTypes__default["default"].string, PropTypes__default["default"].elementType]),
68
187
 
188
+ /**
189
+ * Will auto-align the popover on first render if it is not visible. This prop is currently experimental and is subject to futurue changes.
190
+ */
191
+ autoAlign: PropTypes__default["default"].bool,
192
+
69
193
  /**
70
194
  * Specify whether a caret should be rendered
71
195
  */
@@ -97,12 +221,17 @@ Popover.propTypes = {
97
221
  */
98
222
  open: PropTypes__default["default"].bool.isRequired
99
223
  };
100
- var PopoverContent = /*#__PURE__*/React__default["default"].forwardRef(function PopoverContent(_ref, ref) {
224
+ var PopoverContent = /*#__PURE__*/React__default["default"].forwardRef(function PopoverContent(_ref, forwardRef) {
101
225
  var className = _ref.className,
102
226
  children = _ref.children,
103
227
  rest = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded2);
104
228
 
105
229
  var prefix = usePrefix.usePrefix();
230
+
231
+ var _React$useContext = React__default["default"].useContext(PopoverContext),
232
+ floating = _React$useContext.floating;
233
+
234
+ var ref = useMergedRefs.useMergedRefs([floating, forwardRef]);
106
235
  return /*#__PURE__*/React__default["default"].createElement("span", _rollupPluginBabelHelpers["extends"]({}, rest, {
107
236
  className: "".concat(prefix, "--popover")
108
237
  }), /*#__PURE__*/React__default["default"].createElement("span", {
@@ -30,18 +30,25 @@ var Select = /*#__PURE__*/React__default["default"].forwardRef(function Select(_
30
30
 
31
31
  var className = _ref.className,
32
32
  id = _ref.id,
33
- inline = _ref.inline,
33
+ _ref$inline = _ref.inline,
34
+ inline = _ref$inline === void 0 ? false : _ref$inline,
34
35
  labelText = _ref.labelText,
35
- disabled = _ref.disabled,
36
+ _ref$disabled = _ref.disabled,
37
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
36
38
  children = _ref.children,
37
- noLabel = _ref.noLabel,
38
- hideLabel = _ref.hideLabel,
39
- invalid = _ref.invalid,
39
+ _ref$noLabel = _ref.noLabel,
40
+ noLabel = _ref$noLabel === void 0 ? false : _ref$noLabel,
41
+ _ref$hideLabel = _ref.hideLabel,
42
+ hideLabel = _ref$hideLabel === void 0 ? false : _ref$hideLabel,
43
+ _ref$invalid = _ref.invalid,
44
+ invalid = _ref$invalid === void 0 ? false : _ref$invalid,
40
45
  invalidText = _ref.invalidText,
41
46
  helperText = _ref.helperText,
42
- light = _ref.light,
47
+ _ref$light = _ref.light,
48
+ light = _ref$light === void 0 ? false : _ref$light,
43
49
  size = _ref.size,
44
- warn = _ref.warn,
50
+ _ref$warn = _ref.warn,
51
+ warn = _ref$warn === void 0 ? false : _ref$warn,
45
52
  warnText = _ref.warnText,
46
53
  other = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded);
47
54
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@carbon/react",
3
3
  "description": "React components for the Carbon Design System",
4
- "version": "1.6.0",
4
+ "version": "1.7.0-rc.0",
5
5
  "license": "Apache-2.0",
6
6
  "main": "lib/index.js",
7
7
  "module": "es/index.js",
@@ -129,5 +129,5 @@
129
129
  "**/*.scss",
130
130
  "**/*.css"
131
131
  ],
132
- "gitHead": "07aff903e75a56d215c3582c214505379448e38e"
132
+ "gitHead": "a0ece2d0b5c0b85dc2cce0757f1d9b2d5ee0ce1b"
133
133
  }