@utilitywarehouse/hearth-react-native 0.6.0 → 0.7.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 (179) hide show
  1. package/.storybook/main.ts +12 -6
  2. package/.turbo/turbo-build.log +1 -1
  3. package/.turbo/turbo-lint.log +1 -1
  4. package/CHANGELOG.md +6 -0
  5. package/build/components/BottomSheet/BottomSheetBackdrop.js +2 -2
  6. package/build/components/BottomSheet/BottomSheetFlatList.js +2 -2
  7. package/build/components/BottomSheet/BottomSheetHandle.js +2 -2
  8. package/build/components/Button/ButtonIcon.js +2 -1
  9. package/build/components/Button/ButtonRoot.js +2 -6
  10. package/build/components/Button/ButtonText.js +4 -1
  11. package/build/components/Card/Card.context.d.ts +7 -0
  12. package/build/components/Card/CardAction/CardAction.context.d.ts +9 -0
  13. package/build/components/Card/{CardAction.context.js → CardAction/CardAction.context.js} +7 -1
  14. package/build/components/Card/CardAction/CardAction.d.ts +18 -0
  15. package/build/components/Card/CardAction/CardAction.js +7 -0
  16. package/build/components/Card/CardAction/CardAction.props.d.ts +63 -0
  17. package/build/components/Card/CardAction/CardAction.props.js +1 -0
  18. package/build/components/Card/CardAction/CardActionContent.d.ts +6 -0
  19. package/build/components/Card/CardAction/CardActionContent.js +13 -0
  20. package/build/components/Card/CardAction/CardActionHelperText.d.ts +6 -0
  21. package/build/components/Card/CardAction/CardActionHelperText.js +13 -0
  22. package/build/components/Card/CardAction/CardActionIcon.d.ts +9 -0
  23. package/build/components/Card/CardAction/CardActionIcon.js +19 -0
  24. package/build/components/Card/CardAction/CardActionLeadingContent.d.ts +6 -0
  25. package/build/components/Card/CardAction/CardActionLeadingContent.js +5 -0
  26. package/build/components/Card/CardAction/CardActionRoot.d.ts +12 -0
  27. package/build/components/Card/CardAction/CardActionRoot.js +155 -0
  28. package/build/components/Card/CardAction/CardActionText.d.ts +6 -0
  29. package/build/components/Card/CardAction/CardActionText.js +9 -0
  30. package/build/components/Card/CardAction/CardActionTrailingContent.d.ts +6 -0
  31. package/build/components/Card/CardAction/CardActionTrailingContent.js +5 -0
  32. package/build/components/Card/CardAction/CardActionTrailingIcon.d.ts +9 -0
  33. package/build/components/Card/CardAction/CardActionTrailingIcon.js +19 -0
  34. package/build/components/Card/CardAction/index.d.ts +10 -0
  35. package/build/components/Card/CardAction/index.js +9 -0
  36. package/build/components/Card/CardContent.d.ts +6 -0
  37. package/build/components/Card/CardContent.js +33 -0
  38. package/build/components/Card/CardPressHandler.context.d.ts +6 -0
  39. package/build/components/Card/CardPressHandler.context.js +6 -0
  40. package/build/components/Card/{CardAction.d.ts → CardPressHandler.d.ts} +3 -3
  41. package/build/components/Card/CardPressHandler.js +13 -0
  42. package/build/components/Card/CardRoot.js +103 -11
  43. package/build/components/Card/index.d.ts +3 -2
  44. package/build/components/Card/index.js +3 -2
  45. package/build/components/Checkbox/CheckboxIcon.js +2 -1
  46. package/build/components/Container/Container.js +3 -3
  47. package/build/components/CurrencyInput/CurrencyInput.js +1 -1
  48. package/build/components/Helper/HelperIcon.js +2 -1
  49. package/build/components/Icon/Icon.d.ts +2 -6
  50. package/build/components/IconButton/IconButtonIcon.js +2 -1
  51. package/build/components/IconContainer/IconContainer.d.ts +4 -3
  52. package/build/components/IconContainer/IconContainer.js +3 -3
  53. package/build/components/Input/InputField.js +4 -2
  54. package/build/components/Input/InputIcon.js +2 -1
  55. package/build/components/Link/LinkIcon.js +3 -2
  56. package/build/components/List/ListAction/ListActionTrailingIcon.js +2 -1
  57. package/build/components/List/ListItem/ListItemIcon.js +2 -1
  58. package/build/components/List/ListItem/ListItemTrailingIcon.js +2 -3
  59. package/build/components/Radio/RadioIcon.js +7 -2
  60. package/build/components/RadioCard/RadioCardIcon.js +3 -2
  61. package/build/components/Spinner/Spinner.js +2 -0
  62. package/build/components/Spinner/Spinner.web.js +2 -0
  63. package/build/components/Switch/Switch.js +5 -3
  64. package/build/components/Switch/Switch.web.js +1 -0
  65. package/build/components/Tabs/TabsList.js +6 -1
  66. package/build/components/Textarea/TextareaField.js +1 -1
  67. package/build/components/ToggleButton/ToggleButtonIcon.js +2 -1
  68. package/build/components/ToggleButton/ToggleButtonRoot.js +2 -2
  69. package/build/components/UnstyledIconButton/UnstyledIconButtonIcon.js +2 -1
  70. package/build/components/index.d.ts +1 -1
  71. package/build/components/index.js +1 -1
  72. package/build/core/index.d.ts +3 -3
  73. package/build/core/index.js +3 -3
  74. package/build/core/themes.d.ts +24 -12
  75. package/build/hooks/useColorMode.d.ts +1 -1
  76. package/build/hooks/useColorMode.js +7 -8
  77. package/build/tokens/components/dark/banner.d.ts +19 -0
  78. package/build/tokens/components/dark/banner.js +19 -0
  79. package/build/tokens/components/dark/card-action.d.ts +11 -0
  80. package/build/tokens/components/dark/card-action.js +10 -0
  81. package/build/tokens/components/dark/card-content.d.ts +25 -0
  82. package/build/tokens/components/dark/card-content.js +24 -0
  83. package/build/tokens/components/dark/drawer.d.ts +29 -0
  84. package/build/tokens/components/dark/drawer.js +28 -0
  85. package/build/tokens/components/dark/illustrations.d.ts +0 -1
  86. package/build/tokens/components/dark/illustrations.js +0 -1
  87. package/build/tokens/components/dark/index.d.ts +3 -0
  88. package/build/tokens/components/dark/index.js +3 -0
  89. package/build/tokens/components/light/banner.d.ts +19 -0
  90. package/build/tokens/components/light/banner.js +19 -0
  91. package/build/tokens/components/light/card-action.d.ts +11 -0
  92. package/build/tokens/components/light/card-action.js +10 -0
  93. package/build/tokens/components/light/card-content.d.ts +25 -0
  94. package/build/tokens/components/light/card-content.js +24 -0
  95. package/build/tokens/components/light/drawer.d.ts +29 -0
  96. package/build/tokens/components/light/drawer.js +28 -0
  97. package/build/tokens/components/light/illustrations.d.ts +0 -1
  98. package/build/tokens/components/light/illustrations.js +0 -1
  99. package/build/tokens/components/light/index.d.ts +3 -0
  100. package/build/tokens/components/light/index.js +3 -0
  101. package/build/tokens/layout.d.ts +6 -6
  102. package/build/tokens/layout.js +3 -3
  103. package/build/tokens/typography.d.ts +6 -0
  104. package/build/tokens/typography.js +3 -0
  105. package/docs/components/NextPrevPage.tsx +5 -5
  106. package/docs/components/VariantTitle.tsx +17 -7
  107. package/package.json +16 -14
  108. package/src/components/BottomSheet/BottomSheetBackdrop.tsx +2 -2
  109. package/src/components/BottomSheet/BottomSheetFlatList.tsx +2 -3
  110. package/src/components/BottomSheet/BottomSheetHandle.tsx +1 -1
  111. package/src/components/Button/ButtonIcon.tsx +2 -1
  112. package/src/components/Button/ButtonRoot.tsx +2 -6
  113. package/src/components/Button/ButtonText.tsx +4 -1
  114. package/src/components/Card/Card.context.ts +7 -0
  115. package/src/components/Card/Card.docs.mdx +212 -14
  116. package/src/components/Card/Card.stories.tsx +50 -3
  117. package/src/components/Card/CardAction/CardAction.context.ts +22 -0
  118. package/src/components/Card/CardAction/CardAction.props.ts +87 -0
  119. package/src/components/Card/CardAction/CardAction.stories.tsx +265 -0
  120. package/src/components/Card/CardAction/CardAction.tsx +10 -0
  121. package/src/components/Card/CardAction/CardActionContent.tsx +20 -0
  122. package/src/components/Card/CardAction/CardActionHelperText.tsx +21 -0
  123. package/src/components/Card/CardAction/CardActionIcon.tsx +32 -0
  124. package/src/components/Card/CardAction/CardActionLeadingContent.tsx +9 -0
  125. package/src/components/Card/CardAction/CardActionRoot.tsx +258 -0
  126. package/src/components/Card/CardAction/CardActionText.tsx +17 -0
  127. package/src/components/Card/CardAction/CardActionTrailingContent.tsx +9 -0
  128. package/src/components/Card/CardAction/CardActionTrailingIcon.tsx +32 -0
  129. package/src/components/Card/CardAction/index.ts +10 -0
  130. package/src/components/Card/CardContent.tsx +40 -0
  131. package/src/components/Card/CardPressHandler.context.ts +12 -0
  132. package/src/components/Card/CardPressHandler.tsx +20 -0
  133. package/src/components/Card/CardRoot.tsx +128 -13
  134. package/src/components/Card/index.ts +3 -2
  135. package/src/components/Checkbox/CheckboxIcon.tsx +2 -1
  136. package/src/components/Container/Container.tsx +3 -3
  137. package/src/components/CurrencyInput/CurrencyInput.tsx +1 -1
  138. package/src/components/Helper/HelperIcon.tsx +2 -1
  139. package/src/components/Icon/Icon.tsx +4 -3
  140. package/src/components/IconButton/IconButtonIcon.tsx +2 -1
  141. package/src/components/IconContainer/IconContainer.tsx +17 -19
  142. package/src/components/Input/InputField.tsx +2 -1
  143. package/src/components/Input/InputIcon.tsx +2 -1
  144. package/src/components/Link/LinkIcon.tsx +3 -2
  145. package/src/components/List/ListAction/ListActionTrailingIcon.tsx +2 -1
  146. package/src/components/List/ListItem/ListItemIcon.tsx +2 -1
  147. package/src/components/List/ListItem/ListItemTrailingIcon.tsx +2 -3
  148. package/src/components/Radio/RadioIcon.tsx +8 -3
  149. package/src/components/RadioCard/RadioCardIcon.tsx +4 -3
  150. package/src/components/Spinner/Spinner.tsx +2 -0
  151. package/src/components/Spinner/Spinner.web.tsx +2 -0
  152. package/src/components/Switch/Switch.tsx +10 -5
  153. package/src/components/Switch/Switch.web.tsx +5 -0
  154. package/src/components/Tabs/TabsList.tsx +2 -0
  155. package/src/components/Textarea/TextareaField.tsx +1 -1
  156. package/src/components/ToggleButton/ToggleButtonIcon.tsx +2 -1
  157. package/src/components/ToggleButton/ToggleButtonRoot.tsx +2 -2
  158. package/src/components/UnstyledIconButton/UnstyledIconButtonIcon.tsx +2 -1
  159. package/src/components/index.ts +1 -9
  160. package/src/core/index.ts +14 -11
  161. package/src/hooks/useColorMode.ts +9 -12
  162. package/src/tokens/components/dark/banner.ts +19 -0
  163. package/src/tokens/components/dark/card-action.ts +11 -0
  164. package/src/tokens/components/dark/card-content.ts +25 -0
  165. package/src/tokens/components/dark/drawer.ts +29 -0
  166. package/src/tokens/components/dark/illustrations.ts +0 -1
  167. package/src/tokens/components/dark/index.ts +3 -0
  168. package/src/tokens/components/light/banner.ts +19 -0
  169. package/src/tokens/components/light/card-action.ts +11 -0
  170. package/src/tokens/components/light/card-content.ts +25 -0
  171. package/src/tokens/components/light/drawer.ts +29 -0
  172. package/src/tokens/components/light/illustrations.ts +0 -1
  173. package/src/tokens/components/light/index.ts +3 -0
  174. package/src/tokens/layout.ts +3 -3
  175. package/src/tokens/typography.ts +3 -0
  176. package/build/components/Card/CardAction.context.d.ts +0 -6
  177. package/build/components/Card/CardAction.js +0 -13
  178. package/src/components/Card/CardAction.context.ts +0 -12
  179. package/src/components/Card/CardAction.tsx +0 -18
@@ -2,6 +2,7 @@ import { Canvas, Controls, Meta, Primary, Story } from '@storybook/addon-docs/bl
2
2
  import { BodyText, Card, Center, DetailText } from '../../';
3
3
  import { BackToTopButton, UsageWrap, ViewFigmaButton } from '../../../docs/components';
4
4
  import * as Stories from './Card.stories';
5
+ import * as ActionStories from './CardAction/CardAction.stories';
5
6
 
6
7
  <Meta title="Components / Card" />
7
8
 
@@ -17,7 +18,9 @@ A Card component serves as a visual container that groups related content and ac
17
18
  - [Usage](#usage)
18
19
  - [Props](#props)
19
20
  - [Variants](#variants)
20
- - [Interactive](#interactive)
21
+ - [Examples](#examples)
22
+ - [Interactive](#interactive)
23
+ - [With `CardAction`](#with-cardaction)
21
24
 
22
25
  ## Playground
23
26
 
@@ -55,7 +58,7 @@ const MyComponent = () => (
55
58
  | colorScheme | `'neutralStrong' \| 'neutralSubtle' \| 'purple' \| 'energy'` <br /> `'broadband' \| 'mobile' \| 'insurance' \| 'cashback' \|` <br /> `'pig'` | The color scheme of the card. | `'neutralStrong'` |
56
59
  | noPadding | `boolean` | Wether or not the card has padding. | `false` |
57
60
  | selected | `boolean` | Whether the card is selected. | `false` |
58
- | onPress | `() => void` | Callback function to be called. | - |
61
+ | onPress | `() => void` | Callback function to be called. | `-` |
59
62
  | disabled | `boolean` | Whether the card is disabled. | `false` |
60
63
  | space | `'none' \| '2xs' \| 'xs' \| 'sm' \| 'md' \| 'lg' \| 'xl' \| '2xl'` | The space between the content. | `none` |
61
64
  | alignItems | `'flex-start' \| 'flex-end' \| `<br />`'center' \| 'stretch' \| 'baseline'` | The align items of the flex container. | `flex-start` |
@@ -66,42 +69,237 @@ const MyComponent = () => (
66
69
  | rowGap | `number` | The row gap between the content. | `0` |
67
70
  | columnGap | `number` | The column gap between the content. | `0` |
68
71
 
72
+ ### `CardPressHandler`
73
+
74
+ | Property | Type | Description | Default |
75
+ | ---------------- | -------- | --------------------------------------------------------------------------- | --------- |
76
+ | handlerToInherit | `string` | The handler to inherit from the child component when the `Card` is pressed. | `onPress` |
77
+
69
78
  ### `CardAction`
70
79
 
71
- | Property | Type | Description | Default |
72
- | --------------- | -------- | -------------------------------------------------------------------------- | --------- |
73
- | actionToInherit | `string` | The action to inherit from the child component when the `Card` is pressed. | `onPress` |
80
+ | Property | Type | Description | Default |
81
+ | -------------------- | -------------------------------------------------------------------------------------------------- | -------------------------------------------------------- | ---------- |
82
+ | loading | `boolean` | Show loading skeleton state | `false` |
83
+ | disabled | `boolean` | Disable interactions | `false` |
84
+ | size | `'md' \| 'lg'` | Size of the heading text | `'md'` |
85
+ | onPress | `() => void` | Callback when the action is pressed | `-` |
86
+ | heading | `string` | The main heading text (required when not using children) | `-` |
87
+ | helperText | `string` | Optional secondary text below the heading | `-` |
88
+ | leadingIcon | `ReactNode` | The leading icon. | `-` |
89
+ | trailingIcon | `ReactNode` | The trailing icon. | `-` |
90
+ | leadingContent | `ReactNode` | Content to display on the left (typically an icon) | `-` |
91
+ | trailingContent | `ReactNode` | Content to display on the right (typically an icon) | `-` |
92
+ | iconContainer | `boolean` | Whether to show the icon container | `false` |
93
+ | iconContainerVariant | `'subtle' \| 'emphasis'` | Variant of the icon container | `'subtle'` |
94
+ | iconContainerColor | `'pig' \| 'energy' \| 'broadband' \| 'mobile' \|` <br />`'insurance' \| 'cashback' \| 'highlight'` | Semantic colour family for surface tokens | `pig` |
95
+ | badge | `BadgeProps` | Badge configuration object | |
96
+ | badgePosition | `'bottom' \| 'middle' \| 'right' \| 'top'` | Position of the badge | `'bottom'` |
74
97
 
75
98
  ## Variants
76
99
 
77
100
  <Canvas of={Stories.Variants} />
78
101
 
79
- ## Interactive
102
+ ## Examples
103
+
104
+ ### Interactive
80
105
 
81
106
  You can make the card interactive by adding an `onPress` prop. You can also toggle the `selected` prop
82
107
  to change the card's appearance.
83
108
 
84
- Alternatively to make the card inherit an action from a child component, you can use the `CardAction` component.
85
- This will by default inherit the `onPress` action from the child component. You can specify a different action
86
- by passing the `actionToInherit` prop e.g `onChange`. Wrapping a component in a `CardAction` component will
109
+ Alternatively to make the card inherit an event handler from a child component, you can use the `CardPressHandler` component.
110
+ This will by default inherit the `onPress` handler from the child component. You can specify a different action
111
+ by passing the `handlerToInherit` prop e.g `onChange`. Wrapping a component in a `CardPressHandler` component will
87
112
  make the card interactive and also show the `active` state of the child component when the `Card` is pressed.
88
113
 
89
114
  <Canvas of={Stories.Interactive} />
90
115
 
91
- See example below for how to use the `CardAction` component:
116
+ See example below for how to use the `CardPressHandler` component:
92
117
 
93
118
  ```jsx
94
- import { Card, CardAction, BodyText, Heading, Felx, Button } from '@utilitywarehouse/hearth-react-native';
119
+ import {
120
+ Card,
121
+ CardPressHandler,
122
+ BodyText,
123
+ Heading,
124
+ Flex,
125
+ Button,
126
+ } from '@utilitywarehouse/hearth-react-native';
95
127
 
96
128
  const MyComponent = () => (
97
129
  <Card variant="emphasis" colorScheme="neutralSubtle">
98
130
  <Flex space="md" direction="column" align="stretch">
99
131
  <Heading size="md">Heading</Heading>
100
- <BodyText>{children as string}</BodyText>
101
- <CardAction>
132
+ <BodyText>Content</BodyText>
133
+ <CardPressHandler>
102
134
  <Button onPress={() => console.log('pressed')}>Press me</Button>
103
- </CardAction>
135
+ </CardPressHandler>
104
136
  </Flex>
105
137
  </Card>
106
138
  );
107
139
  ```
140
+
141
+ ### With `CardAction`
142
+
143
+ You can use the `CardAction` component within a `Card` to create actionable items with consistent styling.
144
+
145
+ <Canvas of={Stories.WithActions} />
146
+
147
+ ```jsx
148
+ import { Card, CardAction, BodyText, Heading, Flex } from '@utilitywarehouse/hearth-react-native';
149
+
150
+ const MyComponent = () => (
151
+ <Card variant="emphasis">
152
+ <BodyText>Content</BodyText>
153
+ <CardAction
154
+ onPress={() => console.log('Card action pressed')}
155
+ heading="Card Action Head"
156
+ helperText="Some helper text"
157
+ leadingIcon={BellMediumIcon}
158
+ />
159
+ <CardAction
160
+ onPress={() => console.log('Card action pressed')}
161
+ heading="Card Action Head"
162
+ leadingIcon={BellMediumIcon}
163
+ />
164
+ <CardAction
165
+ onPress={() => console.log('Card action pressed')}
166
+ heading="Card Action Head"
167
+ helperText="Testing"
168
+ leadingIcon={BellMediumIcon}
169
+ iconContainer={false}
170
+ />
171
+ </Card>
172
+ );
173
+ ```
174
+
175
+ #### `CardAction` Playground
176
+
177
+ <Canvas of={ActionStories.Playground} />
178
+ <Controls of={ActionStories.Playground} />
179
+
180
+ #### `CardAction` With Badge
181
+
182
+ The badge can be positioned in three different locations:
183
+
184
+ ```tsx
185
+ import { Card, CardAction } from '@utilitywarehouse/hearth-react-native';
186
+
187
+ const MyComponent = () => (
188
+ <>
189
+ {/* Badge at bottom (default) */}
190
+ <Card>
191
+ <CardAction
192
+ heading="Action"
193
+ helperText="Helper text"
194
+ badge={{ text: 'New' }}
195
+ badgePosition="bottom"
196
+ onPress={() => console.log('pressed')}
197
+ />
198
+ </Card>
199
+
200
+ {/* Badge in middle (between heading and helper text) */}
201
+ <Card>
202
+ <CardAction
203
+ heading="Action"
204
+ helperText="Helper text"
205
+ badge={{ text: 'New' }}
206
+ badgePosition="middle"
207
+ onPress={() => console.log('pressed')}
208
+ />
209
+ </Card>
210
+
211
+ {/* Badge on the right */}
212
+ <Card>
213
+ <CardAction
214
+ heading="Action"
215
+ helperText="Helper text"
216
+ badge={{ text: 'New' }}
217
+ badgePosition="right"
218
+ onPress={() => console.log('pressed')}
219
+ />
220
+ </Card>
221
+ </>
222
+ );
223
+ ```
224
+
225
+ #### `CardAction` Size Variants
226
+
227
+ ```tsx
228
+ import { Card, CardAction } from '@utilitywarehouse/hearth-react-native';
229
+
230
+ const MyComponent = () => (
231
+ <>
232
+ <Card>
233
+ <CardAction
234
+ heading="Medium heading"
235
+ helperText="Default md size"
236
+ size="md"
237
+ onPress={() => console.log('pressed')}
238
+ />
239
+ </Card>
240
+
241
+ <Card>
242
+ <CardAction
243
+ heading="Large heading"
244
+ helperText="Larger lg size"
245
+ size="lg"
246
+ onPress={() => console.log('pressed')}
247
+ />
248
+ </Card>
249
+ </>
250
+ );
251
+ ```
252
+
253
+ #### `CardAction` Advanced Usage with Children
254
+
255
+ For more complex layouts, you can use the component parts directly:
256
+
257
+ ```tsx
258
+ import {
259
+ Card,
260
+ CardAction,
261
+ CardActionLeadingContent,
262
+ CardActionContent,
263
+ CardActionText,
264
+ CardActionHelperText,
265
+ CardActionTrailingContent,
266
+ CardActionIcon,
267
+ CardActionTrailingIcon,
268
+ } from '@utilitywarehouse/hearth-react-native';
269
+ import {
270
+ ElectricityMediumIcon,
271
+ ChevronRightSmallIcon,
272
+ } from '@utilitywarehouse/hearth-react-native-icons';
273
+
274
+ const MyComponent = () => (
275
+ <Card>
276
+ <CardAction onPress={() => console.log('pressed')}>
277
+ <CardActionLeadingContent>
278
+ <CardActionIcon as={ElectricityMediumIcon} />
279
+ </CardActionLeadingContent>
280
+ <CardActionContent>
281
+ <CardActionText>Custom Layout</CardActionText>
282
+ <CardActionHelperText>With complete control</CardActionHelperText>
283
+ </CardActionContent>
284
+ <CardActionTrailingContent>
285
+ <CardActionTrailingIcon as={ChevronRightSmallIcon} />
286
+ </CardActionTrailingContent>
287
+ </CardAction>
288
+ </Card>
289
+ );
290
+ ```
291
+
292
+ #### `CardAction` Component Parts
293
+
294
+ - `CardAction` - Main component wrapper
295
+ - `CardActionContent` - Container for text content
296
+ - `CardActionText` - Heading text
297
+ - `CardActionHelperText` - Secondary helper text
298
+ - `CardActionLeadingContent` - Container for leading content
299
+ - `CardActionTrailingContent` - Container for trailing content
300
+ - `CardActionIcon` - Styled icon for leading content
301
+ - `CardActionTrailingIcon` - Styled icon for trailing content
302
+
303
+ #### `CardAction` Accessibility
304
+
305
+ The component automatically sets `accessibilityRole="button"` when an `onPress` handler is provided, ensuring proper screen reader announcements.
@@ -1,5 +1,6 @@
1
1
  import { Meta, StoryObj } from '@storybook/react-vite';
2
- import { Card, CardAction } from '.';
2
+ import { BellMediumIcon } from '@utilitywarehouse/hearth-react-native-icons';
3
+ import { Card, CardAction, CardPressHandler } from '.';
3
4
  import { VariantTitle } from '../../../docs/components';
4
5
  import { BodyText } from '../BodyText';
5
6
  import { Button } from '../Button';
@@ -59,6 +60,52 @@ export const Playground: Story = {
59
60
  },
60
61
  };
61
62
 
63
+ export const WithActions: Story = {
64
+ render: ({ children, ...props }) => {
65
+ return (
66
+ <Card {...props} flexDirection="column" alignItems="stretch" space="md" variant="emphasis">
67
+ <BodyText>{children as string}</BodyText>
68
+ <CardAction
69
+ onPress={() => console.log('Card action pressed')}
70
+ heading="Card Action Head"
71
+ helperText="Some helper text"
72
+ leadingIcon={BellMediumIcon}
73
+ />
74
+ <CardAction
75
+ onPress={() => console.log('Card action pressed')}
76
+ heading="Card Action Head"
77
+ leadingIcon={BellMediumIcon}
78
+ />
79
+ <CardAction
80
+ onPress={() => console.log('Card action pressed')}
81
+ heading="Card Action Head"
82
+ helperText="Testing"
83
+ leadingIcon={BellMediumIcon}
84
+ iconContainer={false}
85
+ />
86
+ </Card>
87
+ );
88
+ },
89
+ };
90
+
91
+ export const WithOnlyAction: Story = {
92
+ args: {
93
+ variant: 'emphasis',
94
+ },
95
+ render: ({ children, ...props }) => {
96
+ return (
97
+ <Card {...props} flexDirection="column" alignItems="stretch" space="md">
98
+ <CardAction
99
+ onPress={() => console.log('Card action pressed')}
100
+ heading="Card Action Head"
101
+ helperText="Some helper text"
102
+ leadingIcon={BellMediumIcon}
103
+ />
104
+ </Card>
105
+ );
106
+ },
107
+ };
108
+
62
109
  export const Variants: Story = {
63
110
  parameters: {
64
111
  controls: { exclude: ['variant', 'colorScheme'] },
@@ -224,9 +271,9 @@ export const Interactive: Story = {
224
271
  >
225
272
  <Heading size="md">Heading</Heading>
226
273
  <BodyText>{children as string}</BodyText>
227
- <CardAction>
274
+ <CardPressHandler>
228
275
  <Button onPress={() => console.log('pressed')}>Press me</Button>
229
- </CardAction>
276
+ </CardPressHandler>
230
277
  </Card>
231
278
  </VariantTitle>
232
279
  </Flex>
@@ -0,0 +1,22 @@
1
+ import { createContext, useContext } from 'react';
2
+
3
+ export interface ICardActionContext {
4
+ showPressed: boolean;
5
+ active?: boolean;
6
+ loading: boolean;
7
+ disabled: boolean;
8
+ size: 'md' | 'lg';
9
+ }
10
+
11
+ export const CardActionContext = createContext<ICardActionContext>({
12
+ showPressed: false,
13
+ active: false,
14
+ loading: false,
15
+ disabled: false,
16
+ size: 'md',
17
+ });
18
+
19
+ export const useCardActionContext = () => {
20
+ const context = useContext(CardActionContext);
21
+ return context;
22
+ };
@@ -0,0 +1,87 @@
1
+ import { ComponentType } from 'react';
2
+ import type { PressableProps, ViewProps } from 'react-native';
3
+ import BadgeProps from '../../Badge/Badge.props';
4
+ import { IconContainerProps } from '../../IconContainer';
5
+
6
+ interface CardActionBaseProps extends Omit<PressableProps, 'children'> {
7
+ loading?: boolean;
8
+ disabled?: boolean;
9
+ size?: 'md' | 'lg';
10
+ }
11
+
12
+ interface CardActionContentProps {
13
+ heading: string;
14
+ helperText?: string;
15
+ badge?: BadgeProps;
16
+ badgePosition?: 'bottom' | 'middle' | 'right' | 'top';
17
+ iconContainer?: boolean;
18
+ iconContainerVariant?: IconContainerProps['variant'];
19
+ iconContainerColor?: IconContainerProps['color'];
20
+ }
21
+
22
+ export interface CardActionWithChildren extends CardActionBaseProps {
23
+ children: ViewProps['children'];
24
+ heading?: never;
25
+ helperText?: never;
26
+ leadingContent?: never;
27
+ leadingIcon?: never;
28
+ trailingContent?: never;
29
+ trailingIcon?: never;
30
+ badge?: never;
31
+ badgePosition?: never;
32
+ iconContainer?: never;
33
+ iconContainerVariant?: never;
34
+ iconContainerColor?: never;
35
+ }
36
+
37
+ // Leading content variants
38
+ type CardActionWithLeadingContent = CardActionBaseProps &
39
+ CardActionContentProps & {
40
+ children?: never;
41
+ leadingContent: ViewProps['children'];
42
+ leadingIcon?: never;
43
+ };
44
+
45
+ type CardActionWithLeadingIcon = CardActionBaseProps &
46
+ CardActionContentProps & {
47
+ children?: never;
48
+ leadingContent?: never;
49
+ leadingIcon: ComponentType;
50
+ };
51
+
52
+ type CardActionWithNoLeading = CardActionBaseProps &
53
+ CardActionContentProps & {
54
+ children?: never;
55
+ leadingContent?: never;
56
+ leadingIcon?: never;
57
+ };
58
+
59
+ type CardActionLeadingVariants =
60
+ | CardActionWithLeadingContent
61
+ | CardActionWithLeadingIcon
62
+ | CardActionWithNoLeading;
63
+
64
+ // Trailing content combined with leading variants
65
+ type CardActionWithTrailingContent = CardActionLeadingVariants & {
66
+ trailingContent: ViewProps['children'];
67
+ trailingIcon?: never;
68
+ };
69
+
70
+ type CardActionWithTrailingIcon = CardActionLeadingVariants & {
71
+ trailingContent?: never;
72
+ trailingIcon: ComponentType;
73
+ };
74
+
75
+ type CardActionWithNoTrailing = CardActionLeadingVariants & {
76
+ trailingContent?: never;
77
+ trailingIcon?: never;
78
+ };
79
+
80
+ type CardActionWithoutChildren =
81
+ | CardActionWithTrailingContent
82
+ | CardActionWithTrailingIcon
83
+ | CardActionWithNoTrailing;
84
+
85
+ type CardActionProps = CardActionWithChildren | CardActionWithoutChildren;
86
+
87
+ export default CardActionProps;