@metamask/design-system-react 0.24.0 → 0.26.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 (296) hide show
  1. package/CHANGELOG.md +35 -1
  2. package/dist/components/AvatarBase/AvatarBase.cjs +1 -1
  3. package/dist/components/AvatarBase/AvatarBase.cjs.map +1 -1
  4. package/dist/components/AvatarBase/AvatarBase.mjs +1 -1
  5. package/dist/components/AvatarBase/AvatarBase.mjs.map +1 -1
  6. package/dist/components/AvatarFavicon/AvatarFavicon.cjs +1 -1
  7. package/dist/components/AvatarFavicon/AvatarFavicon.cjs.map +1 -1
  8. package/dist/components/AvatarFavicon/AvatarFavicon.mjs +1 -1
  9. package/dist/components/AvatarFavicon/AvatarFavicon.mjs.map +1 -1
  10. package/dist/components/AvatarIcon/AvatarIcon.constants.cjs +2 -2
  11. package/dist/components/AvatarIcon/AvatarIcon.constants.cjs.map +1 -1
  12. package/dist/components/AvatarIcon/AvatarIcon.constants.mjs +2 -2
  13. package/dist/components/AvatarIcon/AvatarIcon.constants.mjs.map +1 -1
  14. package/dist/components/AvatarNetwork/AvatarNetwork.cjs +2 -3
  15. package/dist/components/AvatarNetwork/AvatarNetwork.cjs.map +1 -1
  16. package/dist/components/AvatarNetwork/AvatarNetwork.d.cts.map +1 -1
  17. package/dist/components/AvatarNetwork/AvatarNetwork.d.mts.map +1 -1
  18. package/dist/components/AvatarNetwork/AvatarNetwork.mjs +2 -3
  19. package/dist/components/AvatarNetwork/AvatarNetwork.mjs.map +1 -1
  20. package/dist/components/AvatarNetwork/index.cjs +2 -2
  21. package/dist/components/AvatarNetwork/index.cjs.map +1 -1
  22. package/dist/components/AvatarNetwork/index.d.cts +1 -1
  23. package/dist/components/AvatarNetwork/index.d.cts.map +1 -1
  24. package/dist/components/AvatarNetwork/index.d.mts +1 -1
  25. package/dist/components/AvatarNetwork/index.d.mts.map +1 -1
  26. package/dist/components/AvatarNetwork/index.mjs +1 -1
  27. package/dist/components/AvatarNetwork/index.mjs.map +1 -1
  28. package/dist/components/AvatarToken/AvatarToken.cjs +2 -2
  29. package/dist/components/AvatarToken/AvatarToken.cjs.map +1 -1
  30. package/dist/components/AvatarToken/AvatarToken.mjs +2 -2
  31. package/dist/components/AvatarToken/AvatarToken.mjs.map +1 -1
  32. package/dist/components/BannerAlert/BannerAlert.cjs +1 -2
  33. package/dist/components/BannerAlert/BannerAlert.cjs.map +1 -1
  34. package/dist/components/BannerAlert/BannerAlert.constants.cjs +8 -9
  35. package/dist/components/BannerAlert/BannerAlert.constants.cjs.map +1 -1
  36. package/dist/components/BannerAlert/BannerAlert.constants.d.cts +1 -2
  37. package/dist/components/BannerAlert/BannerAlert.constants.d.cts.map +1 -1
  38. package/dist/components/BannerAlert/BannerAlert.constants.d.mts +1 -2
  39. package/dist/components/BannerAlert/BannerAlert.constants.d.mts.map +1 -1
  40. package/dist/components/BannerAlert/BannerAlert.constants.mjs +1 -2
  41. package/dist/components/BannerAlert/BannerAlert.constants.mjs.map +1 -1
  42. package/dist/components/BannerAlert/BannerAlert.d.cts.map +1 -1
  43. package/dist/components/BannerAlert/BannerAlert.d.mts.map +1 -1
  44. package/dist/components/BannerAlert/BannerAlert.mjs +1 -2
  45. package/dist/components/BannerAlert/BannerAlert.mjs.map +1 -1
  46. package/dist/components/FormTextField/FormTextField.cjs +38 -0
  47. package/dist/components/FormTextField/FormTextField.cjs.map +1 -0
  48. package/dist/components/FormTextField/FormTextField.d.cts +4 -0
  49. package/dist/components/FormTextField/FormTextField.d.cts.map +1 -0
  50. package/dist/components/FormTextField/FormTextField.d.mts +4 -0
  51. package/dist/components/FormTextField/FormTextField.d.mts.map +1 -0
  52. package/dist/components/FormTextField/FormTextField.mjs +19 -0
  53. package/dist/components/FormTextField/FormTextField.mjs.map +1 -0
  54. package/dist/components/FormTextField/FormTextField.types.cjs +3 -0
  55. package/dist/components/FormTextField/FormTextField.types.cjs.map +1 -0
  56. package/dist/components/FormTextField/FormTextField.types.d.cts +50 -0
  57. package/dist/components/FormTextField/FormTextField.types.d.cts.map +1 -0
  58. package/dist/components/FormTextField/FormTextField.types.d.mts +50 -0
  59. package/dist/components/FormTextField/FormTextField.types.d.mts.map +1 -0
  60. package/dist/components/FormTextField/FormTextField.types.mjs +2 -0
  61. package/dist/components/FormTextField/FormTextField.types.mjs.map +1 -0
  62. package/dist/components/FormTextField/index.cjs +6 -0
  63. package/dist/components/FormTextField/index.cjs.map +1 -0
  64. package/dist/components/FormTextField/index.d.cts +3 -0
  65. package/dist/components/FormTextField/index.d.cts.map +1 -0
  66. package/dist/components/FormTextField/index.d.mts +3 -0
  67. package/dist/components/FormTextField/index.d.mts.map +1 -0
  68. package/dist/components/FormTextField/index.mjs +2 -0
  69. package/dist/components/FormTextField/index.mjs.map +1 -0
  70. package/dist/components/Icon/Icon.cjs +2 -2
  71. package/dist/components/Icon/Icon.cjs.map +1 -1
  72. package/dist/components/Icon/Icon.constants.cjs +6 -6
  73. package/dist/components/Icon/Icon.constants.cjs.map +1 -1
  74. package/dist/components/Icon/Icon.constants.d.cts +1 -1
  75. package/dist/components/Icon/Icon.constants.d.cts.map +1 -1
  76. package/dist/components/Icon/Icon.constants.d.mts +1 -1
  77. package/dist/components/Icon/Icon.constants.d.mts.map +1 -1
  78. package/dist/components/Icon/Icon.constants.mjs +1 -1
  79. package/dist/components/Icon/Icon.constants.mjs.map +1 -1
  80. package/dist/components/Icon/Icon.d.cts.map +1 -1
  81. package/dist/components/Icon/Icon.d.mts.map +1 -1
  82. package/dist/components/Icon/Icon.mjs +1 -1
  83. package/dist/components/Icon/Icon.mjs.map +1 -1
  84. package/dist/components/Icon/index.cjs +4 -4
  85. package/dist/components/Icon/index.cjs.map +1 -1
  86. package/dist/components/Icon/index.d.cts +1 -1
  87. package/dist/components/Icon/index.d.cts.map +1 -1
  88. package/dist/components/Icon/index.d.mts +1 -1
  89. package/dist/components/Icon/index.d.mts.map +1 -1
  90. package/dist/components/Icon/index.mjs +1 -1
  91. package/dist/components/Icon/index.mjs.map +1 -1
  92. package/dist/components/Popover/Popover.cjs +129 -0
  93. package/dist/components/Popover/Popover.cjs.map +1 -0
  94. package/dist/components/Popover/Popover.constants.cjs +28 -0
  95. package/dist/components/Popover/Popover.constants.cjs.map +1 -0
  96. package/dist/components/Popover/Popover.constants.d.cts +12 -0
  97. package/dist/components/Popover/Popover.constants.d.cts.map +1 -0
  98. package/dist/components/Popover/Popover.constants.d.mts +12 -0
  99. package/dist/components/Popover/Popover.constants.d.mts.map +1 -0
  100. package/dist/components/Popover/Popover.constants.mjs +25 -0
  101. package/dist/components/Popover/Popover.constants.mjs.map +1 -0
  102. package/dist/components/Popover/Popover.d.cts +4 -0
  103. package/dist/components/Popover/Popover.d.cts.map +1 -0
  104. package/dist/components/Popover/Popover.d.mts +4 -0
  105. package/dist/components/Popover/Popover.d.mts.map +1 -0
  106. package/dist/components/Popover/Popover.mjs +110 -0
  107. package/dist/components/Popover/Popover.mjs.map +1 -0
  108. package/dist/components/Popover/Popover.types.cjs +33 -0
  109. package/dist/components/Popover/Popover.types.cjs.map +1 -0
  110. package/dist/components/Popover/Popover.types.d.cts +128 -0
  111. package/dist/components/Popover/Popover.types.d.cts.map +1 -0
  112. package/dist/components/Popover/Popover.types.d.mts +128 -0
  113. package/dist/components/Popover/Popover.types.d.mts.map +1 -0
  114. package/dist/components/Popover/Popover.types.mjs +30 -0
  115. package/dist/components/Popover/Popover.types.mjs.map +1 -0
  116. package/dist/components/Popover/index.cjs +9 -0
  117. package/dist/components/Popover/index.cjs.map +1 -0
  118. package/dist/components/Popover/index.d.cts +4 -0
  119. package/dist/components/Popover/index.d.cts.map +1 -0
  120. package/dist/components/Popover/index.d.mts +4 -0
  121. package/dist/components/Popover/index.d.mts.map +1 -0
  122. package/dist/components/Popover/index.mjs +3 -0
  123. package/dist/components/Popover/index.mjs.map +1 -0
  124. package/dist/components/Tag/Tag.cjs +51 -0
  125. package/dist/components/Tag/Tag.cjs.map +1 -0
  126. package/dist/components/Tag/Tag.constants.cjs +26 -0
  127. package/dist/components/Tag/Tag.constants.cjs.map +1 -0
  128. package/dist/components/Tag/Tag.constants.d.cts +5 -0
  129. package/dist/components/Tag/Tag.constants.d.cts.map +1 -0
  130. package/dist/components/Tag/Tag.constants.d.mts +5 -0
  131. package/dist/components/Tag/Tag.constants.d.mts.map +1 -0
  132. package/dist/components/Tag/Tag.constants.mjs +23 -0
  133. package/dist/components/Tag/Tag.constants.mjs.map +1 -0
  134. package/dist/components/Tag/Tag.d.cts +4 -0
  135. package/dist/components/Tag/Tag.d.cts.map +1 -0
  136. package/dist/components/Tag/Tag.d.mts +4 -0
  137. package/dist/components/Tag/Tag.d.mts.map +1 -0
  138. package/dist/components/Tag/Tag.mjs +32 -0
  139. package/dist/components/Tag/Tag.mjs.map +1 -0
  140. package/dist/components/Tag/Tag.types.cjs +3 -0
  141. package/dist/components/Tag/Tag.types.cjs.map +1 -0
  142. package/dist/components/Tag/Tag.types.d.cts +31 -0
  143. package/dist/components/Tag/Tag.types.d.cts.map +1 -0
  144. package/dist/components/Tag/Tag.types.d.mts +31 -0
  145. package/dist/components/Tag/Tag.types.d.mts.map +1 -0
  146. package/dist/components/Tag/Tag.types.mjs +2 -0
  147. package/dist/components/Tag/Tag.types.mjs.map +1 -0
  148. package/dist/components/Tag/index.cjs +8 -0
  149. package/dist/components/Tag/index.cjs.map +1 -0
  150. package/dist/components/Tag/index.d.cts +4 -0
  151. package/dist/components/Tag/index.d.cts.map +1 -0
  152. package/dist/components/Tag/index.d.mts +4 -0
  153. package/dist/components/Tag/index.d.mts.map +1 -0
  154. package/dist/components/Tag/index.mjs +3 -0
  155. package/dist/components/Tag/index.mjs.map +1 -0
  156. package/dist/components/TextArea/TextArea.cjs +37 -0
  157. package/dist/components/TextArea/TextArea.cjs.map +1 -0
  158. package/dist/components/TextArea/TextArea.constants.cjs +35 -0
  159. package/dist/components/TextArea/TextArea.constants.cjs.map +1 -0
  160. package/dist/components/TextArea/TextArea.constants.d.cts +28 -0
  161. package/dist/components/TextArea/TextArea.constants.d.cts.map +1 -0
  162. package/dist/components/TextArea/TextArea.constants.d.mts +28 -0
  163. package/dist/components/TextArea/TextArea.constants.d.mts.map +1 -0
  164. package/dist/components/TextArea/TextArea.constants.mjs +32 -0
  165. package/dist/components/TextArea/TextArea.constants.mjs.map +1 -0
  166. package/dist/components/TextArea/TextArea.d.cts +9 -0
  167. package/dist/components/TextArea/TextArea.d.cts.map +1 -0
  168. package/dist/components/TextArea/TextArea.d.mts +9 -0
  169. package/dist/components/TextArea/TextArea.d.mts.map +1 -0
  170. package/dist/components/TextArea/TextArea.mjs +18 -0
  171. package/dist/components/TextArea/TextArea.mjs.map +1 -0
  172. package/dist/components/TextArea/TextArea.types.cjs +3 -0
  173. package/dist/components/TextArea/TextArea.types.cjs.map +1 -0
  174. package/dist/components/TextArea/TextArea.types.d.cts +33 -0
  175. package/dist/components/TextArea/TextArea.types.d.cts.map +1 -0
  176. package/dist/components/TextArea/TextArea.types.d.mts +33 -0
  177. package/dist/components/TextArea/TextArea.types.d.mts.map +1 -0
  178. package/dist/components/TextArea/TextArea.types.mjs +2 -0
  179. package/dist/components/TextArea/TextArea.types.mjs.map +1 -0
  180. package/dist/components/TextArea/index.cjs +8 -0
  181. package/dist/components/TextArea/index.cjs.map +1 -0
  182. package/dist/components/TextArea/index.d.cts +4 -0
  183. package/dist/components/TextArea/index.d.cts.map +1 -0
  184. package/dist/components/TextArea/index.d.mts +4 -0
  185. package/dist/components/TextArea/index.d.mts.map +1 -0
  186. package/dist/components/TextArea/index.mjs +3 -0
  187. package/dist/components/TextArea/index.mjs.map +1 -0
  188. package/dist/components/TextButton/TextButton.cjs +7 -28
  189. package/dist/components/TextButton/TextButton.cjs.map +1 -1
  190. package/dist/components/TextButton/TextButton.d.cts.map +1 -1
  191. package/dist/components/TextButton/TextButton.d.mts.map +1 -1
  192. package/dist/components/TextButton/TextButton.mjs +7 -28
  193. package/dist/components/TextButton/TextButton.mjs.map +1 -1
  194. package/dist/components/TextButton/TextButton.types.cjs.map +1 -1
  195. package/dist/components/TextButton/TextButton.types.d.cts +9 -25
  196. package/dist/components/TextButton/TextButton.types.d.cts.map +1 -1
  197. package/dist/components/TextButton/TextButton.types.d.mts +9 -25
  198. package/dist/components/TextButton/TextButton.types.d.mts.map +1 -1
  199. package/dist/components/TextButton/TextButton.types.mjs.map +1 -1
  200. package/dist/components/TextButton/index.cjs +1 -3
  201. package/dist/components/TextButton/index.cjs.map +1 -1
  202. package/dist/components/TextButton/index.d.cts +0 -1
  203. package/dist/components/TextButton/index.d.cts.map +1 -1
  204. package/dist/components/TextButton/index.d.mts +0 -1
  205. package/dist/components/TextButton/index.d.mts.map +1 -1
  206. package/dist/components/TextButton/index.mjs +0 -1
  207. package/dist/components/TextButton/index.mjs.map +1 -1
  208. package/dist/components/TextFieldSearch/TextFieldSearch.cjs +40 -0
  209. package/dist/components/TextFieldSearch/TextFieldSearch.cjs.map +1 -0
  210. package/dist/components/TextFieldSearch/TextFieldSearch.d.cts +6 -0
  211. package/dist/components/TextFieldSearch/TextFieldSearch.d.cts.map +1 -0
  212. package/dist/components/TextFieldSearch/TextFieldSearch.d.mts +6 -0
  213. package/dist/components/TextFieldSearch/TextFieldSearch.d.mts.map +1 -0
  214. package/dist/components/TextFieldSearch/TextFieldSearch.mjs +21 -0
  215. package/dist/components/TextFieldSearch/TextFieldSearch.mjs.map +1 -0
  216. package/dist/components/TextFieldSearch/TextFieldSearch.types.cjs +3 -0
  217. package/dist/components/TextFieldSearch/TextFieldSearch.types.cjs.map +1 -0
  218. package/dist/components/TextFieldSearch/TextFieldSearch.types.d.cts +17 -0
  219. package/dist/components/TextFieldSearch/TextFieldSearch.types.d.cts.map +1 -0
  220. package/dist/components/TextFieldSearch/TextFieldSearch.types.d.mts +17 -0
  221. package/dist/components/TextFieldSearch/TextFieldSearch.types.d.mts.map +1 -0
  222. package/dist/components/TextFieldSearch/TextFieldSearch.types.mjs +2 -0
  223. package/dist/components/TextFieldSearch/TextFieldSearch.types.mjs.map +1 -0
  224. package/dist/components/TextFieldSearch/index.cjs +6 -0
  225. package/dist/components/TextFieldSearch/index.cjs.map +1 -0
  226. package/dist/components/TextFieldSearch/index.d.cts +3 -0
  227. package/dist/components/TextFieldSearch/index.d.cts.map +1 -0
  228. package/dist/components/TextFieldSearch/index.d.mts +3 -0
  229. package/dist/components/TextFieldSearch/index.d.mts.map +1 -0
  230. package/dist/components/TextFieldSearch/index.mjs +2 -0
  231. package/dist/components/TextFieldSearch/index.mjs.map +1 -0
  232. package/dist/components/Toast/Toast.cjs +73 -0
  233. package/dist/components/Toast/Toast.cjs.map +1 -0
  234. package/dist/components/Toast/Toast.constants.cjs +24 -0
  235. package/dist/components/Toast/Toast.constants.cjs.map +1 -0
  236. package/dist/components/Toast/Toast.constants.d.cts +16 -0
  237. package/dist/components/Toast/Toast.constants.d.cts.map +1 -0
  238. package/dist/components/Toast/Toast.constants.d.mts +16 -0
  239. package/dist/components/Toast/Toast.constants.d.mts.map +1 -0
  240. package/dist/components/Toast/Toast.constants.mjs +19 -0
  241. package/dist/components/Toast/Toast.constants.mjs.map +1 -0
  242. package/dist/components/Toast/Toast.d.cts +4 -0
  243. package/dist/components/Toast/Toast.d.cts.map +1 -0
  244. package/dist/components/Toast/Toast.d.mts +4 -0
  245. package/dist/components/Toast/Toast.d.mts.map +1 -0
  246. package/dist/components/Toast/Toast.mjs +54 -0
  247. package/dist/components/Toast/Toast.mjs.map +1 -0
  248. package/dist/components/Toast/Toast.types.cjs +3 -0
  249. package/dist/components/Toast/Toast.types.cjs.map +1 -0
  250. package/dist/components/Toast/Toast.types.d.cts +60 -0
  251. package/dist/components/Toast/Toast.types.d.cts.map +1 -0
  252. package/dist/components/Toast/Toast.types.d.mts +60 -0
  253. package/dist/components/Toast/Toast.types.d.mts.map +1 -0
  254. package/dist/components/Toast/Toast.types.mjs +2 -0
  255. package/dist/components/Toast/Toast.types.mjs.map +1 -0
  256. package/dist/components/Toast/Toaster.cjs +210 -0
  257. package/dist/components/Toast/Toaster.cjs.map +1 -0
  258. package/dist/components/Toast/Toaster.d.cts +11 -0
  259. package/dist/components/Toast/Toaster.d.cts.map +1 -0
  260. package/dist/components/Toast/Toaster.d.mts +11 -0
  261. package/dist/components/Toast/Toaster.d.mts.map +1 -0
  262. package/dist/components/Toast/Toaster.mjs +191 -0
  263. package/dist/components/Toast/Toaster.mjs.map +1 -0
  264. package/dist/components/Toast/index.cjs +11 -0
  265. package/dist/components/Toast/index.cjs.map +1 -0
  266. package/dist/components/Toast/index.d.cts +5 -0
  267. package/dist/components/Toast/index.d.cts.map +1 -0
  268. package/dist/components/Toast/index.d.mts +5 -0
  269. package/dist/components/Toast/index.d.mts.map +1 -0
  270. package/dist/components/Toast/index.mjs +4 -0
  271. package/dist/components/Toast/index.mjs.map +1 -0
  272. package/dist/components/index.cjs +21 -2
  273. package/dist/components/index.cjs.map +1 -1
  274. package/dist/components/index.d.cts +13 -1
  275. package/dist/components/index.d.cts.map +1 -1
  276. package/dist/components/index.d.mts +13 -1
  277. package/dist/components/index.d.mts.map +1 -1
  278. package/dist/components/index.mjs +7 -1
  279. package/dist/components/index.mjs.map +1 -1
  280. package/dist/types/index.cjs +2 -23
  281. package/dist/types/index.cjs.map +1 -1
  282. package/dist/types/index.d.cts +1 -14
  283. package/dist/types/index.d.cts.map +1 -1
  284. package/dist/types/index.d.mts +1 -14
  285. package/dist/types/index.d.mts.map +1 -1
  286. package/dist/types/index.mjs +1 -15
  287. package/dist/types/index.mjs.map +1 -1
  288. package/package.json +7 -5
  289. package/dist/components/TextButton/TextButton.constants.cjs +0 -12
  290. package/dist/components/TextButton/TextButton.constants.cjs.map +0 -1
  291. package/dist/components/TextButton/TextButton.constants.d.cts +0 -4
  292. package/dist/components/TextButton/TextButton.constants.d.cts.map +0 -1
  293. package/dist/components/TextButton/TextButton.constants.d.mts +0 -4
  294. package/dist/components/TextButton/TextButton.constants.d.mts.map +0 -1
  295. package/dist/components/TextButton/TextButton.constants.mjs +0 -9
  296. package/dist/components/TextButton/TextButton.constants.mjs.map +0 -1
@@ -0,0 +1,54 @@
1
+ function $importDefault(module) {
2
+ if (module?.__esModule) {
3
+ return module.default;
4
+ }
5
+ return module;
6
+ }
7
+ import { BoxBackgroundColor, BoxBorderColor, ButtonSize, IconSize, ToastSeverity } from "@metamask/design-system-shared";
8
+ import $React, { forwardRef } from "react";
9
+ const React = $importDefault($React);
10
+ import { twMerge } from "../../utils/tw-merge.mjs";
11
+ import { BannerBase } from "../BannerBase/index.mjs";
12
+ import { Icon } from "../Icon/index.mjs";
13
+ import { TOAST_SEVERITY_ICON_MAP } from "./Toast.constants.mjs";
14
+ const renderSeverityAccessory = ({ severity, startAccessory, iconProps, }) => {
15
+ if (startAccessory !== null && startAccessory !== undefined) {
16
+ return startAccessory;
17
+ }
18
+ if (!severity || severity === ToastSeverity.Default) {
19
+ return undefined;
20
+ }
21
+ const { name, color } = TOAST_SEVERITY_ICON_MAP[severity];
22
+ return React.createElement(Icon, { name: name, color: color, size: IconSize.Lg, ...iconProps });
23
+ };
24
+ export const Toast = forwardRef(({ actionButtonLabel, actionButtonOnClick, actionButtonProps, className, closeButtonProps, iconProps, onClose, severity = ToastSeverity.Default, startAccessory, ...props }, ref) => {
25
+ // Only pass action props through when both the label and handler are set so
26
+ // BannerBase can keep its action button contract simple.
27
+ const resolvedActionProps = actionButtonLabel && actionButtonOnClick
28
+ ? {
29
+ actionButtonLabel,
30
+ actionButtonOnClick,
31
+ actionButtonProps: {
32
+ size: ButtonSize.Sm,
33
+ ...actionButtonProps,
34
+ },
35
+ }
36
+ : {};
37
+ // Derive the close button config from the Toast API, keeping the button
38
+ // visible whenever the consumer provides dismiss behavior or overrides.
39
+ const resolvedCloseButtonProps = onClose || closeButtonProps
40
+ ? {
41
+ ariaLabel: 'Close toast',
42
+ ...closeButtonProps,
43
+ }
44
+ : undefined;
45
+ // Toast reuses BannerBase so the web surface stays aligned with the shared
46
+ // banner layout and the React Native Toast API.
47
+ return (React.createElement(BannerBase, { ref: ref, ...resolvedActionProps, ...props, backgroundColor: BoxBackgroundColor.BackgroundSection, borderColor: BoxBorderColor.BorderMuted, borderWidth: 1, className: twMerge('rounded-xl', className), closeButtonProps: resolvedCloseButtonProps, onClose: onClose, startAccessory: renderSeverityAccessory({
48
+ severity,
49
+ startAccessory,
50
+ iconProps,
51
+ }) }));
52
+ });
53
+ Toast.displayName = 'Toast';
54
+ //# sourceMappingURL=Toast.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.tsx"],"names":[],"mappings":";;;;;;AAAA,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,UAAU,EACV,QAAQ,EACR,aAAa,EACd,uCAAuC;AACxC,OAAO,QAAO,EAAE,UAAU,EAAE,cAAc;;AAE1C,OAAO,EAAE,OAAO,EAAE,iCAA6B;AAC/C,OAAO,EAAE,UAAU,EAAE,gCAAsB;AAC3C,OAAO,EAAE,IAAI,EAAE,0BAAgB;AAE/B,OAAO,EAAE,uBAAuB,EAAE,8BAA0B;AAG5D,MAAM,uBAAuB,GAAG,CAAC,EAC/B,QAAQ,EACR,cAAc,EACd,SAAS,GACqD,EAAE,EAAE;IAClE,IAAI,cAAc,KAAK,IAAI,IAAI,cAAc,KAAK,SAAS,EAAE;QAC3D,OAAO,cAAc,CAAC;KACvB;IAED,IAAI,CAAC,QAAQ,IAAI,QAAQ,KAAK,aAAa,CAAC,OAAO,EAAE;QACnD,OAAO,SAAS,CAAC;KAClB;IAED,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAE1D,OAAO,oBAAC,IAAI,IAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,QAAQ,CAAC,EAAE,KAAM,SAAS,GAAI,CAAC;AAC9E,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,CAC7B,CACE,EACE,iBAAiB,EACjB,mBAAmB,EACnB,iBAAiB,EACjB,SAAS,EACT,gBAAgB,EAChB,SAAS,EACT,OAAO,EACP,QAAQ,GAAG,aAAa,CAAC,OAAO,EAChC,cAAc,EACd,GAAG,KAAK,EACT,EACD,GAAG,EACH,EAAE;IACF,4EAA4E;IAC5E,yDAAyD;IACzD,MAAM,mBAAmB,GACvB,iBAAiB,IAAI,mBAAmB;QACtC,CAAC,CAAC;YACE,iBAAiB;YACjB,mBAAmB;YACnB,iBAAiB,EAAE;gBACjB,IAAI,EAAE,UAAU,CAAC,EAAE;gBACnB,GAAG,iBAAiB;aACrB;SACF;QACH,CAAC,CAAC,EAAE,CAAC;IAET,wEAAwE;IACxE,wEAAwE;IACxE,MAAM,wBAAwB,GAC5B,OAAO,IAAI,gBAAgB;QACzB,CAAC,CAAC;YACE,SAAS,EAAE,aAAa;YACxB,GAAG,gBAAgB;SACpB;QACH,CAAC,CAAC,SAAS,CAAC;IAEhB,2EAA2E;IAC3E,gDAAgD;IAChD,OAAO,CACL,oBAAC,UAAU,IACT,GAAG,EAAE,GAAG,KACJ,mBAAmB,KACnB,KAAK,EACT,eAAe,EAAE,kBAAkB,CAAC,iBAAiB,EACrD,WAAW,EAAE,cAAc,CAAC,WAAW,EACvC,WAAW,EAAE,CAAC,EACd,SAAS,EAAE,OAAO,CAAC,YAAY,EAAE,SAAS,CAAC,EAC3C,gBAAgB,EAAE,wBAAwB,EAC1C,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,uBAAuB,CAAC;YACtC,QAAQ;YACR,cAAc;YACd,SAAS;SACV,CAAC,GACF,CACH,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,KAAK,CAAC,WAAW,GAAG,OAAO,CAAC","sourcesContent":["import {\n BoxBackgroundColor,\n BoxBorderColor,\n ButtonSize,\n IconSize,\n ToastSeverity,\n} from '@metamask/design-system-shared';\nimport React, { forwardRef } from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\nimport { BannerBase } from '../BannerBase';\nimport { Icon } from '../Icon';\n\nimport { TOAST_SEVERITY_ICON_MAP } from './Toast.constants';\nimport type { ToastProps } from './Toast.types';\n\nconst renderSeverityAccessory = ({\n severity,\n startAccessory,\n iconProps,\n}: Pick<ToastProps, 'severity' | 'startAccessory' | 'iconProps'>) => {\n if (startAccessory !== null && startAccessory !== undefined) {\n return startAccessory;\n }\n\n if (!severity || severity === ToastSeverity.Default) {\n return undefined;\n }\n\n const { name, color } = TOAST_SEVERITY_ICON_MAP[severity];\n\n return <Icon name={name} color={color} size={IconSize.Lg} {...iconProps} />;\n};\n\nexport const Toast = forwardRef<HTMLDivElement, ToastProps>(\n (\n {\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps,\n className,\n closeButtonProps,\n iconProps,\n onClose,\n severity = ToastSeverity.Default,\n startAccessory,\n ...props\n },\n ref,\n ) => {\n // Only pass action props through when both the label and handler are set so\n // BannerBase can keep its action button contract simple.\n const resolvedActionProps =\n actionButtonLabel && actionButtonOnClick\n ? {\n actionButtonLabel,\n actionButtonOnClick,\n actionButtonProps: {\n size: ButtonSize.Sm,\n ...actionButtonProps,\n },\n }\n : {};\n\n // Derive the close button config from the Toast API, keeping the button\n // visible whenever the consumer provides dismiss behavior or overrides.\n const resolvedCloseButtonProps =\n onClose || closeButtonProps\n ? {\n ariaLabel: 'Close toast',\n ...closeButtonProps,\n }\n : undefined;\n\n // Toast reuses BannerBase so the web surface stays aligned with the shared\n // banner layout and the React Native Toast API.\n return (\n <BannerBase\n ref={ref}\n {...resolvedActionProps}\n {...props}\n backgroundColor={BoxBackgroundColor.BackgroundSection}\n borderColor={BoxBorderColor.BorderMuted}\n borderWidth={1}\n className={twMerge('rounded-xl', className)}\n closeButtonProps={resolvedCloseButtonProps}\n onClose={onClose}\n startAccessory={renderSeverityAccessory({\n severity,\n startAccessory,\n iconProps,\n })}\n />\n );\n },\n);\n\nToast.displayName = 'Toast';\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=Toast.types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast.types.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon';\n\ntype ToastCloseButtonProps = Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onClick'\n>;\n\n/**\n * Props for the Toast visual component.\n * Extends the platform BannerBase props with severity and an icon override.\n * `onClose` is simplified to `() => void` (no MouseEvent) to align with the\n * React Native API and the imperative `toast()` pattern.\n */\nexport type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> &\n ToastPropsShared & {\n /**\n * Optional handler called when the close button is pressed.\n * When provided, a close button is shown.\n */\n onClose?: () => void;\n /**\n * Optional props passed to the severity `Icon`.\n * Only used when `severity` is not `Default` and `startAccessory` is not provided.\n */\n iconProps?: Omit<IconProps, 'name' | 'color'>;\n /**\n * Optional props for the close `ButtonIcon`.\n * `ariaLabel` defaults to `'Close toast'`.\n */\n closeButtonProps?: ToastCloseButtonProps;\n /**\n * Optional test identifier forwarded to the root Toast element.\n */\n 'data-testid'?: string;\n };\n\n/**\n * Options passed to the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastProps & {\n /**\n * When true the toast stays visible until explicitly dismissed.\n * Defaults to false.\n */\n hasNoTimeout?: boolean;\n};\n\n/**\n * Imperative handle exposed by `<Toaster ref={...} />`.\n */\nexport type ToasterRef = {\n showToast: (options: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Props for the `<Toaster />` container component.\n */\nexport type ToasterProps = {\n /**\n * Optional extra CSS classes applied to the fixed outer container.\n */\n className?: string;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;\n"]}
@@ -0,0 +1,60 @@
1
+ /// <reference types="react" />
2
+ import type { ToastPropsShared } from "@metamask/design-system-shared";
3
+ import type { BannerBaseProps } from "../BannerBase/index.cjs";
4
+ import type { IconProps } from "../Icon/index.cjs";
5
+ type ToastCloseButtonProps = Omit<NonNullable<BannerBaseProps['closeButtonProps']>, 'onClick'>;
6
+ /**
7
+ * Props for the Toast visual component.
8
+ * Extends the platform BannerBase props with severity and an icon override.
9
+ * `onClose` is simplified to `() => void` (no MouseEvent) to align with the
10
+ * React Native API and the imperative `toast()` pattern.
11
+ */
12
+ export type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> & ToastPropsShared & {
13
+ /**
14
+ * Optional handler called when the close button is pressed.
15
+ * When provided, a close button is shown.
16
+ */
17
+ onClose?: () => void;
18
+ /**
19
+ * Optional props passed to the severity `Icon`.
20
+ * Only used when `severity` is not `Default` and `startAccessory` is not provided.
21
+ */
22
+ iconProps?: Omit<IconProps, 'name' | 'color'>;
23
+ /**
24
+ * Optional props for the close `ButtonIcon`.
25
+ * `ariaLabel` defaults to `'Close toast'`.
26
+ */
27
+ closeButtonProps?: ToastCloseButtonProps;
28
+ /**
29
+ * Optional test identifier forwarded to the root Toast element.
30
+ */
31
+ 'data-testid'?: string;
32
+ };
33
+ /**
34
+ * Options passed to the imperative `toast(...)` API.
35
+ */
36
+ export type ToastOptions = ToastProps & {
37
+ /**
38
+ * When true the toast stays visible until explicitly dismissed.
39
+ * Defaults to false.
40
+ */
41
+ hasNoTimeout?: boolean;
42
+ };
43
+ /**
44
+ * Imperative handle exposed by `<Toaster ref={...} />`.
45
+ */
46
+ export type ToasterRef = {
47
+ showToast: (options: ToastOptions) => void;
48
+ closeToast: () => void;
49
+ };
50
+ /**
51
+ * Props for the `<Toaster />` container component.
52
+ */
53
+ export type ToasterProps = {
54
+ /**
55
+ * Optional extra CSS classes applied to the fixed outer container.
56
+ */
57
+ className?: string;
58
+ } & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;
59
+ export {};
60
+ //# sourceMappingURL=Toast.types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast.types.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uCAAuC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAsB;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,0BAAgB;AAEzC,KAAK,qBAAqB,GAAG,IAAI,CAC/B,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,kBAAkB,GAAG,SAAS,CAAC,GAC5E,gBAAgB,GAAG;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC9C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;IACzC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,60 @@
1
+ /// <reference types="react" />
2
+ import type { ToastPropsShared } from "@metamask/design-system-shared";
3
+ import type { BannerBaseProps } from "../BannerBase/index.mjs";
4
+ import type { IconProps } from "../Icon/index.mjs";
5
+ type ToastCloseButtonProps = Omit<NonNullable<BannerBaseProps['closeButtonProps']>, 'onClick'>;
6
+ /**
7
+ * Props for the Toast visual component.
8
+ * Extends the platform BannerBase props with severity and an icon override.
9
+ * `onClose` is simplified to `() => void` (no MouseEvent) to align with the
10
+ * React Native API and the imperative `toast()` pattern.
11
+ */
12
+ export type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> & ToastPropsShared & {
13
+ /**
14
+ * Optional handler called when the close button is pressed.
15
+ * When provided, a close button is shown.
16
+ */
17
+ onClose?: () => void;
18
+ /**
19
+ * Optional props passed to the severity `Icon`.
20
+ * Only used when `severity` is not `Default` and `startAccessory` is not provided.
21
+ */
22
+ iconProps?: Omit<IconProps, 'name' | 'color'>;
23
+ /**
24
+ * Optional props for the close `ButtonIcon`.
25
+ * `ariaLabel` defaults to `'Close toast'`.
26
+ */
27
+ closeButtonProps?: ToastCloseButtonProps;
28
+ /**
29
+ * Optional test identifier forwarded to the root Toast element.
30
+ */
31
+ 'data-testid'?: string;
32
+ };
33
+ /**
34
+ * Options passed to the imperative `toast(...)` API.
35
+ */
36
+ export type ToastOptions = ToastProps & {
37
+ /**
38
+ * When true the toast stays visible until explicitly dismissed.
39
+ * Defaults to false.
40
+ */
41
+ hasNoTimeout?: boolean;
42
+ };
43
+ /**
44
+ * Imperative handle exposed by `<Toaster ref={...} />`.
45
+ */
46
+ export type ToasterRef = {
47
+ showToast: (options: ToastOptions) => void;
48
+ closeToast: () => void;
49
+ };
50
+ /**
51
+ * Props for the `<Toaster />` container component.
52
+ */
53
+ export type ToasterProps = {
54
+ /**
55
+ * Optional extra CSS classes applied to the fixed outer container.
56
+ */
57
+ className?: string;
58
+ } & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;
59
+ export {};
60
+ //# sourceMappingURL=Toast.types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast.types.d.mts","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,uCAAuC;AAEvE,OAAO,KAAK,EAAE,eAAe,EAAE,gCAAsB;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,0BAAgB;AAEzC,KAAK,qBAAqB,GAAG,IAAI,CAC/B,WAAW,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC,EAChD,SAAS,CACV,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,eAAe,EAAE,kBAAkB,GAAG,SAAS,CAAC,GAC5E,gBAAgB,GAAG;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;OAGG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC;IAC9C;;;OAGG;IACH,gBAAgB,CAAC,EAAE,qBAAqB,CAAC;IACzC;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,UAAU,GAAG;IACtC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3C,UAAU,EAAE,MAAM,IAAI,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=Toast.types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toast.types.mjs","sourceRoot":"","sources":["../../../src/components/Toast/Toast.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ToastPropsShared } from '@metamask/design-system-shared';\n\nimport type { BannerBaseProps } from '../BannerBase';\nimport type { IconProps } from '../Icon';\n\ntype ToastCloseButtonProps = Omit<\n NonNullable<BannerBaseProps['closeButtonProps']>,\n 'onClick'\n>;\n\n/**\n * Props for the Toast visual component.\n * Extends the platform BannerBase props with severity and an icon override.\n * `onClose` is simplified to `() => void` (no MouseEvent) to align with the\n * React Native API and the imperative `toast()` pattern.\n */\nexport type ToastProps = Omit<BannerBaseProps, 'closeButtonProps' | 'onClose'> &\n ToastPropsShared & {\n /**\n * Optional handler called when the close button is pressed.\n * When provided, a close button is shown.\n */\n onClose?: () => void;\n /**\n * Optional props passed to the severity `Icon`.\n * Only used when `severity` is not `Default` and `startAccessory` is not provided.\n */\n iconProps?: Omit<IconProps, 'name' | 'color'>;\n /**\n * Optional props for the close `ButtonIcon`.\n * `ariaLabel` defaults to `'Close toast'`.\n */\n closeButtonProps?: ToastCloseButtonProps;\n /**\n * Optional test identifier forwarded to the root Toast element.\n */\n 'data-testid'?: string;\n };\n\n/**\n * Options passed to the imperative `toast(...)` API.\n */\nexport type ToastOptions = ToastProps & {\n /**\n * When true the toast stays visible until explicitly dismissed.\n * Defaults to false.\n */\n hasNoTimeout?: boolean;\n};\n\n/**\n * Imperative handle exposed by `<Toaster ref={...} />`.\n */\nexport type ToasterRef = {\n showToast: (options: ToastOptions) => void;\n closeToast: () => void;\n};\n\n/**\n * Props for the `<Toaster />` container component.\n */\nexport type ToasterProps = {\n /**\n * Optional extra CSS classes applied to the fixed outer container.\n */\n className?: string;\n} & Omit<React.HTMLAttributes<HTMLDivElement>, 'style'>;\n"]}
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.toast = exports.Toaster = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ const tw_merge_1 = require("../../utils/tw-merge.cjs");
29
+ const Toast_1 = require("./Toast.cjs");
30
+ const Toast_constants_1 = require("./Toast.constants.cjs");
31
+ let storeToastOptions;
32
+ const toastStoreListeners = new Set();
33
+ const normalizeToastOptions = (options) => ({
34
+ hasNoTimeout: false,
35
+ ...options,
36
+ });
37
+ const emitToastStoreChange = () => {
38
+ toastStoreListeners.forEach((listener) => listener(storeToastOptions));
39
+ };
40
+ const setStoreToastOptions = (options) => {
41
+ storeToastOptions = normalizeToastOptions(options);
42
+ emitToastStoreChange();
43
+ };
44
+ const clearStoreToastOptions = () => {
45
+ storeToastOptions = undefined;
46
+ emitToastStoreChange();
47
+ };
48
+ const subscribeToToastStore = (listener) => {
49
+ toastStoreListeners.add(listener);
50
+ listener(storeToastOptions);
51
+ return () => {
52
+ toastStoreListeners.delete(listener);
53
+ };
54
+ };
55
+ const getToastProps = ({ hasNoTimeout: _hasNoTimeout, ...toastProps }) => toastProps;
56
+ const ToasterComponent = (0, react_1.forwardRef)(({ className, ...props }, ref) => {
57
+ const [toastOptions, setToastOptions] = (0, react_1.useState)(undefined);
58
+ const toastOptionsRef = (0, react_1.useRef)(undefined);
59
+ const [isVisible, setIsVisible] = (0, react_1.useState)(false);
60
+ const isVisibleRef = (0, react_1.useRef)(false);
61
+ const replacementTimerRef = (0, react_1.useRef)(null);
62
+ const autoDismissTimerRef = (0, react_1.useRef)(null);
63
+ const exitTimerRef = (0, react_1.useRef)(null);
64
+ const enterAnimationFrameRef = (0, react_1.useRef)(null);
65
+ const pendingToastRef = (0, react_1.useRef)(undefined);
66
+ const setCurrentToastOptions = (0, react_1.useCallback)((options) => {
67
+ toastOptionsRef.current = options;
68
+ setToastOptions(options);
69
+ }, []);
70
+ const setCurrentIsVisible = (0, react_1.useCallback)((nextIsVisible) => {
71
+ isVisibleRef.current = nextIsVisible;
72
+ setIsVisible(nextIsVisible);
73
+ }, []);
74
+ const clearPendingTimers = (0, react_1.useCallback)(() => {
75
+ if (replacementTimerRef.current !== null) {
76
+ clearTimeout(replacementTimerRef.current);
77
+ replacementTimerRef.current = null;
78
+ }
79
+ if (autoDismissTimerRef.current !== null) {
80
+ clearTimeout(autoDismissTimerRef.current);
81
+ autoDismissTimerRef.current = null;
82
+ }
83
+ if (exitTimerRef.current !== null) {
84
+ clearTimeout(exitTimerRef.current);
85
+ exitTimerRef.current = null;
86
+ }
87
+ if (enterAnimationFrameRef.current !== null) {
88
+ cancelAnimationFrame(enterAnimationFrameRef.current);
89
+ enterAnimationFrameRef.current = null;
90
+ }
91
+ }, []);
92
+ const closeRenderedToast = (0, react_1.useCallback)(() => {
93
+ if (!toastOptionsRef.current && !isVisibleRef.current) {
94
+ clearPendingTimers();
95
+ pendingToastRef.current = undefined;
96
+ return;
97
+ }
98
+ clearPendingTimers();
99
+ pendingToastRef.current = undefined;
100
+ setCurrentIsVisible(false);
101
+ exitTimerRef.current = setTimeout(() => {
102
+ exitTimerRef.current = null;
103
+ setCurrentToastOptions(undefined);
104
+ }, Toast_constants_1.TOAST_ANIMATION_DURATION);
105
+ }, [clearPendingTimers, setCurrentIsVisible, setCurrentToastOptions]);
106
+ // Replace the currently mounted toast rather than queueing multiple toasts.
107
+ // This mirrors the old app-level toast service behavior while keeping the
108
+ // imperative API centered in the shared single-toast store.
109
+ const showRenderedToast = (0, react_1.useCallback)((options) => {
110
+ const normalizedOptions = normalizeToastOptions(options);
111
+ const timeoutDuration = 0;
112
+ if (toastOptionsRef.current) {
113
+ pendingToastRef.current = normalizedOptions;
114
+ setCurrentIsVisible(false);
115
+ if (exitTimerRef.current !== null) {
116
+ clearTimeout(exitTimerRef.current);
117
+ exitTimerRef.current = null;
118
+ }
119
+ exitTimerRef.current = setTimeout(() => {
120
+ exitTimerRef.current = null;
121
+ setCurrentToastOptions(pendingToastRef.current);
122
+ pendingToastRef.current = undefined;
123
+ }, Toast_constants_1.TOAST_ANIMATION_DURATION);
124
+ return;
125
+ }
126
+ if (replacementTimerRef.current !== null) {
127
+ clearTimeout(replacementTimerRef.current);
128
+ }
129
+ replacementTimerRef.current = setTimeout(() => {
130
+ replacementTimerRef.current = null;
131
+ setCurrentToastOptions(normalizedOptions);
132
+ }, timeoutDuration);
133
+ }, [setCurrentIsVisible, setCurrentToastOptions]);
134
+ (0, react_1.useImperativeHandle)(ref, () => ({
135
+ closeToast: clearStoreToastOptions,
136
+ showToast: setStoreToastOptions,
137
+ }), []);
138
+ // Subscribe before sibling passive effects run so toast() can be called
139
+ // from anywhere once the app root has rendered <Toaster />.
140
+ (0, react_1.useLayoutEffect)(() => {
141
+ return subscribeToToastStore((options) => {
142
+ if (options) {
143
+ showRenderedToast(options);
144
+ return;
145
+ }
146
+ closeRenderedToast();
147
+ });
148
+ }, [closeRenderedToast, showRenderedToast]);
149
+ // Delay the enter transition until after mount so the DOM can paint the
150
+ // offscreen starting position before we slide the toast into view.
151
+ (0, react_1.useEffect)(() => {
152
+ if (toastOptions && !isVisible) {
153
+ enterAnimationFrameRef.current = requestAnimationFrame(() => {
154
+ enterAnimationFrameRef.current = requestAnimationFrame(() => {
155
+ setCurrentIsVisible(true);
156
+ enterAnimationFrameRef.current = null;
157
+ });
158
+ });
159
+ }
160
+ return () => {
161
+ clearPendingTimers();
162
+ };
163
+ }, [clearPendingTimers, setCurrentIsVisible, toastOptions]); // intentionally omit isVisible — only react to new toast options
164
+ // Auto-dismiss once the toast is visible, unless the caller requested a
165
+ // persistent toast.
166
+ (0, react_1.useEffect)(() => {
167
+ if (isVisible && toastOptions && !toastOptions.hasNoTimeout) {
168
+ autoDismissTimerRef.current = setTimeout(() => {
169
+ autoDismissTimerRef.current = null;
170
+ clearStoreToastOptions();
171
+ }, Toast_constants_1.TOAST_VISIBILITY_DURATION);
172
+ return () => {
173
+ clearPendingTimers();
174
+ };
175
+ }
176
+ return undefined;
177
+ }, [clearPendingTimers, isVisible, toastOptions]);
178
+ (0, react_1.useEffect)(() => {
179
+ return () => {
180
+ clearPendingTimers();
181
+ pendingToastRef.current = undefined;
182
+ toastOptionsRef.current = undefined;
183
+ isVisibleRef.current = false;
184
+ };
185
+ }, [clearPendingTimers]);
186
+ if (!toastOptions) {
187
+ return null;
188
+ }
189
+ const { onClose: toastOnClose, className: toastClassName, ...toastProps } = getToastProps(toastOptions);
190
+ return (react_1.default.createElement("div", { role: "status", "aria-live": "polite", "aria-atomic": "true", className: (0, tw_merge_1.twMerge)('pointer-events-none fixed inset-x-4 bottom-4 z-[1000] flex justify-center', className), ...props },
191
+ react_1.default.createElement("div", { className: "pointer-events-auto w-full transition-transform ease-in-out", style: {
192
+ transitionDuration: `${Toast_constants_1.TOAST_ANIMATION_DURATION}ms`,
193
+ transform: isVisible
194
+ ? 'translateY(0)'
195
+ : 'translateY(calc(100% + 16px))',
196
+ } },
197
+ react_1.default.createElement(Toast_1.Toast, { ...toastProps, className: toastClassName, onClose: () => {
198
+ clearStoreToastOptions();
199
+ toastOnClose?.();
200
+ } }))));
201
+ });
202
+ ToasterComponent.displayName = 'Toaster';
203
+ exports.Toaster = ToasterComponent;
204
+ exports.toast = ((options) => {
205
+ setStoreToastOptions(options);
206
+ });
207
+ exports.toast.dismiss = () => {
208
+ clearStoreToastOptions();
209
+ };
210
+ //# sourceMappingURL=Toaster.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toaster.cjs","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+CAQe;AAEf,uDAA+C;AAE/C,uCAAgC;AAChC,2DAG2B;AAU3B,IAAI,iBAA2C,CAAC;AAChD,MAAM,mBAAmB,GAAG,IAAI,GAAG,EAAsB,CAAC;AAE1D,MAAM,qBAAqB,GAAG,CAAC,OAAqB,EAAgB,EAAE,CAAC,CAAC;IACtE,YAAY,EAAE,KAAK;IACnB,GAAG,OAAO;CACX,CAAC,CAAC;AAEH,MAAM,oBAAoB,GAAG,GAAG,EAAE;IAChC,mBAAmB,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC;AACzE,CAAC,CAAC;AAEF,MAAM,oBAAoB,GAAG,CAAC,OAAqB,EAAE,EAAE;IACrD,iBAAiB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;IACnD,oBAAoB,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,sBAAsB,GAAG,GAAG,EAAE;IAClC,iBAAiB,GAAG,SAAS,CAAC;IAC9B,oBAAoB,EAAE,CAAC;AACzB,CAAC,CAAC;AAEF,MAAM,qBAAqB,GAAG,CAAC,QAA4B,EAAE,EAAE;IAC7D,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAClC,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IAE5B,OAAO,GAAG,EAAE;QACV,mBAAmB,CAAC,MAAM,CAAC,QAAQ,C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AC,CAAC,OAAqB,EAAE,EAAE;IAC9C,oBAAoB,CAAC,OAAO,CAAC,CAAC;AAChC,CAAC,CAAkB,CAAC;AAEpB,aAAK,CAAC,OAAO,GAAG,GAAG,EAAE;IACnB,sBAAsB,EAAE,CAAC;AAC3B,CAAC,CAAC","sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useImperativeHandle,\n useLayoutEffect,\n useRef,\n useState,\n} from 'react';\n\nimport { twMerge } from '../../utils/tw-merge';\n\nimport { Toast } from './Toast';\nimport {\n TOAST_ANIMATION_DURATION,\n TOAST_VISIBILITY_DURATION,\n} from './Toast.constants';\nimport type {\n ToastOptions,\n ToastProps,\n ToasterProps,\n ToasterRef,\n} from './Toast.types';\n\ntype ToastStoreListener = (options: ToastOptions | undefined) => void;\n\nlet storeToastOptions: ToastOptions | undefined;\nconst toastStoreListeners = new Set<ToastStoreListener>();\n\nconst normalizeToastOptions = (options: ToastOptions): ToastOptions => ({\n hasNoTimeout: false,\n ...options,\n});\n\nconst emitToastStoreChange = () => {\n toastStoreListeners.forEach((listener) => listener(storeToastOptions));\n};\n\nconst setStoreToastOptions = (options: ToastOptions) => {\n storeToastOptions = normalizeToastOptions(options);\n emitToastStoreChange();\n};\n\nconst clearStoreToastOptions = () => {\n storeToastOptions = undefined;\n emitToastStoreChange();\n};\n\nconst subscribeToToastStore = (listener: ToastStoreListener) => {\n toastStoreListeners.add(listener);\n listener(storeToastOptions);\n\n return () => {\n toastStoreListeners.delete(listener);\n };\n};\n\nconst getToastProps = ({\n hasNoTimeout: _hasNoTimeout,\n ...toastProps\n}: ToastOptions): ToastProps => toastProps;\n\nconst ToasterComponent = forwardRef<ToasterRef, ToasterProps>(\n ({ className, ...props }, ref) => {\n const [toastOptions, setToastOptions] = useState<ToastOptions | undefined>(\n undefined,\n );\n const toastOptionsRef = useRef<ToastOptions | undefined>(undefined);\n const [isVisible, setIsVisible] = useState(false);\n const isVisibleRef = useRef(false);\n const replacementTimerRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const autoDismissTimerRef = useRef<ReturnType<typeof setTimeout> | null>(\n null,\n );\n const exitTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);\n const enterAnimationFrameRef = useRef<number | null>(null);\n const pendingToastRef = useRef<ToastOptions | undefined>(undefined);\n\n const setCurrentToastOptions = useCallback(\n (options: ToastOptions | undefined) => {\n toastOptionsRef.current = options;\n setToastOptions(options);\n },\n [],\n );\n\n const setCurrentIsVisible = useCallback((nextIsVisible: boolean) => {\n isVisibleRef.current = nextIsVisible;\n setIsVisible(nextIsVisible);\n }, []);\n\n const clearPendingTimers = useCallback(() => {\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n replacementTimerRef.current = null;\n }\n if (autoDismissTimerRef.current !== null) {\n clearTimeout(autoDismissTimerRef.current);\n autoDismissTimerRef.current = null;\n }\n if (exitTimerRef.current !== null) {\n clearTimeout(exitTimerRef.current);\n exitTimerRef.current = null;\n }\n if (enterAnimationFrameRef.current !== null) {\n cancelAnimationFrame(enterAnimationFrameRef.current);\n enterAnimationFrameRef.current = null;\n }\n }, []);\n\n const closeRenderedToast = useCallback(() => {\n if (!toastOptionsRef.current && !isVisibleRef.current) {\n clearPendingTimers();\n pendingToastRef.current = undefined;\n return;\n }\n\n clearPendingTimers();\n pendingToastRef.current = undefined;\n setCurrentIsVisible(false);\n exitTimerRef.current = setTimeout(() => {\n exitTimerRef.current = null;\n setCurrentToastOptions(undefined);\n }, TOAST_ANIMATION_DURATION);\n }, [clearPendingTimers, setCurrentIsVisible, setCurrentToastOptions]);\n\n // Replace the currently mounted toast rather than queueing multiple toasts.\n // This mirrors the old app-level toast service behavior while keeping the\n // imperative API centered in the shared single-toast store.\n const showRenderedToast = useCallback(\n (options: ToastOptions) => {\n const normalizedOptions = normalizeToastOptions(options);\n const timeoutDuration = 0;\n\n if (toastOptionsRef.current) {\n pendingToastRef.current = normalizedOptions;\n setCurrentIsVisible(false);\n if (exitTimerRef.current !== null) {\n clearTimeout(exitTimerRef.current);\n exitTimerRef.current = null;\n }\n exitTimerRef.current = setTimeout(() => {\n exitTimerRef.current = null;\n setCurrentToastOptions(pendingToastRef.current);\n pendingToastRef.current = undefined;\n }, TOAST_ANIMATION_DURATION);\n return;\n }\n\n if (replacementTimerRef.current !== null) {\n clearTimeout(replacementTimerRef.current);\n }\n\n replacementTimerRef.current = setTimeout(() => {\n replacementTimerRef.current = null;\n setCurrentToastOptions(normalizedOptions);\n }, timeoutDuration);\n },\n [setCurrentIsVisible, setCurrentToastOptions],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n closeToast: clearStoreToastOptions,\n showToast: setStoreToastOptions,\n }),\n [],\n );\n\n // Subscribe before sibling passive effects run so toast() can be called\n // from anywhere once the app root has rendered <Toaster />.\n useLayoutEffect(() => {\n return subscribeToToastStore((options) => {\n if (options) {\n showRenderedToast(options);\n return;\n }\n\n closeRenderedToast();\n });\n }, [closeRenderedToast, showRenderedToast]);\n\n // Delay the enter transition until after mount so the DOM can paint the\n // offscreen starting position before we slide the toast into view.\n useEffect(() => {\n if (toastOptions && !isVisible) {\n enterAnimationFrameRef.current = requestAnimationFrame(() => {\n enterAnimationFrameRef.current = requestAnimationFrame(() => {\n setCurrentIsVisible(true);\n enterAnimationFrameRef.current = null;\n });\n });\n }\n return () => {\n clearPendingTimers();\n };\n }, [clearPendingTimers, setCurrentIsVisible, toastOptions]); // intentionally omit isVisible — only react to new toast options\n\n // Auto-dismiss once the toast is visible, unless the caller requested a\n // persistent toast.\n useEffect(() => {\n if (isVisible && toastOptions && !toastOptions.hasNoTimeout) {\n autoDismissTimerRef.current = setTimeout(() => {\n autoDismissTimerRef.current = null;\n clearStoreToastOptions();\n }, TOAST_VISIBILITY_DURATION);\n return () => {\n clearPendingTimers();\n };\n }\n return undefined;\n }, [clearPendingTimers, isVisible, toastOptions]);\n\n useEffect(() => {\n return () => {\n clearPendingTimers();\n pendingToastRef.current = undefined;\n toastOptionsRef.current = undefined;\n isVisibleRef.current = false;\n };\n }, [clearPendingTimers]);\n\n if (!toastOptions) {\n return null;\n }\n\n const {\n onClose: toastOnClose,\n className: toastClassName,\n ...toastProps\n } = getToastProps(toastOptions);\n\n return (\n <div\n role=\"status\"\n aria-live=\"polite\"\n aria-atomic=\"true\"\n className={twMerge(\n 'pointer-events-none fixed inset-x-4 bottom-4 z-[1000] flex justify-center',\n className,\n )}\n {...props}\n >\n <div\n className=\"pointer-events-auto w-full transition-transform ease-in-out\"\n style={{\n transitionDuration: `${TOAST_ANIMATION_DURATION}ms`,\n transform: isVisible\n ? 'translateY(0)'\n : 'translateY(calc(100% + 16px))',\n }}\n >\n <Toast\n {...toastProps}\n className={toastClassName}\n onClose={() => {\n clearStoreToastOptions();\n toastOnClose?.();\n }}\n />\n </div>\n </div>\n );\n },\n);\n\nToasterComponent.displayName = 'Toaster';\n\ntype ToastFunction = ((options: ToastOptions) => void) & {\n dismiss: () => void;\n};\n\nexport const Toaster = ToasterComponent;\n\nexport const toast = ((options: ToastOptions) => {\n setStoreToastOptions(options);\n}) as ToastFunction;\n\ntoast.dismiss = () => {\n clearStoreToastOptions();\n};\n"]}
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import type { ToastOptions, ToasterRef } from "./Toast.types.cjs";
3
+ type ToastFunction = ((options: ToastOptions) => void) & {
4
+ dismiss: () => void;
5
+ };
6
+ export declare const Toaster: React.ForwardRefExoticComponent<{
7
+ className?: string | undefined;
8
+ } & Omit<React.HTMLAttributes<HTMLDivElement>, "style"> & React.RefAttributes<ToasterRef>>;
9
+ export declare const toast: ToastFunction;
10
+ export {};
11
+ //# sourceMappingURL=Toaster.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toaster.d.cts","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":"AAAA,OAAO,KAQN,cAAc;AASf,OAAO,KAAK,EACV,YAAY,EAGZ,UAAU,EACX,0BAAsB;AAyPvB,KAAK,aAAa,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG;IACvD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,OAAO;;0FAAmB,CAAC;AAExC,eAAO,MAAM,KAAK,eAEC,CAAC"}
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import type { ToastOptions, ToasterRef } from "./Toast.types.mjs";
3
+ type ToastFunction = ((options: ToastOptions) => void) & {
4
+ dismiss: () => void;
5
+ };
6
+ export declare const Toaster: React.ForwardRefExoticComponent<{
7
+ className?: string | undefined;
8
+ } & Omit<React.HTMLAttributes<HTMLDivElement>, "style"> & React.RefAttributes<ToasterRef>>;
9
+ export declare const toast: ToastFunction;
10
+ export {};
11
+ //# sourceMappingURL=Toaster.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Toaster.d.mts","sourceRoot":"","sources":["../../../src/components/Toast/Toaster.tsx"],"names":[],"mappings":"AAAA,OAAO,KAQN,cAAc;AASf,OAAO,KAAK,EACV,YAAY,EAGZ,UAAU,EACX,0BAAsB;AAyPvB,KAAK,aAAa,GAAG,CAAC,CAAC,OAAO,EAAE,YAAY,KAAK,IAAI,CAAC,GAAG;IACvD,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAEF,eAAO,MAAM,OAAO;;0FAAmB,CAAC;AAExC,eAAO,MAAM,KAAK,eAEC,CAAC"}