@coinbase/cds-mcp-server 8.17.2 → 8.17.4

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 (284) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/mcp-docs/mobile/components/Accordion.txt +188 -0
  3. package/mcp-docs/mobile/components/AccordionItem.txt +29 -0
  4. package/mcp-docs/mobile/components/Alert.txt +155 -0
  5. package/mcp-docs/mobile/components/AreaChart.txt +265 -0
  6. package/mcp-docs/mobile/components/Avatar.txt +195 -0
  7. package/mcp-docs/mobile/components/AvatarButton.txt +225 -0
  8. package/mcp-docs/mobile/components/Banner.txt +221 -0
  9. package/mcp-docs/mobile/components/BarChart.txt +815 -0
  10. package/mcp-docs/mobile/components/Box.txt +173 -0
  11. package/mcp-docs/mobile/components/BrowserBar.txt +146 -0
  12. package/mcp-docs/mobile/components/Button.txt +198 -0
  13. package/mcp-docs/mobile/components/ButtonGroup.txt +79 -0
  14. package/mcp-docs/mobile/components/Carousel.txt +1083 -0
  15. package/mcp-docs/mobile/components/CartesianChart.txt +825 -0
  16. package/mcp-docs/mobile/components/CellMedia.txt +70 -0
  17. package/mcp-docs/mobile/components/Checkbox.txt +245 -0
  18. package/mcp-docs/mobile/components/CheckboxCell.txt +201 -0
  19. package/mcp-docs/mobile/components/CheckboxGroup.txt +284 -0
  20. package/mcp-docs/mobile/components/Chip.txt +194 -0
  21. package/mcp-docs/mobile/components/Coachmark.txt +157 -0
  22. package/mcp-docs/mobile/components/Collapsible.txt +104 -0
  23. package/mcp-docs/mobile/components/ContainedAssetCard.txt +134 -0
  24. package/mcp-docs/mobile/components/ContentCard.txt +365 -0
  25. package/mcp-docs/mobile/components/ContentCardBody.txt +135 -0
  26. package/mcp-docs/mobile/components/ContentCardFooter.txt +127 -0
  27. package/mcp-docs/mobile/components/ContentCardHeader.txt +145 -0
  28. package/mcp-docs/mobile/components/ContentCell.txt +226 -0
  29. package/mcp-docs/mobile/components/ControlGroup.txt +443 -0
  30. package/mcp-docs/mobile/components/DatePicker.txt +496 -0
  31. package/mcp-docs/mobile/components/Divider.txt +138 -0
  32. package/mcp-docs/mobile/components/DotCount.txt +145 -0
  33. package/mcp-docs/mobile/components/DotStatusColor.txt +58 -0
  34. package/mcp-docs/mobile/components/DotSymbol.txt +134 -0
  35. package/mcp-docs/mobile/components/Fallback.txt +157 -0
  36. package/mcp-docs/mobile/components/FloatingAssetCard.txt +155 -0
  37. package/mcp-docs/mobile/components/HStack.txt +234 -0
  38. package/mcp-docs/mobile/components/HeroSquare.txt +47 -0
  39. package/mcp-docs/mobile/components/Icon.txt +51 -0
  40. package/mcp-docs/mobile/components/IconButton.txt +268 -0
  41. package/mcp-docs/mobile/components/InputChip.txt +187 -0
  42. package/mcp-docs/mobile/components/Interactable.txt +186 -0
  43. package/mcp-docs/mobile/components/LineChart.txt +1324 -0
  44. package/mcp-docs/mobile/components/Link.txt +291 -0
  45. package/mcp-docs/mobile/components/ListCell.txt +412 -0
  46. package/mcp-docs/mobile/components/LogoMark.txt +84 -0
  47. package/mcp-docs/mobile/components/LogoWordMark.txt +93 -0
  48. package/mcp-docs/mobile/components/Lottie.txt +138 -0
  49. package/mcp-docs/mobile/components/LottieStatusAnimation.txt +46 -0
  50. package/mcp-docs/mobile/components/Modal.txt +83 -0
  51. package/mcp-docs/mobile/components/ModalBody.txt +33 -0
  52. package/mcp-docs/mobile/components/ModalFooter.txt +24 -0
  53. package/mcp-docs/mobile/components/ModalHeader.txt +27 -0
  54. package/mcp-docs/mobile/components/MultiContentModule.txt +379 -0
  55. package/mcp-docs/mobile/components/NavigationTitle.txt +131 -0
  56. package/mcp-docs/mobile/components/NavigationTitleSelect.txt +141 -0
  57. package/mcp-docs/mobile/components/NudgeCard.txt +89 -0
  58. package/mcp-docs/mobile/components/Numpad.txt +340 -0
  59. package/mcp-docs/mobile/components/Overlay.txt +151 -0
  60. package/mcp-docs/mobile/components/PageFooter.txt +160 -0
  61. package/mcp-docs/mobile/components/PageHeader.txt +185 -0
  62. package/mcp-docs/mobile/components/PeriodSelector.txt +407 -0
  63. package/mcp-docs/mobile/components/Pictogram.txt +47 -0
  64. package/mcp-docs/mobile/components/Point.txt +204 -0
  65. package/mcp-docs/mobile/components/PortalProvider.txt +78 -0
  66. package/mcp-docs/mobile/components/Pressable.txt +210 -0
  67. package/mcp-docs/mobile/components/ProgressBar.txt +129 -0
  68. package/mcp-docs/mobile/components/ProgressBarWithFixedLabels.txt +160 -0
  69. package/mcp-docs/mobile/components/ProgressBarWithFloatLabel.txt +137 -0
  70. package/mcp-docs/mobile/components/ProgressCircle.txt +236 -0
  71. package/mcp-docs/mobile/components/Radio.txt +241 -0
  72. package/mcp-docs/mobile/components/RadioCell.txt +201 -0
  73. package/mcp-docs/mobile/components/RadioGroup.txt +281 -0
  74. package/mcp-docs/mobile/components/ReferenceLine.txt +152 -0
  75. package/mcp-docs/mobile/components/RemoteImage.txt +105 -0
  76. package/mcp-docs/mobile/components/RemoteImageGroup.txt +60 -0
  77. package/mcp-docs/mobile/components/RollingNumber.txt +788 -0
  78. package/mcp-docs/mobile/components/Scrubber.txt +203 -0
  79. package/mcp-docs/mobile/components/SearchInput.txt +191 -0
  80. package/mcp-docs/mobile/components/SectionHeader.txt +204 -0
  81. package/mcp-docs/mobile/components/SegmentedTabs.txt +315 -0
  82. package/mcp-docs/mobile/components/Select.txt +211 -0
  83. package/mcp-docs/mobile/components/SelectChip.txt +323 -0
  84. package/mcp-docs/mobile/components/SelectOption.txt +84 -0
  85. package/mcp-docs/mobile/components/SlideButton.txt +330 -0
  86. package/mcp-docs/mobile/components/Spacer.txt +83 -0
  87. package/mcp-docs/mobile/components/Sparkline.txt +122 -0
  88. package/mcp-docs/mobile/components/SparklineGradient.txt +106 -0
  89. package/mcp-docs/mobile/components/SparklineInteractive.txt +156 -0
  90. package/mcp-docs/mobile/components/SparklineInteractiveHeader.txt +72 -0
  91. package/mcp-docs/mobile/components/Spinner.txt +48 -0
  92. package/mcp-docs/mobile/components/SpotIcon.txt +47 -0
  93. package/mcp-docs/mobile/components/SpotRectangle.txt +47 -0
  94. package/mcp-docs/mobile/components/SpotSquare.txt +47 -0
  95. package/mcp-docs/mobile/components/Stepper.txt +527 -0
  96. package/mcp-docs/mobile/components/SubBrandLogoMark.txt +125 -0
  97. package/mcp-docs/mobile/components/SubBrandLogoWordMark.txt +125 -0
  98. package/mcp-docs/mobile/components/Switch.txt +97 -0
  99. package/mcp-docs/mobile/components/TabIndicator.txt +48 -0
  100. package/mcp-docs/mobile/components/TabLabel.txt +153 -0
  101. package/mcp-docs/mobile/components/TabNavigation.txt +146 -0
  102. package/mcp-docs/mobile/components/TabbedChips.txt +142 -0
  103. package/mcp-docs/mobile/components/Tabs.txt +190 -0
  104. package/mcp-docs/mobile/components/Tag.txt +300 -0
  105. package/mcp-docs/mobile/components/Text.txt +211 -0
  106. package/mcp-docs/mobile/components/TextInput.txt +717 -0
  107. package/mcp-docs/mobile/components/ThemeProvider.txt +132 -0
  108. package/mcp-docs/mobile/components/Toast.txt +196 -0
  109. package/mcp-docs/mobile/components/Tooltip.txt +59 -0
  110. package/mcp-docs/mobile/components/TopNavBar.txt +161 -0
  111. package/mcp-docs/mobile/components/Tour.txt +158 -0
  112. package/mcp-docs/mobile/components/Tray.txt +252 -0
  113. package/mcp-docs/mobile/components/UpsellCard.txt +321 -0
  114. package/mcp-docs/mobile/components/VStack.txt +222 -0
  115. package/mcp-docs/mobile/components/XAxis.txt +621 -0
  116. package/mcp-docs/mobile/components/YAxis.txt +567 -0
  117. package/mcp-docs/mobile/getting-started/ai-overview.txt +108 -0
  118. package/mcp-docs/mobile/getting-started/installation.txt +57 -0
  119. package/mcp-docs/mobile/getting-started/introduction.txt +102 -0
  120. package/mcp-docs/mobile/getting-started/playground.txt +28 -0
  121. package/mcp-docs/mobile/getting-started/styling.txt +84 -0
  122. package/mcp-docs/mobile/getting-started/theming.txt +286 -0
  123. package/mcp-docs/mobile/hooks/useDimensions.txt +72 -0
  124. package/mcp-docs/mobile/hooks/useEventHandler.txt +120 -0
  125. package/mcp-docs/mobile/hooks/useMergeRefs.txt +116 -0
  126. package/mcp-docs/mobile/hooks/useOverlayContentContext.txt +280 -0
  127. package/mcp-docs/mobile/hooks/usePreviousValue.txt +74 -0
  128. package/mcp-docs/mobile/hooks/useRefMap.txt +178 -0
  129. package/mcp-docs/mobile/hooks/useTheme.txt +321 -0
  130. package/mcp-docs/mobile/routes.txt +139 -0
  131. package/mcp-docs/web/components/Accordion.txt +189 -0
  132. package/mcp-docs/web/components/AccordionItem.txt +31 -0
  133. package/mcp-docs/web/components/Alert.txt +164 -0
  134. package/mcp-docs/web/components/AreaChart.txt +510 -0
  135. package/mcp-docs/web/components/Avatar.txt +211 -0
  136. package/mcp-docs/web/components/AvatarButton.txt +240 -0
  137. package/mcp-docs/web/components/Banner.txt +226 -0
  138. package/mcp-docs/web/components/BarChart.txt +1267 -0
  139. package/mcp-docs/web/components/Box.txt +175 -0
  140. package/mcp-docs/web/components/Button.txt +212 -0
  141. package/mcp-docs/web/components/ButtonGroup.txt +79 -0
  142. package/mcp-docs/web/components/Calendar.txt +181 -0
  143. package/mcp-docs/web/components/Carousel.txt +1575 -0
  144. package/mcp-docs/web/components/CartesianChart.txt +1044 -0
  145. package/mcp-docs/web/components/CellMedia.txt +56 -0
  146. package/mcp-docs/web/components/Checkbox.txt +188 -0
  147. package/mcp-docs/web/components/CheckboxCell.txt +202 -0
  148. package/mcp-docs/web/components/CheckboxGroup.txt +219 -0
  149. package/mcp-docs/web/components/Chip.txt +196 -0
  150. package/mcp-docs/web/components/Coachmark.txt +188 -0
  151. package/mcp-docs/web/components/Collapsible.txt +119 -0
  152. package/mcp-docs/web/components/ContainedAssetCard.txt +232 -0
  153. package/mcp-docs/web/components/ContentCard.txt +367 -0
  154. package/mcp-docs/web/components/ContentCardBody.txt +137 -0
  155. package/mcp-docs/web/components/ContentCardFooter.txt +129 -0
  156. package/mcp-docs/web/components/ContentCardHeader.txt +147 -0
  157. package/mcp-docs/web/components/ContentCell.txt +219 -0
  158. package/mcp-docs/web/components/ControlGroup.txt +436 -0
  159. package/mcp-docs/web/components/DatePicker.txt +505 -0
  160. package/mcp-docs/web/components/Divider.txt +143 -0
  161. package/mcp-docs/web/components/DotCount.txt +149 -0
  162. package/mcp-docs/web/components/DotStatusColor.txt +58 -0
  163. package/mcp-docs/web/components/DotSymbol.txt +137 -0
  164. package/mcp-docs/web/components/Dropdown.txt +119 -0
  165. package/mcp-docs/web/components/Fallback.txt +163 -0
  166. package/mcp-docs/web/components/FloatingAssetCard.txt +250 -0
  167. package/mcp-docs/web/components/FullscreenAlert.txt +69 -0
  168. package/mcp-docs/web/components/FullscreenModal.txt +145 -0
  169. package/mcp-docs/web/components/FullscreenModalLayout.txt +187 -0
  170. package/mcp-docs/web/components/Grid.txt +236 -0
  171. package/mcp-docs/web/components/GridColumn.txt +209 -0
  172. package/mcp-docs/web/components/HStack.txt +236 -0
  173. package/mcp-docs/web/components/HeroSquare.txt +48 -0
  174. package/mcp-docs/web/components/Icon.txt +145 -0
  175. package/mcp-docs/web/components/IconButton.txt +390 -0
  176. package/mcp-docs/web/components/InputChip.txt +187 -0
  177. package/mcp-docs/web/components/Interactable.txt +193 -0
  178. package/mcp-docs/web/components/LineChart.txt +1576 -0
  179. package/mcp-docs/web/components/Link.txt +243 -0
  180. package/mcp-docs/web/components/ListCell.txt +418 -0
  181. package/mcp-docs/web/components/LogoMark.txt +84 -0
  182. package/mcp-docs/web/components/LogoWordMark.txt +93 -0
  183. package/mcp-docs/web/components/Lottie.txt +157 -0
  184. package/mcp-docs/web/components/LottieStatusAnimation.txt +57 -0
  185. package/mcp-docs/web/components/MediaQueryProvider.txt +108 -0
  186. package/mcp-docs/web/components/Modal.txt +196 -0
  187. package/mcp-docs/web/components/ModalBody.txt +117 -0
  188. package/mcp-docs/web/components/ModalFooter.txt +119 -0
  189. package/mcp-docs/web/components/ModalHeader.txt +123 -0
  190. package/mcp-docs/web/components/MultiContentModule.txt +381 -0
  191. package/mcp-docs/web/components/NavigationBar.txt +102 -0
  192. package/mcp-docs/web/components/NavigationTitle.txt +25 -0
  193. package/mcp-docs/web/components/NavigationTitleSelect.txt +45 -0
  194. package/mcp-docs/web/components/NudgeCard.txt +181 -0
  195. package/mcp-docs/web/components/Overlay.txt +171 -0
  196. package/mcp-docs/web/components/PageFooter.txt +184 -0
  197. package/mcp-docs/web/components/PageHeader.txt +243 -0
  198. package/mcp-docs/web/components/Pagination.txt +499 -0
  199. package/mcp-docs/web/components/PeriodSelector.txt +703 -0
  200. package/mcp-docs/web/components/Pictogram.txt +48 -0
  201. package/mcp-docs/web/components/Point.txt +460 -0
  202. package/mcp-docs/web/components/PortalProvider.txt +76 -0
  203. package/mcp-docs/web/components/Pressable.txt +193 -0
  204. package/mcp-docs/web/components/ProgressBar.txt +163 -0
  205. package/mcp-docs/web/components/ProgressBarWithFixedLabels.txt +212 -0
  206. package/mcp-docs/web/components/ProgressBarWithFloatLabel.txt +181 -0
  207. package/mcp-docs/web/components/ProgressCircle.txt +443 -0
  208. package/mcp-docs/web/components/Radio.txt +219 -0
  209. package/mcp-docs/web/components/RadioCell.txt +215 -0
  210. package/mcp-docs/web/components/RadioGroup.txt +288 -0
  211. package/mcp-docs/web/components/ReferenceLine.txt +451 -0
  212. package/mcp-docs/web/components/RemoteImage.txt +165 -0
  213. package/mcp-docs/web/components/RemoteImageGroup.txt +86 -0
  214. package/mcp-docs/web/components/RollingNumber.txt +1021 -0
  215. package/mcp-docs/web/components/Scrubber.txt +231 -0
  216. package/mcp-docs/web/components/SearchInput.txt +117 -0
  217. package/mcp-docs/web/components/SectionHeader.txt +217 -0
  218. package/mcp-docs/web/components/SegmentedTabs.txt +324 -0
  219. package/mcp-docs/web/components/Select.txt +224 -0
  220. package/mcp-docs/web/components/SelectChip.txt +314 -0
  221. package/mcp-docs/web/components/SelectOption.txt +165 -0
  222. package/mcp-docs/web/components/Sidebar.txt +349 -0
  223. package/mcp-docs/web/components/SidebarItem.txt +131 -0
  224. package/mcp-docs/web/components/SidebarMoreMenu.txt +30 -0
  225. package/mcp-docs/web/components/Spacer.txt +173 -0
  226. package/mcp-docs/web/components/Sparkline.txt +122 -0
  227. package/mcp-docs/web/components/SparklineGradient.txt +106 -0
  228. package/mcp-docs/web/components/SparklineInteractive.txt +153 -0
  229. package/mcp-docs/web/components/SparklineInteractiveHeader.txt +76 -0
  230. package/mcp-docs/web/components/Spinner.txt +128 -0
  231. package/mcp-docs/web/components/SpotIcon.txt +48 -0
  232. package/mcp-docs/web/components/SpotRectangle.txt +48 -0
  233. package/mcp-docs/web/components/SpotSquare.txt +48 -0
  234. package/mcp-docs/web/components/Stepper.txt +682 -0
  235. package/mcp-docs/web/components/SubBrandLogoMark.txt +125 -0
  236. package/mcp-docs/web/components/SubBrandLogoWordMark.txt +125 -0
  237. package/mcp-docs/web/components/Switch.txt +85 -0
  238. package/mcp-docs/web/components/TabIndicator.txt +48 -0
  239. package/mcp-docs/web/components/TabLabel.txt +158 -0
  240. package/mcp-docs/web/components/TabNavigation.txt +159 -0
  241. package/mcp-docs/web/components/TabbedChips.txt +155 -0
  242. package/mcp-docs/web/components/Table.txt +367 -0
  243. package/mcp-docs/web/components/TableBody.txt +83 -0
  244. package/mcp-docs/web/components/TableCaption.txt +102 -0
  245. package/mcp-docs/web/components/TableCell.txt +165 -0
  246. package/mcp-docs/web/components/TableCellFallback.txt +97 -0
  247. package/mcp-docs/web/components/TableFooter.txt +83 -0
  248. package/mcp-docs/web/components/TableHeader.txt +100 -0
  249. package/mcp-docs/web/components/TableRow.txt +140 -0
  250. package/mcp-docs/web/components/Tabs.txt +212 -0
  251. package/mcp-docs/web/components/Tag.txt +304 -0
  252. package/mcp-docs/web/components/Text.txt +232 -0
  253. package/mcp-docs/web/components/TextInput.txt +652 -0
  254. package/mcp-docs/web/components/ThemeProvider.txt +199 -0
  255. package/mcp-docs/web/components/TileButton.txt +158 -0
  256. package/mcp-docs/web/components/Toast.txt +203 -0
  257. package/mcp-docs/web/components/Tooltip.txt +89 -0
  258. package/mcp-docs/web/components/Tour.txt +179 -0
  259. package/mcp-docs/web/components/Tray.txt +288 -0
  260. package/mcp-docs/web/components/UpsellCard.txt +319 -0
  261. package/mcp-docs/web/components/VStack.txt +224 -0
  262. package/mcp-docs/web/components/XAxis.txt +619 -0
  263. package/mcp-docs/web/components/YAxis.txt +548 -0
  264. package/mcp-docs/web/getting-started/ai-overview.txt +108 -0
  265. package/mcp-docs/web/getting-started/installation.txt +103 -0
  266. package/mcp-docs/web/getting-started/introduction.txt +102 -0
  267. package/mcp-docs/web/getting-started/playground.txt +28 -0
  268. package/mcp-docs/web/getting-started/styling.txt +161 -0
  269. package/mcp-docs/web/getting-started/templates.txt +121 -0
  270. package/mcp-docs/web/getting-started/theming.txt +426 -0
  271. package/mcp-docs/web/hooks/useBreakpoints.txt +61 -0
  272. package/mcp-docs/web/hooks/useDimensions.txt +114 -0
  273. package/mcp-docs/web/hooks/useEventHandler.txt +120 -0
  274. package/mcp-docs/web/hooks/useHasMounted.txt +75 -0
  275. package/mcp-docs/web/hooks/useIsoEffect.txt +58 -0
  276. package/mcp-docs/web/hooks/useMediaQuery.txt +114 -0
  277. package/mcp-docs/web/hooks/useMergeRefs.txt +116 -0
  278. package/mcp-docs/web/hooks/useOverlayContentContext.txt +279 -0
  279. package/mcp-docs/web/hooks/usePreviousValue.txt +74 -0
  280. package/mcp-docs/web/hooks/useRefMap.txt +178 -0
  281. package/mcp-docs/web/hooks/useScrollBlocker.txt +82 -0
  282. package/mcp-docs/web/hooks/useTheme.txt +364 -0
  283. package/mcp-docs/web/routes.txt +163 -0
  284. package/package.json +1 -1
@@ -0,0 +1,120 @@
1
+ # useEventHandler
2
+
3
+ Creates event handlers for components based on the EventHandlerProvider configuration. It enables centralized event handling and analytics tracking by mapping component actions to configured handlers.
4
+
5
+ ## Import
6
+
7
+ ```tsx
8
+ import { useEventHandler } from '@coinbase/cds-common/hooks/useEventHandler'
9
+ ```
10
+
11
+ ## API
12
+
13
+ :::warning
14
+ Must be used within an EventHandlerProvider. The provider's configuration determines which events are handled and how they are processed. The provider config should include:
15
+
16
+ - `actionMapping?: Record<string, string>` - Optional mapping of CDS actions to handler actions
17
+ - `handlers?: Record<EventHandlerComponent, Record<string, (eventData: EventCallbackProps) => void>>` - Event handlers for components
18
+
19
+ :::
20
+
21
+ ### Parameters
22
+
23
+ ```tsx
24
+ type EventDataEntryTypes = string | number | boolean | null | undefined;
25
+ type EventDataEntry = EventDataEntryTypes | EventDataEntryTypes[];
26
+ type RecursiveMapType<T> = T | Record<string, T>;
27
+
28
+ type EventHandlerComponent = 'Button';
29
+ type EventHandlerAction = string;
30
+ type EventCustomData = Record<string, RecursiveMapType<EventDataEntry>>;
31
+
32
+ type EventHandlerCustomConfig = {
33
+ componentName: string;
34
+ actions: EventHandlerAction[];
35
+ data?: EventCustomData;
36
+ };
37
+
38
+ function useEventHandler(
39
+ component: EventHandlerComponent,
40
+ action: EventHandlerAction,
41
+ eventConfig?: EventHandlerCustomConfig,
42
+ analyticsId?: string,
43
+ ): () => void;
44
+ ```
45
+
46
+ - `component`: The component type to handle events for (currently supports 'Button')
47
+ - `action`: The action type to handle (e.g., 'onClick', 'onHover'). This is a string type that can be mapped to custom handler actions.
48
+ - `eventConfig` (optional): Configuration object for the event:
49
+ - `componentName`: Name of the component for tracking purposes
50
+ - `actions`: List of actions to track
51
+ - `data`: Additional data to pass to the handler
52
+ - `analyticsId` (optional): A unique identifier for analytics tracking that takes precedence over eventConfig
53
+
54
+ ### Returns
55
+
56
+ ```tsx
57
+ type EventCallbackProps = {
58
+ componentName?: string;
59
+ analyticsId?: string;
60
+ data?: EventCustomData;
61
+ };
62
+
63
+ type Return = () => void;
64
+ ```
65
+
66
+ Returns a callback function that when invoked will trigger the event handling. The function:
67
+
68
+ - Executes the configured handler for the component and action when called
69
+ - Maps CDS actions to custom handler actions if `actionMapping` is provided in the EventHandlerProvider
70
+ - Returns a no-op function if:
71
+ - No handlers are configured
72
+ - No eventConfig actions are provided and no analyticsId is set
73
+ - The handler for the component doesn't exist
74
+ - The action is not listed in eventConfig actions (when using eventConfig)
75
+ - The params object is empty
76
+
77
+ ## Examples
78
+
79
+ ### Usage
80
+
81
+ ```tsx live
82
+ function ExampleWithProvider() {
83
+ const { show: showToast } = useToast();
84
+
85
+ // Example provider configuration with action mapping
86
+ const config = {
87
+ actionMapping: {
88
+ onClick: 'click', // Maps CDS onClick to custom 'click' handler
89
+ },
90
+ handlers: {
91
+ Button: {
92
+ click: ({ componentName, data }) => {
93
+ showToast(`Button ${componentName} clicked with data: ${JSON.stringify(data)}`);
94
+ },
95
+ },
96
+ },
97
+ };
98
+
99
+ function ButtonExample() {
100
+ const eventConfig = {
101
+ actions: ['click'], // Use mapped action name
102
+ componentName: 'mapped_button',
103
+ data: {
104
+ source: 'action_mapping_example',
105
+ },
106
+ };
107
+
108
+ const handleButtonClick = useEventHandler('Button', 'onClick', eventConfig);
109
+
110
+ return <Button onClick={handleButtonClick}>Click for Mapped Action</Button>;
111
+ }
112
+
113
+ return (
114
+ <EventHandlerProvider config={config}>
115
+ <ButtonExample />
116
+ </EventHandlerProvider>
117
+ );
118
+ }
119
+ ```
120
+
@@ -0,0 +1,75 @@
1
+ # useHasMounted
2
+
3
+ Returns a boolean indicating if the component has mounted.
4
+
5
+ ## Import
6
+
7
+ ```tsx
8
+ import { useHasMounted } from '@coinbase/cds-web/hooks/useHasMounted'
9
+ ```
10
+
11
+ ## API
12
+
13
+ ### Parameters
14
+
15
+ The `useHasMounted` hook does not accept any parameters.
16
+
17
+ ### Returns
18
+
19
+ ```tsx
20
+ type Return = boolean;
21
+ ```
22
+
23
+ Returns a boolean:
24
+
25
+ - `true`: Component has mounted and is running in a browser environment
26
+ - `false`: Component hasn't mounted yet or is running in a non-browser environment (e.g., server-side rendering)
27
+
28
+ :::tip
29
+ This hook is useful for preventing hydration mismatches and ensuring code only runs in the browser environment.
30
+ :::
31
+
32
+ ## Examples
33
+
34
+ `useHasMounted` should be used when conditionally rendering components or styles in SSR or SSG environments.
35
+
36
+ We recommend using `useHasMounted` whenever you use [useBreakpoints](/hooks/useBreakpoints) or any other hooks that rely on the window object to conditionally render content. This combination can be used to prevent cumulative layout shifts (CLS). This is called two pass rendering and ensures that the component has been mounted and the window object is present before painting the DOM.
37
+
38
+ ```jsx
39
+ const { isPhone } = useBreakpoints();
40
+ const hasMounted = useHasMounted();
41
+
42
+ // in component render
43
+ {
44
+ hasMounted && isPhone && <TextHeadline as="h3">Welcome {username}!</TextHeadline>;
45
+ }
46
+ ```
47
+
48
+ ### Basic usage
49
+
50
+ ```tsx live
51
+ function Example() {
52
+ const hasMounted = useHasMounted();
53
+
54
+ return <TextHeadline>Component has {hasMounted ? 'mounted' : 'not mounted'}</TextHeadline>;
55
+ }
56
+ ```
57
+
58
+ ### Preventing Hydration Mismatch
59
+
60
+ ```tsx live
61
+ function Example() {
62
+ const hasMounted = useHasMounted();
63
+ const [currentTime, setCurrentTime] = useState('');
64
+
65
+ useEffect(() => {
66
+ // Only run client-side code after mounting
67
+ if (hasMounted) {
68
+ setCurrentTime(new Date().toLocaleTimeString());
69
+ }
70
+ }, [hasMounted]);
71
+
72
+ return <TextHeadline>{hasMounted ? `Current time: ${currentTime}` : 'Loading...'}</TextHeadline>;
73
+ }
74
+ ```
75
+
@@ -0,0 +1,58 @@
1
+ # useIsoEffect
2
+
3
+ A safe way of calling useLayoutEffect only on the client. Does nothing on the server.
4
+
5
+ ## Import
6
+
7
+ ```tsx
8
+ import { useIsoEffect } from '@coinbase/cds-web/hooks/useIsoEffect'
9
+ ```
10
+
11
+ ## API
12
+
13
+ ### Parameters
14
+
15
+ The `useIsoEffect` hook accepts the same parameters as React's `useEffect` and `useLayoutEffect`:
16
+
17
+ - `effect: () => (void | (() => void))` - The effect function to run
18
+ - `deps?: any[]` - Optional array of dependencies
19
+
20
+ ### Returns
21
+
22
+ Returns nothing (void).
23
+
24
+ :::tip
25
+ This hook automatically uses `useLayoutEffect` when running in the browser and falls back to `useEffect` during server-side rendering. This prevents warnings and ensures proper timing of effects across different environments.
26
+ :::
27
+
28
+ ## Examples
29
+
30
+ ### Usage
31
+
32
+ ```tsx live
33
+ function Example() {
34
+ const [position, setPosition] = useState({ x: 0, y: 0 });
35
+
36
+ useIsoEffect(() => {
37
+ const updatePosition = (e: MouseEvent) => {
38
+ setPosition({ x: e.clientX, y: e.clientY });
39
+ };
40
+
41
+ window.addEventListener('mousemove', updatePosition);
42
+
43
+ // Cleanup function to remove event listener
44
+ return () => {
45
+ window.removeEventListener('mousemove', updatePosition);
46
+ };
47
+ }, []); // Empty deps array means this effect runs once on mount
48
+
49
+ return (
50
+ <VStack gap={2}>
51
+ <TextHeadline>Mouse Position</TextHeadline>
52
+ <Text>X: {position.x}</Text>
53
+ <Text>Y: {position.y}</Text>
54
+ </VStack>
55
+ );
56
+ }
57
+ ```
58
+
@@ -0,0 +1,114 @@
1
+ # useMediaQuery
2
+
3
+ Subscribes to window.matchMedia changes with SSR support.
4
+
5
+ ## Import
6
+
7
+ ```tsx
8
+ import { useMediaQuery } from '@coinbase/cds-web/hooks/useMediaQuery'
9
+ ```
10
+
11
+ ## API
12
+
13
+ ### Parameters
14
+
15
+ The `useMediaQuery` hook accepts a single parameter:
16
+
17
+ - `query: string` - A CSS media query string to subscribe to. Can include:
18
+ - **Viewport dimensions**: `(min-width: 768px)`, `(max-width: 767px)`, `(width: 1024px)`
19
+ - **User preferences**: `(prefers-color-scheme: dark)`, `(prefers-reduced-motion: reduce)`
20
+ - **Device features**: `(orientation: portrait)`, `(pointer: coarse)`, `(hover: hover)`
21
+ - **Complex queries**: Combined with `and`, `not`, or `,` operators
22
+
23
+ ### Returns
24
+
25
+ Returns a `boolean` that indicates whether the media query matches:
26
+
27
+ - `true` - The media query conditions are currently met
28
+ - `false` - The media query conditions are not met
29
+ - Automatically updates when the media query state changes
30
+ - Uses MediaQueryProvider's default values during server-side rendering
31
+
32
+ ## Examples
33
+
34
+ ### Basic usage
35
+
36
+ Use the `useMediaQuery` hook to call `window.matchMedia` with SSR support. It must be used within a MediaQueryProvider component.
37
+
38
+ This hook is ideal for conditional rendering based on viewport size, user preferences, or other media features.
39
+
40
+ It subscribes to a single state shared by all media queries to ensure Suspense works correctly.
41
+
42
+ [See the MediaQueryProvider docs here &rarr;](/components/other/MediaQueryProvider)
43
+
44
+ :::warning
45
+ Do not use `useMediaQuery` for responsive styles. Use CSS media queries or [the `StyleProps` API](/getting-started/styling#responsive-styles) for responsive styles.
46
+ :::
47
+
48
+ ```tsx live
49
+ () => {
50
+ const Page = () => {
51
+ const isMobile = useMediaQuery('(max-width: 767px)');
52
+ const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)');
53
+ return <JSONCodeBlock json={{ isMobile, prefersDarkMode }} />;
54
+ };
55
+
56
+ const App = () => (
57
+ <MediaQueryProvider>
58
+ <Page />
59
+ </MediaQueryProvider>
60
+ );
61
+
62
+ return <App />;
63
+ };
64
+ ```
65
+
66
+ ### SSR support
67
+
68
+ The `useMediaQuery` hook integrates with the MediaQueryProvider `defaultValues` to provide consistent behavior between server and client rendering.
69
+
70
+ On the client the native `window.matchMedia` API is used. On the server the hook solves the `window.matchMedia` queries by comparing to the MediaQueryProvider `defaultValues`.
71
+
72
+ The comparison against `defaultValues` during SSR is limited: it cannot solve highly complex media queries. If a complex query cannot be solved during SSR the hook will simply return `false`, and the query can still be solved by `window.matchMedia` on the client.
73
+
74
+ :::tip
75
+ You can populate the MediaQueryProvider `defaultValues` with user preferences, cookies, etc. to ensure the correct styles are applied on the server.
76
+ :::
77
+
78
+ #### Simple queries that can be solved during SSR
79
+
80
+ - Simple media queries
81
+ - `width`, `min-width`, `max-width`, `height`, `min-height`, and `max-height` with pixel or em units
82
+ - `prefers-contrast` and `prefers-color-scheme`
83
+ - Logical `and` operator
84
+
85
+ #### Complex queries that cannot be solved during SSR
86
+
87
+ - Multiple comma-delimited values
88
+ - Logical `not` and `or` operators
89
+ - Mathematical `<=` and `>=` operators
90
+ - Complex or nested queries
91
+ - Other media types or features
92
+
93
+ [See the MediaQueryProvider SSR docs here &rarr;](/components/other/MediaQueryProvider#ssr-support)
94
+
95
+ ### Complex queries on the client
96
+
97
+ Complex queries cannot be solved during SSR. They are solved on the client by calling `window.matchMedia`.
98
+
99
+ ```tsx live
100
+ () => {
101
+ const isPortrait = useMediaQuery('(orientation: portrait)');
102
+ const isHighDPI = useMediaQuery('(min-resolution: 2dppx)');
103
+ const isTouch = useMediaQuery('(pointer: coarse)');
104
+ const isMediumHeight = useMediaQuery('(min-height: 600px) and (max-height: 900px)');
105
+
106
+ const complexQuery = useMediaQuery(
107
+ `((width >= 1200px) and (orientation: landscape)),
108
+ (width < 560px) or ((width > 768px) and (width < 900px))`,
109
+ );
110
+
111
+ return <JSONCodeBlock json={{ isPortrait, isHighDPI, isTouch, isMediumHeight, complexQuery }} />;
112
+ };
113
+ ```
114
+
@@ -0,0 +1,116 @@
1
+ # useMergeRefs
2
+
3
+ Combines multiple refs into a single ref callback, allowing a component to work with multiple ref instances simultaneously. Useful when you need to combine refs from different sources, such as forwarded refs and internal component state.
4
+
5
+ ## Import
6
+
7
+ ```tsx
8
+ import { useMergeRefs } from '@coinbase/cds-common/hooks/useMergeRefs'
9
+ ```
10
+
11
+ ## API
12
+
13
+ ### Parameters
14
+
15
+ The `useMergeRefs` hook accepts a spread of refs as its parameter:
16
+
17
+ - `...refs: (React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null)[]` - An array of refs to merge. Can include:
18
+ - `MutableRefObject` - Object-based refs created with `useRef`
19
+ - `LegacyRef` - Function-based refs or string refs (legacy)
20
+ - `undefined` or `null` - Optional refs that might not be provided
21
+
22
+ ### Returns
23
+
24
+ Returns a `React.RefCallback<T>` function that can be used as a ref:
25
+
26
+ - The returned callback handles updating all provided refs when the referenced element changes
27
+ - Properly handles both object-based and function-based refs
28
+ - Safely handles undefined or null refs by ignoring them
29
+
30
+ :::tip
31
+ This hook is particularly useful when working with components that need to combine multiple refs, such as when using both forwarded refs and internal state refs, or when composing components that each require their own ref.
32
+ :::
33
+
34
+ ## Examples
35
+
36
+ ### Basic usage
37
+
38
+ ```tsx live
39
+ function Example() {
40
+ // Create an internal ref for component logic
41
+ const internalRef = useRef<HTMLDivElement>(null);
42
+
43
+ // Simulating a forwarded ref from parent
44
+ const Component = forwardRef((props, forwardedRef) => {
45
+ // Merge the internal ref with the forwarded ref
46
+ const refs = useMergeRefs(forwardedRef, internalRef);
47
+
48
+ return (
49
+ <Box ref={refs} padding={3} background="bgAlternate" borderRadius={300}>
50
+ <TextBody>This box uses a merged ref</TextBody>
51
+ </Box>
52
+ );
53
+ });
54
+
55
+ return <Component />;
56
+ }
57
+ ```
58
+
59
+ ### With Multiple Refs
60
+
61
+ ```tsx live
62
+ function Example() {
63
+ const firstRef = useRef<HTMLDivElement>(null);
64
+ const secondRef = useRef<HTMLDivElement>(null);
65
+ const thirdRef = useRef<HTMLDivElement>(null);
66
+
67
+ // Function to check if all refs are properly set
68
+ const checkRefs = () => {
69
+ const allRefsSet = firstRef.current && secondRef.current && thirdRef.current;
70
+ alert(`All refs are ${allRefsSet ? 'set' : 'not set'}`);
71
+ };
72
+
73
+ // Merge all three refs
74
+ const mergedRefs = useMergeRefs(firstRef, secondRef, thirdRef);
75
+
76
+ return (
77
+ <VStack gap={2}>
78
+ <Box ref={mergedRefs} padding={3} background="bgAlternate" borderRadius={300}>
79
+ <TextBody>This element is referenced by three refs</TextBody>
80
+ </Box>
81
+ <Button onClick={checkRefs}>Check Refs</Button>
82
+ </VStack>
83
+ );
84
+ }
85
+ ```
86
+
87
+ ### With Function Ref
88
+
89
+ ```tsx live
90
+ function Example() {
91
+ const [elementWidth, setElementWidth] = useState<number>(0);
92
+
93
+ // Create a function ref that measures the element
94
+ const functionRef = (element: HTMLDivElement | null) => {
95
+ if (element) {
96
+ setElementWidth(element.offsetWidth);
97
+ }
98
+ };
99
+
100
+ // Create an object ref for other purposes
101
+ const objectRef = useRef<HTMLDivElement>(null);
102
+
103
+ // Merge both types of refs
104
+ const refs = useMergeRefs(functionRef, objectRef);
105
+
106
+ return (
107
+ <VStack gap={2}>
108
+ <Box ref={refs} padding={3} background="bgAlternate" borderRadius={300} width="100%">
109
+ <TextBody>This box uses both function and object refs</TextBody>
110
+ </Box>
111
+ <TextBody>Box width: {elementWidth}px</TextBody>
112
+ </VStack>
113
+ );
114
+ }
115
+ ```
116
+