@transferwise/components 0.0.0-experimental-fdc11fa → 0.0.0-experimental-88ddab3

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 (67) hide show
  1. package/build/index.esm.js +658 -13
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +661 -13
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +1 -1
  6. package/build/styles/inputs/Input.css +1 -1
  7. package/build/styles/inputs/InputGroup.css +1 -1
  8. package/build/styles/inputs/SelectInput.css +1 -0
  9. package/build/styles/inputs/TextArea.css +1 -1
  10. package/build/styles/main.css +1 -1
  11. package/build/types/common/hooks/useMedia.d.ts +2 -0
  12. package/build/types/common/hooks/useMedia.d.ts.map +1 -0
  13. package/build/types/common/hooks/useScreenSize.d.ts +3 -0
  14. package/build/types/common/hooks/useScreenSize.d.ts.map +1 -0
  15. package/build/types/common/preventScroll/PreventScroll.d.ts +2 -0
  16. package/build/types/common/preventScroll/PreventScroll.d.ts.map +1 -0
  17. package/build/types/dateLookup/dateTrigger/DateTrigger.messages.d.ts +7 -7
  18. package/build/types/dateLookup/dateTrigger/DateTrigger.messages.d.ts.map +1 -1
  19. package/build/types/index.d.ts +4 -0
  20. package/build/types/index.d.ts.map +1 -1
  21. package/build/types/inputs/Input.d.ts +1 -0
  22. package/build/types/inputs/Input.d.ts.map +1 -1
  23. package/build/types/inputs/SearchInput.d.ts +10 -0
  24. package/build/types/inputs/SearchInput.d.ts.map +1 -0
  25. package/build/types/inputs/SelectInput.d.ts +41 -0
  26. package/build/types/inputs/SelectInput.d.ts.map +1 -0
  27. package/build/types/inputs/_BottomSheet.d.ts +17 -0
  28. package/build/types/inputs/_BottomSheet.d.ts.map +1 -0
  29. package/build/types/inputs/_ButtonInput.d.ts +6 -0
  30. package/build/types/inputs/_ButtonInput.d.ts.map +1 -0
  31. package/build/types/inputs/_Popover.d.ts +18 -0
  32. package/build/types/inputs/_Popover.d.ts.map +1 -0
  33. package/build/types/inputs/_common.d.ts.map +1 -1
  34. package/build/types/utilities/wrapInFragment.d.ts +3 -0
  35. package/build/types/utilities/wrapInFragment.d.ts.map +1 -0
  36. package/package.json +13 -7
  37. package/src/common/hooks/useMedia.ts +15 -0
  38. package/src/common/hooks/useScreenSize.ts +7 -0
  39. package/src/common/preventScroll/PreventScroll.tsx +6 -0
  40. package/src/index.ts +8 -0
  41. package/src/inputs/Input.css +1 -1
  42. package/src/inputs/Input.less +14 -0
  43. package/src/inputs/Input.tsx +6 -2
  44. package/src/inputs/InputGroup.css +1 -1
  45. package/src/inputs/InputGroup.less +6 -1
  46. package/src/inputs/SearchInput.story.tsx +40 -0
  47. package/src/inputs/SearchInput.tsx +35 -0
  48. package/src/inputs/SelectInput.css +1 -0
  49. package/src/inputs/SelectInput.less +183 -0
  50. package/src/inputs/SelectInput.story.tsx +260 -0
  51. package/src/inputs/SelectInput.tsx +552 -0
  52. package/src/inputs/TextArea.css +1 -1
  53. package/src/inputs/TextArea.less +5 -0
  54. package/src/inputs/_BottomSheet.less +107 -0
  55. package/src/inputs/_BottomSheet.tsx +128 -0
  56. package/src/inputs/_ButtonInput.less +7 -0
  57. package/src/inputs/_ButtonInput.tsx +27 -0
  58. package/src/inputs/_Popover.less +38 -0
  59. package/src/inputs/_Popover.tsx +118 -0
  60. package/src/inputs/_common.less +0 -4
  61. package/src/inputs/_common.ts +0 -1
  62. package/src/main.css +1 -1
  63. package/src/main.less +4 -0
  64. package/src/select/searchBox/__snapshots__/SearchBox.spec.js.snap +1 -1
  65. package/src/ssr.spec.js +7 -0
  66. package/src/utilities/wrapInFragment.tsx +3 -0
  67. /package/src/dateLookup/dateTrigger/{DateTrigger.messages.js → DateTrigger.messages.ts} +0 -0
@@ -2,7 +2,7 @@ import classNames from 'classnames';
2
2
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
3
3
  import * as React from 'react';
4
4
  import React__default, { forwardRef, cloneElement, useState, useRef, useMemo, useEffect, useLayoutEffect, createContext, useContext, useCallback, PureComponent, createRef, Component, Children, Fragment as Fragment$1 } from 'react';
5
- import { ChevronUp, CrossCircleFill, Cross, NavigateAway, Check, Info as Info$1, Alert as Alert$2, ClockBorderless, CheckCircle, InfoCircle, Warning, CrossCircle, Clock, Briefcase, Person, ArrowLeft, QuestionMarkCircle, AlertCircle, CheckCircleFill, Search, ArrowRight, Download, ClockFill, Upload as Upload$2, Document, Plus, PlusCircle, AlertCircleFill } from '@transferwise/icons';
5
+ import { ChevronUp, CrossCircleFill, Cross, NavigateAway, Check, Info as Info$1, Alert as Alert$2, ClockBorderless, CheckCircle, InfoCircle, Warning, CrossCircle, Clock, Briefcase, Person, ArrowLeft, QuestionMarkCircle, AlertCircle, Search, ChevronDown, CheckCircleFill, ArrowRight, Download, ClockFill, Upload as Upload$2, Document, Plus, PlusCircle, AlertCircleFill } from '@transferwise/icons';
6
6
  import PropTypes from 'prop-types';
7
7
  import { defineMessages, useIntl, injectIntl, IntlProvider } from 'react-intl';
8
8
  import { useTheme, ThemeProvider } from '@wise/components-theming';
@@ -13,6 +13,11 @@ import { createPortal } from 'react-dom';
13
13
  import { isUndefined, isKey, isNumber, isEmpty, isNull, isArray } from '@transferwise/neptune-validation';
14
14
  import mergeRefs from 'react-merge-refs';
15
15
  import { usePopper } from 'react-popper';
16
+ import { Transition, Listbox } from '@headlessui/react';
17
+ import { useId } from '@radix-ui/react-id';
18
+ import { useSyncExternalStore } from 'use-sync-external-store/shim';
19
+ import { useFloating, useDismiss, useRole, useInteractions, FloatingPortal, FloatingFocusManager, offset, flip, shift, size, autoUpdate } from '@floating-ui/react';
20
+ import { usePreventScroll } from '@react-aria/overlays';
16
21
  import { Illustration } from '@wise/art';
17
22
  import clamp$2 from 'lodash.clamp';
18
23
  import debounce from 'lodash.debounce';
@@ -1969,7 +1974,7 @@ const MOVE_OFFSET_THRESHOLD = 50;
1969
1974
  * Neptune Web: https://transferwise.github.io/neptune-web/components/overlays/BottomSheet
1970
1975
  *
1971
1976
  */
1972
- const BottomSheet = props => {
1977
+ const BottomSheet$1 = props => {
1973
1978
  const bottomSheetReference = useRef(null);
1974
1979
  const topBarReference = useRef(null);
1975
1980
  const contentReference = useRef(null);
@@ -2123,7 +2128,7 @@ const BottomSheet = props => {
2123
2128
  })
2124
2129
  });
2125
2130
  };
2126
- var BottomSheet$1 = BottomSheet;
2131
+ var BottomSheet$2 = BottomSheet$1;
2127
2132
 
2128
2133
  const typeClassMap$1 = {
2129
2134
  [ControlType.ACCENT]: 'btn-accent',
@@ -3150,7 +3155,7 @@ const ResponsivePanel = /*#__PURE__*/forwardRef(({
3150
3155
  isMobile
3151
3156
  } = useLayout();
3152
3157
  if (isMobile) {
3153
- return /*#__PURE__*/jsx(BottomSheet$1, {
3158
+ return /*#__PURE__*/jsx(BottomSheet$2, {
3154
3159
  open: open,
3155
3160
  className: className,
3156
3161
  onClose: onClose,
@@ -5828,7 +5833,7 @@ const Modal = ({
5828
5833
  });
5829
5834
  };
5830
5835
 
5831
- const Popover = ({
5836
+ const Popover$1 = ({
5832
5837
  children,
5833
5838
  className,
5834
5839
  content,
@@ -5882,12 +5887,12 @@ const logActionRequired = ({
5882
5887
  }) => {
5883
5888
  logActionRequiredIf(`Popover has deprecated ${preferredPlacement} value for the 'preferredPlacement' prop. Please use ${deprecatedPlacements[preferredPlacement]} instead.`, deprecatedPlacements[preferredPlacement]);
5884
5889
  };
5885
- Popover.defaultProps = {
5890
+ Popover$1.defaultProps = {
5886
5891
  className: undefined,
5887
5892
  preferredPlacement: Position.RIGHT,
5888
5893
  title: undefined
5889
5894
  };
5890
- Popover.propTypes = {
5895
+ Popover$1.propTypes = {
5891
5896
  children: PropTypes.node.isRequired,
5892
5897
  className: PropTypes.string,
5893
5898
  content: PropTypes.node.isRequired,
@@ -5904,7 +5909,7 @@ const deprecatedPlacements = {
5904
5909
  [Position.LEFT_TOP]: Position.TOP,
5905
5910
  [Position.RIGHT_TOP]: Position.TOP
5906
5911
  };
5907
- var Popover$1 = Popover;
5912
+ var Popover$2 = Popover$1;
5908
5913
 
5909
5914
  const Info = ({
5910
5915
  className = undefined,
@@ -5946,7 +5951,7 @@ const Info = ({
5946
5951
  title: title,
5947
5952
  onClose: () => setOpen(false)
5948
5953
  })]
5949
- }) : /*#__PURE__*/jsx(Popover$1, {
5954
+ }) : /*#__PURE__*/jsx(Popover$2, {
5950
5955
  content: content,
5951
5956
  preferredPlacement: Position.BOTTOM,
5952
5957
  title: title,
@@ -6135,11 +6140,12 @@ function formControlClassNameBase({
6135
6140
  'np-form-control--size-sm np-text-body-default': size === 'sm',
6136
6141
  'np-form-control--size-md np-text-body-large': size === 'md',
6137
6142
  'np-form-control--size-lg np-text-title-subsection': size === 'lg'
6138
- }, 'np-form-control--shape-rectangle');
6143
+ });
6139
6144
  }
6140
6145
 
6141
6146
  const Input = /*#__PURE__*/forwardRef(function Input({
6142
6147
  size = 'auto',
6148
+ shape = 'rectangle',
6143
6149
  className,
6144
6150
  ...restProps
6145
6151
  }, reference) {
@@ -6148,7 +6154,10 @@ const Input = /*#__PURE__*/forwardRef(function Input({
6148
6154
  ref: reference,
6149
6155
  className: classNames(className, formControlClassNameBase({
6150
6156
  size
6151
- }))
6157
+ }), 'np-input', {
6158
+ 'np-input--shape-rectangle': shape === 'rectangle',
6159
+ 'np-input--shape-pill': shape === 'pill'
6160
+ })
6152
6161
  // eslint-disable-next-line react/forbid-dom-props
6153
6162
  ,
6154
6163
  style: inputPaddings,
@@ -6156,6 +6165,642 @@ const Input = /*#__PURE__*/forwardRef(function Input({
6156
6165
  });
6157
6166
  });
6158
6167
 
6168
+ const SearchInput = /*#__PURE__*/forwardRef(function SearchInput({
6169
+ shape = 'pill',
6170
+ disabled,
6171
+ className,
6172
+ ...restProps
6173
+ }, ref) {
6174
+ return /*#__PURE__*/jsx(InputGroup, {
6175
+ addonStart: {
6176
+ content: /*#__PURE__*/jsx(Search, {
6177
+ size: 24
6178
+ }),
6179
+ initialContentWidth: 24
6180
+ },
6181
+ disabled: disabled,
6182
+ className: className,
6183
+ children: /*#__PURE__*/jsx(Input, {
6184
+ ref: ref,
6185
+ role: "searchbox",
6186
+ inputMode: "search",
6187
+ shape: shape,
6188
+ ...restProps
6189
+ })
6190
+ });
6191
+ });
6192
+
6193
+ function useMedia(query) {
6194
+ return useSyncExternalStore(onStoreChange => {
6195
+ const mediaQueryList = window.matchMedia(query);
6196
+ mediaQueryList.addEventListener('change', onStoreChange);
6197
+ return () => {
6198
+ mediaQueryList.removeEventListener('change', onStoreChange);
6199
+ };
6200
+ }, () => typeof window !== 'undefined' ? window.matchMedia(query).matches : undefined, () => undefined);
6201
+ }
6202
+
6203
+ function useScreenSize(size) {
6204
+ return useMedia(`(min-width: ${size}px)`);
6205
+ }
6206
+
6207
+ function wrapInFragment(value) {
6208
+ return /*#__PURE__*/jsx(Fragment, {
6209
+ children: value
6210
+ });
6211
+ }
6212
+
6213
+ function PreventScroll() {
6214
+ usePreventScroll();
6215
+ return null;
6216
+ }
6217
+
6218
+ function BottomSheet({
6219
+ open,
6220
+ renderTrigger,
6221
+ title,
6222
+ initialFocusRef,
6223
+ padding = 'md',
6224
+ children,
6225
+ onClose
6226
+ }) {
6227
+ const {
6228
+ refs,
6229
+ context
6230
+ } = useFloating({
6231
+ open,
6232
+ onOpenChange: value => {
6233
+ if (!value) {
6234
+ onClose?.();
6235
+ }
6236
+ }
6237
+ });
6238
+ const dismiss = useDismiss(context, {
6239
+ outsidePressEvent: 'mousedown'
6240
+ });
6241
+ const role = useRole(context);
6242
+ const {
6243
+ getReferenceProps,
6244
+ getFloatingProps
6245
+ } = useInteractions([dismiss, role]);
6246
+ const [floatingKey, setFloatingKey] = useState(0);
6247
+ return /*#__PURE__*/jsxs(Fragment, {
6248
+ children: [open ? /*#__PURE__*/jsx(PreventScroll, {}) : null, renderTrigger?.({
6249
+ ref: refs.setReference,
6250
+ getInteractionProps: getReferenceProps
6251
+ }), /*#__PURE__*/jsx(FloatingPortal, {
6252
+ children: /*#__PURE__*/jsxs(Transition, {
6253
+ show: open,
6254
+ className: "np-bottom-sheet-v2-container",
6255
+ beforeEnter: () => {
6256
+ setFloatingKey(prev => prev + 1);
6257
+ },
6258
+ children: [/*#__PURE__*/jsx(Transition.Child, {
6259
+ enter: "np-bottom-sheet-v2-backdrop-container--enter",
6260
+ enterFrom: "np-bottom-sheet-v2-backdrop-container--enter-from",
6261
+ leave: "np-bottom-sheet-v2-backdrop-container--leave",
6262
+ leaveTo: "np-bottom-sheet-v2-backdrop-container--leave-to",
6263
+ children: /*#__PURE__*/jsx("div", {
6264
+ className: "np-bottom-sheet-v2-backdrop"
6265
+ })
6266
+ }), /*#__PURE__*/jsx(FloatingFocusManager, {
6267
+ context: context,
6268
+ initialFocus: initialFocusRef,
6269
+ children: /*#__PURE__*/jsx("div", {
6270
+ className: "np-bottom-sheet-v2",
6271
+ children: /*#__PURE__*/jsx(Transition.Child, {
6272
+ className: "np-bottom-sheet-v2-content",
6273
+ enter: "np-bottom-sheet-v2-content--enter",
6274
+ enterFrom: "np-bottom-sheet-v2-content--enter-from",
6275
+ leave: "np-bottom-sheet-v2-content--leave",
6276
+ leaveTo: "np-bottom-sheet-v2-content--leave-to",
6277
+ children: /*#__PURE__*/jsxs("div", {
6278
+ // Force inner state invalidation on open
6279
+ ref: refs.setFloating,
6280
+ className: "np-bottom-sheet-v2-content-inner-container",
6281
+ ...getFloatingProps(),
6282
+ children: [/*#__PURE__*/jsx("div", {
6283
+ className: "np-bottom-sheet-v2-header",
6284
+ children: /*#__PURE__*/jsx(CloseButton, {
6285
+ size: Size.SMALL,
6286
+ onClick: () => {
6287
+ onClose?.();
6288
+ }
6289
+ })
6290
+ }), /*#__PURE__*/jsxs("div", {
6291
+ className: classNames('np-bottom-sheet-v2-content-inner', title && 'np-bottom-sheet-v2-content-inner--has-title', {
6292
+ 'np-bottom-sheet-v2-content-inner--padding-md': padding === 'md'
6293
+ }),
6294
+ children: [title ? /*#__PURE__*/jsx("h2", {
6295
+ className: "np-bottom-sheet-v2-title np-text-title-body",
6296
+ children: title
6297
+ }) : null, /*#__PURE__*/jsx("div", {
6298
+ className: "np-bottom-sheet-v2-body np-text-body-default",
6299
+ children: children
6300
+ })]
6301
+ })]
6302
+ }, floatingKey)
6303
+ })
6304
+ })
6305
+ })]
6306
+ })
6307
+ })]
6308
+ });
6309
+ }
6310
+
6311
+ const ButtonInput = /*#__PURE__*/forwardRef(function ButtonInput({
6312
+ size = 'md',
6313
+ className,
6314
+ style,
6315
+ ...restProps
6316
+ }, ref) {
6317
+ const inputPaddings = useInputPaddings();
6318
+ return /*#__PURE__*/jsx("button", {
6319
+ ref: ref,
6320
+ type: "button",
6321
+ className: classNames(className, formControlClassNameBase({
6322
+ size
6323
+ }), 'np-button-input')
6324
+ // eslint-disable-next-line react/forbid-dom-props
6325
+ ,
6326
+ style: {
6327
+ ...inputPaddings,
6328
+ ...style
6329
+ },
6330
+ ...restProps
6331
+ });
6332
+ });
6333
+
6334
+ const floatingPadding = 16;
6335
+ function Popover({
6336
+ placement,
6337
+ open,
6338
+ renderTrigger,
6339
+ title,
6340
+ padding = 'md',
6341
+ children,
6342
+ onClose
6343
+ }) {
6344
+ const {
6345
+ refs,
6346
+ floatingStyles,
6347
+ context
6348
+ } = useFloating({
6349
+ placement,
6350
+ middleware: [offset(8), flip({
6351
+ padding: floatingPadding,
6352
+ crossAxis: false
6353
+ }), shift(), size({
6354
+ padding: floatingPadding,
6355
+ apply: ({
6356
+ elements,
6357
+ rects,
6358
+ availableHeight
6359
+ }) => {
6360
+ elements.floating.style.setProperty('--max-height', `${availableHeight}px`);
6361
+ elements.floating.style.setProperty('--width', `${rects.reference.width}px`);
6362
+ }
6363
+ })],
6364
+ whileElementsMounted: autoUpdate,
6365
+ open,
6366
+ onOpenChange: value => {
6367
+ if (!value) {
6368
+ onClose?.();
6369
+ }
6370
+ }
6371
+ });
6372
+ const dismiss = useDismiss(context, {
6373
+ outsidePressEvent: 'mousedown'
6374
+ });
6375
+ const role = useRole(context);
6376
+ const {
6377
+ getReferenceProps,
6378
+ getFloatingProps
6379
+ } = useInteractions([role, dismiss]);
6380
+ const [floatingKey, setFloatingKey] = useState(0);
6381
+ return /*#__PURE__*/jsxs(Fragment, {
6382
+ children: [open ? /*#__PURE__*/jsx(PreventScroll, {}) : null, renderTrigger({
6383
+ ref: refs.setReference,
6384
+ getInteractionProps: getReferenceProps
6385
+ }), /*#__PURE__*/jsx(FloatingPortal, {
6386
+ children: /*#__PURE__*/jsx(FloatingFocusManager, {
6387
+ context: context,
6388
+ children: /*#__PURE__*/jsx(Transition, {
6389
+ show: open,
6390
+ leave: "transition-opacity",
6391
+ leaveTo: "opacity-0",
6392
+ beforeEnter: () => {
6393
+ setFloatingKey(prev => prev + 1);
6394
+ },
6395
+ children: /*#__PURE__*/jsx("div", {
6396
+ // Force inner state invalidation on open
6397
+ ref: refs.setFloating,
6398
+ className: "np-popover-v2-container"
6399
+ // eslint-disable-next-line react/forbid-dom-props
6400
+ ,
6401
+ style: floatingStyles,
6402
+ ...getFloatingProps(),
6403
+ children: /*#__PURE__*/jsxs("div", {
6404
+ className: classNames('np-popover-v2', title && 'np-popover-v2--has-title', {
6405
+ 'np-popover-v2--padding-md': padding === 'md'
6406
+ }),
6407
+ children: [title ? /*#__PURE__*/jsx("h2", {
6408
+ className: "np-popover-v2-title np-text-title-body",
6409
+ children: title
6410
+ }) : null, /*#__PURE__*/jsx("div", {
6411
+ className: "np-popover-v2-content np-text-body-default",
6412
+ children: children
6413
+ })]
6414
+ })
6415
+ }, floatingKey)
6416
+ })
6417
+ })
6418
+ })]
6419
+ });
6420
+ }
6421
+
6422
+ function searchableString(value) {
6423
+ return value.trim().replace(/\s+/gu, ' ').toLowerCase();
6424
+ }
6425
+ function inferSearchableStrings(value) {
6426
+ if (typeof value === 'string') {
6427
+ return [searchableString(value)];
6428
+ }
6429
+ if (typeof value === 'object' && value != null) {
6430
+ return Object.values(value).filter(innerValue => typeof innerValue === 'string').map(innerValue => searchableString(innerValue));
6431
+ }
6432
+ return [];
6433
+ }
6434
+ const SelectInputHasValueContext = /*#__PURE__*/createContext(false);
6435
+ const SelectInputOptionContentCompactContext = /*#__PURE__*/createContext(false);
6436
+ function dedupeSelectInputOptionItem(item, existingValues) {
6437
+ if (existingValues.has(item.value)) {
6438
+ return {
6439
+ ...item,
6440
+ value: undefined
6441
+ };
6442
+ }
6443
+ existingValues.add(item.value);
6444
+ return item;
6445
+ }
6446
+ function dedupeSelectInputItems(items) {
6447
+ const existingValues = new Set();
6448
+ return items.map(item => {
6449
+ switch (item.type) {
6450
+ case 'option':
6451
+ {
6452
+ return dedupeSelectInputOptionItem(item, existingValues);
6453
+ }
6454
+ case 'group':
6455
+ {
6456
+ return {
6457
+ ...item,
6458
+ options: item.options.map(option => dedupeSelectInputOptionItem(option, existingValues))
6459
+ };
6460
+ }
6461
+ }
6462
+ return item;
6463
+ });
6464
+ }
6465
+ function SelectInput({
6466
+ name,
6467
+ placeholder,
6468
+ items,
6469
+ defaultValue,
6470
+ value: controlledValue,
6471
+ renderValue = wrapInFragment,
6472
+ compareValues,
6473
+ filterable,
6474
+ filterPlaceholder,
6475
+ disabled,
6476
+ className,
6477
+ onChange,
6478
+ onClear
6479
+ }) {
6480
+ const intl = useIntl();
6481
+ const [open, setOpen] = useState(false);
6482
+ const triggerRef = useRef(null);
6483
+ const screenSm = useScreenSize(Breakpoint.SMALL);
6484
+ const OptionsOverlay = screenSm ? Popover : BottomSheet;
6485
+ const searchInputRef = useRef(null);
6486
+ const listboxRef = useRef(null);
6487
+ const controllerRef = filterable ? searchInputRef : listboxRef;
6488
+ return /*#__PURE__*/jsx(Listbox, {
6489
+ name: name,
6490
+ defaultValue: defaultValue,
6491
+ value: controlledValue
6492
+ // TODO: Remove assertion when upgrading TypeScript to v5
6493
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
6494
+ ,
6495
+ by: compareValues,
6496
+ disabled: disabled,
6497
+ onChange: value => {
6498
+ setOpen(false);
6499
+ onChange?.(value);
6500
+ },
6501
+ children: ({
6502
+ disabled: uiDisabled,
6503
+ value
6504
+ }) => /*#__PURE__*/jsx(SelectInputHasValueContext.Provider, {
6505
+ value: value != null,
6506
+ children: /*#__PURE__*/jsx(InputGroup, {
6507
+ addonEnd: {
6508
+ content: /*#__PURE__*/jsxs("span", {
6509
+ className: classNames('np-select-input-addon-container', uiDisabled && 'disabled'),
6510
+ children: [onClear != null && value != null ? /*#__PURE__*/jsxs(Fragment, {
6511
+ children: [/*#__PURE__*/jsx("button", {
6512
+ type: "button",
6513
+ "aria-label": intl.formatMessage(messages$4.ariaLabel),
6514
+ disabled: uiDisabled,
6515
+ className: "np-select-input-addon np-select-input-addon--interactive",
6516
+ onClick: event => {
6517
+ event.preventDefault();
6518
+ onClear();
6519
+ triggerRef.current?.focus({
6520
+ preventScroll: true
6521
+ });
6522
+ },
6523
+ children: /*#__PURE__*/jsx(Cross, {
6524
+ size: 16
6525
+ })
6526
+ }), /*#__PURE__*/jsx("span", {
6527
+ className: "np-select-input-addon-separator"
6528
+ })]
6529
+ }) : null, /*#__PURE__*/jsx("span", {
6530
+ className: "np-select-input-addon",
6531
+ children: /*#__PURE__*/jsx(ChevronDown, {
6532
+ size: 16
6533
+ })
6534
+ })]
6535
+ }),
6536
+ padding: 'sm'
6537
+ },
6538
+ className: className,
6539
+ children: /*#__PURE__*/jsx(OptionsOverlay, {
6540
+ open: open,
6541
+ renderTrigger: ({
6542
+ ref,
6543
+ getInteractionProps
6544
+ }) => /*#__PURE__*/jsx(Listbox.Button, {
6545
+ ref: mergeRefs([ref, triggerRef]),
6546
+ as: SelectInputButton,
6547
+ overrides: getInteractionProps(),
6548
+ onClick: () => {
6549
+ setOpen(prev => !prev);
6550
+ },
6551
+ children: value != null ? /*#__PURE__*/jsx(SelectInputOptionContentCompactContext.Provider, {
6552
+ value: true,
6553
+ children: renderValue(value, true)
6554
+ }) : /*#__PURE__*/jsx("span", {
6555
+ className: "np-select-input-placeholder",
6556
+ children: placeholder
6557
+ })
6558
+ }),
6559
+ initialFocusRef: controllerRef,
6560
+ padding: "none",
6561
+ onClose: () => {
6562
+ setOpen(false);
6563
+ },
6564
+ children: /*#__PURE__*/jsx(SelectInputOptions, {
6565
+ items: items,
6566
+ renderValue: renderValue,
6567
+ filterable: filterable,
6568
+ filterPlaceholder: filterPlaceholder,
6569
+ searchInputRef: searchInputRef,
6570
+ listboxRef: listboxRef
6571
+ })
6572
+ })
6573
+ })
6574
+ })
6575
+ });
6576
+ }
6577
+ const SelectInputButton = /*#__PURE__*/forwardRef(function SelectInputButton({
6578
+ overrides,
6579
+ ...restProps
6580
+ }, ref) {
6581
+ return /*#__PURE__*/jsx(ButtonInput, {
6582
+ ref: ref,
6583
+ ...restProps,
6584
+ ...overrides
6585
+ });
6586
+ });
6587
+ const SelectInputOptionsContainer = /*#__PURE__*/forwardRef(function SelectInputOptionsContainer({
6588
+ 'aria-orientation': ariaOrientation,
6589
+ 'aria-activedescendant': ariaActiveDescendant,
6590
+ role,
6591
+ tabIndex,
6592
+ onAriaActiveDescendantChange,
6593
+ ...restProps
6594
+ }, ref) {
6595
+ const handleAriaActiveDescendantChange = useEffectEvent(onAriaActiveDescendantChange);
6596
+ useEffect(() => {
6597
+ handleAriaActiveDescendantChange(ariaActiveDescendant);
6598
+ }, [ariaActiveDescendant, handleAriaActiveDescendantChange]);
6599
+ return /*#__PURE__*/jsx("div", {
6600
+ ref: ref,
6601
+ ...restProps
6602
+ });
6603
+ });
6604
+ function SelectInputOptions({
6605
+ items,
6606
+ renderValue = wrapInFragment,
6607
+ filterable,
6608
+ filterPlaceholder,
6609
+ searchInputRef,
6610
+ listboxRef
6611
+ }) {
6612
+ const [query, setQuery] = useState('');
6613
+ const needle = useMemo(() => query ? searchableString(query) : null, [query]);
6614
+ const listboxContainerRef = useRef(null);
6615
+ useEffect(() => {
6616
+ if (listboxContainerRef.current != null) {
6617
+ listboxContainerRef.current.style.setProperty('--initial-height', `${listboxContainerRef.current.offsetHeight}px`);
6618
+ }
6619
+ }, []);
6620
+ const listboxId = useId();
6621
+ const controllerRef = filterable ? searchInputRef : listboxRef;
6622
+ return /*#__PURE__*/jsxs(Listbox.Options, {
6623
+ as: SelectInputOptionsContainer,
6624
+ static: true,
6625
+ className: "np-select-input-options-container",
6626
+ onAriaActiveDescendantChange: value => {
6627
+ if (controllerRef.current != null) {
6628
+ if (value != null) {
6629
+ controllerRef.current.setAttribute('aria-activedescendant', value);
6630
+ } else {
6631
+ controllerRef.current.removeAttribute('aria-activedescendant');
6632
+ }
6633
+ }
6634
+ },
6635
+ children: [filterable ? /*#__PURE__*/jsx("div", {
6636
+ className: "np-select-input-query-container",
6637
+ children: /*#__PURE__*/jsx(SearchInput, {
6638
+ ref: searchInputRef,
6639
+ shape: "rectangle",
6640
+ placeholder: filterPlaceholder,
6641
+ value: query,
6642
+ "aria-controls": listboxId,
6643
+ onKeyDown: event => {
6644
+ // Prevent interfering with the matcher of Headless UI
6645
+ // https://mathiasbynens.be/notes/javascript-unicode#regex
6646
+ if (/^.$/u.test(event.key)) {
6647
+ event.stopPropagation();
6648
+ }
6649
+ },
6650
+ onChange: event => {
6651
+ setQuery(event.currentTarget.value);
6652
+ }
6653
+ })
6654
+ }) : null, /*#__PURE__*/jsx("div", {
6655
+ ref: listboxContainerRef,
6656
+ className: classNames('np-select-input-listbox-container', items.some(item => item.type === 'group') && 'np-select-input-listbox-container--has-group'),
6657
+ children: /*#__PURE__*/jsx("div", {
6658
+ ref: listboxRef,
6659
+ id: listboxId,
6660
+ role: "listbox",
6661
+ "aria-orientation": "vertical",
6662
+ tabIndex: 0,
6663
+ className: "np-select-input-listbox",
6664
+ children: (needle == null ? items : dedupeSelectInputItems(items)).map((item, index) => /*#__PURE__*/jsx(SelectInputItemView
6665
+ // eslint-disable-next-line react/no-array-index-key
6666
+ , {
6667
+ item: item,
6668
+ renderValue: renderValue,
6669
+ needle: needle
6670
+ }, index))
6671
+ })
6672
+ })]
6673
+ });
6674
+ }
6675
+ function SelectInputItemView({
6676
+ item,
6677
+ renderValue,
6678
+ needle
6679
+ }) {
6680
+ switch (item.type) {
6681
+ case 'option':
6682
+ {
6683
+ if (item.value != null && (!needle || inferSearchableStrings(item.filterMatchers ?? item.value).some(haystack => haystack.includes(needle)))) {
6684
+ return /*#__PURE__*/jsx(SelectInputOption, {
6685
+ value: item.value,
6686
+ disabled: item.disabled,
6687
+ children: renderValue(item.value, false)
6688
+ });
6689
+ }
6690
+ break;
6691
+ }
6692
+ case 'group':
6693
+ {
6694
+ return /*#__PURE__*/jsx(SelectInputGroupItemView, {
6695
+ item: item,
6696
+ renderValue: renderValue,
6697
+ needle: needle
6698
+ });
6699
+ }
6700
+ case 'separator':
6701
+ {
6702
+ if (needle == null) {
6703
+ return /*#__PURE__*/jsx("hr", {
6704
+ className: "np-select-input-separator-item",
6705
+ "aria-hidden": true
6706
+ });
6707
+ }
6708
+ break;
6709
+ }
6710
+ }
6711
+ return null;
6712
+ }
6713
+ function SelectInputGroupItemView({
6714
+ item,
6715
+ renderValue,
6716
+ needle
6717
+ }) {
6718
+ const headerId = useId();
6719
+ return (
6720
+ /*#__PURE__*/
6721
+ // An empty container may be rendered when no options match `needle`
6722
+ // However, pre-filtering would result in worse performance overall
6723
+ jsxs("section", {
6724
+ role: "group",
6725
+ "aria-labelledby": headerId,
6726
+ className: classNames(needle == null && 'np-select-input-group-item--without-needle'),
6727
+ children: [needle == null ? /*#__PURE__*/jsx("header", {
6728
+ id: headerId,
6729
+ role: "presentation",
6730
+ className: "np-select-input-group-item-header np-text-title-group",
6731
+ children: item.label
6732
+ }) : null, item.options.map((option, index) => /*#__PURE__*/jsx(SelectInputItemView
6733
+ // eslint-disable-next-line react/no-array-index-key
6734
+ , {
6735
+ item: option,
6736
+ renderValue: renderValue,
6737
+ needle: needle
6738
+ }, index))]
6739
+ })
6740
+ );
6741
+ }
6742
+ function SelectInputOption({
6743
+ value,
6744
+ disabled,
6745
+ children
6746
+ }) {
6747
+ const parentHasValue = useContext(SelectInputHasValueContext);
6748
+ // Avoid flash during exit transition
6749
+ const {
6750
+ current: cachedParentHasValue
6751
+ } = useRef(parentHasValue);
6752
+ return /*#__PURE__*/jsx(Listbox.Option, {
6753
+ as: "div",
6754
+ value: value,
6755
+ disabled: disabled,
6756
+ className: ({
6757
+ active,
6758
+ disabled: uiDisabled
6759
+ }) => classNames('np-select-input-option-container np-text-body-large', active && 'np-select-input-option-container--active', uiDisabled && 'np-select-input-option-container--disabled'),
6760
+ children: ({
6761
+ selected
6762
+ }) => /*#__PURE__*/jsxs(Fragment, {
6763
+ children: [cachedParentHasValue ? /*#__PURE__*/jsx(Check, {
6764
+ size: 16,
6765
+ className: classNames(!selected && 'np-select-input-option-check--not-selected')
6766
+ }) : null, /*#__PURE__*/jsx("div", {
6767
+ className: "np-select-input-option",
6768
+ children: children
6769
+ })]
6770
+ })
6771
+ });
6772
+ }
6773
+ function SelectInputOptionContent({
6774
+ title,
6775
+ note,
6776
+ description,
6777
+ icon
6778
+ }) {
6779
+ const compact = useContext(SelectInputOptionContentCompactContext);
6780
+ return /*#__PURE__*/jsxs("div", {
6781
+ className: "np-select-input-option-content-container np-text-body-large",
6782
+ children: [icon ? /*#__PURE__*/jsx("div", {
6783
+ className: classNames('np-select-input-option-content-icon', !compact && 'np-select-input-option-content-icon--not-compact'),
6784
+ children: icon
6785
+ }) : null, /*#__PURE__*/jsxs("div", {
6786
+ className: "np-select-input-option-content-text",
6787
+ children: [/*#__PURE__*/jsxs("div", {
6788
+ className: classNames('np-select-input-option-content-text-line-1', compact && 'np-select-input-option-content-text-compact'),
6789
+ children: [/*#__PURE__*/jsx("h4", {
6790
+ className: "d-inline np-text-body-large",
6791
+ children: title
6792
+ }), note ? /*#__PURE__*/jsx("span", {
6793
+ className: "np-select-input-option-content-text-secondary np-text-body-default",
6794
+ children: note
6795
+ }) : null]
6796
+ }), description ? /*#__PURE__*/jsx("div", {
6797
+ className: classNames('np-select-input-option-content-text-secondary np-text-body-default', compact && 'np-select-input-option-content-text-compact'),
6798
+ children: description
6799
+ }) : null]
6800
+ })]
6801
+ });
6802
+ }
6803
+
6159
6804
  const TextArea = /*#__PURE__*/forwardRef(function TextArea({
6160
6805
  className,
6161
6806
  ...restProps
@@ -7271,7 +7916,7 @@ function Select({
7271
7916
  headerTitle: searchPlaceholder || formatMessage(messages$3.searchPlaceholder),
7272
7917
  onClose: handleCloseOptions,
7273
7918
  children: renderOptionsList()
7274
- }) : /*#__PURE__*/jsx(BottomSheet$1, {
7919
+ }) : /*#__PURE__*/jsx(BottomSheet$2, {
7275
7920
  open: open,
7276
7921
  onClose: handleCloseOptions,
7277
7922
  children: renderOptionsList({
@@ -14385,5 +15030,5 @@ const translations = {
14385
15030
  zh
14386
15031
  };
14387
15032
 
14388
- export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$1 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron$1 as Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat$1 as InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput$1 as PhoneNumberInput, Popover$1 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, Section, Select, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat$1 as TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useSnackbar };
15033
+ export { Accordion, ActionButton, ActionOption, Alert$1 as Alert, ArrowPosition as AlertArrowPosition, Avatar, AvatarType, AvatarWrapper, Badge, Card as BaseCard, Body, BottomSheet$2 as BottomSheet, Breakpoint, Button, Card$2 as Card, Checkbox$1 as Checkbox, CheckboxButton$1 as CheckboxButton, CheckboxOption, Chevron$1 as Chevron, Chip, Chips, CircularButton$1 as CircularButton, ControlType, CriticalCommsBanner, DEFAULT_LANG, DEFAULT_LOCALE, DateInput$1 as DateInput, DateLookup$1 as DateLookup, DateMode, Decision$1 as Decision, Presentation as DecisionPresentation, Type as DecisionType, DefinitionList$1 as DefinitionList, Dimmer$1 as Dimmer, Direction, DirectionProvider, Display, Drawer$1 as Drawer, DropFade, DynamicFieldDefinitionList$1 as DynamicFieldDefinitionList, Emphasis, FileType, FlowNavigation, Header, Image, Info, InfoPresentation, InlineAlert, Input, InputGroup, InputWithDisplayFormat$1 as InputWithDisplayFormat, InstructionsList$1 as InstructionsList, LanguageProvider, Layout$1 as Layout, Link, ListItem$1 as ListItem, Loader$1 as Loader, Logo$1 as Logo, LogoType, Markdown$1 as Markdown, MarkdownNodeType, Modal, Money$1 as Money, MoneyInput$1 as MoneyInput, MonthFormat, NavigationOption, NavigationOptionList$1 as NavigationOptionsList, Nudge, Option$2 as Option, OverlayHeader$1 as OverlayHeader, PhoneNumberInput$1 as PhoneNumberInput, Popover$2 as Popover, Position, Priority, ProcessIndicator$1 as ProcessIndicator, ProfileType, Progress, ProgressBar, PromoCard$1 as PromoCard, PromoCard$1 as PromoCardGroup, Provider$1 as Provider, RTL_LANGUAGES, Radio$1 as Radio, RadioGroup$1 as RadioGroup, RadioOption$1 as RadioOption, SUPPORTED_LANGUAGES, Scroll, SearchInput, Section, Select, SelectInput, SelectInputOptionContent, Sentiment, Size, SlidingPanel$1 as SlidingPanel, SnackbarConsumer, SnackbarContext, SnackbarPortal, SnackbarProvider$1 as SnackbarProvider, Status, StatusIcon, Stepper, Sticky$1 as Sticky, Summary, Switch, SwitchOption, Tabs$1 as Tabs, TextArea, TextareaWithDisplayFormat$1 as TextareaWithDisplayFormat, Theme, Title, Tooltip$1 as Tooltip, Type$1 as Type, Typeahead, Typography, Upload$1 as Upload, UploadInput, UploadStep, Variant, Width, adjustLocale, getCountryFromLocale, getDirectionFromLocale, getLangFromLocale, isBrowser, isServerSide, translations, useDirection, useLayout, useSnackbar };
14389
15034
  //# sourceMappingURL=index.esm.js.map