@transferwise/components 46.140.1 → 46.141.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 (134) hide show
  1. package/build/avatarWrapper/AvatarWrapper.js +3 -4
  2. package/build/avatarWrapper/AvatarWrapper.js.map +1 -1
  3. package/build/avatarWrapper/AvatarWrapper.mjs +4 -5
  4. package/build/avatarWrapper/AvatarWrapper.mjs.map +1 -1
  5. package/build/button/LegacyButton.js.map +1 -1
  6. package/build/button/LegacyButton.mjs.map +1 -1
  7. package/build/common/hooks/useHasIntersected/useHasIntersected.js +6 -4
  8. package/build/common/hooks/useHasIntersected/useHasIntersected.js.map +1 -1
  9. package/build/common/hooks/useHasIntersected/useHasIntersected.mjs +6 -4
  10. package/build/common/hooks/useHasIntersected/useHasIntersected.mjs.map +1 -1
  11. package/build/common/liveRegion/LiveRegion.js +4 -1
  12. package/build/common/liveRegion/LiveRegion.js.map +1 -1
  13. package/build/common/liveRegion/LiveRegion.mjs +4 -1
  14. package/build/common/liveRegion/LiveRegion.mjs.map +1 -1
  15. package/build/dateInput/DateInput.js +10 -10
  16. package/build/dateInput/DateInput.js.map +1 -1
  17. package/build/dateInput/DateInput.mjs +10 -10
  18. package/build/dateInput/DateInput.mjs.map +1 -1
  19. package/build/dateLookup/monthCalendar/table/MonthCalendarTable.js +1 -1
  20. package/build/dateLookup/monthCalendar/table/MonthCalendarTable.js.map +1 -1
  21. package/build/dateLookup/monthCalendar/table/MonthCalendarTable.mjs +1 -1
  22. package/build/dateLookup/monthCalendar/table/MonthCalendarTable.mjs.map +1 -1
  23. package/build/dateLookup/yearCalendar/table/YearCalendarTable.js +1 -1
  24. package/build/dateLookup/yearCalendar/table/YearCalendarTable.js.map +1 -1
  25. package/build/dateLookup/yearCalendar/table/YearCalendarTable.mjs +1 -1
  26. package/build/dateLookup/yearCalendar/table/YearCalendarTable.mjs.map +1 -1
  27. package/build/expressiveMoneyInput/ExpressiveMoneyInput.js.map +1 -1
  28. package/build/expressiveMoneyInput/ExpressiveMoneyInput.mjs.map +1 -1
  29. package/build/expressiveMoneyInput/amountInput/AmountInput.js +17 -11
  30. package/build/expressiveMoneyInput/amountInput/AmountInput.js.map +1 -1
  31. package/build/expressiveMoneyInput/amountInput/AmountInput.mjs +18 -12
  32. package/build/expressiveMoneyInput/amountInput/AmountInput.mjs.map +1 -1
  33. package/build/expressiveMoneyInput/hooks/useInputStyle.js +8 -6
  34. package/build/expressiveMoneyInput/hooks/useInputStyle.js.map +1 -1
  35. package/build/expressiveMoneyInput/hooks/useInputStyle.mjs +9 -7
  36. package/build/expressiveMoneyInput/hooks/useInputStyle.mjs.map +1 -1
  37. package/build/header/Header.js +1 -1
  38. package/build/header/Header.js.map +1 -1
  39. package/build/header/Header.mjs +1 -1
  40. package/build/header/Header.mjs.map +1 -1
  41. package/build/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.js.map +1 -1
  42. package/build/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.mjs.map +1 -1
  43. package/build/inputs/SelectInput/Options/SelectInputOptions.js +34 -22
  44. package/build/inputs/SelectInput/Options/SelectInputOptions.js.map +1 -1
  45. package/build/inputs/SelectInput/Options/SelectInputOptions.mjs +35 -23
  46. package/build/inputs/SelectInput/Options/SelectInputOptions.mjs.map +1 -1
  47. package/build/inputs/SelectInput/Popover/SelectInputPopover.js.map +1 -1
  48. package/build/inputs/SelectInput/Popover/SelectInputPopover.mjs.map +1 -1
  49. package/build/inputs/SelectInput/SelectInput.js +8 -6
  50. package/build/inputs/SelectInput/SelectInput.js.map +1 -1
  51. package/build/inputs/SelectInput/SelectInput.mjs +9 -7
  52. package/build/inputs/SelectInput/SelectInput.mjs.map +1 -1
  53. package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.js.map +1 -1
  54. package/build/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.mjs.map +1 -1
  55. package/build/nudge/Nudge.js +31 -15
  56. package/build/nudge/Nudge.js.map +1 -1
  57. package/build/nudge/Nudge.mjs +32 -16
  58. package/build/nudge/Nudge.mjs.map +1 -1
  59. package/build/phoneNumberInput/PhoneNumberInput.js +9 -12
  60. package/build/phoneNumberInput/PhoneNumberInput.js.map +1 -1
  61. package/build/phoneNumberInput/PhoneNumberInput.mjs +9 -12
  62. package/build/phoneNumberInput/PhoneNumberInput.mjs.map +1 -1
  63. package/build/promoCard/PromoCardGroup.js +34 -16
  64. package/build/promoCard/PromoCardGroup.js.map +1 -1
  65. package/build/promoCard/PromoCardGroup.mjs +35 -17
  66. package/build/promoCard/PromoCardGroup.mjs.map +1 -1
  67. package/build/segmentedControl/SegmentedControl.js +6 -1
  68. package/build/segmentedControl/SegmentedControl.js.map +1 -1
  69. package/build/segmentedControl/SegmentedControl.mjs +7 -2
  70. package/build/segmentedControl/SegmentedControl.mjs.map +1 -1
  71. package/build/tabs/Tabs.js +1 -1
  72. package/build/tabs/Tabs.js.map +1 -1
  73. package/build/tabs/Tabs.mjs +1 -1
  74. package/build/tabs/Tabs.mjs.map +1 -1
  75. package/build/tooltip/Tooltip.js +6 -3
  76. package/build/tooltip/Tooltip.js.map +1 -1
  77. package/build/tooltip/Tooltip.mjs +6 -3
  78. package/build/tooltip/Tooltip.mjs.map +1 -1
  79. package/build/types/avatarWrapper/AvatarWrapper.d.ts.map +1 -1
  80. package/build/types/common/hooks/useHasIntersected/useHasIntersected.d.ts.map +1 -1
  81. package/build/types/common/liveRegion/LiveRegion.d.ts.map +1 -1
  82. package/build/types/dateLookup/monthCalendar/table/MonthCalendarTable.d.ts.map +1 -1
  83. package/build/types/expressiveMoneyInput/ExpressiveMoneyInput.d.ts.map +1 -1
  84. package/build/types/expressiveMoneyInput/amountInput/AmountInput.d.ts.map +1 -1
  85. package/build/types/expressiveMoneyInput/hooks/useInputStyle.d.ts +2 -2
  86. package/build/types/expressiveMoneyInput/hooks/useInputStyle.d.ts.map +1 -1
  87. package/build/types/expressiveMoneyInput/hooks/useSelectionRange.d.ts.map +1 -1
  88. package/build/types/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.d.ts.map +1 -1
  89. package/build/types/inputs/SelectInput/Options/SelectInputOptions.d.ts.map +1 -1
  90. package/build/types/inputs/SelectInput/Popover/SelectInputPopover.d.ts.map +1 -1
  91. package/build/types/inputs/SelectInput/SelectInput.d.ts.map +1 -1
  92. package/build/types/nudge/Nudge.d.ts.map +1 -1
  93. package/build/types/phoneNumberInput/PhoneNumberInput.d.ts.map +1 -1
  94. package/build/types/promoCard/PromoCardGroup.d.ts.map +1 -1
  95. package/build/types/segmentedControl/SegmentedControl.d.ts.map +1 -1
  96. package/build/types/tooltip/Tooltip.d.ts.map +1 -1
  97. package/build/types/uploadInput/UploadInput.d.ts.map +1 -1
  98. package/build/uploadInput/UploadInput.js +29 -25
  99. package/build/uploadInput/UploadInput.js.map +1 -1
  100. package/build/uploadInput/UploadInput.mjs +29 -25
  101. package/build/uploadInput/UploadInput.mjs.map +1 -1
  102. package/package.json +2 -2
  103. package/src/avatarWrapper/AvatarWrapper.test.tsx +33 -3
  104. package/src/avatarWrapper/AvatarWrapper.tsx +5 -6
  105. package/src/button/LegacyButton.tsx +1 -1
  106. package/src/button/_stories/Button.test.story.tsx +3 -3
  107. package/src/common/hooks/useContainerSize.test.tsx +1 -1
  108. package/src/common/hooks/useHasIntersected/useHasIntersected.ts +12 -4
  109. package/src/common/liveRegion/LiveRegion.tsx +5 -2
  110. package/src/dateInput/DateInput.tsx +10 -10
  111. package/src/dateLookup/monthCalendar/table/MonthCalendarTable.tsx +1 -5
  112. package/src/dateLookup/yearCalendar/table/YearCalendarTable.tsx +1 -1
  113. package/src/expressiveMoneyInput/ExpressiveMoneyInput.tsx +1 -1
  114. package/src/expressiveMoneyInput/amountInput/AmountInput.tsx +22 -15
  115. package/src/expressiveMoneyInput/hooks/useInputStyle.ts +20 -8
  116. package/src/expressiveMoneyInput/hooks/useSelectionRange.ts +2 -0
  117. package/src/header/Header.tsx +2 -2
  118. package/src/inputs/SelectInput/BottomSheet/SelectInputBottomSheet.tsx +4 -0
  119. package/src/inputs/SelectInput/Options/SelectInputOptions.tsx +43 -27
  120. package/src/inputs/SelectInput/Popover/SelectInputPopover.tsx +4 -0
  121. package/src/inputs/SelectInput/SelectInput.tsx +21 -15
  122. package/src/inputs/SelectInput/TriggerButton/SelectInputTriggerButton.tsx +1 -1
  123. package/src/nudge/Nudge.tsx +29 -20
  124. package/src/phoneNumberInput/PhoneNumberInput.test.tsx +16 -0
  125. package/src/phoneNumberInput/PhoneNumberInput.tsx +11 -13
  126. package/src/promoCard/PromoCard.story.tsx +3 -3
  127. package/src/promoCard/PromoCardGroup.tsx +39 -21
  128. package/src/segmentedControl/SegmentedControl.test.tsx +25 -0
  129. package/src/segmentedControl/SegmentedControl.tsx +7 -1
  130. package/src/select/Select.story.tsx +1 -1
  131. package/src/tabs/Tabs.tsx +1 -1
  132. package/src/tooltip/Tooltip.tsx +3 -0
  133. package/src/uploadInput/UploadInput.test.tsx +19 -0
  134. package/src/uploadInput/UploadInput.tsx +28 -24
@@ -86,10 +86,9 @@ const AvatarWrapper = ({
86
86
  avatarProps,
87
87
  badgeProps
88
88
  }) => {
89
- const [hasImageLoadError, setImageLoadError] = React.useState(false);
89
+ const [errorUrl, setErrorUrl] = React.useState(undefined);
90
+ const hasImageLoadError = errorUrl === url;
90
91
  const isBusinessProfile = profileType$1 === profileType.ProfileType.BUSINESS;
91
- // Reset the errored state when url changes
92
- React.useEffect(() => setImageLoadError(false), [url]);
93
92
  const getAvatarProps = () => {
94
93
  let updatedAvatarProps = avatarProps;
95
94
  if (!badgeUrl && !badgeStatusIcon && ariaLabel) {
@@ -104,7 +103,7 @@ const AvatarWrapper = ({
104
103
  children: /*#__PURE__*/jsxRuntime.jsx("img", {
105
104
  src: url,
106
105
  alt: "",
107
- onError: () => setImageLoadError(true)
106
+ onError: () => setErrorUrl(url)
108
107
  }),
109
108
  ...updatedAvatarProps
110
109
  };
@@ -1 +1 @@
1
- {"version":3,"file":"AvatarWrapper.js","sources":["../../src/avatarWrapper/AvatarWrapper.tsx"],"sourcesContent":["import { Person, Briefcase as BriefcaseIcon } from '@transferwise/icons';\nimport { useState, useEffect } from 'react';\n\nimport Avatar, { AvatarProps, AvatarType } from '../avatar';\nimport Badge, { BadgeProps } from '../badge';\nimport {\n ProfileType,\n ProfileTypePersonal,\n ProfileTypeBusiness,\n Size,\n Sentiment,\n getInitials,\n Status,\n} from '../common';\nimport StatusIcon from '../statusIcon/StatusIcon';\n\ninterface OptionalBadgeProps extends Omit<BadgeProps, 'badge'> {\n url?: string;\n ariaLabel?: string;\n altText?: string;\n statusIcon?: Sentiment | Status.PENDING;\n}\n\nconst OptionalBadge = ({\n url,\n altText,\n statusIcon,\n children,\n ariaLabel,\n ...rest\n}: OptionalBadgeProps) => {\n if (url) {\n return (\n <Badge aria-label={ariaLabel} badge={<img src={url} alt={altText} />} {...rest}>\n {children}\n </Badge>\n );\n }\n if (statusIcon) {\n return (\n <Badge\n aria-label={ariaLabel}\n badge={<StatusIcon sentiment={statusIcon} size={Size.SMALL} />}\n {...rest}\n >\n {children}\n </Badge>\n );\n }\n return <>{children}</>;\n};\n\nexport type AvatarWrapperProps = {\n url?: string;\n 'aria-label'?: string;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n profileId?: string;\n name?: string;\n avatarProps?: AvatarProps;\n badgeProps?: BadgeProps;\n} & (\n | {\n badgeUrl: string;\n badgeAltText: string;\n badgeStatusIcon?: never;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon: Sentiment | Status.PENDING;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon?: never;\n }\n);\n\n/**\n * @deprecated Use `AvatarView` component instead\n */\nconst AvatarWrapper = ({\n url,\n 'aria-label': ariaLabel,\n profileType,\n profileId,\n badgeUrl,\n badgeAltText,\n badgeStatusIcon,\n name,\n avatarProps,\n badgeProps,\n}: AvatarWrapperProps) => {\n const [hasImageLoadError, setImageLoadError] = useState(false);\n const isBusinessProfile = profileType === ProfileType.BUSINESS;\n\n // Reset the errored state when url changes\n useEffect(() => setImageLoadError(false), [url]);\n\n const getAvatarProps = () => {\n let updatedAvatarProps = avatarProps;\n if (!badgeUrl && !badgeStatusIcon && ariaLabel) {\n updatedAvatarProps = { ...updatedAvatarProps, 'aria-label': ariaLabel };\n }\n if (url && !hasImageLoadError) {\n return {\n type: AvatarType.THUMBNAIL,\n children: <img src={url} alt=\"\" onError={() => setImageLoadError(true)} />,\n ...updatedAvatarProps,\n };\n }\n if (profileType) {\n return {\n type: AvatarType.ICON,\n children: isBusinessProfile ? <BriefcaseIcon size=\"24\" /> : <Person size=\"24\" />,\n ...updatedAvatarProps,\n };\n }\n if (name) {\n return {\n type: AvatarType.INITIALS,\n children: <>{getInitials(name)}</>,\n backgroundColorSeed: profileId?.toString(),\n ...updatedAvatarProps,\n };\n }\n return {\n type: AvatarType.ICON,\n children: <Person size=\"24\" />,\n ...updatedAvatarProps,\n };\n };\n\n return (\n <OptionalBadge\n url={badgeUrl}\n ariaLabel={ariaLabel}\n altText={badgeAltText}\n statusIcon={badgeStatusIcon}\n {...badgeProps}\n >\n <Avatar size={Size.MEDIUM} {...getAvatarProps()} />\n </OptionalBadge>\n );\n};\n\nexport default AvatarWrapper;\n"],"names":["OptionalBadge","url","altText","statusIcon","children","ariaLabel","rest","_jsx","Badge","badge","src","alt","StatusIcon","sentiment","size","Size","SMALL","_Fragment","AvatarWrapper","profileType","profileId","badgeUrl","badgeAltText","badgeStatusIcon","name","avatarProps","badgeProps","hasImageLoadError","setImageLoadError","useState","isBusinessProfile","ProfileType","BUSINESS","useEffect","getAvatarProps","updatedAvatarProps","type","AvatarType","THUMBNAIL","onError","ICON","BriefcaseIcon","Person","INITIALS","getInitials","backgroundColorSeed","toString","Avatar","MEDIUM"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAMA,aAAa,GAAGA,CAAC;EACrBC,GA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AQ,eAAEG,cAAA,CAACmC,YAAM,EAAA;AAAC5B,QAAAA,IAAI,EAAC;AAAI,OAAA,CAAG;MAC9B,GAAGqB;KACJ;EACH,CAAC;EAED,oBACE5B,cAAA,CAACP,aAAa,EAAA;AACZC,IAAAA,GAAG,EAAEoB,QAAS;AACdhB,IAAAA,SAAS,EAAEA,SAAU;AACrBH,IAAAA,OAAO,EAAEoB,YAAa;AACtBnB,IAAAA,UAAU,EAAEoB,eAAgB;AAAA,IAAA,GACxBG,UAAU;IAAAtB,QAAA,eAEdG,cAAA,CAACwC,cAAM,EAAA;MAACjC,IAAI,EAAEC,SAAI,CAACiC,MAAO;AAAA,MAAA,GAAKd,cAAc;KAAG;AAClD,GAAe,CAAC;AAEpB;;;;"}
1
+ {"version":3,"file":"AvatarWrapper.js","sources":["../../src/avatarWrapper/AvatarWrapper.tsx"],"sourcesContent":["import { Person, Briefcase as BriefcaseIcon } from '@transferwise/icons';\nimport { useState } from 'react';\n\nimport Avatar, { AvatarProps, AvatarType } from '../avatar';\nimport Badge, { BadgeProps } from '../badge';\nimport {\n ProfileType,\n ProfileTypePersonal,\n ProfileTypeBusiness,\n Size,\n Sentiment,\n getInitials,\n Status,\n} from '../common';\nimport StatusIcon from '../statusIcon/StatusIcon';\n\ninterface OptionalBadgeProps extends Omit<BadgeProps, 'badge'> {\n url?: string;\n ariaLabel?: string;\n altText?: string;\n statusIcon?: Sentiment | Status.PENDING;\n}\n\nconst OptionalBadge = ({\n url,\n altText,\n statusIcon,\n children,\n ariaLabel,\n ...rest\n}: OptionalBadgeProps) => {\n if (url) {\n return (\n <Badge aria-label={ariaLabel} badge={<img src={url} alt={altText} />} {...rest}>\n {children}\n </Badge>\n );\n }\n if (statusIcon) {\n return (\n <Badge\n aria-label={ariaLabel}\n badge={<StatusIcon sentiment={statusIcon} size={Size.SMALL} />}\n {...rest}\n >\n {children}\n </Badge>\n );\n }\n return <>{children}</>;\n};\n\nexport type AvatarWrapperProps = {\n url?: string;\n 'aria-label'?: string;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n profileId?: string;\n name?: string;\n avatarProps?: AvatarProps;\n badgeProps?: BadgeProps;\n} & (\n | {\n badgeUrl: string;\n badgeAltText: string;\n badgeStatusIcon?: never;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon: Sentiment | Status.PENDING;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon?: never;\n }\n);\n\n/**\n * @deprecated Use `AvatarView` component instead\n */\nconst AvatarWrapper = ({\n url,\n 'aria-label': ariaLabel,\n profileType,\n profileId,\n badgeUrl,\n badgeAltText,\n badgeStatusIcon,\n name,\n avatarProps,\n badgeProps,\n}: AvatarWrapperProps) => {\n const [errorUrl, setErrorUrl] = useState<string | undefined>(undefined);\n\n const hasImageLoadError = errorUrl === url;\n const isBusinessProfile = profileType === ProfileType.BUSINESS;\n\n const getAvatarProps = () => {\n let updatedAvatarProps = avatarProps;\n if (!badgeUrl && !badgeStatusIcon && ariaLabel) {\n updatedAvatarProps = { ...updatedAvatarProps, 'aria-label': ariaLabel };\n }\n if (url && !hasImageLoadError) {\n return {\n type: AvatarType.THUMBNAIL,\n children: <img src={url} alt=\"\" onError={() => setErrorUrl(url)} />,\n ...updatedAvatarProps,\n };\n }\n if (profileType) {\n return {\n type: AvatarType.ICON,\n children: isBusinessProfile ? <BriefcaseIcon size=\"24\" /> : <Person size=\"24\" />,\n ...updatedAvatarProps,\n };\n }\n if (name) {\n return {\n type: AvatarType.INITIALS,\n children: <>{getInitials(name)}</>,\n backgroundColorSeed: profileId?.toString(),\n ...updatedAvatarProps,\n };\n }\n return {\n type: AvatarType.ICON,\n children: <Person size=\"24\" />,\n ...updatedAvatarProps,\n };\n };\n\n return (\n <OptionalBadge\n url={badgeUrl}\n ariaLabel={ariaLabel}\n altText={badgeAltText}\n statusIcon={badgeStatusIcon}\n {...badgeProps}\n >\n <Avatar size={Size.MEDIUM} {...getAvatarProps()} />\n </OptionalBadge>\n );\n};\n\nexport default AvatarWrapper;\n"],"names":["OptionalBadge","url","altText","statusIcon","children","ariaLabel","rest","_jsx","Badge","badge","src","alt","StatusIcon","sentiment","size","Size","SMALL","_Fragment","AvatarWrapper","profileType","profileId","badgeUrl","badgeAltText","badgeStatusIcon","name","avatarProps","badgeProps","errorUrl","setErrorUrl","useState","undefined","hasImageLoadError","isBusinessProfile","ProfileType","BUSINESS","getAvatarProps","updatedAvatarProps","type","AvatarType","THUMBNAIL","onError","ICON","BriefcaseIcon","Person","INITIALS","getInitials","backgroundColorSeed","toString","Avatar","MEDIUM"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAMA,aAAa,GAAGA,CAAC;EACrBC,GAAG;EACHC,OAAO;EACPC,UAAU;EACVC,QAAQ;EACRC,SAAS;EACT,GAAGC;AAAI,CACY,KAAI;AACvB,EAAA,IAAIL,GAAG,EAAE;IACP,oBACEM,cAAA,CAACC,aAAK,EAAA;AAAC,MAAA,YAAA,EAAYH,SAAU;AAACI,MAAAA,KAAK,eAAEF,cAAA,CAAA,KAAA,EAAA;AAAKG,QAAAA,GAAG,EAAET,GAAI;AAACU,QAAAA,GAAG,EAAET;AAAQ,QAAI;AAAA,MAAA,GAAKI,IAAI;AAAAF,MAAAA,QAAA,EAC3EA;AAAQ,KACJ,CAAC;AAEZ,EAAA;AACA,EAAA,IAAID,UAAU,EAAE;IACd,oBACEI,cAAA,CAACC,aAAK,EAAA;AACJ,MAAA,YAAA,EAAYH,SAAU;MACtBI,KAAK,eAAEF,cAAA,CAACK,kBAAU,EAAA;AAACC,QAAAA,SAAS,EAAEV,UAAW;QAACW,IAAI,EAAEC,SAAI,CAACC;AAAM,QAAI;AAAA,MAAA,GAC3DV,IAAI;AAAAF,MAAAA,QAAA,EAEPA;AAAQ,KACJ,CAAC;AAEZ,EAAA;EACA,oBAAOG,cAAA,CAAAU,mBAAA,EAAA;AAAAb,IAAAA,QAAA,EAAGA;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A,CAACoC,YAAM,EAAA;AAAC7B,UAAAA,IAAI,EAAC;AAAI,SAAA,CAAG;QAChF,GAAGsB;OACJ;AACH,IAAA;AACA,IAAA,IAAIZ,IAAI,EAAE;MACR,OAAO;QACLa,IAAI,EAAEC,sBAAU,CAACM,QAAQ;QACzBxC,QAAQ,eAAEG,cAAA,CAAAU,mBAAA,EAAA;UAAAb,QAAA,EAAGyC,oBAAW,CAACrB,IAAI;AAAC,SAAC,CAAG;AAClCsB,QAAAA,mBAAmB,EAAE1B,SAAS,EAAE2B,QAAQ,EAAE;QAC1C,GAAGX;OACJ;AACH,IAAA;IACA,OAAO;MACLC,IAAI,EAAEC,sBAAU,CAACG,IAAI;MACrBrC,QAAQ,eAAEG,cAAA,CAACoC,YAAM,EAAA;AAAC7B,QAAAA,IAAI,EAAC;AAAI,OAAA,CAAG;MAC9B,GAAGsB;KACJ;EACH,CAAC;EAED,oBACE7B,cAAA,CAACP,aAAa,EAAA;AACZC,IAAAA,GAAG,EAAEoB,QAAS;AACdhB,IAAAA,SAAS,EAAEA,SAAU;AACrBH,IAAAA,OAAO,EAAEoB,YAAa;AACtBnB,IAAAA,UAAU,EAAEoB,eAAgB;AAAA,IAAA,GACxBG,UAAU;IAAAtB,QAAA,eAEdG,cAAA,CAACyC,cAAM,EAAA;MAAClC,IAAI,EAAEC,SAAI,CAACkC,MAAO;AAAA,MAAA,GAAKd,cAAc;KAAG;AAClD,GAAe,CAAC;AAEpB;;;;"}
@@ -1,5 +1,5 @@
1
1
  import { Briefcase, Person } from '@transferwise/icons';
2
- import { useState, useEffect } from 'react';
2
+ import { useState } from 'react';
3
3
  import { AvatarType } from '../avatar/avatarTypes.mjs';
4
4
  import Avatar from '../avatar/Avatar.mjs';
5
5
  import Badge from '../badge/Badge.mjs';
@@ -82,10 +82,9 @@ const AvatarWrapper = ({
82
82
  avatarProps,
83
83
  badgeProps
84
84
  }) => {
85
- const [hasImageLoadError, setImageLoadError] = useState(false);
85
+ const [errorUrl, setErrorUrl] = useState(undefined);
86
+ const hasImageLoadError = errorUrl === url;
86
87
  const isBusinessProfile = profileType === ProfileType.BUSINESS;
87
- // Reset the errored state when url changes
88
- useEffect(() => setImageLoadError(false), [url]);
89
88
  const getAvatarProps = () => {
90
89
  let updatedAvatarProps = avatarProps;
91
90
  if (!badgeUrl && !badgeStatusIcon && ariaLabel) {
@@ -100,7 +99,7 @@ const AvatarWrapper = ({
100
99
  children: /*#__PURE__*/jsx("img", {
101
100
  src: url,
102
101
  alt: "",
103
- onError: () => setImageLoadError(true)
102
+ onError: () => setErrorUrl(url)
104
103
  }),
105
104
  ...updatedAvatarProps
106
105
  };
@@ -1 +1 @@
1
- {"version":3,"file":"AvatarWrapper.mjs","sources":["../../src/avatarWrapper/AvatarWrapper.tsx"],"sourcesContent":["import { Person, Briefcase as BriefcaseIcon } from '@transferwise/icons';\nimport { useState, useEffect } from 'react';\n\nimport Avatar, { AvatarProps, AvatarType } from '../avatar';\nimport Badge, { BadgeProps } from '../badge';\nimport {\n ProfileType,\n ProfileTypePersonal,\n ProfileTypeBusiness,\n Size,\n Sentiment,\n getInitials,\n Status,\n} from '../common';\nimport StatusIcon from '../statusIcon/StatusIcon';\n\ninterface OptionalBadgeProps extends Omit<BadgeProps, 'badge'> {\n url?: string;\n ariaLabel?: string;\n altText?: string;\n statusIcon?: Sentiment | Status.PENDING;\n}\n\nconst OptionalBadge = ({\n url,\n altText,\n statusIcon,\n children,\n ariaLabel,\n ...rest\n}: OptionalBadgeProps) => {\n if (url) {\n return (\n <Badge aria-label={ariaLabel} badge={<img src={url} alt={altText} />} {...rest}>\n {children}\n </Badge>\n );\n }\n if (statusIcon) {\n return (\n <Badge\n aria-label={ariaLabel}\n badge={<StatusIcon sentiment={statusIcon} size={Size.SMALL} />}\n {...rest}\n >\n {children}\n </Badge>\n );\n }\n return <>{children}</>;\n};\n\nexport type AvatarWrapperProps = {\n url?: string;\n 'aria-label'?: string;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n profileId?: string;\n name?: string;\n avatarProps?: AvatarProps;\n badgeProps?: BadgeProps;\n} & (\n | {\n badgeUrl: string;\n badgeAltText: string;\n badgeStatusIcon?: never;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon: Sentiment | Status.PENDING;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon?: never;\n }\n);\n\n/**\n * @deprecated Use `AvatarView` component instead\n */\nconst AvatarWrapper = ({\n url,\n 'aria-label': ariaLabel,\n profileType,\n profileId,\n badgeUrl,\n badgeAltText,\n badgeStatusIcon,\n name,\n avatarProps,\n badgeProps,\n}: AvatarWrapperProps) => {\n const [hasImageLoadError, setImageLoadError] = useState(false);\n const isBusinessProfile = profileType === ProfileType.BUSINESS;\n\n // Reset the errored state when url changes\n useEffect(() => setImageLoadError(false), [url]);\n\n const getAvatarProps = () => {\n let updatedAvatarProps = avatarProps;\n if (!badgeUrl && !badgeStatusIcon && ariaLabel) {\n updatedAvatarProps = { ...updatedAvatarProps, 'aria-label': ariaLabel };\n }\n if (url && !hasImageLoadError) {\n return {\n type: AvatarType.THUMBNAIL,\n children: <img src={url} alt=\"\" onError={() => setImageLoadError(true)} />,\n ...updatedAvatarProps,\n };\n }\n if (profileType) {\n return {\n type: AvatarType.ICON,\n children: isBusinessProfile ? <BriefcaseIcon size=\"24\" /> : <Person size=\"24\" />,\n ...updatedAvatarProps,\n };\n }\n if (name) {\n return {\n type: AvatarType.INITIALS,\n children: <>{getInitials(name)}</>,\n backgroundColorSeed: profileId?.toString(),\n ...updatedAvatarProps,\n };\n }\n return {\n type: AvatarType.ICON,\n children: <Person size=\"24\" />,\n ...updatedAvatarProps,\n };\n };\n\n return (\n <OptionalBadge\n url={badgeUrl}\n ariaLabel={ariaLabel}\n altText={badgeAltText}\n statusIcon={badgeStatusIcon}\n {...badgeProps}\n >\n <Avatar size={Size.MEDIUM} {...getAvatarProps()} />\n </OptionalBadge>\n );\n};\n\nexport default AvatarWrapper;\n"],"names":["OptionalBadge","url","altText","statusIcon","children","ariaLabel","rest","_jsx","Badge","badge","src","alt","StatusIcon","sentiment","size","Size","SMALL","_Fragment","AvatarWrapper","profileType","profileId","badgeUrl","badgeAltText","badgeStatusIcon","name","avatarProps","badgeProps","hasImageLoadError","setImageLoadError","useState","isBusinessProfile","ProfileType","BUSINESS","useEffect","getAvatarProps","updatedAvatarProps","type","AvatarType","THUMBNAIL","onError","ICON","BriefcaseIcon","Person","INITIALS","getInitials","backgroundColorSeed","toString","Avatar","MEDIUM"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAMA,aAAa,GAAGA,CAAC;EACrBC,GAAG;EACHC,OAAO;EACPC,UAAU;EACVC,QAAQ;EACRC,SAAS;EACT,GAAGC;AAAI,CACY,KAAI;AACvB,EAAA,IAAIL,GAAG,EAAE;IACP,oBACEM,GAAA,CAACC,KAAK,EAAA;AAAC,MAAA,YAAA,EAAYH,SAAU;AAACI,MAAAA,KAAK,eAAEF,GAAA,CAAA,KAAA,EAAA;AAAKG,QAAAA,GAAG,EAAET,GAAI;AAACU,QAAAA,GAAG,EAAET;AAAQ,QAAI;AAAA,MAAA,GAAKI,IAAI;AAAAF,MAAAA,QAAA,EAC3EA;AAAQ,KACJ,CAAC;AAEZ,EAAA;AACA,EAAA,IAAID,UAAU,EAAE;IACd,oBACEI,GAAA,CAACC,KAAK,EAAA;AACJ,MAAA,YAAA,EAAYH,SAAU;MACtBI,KAAK,eAAEF,GAAA,CAACK,UAAU,EAAA;AAACC,QAAAA,SAAS,EAAEV,UAAW;QAACW,IAAI,EAAEC,IAAI,CAACC;AAAM,QAAI;AAAA,MAAA,GAC3DV,IAAI;AAAAF,MAAAA,QAAA,EAEPA;AAAQ,KACJ,CAAC;AAEZ,EAAA;EACA,oBAAOG,GAAA,CAAAU,QAAA,EAAA;AAAAb,IAAAA,QAAA,EAAGA;AAAQ,IAAI;AACxB,CAAC;AA4BD;;AAEG;AACH,MA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A;AAAC5B,UAAAA,IAAI,EAAC;AAAI,SAAA,CAAG;QAChF,GAAGqB;OACJ;AACH,IAAA;AACA,IAAA,IAAIX,IAAI,EAAE;MACR,OAAO;QACLY,IAAI,EAAEC,UAAU,CAACM,QAAQ;QACzBvC,QAAQ,eAAEG,GAAA,CAAAU,QAAA,EAAA;UAAAb,QAAA,EAAGwC,WAAW,CAACpB,IAAI;AAAC,SAAC,CAAG;AAClCqB,QAAAA,mBAAmB,EAAEzB,SAAS,EAAE0B,QAAQ,EAAE;QAC1C,GAAGX;OACJ;AACH,IAAA;IACA,OAAO;MACLC,IAAI,EAAEC,UAAU,CAACG,IAAI;MACrBpC,QAAQ,eAAEG,GAAA,CAACmC,MAAM,EAAA;AAAC5B,QAAAA,IAAI,EAAC;AAAI,OAAA,CAAG;MAC9B,GAAGqB;KACJ;EACH,CAAC;EAED,oBACE5B,GAAA,CAACP,aAAa,EAAA;AACZC,IAAAA,GAAG,EAAEoB,QAAS;AACdhB,IAAAA,SAAS,EAAEA,SAAU;AACrBH,IAAAA,OAAO,EAAEoB,YAAa;AACtBnB,IAAAA,UAAU,EAAEoB,eAAgB;AAAA,IAAA,GACxBG,UAAU;IAAAtB,QAAA,eAEdG,GAAA,CAACwC,MAAM,EAAA;MAACjC,IAAI,EAAEC,IAAI,CAACiC,MAAO;AAAA,MAAA,GAAKd,cAAc;KAAG;AAClD,GAAe,CAAC;AAEpB;;;;"}
1
+ {"version":3,"file":"AvatarWrapper.mjs","sources":["../../src/avatarWrapper/AvatarWrapper.tsx"],"sourcesContent":["import { Person, Briefcase as BriefcaseIcon } from '@transferwise/icons';\nimport { useState } from 'react';\n\nimport Avatar, { AvatarProps, AvatarType } from '../avatar';\nimport Badge, { BadgeProps } from '../badge';\nimport {\n ProfileType,\n ProfileTypePersonal,\n ProfileTypeBusiness,\n Size,\n Sentiment,\n getInitials,\n Status,\n} from '../common';\nimport StatusIcon from '../statusIcon/StatusIcon';\n\ninterface OptionalBadgeProps extends Omit<BadgeProps, 'badge'> {\n url?: string;\n ariaLabel?: string;\n altText?: string;\n statusIcon?: Sentiment | Status.PENDING;\n}\n\nconst OptionalBadge = ({\n url,\n altText,\n statusIcon,\n children,\n ariaLabel,\n ...rest\n}: OptionalBadgeProps) => {\n if (url) {\n return (\n <Badge aria-label={ariaLabel} badge={<img src={url} alt={altText} />} {...rest}>\n {children}\n </Badge>\n );\n }\n if (statusIcon) {\n return (\n <Badge\n aria-label={ariaLabel}\n badge={<StatusIcon sentiment={statusIcon} size={Size.SMALL} />}\n {...rest}\n >\n {children}\n </Badge>\n );\n }\n return <>{children}</>;\n};\n\nexport type AvatarWrapperProps = {\n url?: string;\n 'aria-label'?: string;\n profileType?: ProfileTypeBusiness | ProfileTypePersonal;\n profileId?: string;\n name?: string;\n avatarProps?: AvatarProps;\n badgeProps?: BadgeProps;\n} & (\n | {\n badgeUrl: string;\n badgeAltText: string;\n badgeStatusIcon?: never;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon: Sentiment | Status.PENDING;\n }\n | {\n badgeUrl?: never;\n badgeAltText?: never;\n badgeStatusIcon?: never;\n }\n);\n\n/**\n * @deprecated Use `AvatarView` component instead\n */\nconst AvatarWrapper = ({\n url,\n 'aria-label': ariaLabel,\n profileType,\n profileId,\n badgeUrl,\n badgeAltText,\n badgeStatusIcon,\n name,\n avatarProps,\n badgeProps,\n}: AvatarWrapperProps) => {\n const [errorUrl, setErrorUrl] = useState<string | undefined>(undefined);\n\n const hasImageLoadError = errorUrl === url;\n const isBusinessProfile = profileType === ProfileType.BUSINESS;\n\n const getAvatarProps = () => {\n let updatedAvatarProps = avatarProps;\n if (!badgeUrl && !badgeStatusIcon && ariaLabel) {\n updatedAvatarProps = { ...updatedAvatarProps, 'aria-label': ariaLabel };\n }\n if (url && !hasImageLoadError) {\n return {\n type: AvatarType.THUMBNAIL,\n children: <img src={url} alt=\"\" onError={() => setErrorUrl(url)} />,\n ...updatedAvatarProps,\n };\n }\n if (profileType) {\n return {\n type: AvatarType.ICON,\n children: isBusinessProfile ? <BriefcaseIcon size=\"24\" /> : <Person size=\"24\" />,\n ...updatedAvatarProps,\n };\n }\n if (name) {\n return {\n type: AvatarType.INITIALS,\n children: <>{getInitials(name)}</>,\n backgroundColorSeed: profileId?.toString(),\n ...updatedAvatarProps,\n };\n }\n return {\n type: AvatarType.ICON,\n children: <Person size=\"24\" />,\n ...updatedAvatarProps,\n };\n };\n\n return (\n <OptionalBadge\n url={badgeUrl}\n ariaLabel={ariaLabel}\n altText={badgeAltText}\n statusIcon={badgeStatusIcon}\n {...badgeProps}\n >\n <Avatar size={Size.MEDIUM} {...getAvatarProps()} />\n </OptionalBadge>\n );\n};\n\nexport default AvatarWrapper;\n"],"names":["OptionalBadge","url","altText","statusIcon","children","ariaLabel","rest","_jsx","Badge","badge","src","alt","StatusIcon","sentiment","size","Size","SMALL","_Fragment","AvatarWrapper","profileType","profileId","badgeUrl","badgeAltText","badgeStatusIcon","name","avatarProps","badgeProps","errorUrl","setErrorUrl","useState","undefined","hasImageLoadError","isBusinessProfile","ProfileType","BUSINESS","getAvatarProps","updatedAvatarProps","type","AvatarType","THUMBNAIL","onError","ICON","BriefcaseIcon","Person","INITIALS","getInitials","backgroundColorSeed","toString","Avatar","MEDIUM"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBA,MAAMA,aAAa,GAAGA,CAAC;EACrBC,GAAG;EACHC,OAAO;EACPC,UAAU;EACVC,QAAQ;EACRC,SAAS;EACT,GAAGC;AAAI,CACY,KAAI;AACvB,EAAA,IAAIL,GAAG,EAAE;IACP,oBACEM,GAAA,CAACC,KAAK,EAAA;AAAC,MAAA,YAAA,EAAYH,SAAU;AAACI,MAAAA,KAAK,eAAEF,GAAA,CAAA,KAAA,EAAA;AAAKG,QAAAA,GAAG,EAAET,GAAI;AAACU,QAAAA,GAAG,EAAET;AAAQ,QAAI;AAAA,MAAA,GAAKI,IAAI;AAAAF,MAAAA,QAAA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AI,CAACkC,MAAO;AAAA,MAAA,GAAKd,cAAc;KAAG;AAClD,GAAe,CAAC;AAEpB;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"LegacyButton.js","sources":["../../src/button/LegacyButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { ElementType, forwardRef, MouseEvent } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport {\n Size,\n ControlType,\n Priority,\n ControlTypeAccent,\n ControlTypeNegative,\n ControlTypePositive,\n PriorityPrimary,\n PrioritySecondary,\n PriorityTertiary,\n SizeExtraSmall,\n SizeSmall,\n SizeMedium,\n SizeLarge,\n} from '../common';\nimport ProcessIndicator from '../processIndicator';\n\nimport messages from '../i18n/commonMessages/Button.messages';\nimport { typeClassMap, priorityClassMap } from './classMap';\nimport { establishNewPriority, establishNewType, logDeprecationNotices } from './legacyUtils';\nimport { ButtonReferenceType } from './Button.types';\n\n/** @deprecated */\ntype DeprecatedTypes = 'primary' | 'pay' | 'secondary' | 'danger' | 'link';\n\n/** @deprecated */\ntype DeprecatedSizes = SizeExtraSmall;\n\n/**\n * @deprecated Use new button instead of these APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type CommonProps = {\n v2?: false;\n\n /** Makes the button take up the full width of its container */\n block?: boolean;\n\n /**\n * The `target` attribute for HTML anchor.\n * If set to `_blank`, `rel=\"noopener noreferrer\"` is automatically added to the rendered node.\n */\n target?: string;\n /**\n * Toggles the disabled state\n * @default false\n */\n\n disabled?: boolean;\n /**\n * Toggles the loading state\n * @default false\n */\n loading?: boolean;\n type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes | null;\n priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary | null;\n size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;\n htmlType?: 'submit' | 'reset' | 'button';\n};\n\n/**\n * @deprecated Use new button instead of APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type ButtonProps = CommonProps &\n Omit<React.ComponentPropsWithRef<'button'>, 'type'> & {\n as?: 'button';\n };\n\ntype AnchorProps = CommonProps &\n Omit<React.ComponentPropsWithRef<'a'>, 'type'> & {\n as?: 'a';\n };\n\n/**\n * @deprecated Use new button instead of APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type LegacyButtonProps = ButtonProps | AnchorProps;\n\n/**\n * @deprecated Use new Button component via `<Button v2 .. />` and new props.\n */\nconst LegacyButton = forwardRef<ButtonReferenceType, LegacyButtonProps>(\n (\n {\n as: component = 'button',\n block = false,\n children,\n className,\n disabled,\n loading = false,\n priority = Priority.PRIMARY,\n size = Size.MEDIUM,\n type = ControlType.ACCENT,\n onClick,\n ...rest\n }: LegacyButtonProps,\n ref,\n ) => {\n const intl = useIntl();\n\n logDeprecationNotices({ size, type });\n\n const newType = establishNewType(type);\n const newPriority = establishNewPriority(priority, type);\n\n const classes = clsx(\n `btn btn-${size}`,\n `np-btn np-btn-${size}`,\n {\n 'btn-loading': loading,\n 'btn-block np-btn-block': block,\n disabled,\n },\n // @ts-expect-error fix when refactor `typeClassMap` to TypeScript\n typeClassMap[newType],\n // @ts-expect-error fix when refactor `typeClassMap` to TypeScript\n priorityClassMap[newPriority],\n className,\n );\n\n function processIndicatorSize() {\n return ['sm', 'xs'].includes(size) ? 'xxs' : 'xs';\n }\n\n const Element = (component as ElementType) ?? 'button';\n let props;\n\n if (Element === 'button') {\n const { htmlType = 'button', ...restProps } = rest as ButtonProps;\n props = {\n ...restProps,\n disabled,\n 'aria-disabled': loading,\n type: htmlType,\n };\n } else {\n props = {\n ...rest,\n 'aria-disabled': loading,\n } as AnchorProps;\n }\n\n /**\n * Ensures that the button cannot be activated in loading or disabled mode,\n * when `aria-disabled` might be used over the `disabled` HTML attribute\n */\n const handleClick =\n (handler: LegacyButtonProps['onClick']) =>\n (event: MouseEvent<HTMLButtonElement> & MouseEvent<HTMLAnchorElement>) => {\n if (disabled || loading) {\n event.preventDefault();\n } else if (typeof handler === 'function') {\n handler(event);\n }\n };\n\n return (\n <Element\n ref={ref as React.Ref<ButtonReferenceType>}\n className={classes}\n onClick={handleClick(onClick)}\n {...props}\n aria-live={loading ? 'polite' : 'off'}\n aria-busy={loading}\n aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}\n >\n {children}\n {loading && (\n <ProcessIndicator\n size={processIndicatorSize()}\n className=\"btn-loader\"\n data-testid=\"ButtonProgressIndicator\"\n />\n )}\n </Element>\n );\n },\n);\n\nexport default LegacyButton;\n"],"names":["LegacyButton","forwardRef","as","component","block","children","className","disabled","loading","priority","Priority","PRIMARY","size","Size","MEDIUM","type","ControlType","ACCENT","onClick","rest","ref","intl","useIntl","logDeprecationNotices","newType","establishNewType","newPriority","establishNewPriority","classes","clsx","typeClassMap","priorityClassMap","processIndicatorSize","includes","Element","props","htmlType","restProps","handleClick","handler","event","preventDefault","_jsxs","formatMessage","messages","loadingAriaLabel","_jsx","ProcessIndicator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,MAAMA,YAAY,gBAAGC,gBAAU,CAC7B,CACE;EACEC,EAAE,EAAEC,SAAS,GAAG,QAAQ;AACxBC,EAAAA,KAAK,GAAG,KAAK;EACbC,QAAQ;EACRC,SAAS;EACTC,QAAQ;AACRC,EAAAA,OAAO,GAAG,KAAK;EACfC,QAAQ,GAAGC,gBAAQ,CAACC,OAAO;QAC3BC,MAAI,GAAGC,SAAI,CAACC,MAAM;EAClBC,IAAI,GAAGC,mBAAW,CAACC,MAAM;EACzBC,OAAO;EACP,GAAGC;AAAI,CACW,EACpBC,GAAG,KACD;AACF,EAAA,MAAMC,IAAI,GAAGC,iBAAO,EAAE;AAEtBC,EAAAA,iCAAqB,CAAC;UAAEX,MAAI;AAAEG,IAAAA;AAAI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,IAAI,OAAOF,OAAO,KAAK,UAAU,EAAE;MACxCA,OAAO,CAACC,KAAK,CAAC;AAChB,IAAA;EACF,CAAC;EAEH,oBACEE,eAAA,CAACR,OAAO,EAAA;AACNd,IAAAA,GAAG,EAAEA,GAAsC;AAC3Cd,IAAAA,SAAS,EAAEsB,OAAQ;AACnBV,IAAAA,OAAO,EAAEoB,WAAW,CAACpB,OAAO,CAAE;AAAA,IAAA,GAC1BiB,KAAK;AACT,IAAA,WAAA,EAAW3B,OAAO,GAAG,QAAQ,GAAG,KAAM;AACtC,IAAA,WAAA,EAAWA,OAAQ;AACnB,IAAA,YAAA,EAAYA,OAAO,GAAGa,IAAI,CAACsB,aAAa,CAACC,uBAAQ,CAACC,gBAAgB,CAAC,GAAG1B,IAAI,CAAC,YAAY,CAAE;AAAAd,IAAAA,QAAA,GAExFA,QAAQ,EACRG,OAAO,iBACNsC,cAAA,CAACC,wBAAgB,EAAA;MACfnC,IAAI,EAAEoB,oBAAoB,EAAG;AAC7B1B,MAAAA,SAAS,EAAC,YAAY;MACtB,aAAA,EAAY;AAAyB,KAAA,CAExC;AAAA,GACM,CAAC;AAEd,CAAC;;;;"}
1
+ {"version":3,"file":"LegacyButton.js","sources":["../../src/button/LegacyButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { ElementType, forwardRef, MouseEvent } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport {\n Size,\n ControlType,\n Priority,\n ControlTypeAccent,\n ControlTypeNegative,\n ControlTypePositive,\n PriorityPrimary,\n PrioritySecondary,\n PriorityTertiary,\n SizeExtraSmall,\n SizeSmall,\n SizeMedium,\n SizeLarge,\n} from '../common';\nimport ProcessIndicator from '../processIndicator';\n\nimport messages from '../i18n/commonMessages/Button.messages';\nimport { typeClassMap, priorityClassMap } from './classMap';\nimport { establishNewPriority, establishNewType, logDeprecationNotices } from './legacyUtils';\nimport { ButtonReferenceType } from './Button.types';\n\n/** @deprecated */\ntype DeprecatedTypes = 'primary' | 'pay' | 'secondary' | 'danger' | 'link';\n\n/** @deprecated */\ntype DeprecatedSizes = SizeExtraSmall;\n\n/**\n * @deprecated Use new button instead of these APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type CommonProps = {\n v2?: false;\n\n /** Makes the button take up the full width of its container */\n block?: boolean;\n\n /**\n * The `target` attribute for HTML anchor.\n * If set to `_blank`, `rel=\"noopener noreferrer\"` is automatically added to the rendered node.\n */\n target?: string;\n /**\n * Toggles the disabled state\n * @default false\n */\n\n disabled?: boolean;\n /**\n * Toggles the loading state\n * @default false\n */\n loading?: boolean;\n type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes | null;\n priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary | null;\n size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;\n htmlType?: 'submit' | 'reset' | 'button';\n};\n\n/**\n * @deprecated Use new button instead of APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type ButtonProps = CommonProps &\n Omit<React.ComponentPropsWithRef<'button'>, 'type'> & {\n as?: 'button';\n };\n\ntype AnchorProps = CommonProps &\n Omit<React.ComponentPropsWithRef<'a'>, 'type'> & {\n as?: 'a';\n };\n\n/**\n * @deprecated Use new button instead of APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type LegacyButtonProps = ButtonProps | AnchorProps;\n\n/**\n * @deprecated Use new Button component via `<Button v2 .. />` and new props.\n */\nconst LegacyButton = forwardRef<ButtonReferenceType, LegacyButtonProps>(\n (\n {\n as: component = 'button',\n block = false,\n children,\n className,\n disabled,\n loading = false,\n priority = Priority.PRIMARY,\n size = Size.MEDIUM,\n type = ControlType.ACCENT,\n onClick,\n ...rest\n }: LegacyButtonProps,\n ref,\n ) => {\n const intl = useIntl();\n\n logDeprecationNotices({ size, type });\n\n const newType = establishNewType(type);\n const newPriority = establishNewPriority(priority, type);\n\n const classes = clsx(\n `btn btn-${size}`,\n `np-btn np-btn-${size}`,\n {\n 'btn-loading': loading,\n 'btn-block np-btn-block': block,\n disabled,\n },\n // @ts-expect-error fix when refactor `typeClassMap` to TypeScript\n typeClassMap[newType],\n // @ts-expect-error fix when refactor `typeClassMap` to TypeScript\n priorityClassMap[newPriority],\n className,\n );\n\n function processIndicatorSize() {\n return ['sm', 'xs'].includes(size) ? 'xxs' : 'xs';\n }\n\n const Element = (component as ElementType) ?? 'button';\n let props;\n\n if (Element === 'button') {\n const { htmlType = 'button', ...restProps } = rest as ButtonProps;\n props = {\n ...restProps,\n disabled,\n 'aria-disabled': loading,\n type: htmlType,\n };\n } else {\n props = {\n ...rest,\n 'aria-disabled': loading,\n } as AnchorProps;\n }\n\n /**\n * Ensures that the button cannot be activated in loading or disabled mode,\n * when `aria-disabled` might be used over the `disabled` HTML attribute\n */\n const handleClick =\n (handler: LegacyButtonProps['onClick']) =>\n (event: MouseEvent<HTMLButtonElement> & MouseEvent<HTMLAnchorElement>) => {\n if (disabled || loading) {\n event.preventDefault();\n } else if (typeof handler === 'function') {\n handler(event);\n }\n };\n\n return (\n <Element\n ref={ref}\n className={classes}\n onClick={handleClick(onClick)}\n {...props}\n aria-live={loading ? 'polite' : 'off'}\n aria-busy={loading}\n aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}\n >\n {children}\n {loading && (\n <ProcessIndicator\n size={processIndicatorSize()}\n className=\"btn-loader\"\n data-testid=\"ButtonProgressIndicator\"\n />\n )}\n </Element>\n );\n },\n);\n\nexport default LegacyButton;\n"],"names":["LegacyButton","forwardRef","as","component","block","children","className","disabled","loading","priority","Priority","PRIMARY","size","Size","MEDIUM","type","ControlType","ACCENT","onClick","rest","ref","intl","useIntl","logDeprecationNotices","newType","establishNewType","newPriority","establishNewPriority","classes","clsx","typeClassMap","priorityClassMap","processIndicatorSize","includes","Element","props","htmlType","restProps","handleClick","handler","event","preventDefault","_jsxs","formatMessage","messages","loadingAriaLabel","_jsx","ProcessIndicator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,MAAMA,YAAY,gBAAGC,gBAAU,CAC7B,CACE;EACEC,EAAE,EAAEC,SAAS,GAAG,QAAQ;AACxBC,EAAAA,KAAK,GAAG,KAAK;EACbC,QAAQ;EACRC,SAAS;EACTC,QAAQ;AACRC,EAAAA,OAAO,GAAG,KAAK;EACfC,QAAQ,GAAGC,gBAAQ,CAACC,OAAO;QAC3BC,MAAI,GAAGC,SAAI,CAACC,MAAM;EAClBC,IAAI,GAAGC,mBAAW,CAACC,MAAM;EACzBC,OAAO;EACP,GAAGC;AAAI,CACW,EACpBC,GAAG,KACD;AACF,EAAA,MAAMC,IAAI,GAAGC,iBAAO,EAAE;AAEtBC,EAAAA,iCAAqB,CAAC;UAAEX,MAAI;AAAEG,IAAAA;AAAI,GAAE,CAAC;AAErC,EAAA,MAAMS,OAAO,GAAGC,4BAAgB,CAACV,IAAI,CAAC;AACtC,EAAA,MAAMW,WAAW,GAAGC,gCAAoB,CAAClB,QAAQ,EAAEM,IAAI,CAAC;EAExD,MAAMa,OAAO,GAAGC,SAAI,CAClB,CAAA,QAAA,EAAWjB,MAAI,CAAA,CAAE,EACjB,CAAA,cAAA,EAAiBA,MAAI,CAAA,CAAE,EACvB;AACE,IAAA,aAAa,EAAEJ,OAAO;AACtB,IAAA,wBAAwB,EAAEJ,KAAK;AAC/BG,IAAAA;GACD;AACD;EACAuB,qBAAY,CAACN,OAAO,CAAC;AACrB;AACAO,EAAAA,yBAAgB,CAACL,WAAW,CAAC,EAC7BpB,SAAS,CACV;EAED,SAAS0B,oBAAoBA,GAAA;AAC3B,IAAA,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAACC,QAAQ,CAACrB,MAAI,CAAC,GAAG,KAAK,GAAG,IAAI;AACnD,EAAA;AAEA,EAAA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AAAA,SAAS,EAAC,YAAY;MACtB,aAAA,EAAY;AAAyB,KAAA,CAExC;AAAA,GACM,CAAC;AAEd,CAAC;;;;"}
@@ -1 +1 @@
1
- {"version":3,"file":"LegacyButton.mjs","sources":["../../src/button/LegacyButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { ElementType, forwardRef, MouseEvent } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport {\n Size,\n ControlType,\n Priority,\n ControlTypeAccent,\n ControlTypeNegative,\n ControlTypePositive,\n PriorityPrimary,\n PrioritySecondary,\n PriorityTertiary,\n SizeExtraSmall,\n SizeSmall,\n SizeMedium,\n SizeLarge,\n} from '../common';\nimport ProcessIndicator from '../processIndicator';\n\nimport messages from '../i18n/commonMessages/Button.messages';\nimport { typeClassMap, priorityClassMap } from './classMap';\nimport { establishNewPriority, establishNewType, logDeprecationNotices } from './legacyUtils';\nimport { ButtonReferenceType } from './Button.types';\n\n/** @deprecated */\ntype DeprecatedTypes = 'primary' | 'pay' | 'secondary' | 'danger' | 'link';\n\n/** @deprecated */\ntype DeprecatedSizes = SizeExtraSmall;\n\n/**\n * @deprecated Use new button instead of these APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type CommonProps = {\n v2?: false;\n\n /** Makes the button take up the full width of its container */\n block?: boolean;\n\n /**\n * The `target` attribute for HTML anchor.\n * If set to `_blank`, `rel=\"noopener noreferrer\"` is automatically added to the rendered node.\n */\n target?: string;\n /**\n * Toggles the disabled state\n * @default false\n */\n\n disabled?: boolean;\n /**\n * Toggles the loading state\n * @default false\n */\n loading?: boolean;\n type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes | null;\n priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary | null;\n size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;\n htmlType?: 'submit' | 'reset' | 'button';\n};\n\n/**\n * @deprecated Use new button instead of APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type ButtonProps = CommonProps &\n Omit<React.ComponentPropsWithRef<'button'>, 'type'> & {\n as?: 'button';\n };\n\ntype AnchorProps = CommonProps &\n Omit<React.ComponentPropsWithRef<'a'>, 'type'> & {\n as?: 'a';\n };\n\n/**\n * @deprecated Use new button instead of APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type LegacyButtonProps = ButtonProps | AnchorProps;\n\n/**\n * @deprecated Use new Button component via `<Button v2 .. />` and new props.\n */\nconst LegacyButton = forwardRef<ButtonReferenceType, LegacyButtonProps>(\n (\n {\n as: component = 'button',\n block = false,\n children,\n className,\n disabled,\n loading = false,\n priority = Priority.PRIMARY,\n size = Size.MEDIUM,\n type = ControlType.ACCENT,\n onClick,\n ...rest\n }: LegacyButtonProps,\n ref,\n ) => {\n const intl = useIntl();\n\n logDeprecationNotices({ size, type });\n\n const newType = establishNewType(type);\n const newPriority = establishNewPriority(priority, type);\n\n const classes = clsx(\n `btn btn-${size}`,\n `np-btn np-btn-${size}`,\n {\n 'btn-loading': loading,\n 'btn-block np-btn-block': block,\n disabled,\n },\n // @ts-expect-error fix when refactor `typeClassMap` to TypeScript\n typeClassMap[newType],\n // @ts-expect-error fix when refactor `typeClassMap` to TypeScript\n priorityClassMap[newPriority],\n className,\n );\n\n function processIndicatorSize() {\n return ['sm', 'xs'].includes(size) ? 'xxs' : 'xs';\n }\n\n const Element = (component as ElementType) ?? 'button';\n let props;\n\n if (Element === 'button') {\n const { htmlType = 'button', ...restProps } = rest as ButtonProps;\n props = {\n ...restProps,\n disabled,\n 'aria-disabled': loading,\n type: htmlType,\n };\n } else {\n props = {\n ...rest,\n 'aria-disabled': loading,\n } as AnchorProps;\n }\n\n /**\n * Ensures that the button cannot be activated in loading or disabled mode,\n * when `aria-disabled` might be used over the `disabled` HTML attribute\n */\n const handleClick =\n (handler: LegacyButtonProps['onClick']) =>\n (event: MouseEvent<HTMLButtonElement> & MouseEvent<HTMLAnchorElement>) => {\n if (disabled || loading) {\n event.preventDefault();\n } else if (typeof handler === 'function') {\n handler(event);\n }\n };\n\n return (\n <Element\n ref={ref as React.Ref<ButtonReferenceType>}\n className={classes}\n onClick={handleClick(onClick)}\n {...props}\n aria-live={loading ? 'polite' : 'off'}\n aria-busy={loading}\n aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}\n >\n {children}\n {loading && (\n <ProcessIndicator\n size={processIndicatorSize()}\n className=\"btn-loader\"\n data-testid=\"ButtonProgressIndicator\"\n />\n )}\n </Element>\n );\n },\n);\n\nexport default LegacyButton;\n"],"names":["LegacyButton","forwardRef","as","component","block","children","className","disabled","loading","priority","Priority","PRIMARY","size","Size","MEDIUM","type","ControlType","ACCENT","onClick","rest","ref","intl","useIntl","logDeprecationNotices","newType","establishNewType","newPriority","establishNewPriority","classes","clsx","typeClassMap","priorityClassMap","processIndicatorSize","includes","Element","props","htmlType","restProps","handleClick","handler","event","preventDefault","_jsxs","formatMessage","messages","loadingAriaLabel","_jsx","ProcessIndicator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,MAAMA,YAAY,gBAAGC,UAAU,CAC7B,CACE;EACEC,EAAE,EAAEC,SAAS,GAAG,QAAQ;AACxBC,EAAAA,KAAK,GAAG,KAAK;EACbC,QAAQ;EACRC,SAAS;EACTC,QAAQ;AACRC,EAAAA,OAAO,GAAG,KAAK;EACfC,QAAQ,GAAGC,QAAQ,CAACC,OAAO;EAC3BC,IAAI,GAAGC,IAAI,CAACC,MAAM;EAClBC,IAAI,GAAGC,WAAW,CAACC,MAAM;EACzBC,OAAO;EACP,GAAGC;AAAI,CACW,EACpBC,GAAG,KACD;AACF,EAAA,MAAMC,IAAI,GAAGC,OAAO,EAAE;AAEtBC,EAAAA,qBAAqB,CAAC;IAAEX,IAAI;AAAEG,IA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AC,MAAM,IAAI,OAAOF,OAAO,KAAK,UAAU,EAAE;MACxCA,OAAO,CAACC,KAAK,CAAC;AAChB,IAAA;EACF,CAAC;EAEH,oBACEE,IAAA,CAACR,OAAO,EAAA;AACNd,IAAAA,GAAG,EAAEA,GAAsC;AAC3Cd,IAAAA,SAAS,EAAEsB,OAAQ;AACnBV,IAAAA,OAAO,EAAEoB,WAAW,CAACpB,OAAO,CAAE;AAAA,IAAA,GAC1BiB,KAAK;AACT,IAAA,WAAA,EAAW3B,OAAO,GAAG,QAAQ,GAAG,KAAM;AACtC,IAAA,WAAA,EAAWA,OAAQ;AACnB,IAAA,YAAA,EAAYA,OAAO,GAAGa,IAAI,CAACsB,aAAa,CAACC,QAAQ,CAACC,gBAAgB,CAAC,GAAG1B,IAAI,CAAC,YAAY,CAAE;AAAAd,IAAAA,QAAA,GAExFA,QAAQ,EACRG,OAAO,iBACNsC,GAAA,CAACC,gBAAgB,EAAA;MACfnC,IAAI,EAAEoB,oBAAoB,EAAG;AAC7B1B,MAAAA,SAAS,EAAC,YAAY;MACtB,aAAA,EAAY;AAAyB,KAAA,CAExC;AAAA,GACM,CAAC;AAEd,CAAC;;;;"}
1
+ {"version":3,"file":"LegacyButton.mjs","sources":["../../src/button/LegacyButton.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport { ElementType, forwardRef, MouseEvent } from 'react';\nimport { useIntl } from 'react-intl';\n\nimport {\n Size,\n ControlType,\n Priority,\n ControlTypeAccent,\n ControlTypeNegative,\n ControlTypePositive,\n PriorityPrimary,\n PrioritySecondary,\n PriorityTertiary,\n SizeExtraSmall,\n SizeSmall,\n SizeMedium,\n SizeLarge,\n} from '../common';\nimport ProcessIndicator from '../processIndicator';\n\nimport messages from '../i18n/commonMessages/Button.messages';\nimport { typeClassMap, priorityClassMap } from './classMap';\nimport { establishNewPriority, establishNewType, logDeprecationNotices } from './legacyUtils';\nimport { ButtonReferenceType } from './Button.types';\n\n/** @deprecated */\ntype DeprecatedTypes = 'primary' | 'pay' | 'secondary' | 'danger' | 'link';\n\n/** @deprecated */\ntype DeprecatedSizes = SizeExtraSmall;\n\n/**\n * @deprecated Use new button instead of these APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type CommonProps = {\n v2?: false;\n\n /** Makes the button take up the full width of its container */\n block?: boolean;\n\n /**\n * The `target` attribute for HTML anchor.\n * If set to `_blank`, `rel=\"noopener noreferrer\"` is automatically added to the rendered node.\n */\n target?: string;\n /**\n * Toggles the disabled state\n * @default false\n */\n\n disabled?: boolean;\n /**\n * Toggles the loading state\n * @default false\n */\n loading?: boolean;\n type?: ControlTypeAccent | ControlTypeNegative | ControlTypePositive | DeprecatedTypes | null;\n priority?: PriorityPrimary | PrioritySecondary | PriorityTertiary | null;\n size?: SizeSmall | SizeMedium | SizeLarge | DeprecatedSizes;\n htmlType?: 'submit' | 'reset' | 'button';\n};\n\n/**\n * @deprecated Use new button instead of APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type ButtonProps = CommonProps &\n Omit<React.ComponentPropsWithRef<'button'>, 'type'> & {\n as?: 'button';\n };\n\ntype AnchorProps = CommonProps &\n Omit<React.ComponentPropsWithRef<'a'>, 'type'> & {\n as?: 'a';\n };\n\n/**\n * @deprecated Use new button instead of APIs.\n * @example\n * ```\n * import { Button, ButtonProps } from '@transferwise/components';\n *\n * <Button v2>...</Button>\n * ```\n */\nexport type LegacyButtonProps = ButtonProps | AnchorProps;\n\n/**\n * @deprecated Use new Button component via `<Button v2 .. />` and new props.\n */\nconst LegacyButton = forwardRef<ButtonReferenceType, LegacyButtonProps>(\n (\n {\n as: component = 'button',\n block = false,\n children,\n className,\n disabled,\n loading = false,\n priority = Priority.PRIMARY,\n size = Size.MEDIUM,\n type = ControlType.ACCENT,\n onClick,\n ...rest\n }: LegacyButtonProps,\n ref,\n ) => {\n const intl = useIntl();\n\n logDeprecationNotices({ size, type });\n\n const newType = establishNewType(type);\n const newPriority = establishNewPriority(priority, type);\n\n const classes = clsx(\n `btn btn-${size}`,\n `np-btn np-btn-${size}`,\n {\n 'btn-loading': loading,\n 'btn-block np-btn-block': block,\n disabled,\n },\n // @ts-expect-error fix when refactor `typeClassMap` to TypeScript\n typeClassMap[newType],\n // @ts-expect-error fix when refactor `typeClassMap` to TypeScript\n priorityClassMap[newPriority],\n className,\n );\n\n function processIndicatorSize() {\n return ['sm', 'xs'].includes(size) ? 'xxs' : 'xs';\n }\n\n const Element = (component as ElementType) ?? 'button';\n let props;\n\n if (Element === 'button') {\n const { htmlType = 'button', ...restProps } = rest as ButtonProps;\n props = {\n ...restProps,\n disabled,\n 'aria-disabled': loading,\n type: htmlType,\n };\n } else {\n props = {\n ...rest,\n 'aria-disabled': loading,\n } as AnchorProps;\n }\n\n /**\n * Ensures that the button cannot be activated in loading or disabled mode,\n * when `aria-disabled` might be used over the `disabled` HTML attribute\n */\n const handleClick =\n (handler: LegacyButtonProps['onClick']) =>\n (event: MouseEvent<HTMLButtonElement> & MouseEvent<HTMLAnchorElement>) => {\n if (disabled || loading) {\n event.preventDefault();\n } else if (typeof handler === 'function') {\n handler(event);\n }\n };\n\n return (\n <Element\n ref={ref}\n className={classes}\n onClick={handleClick(onClick)}\n {...props}\n aria-live={loading ? 'polite' : 'off'}\n aria-busy={loading}\n aria-label={loading ? intl.formatMessage(messages.loadingAriaLabel) : rest['aria-label']}\n >\n {children}\n {loading && (\n <ProcessIndicator\n size={processIndicatorSize()}\n className=\"btn-loader\"\n data-testid=\"ButtonProgressIndicator\"\n />\n )}\n </Element>\n );\n },\n);\n\nexport default LegacyButton;\n"],"names":["LegacyButton","forwardRef","as","component","block","children","className","disabled","loading","priority","Priority","PRIMARY","size","Size","MEDIUM","type","ControlType","ACCENT","onClick","rest","ref","intl","useIntl","logDeprecationNotices","newType","establishNewType","newPriority","establishNewPriority","classes","clsx","typeClassMap","priorityClassMap","processIndicatorSize","includes","Element","props","htmlType","restProps","handleClick","handler","event","preventDefault","_jsxs","formatMessage","messages","loadingAriaLabel","_jsx","ProcessIndicator"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsGA,MAAMA,YAAY,gBAAGC,UAAU,CAC7B,CACE;EACEC,EAAE,EAAEC,SAAS,GAAG,QAAQ;AACxBC,EAAAA,KAAK,GAAG,KAAK;EACbC,QAAQ;EACRC,SAAS;EACTC,QAAQ;AACRC,EAAAA,OAAO,GAAG,KAAK;EACfC,QAAQ,GAAGC,QAAQ,CAACC,OAAO;EAC3BC,IAAI,GAAGC,IAAI,CAACC,MAAM;EAClBC,IAAI,GAAGC,WAAW,CAACC,MAAM;EACzBC,OAAO;EACP,GAAGC;AAAI,CACW,EACpBC,GAAG,KACD;AACF,EAAA,MAAMC,IAAI,GAAGC,OAAO,EAAE;AAEtBC,EAAAA,qBAAqB,CAAC;IAAEX,IAAI;AAAEG,IAAAA;AAAI,GAAE,CAAC;AAErC,EAAA,MAAMS,OAAO,GAAGC,gBAAgB,CAACV,IAAI,CAAC;AACtC,EAAA,MAAMW,WAAW,GAAGC,oBAAoB,CAAClB,QAAQ,EAAEM,IAAI,CAAC;EAExD,MAAMa,OAAO,GAAGC,IAAI,CAClB,CAAA,QAAA,EAAWjB,IAAI,CAAA,CAAE,EACjB,CAAA,cAAA,EAAiBA,IAAI,CAAA,CAAE,EACvB;AACE,IAAA,aAAa,EAAEJ,OAAO;AACtB,IAAA,wBAAwB,EAAEJ,KAAK;AAC/BG,IAAAA;GACD;AACD;EACAuB,YAAY,CAACN,OAAO,CAAC;AACrB;AACAO,EAAAA,gBAAgB,CAACL,WAAW,CAAC,EAC7BpB,SAAS,CACV;EAED,SAAS0B,oBAAoBA,GAAA;AAC3B,IAAA,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,CAACC,QAAQ,CAACrB,IAAI,CAAC,GAAG,KAAK,GAAG,IAAI;AACnD,EAAA;AAEA,EAAA,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AA,SAAS,EAAC,YAAY;MACtB,aAAA,EAAY;AAAyB,KAAA,CAExC;AAAA,GACM,CAAC;AAEd,CAAC;;;;"}
@@ -20,7 +20,11 @@ const useHasIntersected = ({
20
20
  elRef,
21
21
  loading = 'eager'
22
22
  }) => {
23
- const [hasIntersected, setHasIntersected] = React.useState(false);
23
+ // Initialize as true if IntersectionObserver is not supported
24
+ // Note: We can't check elRef.current here as it may not be set yet on first render
25
+ const [hasIntersected, setHasIntersected] = React.useState(() => {
26
+ return typeof window === 'undefined' || !window.IntersectionObserver;
27
+ });
24
28
  const {
25
29
  current
26
30
  } = elRef || {};
@@ -41,9 +45,7 @@ const useHasIntersected = ({
41
45
  let observer;
42
46
  let didCancel = false;
43
47
  // Check if window is defined for SSR and Old browsers fallback
44
- if (typeof window === 'undefined' || !window.IntersectionObserver || !isValidReference()) {
45
- setHasIntersected(true);
46
- } else if (current && !didCancel) {
48
+ if (typeof window !== 'undefined' && window.IntersectionObserver && isValidReference() && current && !didCancel) {
47
49
  observer = new IntersectionObserver(handleOnIntersect, ObserverParams);
48
50
  observer.observe(current);
49
51
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useHasIntersected.js","sources":["../../../../src/common/hooks/useHasIntersected/useHasIntersected.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst ObserverParams: IntersectionObserverInit = {\n threshold: 0.1,\n};\n\n/**\n * useHasIntersected.\n * Use this custom hook to detect when an element has became visible inside the viewport. This hook checks only if the intersection happend.\n * Once the intersection has happened the hook will not return false even if the element gets out of the viewport.\n *\n * @param {object} params\n * @param {object} [params.elRef] - node object that contains a react reference to the element that needs to be observed.\n * @param {string} [params.loading = 'eager'] - string that contains the type of loading.\n * @param elRef.loading\n * @usage `const [hasIntersected] = useHasIntersected({imageRef,loading});`\n */\nexport const useHasIntersected = ({\n elRef,\n loading = 'eager',\n}: {\n elRef: React.RefObject<HTMLElement>;\n loading?: 'eager' | 'lazy';\n}) => {\n const [hasIntersected, setHasIntersected] = useState(false);\n\n const { current } = elRef || {};\n\n const isValidReference = () => {\n return elRef && current;\n };\n\n const handleOnIntersect: IntersectionObserverCallback = (entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n setHasIntersected(true);\n\n if (current) {\n observer.unobserve(current);\n }\n }\n });\n };\n\n useEffect(() => {\n let observer: IntersectionObserver | undefined;\n let didCancel = false;\n\n // Check if window is defined for SSR and Old browsers fallback\n if (typeof window === 'undefined' || !window.IntersectionObserver || !isValidReference()) {\n setHasIntersected(true);\n } else if (current && !didCancel) {\n observer = new IntersectionObserver(handleOnIntersect, ObserverParams);\n observer.observe(current);\n }\n return () => {\n didCancel = true;\n if (observer && current) {\n observer.unobserve(current);\n }\n };\n }, [elRef]);\n\n if (loading === 'eager') {\n return [false];\n }\n\n return [hasIntersected];\n};\n"],"names":["ObserverParams","threshold","useHasIntersected","elRef","loading","hasIntersected","setHasIntersected","useState","current","isValidReference","handleOnIntersect","entries","observer","forEach","entry","isIntersecting","unobserve","useEffect","didCancel","window","IntersectionObserver","observe"],"mappings":";;;;AAEA,MAAMA,cAAc,GAA6B;AAC/CC,EAAAA,SAAS,EAAE;CACZ;AAED;;;;;;;;;;AAUG;AACI,MAAMC,iBAAiB,GAAGA,CAAC;EAChCC,KAAK;AACLC,EAAAA,OAAO,GAAG;AAAO,CAIlB,KAAI;EACH,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;EAE3D,MAAM;AAAEC,IAAAA;AAAO,GAAE,GAAGL,KAAK,IAAI,EAAE;EAE/B,MAAMM,gBAAgB,GAAGA,MAAK;IAC5B,OAAON,KAAK,IAAIK,OAAO;EACzB,CAAC;AAED,EAAA,MAAME,iBAAiB,GAAiCA,CAACC,OAAO,EAAEC,QAAQ,KAAI;AAC5ED,IAAAA,OAAO,CAACE,OAAO,CAAEC,KAAK,IAAI;MACxB,IAAIA,KAAK,CAACC,cAAc,EAAE;QACxBT,iBAAiB,CAAC,IAAI,CAAC;AAEvB,QAAA,IAAIE,OAAO,EAAE;AACXI,UAAAA,QAAQ,CAACI,SAAS,CAACR,OAAO,CAAC;AAC7B,QAAA;AACF,MAAA;AACF,IAAA,CAAC,CAAC;EACJ,CAAC;AAEDS,EAAAA,eAAS,CAAC,MAAK;AACb,IAAA,IAAIL,QAA0C;IAC9C,IAAIM,SAAS,GAAG,KAAK;AAErB;AACA,IAAA,IAAI,OAAOC,MAAM,KAAK,WAAW,IAAI,CAACA,MAAM,CAACC,oBAAoB,IAAI,CAACX,gBAAgB,EAAE,EAAE;MACxFH,iBAAiB,CAAC,IAAI,CAAC;AACzB,IAAA,CAAC,MAAM,IAAIE,OAAO,IAAI,CAACU,SAAS,EAAE;AAChCN,MAAAA,QAAQ,GAAG,IAAIQ,oBAAoB,CAACV,iBAAiB,EAAEV,cAAc,CAAC;AACtEY,MAAAA,QAAQ,CAACS,OAAO,CAACb,OAAO,CAAC;AAC3B,IAAA;AACA,IAAA,OAAO,MAAK;AACVU,MAAAA,SAAS,GAAG,IAAI;MAChB,IAAIN,QAAQ,IAAIJ,OAAO,EAAE;AACvBI,QAAAA,QAAQ,CAACI,SAAS,CAACR,OAAO,CAAC;AAC7B,MAAA;IACF,CAAC;AACH,EAAA,CAAC,EAAE,CAACL,KAAK,CAAC,CAAC;EAEX,IAAIC,OAAO,KAAK,OAAO,EAAE;IACvB,OAAO,CAAC,KAAK,CAAC;AAChB,EAAA;EAEA,OAAO,CAACC,cAAc,CAAC;AACzB;;;;"}
1
+ {"version":3,"file":"useHasIntersected.js","sources":["../../../../src/common/hooks/useHasIntersected/useHasIntersected.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst ObserverParams: IntersectionObserverInit = {\n threshold: 0.1,\n};\n\n/**\n * useHasIntersected.\n * Use this custom hook to detect when an element has became visible inside the viewport. This hook checks only if the intersection happend.\n * Once the intersection has happened the hook will not return false even if the element gets out of the viewport.\n *\n * @param {object} params\n * @param {object} [params.elRef] - node object that contains a react reference to the element that needs to be observed.\n * @param {string} [params.loading = 'eager'] - string that contains the type of loading.\n * @param elRef.loading\n * @usage `const [hasIntersected] = useHasIntersected({imageRef,loading});`\n */\nexport const useHasIntersected = ({\n elRef,\n loading = 'eager',\n}: {\n elRef: React.RefObject<HTMLElement>;\n loading?: 'eager' | 'lazy';\n}) => {\n // Initialize as true if IntersectionObserver is not supported\n // Note: We can't check elRef.current here as it may not be set yet on first render\n const [hasIntersected, setHasIntersected] = useState(() => {\n return typeof window === 'undefined' || !window.IntersectionObserver;\n });\n\n const { current } = elRef || {};\n\n const isValidReference = () => {\n return elRef && current;\n };\n\n const handleOnIntersect: IntersectionObserverCallback = (entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n setHasIntersected(true);\n\n if (current) {\n observer.unobserve(current);\n }\n }\n });\n };\n\n useEffect(() => {\n let observer: IntersectionObserver | undefined;\n let didCancel = false;\n\n // Check if window is defined for SSR and Old browsers fallback\n if (\n typeof window !== 'undefined' &&\n window.IntersectionObserver &&\n isValidReference() &&\n current &&\n !didCancel\n ) {\n observer = new IntersectionObserver(handleOnIntersect, ObserverParams);\n observer.observe(current);\n }\n return () => {\n didCancel = true;\n if (observer && current) {\n observer.unobserve(current);\n }\n };\n }, [elRef]);\n\n if (loading === 'eager') {\n return [false];\n }\n\n return [hasIntersected];\n};\n"],"names":["ObserverParams","threshold","useHasIntersected","elRef","loading","hasIntersected","setHasIntersected","useState","window","IntersectionObserver","current","isValidReference","handleOnIntersect","entries","observer","forEach","entry","isIntersecting","unobserve","useEffect","didCancel","observe"],"mappings":";;;;AAEA,MAAMA,cAAc,GAA6B;AAC/CC,EAAAA,SAAS,EAAE;CACZ;AAED;;;;;;;;;;AAUG;AACI,MAAMC,iBAAiB,GAAGA,CAAC;EAChCC,KAAK;AACLC,EAAAA,OAAO,GAAG;AAAO,CAIlB,KAAI;AACH;AACA;EACA,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGC,cAA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,CAAC;AAChB,EAAA;EAEA,OAAO,CAACC,cAAc,CAAC;AACzB;;;;"}
@@ -18,7 +18,11 @@ const useHasIntersected = ({
18
18
  elRef,
19
19
  loading = 'eager'
20
20
  }) => {
21
- const [hasIntersected, setHasIntersected] = useState(false);
21
+ // Initialize as true if IntersectionObserver is not supported
22
+ // Note: We can't check elRef.current here as it may not be set yet on first render
23
+ const [hasIntersected, setHasIntersected] = useState(() => {
24
+ return typeof window === 'undefined' || !window.IntersectionObserver;
25
+ });
22
26
  const {
23
27
  current
24
28
  } = elRef || {};
@@ -39,9 +43,7 @@ const useHasIntersected = ({
39
43
  let observer;
40
44
  let didCancel = false;
41
45
  // Check if window is defined for SSR and Old browsers fallback
42
- if (typeof window === 'undefined' || !window.IntersectionObserver || !isValidReference()) {
43
- setHasIntersected(true);
44
- } else if (current && !didCancel) {
46
+ if (typeof window !== 'undefined' && window.IntersectionObserver && isValidReference() && current && !didCancel) {
45
47
  observer = new IntersectionObserver(handleOnIntersect, ObserverParams);
46
48
  observer.observe(current);
47
49
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useHasIntersected.mjs","sources":["../../../../src/common/hooks/useHasIntersected/useHasIntersected.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst ObserverParams: IntersectionObserverInit = {\n threshold: 0.1,\n};\n\n/**\n * useHasIntersected.\n * Use this custom hook to detect when an element has became visible inside the viewport. This hook checks only if the intersection happend.\n * Once the intersection has happened the hook will not return false even if the element gets out of the viewport.\n *\n * @param {object} params\n * @param {object} [params.elRef] - node object that contains a react reference to the element that needs to be observed.\n * @param {string} [params.loading = 'eager'] - string that contains the type of loading.\n * @param elRef.loading\n * @usage `const [hasIntersected] = useHasIntersected({imageRef,loading});`\n */\nexport const useHasIntersected = ({\n elRef,\n loading = 'eager',\n}: {\n elRef: React.RefObject<HTMLElement>;\n loading?: 'eager' | 'lazy';\n}) => {\n const [hasIntersected, setHasIntersected] = useState(false);\n\n const { current } = elRef || {};\n\n const isValidReference = () => {\n return elRef && current;\n };\n\n const handleOnIntersect: IntersectionObserverCallback = (entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n setHasIntersected(true);\n\n if (current) {\n observer.unobserve(current);\n }\n }\n });\n };\n\n useEffect(() => {\n let observer: IntersectionObserver | undefined;\n let didCancel = false;\n\n // Check if window is defined for SSR and Old browsers fallback\n if (typeof window === 'undefined' || !window.IntersectionObserver || !isValidReference()) {\n setHasIntersected(true);\n } else if (current && !didCancel) {\n observer = new IntersectionObserver(handleOnIntersect, ObserverParams);\n observer.observe(current);\n }\n return () => {\n didCancel = true;\n if (observer && current) {\n observer.unobserve(current);\n }\n };\n }, [elRef]);\n\n if (loading === 'eager') {\n return [false];\n }\n\n return [hasIntersected];\n};\n"],"names":["ObserverParams","threshold","useHasIntersected","elRef","loading","hasIntersected","setHasIntersected","useState","current","isValidReference","handleOnIntersect","entries","observer","forEach","entry","isIntersecting","unobserve","useEffect","didCancel","window","IntersectionObserver","observe"],"mappings":";;AAEA,MAAMA,cAAc,GAA6B;AAC/CC,EAAAA,SAAS,EAAE;CACZ;AAED;;;;;;;;;;AAUG;AACI,MAAMC,iBAAiB,GAAGA,CAAC;EAChCC,KAAK;AACLC,EAAAA,OAAO,GAAG;AAAO,CAIlB,KAAI;EACH,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGC,QAAQ,CAAC,KAAK,CAAC;EAE3D,MAAM;AAAEC,IAAAA;AAAO,GAAE,GAAGL,KAAK,IAAI,EAAE;EAE/B,MAAMM,gBAAgB,GAAGA,MAAK;IAC5B,OAAON,KAAK,IAAIK,OAAO;EACzB,CAAC;AAED,EAAA,MAAME,iBAAiB,GAAiCA,CAACC,OAAO,EAAEC,QAAQ,KAAI;AAC5ED,IAAAA,OAAO,CAACE,OAAO,CAAEC,KAAK,IAAI;MACxB,IAAIA,KAAK,CAACC,cAAc,EAAE;QACxBT,iBAAiB,CAAC,IAAI,CAAC;AAEvB,QAAA,IAAIE,OAAO,EAAE;AACXI,UAAAA,QAAQ,CAACI,SAAS,CAACR,OAAO,CAAC;AAC7B,QAAA;AACF,MAAA;AACF,IAAA,CAAC,CAAC;EACJ,CAAC;AAEDS,EAAAA,SAAS,CAAC,MAAK;AACb,IAAA,IAAIL,QAA0C;IAC9C,IAAIM,SAAS,GAAG,KAAK;AAErB;AACA,IAAA,IAAI,OAAOC,MAAM,KAAK,WAAW,IAAI,CAACA,MAAM,CAACC,oBAAoB,IAAI,CAACX,gBAAgB,EAAE,EAAE;MACxFH,iBAAiB,CAAC,IAAI,CAAC;AACzB,IAAA,CAAC,MAAM,IAAIE,OAAO,IAAI,CAACU,SAAS,EAAE;AAChCN,MAAAA,QAAQ,GAAG,IAAIQ,oBAAoB,CAACV,iBAAiB,EAAEV,cAAc,CAAC;AACtEY,MAAAA,QAAQ,CAACS,OAAO,CAACb,OAAO,CAAC;AAC3B,IAAA;AACA,IAAA,OAAO,MAAK;AACVU,MAAAA,SAAS,GAAG,IAAI;MAChB,IAAIN,QAAQ,IAAIJ,OAAO,EAAE;AACvBI,QAAAA,QAAQ,CAACI,SAAS,CAACR,OAAO,CAAC;AAC7B,MAAA;IACF,CAAC;AACH,EAAA,CAAC,EAAE,CAACL,KAAK,CAAC,CAAC;EAEX,IAAIC,OAAO,KAAK,OAAO,EAAE;IACvB,OAAO,CAAC,KAAK,CAAC;AAChB,EAAA;EAEA,OAAO,CAACC,cAAc,CAAC;AACzB;;;;"}
1
+ {"version":3,"file":"useHasIntersected.mjs","sources":["../../../../src/common/hooks/useHasIntersected/useHasIntersected.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\n\nconst ObserverParams: IntersectionObserverInit = {\n threshold: 0.1,\n};\n\n/**\n * useHasIntersected.\n * Use this custom hook to detect when an element has became visible inside the viewport. This hook checks only if the intersection happend.\n * Once the intersection has happened the hook will not return false even if the element gets out of the viewport.\n *\n * @param {object} params\n * @param {object} [params.elRef] - node object that contains a react reference to the element that needs to be observed.\n * @param {string} [params.loading = 'eager'] - string that contains the type of loading.\n * @param elRef.loading\n * @usage `const [hasIntersected] = useHasIntersected({imageRef,loading});`\n */\nexport const useHasIntersected = ({\n elRef,\n loading = 'eager',\n}: {\n elRef: React.RefObject<HTMLElement>;\n loading?: 'eager' | 'lazy';\n}) => {\n // Initialize as true if IntersectionObserver is not supported\n // Note: We can't check elRef.current here as it may not be set yet on first render\n const [hasIntersected, setHasIntersected] = useState(() => {\n return typeof window === 'undefined' || !window.IntersectionObserver;\n });\n\n const { current } = elRef || {};\n\n const isValidReference = () => {\n return elRef && current;\n };\n\n const handleOnIntersect: IntersectionObserverCallback = (entries, observer) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n setHasIntersected(true);\n\n if (current) {\n observer.unobserve(current);\n }\n }\n });\n };\n\n useEffect(() => {\n let observer: IntersectionObserver | undefined;\n let didCancel = false;\n\n // Check if window is defined for SSR and Old browsers fallback\n if (\n typeof window !== 'undefined' &&\n window.IntersectionObserver &&\n isValidReference() &&\n current &&\n !didCancel\n ) {\n observer = new IntersectionObserver(handleOnIntersect, ObserverParams);\n observer.observe(current);\n }\n return () => {\n didCancel = true;\n if (observer && current) {\n observer.unobserve(current);\n }\n };\n }, [elRef]);\n\n if (loading === 'eager') {\n return [false];\n }\n\n return [hasIntersected];\n};\n"],"names":["ObserverParams","threshold","useHasIntersected","elRef","loading","hasIntersected","setHasIntersected","useState","window","IntersectionObserver","current","isValidReference","handleOnIntersect","entries","observer","forEach","entry","isIntersecting","unobserve","useEffect","didCancel","observe"],"mappings":";;AAEA,MAAMA,cAAc,GAA6B;AAC/CC,EAAAA,SAAS,EAAE;CACZ;AAED;;;;;;;;;;AAUG;AACI,MAAMC,iBAAiB,GAAGA,CAAC;EAChCC,KAAK;AACLC,EAAAA,OAAO,GAAG;AAAO,CAIlB,KAAI;AACH;AACA;EACA,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGC,QAAQ,CAAC,MAAK;IACxD,OAAO,OAAOC,MA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cAAc,CAAC;AACzB;;;;"}
@@ -52,10 +52,13 @@ const LiveRegion = ({
52
52
  const [shouldAnnounce, setShouldAnnounce] = React.useState(false);
53
53
  const announcementTrigger = announceOnChange ?? (typeof children === 'string' || typeof children === 'number' ? children : undefined);
54
54
  React.useEffect(() => {
55
- setShouldAnnounce(false);
56
55
  if (ariaLive === 'off') {
57
56
  return;
58
57
  }
58
+ // Reset announcement state, then schedule new announcement
59
+ // This two-step process ensures screen readers re-announce the content
60
+ // eslint-disable-next-line react-hooks/set-state-in-effect -- Deliberately resetting state to force re-announcement for screen readers
61
+ setShouldAnnounce(false);
59
62
  const timeoutId = window.setTimeout(() => setShouldAnnounce(true), scheduleAnnouncement(ariaLive));
60
63
  return () => window.clearTimeout(timeoutId);
61
64
  }, [ariaLive, announcementTrigger]);
@@ -1 +1 @@
1
- {"version":3,"file":"LiveRegion.js","sources":["../../../src/common/liveRegion/LiveRegion.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport type { HTMLAttributes, ReactNode } from 'react';\n\nimport { WDS_LIVE_REGION_DELAY_MS } from '../constants';\n\nexport type AriaLive = 'off' | 'polite' | 'assertive';\n\ntype LivePoliteness = Exclude<AriaLive, 'off'>;\n\nconst LIVE_REGION_ROLE_BY_POLITENESS: Record<LivePoliteness, 'status' | 'alert'> = {\n assertive: 'alert',\n polite: 'status',\n};\n\nlet nextPoliteAnnouncementAt = 0;\nlet nextAssertiveAnnouncementAt = 0;\n\nconst getNextAnnouncementAt = (politeness: LivePoliteness): number => {\n if (politeness === 'polite') {\n return nextPoliteAnnouncementAt;\n }\n\n return nextAssertiveAnnouncementAt;\n};\n\nconst setNextAnnouncementAt = (politeness: LivePoliteness, value: number): void => {\n if (politeness === 'polite') {\n nextPoliteAnnouncementAt = value;\n return;\n }\n\n nextAssertiveAnnouncementAt = value;\n};\n\nexport const resetLiveRegionAnnouncementQueue = (): void => {\n nextPoliteAnnouncementAt = 0;\n nextAssertiveAnnouncementAt = 0;\n};\n\nconst calcAnnouncementDelayMs = (politeness: LivePoliteness, now: number): number => {\n return Math.max(now + WDS_LIVE_REGION_DELAY_MS, getNextAnnouncementAt(politeness)) - now;\n};\n\nconst scheduleAnnouncement = (politeness: LivePoliteness): number => {\n const now = Date.now();\n const delayMs = calcAnnouncementDelayMs(politeness, now);\n setNextAnnouncementAt(politeness, now + delayMs + WDS_LIVE_REGION_DELAY_MS);\n return delayMs;\n};\n\nexport interface LiveRegionProps extends Omit<\n HTMLAttributes<HTMLDivElement>,\n 'role' | 'aria-live' | 'aria-atomic'\n> {\n /**\n * Determines urgency: 'assertive' interrupts, 'polite' waits for idle, 'off' disables live region.\n */\n 'aria-live': AriaLive;\n /** Optional stable key that triggers a new announcement when it changes. */\n announceOnChange?: string | number;\n /** Test ID for testing tools */\n 'data-testid'?: string;\n children?: ReactNode;\n}\n\n/**\n * Renders an ARIA live region with the correct implicit role.\n *\n * - `aria-live=\"polite\"` → `role=\"status\"`\n * - `aria-live=\"assertive\"` → `role=\"alert\"`\n * - `aria-live=\"off\"` → no live region (renders children unwrapped)\n *\n * The `role` prop is intentionally excluded from the public API\n * to prevent mismatches between `aria-live` and `role`.\n */\nexport const LiveRegion = ({\n 'aria-live': ariaLive,\n announceOnChange,\n children,\n className,\n ...props\n}: LiveRegionProps) => {\n const [shouldAnnounce, setShouldAnnounce] = useState(false);\n const announcementTrigger =\n announceOnChange ??\n (typeof children === 'string' || typeof children === 'number' ? children : undefined);\n\n useEffect(() => {\n setShouldAnnounce(false);\n\n if (ariaLive === 'off') {\n return;\n }\n\n const timeoutId = window.setTimeout(\n () => setShouldAnnounce(true),\n scheduleAnnouncement(ariaLive),\n );\n\n return () => window.clearTimeout(timeoutId);\n }, [ariaLive, announcementTrigger]);\n\n if (ariaLive === 'off') {\n return <>{children}</>;\n }\n\n return (\n <div\n role={LIVE_REGION_ROLE_BY_POLITENESS[ariaLive]}\n aria-live={ariaLive}\n aria-atomic=\"true\"\n className={`wds-LiveRegion ${className ?? ''}`}\n {...props}\n >\n <div aria-hidden={shouldAnnounce ? undefined : 'true'}>{children}</div>\n </div>\n );\n};\n"],"names":["LIVE_REGION_ROLE_BY_POLITENESS","assertive","polite","nextPoliteAnnouncementAt","nextAssertiveAnnouncementAt","getNextAnnouncementAt","politeness","setNextAnnouncementAt","value","calcAnnouncementDelayMs","now","Math","max","WDS_LIVE_REGION_DELAY_MS","scheduleAnnouncement","Date","delayMs","LiveRegion","ariaLive","announceOnChange","children","className","props","shouldAnnounce","setShouldAnnounce","useState","announcementTrigger","undefined","useEffect","timeoutId","window","setTimeout","clearTimeout","_jsx","_Fragment","role"],"mappings":";;;;;;AASA,MAAMA,8BAA8B,GAA+C;AACjFC,EAAAA,SAAS,EAAE,OAAO;AAClBC,EAAAA,MAAM,EAAE;CACT;AAED,IAAIC,wBAAwB,GAAG,CAAC;AAChC,IAAIC,2BAA2B,GAAG,CAAC;AAEnC,MAAMC,qBAAqB,GAAIC,UAA0B,IAAY;EACnE,IAAIA,UAAU,KAAK,QAAQ,EAAE;AAC3B,IAAA,OAAOH,wBAAwB;AACjC,EAAA;AAEA,EAAA,OAAOC,2BAA2B;AACpC,CAAC;AAED,MAAMG,qBAAqB,GAAGA,CAACD,UAA0B,EAAEE,KAAa,KAAU;EAChF,IAAIF,UAAU,KAAK,QAAQ,EAAE;AAC3BH,IAAAA,wBAAwB,GAAGK,KAAK;AAChC,IAAA;AACF,EAAA;AAEAJ,EAAAA,2BAA2B,GAAGI,KAAK;AACrC,CAAC;AAOD,MAAMC,uBAAuB,GAAGA,CAACH,UAA0B,EAAEI,GAAW,KAAY;AAClF,EAAA,OAAOC,IAAI,CAACC,GAAG,CAACF,GAAG,GAAGG,kCAAwB,EAAER,qBAAqB,CAACC,UAAU,CAAC,CAAC,GAAGI,GAAG;AAC1F,CAAC;AAED,MAAMI,oBAAoB,GAAIR,UAA0B,IAAY;AAClE,EAAA,MAAMI,GAAG,GAAGK,IAAI,CAACL,GAAG,EAAE;AACtB,EAAA,MAAMM,OAA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ClBG,IAAAA,SAAS,EAAE,CAAA,eAAA,EAAkBA,SAAS,IAAI,EAAE,CAAA,CAAG;AAAA,IAAA,GAC3CC,KAAK;AAAAF,IAAAA,QAAA,eAETa,cAAA,CAAA,KAAA,EAAA;AAAK,MAAA,aAAA,EAAaV,cAAc,GAAGI,SAAS,GAAG,MAAO;AAAAP,MAAAA,QAAA,EAAEA;KAAc;AACxE,GAAK,CAAC;AAEV;;;;"}
1
+ {"version":3,"file":"LiveRegion.js","sources":["../../../src/common/liveRegion/LiveRegion.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport type { HTMLAttributes, ReactNode } from 'react';\n\nimport { WDS_LIVE_REGION_DELAY_MS } from '../constants';\n\nexport type AriaLive = 'off' | 'polite' | 'assertive';\n\ntype LivePoliteness = Exclude<AriaLive, 'off'>;\n\nconst LIVE_REGION_ROLE_BY_POLITENESS: Record<LivePoliteness, 'status' | 'alert'> = {\n assertive: 'alert',\n polite: 'status',\n};\n\nlet nextPoliteAnnouncementAt = 0;\nlet nextAssertiveAnnouncementAt = 0;\n\nconst getNextAnnouncementAt = (politeness: LivePoliteness): number => {\n if (politeness === 'polite') {\n return nextPoliteAnnouncementAt;\n }\n\n return nextAssertiveAnnouncementAt;\n};\n\nconst setNextAnnouncementAt = (politeness: LivePoliteness, value: number): void => {\n if (politeness === 'polite') {\n nextPoliteAnnouncementAt = value;\n return;\n }\n\n nextAssertiveAnnouncementAt = value;\n};\n\nexport const resetLiveRegionAnnouncementQueue = (): void => {\n nextPoliteAnnouncementAt = 0;\n nextAssertiveAnnouncementAt = 0;\n};\n\nconst calcAnnouncementDelayMs = (politeness: LivePoliteness, now: number): number => {\n return Math.max(now + WDS_LIVE_REGION_DELAY_MS, getNextAnnouncementAt(politeness)) - now;\n};\n\nconst scheduleAnnouncement = (politeness: LivePoliteness): number => {\n const now = Date.now();\n const delayMs = calcAnnouncementDelayMs(politeness, now);\n setNextAnnouncementAt(politeness, now + delayMs + WDS_LIVE_REGION_DELAY_MS);\n return delayMs;\n};\n\nexport interface LiveRegionProps extends Omit<\n HTMLAttributes<HTMLDivElement>,\n 'role' | 'aria-live' | 'aria-atomic'\n> {\n /**\n * Determines urgency: 'assertive' interrupts, 'polite' waits for idle, 'off' disables live region.\n */\n 'aria-live': AriaLive;\n /** Optional stable key that triggers a new announcement when it changes. */\n announceOnChange?: string | number;\n /** Test ID for testing tools */\n 'data-testid'?: string;\n children?: ReactNode;\n}\n\n/**\n * Renders an ARIA live region with the correct implicit role.\n *\n * - `aria-live=\"polite\"` → `role=\"status\"`\n * - `aria-live=\"assertive\"` → `role=\"alert\"`\n * - `aria-live=\"off\"` → no live region (renders children unwrapped)\n *\n * The `role` prop is intentionally excluded from the public API\n * to prevent mismatches between `aria-live` and `role`.\n */\nexport const LiveRegion = ({\n 'aria-live': ariaLive,\n announceOnChange,\n children,\n className,\n ...props\n}: LiveRegionProps) => {\n const [shouldAnnounce, setShouldAnnounce] = useState(false);\n const announcementTrigger =\n announceOnChange ??\n (typeof children === 'string' || typeof children === 'number' ? children : undefined);\n\n useEffect(() => {\n if (ariaLive === 'off') {\n return;\n }\n\n // Reset announcement state, then schedule new announcement\n // This two-step process ensures screen readers re-announce the content\n // eslint-disable-next-line react-hooks/set-state-in-effect -- Deliberately resetting state to force re-announcement for screen readers\n setShouldAnnounce(false);\n\n const timeoutId = window.setTimeout(\n () => setShouldAnnounce(true),\n scheduleAnnouncement(ariaLive),\n );\n\n return () => window.clearTimeout(timeoutId);\n }, [ariaLive, announcementTrigger]);\n\n if (ariaLive === 'off') {\n return <>{children}</>;\n }\n\n return (\n <div\n role={LIVE_REGION_ROLE_BY_POLITENESS[ariaLive]}\n aria-live={ariaLive}\n aria-atomic=\"true\"\n className={`wds-LiveRegion ${className ?? ''}`}\n {...props}\n >\n <div aria-hidden={shouldAnnounce ? undefined : 'true'}>{children}</div>\n </div>\n );\n};\n"],"names":["LIVE_REGION_ROLE_BY_POLITENESS","assertive","polite","nextPoliteAnnouncementAt","nextAssertiveAnnouncementAt","getNextAnnouncementAt","politeness","setNextAnnouncementAt","value","calcAnnouncementDelayMs","now","Math","max","WDS_LIVE_REGION_DELAY_MS","scheduleAnnouncement","Date","delayMs","LiveRegion","ariaLive","announceOnChange","children","className","props","shouldAnnounce","setShouldAnnounce","useState","announcementTrigger","undefined","useEffect","timeoutId","window","setTimeout","clearTimeout","_jsx","_Fragment","role"],"mappings":";;;;;;AASA,MAAMA,8BAA8B,GAA+C;AACjFC,EAAAA,SAAS,EAAE,OAAO;AAClBC,EAAAA,MAAM,EAAE;CACT;AAED,IAAIC,wBAAwB,GAAG,CAAC;AAChC,IAAIC,2BAA2B,GAAG,CAAC;AAEnC,MAAMC,qBAAqB,GAAIC,UAA0B,IAAY;EACnE,IAAIA,UAAU,KAAK,QAAQ,EAAE;AAC3B,IAAA,OAAOH,wBAAwB;AACjC,EAAA;AAEA,EAAA,OAAOC,2BAA2B;AACpC,CAAC;AAED,MAAMG,qBAAqB,GAAGA,CAACD,UAA0B,EAAEE,KAAa,KAAU;EAChF,IAAIF,UAAU,KAAK,QAAQ,EAAE;AAC3BH,IAAAA,wBAAwB,GAAGK,KAAK;AAChC,IAAA;AACF,EAAA;AAEAJ,EAAAA,2BAA2B,GAAGI,KAAK;AACrC,CAAC;AAOD,MAAMC,uBAAuB,GAAGA,CAACH,UAA0B,EAAEI,GAAW,KAAY;AAClF,EAAA,OAAOC,IAAI,CAACC,GAAG,CAACF,GAAG,GAAGG,kCAAwB,EAAER,qBAAqB,CAACC,UAAU,CAAC,CAAC,GAAGI,GAAG;AAC1F,CAAC;AAED,MAAMI,oBAAoB,GAAIR,UAA0B,IAAY;AAClE,EAAA,MAAMI,GAAG,GAAGK,IAAI,CAACL,GAAG,EAAE;AACtB,EAAA,MAAMM,OAAO,GAAGP,uBAAuB,CAACH,UAAU,EAAEI,GAAG,CAAC;EACxDH,qBAAqB,CAACD,UAAU,EAAEI,GAAG,GAAGM,OAAO,GAAGH,kCAAwB,CAAC;AAC3E,E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,eAETa,cAAA,CAAA,KAAA,EAAA;AAAK,MAAA,aAAA,EAAaV,cAAc,GAAGI,SAAS,GAAG,MAAO;AAAAP,MAAAA,QAAA,EAAEA;KAAc;AACxE,GAAK,CAAC;AAEV;;;;"}
@@ -50,10 +50,13 @@ const LiveRegion = ({
50
50
  const [shouldAnnounce, setShouldAnnounce] = useState(false);
51
51
  const announcementTrigger = announceOnChange ?? (typeof children === 'string' || typeof children === 'number' ? children : undefined);
52
52
  useEffect(() => {
53
- setShouldAnnounce(false);
54
53
  if (ariaLive === 'off') {
55
54
  return;
56
55
  }
56
+ // Reset announcement state, then schedule new announcement
57
+ // This two-step process ensures screen readers re-announce the content
58
+ // eslint-disable-next-line react-hooks/set-state-in-effect -- Deliberately resetting state to force re-announcement for screen readers
59
+ setShouldAnnounce(false);
57
60
  const timeoutId = window.setTimeout(() => setShouldAnnounce(true), scheduleAnnouncement(ariaLive));
58
61
  return () => window.clearTimeout(timeoutId);
59
62
  }, [ariaLive, announcementTrigger]);
@@ -1 +1 @@
1
- {"version":3,"file":"LiveRegion.mjs","sources":["../../../src/common/liveRegion/LiveRegion.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport type { HTMLAttributes, ReactNode } from 'react';\n\nimport { WDS_LIVE_REGION_DELAY_MS } from '../constants';\n\nexport type AriaLive = 'off' | 'polite' | 'assertive';\n\ntype LivePoliteness = Exclude<AriaLive, 'off'>;\n\nconst LIVE_REGION_ROLE_BY_POLITENESS: Record<LivePoliteness, 'status' | 'alert'> = {\n assertive: 'alert',\n polite: 'status',\n};\n\nlet nextPoliteAnnouncementAt = 0;\nlet nextAssertiveAnnouncementAt = 0;\n\nconst getNextAnnouncementAt = (politeness: LivePoliteness): number => {\n if (politeness === 'polite') {\n return nextPoliteAnnouncementAt;\n }\n\n return nextAssertiveAnnouncementAt;\n};\n\nconst setNextAnnouncementAt = (politeness: LivePoliteness, value: number): void => {\n if (politeness === 'polite') {\n nextPoliteAnnouncementAt = value;\n return;\n }\n\n nextAssertiveAnnouncementAt = value;\n};\n\nexport const resetLiveRegionAnnouncementQueue = (): void => {\n nextPoliteAnnouncementAt = 0;\n nextAssertiveAnnouncementAt = 0;\n};\n\nconst calcAnnouncementDelayMs = (politeness: LivePoliteness, now: number): number => {\n return Math.max(now + WDS_LIVE_REGION_DELAY_MS, getNextAnnouncementAt(politeness)) - now;\n};\n\nconst scheduleAnnouncement = (politeness: LivePoliteness): number => {\n const now = Date.now();\n const delayMs = calcAnnouncementDelayMs(politeness, now);\n setNextAnnouncementAt(politeness, now + delayMs + WDS_LIVE_REGION_DELAY_MS);\n return delayMs;\n};\n\nexport interface LiveRegionProps extends Omit<\n HTMLAttributes<HTMLDivElement>,\n 'role' | 'aria-live' | 'aria-atomic'\n> {\n /**\n * Determines urgency: 'assertive' interrupts, 'polite' waits for idle, 'off' disables live region.\n */\n 'aria-live': AriaLive;\n /** Optional stable key that triggers a new announcement when it changes. */\n announceOnChange?: string | number;\n /** Test ID for testing tools */\n 'data-testid'?: string;\n children?: ReactNode;\n}\n\n/**\n * Renders an ARIA live region with the correct implicit role.\n *\n * - `aria-live=\"polite\"` → `role=\"status\"`\n * - `aria-live=\"assertive\"` → `role=\"alert\"`\n * - `aria-live=\"off\"` → no live region (renders children unwrapped)\n *\n * The `role` prop is intentionally excluded from the public API\n * to prevent mismatches between `aria-live` and `role`.\n */\nexport const LiveRegion = ({\n 'aria-live': ariaLive,\n announceOnChange,\n children,\n className,\n ...props\n}: LiveRegionProps) => {\n const [shouldAnnounce, setShouldAnnounce] = useState(false);\n const announcementTrigger =\n announceOnChange ??\n (typeof children === 'string' || typeof children === 'number' ? children : undefined);\n\n useEffect(() => {\n setShouldAnnounce(false);\n\n if (ariaLive === 'off') {\n return;\n }\n\n const timeoutId = window.setTimeout(\n () => setShouldAnnounce(true),\n scheduleAnnouncement(ariaLive),\n );\n\n return () => window.clearTimeout(timeoutId);\n }, [ariaLive, announcementTrigger]);\n\n if (ariaLive === 'off') {\n return <>{children}</>;\n }\n\n return (\n <div\n role={LIVE_REGION_ROLE_BY_POLITENESS[ariaLive]}\n aria-live={ariaLive}\n aria-atomic=\"true\"\n className={`wds-LiveRegion ${className ?? ''}`}\n {...props}\n >\n <div aria-hidden={shouldAnnounce ? undefined : 'true'}>{children}</div>\n </div>\n );\n};\n"],"names":["LIVE_REGION_ROLE_BY_POLITENESS","assertive","polite","nextPoliteAnnouncementAt","nextAssertiveAnnouncementAt","getNextAnnouncementAt","politeness","setNextAnnouncementAt","value","calcAnnouncementDelayMs","now","Math","max","WDS_LIVE_REGION_DELAY_MS","scheduleAnnouncement","Date","delayMs","LiveRegion","ariaLive","announceOnChange","children","className","props","shouldAnnounce","setShouldAnnounce","useState","announcementTrigger","undefined","useEffect","timeoutId","window","setTimeout","clearTimeout","_jsx","_Fragment","role"],"mappings":";;;;AASA,MAAMA,8BAA8B,GAA+C;AACjFC,EAAAA,SAAS,EAAE,OAAO;AAClBC,EAAAA,MAAM,EAAE;CACT;AAED,IAAIC,wBAAwB,GAAG,CAAC;AAChC,IAAIC,2BAA2B,GAAG,CAAC;AAEnC,MAAMC,qBAAqB,GAAIC,UAA0B,IAAY;EACnE,IAAIA,UAAU,KAAK,QAAQ,EAAE;AAC3B,IAAA,OAAOH,wBAAwB;AACjC,EAAA;AAEA,EAAA,OAAOC,2BAA2B;AACpC,CAAC;AAED,MAAMG,qBAAqB,GAAGA,CAACD,UAA0B,EAAEE,KAAa,KAAU;EAChF,IAAIF,UAAU,KAAK,QAAQ,EAAE;AAC3BH,IAAAA,wBAAwB,GAAGK,KAAK;AAChC,IAAA;AACF,EAAA;AAEAJ,EAAAA,2BAA2B,GAAGI,KAAK;AACrC,CAAC;AAOD,MAAMC,uBAAuB,GAAGA,CAACH,UAA0B,EAAEI,GAAW,KAAY;AAClF,EAAA,OAAOC,IAAI,CAACC,GAAG,CAACF,GAAG,GAAGG,wBAAwB,EAAER,qBAAqB,CAACC,UAAU,CAAC,CAAC,GAAGI,GAAG;AAC1F,CAA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AACEE,IAAAA,IAAI,EAAEnC,8BAA8B,CAACkB,QAAQ,CAAE;AAC/C,IAAA,WAAA,EAAWA,QAAS;AACpB,IAAA,aAAA,EAAY,MAAM;AAClBG,IAAAA,SAAS,EAAE,CAAA,eAAA,EAAkBA,SAAS,IAAI,EAAE,CAAA,CAAG;AAAA,IAAA,GAC3CC,KAAK;AAAAF,IAAAA,QAAA,eAETa,GAAA,CAAA,KAAA,EAAA;AAAK,MAAA,aAAA,EAAaV,cAAc,GAAGI,SAAS,GAAG,MAAO;AAAAP,MAAAA,QAAA,EAAEA;KAAc;AACxE,GAAK,CAAC;AAEV;;;;"}
1
+ {"version":3,"file":"LiveRegion.mjs","sources":["../../../src/common/liveRegion/LiveRegion.tsx"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport type { HTMLAttributes, ReactNode } from 'react';\n\nimport { WDS_LIVE_REGION_DELAY_MS } from '../constants';\n\nexport type AriaLive = 'off' | 'polite' | 'assertive';\n\ntype LivePoliteness = Exclude<AriaLive, 'off'>;\n\nconst LIVE_REGION_ROLE_BY_POLITENESS: Record<LivePoliteness, 'status' | 'alert'> = {\n assertive: 'alert',\n polite: 'status',\n};\n\nlet nextPoliteAnnouncementAt = 0;\nlet nextAssertiveAnnouncementAt = 0;\n\nconst getNextAnnouncementAt = (politeness: LivePoliteness): number => {\n if (politeness === 'polite') {\n return nextPoliteAnnouncementAt;\n }\n\n return nextAssertiveAnnouncementAt;\n};\n\nconst setNextAnnouncementAt = (politeness: LivePoliteness, value: number): void => {\n if (politeness === 'polite') {\n nextPoliteAnnouncementAt = value;\n return;\n }\n\n nextAssertiveAnnouncementAt = value;\n};\n\nexport const resetLiveRegionAnnouncementQueue = (): void => {\n nextPoliteAnnouncementAt = 0;\n nextAssertiveAnnouncementAt = 0;\n};\n\nconst calcAnnouncementDelayMs = (politeness: LivePoliteness, now: number): number => {\n return Math.max(now + WDS_LIVE_REGION_DELAY_MS, getNextAnnouncementAt(politeness)) - now;\n};\n\nconst scheduleAnnouncement = (politeness: LivePoliteness): number => {\n const now = Date.now();\n const delayMs = calcAnnouncementDelayMs(politeness, now);\n setNextAnnouncementAt(politeness, now + delayMs + WDS_LIVE_REGION_DELAY_MS);\n return delayMs;\n};\n\nexport interface LiveRegionProps extends Omit<\n HTMLAttributes<HTMLDivElement>,\n 'role' | 'aria-live' | 'aria-atomic'\n> {\n /**\n * Determines urgency: 'assertive' interrupts, 'polite' waits for idle, 'off' disables live region.\n */\n 'aria-live': AriaLive;\n /** Optional stable key that triggers a new announcement when it changes. */\n announceOnChange?: string | number;\n /** Test ID for testing tools */\n 'data-testid'?: string;\n children?: ReactNode;\n}\n\n/**\n * Renders an ARIA live region with the correct implicit role.\n *\n * - `aria-live=\"polite\"` → `role=\"status\"`\n * - `aria-live=\"assertive\"` → `role=\"alert\"`\n * - `aria-live=\"off\"` → no live region (renders children unwrapped)\n *\n * The `role` prop is intentionally excluded from the public API\n * to prevent mismatches between `aria-live` and `role`.\n */\nexport const LiveRegion = ({\n 'aria-live': ariaLive,\n announceOnChange,\n children,\n className,\n ...props\n}: LiveRegionProps) => {\n const [shouldAnnounce, setShouldAnnounce] = useState(false);\n const announcementTrigger =\n announceOnChange ??\n (typeof children === 'string' || typeof children === 'number' ? children : undefined);\n\n useEffect(() => {\n if (ariaLive === 'off') {\n return;\n }\n\n // Reset announcement state, then schedule new announcement\n // This two-step process ensures screen readers re-announce the content\n // eslint-disable-next-line react-hooks/set-state-in-effect -- Deliberately resetting state to force re-announcement for screen readers\n setShouldAnnounce(false);\n\n const timeoutId = window.setTimeout(\n () => setShouldAnnounce(true),\n scheduleAnnouncement(ariaLive),\n );\n\n return () => window.clearTimeout(timeoutId);\n }, [ariaLive, announcementTrigger]);\n\n if (ariaLive === 'off') {\n return <>{children}</>;\n }\n\n return (\n <div\n role={LIVE_REGION_ROLE_BY_POLITENESS[ariaLive]}\n aria-live={ariaLive}\n aria-atomic=\"true\"\n className={`wds-LiveRegion ${className ?? ''}`}\n {...props}\n >\n <div aria-hidden={shouldAnnounce ? undefined : 'true'}>{children}</div>\n </div>\n );\n};\n"],"names":["LIVE_REGION_ROLE_BY_POLITENESS","assertive","polite","nextPoliteAnnouncementAt","nextAssertiveAnnouncementAt","getNextAnnouncementAt","politeness","setNextAnnouncementAt","value","calcAnnouncementDelayMs","now","Math","max","WDS_LIVE_REGION_DELAY_MS","scheduleAnnouncement","Date","delayMs","LiveRegion","ariaLive","announceOnChange","children","className","props","shouldAnnounce","setShouldAnnounce","useState","announcementTrigger","undefined","useEffect","timeoutId","window","setTimeout","clearTimeout","_jsx","_Fragment","role"],"mappings":";;;;AASA,MAAMA,8BAA8B,GAA+C;AACjFC,EAAAA,SAAS,EAAE,OAAO;AAClBC,EAAAA,MAAM,EAAE;CACT;AAED,IAAIC,wBAAwB,GAAG,CAAC;AAChC,IAAIC,2BAA2B,GAAG,CAAC;AAEnC,MAAMC,qBAAqB,GAAIC,UAA0B,IAAY;EACnE,IAAIA,UAAU,KAAK,QAAQ,EAAE;AAC3B,IAAA,OAAOH,wBAAwB;AACjC,EAAA;AAEA,EAAA,OAAOC,2BAA2B;AACpC,CAAC;AAED,MAAMG,qBAAqB,GAAGA,CAACD,UAA0B,EAAEE,KAAa,KAAU;EAChF,IAAIF,UAAU,KAAK,QAAQ,EAAE;AAC3BH,IAAAA,wBAAwB,GAAGK,KAAK;AAChC,IAAA;AACF,EAAA;AAEAJ,EAAAA,2BAA2B,GAAGI,KAAK;AACrC,CAAC;AAOD,MAAMC,uBAAuB,GAAGA,CAACH,UAA0B,EAAEI,GAAW,KAAY;AAClF,EAAA,OAAOC,IAAI,CAACC,GAAG,CAACF,GAAG,GAAGG,wBAAwB,EAAER,qBAAqB,CAACC,UAAU,CAAC,CAAC,GAAGI,GAAG;AAC1F,CAAC;AAED,MAAMI,oBAAoB,GAAIR,UAA0B,IAAY;AAClE,EAAA,MAAMI,GAAG,GAAGK,IAAI,CAACL,GAAG,EAAE;AACtB,EAAA,MAAMM,OAAO,GAAGP,uB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ClBG,IAAAA,SAAS,EAAE,CAAA,eAAA,EAAkBA,SAAS,IAAI,EAAE,CAAA,CAAG;AAAA,IAAA,GAC3CC,KAAK;AAAAF,IAAAA,QAAA,eAETa,GAAA,CAAA,KAAA,EAAA;AAAK,MAAA,aAAA,EAAaV,cAAc,GAAGI,SAAS,GAAG,MAAO;AAAAP,MAAAA,QAAA,EAAEA;KAAc;AACxE,GAAK,CAAC;AAEV;;;;"}
@@ -117,10 +117,10 @@ const DateInput = ({
117
117
  const monthYearOnly = mode === dateMode.DateMode.MONTH_YEAR;
118
118
  const monthBeforeDay = getFormatForLocale.MDY.has(locale);
119
119
  const yearFirst = getFormatForLocale.YMD.has(locale);
120
- dayLabel ||= formatMessage(DateInput_messages.default.dayLabel);
121
- monthLabel ||= formatMessage(DateInput_messages.default.monthLabel);
122
- yearLabel ||= formatMessage(DateInput_messages.default.yearLabel);
123
- placeholders = {
120
+ const resolvedDayLabel = dayLabel || formatMessage(DateInput_messages.default.dayLabel);
121
+ const resolvedMonthLabel = monthLabel || formatMessage(DateInput_messages.default.monthLabel);
122
+ const resolvedYearLabel = yearLabel || formatMessage(DateInput_messages.default.yearLabel);
123
+ const resolvedPlaceholders = {
124
124
  day: placeholders?.day || formatMessage(DateInput_messages.default.dayPlaceholder),
125
125
  month: placeholders?.month || formatMessage(DateInput_messages.default.monthLabel),
126
126
  year: placeholders?.year || formatMessage(DateInput_messages.default.yearPlaceholder)
@@ -161,14 +161,14 @@ const DateInput = ({
161
161
  className: "d-flex flex-column",
162
162
  children: [/*#__PURE__*/jsxRuntime.jsx(Body.default, {
163
163
  type: typography.Typography.BODY_DEFAULT,
164
- children: monthLabel
164
+ children: resolvedMonthLabel
165
165
  }), /*#__PURE__*/jsxRuntime.jsx(SelectInput.SelectInput, {
166
166
  triggerRef: monthRef,
167
167
  id: `${id}:month`,
168
168
  parentId: DATE_INPUT_PARENT_ID,
169
169
  name: "month",
170
170
  disabled: disabled,
171
- placeholder: placeholders?.month,
171
+ placeholder: resolvedPlaceholders.month,
172
172
  items: Array.from({
173
173
  length: 12
174
174
  }, (_, index) => ({
@@ -265,7 +265,7 @@ const DateInput = ({
265
265
  children: /*#__PURE__*/jsxRuntime.jsxs("label", {
266
266
  children: [/*#__PURE__*/jsxRuntime.jsx(Body.default, {
267
267
  type: typography.Typography.BODY_DEFAULT,
268
- children: dayLabel
268
+ children: resolvedDayLabel
269
269
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
270
270
  className: `input-group input-group-${size$1} ${disabled ? 'disabled' : ''}`,
271
271
  children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
@@ -277,7 +277,7 @@ const DateInput = ({
277
277
  name: "day",
278
278
  autoComplete: dayAutoComplete,
279
279
  value: displayDay || '',
280
- placeholder: placeholders?.day,
280
+ placeholder: resolvedPlaceholders.day,
281
281
  disabled: disabled,
282
282
  min: 1,
283
283
  max: 31,
@@ -294,7 +294,7 @@ const DateInput = ({
294
294
  children: /*#__PURE__*/jsxRuntime.jsxs("label", {
295
295
  children: [/*#__PURE__*/jsxRuntime.jsx(Body.default, {
296
296
  type: typography.Typography.BODY_DEFAULT,
297
- children: yearLabel
297
+ children: resolvedYearLabel
298
298
  }), /*#__PURE__*/jsxRuntime.jsx("div", {
299
299
  className: `input-group input-group-${size$1} ${disabled ? 'disabled' : ''}`,
300
300
  children: /*#__PURE__*/jsxRuntime.jsx(Input.Input, {
@@ -305,7 +305,7 @@ const DateInput = ({
305
305
  pattern: "[0-9]*",
306
306
  name: "year",
307
307
  autoComplete: yearAutoComplete,
308
- placeholder: placeholders?.year,
308
+ placeholder: resolvedPlaceholders.year,
309
309
  value: displayYear || '',
310
310
  disabled: disabled,
311
311
  min: 0,