@pingux/astro 2.242.1-alpha.0 → 2.243.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,16 +5,12 @@ import { useFilter } from '@react-aria/i18n';
5
5
  import { useLayoutEffect, useResizeObserver } from '@react-aria/utils';
6
6
  import { VisuallyHidden } from '@react-aria/visually-hidden';
7
7
  import { useListState } from '@react-stately/list';
8
- import PropTypes from 'prop-types';
9
8
  import { Badge, Box, Loader, ScrollBox, Text, TextField } from '../..';
10
9
  import { MultivaluesContext } from '../../context/MultivaluesContext';
11
10
  import { useGetTheme, useInputLoader, usePropWarning } from '../../hooks';
12
11
  import loadingStates from '../../utils/devUtils/constants/loadingStates';
13
12
  import { getPendoID } from '../../utils/devUtils/constants/pendoID';
14
- import { isIterableProp } from '../../utils/devUtils/props/isIterable';
15
- import { ariaAttributesBasePropTypes } from '../../utils/docUtils/ariaAttributes';
16
- import { inputFieldAttributesBasePropTypes } from '../../utils/docUtils/fieldAttributes';
17
- import { statusDefaultProp, statusPropTypes } from '../../utils/docUtils/statusProp';
13
+ import statuses from '../../utils/devUtils/constants/statuses';
18
14
  import ListBox from '../ListBox';
19
15
  import Popover from '../Popover/Popover';
20
16
  import BadgeLabelTooltip from './BadgeLabelTooltip';
@@ -26,7 +22,7 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
26
22
  } = props;
27
23
  const {
28
24
  defaultSelectedKeys,
29
- direction,
25
+ direction = 'bottom',
30
26
  disabledKeys = [],
31
27
  containerProps,
32
28
  hasAutoFocus,
@@ -36,7 +32,7 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
36
32
  isDisabled,
37
33
  isFilteringDisabled,
38
34
  isNotFlippable,
39
- isReadOnly,
35
+ isReadOnly = false,
40
36
  isRequired,
41
37
  label,
42
38
  loadingState,
@@ -54,8 +50,10 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
54
50
  placeholder,
55
51
  readOnlyKeys = [],
56
52
  selectedKeys,
57
- scrollBoxProps,
58
- status,
53
+ scrollBoxProps = {
54
+ maxHeight: 300
55
+ },
56
+ status = statuses.DEFAULT,
59
57
  ...others
60
58
  } = otherProps;
61
59
  const hasCustomValue = mode === 'non-restrictive';
@@ -77,7 +75,7 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
77
75
  }
78
76
  }, [initialItems, mode]);
79
77
  const toggleItems = keys => {
80
- setItems(initialItems.filter(item => !Array.from(keys).includes(item.key)));
78
+ setItems((initialItems || []).filter(item => !Array.from(keys).includes(item.key)));
81
79
  if (onSelectionChange) onSelectionChange(keys);
82
80
  // Selecting an option removes it from the list, unmounting its row while
83
81
  // focusedKey still points at it — the virtualizer then holds DOM focus on
@@ -98,7 +96,7 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
98
96
  };
99
97
  const state = useListState({
100
98
  ...otherProps,
101
- items: items.filter(({
99
+ items: (items || []).filter(({
102
100
  key
103
101
  }) => !readOnlyKeys.includes(key)),
104
102
  onSelectionChange: toggleItems,
@@ -110,6 +108,10 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
110
108
  const {
111
109
  selectionManager
112
110
  } = state;
111
+
112
+ // `selectionManager.state` is private in the react-stately typings but is
113
+ // read throughout this component; the access is kept via a cast.
114
+ const selectionManagerState = selectionManager.state;
113
115
  const filteredItems = useMemo(() => Array.from(state.collection), [state.collection, filterString]);
114
116
  const close = () => setIsOpen(false);
115
117
  const {
@@ -119,13 +121,13 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
119
121
  inputValue: filterString
120
122
  });
121
123
  const closeBadgeRefs = useRef([]);
122
- const inputWrapperRef = useRef();
123
- const inputRef = useRef();
124
+ const inputWrapperRef = useRef(null);
125
+ const inputRef = useRef(null);
124
126
  /* istanbul ignore next */
125
127
  useImperativeHandle(ref, () => inputWrapperRef.current);
126
128
  useImperativeHandle(ref, () => inputRef.current);
127
- const listBoxRef = useRef();
128
- const popoverRef = useRef();
129
+ const listBoxRef = useRef(null);
130
+ const popoverRef = useRef(null);
129
131
 
130
132
  // Measure the width of the input to inform the width of the menu (below).
131
133
  const [menuWidth, setMenuWidth] = useState(null);
@@ -151,13 +153,13 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
151
153
  useEffect(() => {
152
154
  if (defaultSelectedKeys) {
153
155
  selectionManager.setSelectedKeys(defaultSelectedKeys);
154
- setItems(prevItems => prevItems.filter(item => !Array.from(defaultSelectedKeys).includes(item.key)));
156
+ setItems(prevItems => (prevItems || []).filter(item => !Array.from(defaultSelectedKeys).includes(item.key)));
155
157
  }
156
158
  }, []);
157
159
  useEffect(() => {
158
160
  if (selectedKeys) {
159
161
  selectionManager.setSelectedKeys(selectedKeys);
160
- setItems(prevItems => prevItems.filter(item => !Array.from(selectedKeys).includes(item.key)));
162
+ setItems(prevItems => (prevItems || []).filter(item => !Array.from(selectedKeys).includes(item.key)));
161
163
  }
162
164
  }, []);
163
165
  useEffect(() => {
@@ -172,7 +174,7 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
172
174
  if (state.selectionManager.isSelected(key)) {
173
175
  return;
174
176
  }
175
- selectionManager.setSelectedKeys([].concat(Array.from(selectionManager.state.selectedKeys), [key]));
177
+ selectionManager.setSelectedKeys([].concat(Array.from(selectionManagerState.selectedKeys), [key]));
176
178
  setCustomItems([].concat(customItems, [{
177
179
  id: key,
178
180
  key,
@@ -261,9 +263,9 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
261
263
  if (activeBadgesKeys.length > 1) {
262
264
  const badgeIndex = activeBadgesKeys.findIndex(item => item === key);
263
265
  const nextFocusBadgeIndex = badgeIndex === activeBadgesKeys.length - 1 ? badgeIndex - 1 : badgeIndex;
264
- closeBadgeRefs.current[nextFocusBadgeIndex].focus();
266
+ closeBadgeRefs.current[nextFocusBadgeIndex]?.focus();
265
267
  } else {
266
- inputRef.current.focus();
268
+ inputRef.current?.focus();
267
269
  }
268
270
  };
269
271
  const readOnlyFieldBadge = (key, name) => {
@@ -292,28 +294,28 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
292
294
  }, name);
293
295
  };
294
296
  const readOnlyInputEntry = isReadOnly && (readOnlyKeys.length ? readOnlyKeys.map(key => {
295
- const item = [].concat(initialItems, customItems).find(el => el.key === key);
297
+ const item = [].concat(initialItems || [], customItems).find(el => el.key === key);
296
298
  if (item) {
297
- return readOnlyTextItem(item.key, item.name);
299
+ return item.key !== undefined && readOnlyTextItem(item.key, item.name);
298
300
  }
299
301
  return null;
300
- }) : initialItems.map(item => {
301
- return readOnlyTextItem(item.key, item.name);
302
+ }) : (initialItems || []).map(item => {
303
+ return item.key !== undefined && readOnlyTextItem(item.key, item.name);
302
304
  }));
303
305
  const onyxReadOnlyInputEntry = isReadOnly && ___EmotionJSX(Box, {
304
306
  isRow: true,
305
307
  gap: "xs"
306
- }, initialItems.map(item => {
307
- return readOnlyFieldBadge(item.key, item.name);
308
+ }, (initialItems || []).map(item => {
309
+ return item.key !== undefined && readOnlyFieldBadge(item.key, item.name || '');
308
310
  }));
309
311
  const readOnlyItems = !isReadOnly && readOnlyKeys.map(key => {
310
- const item = initialItems.find(el => el.key === key);
312
+ const item = (initialItems || []).find(el => el.key === key);
311
313
  if (item) {
312
314
  return ___EmotionJSX(Badge, {
313
315
  key: item.key,
314
316
  label: item.name,
315
317
  variant: "readOnlyBadge",
316
- as: "li",
318
+ as: 'li',
317
319
  tabIndex: 0
318
320
  });
319
321
  }
@@ -327,7 +329,7 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
327
329
  closeBadgeRefs: closeBadgeRefs
328
330
  });
329
331
  const selectedItems = ___EmotionJSX(React.Fragment, null, Array.from(selectionManager.selectedKeys).map((key, i) => {
330
- const item = [].concat(initialItems, customItems).find(el => el.key === key);
332
+ const item = [].concat(initialItems || [], customItems).find(el => el.key === key);
331
333
  if (item) {
332
334
  return multivaluesFieldBadge(item, i);
333
335
  }
@@ -391,7 +393,7 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
391
393
  isDisabled,
392
394
  isReadOnly,
393
395
  isRequired,
394
- label,
396
+ label: label,
395
397
  placeholder,
396
398
  wrapperProps: {
397
399
  ref: inputWrapperRef,
@@ -448,7 +450,7 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
448
450
  }, selectedItems), isOnyx ? onyxReadOnlyInputEntry : readOnlyInputEntry, selectionManager.selectedKeys.size > 0 && visuallyHidden)
449
451
  },
450
452
  value: filterString,
451
- helperText: helperText,
453
+ helperText,
452
454
  "aria-invalid": status === 'error' && true
453
455
  }, getPendoID('MultivaluesField'), others, inputProps)), ___EmotionJSX(Popover, {
454
456
  hasNoArrow: true,
@@ -462,112 +464,4 @@ const DefaultMultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
462
464
  sx: menuWidthSx
463
465
  }, listbox), ___EmotionJSX(EmptyVisuallyHidden, null)));
464
466
  });
465
- DefaultMultivaluesField.propTypes = {
466
- /** The initial selected keys in the collection (uncontrolled). */
467
- defaultSelectedKeys: isIterableProp,
468
- /** Where the menu opens relative to its trigger. */
469
- direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
470
- /**
471
- * The item keys that are disabled. These items cannot be selected.
472
- */
473
- disabledKeys: isIterableProp,
474
- /** Whether the element should receive focus on render. */
475
- hasAutoFocus: PropTypes.bool,
476
- /** Whether the field has a status indicator. */
477
- hasNoStatusIndicator: PropTypes.bool,
478
- /** Text rendered below the input. */
479
- helperText: PropTypes.node,
480
- /**
481
- * Props that get passed as-is to the underlying TextField element
482
- */
483
- inputProps: PropTypes.shape({}),
484
- /** Whether the input is disabled. */
485
- isDisabled: PropTypes.bool,
486
- /**
487
- * Whether the menu is prevented from flipping directions when insufficient space is
488
- * available for the given `direction` placement.
489
- */
490
- isNotFlippable: PropTypes.bool,
491
- /** Whether the input can be selected but not changed by the user. */
492
- isReadOnly: PropTypes.bool,
493
- /** Whether user input is required on the input before form submission. */
494
- isRequired: PropTypes.bool,
495
- /** The list of items.
496
- *
497
- * **Note:** Every item needs to have key and name properties.
498
- *
499
- * `Array<{key: string, name: string}>`
500
- */
501
- items: isIterableProp,
502
- /** The rendered label for the field. */
503
- label: PropTypes.string,
504
- /** Whether the component allows to create new values or only choose from the selection list */
505
- mode: PropTypes.oneOf(['restrictive', 'non-restrictive']),
506
- /**
507
- * Handler that is called when the element loses focus.
508
- *
509
- * `(e: FocusEvent) => void`
510
- */
511
- onBlur: PropTypes.func,
512
- /**
513
- * Handler that is called when the element receives focus.
514
- *
515
- * `(e: FocusEvent) => void`
516
- */
517
- onFocus: PropTypes.func,
518
- /**
519
- * Handler that is called when the input value changes.
520
- *
521
- * `(value: string) => void`
522
- */
523
- onInputChange: PropTypes.func,
524
- /**
525
- * Handler that is called when a key is pressed.
526
- *
527
- * `(e: KeyboardEvent) => void`
528
- */
529
- onKeyDown: PropTypes.func,
530
- /**
531
- * Handler that is called when a key is released.
532
- *
533
- * `(e: KeyboardEvent) => void`
534
- */
535
- onKeyUp: PropTypes.func,
536
- /**
537
- * Method that is called when the open state of the menu changes.
538
- *
539
- * `(isOpen: boolean) => void`
540
- */
541
- onOpenChange: PropTypes.func,
542
- /**
543
- * Handler that is called when the selection changes.
544
- *
545
- * `(keys: Iterable<Key>) => any`
546
- */
547
- onSelectionChange: PropTypes.func,
548
- /** Temporary text that occupies the text input when it is empty. */
549
- placeholder: PropTypes.string,
550
- /**
551
- * The item keys that are readonly. These items cannot be changed or selected.
552
- */
553
- readOnlyKeys: PropTypes.arrayOf(PropTypes.string),
554
- /** The currently selected keys in the collection (controlled). */
555
- selectedKeys: isIterableProp,
556
- // /** Props object that is spread directly into the ScrollBox element. */
557
- /** @ignore */
558
- scrollBoxProps: PropTypes.shape({
559
- maxHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number])
560
- }),
561
- ...statusPropTypes,
562
- ...ariaAttributesBasePropTypes,
563
- ...inputFieldAttributesBasePropTypes
564
- };
565
- DefaultMultivaluesField.defaultProps = {
566
- direction: 'bottom',
567
- isReadOnly: false,
568
- scrollBoxProps: {
569
- maxHeight: 300
570
- },
571
- ...statusDefaultProp
572
- };
573
467
  export default DefaultMultivaluesField;
@@ -1,119 +1,20 @@
1
1
  import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
2
2
  import React, { forwardRef } from 'react';
3
- import PropTypes from 'prop-types';
4
- import { isIterableProp } from '../../utils/devUtils/props/isIterable';
5
- import { ariaAttributesBasePropTypes } from '../../utils/docUtils/ariaAttributes';
6
- import { inputFieldAttributesBasePropTypes } from '../../utils/docUtils/fieldAttributes';
7
- import { statusDefaultProp, statusPropTypes } from '../../utils/docUtils/statusProp';
3
+ import { statusDefaultProp } from '../../utils/docUtils/statusProp';
8
4
  import CondensedMultivaluesField from './CondensedMultivaluesField';
9
5
  import DefaultMultivaluesField from './DefaultMultivaluesField';
10
6
  import { jsx as ___EmotionJSX } from "@emotion/react";
7
+ const displayName = 'MultivaluesField';
8
+
9
+ // No cast on the forwardRef result: a type assertion makes the react-docgen
10
+ // analyzer fail to extract the props table, which breaks the Storybook docs
11
+ // controls (argTypes lose their types and options).
11
12
  const MultivaluesField = /*#__PURE__*/forwardRef((props, ref) => {
12
13
  const Component = props.mode === 'condensed' ? CondensedMultivaluesField : DefaultMultivaluesField;
13
14
  return ___EmotionJSX(Component, _extends({
14
15
  ref: ref
15
16
  }, props));
16
17
  });
17
- MultivaluesField.propTypes = {
18
- /** The initial selected keys in the collection (uncontrolled). */
19
- defaultSelectedKeys: isIterableProp,
20
- /** Where the menu opens relative to its trigger. */
21
- direction: PropTypes.oneOf(['top', 'right', 'bottom', 'left']),
22
- /**
23
- * The item keys that are disabled. These items cannot be selected.
24
- */
25
- disabledKeys: isIterableProp,
26
- /** Whether the element should receive focus on render. */
27
- hasAutoFocus: PropTypes.bool,
28
- /** Whether the field has a status indicator. */
29
- hasNoStatusIndicator: PropTypes.bool,
30
- /** Text rendered below the input. */
31
- helperText: PropTypes.node,
32
- /**
33
- * Props that get passed as-is to the underlying TextField element
34
- */
35
- inputProps: PropTypes.shape({}),
36
- /** Whether the input is disabled. */
37
- isDisabled: PropTypes.bool,
38
- /**
39
- * Whether the menu is prevented from flipping directions when insufficient space is
40
- * available for the given `direction` placement.
41
- */
42
- isNotFlippable: PropTypes.bool,
43
- /** Whether the input can be selected but not changed by the user. */
44
- isReadOnly: PropTypes.bool,
45
- /** Whether user input is required on the input before form submission. */
46
- isRequired: PropTypes.bool,
47
- /** The list of items.
48
- *
49
- * **Note:** Every item needs to have key and name properties.
50
- *
51
- * `Array<{key: string, name: string}>`
52
- */
53
- items: isIterableProp,
54
- /** The rendered label for the field. */
55
- label: PropTypes.string,
56
- /** Whether the component allows to create new values or only choose from the selection list */
57
- mode: PropTypes.oneOf(['restrictive', 'non-restrictive', 'condensed']),
58
- /**
59
- * Handler that is called when the element loses focus.
60
- *
61
- * `(e: FocusEvent) => void`
62
- */
63
- onBlur: PropTypes.func,
64
- /**
65
- * Handler that is called when the element receives focus.
66
- *
67
- * `(e: FocusEvent) => void`
68
- */
69
- onFocus: PropTypes.func,
70
- /**
71
- * Handler that is called when the input value changes.
72
- *
73
- * `(value: string) => void`
74
- */
75
- onInputChange: PropTypes.func,
76
- /**
77
- * Handler that is called when a key is pressed.
78
- *
79
- * `(e: KeyboardEvent) => void`
80
- */
81
- onKeyDown: PropTypes.func,
82
- /**
83
- * Handler that is called when a key is released.
84
- *
85
- * `(e: KeyboardEvent) => void`
86
- */
87
- onKeyUp: PropTypes.func,
88
- /**
89
- * Method that is called when the open state of the menu changes.
90
- *
91
- * `(isOpen: boolean) => void`
92
- */
93
- onOpenChange: PropTypes.func,
94
- /**
95
- * Handler that is called when the selection changes.
96
- *
97
- * `(keys: Iterable<Key>) => any`
98
- */
99
- onSelectionChange: PropTypes.func,
100
- /** Temporary text that occupies the text input when it is empty. */
101
- placeholder: PropTypes.string,
102
- /**
103
- * The item keys that are readonly. These items cannot be changed or selected.
104
- */
105
- readOnlyKeys: PropTypes.arrayOf(PropTypes.string),
106
- /** The currently selected keys in the collection (controlled). */
107
- selectedKeys: isIterableProp,
108
- // /** Props object that is spread directly into the ScrollBox element. */
109
- /** @ignore */
110
- scrollBoxProps: PropTypes.shape({
111
- maxHeight: PropTypes.oneOfType([PropTypes.string, PropTypes.object, PropTypes.number])
112
- }),
113
- ...statusPropTypes,
114
- ...ariaAttributesBasePropTypes,
115
- ...inputFieldAttributesBasePropTypes
116
- };
117
18
  MultivaluesField.defaultProps = {
118
19
  direction: 'bottom',
119
20
  isReadOnly: false,
@@ -122,4 +23,5 @@ MultivaluesField.defaultProps = {
122
23
  },
123
24
  ...statusDefaultProp
124
25
  };
26
+ MultivaluesField.displayName = displayName;
125
27
  export default MultivaluesField;
@@ -41,7 +41,7 @@ const RadioGroupField = /*#__PURE__*/forwardRef((props, ref) => {
41
41
  return ___EmotionJSX(Box, _extends({
42
42
  ref: ref,
43
43
  className: classNames
44
- }, getPendoID(displayName), unhandledAriaProps, radioGroupProps), ___EmotionJSX(Label, _extends({
44
+ }, getPendoID(displayName), unhandledAriaProps, radioGroupProps), label && ___EmotionJSX(Label, _extends({
45
45
  isDisabled: isDisabled,
46
46
  hintText: hintText,
47
47
  isRequired: isRequired,
@@ -0,0 +1 @@
1
+ export {};
@@ -53,6 +53,7 @@ export * from './menuItem';
53
53
  export * from './menuSection';
54
54
  export * from './messages';
55
55
  export * from './Modal';
56
+ export * from './MultivaluesField';
56
57
  export * from './navBar';
57
58
  export * from './navSideBar';
58
59
  export * from './numberField';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pingux/astro",
3
- "version": "2.242.1-alpha.0",
3
+ "version": "2.243.0",
4
4
  "description": "React component library for Ping Identity's design system",
5
5
  "repository": {
6
6
  "type": "git",
@@ -68,7 +68,7 @@
68
68
  "@internationalized/number": "^3.6.0",
69
69
  "@monaco-editor/react": "4.4.2",
70
70
  "@pingux/mdi-react": "^1.2.0",
71
- "@pingux/onyx-tokens": "^0.44.5",
71
+ "@pingux/onyx-tokens": "^0.44.6",
72
72
  "@react-aria/accordion": "~3.0.0-alpha.11",
73
73
  "@react-aria/breadcrumbs": "^3.1.4",
74
74
  "@react-aria/button": "^3.13.2",