@pingux/astro 1.22.0 → 1.23.0-alpha.2
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/lib/cjs/components/ArrayField/ArrayField.js +35 -12
- package/lib/cjs/components/ArrayField/ArrayFieldItem.js +50 -0
- package/lib/cjs/components/PopoverContainer/PopoverContainer.js +69 -9
- package/lib/cjs/components/RockerButtonGroup/RockerButtonGroup.js +2 -1
- package/lib/cjs/components/TooltipTrigger/TooltipTrigger.js +15 -3
- package/lib/cjs/components/TooltipTrigger/TooltipTrigger.stories.js +18 -1
- package/lib/cjs/components/TooltipTrigger/TooltipTrigger.test.js +10 -0
- package/lib/components/ArrayField/ArrayField.js +26 -12
- package/lib/components/ArrayField/ArrayFieldItem.js +31 -0
- package/lib/components/PopoverContainer/PopoverContainer.js +69 -9
- package/lib/components/RockerButtonGroup/RockerButtonGroup.js +2 -1
- package/lib/components/TooltipTrigger/TooltipTrigger.js +15 -3
- package/lib/components/TooltipTrigger/TooltipTrigger.stories.js +11 -0
- package/lib/components/TooltipTrigger/TooltipTrigger.test.js +8 -0
- package/package.json +1 -1
- package/NOTICE.html +0 -4836
@@ -68,6 +68,8 @@ var _statuses = _interopRequireDefault(require("../../utils/devUtils/constants/s
|
|
68
68
|
|
69
69
|
var _isValidPositiveInt = _interopRequireDefault(require("../../utils/devUtils/props/isValidPositiveInt"));
|
70
70
|
|
71
|
+
var _ArrayFieldItem = _interopRequireDefault(require("./ArrayFieldItem"));
|
72
|
+
|
71
73
|
var _react2 = require("@emotion/react");
|
72
74
|
|
73
75
|
var _excluded = ["addButtonLabel", "defaultValue", "value", "label", "helperText", "status", "onAdd", "onChange", "onDelete", "renderField", "labelProps", "maxSize", "maxSizeText"],
|
@@ -102,6 +104,22 @@ var ArrayField = function ArrayField(props) {
|
|
102
104
|
maxSize = props.maxSize,
|
103
105
|
maxSizeText = props.maxSizeText,
|
104
106
|
others = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
107
|
+
|
108
|
+
var valueRef = _react["default"].useRef(value);
|
109
|
+
|
110
|
+
valueRef.current = value;
|
111
|
+
|
112
|
+
var onAddRef = _react["default"].useRef(onAdd);
|
113
|
+
|
114
|
+
onAddRef.current = onAdd;
|
115
|
+
|
116
|
+
var onChangeRef = _react["default"].useRef(onChange);
|
117
|
+
|
118
|
+
onChangeRef.current = onChange;
|
119
|
+
|
120
|
+
var onDeleteRef = _react["default"].useRef(onDelete);
|
121
|
+
|
122
|
+
onDeleteRef.current = onDelete;
|
105
123
|
var isControlled = value !== undefined;
|
106
124
|
var createEmptyField = (0, _react.useCallback)(function () {
|
107
125
|
return {
|
@@ -134,16 +152,16 @@ var ArrayField = function ArrayField(props) {
|
|
134
152
|
}
|
135
153
|
|
136
154
|
if (isControlled) {
|
137
|
-
|
155
|
+
onChangeRef.current(mapArrayFieldWithNewValue(valueRef.current, tempValue, fieldId));
|
138
156
|
} else {
|
139
157
|
setFieldValues(function (oldValues) {
|
140
158
|
return mapArrayFieldWithNewValue(oldValues, tempValue, fieldId);
|
141
159
|
});
|
142
160
|
}
|
143
|
-
}, [isControlled, mapArrayFieldWithNewValue
|
161
|
+
}, [isControlled, mapArrayFieldWithNewValue]);
|
144
162
|
var onFieldDelete = (0, _react.useCallback)(function (fieldId) {
|
145
163
|
if (isControlled) {
|
146
|
-
|
164
|
+
onDeleteRef.current(fieldId);
|
147
165
|
} else {
|
148
166
|
setFieldValues(function (oldValues) {
|
149
167
|
return (0, _filter["default"])(oldValues).call(oldValues, function (_ref) {
|
@@ -152,10 +170,10 @@ var ArrayField = function ArrayField(props) {
|
|
152
170
|
});
|
153
171
|
});
|
154
172
|
}
|
155
|
-
}, [isControlled
|
173
|
+
}, [isControlled]);
|
156
174
|
var onFieldAdd = (0, _react.useCallback)(function () {
|
157
|
-
if (
|
158
|
-
return
|
175
|
+
if (onAddRef.current) {
|
176
|
+
return onAddRef.current();
|
159
177
|
}
|
160
178
|
|
161
179
|
return setFieldValues(function (oldValues) {
|
@@ -163,7 +181,7 @@ var ArrayField = function ArrayField(props) {
|
|
163
181
|
|
164
182
|
return (0, _concat["default"])(_context = []).call(_context, oldValues, [createEmptyField()]);
|
165
183
|
});
|
166
|
-
}, [createEmptyField
|
184
|
+
}, [createEmptyField]);
|
167
185
|
|
168
186
|
var _useLabel = (0, _label.useLabel)(_objectSpread({}, props)),
|
169
187
|
raLabelProps = _useLabel.labelProps;
|
@@ -180,11 +198,16 @@ var ArrayField = function ArrayField(props) {
|
|
180
198
|
fieldValue = _ref2.fieldValue,
|
181
199
|
otherFieldProps = (0, _objectWithoutProperties2["default"])(_ref2, _excluded2);
|
182
200
|
var isDisabled = (value || fieldValues).length === 1;
|
183
|
-
return (0, _react2.jsx)(
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
201
|
+
return (0, _react2.jsx)(_ArrayFieldItem["default"], (0, _extends2["default"])({
|
202
|
+
key: id,
|
203
|
+
id: id,
|
204
|
+
isDisabled: isDisabled,
|
205
|
+
fieldValue: fieldValue,
|
206
|
+
onComponentRender: onComponentRender,
|
207
|
+
onFieldValueChange: onFieldValueChange,
|
208
|
+
onFieldDelete: onFieldDelete,
|
209
|
+
renderField: renderField
|
210
|
+
}, otherFieldProps));
|
188
211
|
})), helperText && (0, _react2.jsx)(_FieldHelperText["default"], {
|
189
212
|
status: status
|
190
213
|
}, helperText), isLimitReached && (0, _react2.jsx)(_FieldHelperText["default"], {
|
@@ -0,0 +1,50 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
6
|
+
|
7
|
+
_Object$defineProperty(exports, "__esModule", {
|
8
|
+
value: true
|
9
|
+
});
|
10
|
+
|
11
|
+
exports["default"] = void 0;
|
12
|
+
|
13
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
|
14
|
+
|
15
|
+
var _react = _interopRequireDefault(require("react"));
|
16
|
+
|
17
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
18
|
+
|
19
|
+
var _Box = _interopRequireDefault(require("../Box"));
|
20
|
+
|
21
|
+
var _react2 = require("@emotion/react");
|
22
|
+
|
23
|
+
var _excluded = ["id", "onComponentRender", "fieldValue", "isDisabled", "onFieldDelete", "onFieldValueChange", "renderField"];
|
24
|
+
|
25
|
+
var ArrayFieldItem = /*#__PURE__*/_react["default"].memo(function (_ref) {
|
26
|
+
var id = _ref.id,
|
27
|
+
onComponentRender = _ref.onComponentRender,
|
28
|
+
fieldValue = _ref.fieldValue,
|
29
|
+
isDisabled = _ref.isDisabled,
|
30
|
+
onFieldDelete = _ref.onFieldDelete,
|
31
|
+
onFieldValueChange = _ref.onFieldValueChange,
|
32
|
+
renderField = _ref.renderField,
|
33
|
+
otherFieldProps = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
34
|
+
return (0, _react2.jsx)(_Box["default"], {
|
35
|
+
as: "li",
|
36
|
+
mb: "xs"
|
37
|
+
}, onComponentRender ? onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) : renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps));
|
38
|
+
});
|
39
|
+
|
40
|
+
ArrayFieldItem.propTypes = {
|
41
|
+
id: _propTypes["default"].string,
|
42
|
+
onComponentRender: _propTypes["default"].func,
|
43
|
+
fieldValue: _propTypes["default"].string,
|
44
|
+
isDisabled: _propTypes["default"].bool,
|
45
|
+
onFieldDelete: _propTypes["default"].func,
|
46
|
+
onFieldValueChange: _propTypes["default"].func,
|
47
|
+
renderField: _propTypes["default"].func
|
48
|
+
};
|
49
|
+
var _default = ArrayFieldItem;
|
50
|
+
exports["default"] = _default;
|
@@ -48,8 +48,9 @@ var _Box = _interopRequireDefault(require("../Box"));
|
|
48
48
|
|
49
49
|
var _react2 = require("@emotion/react");
|
50
50
|
|
51
|
-
var _excluded = ["children", "placement", "arrowProps", "onClose", "isNotClosedOnBlur", "hasNoArrow", "isKeyboardDismissDisabled", "isNonModal", "isDismissable"],
|
52
|
-
_excluded2 = ["children", "className", "placement", "arrowProps", "isOpen", "hasNoArrow", "isNotClosedOnBlur", "isKeyboardDismissDisabled", "isNonModal", "isDismissable"]
|
51
|
+
var _excluded = ["children", "placement", "arrowProps", "arrowCrossOffset", "onClose", "isNotClosedOnBlur", "hasNoArrow", "isKeyboardDismissDisabled", "isNonModal", "isDismissable", "width", "direction"],
|
52
|
+
_excluded2 = ["children", "className", "placement", "arrowProps", "arrowCrossOffset", "isOpen", "hasNoArrow", "isNotClosedOnBlur", "isKeyboardDismissDisabled", "isNonModal", "isDismissable", "width", "direction", "sx"],
|
53
|
+
_excluded3 = ["arrowCrossOffset", "sx", "direction"];
|
53
54
|
|
54
55
|
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
55
56
|
|
@@ -66,12 +67,15 @@ var PopoverContainer = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
66
67
|
var children = props.children,
|
67
68
|
placement = props.placement,
|
68
69
|
arrowProps = props.arrowProps,
|
70
|
+
arrowCrossOffset = props.arrowCrossOffset,
|
69
71
|
onClose = props.onClose,
|
70
72
|
isNotClosedOnBlur = props.isNotClosedOnBlur,
|
71
73
|
hasNoArrow = props.hasNoArrow,
|
72
74
|
isKeyboardDismissDisabled = props.isKeyboardDismissDisabled,
|
73
75
|
isNonModal = props.isNonModal,
|
74
76
|
isDismissable = props.isDismissable,
|
77
|
+
width = props.width,
|
78
|
+
direction = props.direction,
|
75
79
|
others = (0, _objectWithoutProperties2["default"])(props, _excluded);
|
76
80
|
return (0, _react2.jsx)(_overlays.OverlayContainer, null, (0, _react2.jsx)(PopoverWrapper, (0, _extends2["default"])({
|
77
81
|
ref: ref,
|
@@ -82,7 +86,10 @@ var PopoverContainer = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
|
|
82
86
|
isKeyboardDismissDisabled: isKeyboardDismissDisabled,
|
83
87
|
hasNoArrow: hasNoArrow,
|
84
88
|
isNonModal: isNonModal,
|
85
|
-
isDismissable: isDismissable
|
89
|
+
isDismissable: isDismissable,
|
90
|
+
arrowCrossOffset: arrowCrossOffset,
|
91
|
+
width: width,
|
92
|
+
direction: direction
|
86
93
|
}, others), children));
|
87
94
|
});
|
88
95
|
PopoverContainer.propTypes = {
|
@@ -93,19 +100,26 @@ PopoverContainer.propTypes = {
|
|
93
100
|
hasNoArrow: _propTypes["default"].bool,
|
94
101
|
isKeyboardDismissDisabled: _propTypes["default"].bool,
|
95
102
|
isNonModal: _propTypes["default"].bool,
|
96
|
-
isDismissable: _propTypes["default"].bool
|
103
|
+
isDismissable: _propTypes["default"].bool,
|
104
|
+
width: _propTypes["default"].string,
|
105
|
+
arrowCrossOffset: _propTypes["default"].string,
|
106
|
+
direction: _propTypes["default"].oneOf(['top', 'right', 'bottom', 'left'])
|
97
107
|
};
|
98
108
|
var PopoverWrapper = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
99
109
|
var children = props.children,
|
100
110
|
className = props.className,
|
101
111
|
placement = props.placement,
|
102
112
|
arrowProps = props.arrowProps,
|
113
|
+
arrowCrossOffset = props.arrowCrossOffset,
|
103
114
|
isOpen = props.isOpen,
|
104
115
|
hasNoArrow = props.hasNoArrow,
|
105
116
|
isNotClosedOnBlur = props.isNotClosedOnBlur,
|
106
117
|
isKeyboardDismissDisabled = props.isKeyboardDismissDisabled,
|
107
118
|
isNonModal = props.isNonModal,
|
108
119
|
isDismissable = props.isDismissable,
|
120
|
+
width = props.width,
|
121
|
+
direction = props.direction,
|
122
|
+
sx = props.sx,
|
109
123
|
others = (0, _objectWithoutProperties2["default"])(props, _excluded2);
|
110
124
|
var popoverRef = (0, _react.useRef)();
|
111
125
|
/* istanbul ignore next */
|
@@ -135,8 +149,14 @@ var PopoverWrapper = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
135
149
|
className: classNames,
|
136
150
|
role: "presentation",
|
137
151
|
"data-popover-placement": placement,
|
138
|
-
"data-testid": "popover-container"
|
139
|
-
|
152
|
+
"data-testid": "popover-container",
|
153
|
+
sx: _objectSpread(_objectSpread({}, sx), {}, {
|
154
|
+
width: width
|
155
|
+
})
|
156
|
+
}), children, hasNoArrow ? null : (0, _react2.jsx)(PopoverArrow, (0, _extends2["default"])({}, arrowProps, {
|
157
|
+
arrowCrossOffset: arrowCrossOffset,
|
158
|
+
direction: direction
|
159
|
+
}))));
|
140
160
|
});
|
141
161
|
exports.PopoverWrapper = PopoverWrapper;
|
142
162
|
PopoverWrapper.propTypes = {
|
@@ -147,21 +167,61 @@ PopoverWrapper.propTypes = {
|
|
147
167
|
isNotClosedOnBlur: _propTypes["default"].bool,
|
148
168
|
isKeyboardDismissDisabled: _propTypes["default"].bool,
|
149
169
|
isNonModal: _propTypes["default"].bool,
|
150
|
-
isDismissable: _propTypes["default"].bool
|
170
|
+
isDismissable: _propTypes["default"].bool,
|
171
|
+
width: _propTypes["default"].string,
|
172
|
+
arrowCrossOffset: _propTypes["default"].string,
|
173
|
+
sx: _propTypes["default"].shape({}),
|
174
|
+
direction: _propTypes["default"].oneOf(['top', 'right', 'bottom', 'left'])
|
151
175
|
};
|
152
176
|
PopoverWrapper.defaultProps = {
|
153
177
|
placement: 'bottom'
|
154
178
|
};
|
155
179
|
|
156
180
|
var PopoverArrow = function PopoverArrow(props) {
|
157
|
-
var
|
181
|
+
var arrowCrossOffset = props.arrowCrossOffset,
|
182
|
+
sx = props.sx,
|
183
|
+
direction = props.direction,
|
184
|
+
others = (0, _objectWithoutProperties2["default"])(props, _excluded3);
|
185
|
+
/* istanbul ignore next */
|
186
|
+
|
187
|
+
var calculateOffset = function calculateOffset() {
|
188
|
+
switch (true) {
|
189
|
+
case direction === 'top':
|
190
|
+
case direction === 'bottom':
|
191
|
+
return {
|
192
|
+
'&:before': {
|
193
|
+
left: "calc(50% - ".concat(arrowCrossOffset, ") !important")
|
194
|
+
}
|
195
|
+
};
|
196
|
+
|
197
|
+
case direction === 'left':
|
198
|
+
case direction === 'right':
|
199
|
+
return {
|
200
|
+
'&:before': {
|
201
|
+
top: "calc(50% - ".concat(arrowCrossOffset, ") !important")
|
202
|
+
}
|
203
|
+
};
|
204
|
+
|
205
|
+
default:
|
206
|
+
return {};
|
207
|
+
}
|
208
|
+
};
|
209
|
+
|
158
210
|
return (0, _react2.jsx)(_Box["default"], (0, _extends2["default"])({
|
159
211
|
variant: "popoverMenu.arrow",
|
160
212
|
"data-popover-arrow": "arrow",
|
161
213
|
"data-testid": "popover-arrow"
|
162
|
-
}, others
|
214
|
+
}, others, {
|
215
|
+
sx: _objectSpread(_objectSpread({}, arrowCrossOffset && calculateOffset()), sx)
|
216
|
+
}));
|
163
217
|
};
|
164
218
|
|
165
219
|
exports.PopoverArrow = PopoverArrow;
|
220
|
+
PopoverArrow.propTypes = {
|
221
|
+
width: _propTypes["default"].string,
|
222
|
+
arrowCrossOffset: _propTypes["default"].string,
|
223
|
+
sx: _propTypes["default"].shape({}),
|
224
|
+
direction: _propTypes["default"].oneOf(['top', 'right', 'bottom', 'left'])
|
225
|
+
};
|
166
226
|
var _default = PopoverContainer;
|
167
227
|
exports["default"] = _default;
|
@@ -104,7 +104,8 @@ var RockerButtonGroup = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref
|
|
104
104
|
variant: "rockerbutton.rockerContainerInner",
|
105
105
|
isRow: true
|
106
106
|
}, tabListProps, raTabListProps, {
|
107
|
-
ref: buttonGroupRef
|
107
|
+
ref: buttonGroupRef,
|
108
|
+
role: "toolbar"
|
108
109
|
}), (0, _map["default"])(_context = (0, _from["default"])(state.collection)).call(_context, function (item) {
|
109
110
|
return (0, _react2.jsx)(_RockerButton.CollectionRockerButton, {
|
110
111
|
key: item.key,
|
@@ -57,7 +57,8 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
57
57
|
var TooltipTrigger = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
58
58
|
var _context, _useStatusClasses2;
|
59
59
|
|
60
|
-
var
|
60
|
+
var arrowCrossOffset = props.arrowCrossOffset,
|
61
|
+
children = props.children,
|
61
62
|
crossOffset = props.crossOffset,
|
62
63
|
isDisabled = props.isDisabled,
|
63
64
|
align = props.align,
|
@@ -68,7 +69,8 @@ var TooltipTrigger = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
68
69
|
isNotFlippable = props.isNotFlippable,
|
69
70
|
isDarkMode = props.isDarkMode,
|
70
71
|
hasNoArrow = props.hasNoArrow,
|
71
|
-
targetRef = props.targetRef
|
72
|
+
targetRef = props.targetRef,
|
73
|
+
width = props.width;
|
72
74
|
|
73
75
|
var _React$Children$toArr = _react["default"].Children.toArray(children),
|
74
76
|
_React$Children$toArr2 = (0, _slicedToArray2["default"])(_React$Children$toArr, 2),
|
@@ -116,7 +118,10 @@ var TooltipTrigger = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
|
|
116
118
|
placement: placement,
|
117
119
|
arrowProps: arrowProps,
|
118
120
|
className: classNames,
|
119
|
-
hasNoArrow: hasNoArrow
|
121
|
+
hasNoArrow: hasNoArrow,
|
122
|
+
arrowCrossOffset: arrowCrossOffset,
|
123
|
+
width: width,
|
124
|
+
direction: direction
|
120
125
|
}, positionProps, tooltipProps), tooltip);
|
121
126
|
return (0, _react2.jsx)(_react["default"].Fragment, null, (0, _react2.jsx)(_interactions.PressResponder, (0, _extends2["default"])({}, triggerProps, {
|
122
127
|
ref: tooltipTriggerRef
|
@@ -166,12 +171,19 @@ TooltipTrigger.propTypes = {
|
|
166
171
|
/** Tooltip offset relative to its trigger. */
|
167
172
|
offset: _propTypes["default"].number,
|
168
173
|
|
174
|
+
/** Arrow offset relative to the left of the tooltip.
|
175
|
+
* Must be passed as a px or percentage. */
|
176
|
+
arrowCrossOffset: _propTypes["default"].string,
|
177
|
+
|
169
178
|
/** The placement of the element with respect to its anchor element. */
|
170
179
|
placement: _propTypes["default"].string,
|
171
180
|
|
172
181
|
/** By default, opens for both focus and hover. Can be made to open only for focus. */
|
173
182
|
trigger: _propTypes["default"].string,
|
174
183
|
|
184
|
+
/** Width applied to the wrapper of the tooltip component. */
|
185
|
+
width: _propTypes["default"].string,
|
186
|
+
|
175
187
|
/* The ref for the element which the overlay positions itself with respect to. */
|
176
188
|
targetRef: _propTypes["default"].shape({})
|
177
189
|
};
|
@@ -8,7 +8,7 @@ _Object$defineProperty(exports, "__esModule", {
|
|
8
8
|
value: true
|
9
9
|
});
|
10
10
|
|
11
|
-
exports.withDirectionProp = exports.withDelayProp = exports.withAlignProp = exports.isOpen = exports["default"] = exports.TextWithTooltip = exports.IconWithTooltip = exports.Disabled = exports.Default = exports.ChipWithTooltip = void 0;
|
11
|
+
exports.withWidthProp = exports.withDirectionProp = exports.withDelayProp = exports.withArrowCrossOffsetProp = exports.withAlignProp = exports.isOpen = exports["default"] = exports.TextWithTooltip = exports.IconWithTooltip = exports.Disabled = exports.Default = exports.ChipWithTooltip = void 0;
|
12
12
|
|
13
13
|
var _react = _interopRequireDefault(require("react"));
|
14
14
|
|
@@ -60,6 +60,23 @@ var withDelayProp = function withDelayProp() {
|
|
60
60
|
|
61
61
|
exports.withDelayProp = withDelayProp;
|
62
62
|
|
63
|
+
var withWidthProp = function withWidthProp() {
|
64
|
+
return (0, _react2.jsx)(_index.TooltipTrigger, {
|
65
|
+
width: "200px"
|
66
|
+
}, (0, _react2.jsx)(_index.Button, null, "Hover Over Me!"), (0, _react2.jsx)(_index.Tooltip, null, "Custom width display"));
|
67
|
+
};
|
68
|
+
|
69
|
+
exports.withWidthProp = withWidthProp;
|
70
|
+
|
71
|
+
var withArrowCrossOffsetProp = function withArrowCrossOffsetProp() {
|
72
|
+
return (0, _react2.jsx)(_index.TooltipTrigger, {
|
73
|
+
arrowCrossOffset: "30px",
|
74
|
+
isOpen: true
|
75
|
+
}, (0, _react2.jsx)(_index.Button, null, "Hover Over Me!"), (0, _react2.jsx)(_index.Tooltip, null, "Display with a delay"));
|
76
|
+
};
|
77
|
+
|
78
|
+
exports.withArrowCrossOffsetProp = withArrowCrossOffsetProp;
|
79
|
+
|
63
80
|
var isOpen = function isOpen() {
|
64
81
|
return (0, _react2.jsx)(_index.TooltipTrigger, {
|
65
82
|
isOpen: true
|
@@ -106,4 +106,14 @@ test('trigger press events work when a tooltip is disabled', function () {
|
|
106
106
|
_userEvent["default"].click(button);
|
107
107
|
|
108
108
|
expect(onPress).toHaveBeenCalledTimes(1);
|
109
|
+
});
|
110
|
+
test('passing in width applies the correct width to the container', function () {
|
111
|
+
getComponent({
|
112
|
+
isOpen: true,
|
113
|
+
width: '100px'
|
114
|
+
});
|
115
|
+
|
116
|
+
var arrow = _testWrapper.screen.getByTestId('popover-container');
|
117
|
+
|
118
|
+
expect(arrow).toHaveStyle('width: 100px');
|
109
119
|
});
|
@@ -32,6 +32,7 @@ import Text from '../Text';
|
|
32
32
|
import Label from '../Label';
|
33
33
|
import statuses from '../../utils/devUtils/constants/statuses';
|
34
34
|
import isValidPositiveInt from '../../utils/devUtils/props/isValidPositiveInt';
|
35
|
+
import ArrayFieldItem from './ArrayFieldItem';
|
35
36
|
/**
|
36
37
|
* Displays array collections providing useful functions and
|
37
38
|
* optimizations for arrays.
|
@@ -57,6 +58,14 @@ var ArrayField = function ArrayField(props) {
|
|
57
58
|
maxSizeText = props.maxSizeText,
|
58
59
|
others = _objectWithoutProperties(props, _excluded);
|
59
60
|
|
61
|
+
var valueRef = React.useRef(value);
|
62
|
+
valueRef.current = value;
|
63
|
+
var onAddRef = React.useRef(onAdd);
|
64
|
+
onAddRef.current = onAdd;
|
65
|
+
var onChangeRef = React.useRef(onChange);
|
66
|
+
onChangeRef.current = onChange;
|
67
|
+
var onDeleteRef = React.useRef(onDelete);
|
68
|
+
onDeleteRef.current = onDelete;
|
60
69
|
var isControlled = value !== undefined;
|
61
70
|
var createEmptyField = useCallback(function () {
|
62
71
|
return {
|
@@ -89,16 +98,16 @@ var ArrayField = function ArrayField(props) {
|
|
89
98
|
}
|
90
99
|
|
91
100
|
if (isControlled) {
|
92
|
-
|
101
|
+
onChangeRef.current(mapArrayFieldWithNewValue(valueRef.current, tempValue, fieldId));
|
93
102
|
} else {
|
94
103
|
setFieldValues(function (oldValues) {
|
95
104
|
return mapArrayFieldWithNewValue(oldValues, tempValue, fieldId);
|
96
105
|
});
|
97
106
|
}
|
98
|
-
}, [isControlled, mapArrayFieldWithNewValue
|
107
|
+
}, [isControlled, mapArrayFieldWithNewValue]);
|
99
108
|
var onFieldDelete = useCallback(function (fieldId) {
|
100
109
|
if (isControlled) {
|
101
|
-
|
110
|
+
onDeleteRef.current(fieldId);
|
102
111
|
} else {
|
103
112
|
setFieldValues(function (oldValues) {
|
104
113
|
return _filterInstanceProperty(oldValues).call(oldValues, function (_ref) {
|
@@ -107,10 +116,10 @@ var ArrayField = function ArrayField(props) {
|
|
107
116
|
});
|
108
117
|
});
|
109
118
|
}
|
110
|
-
}, [isControlled
|
119
|
+
}, [isControlled]);
|
111
120
|
var onFieldAdd = useCallback(function () {
|
112
|
-
if (
|
113
|
-
return
|
121
|
+
if (onAddRef.current) {
|
122
|
+
return onAddRef.current();
|
114
123
|
}
|
115
124
|
|
116
125
|
return setFieldValues(function (oldValues) {
|
@@ -118,7 +127,7 @@ var ArrayField = function ArrayField(props) {
|
|
118
127
|
|
119
128
|
return _concatInstanceProperty(_context = []).call(_context, oldValues, [createEmptyField()]);
|
120
129
|
});
|
121
|
-
}, [createEmptyField
|
130
|
+
}, [createEmptyField]);
|
122
131
|
|
123
132
|
var _useLabel = useLabel(_objectSpread({}, props)),
|
124
133
|
raLabelProps = _useLabel.labelProps;
|
@@ -136,11 +145,16 @@ var ArrayField = function ArrayField(props) {
|
|
136
145
|
otherFieldProps = _objectWithoutProperties(_ref2, _excluded2);
|
137
146
|
|
138
147
|
var isDisabled = (value || fieldValues).length === 1;
|
139
|
-
return ___EmotionJSX(
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
148
|
+
return ___EmotionJSX(ArrayFieldItem, _extends({
|
149
|
+
key: id,
|
150
|
+
id: id,
|
151
|
+
isDisabled: isDisabled,
|
152
|
+
fieldValue: fieldValue,
|
153
|
+
onComponentRender: onComponentRender,
|
154
|
+
onFieldValueChange: onFieldValueChange,
|
155
|
+
onFieldDelete: onFieldDelete,
|
156
|
+
renderField: renderField
|
157
|
+
}, otherFieldProps));
|
144
158
|
})), helperText && ___EmotionJSX(FieldHelperText, {
|
145
159
|
status: status
|
146
160
|
}, helperText), isLimitReached && ___EmotionJSX(FieldHelperText, {
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
2
|
+
var _excluded = ["id", "onComponentRender", "fieldValue", "isDisabled", "onFieldDelete", "onFieldValueChange", "renderField"];
|
3
|
+
import React from 'react';
|
4
|
+
import PropTypes from 'prop-types';
|
5
|
+
import Box from '../Box';
|
6
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
7
|
+
var ArrayFieldItem = /*#__PURE__*/React.memo(function (_ref) {
|
8
|
+
var id = _ref.id,
|
9
|
+
onComponentRender = _ref.onComponentRender,
|
10
|
+
fieldValue = _ref.fieldValue,
|
11
|
+
isDisabled = _ref.isDisabled,
|
12
|
+
onFieldDelete = _ref.onFieldDelete,
|
13
|
+
onFieldValueChange = _ref.onFieldValueChange,
|
14
|
+
renderField = _ref.renderField,
|
15
|
+
otherFieldProps = _objectWithoutProperties(_ref, _excluded);
|
16
|
+
|
17
|
+
return ___EmotionJSX(Box, {
|
18
|
+
as: "li",
|
19
|
+
mb: "xs"
|
20
|
+
}, onComponentRender ? onComponentRender(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps) : renderField(id, fieldValue, onFieldValueChange, onFieldDelete, isDisabled, otherFieldProps));
|
21
|
+
});
|
22
|
+
ArrayFieldItem.propTypes = {
|
23
|
+
id: PropTypes.string,
|
24
|
+
onComponentRender: PropTypes.func,
|
25
|
+
fieldValue: PropTypes.string,
|
26
|
+
isDisabled: PropTypes.bool,
|
27
|
+
onFieldDelete: PropTypes.func,
|
28
|
+
onFieldValueChange: PropTypes.func,
|
29
|
+
renderField: PropTypes.func
|
30
|
+
};
|
31
|
+
export default ArrayFieldItem;
|
@@ -9,8 +9,9 @@ import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
|
|
9
9
|
import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
|
10
10
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
11
11
|
import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
|
12
|
-
var _excluded = ["children", "placement", "arrowProps", "onClose", "isNotClosedOnBlur", "hasNoArrow", "isKeyboardDismissDisabled", "isNonModal", "isDismissable"],
|
13
|
-
_excluded2 = ["children", "className", "placement", "arrowProps", "isOpen", "hasNoArrow", "isNotClosedOnBlur", "isKeyboardDismissDisabled", "isNonModal", "isDismissable"]
|
12
|
+
var _excluded = ["children", "placement", "arrowProps", "arrowCrossOffset", "onClose", "isNotClosedOnBlur", "hasNoArrow", "isKeyboardDismissDisabled", "isNonModal", "isDismissable", "width", "direction"],
|
13
|
+
_excluded2 = ["children", "className", "placement", "arrowProps", "arrowCrossOffset", "isOpen", "hasNoArrow", "isNotClosedOnBlur", "isKeyboardDismissDisabled", "isNonModal", "isDismissable", "width", "direction", "sx"],
|
14
|
+
_excluded3 = ["arrowCrossOffset", "sx", "direction"];
|
14
15
|
|
15
16
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
16
17
|
|
@@ -31,12 +32,15 @@ var PopoverContainer = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
31
32
|
var children = props.children,
|
32
33
|
placement = props.placement,
|
33
34
|
arrowProps = props.arrowProps,
|
35
|
+
arrowCrossOffset = props.arrowCrossOffset,
|
34
36
|
onClose = props.onClose,
|
35
37
|
isNotClosedOnBlur = props.isNotClosedOnBlur,
|
36
38
|
hasNoArrow = props.hasNoArrow,
|
37
39
|
isKeyboardDismissDisabled = props.isKeyboardDismissDisabled,
|
38
40
|
isNonModal = props.isNonModal,
|
39
41
|
isDismissable = props.isDismissable,
|
42
|
+
width = props.width,
|
43
|
+
direction = props.direction,
|
40
44
|
others = _objectWithoutProperties(props, _excluded);
|
41
45
|
|
42
46
|
return ___EmotionJSX(OverlayContainer, null, ___EmotionJSX(PopoverWrapper, _extends({
|
@@ -48,7 +52,10 @@ var PopoverContainer = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
48
52
|
isKeyboardDismissDisabled: isKeyboardDismissDisabled,
|
49
53
|
hasNoArrow: hasNoArrow,
|
50
54
|
isNonModal: isNonModal,
|
51
|
-
isDismissable: isDismissable
|
55
|
+
isDismissable: isDismissable,
|
56
|
+
arrowCrossOffset: arrowCrossOffset,
|
57
|
+
width: width,
|
58
|
+
direction: direction
|
52
59
|
}, others), children));
|
53
60
|
});
|
54
61
|
PopoverContainer.propTypes = {
|
@@ -59,19 +66,26 @@ PopoverContainer.propTypes = {
|
|
59
66
|
hasNoArrow: PropTypes.bool,
|
60
67
|
isKeyboardDismissDisabled: PropTypes.bool,
|
61
68
|
isNonModal: PropTypes.bool,
|
62
|
-
isDismissable: PropTypes.bool
|
69
|
+
isDismissable: PropTypes.bool,
|
70
|
+
width: PropTypes.string,
|
71
|
+
arrowCrossOffset: PropTypes.string,
|
72
|
+
direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left'])
|
63
73
|
};
|
64
74
|
export var PopoverWrapper = /*#__PURE__*/forwardRef(function (props, ref) {
|
65
75
|
var children = props.children,
|
66
76
|
className = props.className,
|
67
77
|
placement = props.placement,
|
68
78
|
arrowProps = props.arrowProps,
|
79
|
+
arrowCrossOffset = props.arrowCrossOffset,
|
69
80
|
isOpen = props.isOpen,
|
70
81
|
hasNoArrow = props.hasNoArrow,
|
71
82
|
isNotClosedOnBlur = props.isNotClosedOnBlur,
|
72
83
|
isKeyboardDismissDisabled = props.isKeyboardDismissDisabled,
|
73
84
|
isNonModal = props.isNonModal,
|
74
85
|
isDismissable = props.isDismissable,
|
86
|
+
width = props.width,
|
87
|
+
direction = props.direction,
|
88
|
+
sx = props.sx,
|
75
89
|
others = _objectWithoutProperties(props, _excluded2);
|
76
90
|
|
77
91
|
var popoverRef = useRef();
|
@@ -102,8 +116,14 @@ export var PopoverWrapper = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
102
116
|
className: classNames,
|
103
117
|
role: "presentation",
|
104
118
|
"data-popover-placement": placement,
|
105
|
-
"data-testid": "popover-container"
|
106
|
-
|
119
|
+
"data-testid": "popover-container",
|
120
|
+
sx: _objectSpread(_objectSpread({}, sx), {}, {
|
121
|
+
width: width
|
122
|
+
})
|
123
|
+
}), children, hasNoArrow ? null : ___EmotionJSX(PopoverArrow, _extends({}, arrowProps, {
|
124
|
+
arrowCrossOffset: arrowCrossOffset,
|
125
|
+
direction: direction
|
126
|
+
}))));
|
107
127
|
});
|
108
128
|
PopoverWrapper.propTypes = {
|
109
129
|
placement: PropTypes.string,
|
@@ -113,18 +133,58 @@ PopoverWrapper.propTypes = {
|
|
113
133
|
isNotClosedOnBlur: PropTypes.bool,
|
114
134
|
isKeyboardDismissDisabled: PropTypes.bool,
|
115
135
|
isNonModal: PropTypes.bool,
|
116
|
-
isDismissable: PropTypes.bool
|
136
|
+
isDismissable: PropTypes.bool,
|
137
|
+
width: PropTypes.string,
|
138
|
+
arrowCrossOffset: PropTypes.string,
|
139
|
+
sx: PropTypes.shape({}),
|
140
|
+
direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left'])
|
117
141
|
};
|
118
142
|
PopoverWrapper.defaultProps = {
|
119
143
|
placement: 'bottom'
|
120
144
|
};
|
121
145
|
export var PopoverArrow = function PopoverArrow(props) {
|
122
|
-
var
|
146
|
+
var arrowCrossOffset = props.arrowCrossOffset,
|
147
|
+
sx = props.sx,
|
148
|
+
direction = props.direction,
|
149
|
+
others = _objectWithoutProperties(props, _excluded3);
|
150
|
+
/* istanbul ignore next */
|
151
|
+
|
152
|
+
|
153
|
+
var calculateOffset = function calculateOffset() {
|
154
|
+
switch (true) {
|
155
|
+
case direction === 'top':
|
156
|
+
case direction === 'bottom':
|
157
|
+
return {
|
158
|
+
'&:before': {
|
159
|
+
left: "calc(50% - ".concat(arrowCrossOffset, ") !important")
|
160
|
+
}
|
161
|
+
};
|
162
|
+
|
163
|
+
case direction === 'left':
|
164
|
+
case direction === 'right':
|
165
|
+
return {
|
166
|
+
'&:before': {
|
167
|
+
top: "calc(50% - ".concat(arrowCrossOffset, ") !important")
|
168
|
+
}
|
169
|
+
};
|
170
|
+
|
171
|
+
default:
|
172
|
+
return {};
|
173
|
+
}
|
174
|
+
};
|
123
175
|
|
124
176
|
return ___EmotionJSX(Box, _extends({
|
125
177
|
variant: "popoverMenu.arrow",
|
126
178
|
"data-popover-arrow": "arrow",
|
127
179
|
"data-testid": "popover-arrow"
|
128
|
-
}, others
|
180
|
+
}, others, {
|
181
|
+
sx: _objectSpread(_objectSpread({}, arrowCrossOffset && calculateOffset()), sx)
|
182
|
+
}));
|
183
|
+
};
|
184
|
+
PopoverArrow.propTypes = {
|
185
|
+
width: PropTypes.string,
|
186
|
+
arrowCrossOffset: PropTypes.string,
|
187
|
+
sx: PropTypes.shape({}),
|
188
|
+
direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left'])
|
129
189
|
};
|
130
190
|
export default PopoverContainer;
|