@pingux/astro 1.38.0-alpha.8 → 1.38.0-alpha.9

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.
@@ -147,7 +147,7 @@ var ComboBoxInput = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
147
147
  }, [isLoading, showLoading, inputValue]); // END - minimum delay time for loading indicator = 500ms
148
148
 
149
149
  (0, _hooks.usePropWarning)(props, 'disabled', 'isDisabled');
150
- var button = (0, _react2.jsx)(_.Box, {
150
+ var button = !isReadOnly && (0, _react2.jsx)(_.Box, {
151
151
  isRow: true,
152
152
  variant: "boxes.inputInContainerSlot"
153
153
  }, // Render loader after delay if filtering or loading
@@ -76,7 +76,7 @@ var _ScrollBox = _interopRequireDefault(require("../ScrollBox"));
76
76
 
77
77
  var _react2 = require("@emotion/react");
78
78
 
79
- var _excluded = ["hasAutoFocus", "hasAddOption", "hasCustomValue", "hasNoEmptySelection", "selectedKey", "onSelectionChange", "defaultItems", "items", "loadingState", "onLoadMore", "inputValue", "menuTrigger", "isNotFlippable", "direction", "scrollBoxProps", "controlProps", "defaultFilter", "status", "helperText"],
79
+ var _excluded = ["hasAutoFocus", "hasAddOption", "hasCustomValue", "hasNoEmptySelection", "selectedKey", "onSelectionChange", "defaultItems", "items", "loadingState", "onLoadMore", "inputValue", "isReadOnly", "menuTrigger", "isNotFlippable", "direction", "scrollBoxProps", "controlProps", "defaultFilter", "status", "helperText"],
80
80
  _excluded2 = ["shouldFocusOnHover", "shouldSelectOnPressUp"];
81
81
 
82
82
  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); }
@@ -108,6 +108,7 @@ var ComboBoxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
108
108
  loadingState = props.loadingState,
109
109
  onLoadMore = props.onLoadMore,
110
110
  inputValue = props.inputValue,
111
+ isReadOnly = props.isReadOnly,
111
112
  menuTrigger = props.menuTrigger,
112
113
  isNotFlippable = props.isNotFlippable,
113
114
  direction = props.direction,
@@ -183,7 +184,7 @@ var ComboBoxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
183
184
  contains = _useFilter.contains;
184
185
 
185
186
  var state = (0, _combobox2.useComboBoxState)(_objectSpread(_objectSpread({}, comboBoxOptions), {}, {
186
- defaultItems: defaultItems,
187
+ defaultItems: isReadOnly ? [] : defaultItems,
187
188
  items: items,
188
189
  onSelectionChange: hasAddOption || hasCustomValue ? onSelectionChangeHandler : onSelectionChange,
189
190
  defaultFilter: typeof defaultFilter !== 'undefined' ? defaultFilter : contains
@@ -254,7 +255,16 @@ var ComboBoxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
254
255
  minWidth: menuWidth
255
256
  });
256
257
 
257
- var listbox = (0, _react2.jsx)(_focus.FocusScope, {
258
+ var listBox = !isReadOnly && (0, _react2.jsx)(_PopoverContainer["default"], {
259
+ hasNoArrow: true,
260
+ isDismissable: true,
261
+ isNonModal: true,
262
+ isOpen: state.isOpen,
263
+ onClose: state.close,
264
+ placement: placement,
265
+ ref: popoverRef,
266
+ style: style
267
+ }, (0, _react2.jsx)(_focus.FocusScope, {
258
268
  restoreFocus: true
259
269
  }, (0, _react2.jsx)(_overlays.DismissButton, {
260
270
  onDismiss: state.close
@@ -270,7 +280,7 @@ var ComboBoxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
270
280
  isSelectedOnPressUp: shouldSelectOnPressUp
271
281
  }, otherListBoxProps))), (0, _react2.jsx)(_overlays.DismissButton, {
272
282
  onDismiss: state.close
273
- }));
283
+ })));
274
284
  return (0, _react2.jsx)(_react["default"].Fragment, null, (0, _react2.jsx)(_ComboBox["default"], (0, _extends2["default"])({}, props, {
275
285
  isOpen: state.isOpen,
276
286
  inputProps: inputProps,
@@ -281,16 +291,7 @@ var ComboBoxField = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
281
291
  triggerRef: buttonRef,
282
292
  controlProps: controlProps,
283
293
  "aria-invalid": status === 'error' && true
284
- })), (0, _react2.jsx)(_PopoverContainer["default"], {
285
- hasNoArrow: true,
286
- isDismissable: true,
287
- isNonModal: true,
288
- isOpen: state.isOpen,
289
- onClose: state.close,
290
- placement: placement,
291
- ref: popoverRef,
292
- style: style
293
- }, listbox));
294
+ })), listBox);
294
295
  });
295
296
  ComboBoxField.propTypes = _objectSpread({
296
297
  /* Whether or not adding new options to the list is enabled. */
@@ -26,7 +26,7 @@ _Object$defineProperty(exports, "__esModule", {
26
26
  value: true
27
27
  });
28
28
 
29
- exports["default"] = exports.WithoutStatusIndicator = exports.WithSections = exports.WithCustomInputValue = exports.WithCustomHeight = exports.Required = exports.HelperText = exports.FocusMenuTrigger = exports.DisabledKeys = exports.Disabled = exports.Default = exports.CustomDefaultFilter = exports.ControlledWithCustomValue = exports.ControlledWithAddOption = exports.ControlledSelection = exports.ControlledMenu = exports.ControlledInput = exports.ControlledFiltering = exports.AsyncLoading = exports.AllowCustomValue = void 0;
29
+ exports["default"] = exports.WithoutStatusIndicator = exports.WithSections = exports.WithCustomInputValue = exports.WithCustomHeight = exports.Required = exports.ReadOnly = exports.HelperText = exports.FocusMenuTrigger = exports.DisabledKeys = exports.Disabled = exports.Default = exports.CustomDefaultFilter = exports.ControlledWithCustomValue = exports.ControlledWithAddOption = exports.ControlledSelection = exports.ControlledMenu = exports.ControlledInput = exports.ControlledFiltering = exports.AsyncLoading = exports.AllowCustomValue = void 0;
30
30
 
31
31
  var _regenerator = _interopRequireDefault(require("@babel/runtime-corejs3/regenerator"));
32
32
 
@@ -567,6 +567,20 @@ var HelperText = function HelperText() {
567
567
 
568
568
  exports.HelperText = HelperText;
569
569
 
570
+ var ReadOnly = function ReadOnly() {
571
+ return (0, _react2.jsx)(_.OverlayProvider, null, (0, _react2.jsx)(_ComboBoxField["default"], (0, _extends2["default"])({
572
+ label: "Example label",
573
+ defaultItems: items,
574
+ isReadOnly: true
575
+ }, actions), function (item) {
576
+ return (0, _react2.jsx)(_.Item, {
577
+ key: item.name
578
+ }, item.name);
579
+ }));
580
+ };
581
+
582
+ exports.ReadOnly = ReadOnly;
583
+
570
584
  var Required = function Required() {
571
585
  return (0, _react2.jsx)(_.OverlayProvider, null, (0, _react2.jsx)(_ComboBoxField["default"], (0, _extends2["default"])({
572
586
  label: "Example label",
@@ -1215,4 +1215,40 @@ test('popover closes on input blur', function () {
1215
1215
 
1216
1216
  expect(_testWrapper.screen.queryByRole('listbox')).not.toBeInTheDocument();
1217
1217
  expect(_testWrapper.screen.queryByRole('option')).not.toBeInTheDocument();
1218
+ });
1219
+ describe('when isReadOnly is true', function () {
1220
+ var testProp = {
1221
+ isReadOnly: true
1222
+ };
1223
+ var TEST_DEFAULT_INPUT_VALUE = 'test default input value';
1224
+ test('it does not have the show suggestions button', function () {
1225
+ getComponent(testProp);
1226
+ expect(_testWrapper.screen.queryByRole('button', {
1227
+ name: "".concat(defaultProps.label, " Show suggestions")
1228
+ })).not.toBeInTheDocument();
1229
+ });
1230
+ test('it has attribute readonly', function () {
1231
+ getComponent(testProp);
1232
+ expect(_testWrapper.screen.getByRole('combobox', {
1233
+ name: defaultProps.label
1234
+ })).toHaveAttribute('readonly');
1235
+ });
1236
+ test('the default selected value is selected', function () {
1237
+ testProp.defaultInputValue = TEST_DEFAULT_INPUT_VALUE;
1238
+ getComponent(testProp);
1239
+ expect(_testWrapper.screen.getByRole('combobox', {
1240
+ name: defaultProps.label
1241
+ })).toHaveValue(TEST_DEFAULT_INPUT_VALUE);
1242
+ });
1243
+ test('the dropdown does not open when clicked', function () {
1244
+ getComponent(testProp);
1245
+
1246
+ _userEvent["default"].click(_testWrapper.screen.getByRole('combobox', {
1247
+ name: defaultProps.label
1248
+ }));
1249
+
1250
+ expect(_testWrapper.screen.queryByRole('listbox', {
1251
+ name: 'Test Label Suggestions'
1252
+ })).not.toBeInTheDocument();
1253
+ });
1218
1254
  });
@@ -99,7 +99,7 @@ var Default = function Default(_ref) {
99
99
  var variant = _ref.variant,
100
100
  args = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
101
101
  return (0, _react2.jsx)(_["default"], (0, _extends2["default"])({
102
- id: "custom-id",
102
+ id: "default-id",
103
103
  name: "custom-name",
104
104
  label: "Example Label"
105
105
  }, variant && {
@@ -113,7 +113,7 @@ exports.Default = Default;
113
113
 
114
114
  var SmallVariant = function SmallVariant() {
115
115
  return (0, _react2.jsx)(_["default"], {
116
- id: "custom-id",
116
+ id: "small-variant-id",
117
117
  name: "custom-name",
118
118
  label: "Example Label",
119
119
  controlProps: {
@@ -268,7 +268,7 @@ exports.Warning = Warning;
268
268
 
269
269
  var WithHelpHint = function WithHelpHint() {
270
270
  return (0, _react2.jsx)(_["default"], {
271
- id: "custom-id",
271
+ id: "with-help-hint-id",
272
272
  name: "custom-name",
273
273
  hintText: "Example Hint",
274
274
  label: "Example Label"
@@ -104,7 +104,7 @@ var ComboBoxInput = /*#__PURE__*/forwardRef(function (props, ref) {
104
104
 
105
105
  usePropWarning(props, 'disabled', 'isDisabled');
106
106
 
107
- var button = ___EmotionJSX(Box, {
107
+ var button = !isReadOnly && ___EmotionJSX(Box, {
108
108
  isRow: true,
109
109
  variant: "boxes.inputInContainerSlot"
110
110
  }, // Render loader after delay if filtering or loading
@@ -10,7 +10,7 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
10
10
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
11
11
  import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
12
12
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
13
- var _excluded = ["hasAutoFocus", "hasAddOption", "hasCustomValue", "hasNoEmptySelection", "selectedKey", "onSelectionChange", "defaultItems", "items", "loadingState", "onLoadMore", "inputValue", "menuTrigger", "isNotFlippable", "direction", "scrollBoxProps", "controlProps", "defaultFilter", "status", "helperText"],
13
+ var _excluded = ["hasAutoFocus", "hasAddOption", "hasCustomValue", "hasNoEmptySelection", "selectedKey", "onSelectionChange", "defaultItems", "items", "loadingState", "onLoadMore", "inputValue", "isReadOnly", "menuTrigger", "isNotFlippable", "direction", "scrollBoxProps", "controlProps", "defaultFilter", "status", "helperText"],
14
14
  _excluded2 = ["shouldFocusOnHover", "shouldSelectOnPressUp"];
15
15
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
16
16
  import _Array$from from "@babel/runtime-corejs3/core-js-stable/array/from";
@@ -59,6 +59,7 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
59
59
  loadingState = props.loadingState,
60
60
  onLoadMore = props.onLoadMore,
61
61
  inputValue = props.inputValue,
62
+ isReadOnly = props.isReadOnly,
62
63
  menuTrigger = props.menuTrigger,
63
64
  isNotFlippable = props.isNotFlippable,
64
65
  direction = props.direction,
@@ -135,7 +136,7 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
135
136
  contains = _useFilter.contains;
136
137
 
137
138
  var state = useComboBoxState(_objectSpread(_objectSpread({}, comboBoxOptions), {}, {
138
- defaultItems: defaultItems,
139
+ defaultItems: isReadOnly ? [] : defaultItems,
139
140
  items: items,
140
141
  onSelectionChange: hasAddOption || hasCustomValue ? onSelectionChangeHandler : onSelectionChange,
141
142
  defaultFilter: typeof defaultFilter !== 'undefined' ? defaultFilter : contains
@@ -206,7 +207,16 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
206
207
  minWidth: menuWidth
207
208
  });
208
209
 
209
- var listbox = ___EmotionJSX(FocusScope, {
210
+ var listBox = !isReadOnly && ___EmotionJSX(PopoverContainer, {
211
+ hasNoArrow: true,
212
+ isDismissable: true,
213
+ isNonModal: true,
214
+ isOpen: state.isOpen,
215
+ onClose: state.close,
216
+ placement: placement,
217
+ ref: popoverRef,
218
+ style: style
219
+ }, ___EmotionJSX(FocusScope, {
210
220
  restoreFocus: true
211
221
  }, ___EmotionJSX(DismissButton, {
212
222
  onDismiss: state.close
@@ -222,7 +232,7 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
222
232
  isSelectedOnPressUp: shouldSelectOnPressUp
223
233
  }, otherListBoxProps))), ___EmotionJSX(DismissButton, {
224
234
  onDismiss: state.close
225
- }));
235
+ })));
226
236
 
227
237
  return ___EmotionJSX(React.Fragment, null, ___EmotionJSX(ComboBoxInput, _extends({}, props, {
228
238
  isOpen: state.isOpen,
@@ -234,16 +244,7 @@ var ComboBoxField = /*#__PURE__*/forwardRef(function (props, ref) {
234
244
  triggerRef: buttonRef,
235
245
  controlProps: controlProps,
236
246
  "aria-invalid": status === 'error' && true
237
- })), ___EmotionJSX(PopoverContainer, {
238
- hasNoArrow: true,
239
- isDismissable: true,
240
- isNonModal: true,
241
- isOpen: state.isOpen,
242
- onClose: state.close,
243
- placement: placement,
244
- ref: popoverRef,
245
- style: style
246
- }, listbox));
247
+ })), listBox);
247
248
  });
248
249
  ComboBoxField.propTypes = _objectSpread({
249
250
  /* Whether or not adding new options to the list is enabled. */
@@ -478,6 +478,17 @@ export var HelperText = function HelperText() {
478
478
  }, item.name);
479
479
  }));
480
480
  };
481
+ export var ReadOnly = function ReadOnly() {
482
+ return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({
483
+ label: "Example label",
484
+ defaultItems: items,
485
+ isReadOnly: true
486
+ }, actions), function (item) {
487
+ return ___EmotionJSX(Item, {
488
+ key: item.name
489
+ }, item.name);
490
+ }));
491
+ };
481
492
  export var Required = function Required() {
482
493
  return ___EmotionJSX(OverlayProvider, null, ___EmotionJSX(ComboBoxField, _extends({
483
494
  label: "Example label",
@@ -1008,4 +1008,38 @@ test('popover closes on input blur', function () {
1008
1008
  userEvent.click(document.body);
1009
1009
  expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
1010
1010
  expect(screen.queryByRole('option')).not.toBeInTheDocument();
1011
+ });
1012
+ describe('when isReadOnly is true', function () {
1013
+ var testProp = {
1014
+ isReadOnly: true
1015
+ };
1016
+ var TEST_DEFAULT_INPUT_VALUE = 'test default input value';
1017
+ test('it does not have the show suggestions button', function () {
1018
+ getComponent(testProp);
1019
+ expect(screen.queryByRole('button', {
1020
+ name: "".concat(defaultProps.label, " Show suggestions")
1021
+ })).not.toBeInTheDocument();
1022
+ });
1023
+ test('it has attribute readonly', function () {
1024
+ getComponent(testProp);
1025
+ expect(screen.getByRole('combobox', {
1026
+ name: defaultProps.label
1027
+ })).toHaveAttribute('readonly');
1028
+ });
1029
+ test('the default selected value is selected', function () {
1030
+ testProp.defaultInputValue = TEST_DEFAULT_INPUT_VALUE;
1031
+ getComponent(testProp);
1032
+ expect(screen.getByRole('combobox', {
1033
+ name: defaultProps.label
1034
+ })).toHaveValue(TEST_DEFAULT_INPUT_VALUE);
1035
+ });
1036
+ test('the dropdown does not open when clicked', function () {
1037
+ getComponent(testProp);
1038
+ userEvent.click(screen.getByRole('combobox', {
1039
+ name: defaultProps.label
1040
+ }));
1041
+ expect(screen.queryByRole('listbox', {
1042
+ name: 'Test Label Suggestions'
1043
+ })).not.toBeInTheDocument();
1044
+ });
1011
1045
  });
@@ -57,7 +57,7 @@ export var Default = function Default(_ref) {
57
57
  args = _objectWithoutProperties(_ref, _excluded);
58
58
 
59
59
  return ___EmotionJSX(TextField, _extends({
60
- id: "custom-id",
60
+ id: "default-id",
61
61
  name: "custom-name",
62
62
  label: "Example Label"
63
63
  }, variant && {
@@ -68,7 +68,7 @@ export var Default = function Default(_ref) {
68
68
  };
69
69
  export var SmallVariant = function SmallVariant() {
70
70
  return ___EmotionJSX(TextField, {
71
- id: "custom-id",
71
+ id: "small-variant-id",
72
72
  name: "custom-name",
73
73
  label: "Example Label",
74
74
  controlProps: {
@@ -187,7 +187,7 @@ export var Warning = function Warning() {
187
187
  };
188
188
  export var WithHelpHint = function WithHelpHint() {
189
189
  return ___EmotionJSX(TextField, {
190
- id: "custom-id",
190
+ id: "with-help-hint-id",
191
191
  name: "custom-name",
192
192
  hintText: "Example Hint",
193
193
  label: "Example Label"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "1.38.0-alpha.8",
3
+ "version": "1.38.0-alpha.9",
4
4
  "description": "PingUX themeable React component library",
5
5
  "repository": {
6
6
  "type": "git",