@utilitywarehouse/hearth-react-native 0.16.1 → 0.17.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 (73) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-lint.log +14 -14
  3. package/CHANGELOG.md +156 -0
  4. package/build/components/Card/CardAction/CardActionRoot.js +12 -2
  5. package/build/components/Card/CardActions.context.d.ts +6 -0
  6. package/build/components/Card/CardActions.context.js +5 -0
  7. package/build/components/Card/CardActions.d.ts +7 -0
  8. package/build/components/Card/CardActions.js +29 -0
  9. package/build/components/Card/CardRoot.js +16 -104
  10. package/build/components/Card/helpers.d.ts +8 -0
  11. package/build/components/Card/helpers.js +146 -0
  12. package/build/components/Card/index.d.ts +2 -0
  13. package/build/components/Card/index.js +2 -0
  14. package/build/components/DateInput/DateInput.d.ts +1 -1
  15. package/build/components/DateInput/DateInput.js +2 -3
  16. package/build/components/DateInput/DateInput.props.d.ts +22 -1
  17. package/build/components/DateInput/DateInputSegment.d.ts +2 -16
  18. package/build/components/DateInput/DateInputSegment.js +3 -6
  19. package/build/components/ExpandableCard/ExpandableCardGroup.d.ts +1 -1
  20. package/build/components/ExpandableCard/ExpandableCardGroup.js +2 -2
  21. package/build/components/ExpandableCard/ExpandableCardGroup.props.d.ts +4 -0
  22. package/build/components/Input/Input.js +4 -3
  23. package/build/components/Input/Input.props.d.ts +9 -0
  24. package/build/components/List/List.context.d.ts +4 -2
  25. package/build/components/List/List.context.js +0 -2
  26. package/build/components/List/List.d.ts +1 -1
  27. package/build/components/List/List.js +25 -38
  28. package/build/components/List/List.props.d.ts +1 -0
  29. package/build/components/List/ListAction/ListAction.js +24 -7
  30. package/build/components/List/ListAction/ListAction.props.d.ts +1 -0
  31. package/build/components/List/ListItem/ListItemRoot.js +12 -4
  32. package/build/utils/isThemedImageProps.d.ts +1 -1
  33. package/package.json +2 -2
  34. package/src/components/Card/Card.docs.mdx +224 -66
  35. package/src/components/Card/Card.stories.tsx +29 -25
  36. package/src/components/Card/CardAction/CardAction.stories.tsx +239 -93
  37. package/src/components/Card/CardAction/CardActionRoot.tsx +15 -2
  38. package/src/components/Card/CardActions.context.ts +12 -0
  39. package/src/components/Card/CardActions.tsx +40 -0
  40. package/src/components/Card/CardRoot.tsx +27 -132
  41. package/src/components/Card/helpers.tsx +195 -0
  42. package/src/components/Card/index.ts +2 -0
  43. package/src/components/DateInput/DateInput.docs.mdx +47 -29
  44. package/src/components/DateInput/DateInput.props.ts +32 -1
  45. package/src/components/DateInput/DateInput.stories.tsx +10 -0
  46. package/src/components/DateInput/DateInput.tsx +12 -1
  47. package/src/components/DateInput/DateInputSegment.tsx +8 -23
  48. package/src/components/ExpandableCard/ExpandableCard.figma.tsx +33 -38
  49. package/src/components/ExpandableCard/ExpandableCardGroup.figma.tsx +34 -17
  50. package/src/components/ExpandableCard/ExpandableCardGroup.props.ts +5 -0
  51. package/src/components/ExpandableCard/ExpandableCardGroup.tsx +2 -0
  52. package/src/components/HighlightBanner/HighlightBanner.figma.tsx +46 -0
  53. package/src/components/IconButton/IconButton.figma.tsx +20 -30
  54. package/src/components/IconContainer/IconContainer.figma.tsx +7 -13
  55. package/src/components/IndicatorIconButton/IndicatorIconButton.figma.tsx +16 -0
  56. package/src/components/Input/Input.docs.mdx +55 -15
  57. package/src/components/Input/Input.figma.tsx +106 -40
  58. package/src/components/Input/Input.props.ts +9 -0
  59. package/src/components/Input/Input.tsx +21 -0
  60. package/src/components/Link/Link.figma.tsx +31 -38
  61. package/src/components/List/List.context.ts +2 -4
  62. package/src/components/List/List.docs.mdx +10 -5
  63. package/src/components/List/List.figma.tsx +42 -28
  64. package/src/components/List/List.props.ts +1 -0
  65. package/src/components/List/List.stories.tsx +43 -0
  66. package/src/components/List/List.tsx +38 -51
  67. package/src/components/List/ListAction/ListAction.figma.tsx +5 -13
  68. package/src/components/List/ListAction/ListAction.props.ts +1 -0
  69. package/src/components/List/ListAction/ListAction.tsx +40 -10
  70. package/src/components/List/ListItem/ListItem.figma.tsx +43 -27
  71. package/src/components/List/ListItem/ListItemRoot.tsx +15 -4
  72. package/src/utils/isThemedImageProps.ts +1 -1
  73. package/src/components/InlineLink/InlineLink.figma.tsx +0 -33
@@ -1,104 +1,18 @@
1
- import React, { ReactNode, useMemo } from 'react';
1
+ import { ReactNode, useMemo } from 'react';
2
2
  import { GestureResponderEvent, Pressable, ViewStyle } from 'react-native';
3
3
  import { StyleSheet } from 'react-native-unistyles';
4
4
  import { useStyleProps } from '../../hooks';
5
5
  import { CardContext } from './Card.context';
6
6
  import CardProps from './Card.props';
7
+ import CardActions from './CardActions';
7
8
  import CardContent from './CardContent';
8
-
9
- // Helper to check if children contain specific component types
10
- const checkForComponentType = (children: React.ReactNode, displayName: string): boolean => {
11
- return React.Children.toArray(children).some(child => {
12
- if (React.isValidElement(child)) {
13
- // @ts-expect-error - type
14
- if (child.type.displayName === displayName) {
15
- return true;
16
- }
17
- const childProps = child.props as any;
18
- if (childProps.children) {
19
- return checkForComponentType(childProps.children, displayName);
20
- }
21
- }
22
- return false;
23
- });
24
- };
25
-
26
- // Helper to filter out specific component types from children
27
- const filterChildren = (children: React.ReactNode, excludeDisplayName: string): React.ReactNode => {
28
- return React.Children.map(children, child => {
29
- if (React.isValidElement(child)) {
30
- // @ts-expect-error - type
31
- if (child.type.displayName === excludeDisplayName) {
32
- return null;
33
- }
34
- const childProps = child.props as any;
35
- if (childProps.children) {
36
- return React.cloneElement(child, {
37
- ...childProps,
38
- children: filterChildren(childProps.children, excludeDisplayName),
39
- });
40
- }
41
- }
42
- return child;
43
- });
44
- };
45
-
46
- // Helper to extract specific component types from children
47
- const extractChildren = (
48
- children: React.ReactNode,
49
- includeDisplayName: string,
50
- markFirst = false
51
- ): React.ReactNode => {
52
- let isFirstFound = false;
53
- return React.Children.map(children, child => {
54
- if (React.isValidElement(child)) {
55
- // @ts-expect-error - type
56
- if (child.type.displayName === includeDisplayName) {
57
- const isFirst = markFirst && !isFirstFound;
58
- if (isFirst) {
59
- isFirstFound = true;
60
- }
61
- return markFirst
62
- ? React.cloneElement(child, { ...(child.props || {}), isFirst } as any)
63
- : child;
64
- }
65
- const childProps = child.props as any;
66
- if (childProps.children) {
67
- return extractChildren(childProps.children, includeDisplayName, markFirst);
68
- }
69
- }
70
- return null;
71
- });
72
- };
73
-
74
- // Helper that recursively collects onPress or other defined handlers from descendants
75
- const collectChildActionHandlers = (
76
- children: React.ReactNode
77
- ): Array<(e: GestureResponderEvent) => void> =>
78
- React.Children.toArray(children).reduce(
79
- (handlers, child) => {
80
- if (React.isValidElement(child)) {
81
- const childProps = child.props as any;
82
- // @ts-expect-error - type
83
- if (child.type.displayName === 'CardPressHandler') {
84
- const actionChildren = React.Children.toArray(childProps.children);
85
- const handlerToInherit = childProps['handlerToInherit'] || 'onPress';
86
- const firstChild = actionChildren[0];
87
- if (
88
- React.isValidElement(firstChild) &&
89
- typeof (firstChild.props as any)[handlerToInherit] === 'function'
90
- ) {
91
- handlers.push((firstChild.props as any)[handlerToInherit]);
92
- }
93
- }
94
- if (childProps.children) {
95
- handlers.push(...collectChildActionHandlers(childProps.children));
96
- }
97
- }
98
- return handlers;
99
- },
100
- [] as Array<(e: GestureResponderEvent) => void>
101
- );
9
+ import {
10
+ checkForComponentType,
11
+ collectChildActionHandlers,
12
+ extractCardActions,
13
+ filterChildren,
14
+ hasOnlyPotentialActions,
15
+ } from './helpers';
102
16
 
103
17
  const Card = ({
104
18
  children,
@@ -116,8 +30,8 @@ const Card = ({
116
30
  }: CardProps & { states?: { active?: boolean; disabled?: boolean } }) => {
117
31
  const { active } = states || { active: false };
118
32
  const childActionHandlers = collectChildActionHandlers(children as ReactNode);
119
- const hasActions = checkForComponentType(children as ReactNode, 'CardAction');
120
- const hasContent = checkForComponentType(children as ReactNode, 'CardContent');
33
+ const hasActions = checkForComponentType(children as ReactNode, CardActions);
34
+ const hasContent = checkForComponentType(children as ReactNode, CardContent);
121
35
  // Extract style props using our custom hook
122
36
  const { computedStyles, remainingProps } = useStyleProps(rest);
123
37
 
@@ -132,19 +46,9 @@ const Card = ({
132
46
  const inheritChildAction = childActionHandlers.length > 0;
133
47
  const showPressed = inheritChildAction || !!onPress;
134
48
 
135
- const filteredChildren =
136
- !hasContent && hasActions ? filterChildren(children as ReactNode, 'CardAction') : null;
137
-
138
- // Check if there's any content besides CardActions
139
- const hasOnlyActions =
140
- hasActions &&
141
- !hasContent &&
142
- React.Children.toArray(filteredChildren).filter(child => child != null).length === 0;
143
-
144
- const filteredCardActions =
145
- !hasContent && hasActions
146
- ? extractChildren(children as ReactNode, 'CardAction', hasOnlyActions)
147
- : null;
49
+ // Check if all children are action groups (CardActions)
50
+ const potentiallyOnlyActions = hasOnlyPotentialActions(children as ReactNode, CardActions);
51
+ const hasOnlyActions = potentiallyOnlyActions && !hasContent;
148
52
 
149
53
  const context = useMemo(
150
54
  () => ({
@@ -162,38 +66,30 @@ const Card = ({
162
66
  styles.useVariants({
163
67
  variant,
164
68
  colorScheme,
165
- noPadding: noPadding || hasActions || hasContent,
69
+ noPadding: noPadding || hasActions || hasContent || hasOnlyActions,
166
70
  active,
167
71
  showPressed,
168
72
  disabled,
169
- space: hasActions || hasContent ? 'none' : space,
73
+ space: hasActions || hasContent || hasOnlyActions ? 'none' : space,
170
74
  shadowColor,
171
75
  });
172
76
 
173
77
  const renderChildren = () => {
174
- // Default: render children as-is
175
- if (hasContent || !hasActions) {
78
+ // Explicit CardContent used - render as-is or Card has only actions (or potential action wrappers) - render children directly
79
+ if (hasContent || hasOnlyActions || !hasActions) {
176
80
  return children as ReactNode;
177
81
  }
178
82
 
179
- // Card has actions but no explicit CardContent
180
- if (hasOnlyActions) {
181
- // Only CardActions, no other content - render actions directly
182
- return filteredCardActions as ReactNode;
183
- }
83
+ // Has both actions and other content - wrap non-action content and render actions separately
84
+ const filteredNonActionChildren = filterChildren(children as ReactNode, CardActions);
85
+ const cardActions = extractCardActions(children as ReactNode, CardActions);
184
86
 
185
- if (filteredChildren) {
186
- // Has both actions and other content - wrap content and render actions below
187
- return (
188
- <>
189
- <CardContent>{filteredChildren as ReactNode}</CardContent>
190
- {filteredCardActions as ReactNode}
191
- </>
192
- );
193
- }
194
-
195
- // Fallback
196
- return children as ReactNode;
87
+ return (
88
+ <>
89
+ <CardContent>{filteredNonActionChildren as ReactNode}</CardContent>
90
+ {cardActions}
91
+ </>
92
+ );
197
93
  };
198
94
 
199
95
  return (
@@ -298,7 +194,6 @@ const styles = StyleSheet.create(theme => ({
298
194
  },
299
195
  },
300
196
  },
301
-
302
197
  active: {
303
198
  true: {},
304
199
  },
@@ -0,0 +1,195 @@
1
+ import React from 'react';
2
+ import { GestureResponderEvent } from 'react-native';
3
+
4
+ const getInheritableHandler = (
5
+ child: React.ReactNode,
6
+ handlerToInherit: string
7
+ ): ((e: GestureResponderEvent) => void) | null => {
8
+ if (!React.isValidElement(child)) {
9
+ return null;
10
+ }
11
+
12
+ const childProps = child.props as any;
13
+ const isDisabled = !!childProps.disabled || !!childProps.loading;
14
+ if (isDisabled || typeof childProps[handlerToInherit] !== 'function') {
15
+ return null;
16
+ }
17
+
18
+ return childProps[handlerToInherit];
19
+ };
20
+
21
+ // Helper to check if children contain specific component types
22
+ export const checkForComponentType = (
23
+ children: React.ReactNode,
24
+ componentType: React.ComponentType<any>
25
+ ): boolean => {
26
+ return React.Children.toArray(children).some(child => {
27
+ if (React.isValidElement(child)) {
28
+ if (child.type === componentType) {
29
+ return true;
30
+ }
31
+ const childProps = child.props as any;
32
+ if (childProps.children) {
33
+ return checkForComponentType(childProps.children, componentType);
34
+ }
35
+ }
36
+ return false;
37
+ });
38
+ };
39
+
40
+ // Check if a component has "content" in its children (not just actions)
41
+ export const hasContentInChildren = (
42
+ child: React.ReactNode,
43
+ actionType: React.ComponentType<any>
44
+ ): boolean => {
45
+ if (!React.isValidElement(child)) {
46
+ return false;
47
+ }
48
+
49
+ const childProps = child.props as any;
50
+ if (!childProps?.children) {
51
+ return false;
52
+ }
53
+
54
+ // Check if children contain anything other than the action type
55
+ const childrenArray = React.Children.toArray(childProps.children);
56
+ return childrenArray.some(c => {
57
+ if (!React.isValidElement(c)) {
58
+ // Text, numbers, etc - this is content
59
+ return c != null;
60
+ }
61
+ return c.type !== actionType;
62
+ });
63
+ };
64
+
65
+ // Check if all children are CardActions groups
66
+ export const hasOnlyPotentialActions = (
67
+ children: React.ReactNode,
68
+ actionType: React.ComponentType<any>
69
+ ): boolean => {
70
+ const childArray = React.Children.toArray(children);
71
+ if (childArray.length === 0) {
72
+ return false;
73
+ }
74
+
75
+ let hasActionCandidate = false;
76
+
77
+ for (const child of childArray) {
78
+ if (!React.isValidElement(child)) {
79
+ if (child != null) {
80
+ return false;
81
+ }
82
+ continue;
83
+ }
84
+
85
+ if (child.type === actionType) {
86
+ hasActionCandidate = true;
87
+ continue;
88
+ }
89
+
90
+ if (checkForComponentType(child, actionType)) {
91
+ hasActionCandidate = true;
92
+ continue;
93
+ }
94
+
95
+ if (typeof child.type === 'string') {
96
+ return false;
97
+ }
98
+
99
+ if (hasContentInChildren(child, actionType)) {
100
+ return false;
101
+ }
102
+
103
+ return false;
104
+ }
105
+
106
+ return hasActionCandidate || checkForComponentType(children, actionType);
107
+ };
108
+
109
+ // Helper to filter out specific component types from children
110
+ export const filterChildren = (
111
+ children: React.ReactNode,
112
+ excludeComponentType: React.ComponentType<any>
113
+ ): React.ReactNode => {
114
+ return React.Children.map(children, child => {
115
+ if (React.isValidElement(child)) {
116
+ if (child.type === excludeComponentType) {
117
+ return null;
118
+ }
119
+
120
+ // Check if this child contains the excludeComponentType
121
+ if (checkForComponentType(child, excludeComponentType)) {
122
+ return null; // This child or its descendants contain the action
123
+ }
124
+
125
+ const childProps = child.props as any;
126
+ if (childProps.children) {
127
+ const filteredChildren = filterChildren(childProps.children, excludeComponentType);
128
+ // Only preserve wrapper if it has non-null children
129
+ const hasContent = React.Children.toArray(filteredChildren).some(c => c != null);
130
+ if (!hasContent) {
131
+ return null;
132
+ }
133
+ return React.cloneElement(child, {
134
+ ...childProps,
135
+ children: filteredChildren,
136
+ });
137
+ }
138
+ }
139
+ return child;
140
+ });
141
+ };
142
+
143
+ // Helper to extract only CardActions (preserving wrapper components)
144
+ export const extractCardActions = (
145
+ children: React.ReactNode,
146
+ actionType: React.ComponentType<any>
147
+ ): React.ReactNode => {
148
+ const recursiveExtract = (children: React.ReactNode): React.ReactNode => {
149
+ return React.Children.map(children, child => {
150
+ if (!React.isValidElement(child)) return null;
151
+
152
+ // Direct action
153
+ if (child.type === actionType) {
154
+ return child;
155
+ }
156
+
157
+ // If this child contains a CardActions wrapper in its tree, keep it
158
+ if (checkForComponentType(child, actionType) && !hasContentInChildren(child, actionType)) {
159
+ return child;
160
+ }
161
+
162
+ return null;
163
+ });
164
+ };
165
+
166
+ return recursiveExtract(children);
167
+ };
168
+
169
+ // Helper that recursively collects onPress or other defined handlers from descendants
170
+ export const collectChildActionHandlers = (
171
+ children: React.ReactNode
172
+ ): Array<(e: GestureResponderEvent) => void> =>
173
+ React.Children.toArray(children).reduce(
174
+ (handlers, child) => {
175
+ if (React.isValidElement(child)) {
176
+ const childProps = child.props as any;
177
+ // Check using displayName as CardPressHandler might not be directly importable
178
+ // @ts-expect-error - type
179
+ if (child.type?.displayName === 'CardPressHandler') {
180
+ const actionChildren = React.Children.toArray(childProps.children);
181
+ const handlerToInherit = childProps['handlerToInherit'] || 'onPress';
182
+ const firstChild = actionChildren[0];
183
+ const handler = getInheritableHandler(firstChild, handlerToInherit);
184
+ if (handler) {
185
+ handlers.push(handler);
186
+ }
187
+ }
188
+ if (childProps.children) {
189
+ handlers.push(...collectChildActionHandlers(childProps.children));
190
+ }
191
+ }
192
+ return handlers;
193
+ },
194
+ [] as Array<(e: GestureResponderEvent) => void>
195
+ );
@@ -1,5 +1,7 @@
1
1
  export { default as Card } from './Card';
2
2
  export { useCardContext } from './Card.context';
3
3
  export * from './CardAction';
4
+ export { default as CardActions } from './CardActions';
5
+ export { default as CardContent } from './CardContent';
4
6
  export { default as CardPressHandler } from './CardPressHandler';
5
7
  export { useCardPressHandlerContext } from './CardPressHandler.context';
@@ -26,6 +26,7 @@ The `DateInput` component allows users to enter dates manually using separate in
26
26
  - [Flexible Segments](#flexible-segments)
27
27
  - [Grouping Inputs](#grouping-inputs)
28
28
  - [With State](#with-state)
29
+ - [Overriding Styles](#overriding-styles)
29
30
  - [Accessibility](#accessibility)
30
31
 
31
32
  ## Playground
@@ -65,35 +66,38 @@ const MyComponent = () => {
65
66
 
66
67
  ### DateInputProps
67
68
 
68
- | Prop | Type | Default | Description |
69
- | ------------------ | ----------------------------------- | ----------- | ----------------------------------------------------- |
70
- | `label` | `string` | - | Label text displayed above the inputs |
71
- | `helperText` | `string` | - | Helper text displayed below the inputs |
72
- | `helperIcon` | `ComponentType` | - | Icon component to display with helper/validation text |
73
- | `validationStatus` | `'initial' \| 'valid' \| 'invalid'` | `'initial'` | Validation status of the input |
74
- | `validText` | `string` | - | Text to display when validation status is valid |
75
- | `invalidText` | `string` | - | Text to display when validation status is invalid |
76
- | `required` | `boolean` | `false` | Whether the input is required |
77
- | `disabled` | `boolean` | `false` | Whether the input is disabled |
78
- | `readonly` | `boolean` | `false` | Whether the input is read-only |
79
- | `hideDay` | `boolean` | `false` | Whether to hide the day segment |
80
- | `hideMonth` | `boolean` | `false` | Whether to hide the month segment |
81
- | `hideYear` | `boolean` | `false` | Whether to hide the year segment |
82
- | `dayPlaceholder` | `string` | `'DD'` | Placeholder text for the day segment |
83
- | `monthPlaceholder` | `string` | `'MM'` | Placeholder text for the month segment |
84
- | `yearPlaceholder` | `string` | `'YYYY'` | Placeholder text for the year segment |
85
- | `dayValue` | `string` | - | Controlled value for the day segment |
86
- | `monthValue` | `string` | - | Controlled value for the month segment |
87
- | `yearValue` | `string` | - | Controlled value for the year segment |
88
- | `onDayChange` | `(text: string) => void` | - | Callback fired when the day value changes |
89
- | `onMonthChange` | `(text: string) => void` | - | Callback fired when the month value changes |
90
- | `onYearChange` | `(text: string) => void` | - | Callback fired when the year value changes |
91
- | `onDayFocus` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the day segment receives focus |
92
- | `onMonthFocus` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the month segment receives focus |
93
- | `onYearFocus` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the year segment receives focus |
94
- | `onDayBlur` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the day segment loses focus |
95
- | `onMonthBlur` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the month segment loses focus |
96
- | `onYearBlur` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the year segment loses focus |
69
+ | Prop | Type | Default | Description |
70
+ | --------------------- | ----------------------------------- | ----------- | ----------------------------------------------------- |
71
+ | `label` | `string` | - | Label text displayed above the inputs |
72
+ | `helperText` | `string` | - | Helper text displayed below the inputs |
73
+ | `helperIcon` | `ComponentType` | - | Icon component to display with helper/validation text |
74
+ | `validationStatus` | `'initial' \| 'valid' \| 'invalid'` | `'initial'` | Validation status of the input |
75
+ | `validText` | `string` | - | Text to display when validation status is valid |
76
+ | `invalidText` | `string` | - | Text to display when validation status is invalid |
77
+ | `required` | `boolean` | `false` | Whether the input is required |
78
+ | `disabled` | `boolean` | `false` | Whether the input is disabled |
79
+ | `readonly` | `boolean` | `false` | Whether the input is read-only |
80
+ | `hideDay` | `boolean` | `false` | Whether to hide the day segment |
81
+ | `hideMonth` | `boolean` | `false` | Whether to hide the month segment |
82
+ | `hideYear` | `boolean` | `false` | Whether to hide the year segment |
83
+ | `dayPlaceholder` | `string` | `'DD'` | Placeholder text for the day segment |
84
+ | `monthPlaceholder` | `string` | `'MM'` | Placeholder text for the month segment |
85
+ | `yearPlaceholder` | `string` | `'YYYY'` | Placeholder text for the year segment |
86
+ | `dayValue` | `string` | - | Controlled value for the day segment |
87
+ | `monthValue` | `string` | - | Controlled value for the month segment |
88
+ | `yearValue` | `string` | - | Controlled value for the year segment |
89
+ | `onDayChange` | `(text: string) => void` | - | Callback fired when the day value changes |
90
+ | `onMonthChange` | `(text: string) => void` | - | Callback fired when the month value changes |
91
+ | `onYearChange` | `(text: string) => void` | - | Callback fired when the year value changes |
92
+ | `onDayFocus` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the day segment receives focus |
93
+ | `onMonthFocus` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the month segment receives focus |
94
+ | `onYearFocus` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the year segment receives focus |
95
+ | `onDayBlur` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the day segment loses focus |
96
+ | `onMonthBlur` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the month segment loses focus |
97
+ | `onYearBlur` | `(e: NativeSyntheticEvent) => void` | - | Callback fired when the year segment loses focus |
98
+ | `inputContainerStyle` | `ViewStyle` | - | Custom style for each input container |
99
+ | `inputStyle` | `ViewStyle` | - | Custom style for each input field |
100
+ | `inputLabelStyle` | `TextStyle` | - | Custom style for each input label |
97
101
 
98
102
  ## Examples
99
103
 
@@ -155,6 +159,20 @@ Programmatically control date values:
155
159
 
156
160
  <Canvas of={Stories.WithState} />
157
161
 
162
+ ### Overriding Styles
163
+
164
+ You can override the styles of the input containers, input fields, and input labels using the `inputContainerStyle`, `inputStyle`, and `inputLabelStyle` props respectively:
165
+
166
+ <Canvas of={Stories.CustomWidth} />
167
+
168
+ ```tsx
169
+ <DateInput
170
+ label="Custom width date input"
171
+ helperText="Date input with custom width"
172
+ inputContainerStyle={{ maxWidth: 'auto' }}
173
+ />
174
+ ```
175
+
158
176
  ## Accessibility
159
177
 
160
178
  - Each segment has a descriptive label ("Day", "Month", "Year") for screen readers
@@ -1,5 +1,6 @@
1
- import type { TextInputProps } from 'react-native';
1
+ import type { TextInputProps, ViewProps } from 'react-native';
2
2
  import type { FormFieldBaseProps } from '../FormField/FormField.props';
3
+ import LabelProps from '../Label/Label.props';
3
4
 
4
5
  export interface DateInputProps extends FormFieldBaseProps {
5
6
  /**
@@ -77,4 +78,34 @@ export interface DateInputProps extends FormFieldBaseProps {
77
78
  * Callback fired when the year segment loses focus.
78
79
  */
79
80
  onYearBlur?: TextInputProps['onBlur'];
81
+ /*
82
+ * Style for all the input segment's container.
83
+ */
84
+ inputContainerStyle?: ViewProps['style'];
85
+ /*
86
+ * Style for all the input segment's TextInput.
87
+ */
88
+ inputStyle?: ViewProps['style'];
89
+ /*
90
+ * Style for all the input segment's label.
91
+ */
92
+ inputLabelStyle?: LabelProps['style'];
93
+ }
94
+
95
+ export interface DateInputSegmentProps {
96
+ label: string;
97
+ placeholder?: string;
98
+ value?: string;
99
+ onChange?: (text: string) => void;
100
+ onFocus?: DateInputProps['onDayFocus'];
101
+ onBlur?: DateInputProps['onDayBlur'];
102
+ disabled?: boolean;
103
+ required?: boolean;
104
+ validationStatus?: DateInputProps['validationStatus'];
105
+ maxLength?: number;
106
+ readonly?: boolean;
107
+ testID?: string;
108
+ inputContainerStyle?: ViewProps['style'];
109
+ inputStyle?: ViewProps['style'];
110
+ inputLabelStyle?: LabelProps['style'];
80
111
  }
@@ -267,3 +267,13 @@ export const WithState: Story = {
267
267
  );
268
268
  },
269
269
  };
270
+
271
+ export const CustomWidth: Story = {
272
+ render: () => (
273
+ <DateInput
274
+ label="Custom width date input"
275
+ helperText="Date input with custom width"
276
+ inputContainerStyle={{ maxWidth: 'auto' }}
277
+ />
278
+ ),
279
+ };
@@ -32,6 +32,9 @@ const DateInput = ({
32
32
  onDayBlur,
33
33
  onMonthBlur,
34
34
  onYearBlur,
35
+ inputLabelStyle,
36
+ inputContainerStyle,
37
+ inputStyle,
35
38
  ...props
36
39
  }: DateInputProps) => {
37
40
  return (
@@ -63,6 +66,9 @@ const DateInput = ({
63
66
  validationStatus={validationStatus}
64
67
  maxLength={2}
65
68
  testID="date-input-day"
69
+ inputContainerStyle={inputContainerStyle}
70
+ inputStyle={inputStyle}
71
+ inputLabelStyle={inputLabelStyle}
66
72
  />
67
73
  )}
68
74
  {!hideMonth && (
@@ -79,6 +85,9 @@ const DateInput = ({
79
85
  validationStatus={validationStatus}
80
86
  maxLength={2}
81
87
  testID="date-input-month"
88
+ inputContainerStyle={inputContainerStyle}
89
+ inputStyle={inputStyle}
90
+ inputLabelStyle={inputLabelStyle}
82
91
  />
83
92
  )}
84
93
  {!hideYear && (
@@ -95,6 +104,9 @@ const DateInput = ({
95
104
  validationStatus={validationStatus}
96
105
  maxLength={4}
97
106
  testID="date-input-year"
107
+ inputContainerStyle={inputContainerStyle}
108
+ inputStyle={inputStyle}
109
+ inputLabelStyle={inputLabelStyle}
98
110
  />
99
111
  )}
100
112
  </View>
@@ -111,7 +123,6 @@ const styles = StyleSheet.create(theme => ({
111
123
  container: {
112
124
  flexDirection: 'row',
113
125
  gap: theme.components.input.date.gap,
114
- // alignItems: 'stretch',
115
126
  },
116
127
  }));
117
128
 
@@ -2,22 +2,7 @@ import { View } from 'react-native';
2
2
  import { StyleSheet } from 'react-native-unistyles';
3
3
  import { BodyText } from '../BodyText';
4
4
  import { Input } from '../Input';
5
- import type { DateInputProps } from './DateInput.props';
6
-
7
- interface DateInputSegmentProps {
8
- label: string;
9
- placeholder?: string;
10
- value?: string;
11
- onChange?: (text: string) => void;
12
- onFocus?: DateInputProps['onDayFocus'];
13
- onBlur?: DateInputProps['onDayBlur'];
14
- disabled?: boolean;
15
- required?: boolean;
16
- validationStatus?: DateInputProps['validationStatus'];
17
- maxLength?: number;
18
- readonly?: boolean;
19
- testID?: string;
20
- }
5
+ import type { DateInputSegmentProps } from './DateInput.props';
21
6
 
22
7
  const DateInputSegment = ({
23
8
  label,
@@ -31,11 +16,14 @@ const DateInputSegment = ({
31
16
  maxLength,
32
17
  readonly,
33
18
  testID,
19
+ inputContainerStyle,
20
+ inputStyle,
21
+ inputLabelStyle,
34
22
  }: DateInputSegmentProps) => {
35
23
  styles.useVariants({ disabled });
36
24
  return (
37
- <View style={styles.container}>
38
- <BodyText size="md" style={styles.label}>
25
+ <View style={[styles.container, inputContainerStyle]}>
26
+ <BodyText size="md" style={[styles.label, inputLabelStyle]}>
39
27
  {label}
40
28
  </BodyText>
41
29
  <Input
@@ -51,7 +39,7 @@ const DateInputSegment = ({
51
39
  disabled={disabled}
52
40
  validationStatus={validationStatus}
53
41
  readonly={readonly}
54
- style={styles.input}
42
+ style={inputStyle}
55
43
  />
56
44
  </View>
57
45
  );
@@ -63,7 +51,7 @@ const styles = StyleSheet.create(theme => ({
63
51
  container: {
64
52
  flex: 1,
65
53
  gap: theme.components.input.gap,
66
- // maxWidth: 96,
54
+ maxWidth: 96,
67
55
  },
68
56
  label: {
69
57
  variants: {
@@ -74,9 +62,6 @@ const styles = StyleSheet.create(theme => ({
74
62
  },
75
63
  },
76
64
  },
77
- input: {
78
- // maxWidth: 96,
79
- },
80
65
  }));
81
66
 
82
67
  export default DateInputSegment;