@transferwise/components 0.0.0-experimental-8e32d17 → 0.0.0-experimental-3f120da

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 (49) hide show
  1. package/build/index.js +53 -157
  2. package/build/index.js.map +1 -1
  3. package/build/index.mjs +55 -157
  4. package/build/index.mjs.map +1 -1
  5. package/build/types/dateInput/DateInput.d.ts +2 -3
  6. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  7. package/build/types/index.d.ts +0 -4
  8. package/build/types/index.d.ts.map +1 -1
  9. package/build/types/inputs/Input.d.ts.map +1 -1
  10. package/build/types/inputs/SelectInput.d.ts +1 -1
  11. package/build/types/inputs/SelectInput.d.ts.map +1 -1
  12. package/build/types/inputs/TextArea.d.ts.map +1 -1
  13. package/build/types/inputs/_common.d.ts +2 -2
  14. package/build/types/inputs/_common.d.ts.map +1 -1
  15. package/build/types/radioGroup/RadioGroup.d.ts.map +1 -1
  16. package/build/types/switch/Switch.d.ts +3 -6
  17. package/build/types/switch/Switch.d.ts.map +1 -1
  18. package/package.json +1 -1
  19. package/src/dateInput/DateInput.tsx +18 -24
  20. package/src/flowNavigation/FlowNavigation.spec.js +10 -0
  21. package/src/flowNavigation/FlowNavigation.story.js +16 -0
  22. package/src/flowNavigation/FlowNavigation.tsx +1 -1
  23. package/src/index.ts +0 -4
  24. package/src/inputs/Input.tsx +3 -5
  25. package/src/inputs/SelectInput.spec.tsx +0 -10
  26. package/src/inputs/SelectInput.tsx +4 -9
  27. package/src/inputs/TextArea.tsx +3 -6
  28. package/src/inputs/_ButtonInput.tsx +2 -2
  29. package/src/inputs/_common.ts +2 -2
  30. package/src/overlayHeader/OverlayHeader.story.js +1 -1
  31. package/src/radioGroup/RadioGroup.rtl.spec.tsx +0 -14
  32. package/src/radioGroup/RadioGroup.story.tsx +0 -26
  33. package/src/radioGroup/RadioGroup.tsx +1 -4
  34. package/src/switch/Switch.spec.tsx +0 -10
  35. package/src/switch/Switch.tsx +13 -22
  36. package/build/types/field/Field.d.ts +0 -12
  37. package/build/types/field/Field.d.ts.map +0 -1
  38. package/build/types/inputs/contexts.d.ts +0 -17
  39. package/build/types/inputs/contexts.d.ts.map +0 -1
  40. package/build/types/label/Label.d.ts +0 -9
  41. package/build/types/label/Label.d.ts.map +0 -1
  42. package/src/dateInput/DateInput.rtl.spec.tsx +0 -17
  43. package/src/field/Field.spec.tsx +0 -95
  44. package/src/field/Field.story.tsx +0 -59
  45. package/src/field/Field.tsx +0 -70
  46. package/src/inputs/contexts.ts +0 -28
  47. package/src/label/Label.spec.tsx +0 -26
  48. package/src/label/Label.story.tsx +0 -37
  49. package/src/label/Label.tsx +0 -20
package/build/index.js CHANGED
@@ -2622,26 +2622,6 @@ const isMonthAndYearFormat = dateString => validDateString(dateString) && dateSt
2622
2622
  const MDY = new Set(['en-US']);
2623
2623
  const YMD = new Set(['hu', 'hu-HU', 'zh-HK', 'zh-CN', 'ja', 'ja-JP']);
2624
2624
 
2625
- const FieldLabelIdContext = /*#__PURE__*/React.createContext(undefined);
2626
- const FieldLabelIdContextProvider = FieldLabelIdContext.Provider;
2627
- const InputIdContext = /*#__PURE__*/React.createContext(undefined);
2628
- const InputIdContextProvider = InputIdContext.Provider;
2629
- const InputDescribedByContext = /*#__PURE__*/React.createContext(undefined);
2630
- const InputDescribedByProvider = InputDescribedByContext.Provider;
2631
- const InputInvalidContext = /*#__PURE__*/React.createContext(undefined);
2632
- const InputInvalidProvider = InputInvalidContext.Provider;
2633
- function useInputAttributes({
2634
- nonLabelable = false
2635
- } = {}) {
2636
- const labelId = React.useContext(FieldLabelIdContext);
2637
- return {
2638
- id: React.useContext(InputIdContext),
2639
- 'aria-labelledby': nonLabelable ? labelId : undefined,
2640
- 'aria-describedby': React.useContext(InputDescribedByContext),
2641
- 'aria-invalid': React.useContext(InputInvalidContext)
2642
- };
2643
- }
2644
-
2645
2625
  var messages$9 = reactIntl.defineMessages({
2646
2626
  monthLabel: {
2647
2627
  id: "neptune.DateInput.month.label"
@@ -2666,7 +2646,7 @@ const convertToLocalMidnight = date => {
2666
2646
  };
2667
2647
 
2668
2648
  const DateInput = ({
2669
- 'aria-labelledby': ariaLabelledByProp,
2649
+ 'aria-labelledby': ariaLabelledBy,
2670
2650
  'aria-label': ariaLabel,
2671
2651
  disabled = false,
2672
2652
  size = exports.Size.MEDIUM,
@@ -2682,14 +2662,9 @@ const DateInput = ({
2682
2662
  onFocus,
2683
2663
  onBlur,
2684
2664
  placeholders,
2685
- id: idProp,
2665
+ id,
2686
2666
  selectProps = {}
2687
2667
  }) => {
2688
- const inputAttributes = useInputAttributes({
2689
- nonLabelable: true
2690
- });
2691
- const id = idProp ?? inputAttributes.id;
2692
- const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes['aria-labelledby'];
2693
2668
  const {
2694
2669
  locale,
2695
2670
  formatMessage
@@ -2726,9 +2701,9 @@ const DateInput = ({
2726
2701
  const [year, setYear] = React.useState(() => getInitialDate('year'));
2727
2702
  const [lastBroadcastedValue, setLastBroadcastedValue] = React.useState(getDateObject);
2728
2703
  const monthNames = getMonthNames(locale, monthFormat);
2729
- dayLabel ||= formatMessage(messages$9.dayLabel);
2730
- monthLabel ||= formatMessage(messages$9.monthLabel);
2731
- yearLabel ||= formatMessage(messages$9.yearLabel);
2704
+ dayLabel = dayLabel || formatMessage(messages$9.dayLabel);
2705
+ monthLabel = monthLabel || formatMessage(messages$9.monthLabel);
2706
+ yearLabel = yearLabel || formatMessage(messages$9.yearLabel);
2732
2707
  placeholders = {
2733
2708
  day: placeholders?.day || formatMessage(messages$9.dayPlaceholder),
2734
2709
  month: placeholders?.month || formatMessage(messages$9.monthLabel),
@@ -2919,7 +2894,6 @@ const DateInput = ({
2919
2894
  const yearFirst = YMD.has(locale);
2920
2895
  return /*#__PURE__*/jsxRuntime.jsx("div", {
2921
2896
  className: "tw-date",
2922
- ...inputAttributes,
2923
2897
  id: id,
2924
2898
  "aria-labelledby": ariaLabelledBy,
2925
2899
  "aria-label": ariaLabel,
@@ -2939,15 +2913,15 @@ const DateInput = ({
2939
2913
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2940
2914
  children: [getMonth(), getDay(), getYear()]
2941
2915
  });
2942
- }
2943
- if (yearFirst) {
2916
+ } else if (yearFirst) {
2944
2917
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2945
2918
  children: [getYear(), getMonth(), getDay()]
2946
2919
  });
2920
+ } else {
2921
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2922
+ children: [getDay(), getMonth(), getYear()]
2923
+ });
2947
2924
  }
2948
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2949
- children: [getDay(), getMonth(), getYear()]
2950
- });
2951
2925
  })()
2952
2926
  })
2953
2927
  });
@@ -4907,7 +4881,7 @@ const FlowNavigation = ({
4907
4881
  }) : /*#__PURE__*/jsxRuntime.jsx("div", {
4908
4882
  className: "np-flow-header__left",
4909
4883
  children: logo
4910
- }), !screenSm && /*#__PURE__*/jsxRuntime.jsx(AnimatedLabel, {
4884
+ }), !screenSm && !done && /*#__PURE__*/jsxRuntime.jsx(AnimatedLabel, {
4911
4885
  className: "m-x-1",
4912
4886
  labels: steps.map(step => step.label),
4913
4887
  activeLabel: activeStep
@@ -4929,84 +4903,6 @@ const FlowNavigation = ({
4929
4903
  });
4930
4904
  };
4931
4905
 
4932
- function InlineAlert({
4933
- id,
4934
- type = 'neutral',
4935
- className,
4936
- children
4937
- }) {
4938
- const danger = type === 'negative' || type === 'error';
4939
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
4940
- role: "alert",
4941
- id: id,
4942
- className: classNames__default.default('alert alert-detach', `alert-${danger ? 'danger' : type}`, className),
4943
- children: [danger && /*#__PURE__*/jsxRuntime.jsx(icons.AlertCircle, {}), /*#__PURE__*/jsxRuntime.jsx("div", {
4944
- children: children
4945
- })]
4946
- });
4947
- }
4948
-
4949
- const Label = ({
4950
- id,
4951
- htmlFor,
4952
- className,
4953
- children
4954
- }) => {
4955
- return /*#__PURE__*/jsxRuntime.jsx("label", {
4956
- id: id,
4957
- htmlFor: htmlFor,
4958
- className: classNames__default.default('control-label d-flex flex-column gap-y-1 m-b-0', className),
4959
- children: children
4960
- });
4961
- };
4962
-
4963
- const Field = ({
4964
- id,
4965
- label,
4966
- hint,
4967
- error,
4968
- className,
4969
- children
4970
- }) => {
4971
- const hasError = Boolean(error);
4972
- const hasHint = Boolean(hint) && !hasError;
4973
- const labelId = reactId.useId();
4974
- const fallbackInputId = reactId.useId(); // TODO: Use `React.useId()` when react>=18
4975
- const inputId = id !== null ? id ?? fallbackInputId : undefined;
4976
- const descriptionId = reactId.useId(); // TODO: Use `React.useId()` when react>=18
4977
- return /*#__PURE__*/jsxRuntime.jsx(FieldLabelIdContextProvider, {
4978
- value: labelId,
4979
- children: /*#__PURE__*/jsxRuntime.jsx(InputIdContextProvider, {
4980
- value: inputId,
4981
- children: /*#__PURE__*/jsxRuntime.jsx(InputDescribedByProvider, {
4982
- value: hasError || hasHint ? descriptionId : undefined,
4983
- children: /*#__PURE__*/jsxRuntime.jsx(InputInvalidProvider, {
4984
- value: hasError,
4985
- children: /*#__PURE__*/jsxRuntime.jsxs("div", {
4986
- className: classNames__default.default('form-group d-block', {
4987
- 'has-error': hasError,
4988
- 'has-info': hasHint
4989
- }, className),
4990
- children: [/*#__PURE__*/jsxRuntime.jsxs(Label, {
4991
- id: labelId,
4992
- htmlFor: inputId,
4993
- children: [label, children]
4994
- }), hasHint && /*#__PURE__*/jsxRuntime.jsx(InlineAlert, {
4995
- type: exports.Sentiment.NEUTRAL,
4996
- id: descriptionId,
4997
- children: hint
4998
- }), hasError && /*#__PURE__*/jsxRuntime.jsx(InlineAlert, {
4999
- type: exports.Sentiment.NEGATIVE,
5000
- id: descriptionId,
5001
- children: error
5002
- })]
5003
- })
5004
- })
5005
- })
5006
- })
5007
- });
5008
- };
5009
-
5010
4906
  const HeaderAction = ({
5011
4907
  action
5012
4908
  }) => {
@@ -5339,16 +5235,20 @@ const Info = ({
5339
5235
  });
5340
5236
  };
5341
5237
 
5342
- function inputClassNameBase({
5343
- size = 'auto'
5344
- } = {}) {
5345
- return classNames__default.default('form-control',
5346
- // TODO: Deprecate
5347
- 'np-form-control', {
5348
- 'np-form-control--size-auto': size === 'auto',
5349
- 'np-form-control--size-sm': size === 'sm',
5350
- 'np-form-control--size-md': size === 'md',
5351
- 'np-form-control--size-lg': size === 'lg'
5238
+ function InlineAlert({
5239
+ id,
5240
+ type = 'neutral',
5241
+ className,
5242
+ children
5243
+ }) {
5244
+ const danger = type === 'negative' || type === 'error';
5245
+ return /*#__PURE__*/jsxRuntime.jsxs("div", {
5246
+ role: "alert",
5247
+ id: id,
5248
+ className: classNames__default.default('alert alert-detach', `alert-${danger ? 'danger' : type}`, className),
5249
+ children: [danger && /*#__PURE__*/jsxRuntime.jsx(icons.AlertCircle, {}), /*#__PURE__*/jsxRuntime.jsx("div", {
5250
+ children: children
5251
+ })]
5352
5252
  });
5353
5253
  }
5354
5254
 
@@ -5470,17 +5370,29 @@ function InputAddon({
5470
5370
  });
5471
5371
  }
5472
5372
 
5373
+ function formControlClassNameBase({
5374
+ size = 'auto'
5375
+ } = {}) {
5376
+ return classNames__default.default('form-control',
5377
+ // TODO: Deprecate
5378
+ 'np-form-control', {
5379
+ 'np-form-control--size-auto': size === 'auto',
5380
+ 'np-form-control--size-sm': size === 'sm',
5381
+ 'np-form-control--size-md': size === 'md',
5382
+ 'np-form-control--size-lg': size === 'lg'
5383
+ });
5384
+ }
5385
+
5473
5386
  const Input = /*#__PURE__*/React.forwardRef(function Input({
5474
5387
  size = 'auto',
5475
5388
  shape = 'rectangle',
5476
5389
  className,
5477
5390
  ...restProps
5478
5391
  }, reference) {
5479
- const inputAttributes = useInputAttributes();
5480
5392
  const inputPaddings = useInputPaddings();
5481
5393
  return /*#__PURE__*/jsxRuntime.jsx("input", {
5482
5394
  ref: reference,
5483
- className: classNames__default.default(className, inputClassNameBase({
5395
+ className: classNames__default.default(className, formControlClassNameBase({
5484
5396
  size
5485
5397
  }), 'np-input', {
5486
5398
  'np-input--shape-rectangle': shape === 'rectangle',
@@ -5489,7 +5401,6 @@ const Input = /*#__PURE__*/React.forwardRef(function Input({
5489
5401
  // eslint-disable-next-line react/forbid-dom-props
5490
5402
  ,
5491
5403
  style: inputPaddings,
5492
- ...inputAttributes,
5493
5404
  ...restProps
5494
5405
  });
5495
5406
  });
@@ -5911,6 +5822,12 @@ const PolymorphicWithOverrides = /*#__PURE__*/React.forwardRef(function Polymorp
5911
5822
  });
5912
5823
  });
5913
5824
 
5825
+ var messages$5 = reactIntl.defineMessages({
5826
+ noResultsFound: {
5827
+ id: "neptune.SelectInput.noResultsFound"
5828
+ }
5829
+ });
5830
+
5914
5831
  function PreventScroll() {
5915
5832
  overlays.usePreventScroll();
5916
5833
  return null;
@@ -6030,7 +5947,7 @@ const ButtonInput = /*#__PURE__*/React.forwardRef(function ButtonInput({
6030
5947
  return /*#__PURE__*/jsxRuntime.jsx("button", {
6031
5948
  ref: ref,
6032
5949
  type: "button",
6033
- className: classNames__default.default(className, inputClassNameBase({
5950
+ className: classNames__default.default(className, formControlClassNameBase({
6034
5951
  size
6035
5952
  }), 'np-button-input')
6036
5953
  // eslint-disable-next-line react/forbid-dom-props
@@ -6146,12 +6063,6 @@ function Popover({
6146
6063
  });
6147
6064
  }
6148
6065
 
6149
- var messages$5 = reactIntl.defineMessages({
6150
- noResultsFound: {
6151
- id: "neptune.SelectInput.noResultsFound"
6152
- }
6153
- });
6154
-
6155
6066
  function searchableString(value) {
6156
6067
  return value.trim().replace(/\s+/gu, ' ').normalize('NFKC').toLowerCase();
6157
6068
  }
@@ -6271,7 +6182,7 @@ function SelectInputClearButton({
6271
6182
  }
6272
6183
  const noop = () => {};
6273
6184
  function SelectInput({
6274
- id: idProp,
6185
+ id,
6275
6186
  name,
6276
6187
  multiple,
6277
6188
  placeholder,
@@ -6292,8 +6203,6 @@ function SelectInput({
6292
6203
  onClose,
6293
6204
  onClear
6294
6205
  }) {
6295
- const inputAttributes = useInputAttributes();
6296
- const id = idProp ?? inputAttributes.id;
6297
6206
  const [open, setOpen] = React.useState(false);
6298
6207
  const initialized = React.useRef(false);
6299
6208
  const handleClose = useEffectEvent(onClose ?? (() => {}));
@@ -6354,7 +6263,6 @@ function SelectInput({
6354
6263
  ref(node);
6355
6264
  triggerRef.current = node;
6356
6265
  },
6357
- ...inputAttributes,
6358
6266
  id,
6359
6267
  ...mergeProps__default.default({
6360
6268
  onClick: () => {
@@ -6708,11 +6616,9 @@ const TextArea = /*#__PURE__*/React.forwardRef(function TextArea({
6708
6616
  className,
6709
6617
  ...restProps
6710
6618
  }, reference) {
6711
- const inputAttributes = useInputAttributes();
6712
6619
  return /*#__PURE__*/jsxRuntime.jsx("textarea", {
6713
6620
  ref: reference,
6714
- className: classNames__default.default(className, inputClassNameBase(), 'np-text-area'),
6715
- ...inputAttributes,
6621
+ className: classNames__default.default(className, formControlClassNameBase(), 'np-text-area'),
6716
6622
  ...restProps
6717
6623
  });
6718
6624
  });
@@ -9458,13 +9364,9 @@ function RadioGroup({
9458
9364
  selectedValue: controlledValue,
9459
9365
  onChange
9460
9366
  }) {
9461
- const inputAttributes = useInputAttributes({
9462
- nonLabelable: true
9463
- });
9464
9367
  const [uncontrolledValue, setUncontrolledValue] = React.useState(controlledValue);
9465
9368
  return radios.length > 0 ? /*#__PURE__*/jsxRuntime.jsx("div", {
9466
9369
  role: "radiogroup",
9467
- ...inputAttributes,
9468
9370
  children: radios.map(({
9469
9371
  value = '',
9470
9372
  ...restProps
@@ -10576,18 +10478,13 @@ const Summary = ({
10576
10478
  };
10577
10479
 
10578
10480
  const Switch = props => {
10579
- const inputAttributes = useInputAttributes({
10580
- nonLabelable: true
10581
- });
10582
10481
  const {
10583
10482
  isModern
10584
10483
  } = componentsTheming.useTheme();
10585
10484
  const {
10586
10485
  checked,
10587
10486
  className,
10588
- id = inputAttributes.id,
10589
- 'aria-label': ariaLabel,
10590
- 'aria-labelledby': ariaLabelledbyProp,
10487
+ id,
10591
10488
  onClick,
10592
10489
  disabled
10593
10490
  } = props;
@@ -10618,18 +10515,19 @@ const Switch = props => {
10618
10515
  })
10619
10516
  });
10620
10517
  };
10621
- const ariaLabelledby = (ariaLabel ? undefined : ariaLabelledbyProp) ?? inputAttributes['aria-labelledby'];
10518
+ const ariaLabel = props['aria-label'];
10519
+ const ariaLabelledby = ariaLabel ? undefined : props['aria-labelledby'];
10520
+ logActionRequiredIf('Switch now expects either `aria-label` or `aria-labelledby`, and will soon make these props required. Please update your usage to provide one or the other.', !ariaLabel && !ariaLabelledby);
10622
10521
  return /*#__PURE__*/jsxRuntime.jsxs("span", {
10623
10522
  className: classNames__default.default('np-switch', {
10624
10523
  'np-switch--unchecked': !checked,
10625
10524
  'np-switch--checked': checked,
10626
- disabled
10525
+ disabled: disabled
10627
10526
  }, className),
10628
10527
  tabIndex: 0,
10629
10528
  role: "switch",
10630
10529
  "aria-checked": checked,
10631
10530
  "aria-label": ariaLabel,
10632
- ...inputAttributes,
10633
10531
  "aria-labelledby": ariaLabelledby,
10634
10532
  id: id,
10635
10533
  "aria-disabled": disabled,
@@ -14517,7 +14415,6 @@ exports.Display = Display;
14517
14415
  exports.Drawer = Drawer$1;
14518
14416
  exports.DropFade = DropFade;
14519
14417
  exports.Emphasis = Emphasis;
14520
- exports.Field = Field;
14521
14418
  exports.FlowNavigation = FlowNavigation;
14522
14419
  exports.Header = Header;
14523
14420
  exports.Image = Image;
@@ -14527,7 +14424,6 @@ exports.Input = Input;
14527
14424
  exports.InputGroup = InputGroup;
14528
14425
  exports.InputWithDisplayFormat = InputWithDisplayFormat;
14529
14426
  exports.InstructionsList = InstructionsList;
14530
- exports.Label = Label;
14531
14427
  exports.LanguageProvider = LanguageProvider;
14532
14428
  exports.Link = Link;
14533
14429
  exports.ListItem = ListItem$1;