@coinbase/cds-mcp-server 8.17.3 → 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.
- package/CHANGELOG.md +4 -0
- package/mcp-docs/mobile/components/Accordion.txt +11 -12
- package/mcp-docs/mobile/components/AccordionItem.txt +5 -6
- package/mcp-docs/mobile/components/Alert.txt +21 -22
- package/mcp-docs/mobile/components/AreaChart.txt +118 -119
- package/mcp-docs/mobile/components/Avatar.txt +82 -83
- package/mcp-docs/mobile/components/AvatarButton.txt +103 -104
- package/mcp-docs/mobile/components/Banner.txt +100 -101
- package/mcp-docs/mobile/components/BarChart.txt +120 -121
- package/mcp-docs/mobile/components/Box.txt +65 -66
- package/mcp-docs/mobile/components/BrowserBar.txt +38 -39
- package/mcp-docs/mobile/components/Button.txt +78 -79
- package/mcp-docs/mobile/components/ButtonGroup.txt +10 -11
- package/mcp-docs/mobile/components/Carousel.txt +103 -104
- package/mcp-docs/mobile/components/CartesianChart.txt +107 -108
- package/mcp-docs/mobile/components/CellMedia.txt +15 -16
- package/mcp-docs/mobile/components/Checkbox.txt +35 -36
- package/mcp-docs/mobile/components/CheckboxCell.txt +73 -74
- package/mcp-docs/mobile/components/CheckboxGroup.txt +24 -25
- package/mcp-docs/mobile/components/Chip.txt +67 -68
- package/mcp-docs/mobile/components/Coachmark.txt +42 -43
- package/mcp-docs/mobile/components/Collapsible.txt +15 -16
- package/mcp-docs/mobile/components/ContainedAssetCard.txt +16 -17
- package/mcp-docs/mobile/components/ContentCard.txt +99 -100
- package/mcp-docs/mobile/components/ContentCardBody.txt +23 -24
- package/mcp-docs/mobile/components/ContentCardFooter.txt +19 -20
- package/mcp-docs/mobile/components/ContentCardHeader.txt +33 -34
- package/mcp-docs/mobile/components/ContentCell.txt +102 -103
- package/mcp-docs/mobile/components/ControlGroup.txt +106 -107
- package/mcp-docs/mobile/components/DatePicker.txt +121 -122
- package/mcp-docs/mobile/components/Divider.txt +31 -32
- package/mcp-docs/mobile/components/DotCount.txt +15 -16
- package/mcp-docs/mobile/components/DotStatusColor.txt +12 -13
- package/mcp-docs/mobile/components/DotSymbol.txt +21 -22
- package/mcp-docs/mobile/components/Fallback.txt +49 -50
- package/mcp-docs/mobile/components/FloatingAssetCard.txt +13 -14
- package/mcp-docs/mobile/components/HStack.txt +99 -100
- package/mcp-docs/mobile/components/HeroSquare.txt +11 -12
- package/mcp-docs/mobile/components/Icon.txt +16 -17
- package/mcp-docs/mobile/components/IconButton.txt +104 -105
- package/mcp-docs/mobile/components/InputChip.txt +62 -63
- package/mcp-docs/mobile/components/Interactable.txt +72 -73
- package/mcp-docs/mobile/components/LineChart.txt +117 -118
- package/mcp-docs/mobile/components/Link.txt +113 -114
- package/mcp-docs/mobile/components/ListCell.txt +149 -128
- package/mcp-docs/mobile/components/LogoMark.txt +8 -9
- package/mcp-docs/mobile/components/LogoWordMark.txt +7 -8
- package/mcp-docs/mobile/components/Lottie.txt +39 -40
- package/mcp-docs/mobile/components/LottieStatusAnimation.txt +11 -12
- package/mcp-docs/mobile/components/Modal.txt +36 -37
- package/mcp-docs/mobile/components/ModalBody.txt +5 -6
- package/mcp-docs/mobile/components/ModalFooter.txt +5 -6
- package/mcp-docs/mobile/components/ModalHeader.txt +5 -6
- package/mcp-docs/mobile/components/MultiContentModule.txt +107 -108
- package/mcp-docs/mobile/components/NavigationTitle.txt +13 -14
- package/mcp-docs/mobile/components/NavigationTitleSelect.txt +20 -21
- package/mcp-docs/mobile/components/NudgeCard.txt +20 -21
- package/mcp-docs/mobile/components/Numpad.txt +108 -109
- package/mcp-docs/mobile/components/Overlay.txt +45 -46
- package/mcp-docs/mobile/components/PageFooter.txt +57 -58
- package/mcp-docs/mobile/components/PageHeader.txt +79 -80
- package/mcp-docs/mobile/components/PeriodSelector.txt +98 -99
- package/mcp-docs/mobile/components/Pictogram.txt +11 -12
- package/mcp-docs/mobile/components/Point.txt +21 -22
- package/mcp-docs/mobile/components/PortalProvider.txt +7 -8
- package/mcp-docs/mobile/components/Pressable.txt +67 -68
- package/mcp-docs/mobile/components/ProgressBar.txt +18 -19
- package/mcp-docs/mobile/components/ProgressBarWithFixedLabels.txt +13 -14
- package/mcp-docs/mobile/components/ProgressBarWithFloatLabel.txt +13 -14
- package/mcp-docs/mobile/components/ProgressCircle.txt +22 -23
- package/mcp-docs/mobile/components/Radio.txt +35 -36
- package/mcp-docs/mobile/components/RadioCell.txt +73 -74
- package/mcp-docs/mobile/components/RadioGroup.txt +35 -36
- package/mcp-docs/mobile/components/ReferenceLine.txt +15 -16
- package/mcp-docs/mobile/components/RemoteImage.txt +47 -48
- package/mcp-docs/mobile/components/RemoteImageGroup.txt +11 -12
- package/mcp-docs/mobile/components/RollingNumber.txt +130 -131
- package/mcp-docs/mobile/components/Scrubber.txt +19 -20
- package/mcp-docs/mobile/components/SearchInput.txt +77 -78
- package/mcp-docs/mobile/components/SectionHeader.txt +16 -17
- package/mcp-docs/mobile/components/SegmentedTabs.txt +105 -106
- package/mcp-docs/mobile/components/Select.txt +35 -36
- package/mcp-docs/mobile/components/SelectChip.txt +143 -144
- package/mcp-docs/mobile/components/SelectOption.txt +26 -27
- package/mcp-docs/mobile/components/SlideButton.txt +128 -129
- package/mcp-docs/mobile/components/Spacer.txt +27 -28
- package/mcp-docs/mobile/components/Sparkline.txt +18 -19
- package/mcp-docs/mobile/components/SparklineGradient.txt +18 -19
- package/mcp-docs/mobile/components/SparklineInteractive.txt +37 -38
- package/mcp-docs/mobile/components/SparklineInteractiveHeader.txt +12 -13
- package/mcp-docs/mobile/components/Spinner.txt +15 -16
- package/mcp-docs/mobile/components/SpotIcon.txt +11 -12
- package/mcp-docs/mobile/components/SpotRectangle.txt +11 -12
- package/mcp-docs/mobile/components/SpotSquare.txt +11 -12
- package/mcp-docs/mobile/components/Stepper.txt +113 -114
- package/mcp-docs/mobile/components/SubBrandLogoMark.txt +8 -9
- package/mcp-docs/mobile/components/SubBrandLogoWordMark.txt +8 -9
- package/mcp-docs/mobile/components/Switch.txt +35 -36
- package/mcp-docs/mobile/components/TabIndicator.txt +12 -13
- package/mcp-docs/mobile/components/TabLabel.txt +28 -29
- package/mcp-docs/mobile/components/TabNavigation.txt +41 -42
- package/mcp-docs/mobile/components/TabbedChips.txt +38 -39
- package/mcp-docs/mobile/components/Tabs.txt +76 -77
- package/mcp-docs/mobile/components/Tag.txt +102 -103
- package/mcp-docs/mobile/components/Text.txt +91 -92
- package/mcp-docs/mobile/components/TextInput.txt +107 -108
- package/mcp-docs/mobile/components/ThemeProvider.txt +8 -9
- package/mcp-docs/mobile/components/Toast.txt +82 -83
- package/mcp-docs/mobile/components/Tooltip.txt +20 -21
- package/mcp-docs/mobile/components/TopNavBar.txt +55 -56
- package/mcp-docs/mobile/components/Tour.txt +18 -19
- package/mcp-docs/mobile/components/Tray.txt +43 -44
- package/mcp-docs/mobile/components/UpsellCard.txt +16 -17
- package/mcp-docs/mobile/components/VStack.txt +99 -100
- package/mcp-docs/mobile/components/XAxis.txt +25 -26
- package/mcp-docs/mobile/components/YAxis.txt +26 -27
- package/mcp-docs/mobile/getting-started/{mcp-server.txt → ai-overview.txt} +51 -37
- package/mcp-docs/mobile/getting-started/installation.txt +57 -0
- package/mcp-docs/mobile/getting-started/introduction.txt +3 -0
- package/mcp-docs/mobile/getting-started/playground.txt +3 -0
- package/mcp-docs/mobile/getting-started/styling.txt +84 -0
- package/mcp-docs/mobile/getting-started/theming.txt +286 -0
- package/mcp-docs/mobile/hooks/useDimensions.txt +27 -2
- package/mcp-docs/mobile/hooks/useEventHandler.txt +120 -0
- package/mcp-docs/mobile/hooks/useMergeRefs.txt +116 -0
- package/mcp-docs/mobile/hooks/useOverlayContentContext.txt +67 -2
- package/mcp-docs/mobile/hooks/usePreviousValue.txt +74 -0
- package/mcp-docs/mobile/hooks/useRefMap.txt +178 -0
- package/mcp-docs/mobile/hooks/useTheme.txt +213 -2
- package/mcp-docs/mobile/routes.txt +8 -1
- package/mcp-docs/web/components/Accordion.txt +12 -13
- package/mcp-docs/web/components/AccordionItem.txt +5 -6
- package/mcp-docs/web/components/Alert.txt +24 -25
- package/mcp-docs/web/components/AreaChart.txt +137 -138
- package/mcp-docs/web/components/Avatar.txt +91 -92
- package/mcp-docs/web/components/AvatarButton.txt +113 -114
- package/mcp-docs/web/components/Banner.txt +101 -102
- package/mcp-docs/web/components/BarChart.txt +367 -368
- package/mcp-docs/web/components/Box.txt +65 -66
- package/mcp-docs/web/components/Button.txt +81 -82
- package/mcp-docs/web/components/ButtonGroup.txt +10 -11
- package/mcp-docs/web/components/Calendar.txt +56 -57
- package/mcp-docs/web/components/Carousel.txt +116 -117
- package/mcp-docs/web/components/CartesianChart.txt +357 -358
- package/mcp-docs/web/components/CellMedia.txt +14 -15
- package/mcp-docs/web/components/Checkbox.txt +22 -23
- package/mcp-docs/web/components/CheckboxCell.txt +70 -71
- package/mcp-docs/web/components/CheckboxGroup.txt +15 -16
- package/mcp-docs/web/components/Chip.txt +67 -68
- package/mcp-docs/web/components/Coachmark.txt +69 -70
- package/mcp-docs/web/components/Collapsible.txt +15 -16
- package/mcp-docs/web/components/ContainedAssetCard.txt +108 -109
- package/mcp-docs/web/components/ContentCard.txt +101 -102
- package/mcp-docs/web/components/ContentCardBody.txt +23 -24
- package/mcp-docs/web/components/ContentCardFooter.txt +19 -20
- package/mcp-docs/web/components/ContentCardHeader.txt +33 -34
- package/mcp-docs/web/components/ContentCell.txt +85 -86
- package/mcp-docs/web/components/ControlGroup.txt +108 -109
- package/mcp-docs/web/components/DatePicker.txt +59 -60
- package/mcp-docs/web/components/Divider.txt +31 -32
- package/mcp-docs/web/components/DotCount.txt +17 -18
- package/mcp-docs/web/components/DotStatusColor.txt +12 -13
- package/mcp-docs/web/components/DotSymbol.txt +24 -25
- package/mcp-docs/web/components/Dropdown.txt +31 -32
- package/mcp-docs/web/components/Fallback.txt +49 -50
- package/mcp-docs/web/components/FloatingAssetCard.txt +108 -109
- package/mcp-docs/web/components/FullscreenAlert.txt +20 -21
- package/mcp-docs/web/components/FullscreenModal.txt +28 -29
- package/mcp-docs/web/components/FullscreenModalLayout.txt +19 -20
- package/mcp-docs/web/components/Grid.txt +106 -107
- package/mcp-docs/web/components/GridColumn.txt +96 -97
- package/mcp-docs/web/components/HStack.txt +101 -102
- package/mcp-docs/web/components/HeroSquare.txt +12 -13
- package/mcp-docs/web/components/Icon.txt +27 -28
- package/mcp-docs/web/components/IconButton.txt +117 -118
- package/mcp-docs/web/components/InputChip.txt +62 -63
- package/mcp-docs/web/components/Interactable.txt +75 -76
- package/mcp-docs/web/components/LineChart.txt +366 -367
- package/mcp-docs/web/components/Link.txt +114 -115
- package/mcp-docs/web/components/ListCell.txt +157 -136
- package/mcp-docs/web/components/LogoMark.txt +8 -9
- package/mcp-docs/web/components/LogoWordMark.txt +7 -8
- package/mcp-docs/web/components/Lottie.txt +44 -45
- package/mcp-docs/web/components/LottieStatusAnimation.txt +11 -12
- package/mcp-docs/web/components/MediaQueryProvider.txt +7 -8
- package/mcp-docs/web/components/Modal.txt +69 -66
- package/mcp-docs/web/components/ModalBody.txt +5 -6
- package/mcp-docs/web/components/ModalFooter.txt +5 -6
- package/mcp-docs/web/components/ModalHeader.txt +5 -6
- package/mcp-docs/web/components/MultiContentModule.txt +109 -110
- package/mcp-docs/web/components/NavigationBar.txt +18 -19
- package/mcp-docs/web/components/NavigationTitle.txt +7 -8
- package/mcp-docs/web/components/NavigationTitleSelect.txt +9 -10
- package/mcp-docs/web/components/NudgeCard.txt +61 -62
- package/mcp-docs/web/components/Overlay.txt +57 -58
- package/mcp-docs/web/components/PageFooter.txt +77 -78
- package/mcp-docs/web/components/PageHeader.txt +107 -108
- package/mcp-docs/web/components/Pagination.txt +115 -116
- package/mcp-docs/web/components/PeriodSelector.txt +158 -159
- package/mcp-docs/web/components/Pictogram.txt +13 -14
- package/mcp-docs/web/components/Point.txt +169 -170
- package/mcp-docs/web/components/PortalProvider.txt +6 -7
- package/mcp-docs/web/components/Pressable.txt +73 -74
- package/mcp-docs/web/components/ProgressBar.txt +20 -21
- package/mcp-docs/web/components/ProgressBarWithFixedLabels.txt +15 -16
- package/mcp-docs/web/components/ProgressBarWithFloatLabel.txt +15 -16
- package/mcp-docs/web/components/ProgressCircle.txt +24 -25
- package/mcp-docs/web/components/Radio.txt +22 -23
- package/mcp-docs/web/components/RadioCell.txt +83 -84
- package/mcp-docs/web/components/RadioGroup.txt +22 -23
- package/mcp-docs/web/components/ReferenceLine.txt +22 -23
- package/mcp-docs/web/components/RemoteImage.txt +49 -50
- package/mcp-docs/web/components/RemoteImageGroup.txt +11 -12
- package/mcp-docs/web/components/RollingNumber.txt +131 -132
- package/mcp-docs/web/components/Scrubber.txt +22 -23
- package/mcp-docs/web/components/SearchInput.txt +29 -30
- package/mcp-docs/web/components/SectionHeader.txt +98 -99
- package/mcp-docs/web/components/SegmentedTabs.txt +109 -110
- package/mcp-docs/web/components/Select.txt +22 -23
- package/mcp-docs/web/components/SelectChip.txt +134 -135
- package/mcp-docs/web/components/SelectOption.txt +31 -32
- package/mcp-docs/web/components/Sidebar.txt +109 -110
- package/mcp-docs/web/components/SidebarItem.txt +6 -7
- package/mcp-docs/web/components/SidebarMoreMenu.txt +5 -6
- package/mcp-docs/web/components/Spacer.txt +57 -58
- package/mcp-docs/web/components/Sparkline.txt +18 -19
- package/mcp-docs/web/components/SparklineGradient.txt +18 -19
- package/mcp-docs/web/components/SparklineInteractive.txt +34 -35
- package/mcp-docs/web/components/SparklineInteractiveHeader.txt +12 -13
- package/mcp-docs/web/components/Spinner.txt +15 -16
- package/mcp-docs/web/components/SpotIcon.txt +12 -13
- package/mcp-docs/web/components/SpotRectangle.txt +12 -13
- package/mcp-docs/web/components/SpotSquare.txt +12 -13
- package/mcp-docs/web/components/Stepper.txt +119 -120
- package/mcp-docs/web/components/SubBrandLogoMark.txt +8 -9
- package/mcp-docs/web/components/SubBrandLogoWordMark.txt +8 -9
- package/mcp-docs/web/components/Switch.txt +23 -24
- package/mcp-docs/web/components/TabIndicator.txt +12 -13
- package/mcp-docs/web/components/TabLabel.txt +28 -29
- package/mcp-docs/web/components/TabNavigation.txt +41 -42
- package/mcp-docs/web/components/TabbedChips.txt +38 -39
- package/mcp-docs/web/components/Table.txt +17 -18
- package/mcp-docs/web/components/TableBody.txt +9 -10
- package/mcp-docs/web/components/TableCaption.txt +13 -14
- package/mcp-docs/web/components/TableCell.txt +21 -22
- package/mcp-docs/web/components/TableCellFallback.txt +16 -17
- package/mcp-docs/web/components/TableFooter.txt +9 -10
- package/mcp-docs/web/components/TableHeader.txt +10 -11
- package/mcp-docs/web/components/TableRow.txt +13 -14
- package/mcp-docs/web/components/Tabs.txt +94 -95
- package/mcp-docs/web/components/Tag.txt +106 -107
- package/mcp-docs/web/components/Text.txt +110 -111
- package/mcp-docs/web/components/TextInput.txt +32 -33
- package/mcp-docs/web/components/ThemeProvider.txt +27 -28
- package/mcp-docs/web/components/TileButton.txt +37 -38
- package/mcp-docs/web/components/Toast.txt +82 -83
- package/mcp-docs/web/components/Tooltip.txt +22 -23
- package/mcp-docs/web/components/Tour.txt +21 -22
- package/mcp-docs/web/components/Tray.txt +23 -24
- package/mcp-docs/web/components/UpsellCard.txt +16 -17
- package/mcp-docs/web/components/VStack.txt +101 -102
- package/mcp-docs/web/components/XAxis.txt +25 -26
- package/mcp-docs/web/components/YAxis.txt +26 -27
- package/mcp-docs/web/getting-started/{mcp-server.txt → ai-overview.txt} +51 -37
- package/mcp-docs/web/getting-started/installation.txt +103 -0
- package/mcp-docs/web/getting-started/introduction.txt +3 -0
- package/mcp-docs/web/getting-started/playground.txt +3 -0
- package/mcp-docs/web/getting-started/styling.txt +161 -0
- package/mcp-docs/web/getting-started/templates.txt +121 -0
- package/mcp-docs/web/getting-started/theming.txt +426 -0
- package/mcp-docs/web/hooks/useBreakpoints.txt +30 -2
- package/mcp-docs/web/hooks/useDimensions.txt +61 -2
- package/mcp-docs/web/hooks/useEventHandler.txt +120 -0
- package/mcp-docs/web/hooks/useHasMounted.txt +22 -2
- package/mcp-docs/web/hooks/useIsoEffect.txt +18 -2
- package/mcp-docs/web/hooks/useMediaQuery.txt +22 -2
- package/mcp-docs/web/hooks/useMergeRefs.txt +116 -0
- package/mcp-docs/web/hooks/useOverlayContentContext.txt +64 -2
- package/mcp-docs/web/hooks/usePreviousValue.txt +74 -0
- package/mcp-docs/web/hooks/useRefMap.txt +178 -0
- package/mcp-docs/web/hooks/useScrollBlocker.txt +21 -2
- package/mcp-docs/web/hooks/useTheme.txt +261 -2
- package/mcp-docs/web/routes.txt +9 -1
- package/package.json +1 -1
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
# theming
|
|
2
|
+
|
|
3
|
+
The theme contains design tokens like colors, fonts, spacing, and more. The ThemeProvider provides access to these values via CSS Variables for web, and React Context for both web and React Native.
|
|
4
|
+
|
|
5
|
+
import { defaultTheme } from '@coinbase/cds-mobile/themes/defaultTheme';
|
|
6
|
+
import { JSONCodeBlock } from '@site/src/components/page/JSONCodeBlock';
|
|
7
|
+
|
|
8
|
+
### ThemeProvider component
|
|
9
|
+
|
|
10
|
+
The ThemeProvider provides the theme context to all child components.
|
|
11
|
+
|
|
12
|
+
You must pass the `theme` prop to configure the theme, and the `activeColorScheme` prop to set light or dark mode.
|
|
13
|
+
|
|
14
|
+
[See the ThemeProvider docs here →](/components/other/ThemeProvider)
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { ThemeProvider } from '@coinbase/cds-mobile/system/ThemeProvider';
|
|
18
|
+
import { defaultTheme } from '@coinbase/cds-mobile/themes/defaultTheme';
|
|
19
|
+
|
|
20
|
+
const App = () => (
|
|
21
|
+
<ThemeProvider theme={defaultTheme} activeColorScheme="light">
|
|
22
|
+
{/* Your app components */}
|
|
23
|
+
</ThemeProvider>
|
|
24
|
+
);
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
:::tip
|
|
28
|
+
Changing the `activeColorScheme` automatically updates the values returned from the `useTheme` hook.
|
|
29
|
+
:::
|
|
30
|
+
|
|
31
|
+
#### `useTheme` hook
|
|
32
|
+
|
|
33
|
+
The `useTheme` hook provides access to the current `theme` and `activeColorScheme`.
|
|
34
|
+
|
|
35
|
+
The `color` and `spectrum` objects automatically change based on the `activeColorScheme`.
|
|
36
|
+
|
|
37
|
+
[See the `useTheme` docs here →](/hooks/useTheme)
|
|
38
|
+
|
|
39
|
+
```jsx
|
|
40
|
+
const theme = useTheme();
|
|
41
|
+
theme.activeColorScheme; // "light" or "dark"
|
|
42
|
+
theme.spectrum; // Resolves to lightSpectrum or darkSpectrum, depends on activeColorScheme
|
|
43
|
+
theme.color; // Resolves to lightColor or darkColor, depends on activeColorScheme
|
|
44
|
+
theme.color.bgPrimary; // "rgb(0,82,255)" or "rgb(87,139,250)", depends on activeColorScheme
|
|
45
|
+
theme.space[2]; // 16
|
|
46
|
+
theme.borderRadius[200]; // 8
|
|
47
|
+
theme.fontSize.display3; // 40
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
#### Nested themes
|
|
51
|
+
|
|
52
|
+
ThemeProviders can be nested to create theme overrides for specific sections.
|
|
53
|
+
|
|
54
|
+
```jsx
|
|
55
|
+
<ThemeProvider theme={defaultTheme} activeColorScheme="light">
|
|
56
|
+
{/* Default theme in light color scheme */}
|
|
57
|
+
|
|
58
|
+
<ThemeProvider theme={customTheme} activeColorScheme="dark">
|
|
59
|
+
{/* Custom theme in dark color scheme */}
|
|
60
|
+
</ThemeProvider>
|
|
61
|
+
</ThemeProvider>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
When nesting, you may want to override specific color values from the current theme. Overrides must be conditionally applied because we don't enforce that a theme has both light and dark colors defined.
|
|
65
|
+
|
|
66
|
+
```jsx
|
|
67
|
+
// Override parts of the parent theme
|
|
68
|
+
const theme = useTheme();
|
|
69
|
+
const customTheme = {
|
|
70
|
+
...theme,
|
|
71
|
+
...(theme.lightColor &&
|
|
72
|
+
theme.lightSpectrum && {
|
|
73
|
+
lightColor: {
|
|
74
|
+
...theme.lightColor,
|
|
75
|
+
bg: `rgb(${theme.lightSpectrum.orange50})`,
|
|
76
|
+
bgPrimary: `rgb(${theme.lightSpectrum.red20})`,
|
|
77
|
+
bgSecondary: `rgb(${theme.lightSpectrum.blue50})`,
|
|
78
|
+
},
|
|
79
|
+
}),
|
|
80
|
+
...(theme.darkColor &&
|
|
81
|
+
theme.darkSpectrum && {
|
|
82
|
+
darkColor: {
|
|
83
|
+
...theme.darkColor,
|
|
84
|
+
bg: `rgb(${theme.darkSpectrum.orange50})`,
|
|
85
|
+
bgPrimary: `rgb(${theme.darkSpectrum.red20})`,
|
|
86
|
+
bgSecondary: `rgb(${theme.darkSpectrum.blue50})`,
|
|
87
|
+
},
|
|
88
|
+
}),
|
|
89
|
+
} as const satisfies Theme;
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Theme inheritence
|
|
93
|
+
|
|
94
|
+
Nested ThemeProviders do not automatically inherit the theme from their parent provider. You can manually inherit the theme with the `useTheme` hook.
|
|
95
|
+
|
|
96
|
+
```jsx
|
|
97
|
+
const Example = () => {
|
|
98
|
+
// Pass the parent theme down to another ThemeProvider
|
|
99
|
+
const theme = useTheme();
|
|
100
|
+
return (
|
|
101
|
+
<ThemeProvider theme={theme} activeColorScheme={theme.activeColorScheme}>
|
|
102
|
+
{children}
|
|
103
|
+
</ThemeProvider>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
#### InvertedThemeProvider component
|
|
109
|
+
|
|
110
|
+
The InvertedThemeProvider automatically inherits from its parent theme and flips the `activeColorScheme` to the opposite value.
|
|
111
|
+
|
|
112
|
+
```jsx
|
|
113
|
+
<ThemeProvider theme={defaultTheme} activeColorScheme="light">
|
|
114
|
+
{/* Default theme in light color scheme */}
|
|
115
|
+
|
|
116
|
+
<InvertedThemeProvider>
|
|
117
|
+
{/* Default theme in inverse (dark) color scheme */}
|
|
118
|
+
</InvertedThemeProvider>
|
|
119
|
+
</ThemeProvider>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `ThemeConfig` vs `Theme` type
|
|
123
|
+
|
|
124
|
+
Use the `ThemeConfig` type when creating a theme, or when passing the `theme` prop to the ThemeProvider.
|
|
125
|
+
|
|
126
|
+
Use the `Theme` type for the return value of the `useTheme` hook. The `Theme` type includes all the properties of `ThemeConfig` - plus the `activeColorScheme`, `color`, and `spectrum` properties.
|
|
127
|
+
|
|
128
|
+
[See the `ThemeConfig` type definition here →](https://github.com/coinbase/cds/blob/master/packages/mobile/src/core/theme.ts#L11)
|
|
129
|
+
|
|
130
|
+
[See the `Theme` type definition here →](https://github.com/coinbase/cds/blob/master/packages/mobile/src/core/theme.ts#L50)
|
|
131
|
+
|
|
132
|
+
:::tip
|
|
133
|
+
Although the `Theme` type includes extra properties, you can still pass the `useTheme` return value directly to the ThemeProvider `theme` prop as shown in the [theme inheritence section.](#theme-inheritence)
|
|
134
|
+
:::
|
|
135
|
+
|
|
136
|
+
### `spectrum` vs `color` values
|
|
137
|
+
|
|
138
|
+
The `spectrum` variables are partial `"r,g,b"` strings while `color` variables are complete CSS color values.
|
|
139
|
+
|
|
140
|
+
Both `color` and `spectrum` behave inversely in light and dark mode.
|
|
141
|
+
|
|
142
|
+
For example with the `defaultTheme` config, `spectrum.gray0` is white in light mode and black in dark mode. We use `spectrum` variables to define `color` variables, so this same behavior extends to `color`.
|
|
143
|
+
|
|
144
|
+
The `color` variables have semantic names which describe their application in the UI. You should prefer to use `color` variables instead of `spectrum` variables when styling UI.
|
|
145
|
+
|
|
146
|
+
```jsx
|
|
147
|
+
const theme = useTheme();
|
|
148
|
+
theme.lightSpectrum.gray0; // "255,255,255"
|
|
149
|
+
theme.darkSpectrum.gray0; // "10,11,13"
|
|
150
|
+
theme.spectrum.gray100; // "255,255,255" or "10,11,13", depends on activeColorScheme
|
|
151
|
+
theme.lightColor.bg; // "rgb(255,255,255)"
|
|
152
|
+
theme.darkColor.bg; // "rgb(10,11,13)"
|
|
153
|
+
theme.color.bg; // "rgb(255,255,255)" or "rgb(10,11,13)", depends on activeColorScheme
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
:::tip
|
|
157
|
+
Prefer to use semantic `color` variables for UI styles. Direct usage of `spectrum` values should be a rare exception.
|
|
158
|
+
:::
|
|
159
|
+
|
|
160
|
+
### Creating a theme
|
|
161
|
+
#### Defining colors
|
|
162
|
+
|
|
163
|
+
We recommend defining `lightSpectrum` and `darkSpectrum` as separate objects. This makes it easier to reference them when defining the `lightColor` and `darkColor` values.
|
|
164
|
+
|
|
165
|
+
The `lightColor` and `darkColor` values must be raw color strings (hex, rgba, hsl, etc), they cannot contain CSS Variables or CSS functions.
|
|
166
|
+
|
|
167
|
+
#### The `space` scale
|
|
168
|
+
|
|
169
|
+
CDS expects that the theme `space` values will be multiples of some base number.
|
|
170
|
+
|
|
171
|
+
For example, the `defaultTheme` uses `8px` as the base number:
|
|
172
|
+
|
|
173
|
+
```jsx
|
|
174
|
+
theme.space[0]; // 0
|
|
175
|
+
theme.space[0.25]; // 2
|
|
176
|
+
theme.space[0.5]; // 4
|
|
177
|
+
theme.space[1]; // 8
|
|
178
|
+
theme.space[1.5]; // 12
|
|
179
|
+
theme.space[2]; // 16
|
|
180
|
+
theme.space[3]; // 24
|
|
181
|
+
// etc.
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
While it is possible to customize the `space` values in any way, deviating from this expectation may produce broken styles.
|
|
185
|
+
|
|
186
|
+
#### Example new theme
|
|
187
|
+
|
|
188
|
+
In this example we'll start with the `defaultTheme` and customize a couple values.
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
import type { ThemeConfig } from '@coinbase/cds-mobile/core/theme';
|
|
192
|
+
import { ThemeProvider } from '@coinbase/cds-mobile/system/ThemeProvider';
|
|
193
|
+
import { defaultTheme } from '@coinbase/cds-mobile/themes/defaultTheme';
|
|
194
|
+
|
|
195
|
+
// Define lightSpectrum and darkSpectrum as separate objects
|
|
196
|
+
const lightSpectrum = {
|
|
197
|
+
...defaultTheme.lightSpectrum,
|
|
198
|
+
blue60: '8,90,255',
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const darkSpectrum = {
|
|
202
|
+
...defaultTheme.darkSpectrum,
|
|
203
|
+
blue60: '65,125,245',
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// Use lightSpectrum and darkSpectrum to define the lightColor and darkColor values
|
|
207
|
+
const myTheme = {
|
|
208
|
+
...defaultTheme,
|
|
209
|
+
id: 'my-custom-theme',
|
|
210
|
+
lightSpectrum,
|
|
211
|
+
darkSpectrum,
|
|
212
|
+
lightColor: {
|
|
213
|
+
...defaultTheme.lightColor,
|
|
214
|
+
bgPrimary: `rgb(${lightSpectrum.red60})`,
|
|
215
|
+
},
|
|
216
|
+
darkColor: {
|
|
217
|
+
...defaultTheme.darkColor,
|
|
218
|
+
bgPrimary: `rgb(${darkSpectrum.red60})`,
|
|
219
|
+
},
|
|
220
|
+
} as const satisfies ThemeConfig;
|
|
221
|
+
|
|
222
|
+
const App = () => (
|
|
223
|
+
<ThemeProvider theme={myTheme} activeColorScheme="light">
|
|
224
|
+
{/* Your app components */}
|
|
225
|
+
</ThemeProvider>
|
|
226
|
+
);
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
:::tip
|
|
230
|
+
Use the `ThemeConfig` type with TypeScript's `satisfies` keyword to enforce type safety for your theme.
|
|
231
|
+
:::
|
|
232
|
+
|
|
233
|
+
### `defaultTheme` config
|
|
234
|
+
|
|
235
|
+
The `defaultTheme` is a good example of a complete `ThemeConfig`. You can use it as an example when developing your own themes.
|
|
236
|
+
|
|
237
|
+
[See the `defaultTheme` source code here →](https://github.com/coinbase/cds/blob/master/packages/mobile/src/themes/defaultTheme.ts)
|
|
238
|
+
|
|
239
|
+
<JSONCodeBlock json={defaultTheme} />
|
|
240
|
+
|
|
241
|
+
### `ThemeVars` namespace
|
|
242
|
+
|
|
243
|
+
The `ThemeVars` namespace contains type definitions for all themeable variable names in CDS. It includes any custom theme variables added in `ThemeVarsExtended`.
|
|
244
|
+
|
|
245
|
+
```tsx
|
|
246
|
+
import type { ThemeVars } from '@coinbase/cds-common/core/theme';
|
|
247
|
+
|
|
248
|
+
// All theme variables are accessible through ThemeVars
|
|
249
|
+
ThemeVars.Color; // 'fg' | 'bg' | 'bgPrimary' | 'bgSecondary' | ...
|
|
250
|
+
ThemeVars.SpectrumColor; // 'blue60' | 'red40' | 'gray100' | ...
|
|
251
|
+
ThemeVars.SpectrumHue; // 'blue' | 'green' | 'orange' | 'gray' | ...
|
|
252
|
+
ThemeVars.SpectrumHueStep; // 0 | 5 | 10 | 20 | ...
|
|
253
|
+
ThemeVars.Space; // 0 | 0.25 | 0.5 | 1 | 2 | ...
|
|
254
|
+
ThemeVars.BorderWidth; // 0 | 100 | 200 | ...
|
|
255
|
+
ThemeVars.BorderRadius; // 0 | 100 | 200 | ...
|
|
256
|
+
ThemeVars.Font; // 'display1' | 'title1' | 'body' | ...
|
|
257
|
+
ThemeVars.FontFamily; // 'display1' | 'title1' | 'body' | ...
|
|
258
|
+
ThemeVars.FontSize; // 'display1' | 'title1' | 'body' | ...
|
|
259
|
+
ThemeVars.FontWeight; // 'display1' | 'title1' | 'body' | ...
|
|
260
|
+
ThemeVars.LineHeight; // 'display1' | 'title1' | 'body' | ...
|
|
261
|
+
ThemeVars.TextTransform; // 'display1' | 'title1' | 'body' | ...
|
|
262
|
+
ThemeVars.IconSize; // 'xs' | 's' | 'm' | 'l'
|
|
263
|
+
ThemeVars.AvatarSize; // 's' | 'm' | 'l' | 'xl' | ...
|
|
264
|
+
ThemeVars.ControlSize; // 'checkboxSize' | 'radioSize' | ...
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Extending the theme
|
|
268
|
+
|
|
269
|
+
You can extend the theme by adding custom theme variables. In this example we'll show how to add a custom color variable, but you can extend other types of `ThemeVars` as well.
|
|
270
|
+
|
|
271
|
+
Start by overriding interfaces in the `ThemeVarsExtended` namespace to add new theme variables. Only the key names are used, the `void` type is just a necessary placeholder.
|
|
272
|
+
|
|
273
|
+
```jsx
|
|
274
|
+
declare module '@coinbase/cds-common/core/theme' {
|
|
275
|
+
export namespace ThemeVarsExtended {
|
|
276
|
+
export interface Color {
|
|
277
|
+
myCustomColor: void;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
This adds `myCustomColor` to `ThemeVars.Color` - which enforces that this variable must be defined in your theme to satisfy the `ThemeConfig` type, and allows this variable name to be passed to the `StyleProps` API anywhere that theme colors are accepted.
|
|
284
|
+
|
|
285
|
+
Now that `myCustomColor` is defined in your theme the `useTheme` hook will include it in the return value.
|
|
286
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
1
|
# useDimensions
|
|
2
|
+
|
|
3
3
|
Measures the screen dimensions and status bar height.
|
|
4
4
|
|
|
5
5
|
## Import
|
|
@@ -8,6 +8,32 @@ Measures the screen dimensions and status bar height.
|
|
|
8
8
|
import { useDimensions } from '@coinbase/cds-mobile/hooks/useDimensions'
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## API
|
|
12
|
+
|
|
13
|
+
### Parameters
|
|
14
|
+
|
|
15
|
+
None. The hook takes no parameters.
|
|
16
|
+
|
|
17
|
+
### Returns
|
|
18
|
+
|
|
19
|
+
Returns an object with the following properties:
|
|
20
|
+
|
|
21
|
+
```tsx
|
|
22
|
+
type Return = {
|
|
23
|
+
screenHeight: number;
|
|
24
|
+
screenWidth: number;
|
|
25
|
+
statusBarHeight: number;
|
|
26
|
+
};
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- `screenHeight`: The total height of the device screen in points (DIP).
|
|
30
|
+
- `screenWidth`: The total width of the device screen in points (DIP).
|
|
31
|
+
- `statusBarHeight`: The height of the device's status bar in points (DIP).
|
|
32
|
+
|
|
33
|
+
:::tip
|
|
34
|
+
All dimensions are in points (DIP - Density Independent Pixels), not physical pixels. Values automatically update on device orientation changes. The status bar height varies by device type, orientation, and presence of notches or dynamic islands.
|
|
35
|
+
:::
|
|
36
|
+
|
|
11
37
|
## Examples
|
|
12
38
|
|
|
13
39
|
### Basic usage
|
|
@@ -44,4 +70,3 @@ function Example() {
|
|
|
44
70
|
}
|
|
45
71
|
```
|
|
46
72
|
|
|
47
|
-
|
|
@@ -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,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
|
+
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
2
1
|
# useOverlayContentContext
|
|
2
|
+
|
|
3
3
|
A React context and hook for detecting if components are rendered inside overlay containers like modals, drawers, tours, and trays.
|
|
4
4
|
|
|
5
5
|
## Import
|
|
@@ -8,6 +8,72 @@ A React context and hook for detecting if components are rendered inside overlay
|
|
|
8
8
|
import { OverlayContentContext, useOverlayContentContext } from '@coinbase/cds-common/overlays/OverlayContentContext'
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
## API
|
|
12
|
+
|
|
13
|
+
### useOverlayContentContext
|
|
14
|
+
|
|
15
|
+
Returns the current overlay context information for mobile applications. This hook does not throw an error when used outside a provider, making it safe to use anywhere in your component tree.
|
|
16
|
+
|
|
17
|
+
#### Return Value
|
|
18
|
+
|
|
19
|
+
The hook returns an object with the following properties:
|
|
20
|
+
|
|
21
|
+
- **`isOverlay?: boolean`** - True if inside any overlay component (derived from other values if not explicitly set)
|
|
22
|
+
- **`isModal?: boolean`** - True if inside a Modal component
|
|
23
|
+
- **`isDrawer?: boolean`** - True if inside a Drawer or Tray component
|
|
24
|
+
- **`isTour?: boolean`** - True if inside a Tour component
|
|
25
|
+
|
|
26
|
+
### OverlayContentContext
|
|
27
|
+
|
|
28
|
+
The React context that provides overlay state information for mobile applications. Can be used directly with `React.useContext` or through the `useOverlayContentContext` hook.
|
|
29
|
+
|
|
30
|
+
#### Context Value Type
|
|
31
|
+
|
|
32
|
+
```typescript
|
|
33
|
+
type OverlayContentContextValue = {
|
|
34
|
+
isOverlay?: boolean;
|
|
35
|
+
isModal?: boolean;
|
|
36
|
+
isDrawer?: boolean;
|
|
37
|
+
isTour?: boolean;
|
|
38
|
+
};
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Provider Usage
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { OverlayContentContext } from '@coinbase/cds-common/overlays/OverlayContentContext';
|
|
45
|
+
|
|
46
|
+
function MyMobileOverlayComponent() {
|
|
47
|
+
const contextValue = {
|
|
48
|
+
isModal: true,
|
|
49
|
+
isDrawer: false,
|
|
50
|
+
isTour: false,
|
|
51
|
+
// isOverlay will be automatically derived as true
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<OverlayContentContext.Provider value={contextValue}>
|
|
56
|
+
{/* Your mobile overlay content */}
|
|
57
|
+
</OverlayContentContext.Provider>
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Mobile Considerations
|
|
63
|
+
|
|
64
|
+
On mobile platforms, overlay contexts are particularly useful for:
|
|
65
|
+
|
|
66
|
+
- **Touch Handling**: Adjusting touch behaviors based on overlay type
|
|
67
|
+
- **Safe Areas**: Managing safe area insets differently in overlays vs full-screen content
|
|
68
|
+
- **Navigation**: Preventing or modifying navigation gestures in overlay contexts
|
|
69
|
+
- **Accessibility**: Providing appropriate focus management for screen readers
|
|
70
|
+
|
|
71
|
+
### Automatic Derivation
|
|
72
|
+
|
|
73
|
+
If `isOverlay` is not explicitly provided in the context value, it will be automatically derived as `true` when any of `isModal`, `isDrawer`, or `isTour` is `true`. This ensures consistent behavior across the system.
|
|
74
|
+
|
|
75
|
+
**Important**: When adding new overlay types to the `OverlayContentContextValue` type, remember to update the derivation logic in the `useOverlayContentContext` hook.
|
|
76
|
+
|
|
11
77
|
## Examples
|
|
12
78
|
|
|
13
79
|
The `useOverlayContentContext` hook provides information about whether a component is rendered inside various types of overlay containers on mobile. This is useful for conditional rendering and behavior based on the overlay context.
|
|
@@ -212,4 +278,3 @@ function SafeAreaExample() {
|
|
|
212
278
|
}
|
|
213
279
|
```
|
|
214
280
|
|
|
215
|
-
|