@transferwise/components 0.0.0-experimental-11854c7 → 0.0.0-experimental-bf4cb26

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.
package/build/index.js CHANGED
@@ -2622,6 +2622,26 @@ 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
+
2625
2645
  var messages$9 = reactIntl.defineMessages({
2626
2646
  monthLabel: {
2627
2647
  id: "neptune.DateInput.month.label"
@@ -2646,7 +2666,7 @@ const convertToLocalMidnight = date => {
2646
2666
  };
2647
2667
 
2648
2668
  const DateInput = ({
2649
- 'aria-labelledby': ariaLabelledBy,
2669
+ 'aria-labelledby': ariaLabelledByProp,
2650
2670
  'aria-label': ariaLabel,
2651
2671
  disabled = false,
2652
2672
  size = exports.Size.MEDIUM,
@@ -2662,9 +2682,14 @@ const DateInput = ({
2662
2682
  onFocus,
2663
2683
  onBlur,
2664
2684
  placeholders,
2665
- id,
2685
+ id: idProp,
2666
2686
  selectProps = {}
2667
2687
  }) => {
2688
+ const inputAttributes = useInputAttributes({
2689
+ nonLabelable: true
2690
+ });
2691
+ const id = idProp ?? inputAttributes.id;
2692
+ const ariaLabelledBy = ariaLabelledByProp ?? inputAttributes['aria-labelledby'];
2668
2693
  const {
2669
2694
  locale,
2670
2695
  formatMessage
@@ -2701,9 +2726,9 @@ const DateInput = ({
2701
2726
  const [year, setYear] = React.useState(() => getInitialDate('year'));
2702
2727
  const [lastBroadcastedValue, setLastBroadcastedValue] = React.useState(getDateObject);
2703
2728
  const monthNames = getMonthNames(locale, monthFormat);
2704
- dayLabel = dayLabel || formatMessage(messages$9.dayLabel);
2705
- monthLabel = monthLabel || formatMessage(messages$9.monthLabel);
2706
- yearLabel = yearLabel || formatMessage(messages$9.yearLabel);
2729
+ dayLabel ||= formatMessage(messages$9.dayLabel);
2730
+ monthLabel ||= formatMessage(messages$9.monthLabel);
2731
+ yearLabel ||= formatMessage(messages$9.yearLabel);
2707
2732
  placeholders = {
2708
2733
  day: placeholders?.day || formatMessage(messages$9.dayPlaceholder),
2709
2734
  month: placeholders?.month || formatMessage(messages$9.monthLabel),
@@ -2894,6 +2919,7 @@ const DateInput = ({
2894
2919
  const yearFirst = YMD.has(locale);
2895
2920
  return /*#__PURE__*/jsxRuntime.jsx("div", {
2896
2921
  className: "tw-date",
2922
+ ...inputAttributes,
2897
2923
  id: id,
2898
2924
  "aria-labelledby": ariaLabelledBy,
2899
2925
  "aria-label": ariaLabel,
@@ -2913,15 +2939,15 @@ const DateInput = ({
2913
2939
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2914
2940
  children: [getMonth(), getDay(), getYear()]
2915
2941
  });
2916
- } else if (yearFirst) {
2942
+ }
2943
+ if (yearFirst) {
2917
2944
  return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2918
2945
  children: [getYear(), getMonth(), getDay()]
2919
2946
  });
2920
- } else {
2921
- return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2922
- children: [getDay(), getMonth(), getYear()]
2923
- });
2924
2947
  }
2948
+ return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
2949
+ children: [getDay(), getMonth(), getYear()]
2950
+ });
2925
2951
  })()
2926
2952
  })
2927
2953
  });
@@ -4920,26 +4946,6 @@ function InlineAlert({
4920
4946
  });
4921
4947
  }
4922
4948
 
4923
- const FieldLabelIdContext = /*#__PURE__*/React.createContext(undefined);
4924
- const FieldLabelIdContextProvider = FieldLabelIdContext.Provider;
4925
- const InputIdContext = /*#__PURE__*/React.createContext(undefined);
4926
- const InputIdContextProvider = InputIdContext.Provider;
4927
- const InputDescribedByContext = /*#__PURE__*/React.createContext(undefined);
4928
- const InputDescribedByProvider = InputDescribedByContext.Provider;
4929
- const InputInvalidContext = /*#__PURE__*/React.createContext(undefined);
4930
- const InputInvalidProvider = InputInvalidContext.Provider;
4931
- function useInputAttributes({
4932
- nonLabelable = false
4933
- } = {}) {
4934
- const labelId = React.useContext(FieldLabelIdContext);
4935
- return {
4936
- id: React.useContext(InputIdContext),
4937
- 'aria-labelledby': nonLabelable ? labelId : undefined,
4938
- 'aria-describedby': React.useContext(InputDescribedByContext),
4939
- 'aria-invalid': React.useContext(InputInvalidContext)
4940
- };
4941
- }
4942
-
4943
4949
  const Label = ({
4944
4950
  id,
4945
4951
  htmlFor,