@qualtrics/ui-react 2.49.0 → 2.49.1-alpha.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.
Files changed (37) hide show
  1. package/dist/__shared/cjs/{index-96632417.js → index-65fe6015.js} +71 -77
  2. package/dist/components/Button/Button2.js +9 -13
  3. package/dist/components/ColorPicker/Palette.js +33 -39
  4. package/dist/components/Combobox/Combobox.js +1 -1
  5. package/dist/components/ConfigPane/ConfigPane.js +5 -6
  6. package/dist/components/Dropdown/Dropdown.js +1 -1
  7. package/dist/components/Dropdown/DropdownButton.js +1 -1
  8. package/dist/components/NewMenu/BaseMenu.js +3 -3
  9. package/dist/components/Tabs/TabContextProvider.js +0 -2
  10. package/dist/components/Tooltip/Tooltip.js +2 -2
  11. package/dist/components/deprecated_NumberStepper/NumberStepperDecrement.js +1 -1
  12. package/dist/components/deprecated_NumberStepper/NumberStepperIncrement.js +1 -1
  13. package/dist/components/deprecated_Tabs/Tabs.js +2 -2
  14. package/dist/icons/index.d.ts +0 -2
  15. package/dist/index.d.ts +8 -4
  16. package/dist/index.js +1 -1
  17. package/dist/next/AdvancedTable/AdvancedTable.js +8 -6
  18. package/dist/next/AdvancedTable/AdvancedTable2.js +3 -3
  19. package/dist/next/AdvancedTable/AdvancedTableCheckbox.js +6 -1
  20. package/dist/next/AdvancedTable/AdvancedTableColumnHeader.js +15 -6
  21. package/dist/next/AdvancedTable/AdvancedTableDnDContext.js +32 -0
  22. package/dist/next/AdvancedTable/AdvancedTableDragPreview.js +9 -11
  23. package/dist/next/AdvancedTable/AdvancedTableRow.js +6 -1
  24. package/dist/next/AdvancedTable/AdvancedTableRowExpandButton.js +12 -3
  25. package/dist/next/AdvancedTable/useAdvancedTableDragAndDrop.js +30 -138
  26. package/dist/next/AdvancedTable/useDragAndDropConfig.js +191 -0
  27. package/dist/next/Drawer/Drawer.js +1 -1
  28. package/dist/next/Menu/Hooks/usePaneSearch.js +12 -7
  29. package/dist/next/PhoneNumberInput/PhoneNumberInput.js +1 -0
  30. package/dist/next/index.d.ts +14 -12
  31. package/dist/next/index.js +263 -126
  32. package/dist/utils/Text/Text.js +1 -1
  33. package/dist/utils/Translation/containsComponentOrElement.js +6 -3
  34. package/dist/utils/Translation/useTranslation.js +5 -1
  35. package/icons/package.json +9 -9
  36. package/next/package.json +9 -9
  37. package/package.json +40 -40
@@ -0,0 +1,191 @@
1
+ import { useState } from 'react';
2
+ import { useSensors, useSensor, MouseSensor, pointerWithin, getClientRect, MeasuringStrategy, MeasuringFrequency } from '@dnd-kit/core';
3
+ import { restrictToWindowEdges } from '@dnd-kit/modifiers';
4
+ import '../../hooks/index.js';
5
+ import useLatest from '../../hooks/useLatest/useLatest.js';
6
+
7
+ const useDragAndDropConfig = (setDragSource, setDropTarget, setDropTargetSide, setPinnedColumns, setColumnOrder, setIsDragging, dropTargetSide) => {
8
+ const dropTargetSideRef = useLatest(dropTargetSide);
9
+ const [initSourcePos, setInitSourcePos] = useState(0);
10
+ const dragAndDropMonitorConfig = {
11
+ onDragStart: event => {
12
+ var _event$active$data$cu, _event$active;
13
+ setDragSource((_event$active$data$cu = event.active.data.current) === null || _event$active$data$cu === void 0 ? void 0 : _event$active$data$cu.id);
14
+ setIsDragging(true);
15
+ const {
16
+ x
17
+ } = ((_event$active = event.active) === null || _event$active === void 0 || (_event$active = _event$active.data.current) === null || _event$active === void 0 || (_event$active = _event$active.columnHeaderRef) === null || _event$active === void 0 || (_event$active = _event$active.current) === null || _event$active === void 0 ? void 0 : _event$active.getBoundingClientRect()) || {
18
+ x: 0
19
+ };
20
+ setInitSourcePos(x);
21
+ },
22
+ onDragCancel: () => {
23
+ setDragSource('');
24
+ setDropTarget('');
25
+ setDropTargetSide(undefined);
26
+ setIsDragging(false);
27
+ },
28
+ onDragEnd: event => {
29
+ setDragSource('');
30
+ setDropTarget('');
31
+ setDropTargetSide(undefined);
32
+ setIsDragging(false);
33
+ const {
34
+ active,
35
+ over
36
+ } = event;
37
+ if (!over) return;
38
+ const {
39
+ id: dragSourceId,
40
+ columnIndex: dragSourceColumnIndex,
41
+ isPinned: dragSourceIsPinned
42
+ } = active.data.current;
43
+ const {
44
+ id,
45
+ columnIndex,
46
+ isPinned
47
+ } = over.data.current;
48
+ if (id === dragSourceId || dropTargetSideRef.current === undefined) {
49
+ return;
50
+ }
51
+ if (isPinned && !dragSourceIsPinned) {
52
+ // Dragging from an unpinned column onto a pinned column
53
+ setPinnedColumns(pinnedColumns => {
54
+ const newPinnedColumns = [...pinnedColumns];
55
+ const newIndex = dropTargetSideRef.current === 'right' ? columnIndex + 1 : columnIndex;
56
+ newPinnedColumns.splice(newIndex, 0, dragSourceId);
57
+ return newPinnedColumns;
58
+ });
59
+ } else if (!isPinned && dragSourceIsPinned) {
60
+ // Dragging from a pinned column onto an upinned column
61
+ setPinnedColumns(pinnedColumns => {
62
+ const newPinnedColumns = [...pinnedColumns];
63
+ newPinnedColumns.splice(dragSourceColumnIndex, 1);
64
+ return newPinnedColumns;
65
+ });
66
+ setColumnOrder(currentColumnOrder => {
67
+ const newColumnOrder = [...currentColumnOrder];
68
+ const dragSourceColumnOrderIndex = newColumnOrder.indexOf(dragSourceId);
69
+ newColumnOrder.splice(dragSourceColumnOrderIndex, 1);
70
+ const columnOrderIndex = newColumnOrder.indexOf(id);
71
+ const newIndex = dropTargetSideRef.current === 'right' ? columnOrderIndex + 1 : columnOrderIndex;
72
+ newColumnOrder.splice(newIndex, 0, dragSourceId);
73
+ return newColumnOrder;
74
+ });
75
+ } else if (isPinned) {
76
+ // Dragging from a pinned column onto a pinned column
77
+ setPinnedColumns(pinnedColumns => {
78
+ const newPinnedColumns = [...pinnedColumns];
79
+ newPinnedColumns.splice(dragSourceColumnIndex, 1);
80
+ const newIndex = dropTargetSideRef.current === 'right' ? columnIndex + 1 : columnIndex;
81
+ newPinnedColumns.splice(newIndex, 0, dragSourceId);
82
+ return newPinnedColumns;
83
+ });
84
+ } else {
85
+ // Dragging from an upinned column onto an upinned column
86
+ setColumnOrder(currentColumnOrder => {
87
+ const newColumnOrder = [...currentColumnOrder];
88
+ const dropIndex = newColumnOrder.indexOf(dragSourceId);
89
+ newColumnOrder.splice(dropIndex, 1);
90
+ const columnOrderIndex = newColumnOrder.indexOf(id);
91
+ const newIndex = dropTargetSideRef.current === 'right' ? columnOrderIndex + 1 : columnOrderIndex;
92
+ newColumnOrder.splice(newIndex, 0, dragSourceId);
93
+ return newColumnOrder;
94
+ });
95
+ }
96
+ },
97
+ onDragMove: event => {
98
+ var _columnHeaderRef$curr, _DragSourceRef$curren;
99
+ const {
100
+ active,
101
+ over,
102
+ activatorEvent,
103
+ delta
104
+ } = event;
105
+ if (!over) return;
106
+ const {
107
+ id: dragSourceId,
108
+ columnIndex: dragSourceColumnIndex,
109
+ isPinned: dragSourceIsPinned,
110
+ columnHeaderRef: DragSourceRef
111
+ } = active.data.current;
112
+ const {
113
+ id,
114
+ columnIndex,
115
+ isPinned,
116
+ columnHeaderRef
117
+ } = over.data.current;
118
+ setDropTarget(id);
119
+ if (id === dragSourceId) {
120
+ setDropTargetSide(undefined);
121
+ return;
122
+ }
123
+
124
+ // Calculate which column line is closest
125
+ const {
126
+ x: targetX,
127
+ width: targetWidth
128
+ } = (columnHeaderRef === null || columnHeaderRef === void 0 || (_columnHeaderRef$curr = columnHeaderRef.current) === null || _columnHeaderRef$curr === void 0 ? void 0 : _columnHeaderRef$curr.getBoundingClientRect()) || {
129
+ x: 0,
130
+ width: 0
131
+ };
132
+ const {
133
+ x: sourceX
134
+ } = (DragSourceRef === null || DragSourceRef === void 0 || (_DragSourceRef$curren = DragSourceRef.current) === null || _DragSourceRef$curren === void 0 ? void 0 : _DragSourceRef$curren.getBoundingClientRect()) || {
135
+ x: 0
136
+ };
137
+
138
+ // Getting scroll position based on initial and current position
139
+ const scrollOffset = sourceX - initSourcePos;
140
+ const {
141
+ clientX: startPosition
142
+ } = activatorEvent;
143
+ const dropX = startPosition + delta.x;
144
+ const diffLeft = Math.abs(dropX - targetX + scrollOffset) || 0;
145
+ const diffRight = Math.abs(dropX - (targetX + targetWidth) + scrollOffset) || 0;
146
+ if (diffLeft < diffRight) {
147
+ // hover over left side
148
+ if (columnIndex - dragSourceColumnIndex === 1 && isPinned === dragSourceIsPinned) {
149
+ setDropTargetSide(undefined);
150
+ } else {
151
+ setDropTargetSide('left');
152
+ }
153
+ } else if (diffLeft >= diffRight) {
154
+ // hover over right side
155
+ if (dragSourceColumnIndex - columnIndex === 1 && isPinned === dragSourceIsPinned) {
156
+ setDropTargetSide(undefined);
157
+ } else {
158
+ setDropTargetSide('right');
159
+ }
160
+ }
161
+ }
162
+ };
163
+ const sensors = useSensors(useSensor(MouseSensor, {
164
+ activationConstraint: {
165
+ distance: 1
166
+ }
167
+ }));
168
+ return {
169
+ ...dragAndDropMonitorConfig,
170
+ sensors,
171
+ collisionDetection: pointerWithin,
172
+ modifiers: [restrictToWindowEdges],
173
+ measuring: {
174
+ droppable: {
175
+ measure: element => getClientRect(element, {
176
+ ignoreTransform: false
177
+ }),
178
+ strategy: MeasuringStrategy.WhileDragging,
179
+ frequency: MeasuringFrequency.Optimized
180
+ }
181
+ },
182
+ accessibility: {
183
+ screenReaderInstructions: {
184
+ draggable: 'draggable'
185
+ }
186
+ },
187
+ autoscroll: false
188
+ };
189
+ };
190
+
191
+ export { useDragAndDropConfig as default };
@@ -95,7 +95,7 @@ const Drawer = _ref => {
95
95
  const containerNode = (_containerRef$current = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) !== null && _containerRef$current !== void 0 ? _containerRef$current : document.body;
96
96
 
97
97
  /* eslint-disable jsx-a11y/no-noninteractive-element-interactions */
98
- return domReady ? /*#__PURE__*/createPortal( /*#__PURE__*/React__default.createElement("aside", {
98
+ return domReady ? /*#__PURE__*/createPortal(/*#__PURE__*/React__default.createElement("aside", {
99
99
  id: drawerId,
100
100
  className: classNames(styles.drawer, {
101
101
  [styles.hidden]: isHidden,
@@ -1,4 +1,4 @@
1
- import React__default, { useMemo, useRef, useCallback, useEffect } from 'react';
1
+ import React__default, { useMemo, useState, useCallback, useRef, useEffect } from 'react';
2
2
  import classNames from 'classnames';
3
3
  import '../../../hooks/index.js';
4
4
  import '../../../utils/index.js';
@@ -16,7 +16,6 @@ import useEventListener from '../../../hooks/useEventListener/useEventListener.j
16
16
  // creates a searchBarConfig, which maps to an instance of `MenuSearch`
17
17
  // returns values that are necessary for use within pane
18
18
  function usePaneSearch(_ref) {
19
- var _searchRef$current$qu, _searchRef$current;
20
19
  let {
21
20
  isSearchable,
22
21
  externalSearchValue,
@@ -52,8 +51,13 @@ function usePaneSearch(_ref) {
52
51
  return searchMatcher === null || searchMatcher === void 0 || (_searchMatcher$toLowe = searchMatcher.toLowerCase) === null || _searchMatcher$toLowe === void 0 ? void 0 : _searchMatcher$toLowe.call(searchMatcher).includes(internalSearchValue.toLowerCase());
53
52
  }), [internalSearchValue, children, isSearchFilteringDisabled]);
54
53
  const focusVirtualBoundary = useFocusVirtualBoundary(items, backButtonRef);
55
- const searchRef = useRef(null);
56
- const searchInput = (_searchRef$current$qu = (_searchRef$current = searchRef.current) === null || _searchRef$current === void 0 ? void 0 : _searchRef$current.querySelector('input')) !== null && _searchRef$current$qu !== void 0 ? _searchRef$current$qu : null;
54
+ const [searchInput, setSearchInput] = useState(null);
55
+ const [searchElement, setSearchElement] = useState(null);
56
+ const searchRef = useCallback(node => {
57
+ var _node$querySelector;
58
+ setSearchElement(node);
59
+ setSearchInput((_node$querySelector = node === null || node === void 0 ? void 0 : node.querySelector('input')) !== null && _node$querySelector !== void 0 ? _node$querySelector : null);
60
+ }, []);
57
61
  const getFirstVisibleItem = () => {
58
62
  var _backButtonRef$curren, _items$find;
59
63
  return (_backButtonRef$curren = backButtonRef === null || backButtonRef === void 0 ? void 0 : backButtonRef.current) !== null && _backButtonRef$curren !== void 0 ? _backButtonRef$curren : (_items$find = items.find(item => item.element.current)) === null || _items$find === void 0 ? void 0 : _items$find.element.current;
@@ -111,8 +115,8 @@ function usePaneSearch(_ref) {
111
115
  setSearchBarConfigs
112
116
  } = useMenuContext();
113
117
  const onInteractOutside = useCallback(e => searchBarConfigs.some(config => {
114
- var _config$ref$current;
115
- return (_config$ref$current = config.ref.current) === null || _config$ref$current === void 0 ? void 0 : _config$ref$current.contains(e.target);
118
+ var _config$searchElement;
119
+ return (_config$searchElement = config.searchElement) === null || _config$searchElement === void 0 ? void 0 : _config$searchElement.contains(e.target);
116
120
  }) && e.preventDefault(), [searchBarConfigs]);
117
121
  useEffect(() => {
118
122
  if (!isSearchable) {
@@ -128,6 +132,7 @@ function usePaneSearch(_ref) {
128
132
  dataTestId: menuParentDataTestId === null || menuParentDataTestId === void 0 ? void 0 : menuParentDataTestId.replace(withinSelect ? DATA_TESTID_SUFFIXES.SELECT_PANE : DATA_TESTID_SUFFIXES$1.MENU_PANE, withinSelect ? DATA_TESTID_SUFFIXES.SELECT_SEARCH : DATA_TESTID_SUFFIXES$1.MENU_SEARCH),
129
133
  setSearchValue,
130
134
  ref: searchRef,
135
+ searchElement,
131
136
  id,
132
137
  searchPlaceholder
133
138
  };
@@ -139,7 +144,7 @@ function usePaneSearch(_ref) {
139
144
  }
140
145
  return configsClone;
141
146
  });
142
- }, [isSearchable, searchPlaceholder, setSearchBarConfigs, internalSearchValue, animatedLeft, animatedRight, menuParentDataTestId, setSearchValue, searchRef, id, withinSelect]);
147
+ }, [isSearchable, searchPlaceholder, setSearchBarConfigs, internalSearchValue, animatedLeft, animatedRight, menuParentDataTestId, setSearchValue, searchRef, searchElement, id, withinSelect]);
143
148
  useEffect(() => () => setSearchBarConfigs(configs => {
144
149
  const configIndex = configs.findIndex(config => config.id === id);
145
150
  if (configIndex === -1) {
@@ -64,6 +64,7 @@ const PhoneNumberInput = /*#__PURE__*/forwardRef((_ref, ref) => {
64
64
  const phoneNumber = parsePhoneNumber(value, countryCode);
65
65
  internationalNumber = phoneNumber.number;
66
66
  isValidLength = phoneNumber.isPossible();
67
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
67
68
  } catch (e) {
68
69
  // `parsePhoneNumber` throws an error if the inputs are invalid.
69
70
  }
@@ -1,16 +1,12 @@
1
- /// <reference types="react" />
2
-
3
1
  import { AllHTMLAttributes } from 'react';
4
2
  import type { ChangeEvent } from 'react';
5
3
  import { ChangeEventHandler } from 'react';
6
4
  import { ComputedPlacement } from '@popperjs/core';
7
5
  import { CountryCode } from 'libphonenumber-js';
8
6
  import { CSSProperties } from 'react';
9
- import { DetailedHTMLProps } from 'react';
10
7
  import { E164Number } from 'libphonenumber-js';
11
8
  import { FocusEventHandler } from 'react';
12
9
  import { FormEvent } from 'react';
13
- import { FormHTMLAttributes } from 'react';
14
10
  import { FunctionComponent } from 'react';
15
11
  import type { InputHTMLAttributes } from 'react';
16
12
  import { MouseEventHandler } from 'react';
@@ -330,6 +326,10 @@ declare interface CheckboxRegisterProps<V extends Values> {
330
326
  ref: RefCallback<HTMLInputElement>;
331
327
  }
332
328
 
329
+ declare type ChildrenType = React_2.ReactNode & React_2.RefAttributes<HTMLElement>;
330
+
331
+ declare type ChildrenType_2 = React_2.ReactNode & React_2.RefAttributes<HTMLElement>;
332
+
333
333
  export declare const CollapsibleSearchInput: React_2.ForwardRefExoticComponent<CollapsibleSearchInputProps & React_2.RefAttributes<HTMLSpanElement>>;
334
334
 
335
335
  export declare interface CollapsibleSearchInputProps {
@@ -378,7 +378,7 @@ export declare interface CollectionGridItemProps {
378
378
  */
379
379
  asChild?: boolean;
380
380
  /** Content to display inside of the grid item */
381
- children?: React_2.ReactNode & React_2.RefAttributes<HTMLElement>;
381
+ children?: ChildrenType;
382
382
  /** Added to the containing `div` */
383
383
  'data-testid'?: string;
384
384
  }
@@ -695,6 +695,8 @@ export declare interface FilterAnchorProps extends Omit<AllHTMLAttributes<HTMLBu
695
695
  className?: string;
696
696
  }
697
697
 
698
+ declare type FormProps = React.ComponentPropsWithoutRef<'form'>;
699
+
698
700
  declare type HandleSubmit = (onSubmit: OnSubmit) => (event: FormEvent<HTMLFormElement>) => Promise<void>;
699
701
 
700
702
  export declare const HStack: React_2.ForwardRefExoticComponent<HStackProps & React_2.RefAttributes<HTMLDivElement>>;
@@ -773,7 +775,7 @@ export declare const LayoutGridItem: React_2.ForwardRefExoticComponent<LayoutGri
773
775
 
774
776
  export declare interface LayoutGridItemProps {
775
777
  /** Content to display inside of the grid item */
776
- children?: React_2.ReactNode & React_2.RefAttributes<HTMLElement>;
778
+ children?: ChildrenType_2;
777
779
  /** Assigns a grid item to one of the areas defined in the parent `LayoutGrid`'s `areas` prop */
778
780
  area?: React_2.CSSProperties['gridArea'];
779
781
  /** Replaces the `LayoutGridItem`'s default element with its single child and merges `LayoutGridItem`'s props and behavior into the child's. This is especially useful if your grid item should be represented by a semantic HTML element. Use this prop with caution, as any future changes we make to the component may override the child's props.
@@ -1356,7 +1358,7 @@ export declare interface ToggleButtonProps {
1356
1358
  }
1357
1359
 
1358
1360
  export declare const Tooltip: React_2.ForwardRefExoticComponent<Omit<TooltipProps_2, "lightTheme"> & {
1359
- children: TooltipProps_2['children'];
1361
+ children: TooltipProps_2["children"];
1360
1362
  } & React_2.RefAttributes<HTMLDivElement>>;
1361
1363
 
1362
1364
  export declare type TooltipProps = Omit<TooltipProps_2, 'lightTheme'> & {
@@ -1412,20 +1414,20 @@ declare interface TooltipProps_2 extends Omit<React_2.AllHTMLAttributes<HTMLDivE
1412
1414
  }
1413
1415
 
1414
1416
  export declare function useForm<V extends Values>({ initialValues, validateField, }: UseFormOptions<V>): {
1415
- Form: (props: Omit<DetailedHTMLProps<FormHTMLAttributes<HTMLFormElement>, HTMLFormElement>, "ref">) => JSX.Element;
1417
+ Form: (props: FormProps) => JSX.Element;
1416
1418
  register: {
1417
1419
  (name: keyof V, options: {
1418
- type: 'text' | 'email' | 'password';
1420
+ type: "text" | "email" | "password";
1419
1421
  }): TextRegisterProps<V>;
1420
1422
  (name: keyof V, options: {
1421
- type: 'checkbox';
1423
+ type: "checkbox";
1422
1424
  }): CheckboxRegisterProps<V>;
1423
1425
  (name: keyof V, options: {
1424
- type: 'radio';
1426
+ type: "radio";
1425
1427
  radioValue: string;
1426
1428
  }): RadioRegisterProps<V>;
1427
1429
  (name: keyof V, options: {
1428
- type: 'custom';
1430
+ type: "custom";
1429
1431
  }): CustomRegisterProps<V>;
1430
1432
  };
1431
1433
  formValues: V;