@transferwise/components 46.13.0 → 46.14.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 (126) hide show
  1. package/build/index.esm.js +175 -346
  2. package/build/index.esm.js.map +1 -1
  3. package/build/index.js +148 -319
  4. package/build/index.js.map +1 -1
  5. package/build/main.css +6 -82
  6. package/build/styles/decision/Decision.css +6 -82
  7. package/build/styles/main.css +6 -82
  8. package/build/types/body/Body.d.ts +1 -1
  9. package/build/types/common/commonProps.d.ts +1 -1
  10. package/build/types/common/commonProps.d.ts.map +1 -1
  11. package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts +1 -1
  12. package/build/types/common/dateUtils/getDayNames/getDayNames.d.ts.map +1 -1
  13. package/build/types/common/dateUtils/getDayNames/index.d.ts +1 -1
  14. package/build/types/common/dateUtils/getDayNames/index.d.ts.map +1 -1
  15. package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts +1 -1
  16. package/build/types/common/dateUtils/getMonthNames/getMonthNames.d.ts.map +1 -1
  17. package/build/types/common/dateUtils/getMonthNames/index.d.ts +1 -1
  18. package/build/types/common/dateUtils/getMonthNames/index.d.ts.map +1 -1
  19. package/build/types/common/dateUtils/index.d.ts +6 -6
  20. package/build/types/common/dateUtils/index.d.ts.map +1 -1
  21. package/build/types/common/dateUtils/isDateValid/index.d.ts +1 -1
  22. package/build/types/common/dateUtils/isDateValid/index.d.ts.map +1 -1
  23. package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts +2 -2
  24. package/build/types/common/dateUtils/isDateValid/isDateValid.d.ts.map +1 -1
  25. package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts +1 -1
  26. package/build/types/common/dateUtils/isMonthAndYearFormat/index.d.ts.map +1 -1
  27. package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts +1 -1
  28. package/build/types/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.d.ts.map +1 -1
  29. package/build/types/common/dateUtils/isWithinRange/index.d.ts +1 -1
  30. package/build/types/common/dateUtils/isWithinRange/index.d.ts.map +1 -1
  31. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts +1 -1
  32. package/build/types/common/dateUtils/isWithinRange/isWithinRange.d.ts.map +1 -1
  33. package/build/types/common/dateUtils/moveToWithinRange/index.d.ts +1 -1
  34. package/build/types/common/dateUtils/moveToWithinRange/index.d.ts.map +1 -1
  35. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts +1 -1
  36. package/build/types/common/dateUtils/moveToWithinRange/moveToWithinRange.d.ts.map +1 -1
  37. package/build/types/common/panel/Panel.d.ts +1 -1
  38. package/build/types/common/responsivePanel/ResponsivePanel.d.ts +1 -1
  39. package/build/types/dateInput/DateInput.d.ts +30 -41
  40. package/build/types/dateInput/DateInput.d.ts.map +1 -1
  41. package/build/types/dateInput/DateInput.messages.d.ts +24 -33
  42. package/build/types/dateInput/DateInput.messages.d.ts.map +1 -1
  43. package/build/types/dateInput/index.d.ts +2 -2
  44. package/build/types/dateInput/index.d.ts.map +1 -1
  45. package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts +1 -1
  46. package/build/types/dateInput/utils/convertToLocalMidnight/convertToLocalMidnight.d.ts.map +1 -1
  47. package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts +1 -1
  48. package/build/types/dateInput/utils/convertToLocalMidnight/index.d.ts.map +1 -1
  49. package/build/types/dateInput/utils/index.d.ts +1 -2
  50. package/build/types/dateInput/utils/index.d.ts.map +1 -1
  51. package/build/types/dateLookup/DateLookup.d.ts +1 -0
  52. package/build/types/dateLookup/DateLookup.d.ts.map +1 -1
  53. package/build/types/decision/Decision.d.ts +39 -52
  54. package/build/types/decision/Decision.d.ts.map +1 -1
  55. package/build/types/decision/index.d.ts +1 -2
  56. package/build/types/decision/index.d.ts.map +1 -1
  57. package/build/types/dimmer/Dimmer.d.ts +1 -1
  58. package/build/types/index.d.ts +2 -0
  59. package/build/types/index.d.ts.map +1 -1
  60. package/build/types/promoCard/PromoCard.d.ts +1 -2
  61. package/build/types/promoCard/PromoCard.d.ts.map +1 -1
  62. package/build/types/select/searchBox/SearchBox.d.ts +1 -1
  63. package/package.json +1 -1
  64. package/src/common/commonProps.ts +1 -1
  65. package/src/common/dateUtils/getDayNames/getDayNames.spec.js +2 -2
  66. package/src/common/dateUtils/getDayNames/{getDayNames.js → getDayNames.ts} +5 -2
  67. package/src/common/dateUtils/getMonthNames/getMonthNames.spec.js +9 -8
  68. package/src/common/dateUtils/getMonthNames/{getMonthNames.js → getMonthNames.ts} +5 -3
  69. package/src/common/dateUtils/isDateValid/{isDateValid.spec.js → isDateValid.spec.ts} +1 -1
  70. package/src/common/dateUtils/isDateValid/isDateValid.ts +13 -0
  71. package/src/common/dateUtils/isMonthAndYearFormat/isMonthAndYearFormat.spec.js +3 -7
  72. package/src/common/dateUtils/isMonthAndYearFormat/{isMonthAndYearFormat.js → isMonthAndYearFormat.ts} +1 -1
  73. package/src/common/dateUtils/isWithinRange/{isWithinRange.spec.js → isWithinRange.spec.ts} +0 -10
  74. package/src/common/dateUtils/isWithinRange/{isWithinRange.js → isWithinRange.ts} +1 -1
  75. package/src/common/dateUtils/moveToWithinRange/{moveToWithinRange.js → moveToWithinRange.ts} +2 -2
  76. package/src/dateInput/DateInput.spec.js +7 -56
  77. package/src/dateInput/DateInput.story.tsx +11 -8
  78. package/src/dateInput/{DateInput.js → DateInput.tsx} +116 -123
  79. package/src/dateInput/index.ts +2 -0
  80. package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.js → convertToLocalMidnight.ts} +1 -1
  81. package/src/dateInput/utils/{index.js → index.ts} +0 -1
  82. package/src/dateLookup/DateLookup.js +12 -1
  83. package/src/dateLookup/DateLookup.testingLibrary.spec.js +12 -1
  84. package/src/dateLookup/dayCalendar/table/DayCalendarTable.js +1 -0
  85. package/src/decision/Decision.css +6 -82
  86. package/src/decision/Decision.less +3 -41
  87. package/src/decision/Decision.spec.js +56 -61
  88. package/src/decision/{Decision.story.js → Decision.story.tsx} +5 -5
  89. package/src/decision/Decision.tsx +133 -0
  90. package/src/decision/index.ts +1 -0
  91. package/src/index.ts +2 -0
  92. package/src/main.css +6 -82
  93. package/src/promoCard/PromoCard.tsx +1 -2
  94. package/src/tile/Tile.js +1 -1
  95. package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts +0 -6
  96. package/build/types/dateInput/utils/explodeDate/explodeDate.d.ts.map +0 -1
  97. package/build/types/dateInput/utils/explodeDate/index.d.ts +0 -2
  98. package/build/types/dateInput/utils/explodeDate/index.d.ts.map +0 -1
  99. package/build/types/decision/decisionEnums.d.ts +0 -9
  100. package/build/types/decision/decisionEnums.d.ts.map +0 -1
  101. package/build/types/sizeSwapper/SizeSwapper.d.ts +0 -3
  102. package/build/types/sizeSwapper/SizeSwapper.d.ts.map +0 -1
  103. package/build/types/sizeSwapper/index.d.ts +0 -2
  104. package/build/types/sizeSwapper/index.d.ts.map +0 -1
  105. package/src/common/dateUtils/isDateValid/isDateValid.js +0 -6
  106. package/src/dateInput/index.js +0 -3
  107. package/src/dateInput/utils/explodeDate/explodeDate.js +0 -7
  108. package/src/dateInput/utils/explodeDate/explodeDate.spec.js +0 -11
  109. package/src/dateInput/utils/explodeDate/index.js +0 -1
  110. package/src/decision/Decision.js +0 -148
  111. package/src/decision/decisionEnums.ts +0 -11
  112. package/src/decision/index.js +0 -2
  113. package/src/sizeSwapper/SizeSwapper.js +0 -69
  114. package/src/sizeSwapper/SizeSwapper.spec.js +0 -100
  115. package/src/sizeSwapper/SizeSwapper.story.js +0 -34
  116. package/src/sizeSwapper/index.js +0 -1
  117. /package/src/common/dateUtils/getDayNames/{index.js → index.ts} +0 -0
  118. /package/src/common/dateUtils/getMonthNames/{index.js → index.ts} +0 -0
  119. /package/src/common/dateUtils/{index.js → index.ts} +0 -0
  120. /package/src/common/dateUtils/isDateValid/{index.js → index.ts} +0 -0
  121. /package/src/common/dateUtils/isMonthAndYearFormat/{index.js → index.ts} +0 -0
  122. /package/src/common/dateUtils/isWithinRange/{index.js → index.ts} +0 -0
  123. /package/src/common/dateUtils/moveToWithinRange/{index.js → index.ts} +0 -0
  124. /package/src/dateInput/{DateInput.messages.js → DateInput.messages.ts} +0 -0
  125. /package/src/dateInput/utils/convertToLocalMidnight/{convertToLocalMidnight.spec.js → convertToLocalMidnight.spec.ts} +0 -0
  126. /package/src/dateInput/utils/convertToLocalMidnight/{index.js → index.ts} +0 -0
package/build/index.js CHANGED
@@ -8,6 +8,7 @@ var icons = require('@transferwise/icons');
8
8
  var reactIntl = require('react-intl');
9
9
  var PropTypes = require('prop-types');
10
10
  var componentsTheming = require('@wise/components-theming');
11
+ var formatting = require('@transferwise/formatting');
11
12
  var react$1 = require('@headlessui/react');
12
13
  var mergeProps = require('merge-props');
13
14
  var mergeRefs = require('react-merge-refs');
@@ -15,7 +16,6 @@ var shim = require('use-sync-external-store/shim');
15
16
  var react = require('@floating-ui/react');
16
17
  var focus = require('@react-aria/focus');
17
18
  var overlays = require('@react-aria/overlays');
18
- var formatting = require('@transferwise/formatting');
19
19
  var reactTransitionGroup = require('react-transition-group');
20
20
  var reactPopper = require('react-popper');
21
21
  var throttle = require('lodash.throttle');
@@ -2779,15 +2779,15 @@ function getDayNames(locale, format = 'short') {
2779
2779
  return days;
2780
2780
  }
2781
2781
 
2782
- function isWithinRange(date, min, max) {
2783
- return !date || (!min || date >= min) && (!max || date <= max);
2784
- }
2785
-
2786
2782
  // Makes sure that date is between min and max dates, returns a cloned min or max
2787
2783
  function moveToWithinRange(date, min, max) {
2788
2784
  return isWithinRange(date, min, max) ? date : new Date(min && date < min ? +min : +max);
2789
2785
  }
2790
2786
 
2787
+ function isWithinRange(date, min, max) {
2788
+ return !date || (!min || date >= min) && (!max || date <= max);
2789
+ }
2790
+
2791
2791
  const getMonthNames = (locale, format = 'long') => {
2792
2792
  const months = [];
2793
2793
  const date = new Date(2018, 0, 1);
@@ -2801,9 +2801,17 @@ const getMonthNames = (locale, format = 'long') => {
2801
2801
  return months;
2802
2802
  };
2803
2803
 
2804
- const isDateValid = date => validDateObject(date) || validDateString(date);
2805
- const validDateString = dateString => typeof dateString === 'string' && validDateObject(new Date(dateString));
2806
- const validDateObject = dateObject => dateObject instanceof Date && !isNaN(dateObject); // eslint-disable-line no-restricted-globals
2804
+ const isDateValid = date => {
2805
+ if (date === null) {
2806
+ return false;
2807
+ } else if (date instanceof Date) {
2808
+ return validDateObject(date);
2809
+ } else {
2810
+ return validDateString(date);
2811
+ }
2812
+ };
2813
+ const validDateString = dateString => validDateObject(new Date(dateString));
2814
+ const validDateObject = dateObject => !isNaN(dateObject.getTime());
2807
2815
 
2808
2816
  const isMonthAndYearFormat = dateString => validDateString(dateString) && dateString.split('-').length < 3;
2809
2817
 
@@ -2825,48 +2833,31 @@ var messages$9 = reactIntl.defineMessages({
2825
2833
  }
2826
2834
  });
2827
2835
 
2828
- const explodeDate = date => {
2829
- const year = date.getFullYear();
2830
- const month = date.getMonth();
2831
- const day = date.getDate();
2832
- return {
2833
- year,
2834
- month,
2835
- day
2836
- };
2837
- };
2838
-
2839
2836
  const convertToLocalMidnight = date => {
2840
2837
  const utcDate = new Date(date.split('T')[0]); // using YYYY-MM-DD creates UTC date
2841
-
2842
2838
  return new Date(utcDate.getUTCFullYear(), utcDate.getUTCMonth(), utcDate.getUTCDate());
2843
2839
  };
2844
2840
 
2845
2841
  const MonthBeforeDay = new Set(['en-US', 'ja-JP']);
2846
- const INITIAL_DEFAULT_STATE = {
2847
- year: null,
2848
- month: null,
2849
- day: null
2850
- };
2851
2842
  const DateInput = ({
2852
2843
  'aria-labelledby': ariaLabelledBy,
2853
2844
  'aria-label': ariaLabel,
2854
- disabled,
2855
- size,
2845
+ disabled = false,
2846
+ size = exports.Size.MEDIUM,
2856
2847
  value,
2857
2848
  dayLabel,
2858
2849
  dayAutoComplete,
2859
2850
  monthLabel,
2860
2851
  yearLabel,
2861
2852
  yearAutoComplete,
2862
- monthFormat,
2863
- mode,
2853
+ monthFormat = exports.MonthFormat.LONG,
2854
+ mode = exports.DateMode.DAY_MONTH_YEAR,
2864
2855
  onChange,
2865
2856
  onFocus,
2866
2857
  onBlur,
2867
2858
  placeholders,
2868
2859
  id,
2869
- selectProps
2860
+ selectProps = {}
2870
2861
  }) => {
2871
2862
  const {
2872
2863
  locale,
@@ -2876,23 +2867,34 @@ const DateInput = ({
2876
2867
  if (value && isDateValid(value)) {
2877
2868
  return typeof value === 'string' ? convertToLocalMidnight(value) : value;
2878
2869
  }
2879
- return null;
2870
+ return undefined;
2880
2871
  };
2881
- const getExplodedDate = unit => {
2882
- let explodedDate = INITIAL_DEFAULT_STATE;
2872
+ const getInitialDate = unit => {
2883
2873
  if (value && isDateValid(value)) {
2884
2874
  const dateObject = getDateObject();
2885
- explodedDate = explodeDate(dateObject);
2886
- if (isMonthAndYearFormat(value)) {
2887
- explodedDate.day = null;
2875
+ if (typeof value === 'string' && isMonthAndYearFormat(value) && unit === 'day') {
2876
+ return null;
2877
+ }
2878
+ if (dateObject !== undefined) {
2879
+ switch (unit) {
2880
+ case 'year':
2881
+ return dateObject.getFullYear();
2882
+ case 'month':
2883
+ return dateObject.getMonth();
2884
+ case 'day':
2885
+ return dateObject.getDate();
2886
+ default:
2887
+ return null;
2888
+ }
2888
2889
  }
2889
2890
  }
2890
- return explodedDate[unit];
2891
+ return null;
2891
2892
  };
2892
- const [day, setDay] = React.useState(() => getExplodedDate('day'));
2893
- const [month, setMonth] = React.useState(() => getExplodedDate('month'));
2894
- const [year, setYear] = React.useState(() => getExplodedDate('year'));
2893
+ const [day, setDay] = React.useState(() => getInitialDate('day'));
2894
+ const [month, setMonth] = React.useState(() => getInitialDate('month'));
2895
+ const [year, setYear] = React.useState(() => getInitialDate('year'));
2895
2896
  const [lastBroadcastedValue, setLastBroadcastedValue] = React.useState(getDateObject);
2897
+ const monthNames = getMonthNames(locale, monthFormat);
2896
2898
  dayLabel = dayLabel || formatMessage(messages$9.dayLabel);
2897
2899
  monthLabel = monthLabel || formatMessage(messages$9.monthLabel);
2898
2900
  yearLabel = yearLabel || formatMessage(messages$9.yearLabel);
@@ -2914,7 +2916,6 @@ const DateInput = ({
2914
2916
  }
2915
2917
  };
2916
2918
  const getSelectElement = () => {
2917
- const monthOptions = getMonthsOptions();
2918
2919
  return /*#__PURE__*/jsxRuntime.jsxs("label", {
2919
2920
  className: "d-flex flex-column",
2920
2921
  children: [/*#__PURE__*/jsxRuntime.jsx("span", {
@@ -2923,70 +2924,60 @@ const DateInput = ({
2923
2924
  }), /*#__PURE__*/jsxRuntime.jsx(SelectInput, {
2924
2925
  name: "month",
2925
2926
  disabled: disabled,
2926
- placeholder: placeholders.month,
2927
- items: monthOptions,
2927
+ placeholder: placeholders?.month,
2928
+ items: Array.from({
2929
+ length: 12
2930
+ }, (_, index) => ({
2931
+ type: 'option',
2932
+ value: index
2933
+ })),
2928
2934
  size: size,
2929
- value: monthOptions.find(item => item.value.value === month)?.value,
2930
- renderValue: ({
2931
- label
2932
- }) => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
2933
- title: label
2935
+ value: month,
2936
+ renderValue: selectedValue => /*#__PURE__*/jsxRuntime.jsx(SelectInputOptionContent, {
2937
+ title: monthNames[selectedValue]
2934
2938
  }),
2935
2939
  onChange: selectedValue => handleMonthChange(selectedValue),
2936
2940
  ...selectProps
2937
2941
  })]
2938
2942
  });
2939
2943
  };
2940
- const getMonthsOptions = () => {
2941
- const options = [];
2942
- const months = getMonthNames(locale, monthFormat);
2943
- months.forEach((label, index) => {
2944
- options.push({
2945
- type: 'option',
2946
- value: {
2947
- label,
2948
- value: index
2949
- }
2950
- });
2951
- });
2952
- return options;
2953
- };
2954
2944
  const handleInternalValue = (newDay = day, newMonth = month, newYear = year) => {
2955
- const dateValue = newDay != null && newMonth != null && newYear != null ? new Date(newYear, newMonth, newDay) : null;
2956
- const newValue = isDateValid(dateValue) ? dateValue : null;
2957
- if (!newValue) {
2958
- broadcastNewValue(INITIAL_DEFAULT_STATE);
2945
+ if (newDay == null || newMonth == null || newYear == null) {
2946
+ broadcastNewValue(null);
2947
+ return;
2948
+ }
2949
+ const dateValue = new Date(newYear, newMonth, newDay);
2950
+ if (!isDateValid(dateValue)) {
2951
+ broadcastNewValue(null);
2952
+ return;
2959
2953
  }
2960
2954
  if (mode === exports.DateMode.MONTH_YEAR) {
2961
- if (newMonth >= 0 && newYear && (newMonth !== month || newYear !== year)) {
2962
- broadcastNewValue(newValue);
2955
+ if (newMonth !== month || newYear !== year) {
2956
+ broadcastNewValue(dateValue);
2963
2957
  }
2964
- } else if (newDay && newMonth >= 0 && newYear && (newDay !== day || newMonth !== month || newYear !== year)) {
2965
- broadcastNewValue(newValue);
2958
+ } else if (newDay !== day || newMonth !== month || newYear !== year) {
2959
+ broadcastNewValue(dateValue);
2966
2960
  }
2967
2961
  };
2968
2962
  const handleDayChange = event => {
2969
2963
  const {
2970
2964
  checkedDay
2971
- } = checkDate(event.target.value, month, year);
2965
+ } = checkDate(Number.parseInt(event.target.value, 10), month, year);
2972
2966
  setDay(checkedDay);
2973
2967
  handleInternalValue(checkedDay, month, year);
2974
2968
  };
2975
- const handleMonthChange = selectedValue => {
2976
- if (!selectedValue) {
2969
+ const handleMonthChange = selectedMonth => {
2970
+ if (selectedMonth === null) {
2977
2971
  setMonth(null);
2978
2972
  handleInternalValue(day, null, year);
2979
2973
  return;
2980
2974
  }
2981
- const selectedMonth = selectedValue ? selectedValue.value : 0;
2982
2975
  const {
2983
2976
  checkedDay
2984
2977
  } = checkDate(day, selectedMonth, year);
2985
2978
  setMonth(selectedMonth);
2986
- if (day) {
2987
- if (checkedDay !== day) {
2988
- setDay(checkedDay);
2989
- }
2979
+ if (day && checkedDay !== day) {
2980
+ setDay(checkedDay);
2990
2981
  }
2991
2982
  handleInternalValue(checkedDay, selectedMonth, year);
2992
2983
  };
@@ -2997,35 +2988,33 @@ const DateInput = ({
2997
2988
  // Correct day based on year and month.
2998
2989
  const {
2999
2990
  checkedDay
3000
- } = checkDate(day, month, newValue);
3001
- if (day) {
3002
- if (checkedDay !== day) {
3003
- setDay(checkedDay);
3004
- }
2991
+ } = checkDate(day, month, Number.parseInt(newValue, 10));
2992
+ if (day && checkedDay !== day) {
2993
+ setDay(checkedDay);
3005
2994
  }
3006
- setYear(slicedYear);
3007
- handleInternalValue(checkedDay, month, slicedYear);
2995
+ setYear(Number.parseInt(slicedYear, 10));
2996
+ handleInternalValue(checkedDay, month, Number.parseInt(slicedYear, 10));
3008
2997
  } else {
3009
- setYear(slicedYear);
2998
+ setYear(Number.parseInt(slicedYear, 10));
3010
2999
  handleInternalValue(day, month, null);
3011
3000
  }
3012
3001
  };
3013
3002
  const broadcastNewValue = newValue => {
3014
3003
  if (newValue !== lastBroadcastedValue) {
3015
3004
  setLastBroadcastedValue(newValue);
3016
- onChange(getDateAsString(newValue) || null);
3005
+ onChange(newValue != null ? getDateAsString(newValue) : null);
3017
3006
  }
3018
3007
  };
3019
3008
  const checkDate = (newDay = null, newMonth = 0, newYear = null) => {
3020
3009
  let checkedDay = newDay;
3021
- const maxDay = new Date(newYear || 2000, newMonth + 1, 0).getDate();
3010
+ const maxDay = new Date(newYear || 2000, newMonth != null ? newMonth + 1 : 1, 0).getDate();
3022
3011
  if (!newDay) {
3023
3012
  checkedDay = null;
3024
3013
  }
3025
- if (newDay && newDay < 0 || newDay === '00') {
3014
+ if (newDay && newDay < 0) {
3026
3015
  checkedDay = 1;
3027
3016
  }
3028
- if (newDay && newMonth || newDay > 31) {
3017
+ if (newDay && newMonth || newDay && newDay > 31) {
3029
3018
  checkedDay = newDay > maxDay ? maxDay : newDay;
3030
3019
  }
3031
3020
  return {
@@ -3045,8 +3034,10 @@ const DateInput = ({
3045
3034
  id: id,
3046
3035
  "aria-labelledby": ariaLabelledBy,
3047
3036
  "aria-label": ariaLabel,
3048
- onFocus: event => shouldPropagateOnFocus(event) ? onFocus && onFocus() : event.stopPropagation(),
3049
- onBlur: event => shouldPropagateOnBlur(event) ? onBlur && onBlur() : event.stopPropagation(),
3037
+ role: "group" // Add role attribute to indicate container for interactive elements
3038
+ ,
3039
+ onFocus: event => shouldPropagateOnFocus(event) ? onFocus && onFocus(event) : event.stopPropagation(),
3040
+ onBlur: event => shouldPropagateOnBlur(event) ? onBlur && onBlur(event) : event.stopPropagation(),
3050
3041
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
3051
3042
  className: "row",
3052
3043
  children: [monthBeforeDay && /*#__PURE__*/jsxRuntime.jsx("div", {
@@ -3099,7 +3090,6 @@ const DateInput = ({
3099
3090
  })
3100
3091
  });
3101
3092
  };
3102
-
3103
3093
  // Should only propagate if the relatedTarget is not part of this DateInput component.
3104
3094
  function shouldPropagateOnFocus({
3105
3095
  target,
@@ -3109,7 +3099,6 @@ function shouldPropagateOnFocus({
3109
3099
  const relatedParent = relatedTarget && relatedTarget.closest('.tw-date');
3110
3100
  return targetParent !== relatedParent;
3111
3101
  }
3112
-
3113
3102
  // Should only propagate if the relatedTarget or the activeElement is not part of this DateInput component.
3114
3103
  function shouldPropagateOnBlur({
3115
3104
  target,
@@ -3126,42 +3115,6 @@ function shouldPropagateOnBlur({
3126
3115
  const focusElementParent = focusElement && focusElement.closest('.tw-date');
3127
3116
  return blurElementParent !== focusElementParent;
3128
3117
  }
3129
- DateInput.propTypes = {
3130
- 'aria-label': PropTypes__default.default.string,
3131
- 'aria-labelledby': PropTypes__default.default.string,
3132
- disabled: PropTypes__default.default.bool,
3133
- size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
3134
- value: PropTypes__default.default.oneOfType([PropTypes__default.default.string, PropTypes__default.default.instanceOf(Date)]),
3135
- onChange: PropTypes__default.default.func.isRequired,
3136
- onFocus: PropTypes__default.default.func,
3137
- onBlur: PropTypes__default.default.func,
3138
- dayLabel: PropTypes__default.default.string,
3139
- dayAutoComplete: PropTypes__default.default.string,
3140
- monthLabel: PropTypes__default.default.string,
3141
- yearLabel: PropTypes__default.default.string,
3142
- yearAutoComplete: PropTypes__default.default.string,
3143
- monthFormat: PropTypes__default.default.oneOf(['long', 'short']),
3144
- mode: PropTypes__default.default.oneOf(['day-month-year', 'month-year']),
3145
- placeholders: PropTypes__default.default.shape({
3146
- day: PropTypes__default.default.node,
3147
- month: PropTypes__default.default.node,
3148
- year: PropTypes__default.default.node
3149
- }),
3150
- id: PropTypes__default.default.string,
3151
- selectProps: PropTypes__default.default.object
3152
- };
3153
- DateInput.defaultProps = {
3154
- disabled: false,
3155
- size: exports.Size.MEDIUM,
3156
- value: null,
3157
- onFocus: null,
3158
- onBlur: null,
3159
- monthFormat: exports.MonthFormat.LONG,
3160
- mode: exports.DateMode.DAY_MONTH_YEAR,
3161
- id: '',
3162
- selectProps: {}
3163
- };
3164
- var DateInput$1 = DateInput;
3165
3118
 
3166
3119
  const POPOVER_OFFSET = [0, 16];
3167
3120
  // By default the flip positioning explores only the opposite alternative. So if left is passed and there's no enough space
@@ -4347,6 +4300,7 @@ class DateLookup extends React.PureComponent {
4347
4300
  size,
4348
4301
  placeholder,
4349
4302
  label,
4303
+ 'aria-labelledby': ariaLabelledBy,
4350
4304
  monthFormat,
4351
4305
  disabled,
4352
4306
  clearable,
@@ -4355,6 +4309,7 @@ class DateLookup extends React.PureComponent {
4355
4309
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
4356
4310
  // eslint-disable-line jsx-a11y/no-static-element-interactions
4357
4311
  ref: this.element,
4312
+ "aria-labelledby": ariaLabelledBy,
4358
4313
  className: "input-group",
4359
4314
  onKeyDown: this.handleKeyDown,
4360
4315
  children: [/*#__PURE__*/jsxRuntime.jsx(DateTrigger$1, {
@@ -4384,6 +4339,7 @@ DateLookup.propTypes = {
4384
4339
  size: PropTypes__default.default.oneOf(['sm', 'md', 'lg']),
4385
4340
  placeholder: PropTypes__default.default.string,
4386
4341
  label: PropTypes__default.default.string,
4342
+ 'aria-labelledby': PropTypes__default.default.string,
4387
4343
  monthFormat: PropTypes__default.default.oneOf(['long', 'short']),
4388
4344
  disabled: PropTypes__default.default.bool,
4389
4345
  onChange: PropTypes__default.default.func.isRequired,
@@ -4406,19 +4362,6 @@ DateLookup.defaultProps = {
4406
4362
  };
4407
4363
  var DateLookup$1 = DateLookup;
4408
4364
 
4409
- // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
4410
- exports.DecisionPresentation = void 0;
4411
- (function (Presentation) {
4412
- Presentation["LIST"] = "LIST";
4413
- Presentation["LIST_BLOCK"] = "LIST_BLOCK";
4414
- Presentation["LIST_BLOCK_GRID"] = "LIST_BLOCK_GRID";
4415
- })(exports.DecisionPresentation || (exports.DecisionPresentation = {}));
4416
- // TODO: consider to move this enum into component file once we migrate it on TypeScript or replace with some common enum
4417
- exports.DecisionType = void 0;
4418
- (function (Type) {
4419
- Type["NAVIGATION"] = "NAVIGATION";
4420
- })(exports.DecisionType || (exports.DecisionType = {}));
4421
-
4422
4365
  const NavigationOption = /*#__PURE__*/React.forwardRef(({
4423
4366
  as: component = 'button',
4424
4367
  disabled = false,
@@ -4452,70 +4395,6 @@ const NavigationOption = /*#__PURE__*/React.forwardRef(({
4452
4395
  });
4453
4396
  });
4454
4397
 
4455
- const Layout = {
4456
- COLUMN: 'COLUMN'
4457
- };
4458
- const SizeSwapper = /*#__PURE__*/React.forwardRef(({
4459
- items,
4460
- inline
4461
- }, reference) => {
4462
- const parentReference = React.useRef(null);
4463
- const [clientWidth] = useClientWidth({
4464
- ref: reference || parentReference
4465
- });
4466
- if (!items || items.length === 0) {
4467
- return null;
4468
- }
4469
- // If all breakpoints are specified and clientWidth never > breakpoint itemsToRender can be undefined.
4470
- // Do not use deconstruct here to get items and layout.
4471
- let itemsToRender = [];
4472
- if (clientWidth) {
4473
- itemsToRender = items.filter(({
4474
- breakpoint = 0
4475
- }) => clientWidth >= breakpoint).pop();
4476
- } else {
4477
- // On SSR environments useClientWidth returns null because ref is undefined so we render
4478
- // all elements by default.
4479
- // If there's no SSR and on first Hydration only the right elements are going to be rendered.
4480
- // If clientWidth is null or zero all elements render like a responsive technique would do.
4481
- itemsToRender.items = items.map(({
4482
- items
4483
- }) => Object.values(items));
4484
- }
4485
-
4486
- // Always return parent container even if there are no items to display to
4487
- // keep the ref on DOM and let clientWidth be calculated properly.
4488
- return /*#__PURE__*/jsxRuntime.jsx("div", {
4489
- ref: parentReference,
4490
- className: classNames__default.default('np-size-swapper', {
4491
- 'd-flex': !inline,
4492
- 'd-inline-flex': inline,
4493
- 'flex-column': itemsToRender && itemsToRender.layout === Layout.COLUMN,
4494
- 'flex-wrap': itemsToRender && itemsToRender.wrap
4495
- }),
4496
- style: {
4497
- visibility: clientWidth ? 'visible' : 'hidden'
4498
- },
4499
- children: itemsToRender && itemsToRender.items
4500
- });
4501
- });
4502
- SizeSwapper.Breakpoint = exports.Breakpoint;
4503
- SizeSwapper.Layout = Layout;
4504
- SizeSwapper.propTypes = {
4505
- inline: PropTypes__default.default.bool,
4506
- /** List of items that will appear at the specified breakpoint and presented in row or columns depending on layout */
4507
- items: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
4508
- items: PropTypes__default.default.arrayOf(PropTypes__default.default.element),
4509
- breakpoint: PropTypes__default.default.number,
4510
- layout: PropTypes__default.default.oneOf([SizeSwapper.Layout.COLUMN]),
4511
- wrap: PropTypes__default.default.bool
4512
- })).isRequired
4513
- };
4514
- SizeSwapper.defaultProps = {
4515
- inline: false
4516
- };
4517
- var SizeSwapper$1 = SizeSwapper;
4518
-
4519
4398
  const Tile = ({
4520
4399
  className,
4521
4400
  description,
@@ -4564,7 +4443,7 @@ Tile.propTypes = {
4564
4443
  className: PropTypes__default.default.string,
4565
4444
  description: PropTypes__default.default.node,
4566
4445
  disabled: PropTypes__default.default.bool,
4567
- href: PropTypes__default.default.string.isRequired,
4446
+ href: PropTypes__default.default.string,
4568
4447
  target: PropTypes__default.default.oneOf(['_self', '_blank', '_parent', '_top']),
4569
4448
  /** Accepts only Avatar and images */
4570
4449
  media: PropTypes__default.default.node.isRequired,
@@ -4583,85 +4462,28 @@ Tile.defaultProps = {
4583
4462
  };
4584
4463
  var Tile$1 = Tile;
4585
4464
 
4465
+ exports.DecisionPresentation = void 0;
4466
+ (function (DecisionPresentation) {
4467
+ DecisionPresentation["LIST"] = "LIST";
4468
+ DecisionPresentation["LIST_BLOCK"] = "LIST_BLOCK";
4469
+ DecisionPresentation["LIST_BLOCK_GRID"] = "LIST_BLOCK_GRID";
4470
+ })(exports.DecisionPresentation || (exports.DecisionPresentation = {}));
4471
+ exports.DecisionType = void 0;
4472
+ (function (DecisionType) {
4473
+ DecisionType["NAVIGATION"] = "NAVIGATION";
4474
+ })(exports.DecisionType || (exports.DecisionType = {}));
4586
4475
  const Decision = ({
4587
4476
  options,
4588
- presentation,
4589
- type,
4590
- showMediaCircleInList,
4591
- isContainerAligned,
4592
- size
4477
+ presentation = exports.DecisionPresentation.LIST,
4478
+ size = exports.Size.MEDIUM,
4479
+ type = exports.DecisionType.NAVIGATION,
4480
+ showMediaCircleInList = true,
4481
+ isContainerAligned = false
4593
4482
  }) => {
4483
+ const screenXs = useScreenSize(exports.Breakpoint.EXTRA_SMALL);
4484
+ const screenSm = useScreenSize(exports.Breakpoint.SMALL);
4594
4485
  if (type === exports.DecisionType.NAVIGATION) {
4595
- const {
4596
- LIST_BLOCK,
4597
- LIST_BLOCK_GRID
4598
- } = exports.DecisionPresentation;
4599
- if (presentation === LIST_BLOCK || presentation === LIST_BLOCK_GRID) {
4600
- const isSmall = size === exports.Size.SMALL;
4601
- const isGrid = presentation === LIST_BLOCK_GRID;
4602
- const items = [{
4603
- items: [],
4604
- layout: SizeSwapper$1.Layout.COLUMN
4605
- }, {
4606
- items: [],
4607
- breakpoint: isSmall ? exports.Breakpoint.EXTRA_SMALL : exports.Breakpoint.SMALL,
4608
- wrap: isGrid
4609
- }];
4610
- options.forEach(({
4611
- description,
4612
- disabled,
4613
- href,
4614
- target,
4615
- media: {
4616
- block,
4617
- list
4618
- },
4619
- onClick,
4620
- title
4621
- }, key) => {
4622
- items[0].items.push( /*#__PURE__*/jsxRuntime.jsx(NavigationOption
4623
- // eslint-disable-next-line react/no-array-index-key
4624
- , {
4625
- complex: false,
4626
- content: description,
4627
- disabled: disabled,
4628
- href: href,
4629
- target: target,
4630
- media: list,
4631
- showMediaAtAllSizes: true,
4632
- showMediaCircle: showMediaCircleInList,
4633
- isContainerAligned: isContainerAligned,
4634
- title: title,
4635
- onClick: onClick
4636
- }, `nav-${key}`));
4637
- items[1].items.push( /*#__PURE__*/jsxRuntime.jsx(Tile$1
4638
- // eslint-disable-next-line react/no-array-index-key
4639
- , {
4640
- className: classNames__default.default(`np-decision__tile${isSmall ? '--small' : ''}`, {
4641
- 'np-decision__tile--fixed-width': isGrid
4642
- }),
4643
- description: description,
4644
- disabled: disabled,
4645
- href: href,
4646
- target: target,
4647
- media: block,
4648
- size: isSmall ? exports.Size.SMALL : exports.Size.MEDIUM,
4649
- title: title,
4650
- onClick: onClick
4651
- }, `tile-${key}`));
4652
- });
4653
- return /*#__PURE__*/jsxRuntime.jsx("div", {
4654
- className: classNames__default.default('np-decision', {
4655
- 'np-decision--small': isSmall,
4656
- 'np-decision--grid': isGrid
4657
- }),
4658
- children: /*#__PURE__*/jsxRuntime.jsx(SizeSwapper$1, {
4659
- items: items
4660
- })
4661
- });
4662
- }
4663
- // LIST
4664
- return options.map(({
4486
+ const renderedOptions = options.map(({
4665
4487
  title,
4666
4488
  description,
4667
4489
  disabled,
@@ -4686,42 +4508,49 @@ const Decision = ({
4686
4508
  title: title,
4687
4509
  onClick: onClick
4688
4510
  }, `nav-${key}`));
4511
+ if (presentation === exports.DecisionPresentation.LIST_BLOCK || presentation === exports.DecisionPresentation.LIST_BLOCK_GRID) {
4512
+ const isSmall = size === exports.Size.SMALL;
4513
+ const breakpoint = isSmall ? screenXs : screenSm;
4514
+ const isGrid = presentation === exports.DecisionPresentation.LIST_BLOCK_GRID;
4515
+ return /*#__PURE__*/jsxRuntime.jsx("div", {
4516
+ className: classNames__default.default('np-decision d-flex', {
4517
+ 'np-decision--small': isSmall,
4518
+ 'np-decision--grid': isGrid
4519
+ }, breakpoint ? isGrid && 'flex-wrap' : 'flex-column'),
4520
+ children: breakpoint ? options.map(({
4521
+ description,
4522
+ disabled,
4523
+ href,
4524
+ target,
4525
+ media: {
4526
+ block
4527
+ },
4528
+ onClick,
4529
+ title
4530
+ }, key) => /*#__PURE__*/jsxRuntime.jsx(Tile$1
4531
+ // eslint-disable-next-line react/no-array-index-key
4532
+ , {
4533
+ className: classNames__default.default(`np-decision__tile${isSmall ? '--small' : ''}`, {
4534
+ 'np-decision__tile--fixed-width': isGrid
4535
+ }),
4536
+ description: description,
4537
+ disabled: disabled,
4538
+ href: href,
4539
+ target: target,
4540
+ media: block,
4541
+ size: isSmall ? exports.Size.SMALL : exports.Size.MEDIUM,
4542
+ title: title,
4543
+ onClick: onClick
4544
+ }, `tile-${key}`)) : renderedOptions
4545
+ });
4546
+ }
4547
+ // LIST
4548
+ return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
4549
+ children: renderedOptions
4550
+ });
4689
4551
  }
4690
- return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {});
4691
- };
4692
- Decision.propTypes = {
4693
- /** A list of elements to be rendered */
4694
- options: PropTypes__default.default.arrayOf(PropTypes__default.default.shape({
4695
- description: PropTypes__default.default.node,
4696
- disabled: PropTypes__default.default.bool,
4697
- href: PropTypes__default.default.string,
4698
- target: PropTypes__default.default.oneOf(['_self', '_blank', '_parent', '_top']),
4699
- media: PropTypes__default.default.shape({
4700
- block: PropTypes__default.default.node.isRequired,
4701
- list: PropTypes__default.default.node.isRequired
4702
- }),
4703
- onClick: PropTypes__default.default.func,
4704
- title: PropTypes__default.default.node.isRequired
4705
- })).isRequired,
4706
- /** Handles the display mode of the component */
4707
- presentation: PropTypes__default.default.oneOf(['LIST', 'LIST_BLOCK', 'LIST_BLOCK_GRID']),
4708
- /** Size currently affects only Tile dimension */
4709
- size: PropTypes__default.default.oneOf(['sm', 'md']),
4710
- /** Decide which kind of element type needs to be rendered ex: Navigation Options or in the future Radio or Checkbox Options */
4711
- type: PropTypes__default.default.oneOf(['NAVIGATION']),
4712
- /** Display media in a circle in list presentation */
4713
- showMediaCircleInList: PropTypes__default.default.bool,
4714
- /** Sets navigation options to be aligned with the parent container */
4715
- isContainerAligned: PropTypes__default.default.bool
4716
- };
4717
- Decision.defaultProps = {
4718
- presentation: exports.DecisionPresentation.LIST,
4719
- size: exports.Size.MEDIUM,
4720
- type: exports.DecisionType.NAVIGATION,
4721
- showMediaCircleInList: true,
4722
- isContainerAligned: false
4552
+ return null;
4723
4553
  };
4724
- var Decision$1 = Decision;
4725
4554
 
4726
4555
  const isLayoutHorizontal = layout => [exports.Layout.HORIZONTAL_LEFT_ALIGNED, exports.Layout.HORIZONTAL_RIGHT_ALIGNED, exports.Layout.HORIZONTAL_JUSTIFIED].includes(layout);
4727
4556
  const getAlignmentClasses = (layout, action) => {
@@ -15483,9 +15312,9 @@ exports.CircularButton = CircularButton$1;
15483
15312
  exports.CriticalCommsBanner = CriticalCommsBanner;
15484
15313
  exports.DEFAULT_LANG = DEFAULT_LANG;
15485
15314
  exports.DEFAULT_LOCALE = DEFAULT_LOCALE;
15486
- exports.DateInput = DateInput$1;
15315
+ exports.DateInput = DateInput;
15487
15316
  exports.DateLookup = DateLookup$1;
15488
- exports.Decision = Decision$1;
15317
+ exports.Decision = Decision;
15489
15318
  exports.DefinitionList = DefinitionList$1;
15490
15319
  exports.Dimmer = Dimmer$1;
15491
15320
  exports.DirectionProvider = DirectionProvider;