@utilitywarehouse/hearth-react-native 0.25.0 → 0.27.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 (42) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-lint.log +15 -15
  3. package/CHANGELOG.md +71 -0
  4. package/build/components/Banner/Banner.js +12 -1
  5. package/build/components/Modal/Modal.d.ts +1 -1
  6. package/build/components/Modal/Modal.js +30 -7
  7. package/build/components/Modal/Modal.props.d.ts +4 -2
  8. package/build/components/PillGroup/Pill.js +0 -1
  9. package/build/components/PillGroup/PillGroup.js +4 -1
  10. package/build/components/SegmentedControl/SegmentedControl.context.d.ts +14 -0
  11. package/build/components/SegmentedControl/SegmentedControl.context.js +9 -0
  12. package/build/components/SegmentedControl/SegmentedControl.d.ts +6 -0
  13. package/build/components/SegmentedControl/SegmentedControl.js +196 -0
  14. package/build/components/SegmentedControl/SegmentedControl.props.d.ts +18 -0
  15. package/build/components/SegmentedControl/SegmentedControl.props.js +1 -0
  16. package/build/components/SegmentedControl/SegmentedControlOption.d.ts +18 -0
  17. package/build/components/SegmentedControl/SegmentedControlOption.js +122 -0
  18. package/build/components/SegmentedControl/SegmentedControlOption.props.d.ts +12 -0
  19. package/build/components/SegmentedControl/SegmentedControlOption.props.js +1 -0
  20. package/build/components/SegmentedControl/index.d.ts +4 -0
  21. package/build/components/SegmentedControl/index.js +2 -0
  22. package/build/components/index.d.ts +1 -0
  23. package/build/components/index.js +1 -0
  24. package/docs/changelog.mdx +136 -0
  25. package/docs/components/AllComponents.web.tsx +14 -0
  26. package/package.json +3 -3
  27. package/src/components/Banner/Banner.tsx +12 -1
  28. package/src/components/Modal/Modal.docs.mdx +9 -3
  29. package/src/components/Modal/Modal.props.ts +4 -2
  30. package/src/components/Modal/Modal.tsx +44 -7
  31. package/src/components/PillGroup/Pill.tsx +0 -1
  32. package/src/components/PillGroup/PillGroup.tsx +4 -0
  33. package/src/components/SegmentedControl/SegmentedControl.context.ts +22 -0
  34. package/src/components/SegmentedControl/SegmentedControl.docs.mdx +90 -0
  35. package/src/components/SegmentedControl/SegmentedControl.figma.tsx +40 -0
  36. package/src/components/SegmentedControl/SegmentedControl.props.ts +20 -0
  37. package/src/components/SegmentedControl/SegmentedControl.stories.tsx +77 -0
  38. package/src/components/SegmentedControl/SegmentedControl.tsx +257 -0
  39. package/src/components/SegmentedControl/SegmentedControlOption.props.ts +14 -0
  40. package/src/components/SegmentedControl/SegmentedControlOption.tsx +213 -0
  41. package/src/components/SegmentedControl/index.ts +4 -0
  42. package/src/components/index.ts +1 -0
@@ -0,0 +1,213 @@
1
+ import { createPressable } from '@gluestack-ui/pressable';
2
+ import { useEffect } from 'react';
3
+ import { Platform, Pressable, View } from 'react-native';
4
+ import Animated, {
5
+ Easing,
6
+ useAnimatedStyle,
7
+ useReducedMotion,
8
+ useSharedValue,
9
+ withTiming,
10
+ } from 'react-native-reanimated';
11
+ import { StyleSheet } from 'react-native-unistyles';
12
+ import { BodyText } from '../BodyText';
13
+ import { useSegmentedControlContext } from './SegmentedControl.context';
14
+ import type SegmentedControlOptionProps from './SegmentedControlOption.props';
15
+
16
+ const AnimatedView = Animated.createAnimatedComponent(View);
17
+
18
+ const SegmentedControlOptionRoot = ({
19
+ value,
20
+ children,
21
+ accessibilityLabel,
22
+ disabled = false,
23
+ style,
24
+ states = {},
25
+ ...props
26
+ }: SegmentedControlOptionProps & { states?: { active?: boolean; disabled?: boolean } }) => {
27
+ const {
28
+ value: selectedValue,
29
+ select,
30
+ disabled: allDisabled,
31
+ size,
32
+ registerOptionLayout,
33
+ } = useSegmentedControlContext();
34
+ const { active = false } = states;
35
+ const reducedMotion = useReducedMotion();
36
+
37
+ const selected = selectedValue === value;
38
+ const isDisabled = disabled || !!allDisabled;
39
+
40
+ const selectedProgress = useSharedValue(selected ? 1 : 0);
41
+
42
+ useEffect(() => {
43
+ selectedProgress.value = withTiming(selected ? 1 : 0, {
44
+ duration: reducedMotion ? 0 : 220,
45
+ easing: Easing.out(Easing.cubic),
46
+ });
47
+ }, [reducedMotion, selected, selectedProgress]);
48
+
49
+ const regularLabelStyle = useAnimatedStyle(() => ({
50
+ opacity: 1 - selectedProgress.value,
51
+ }));
52
+
53
+ const selectedLabelStyle = useAnimatedStyle(() => ({
54
+ opacity: selectedProgress.value,
55
+ }));
56
+
57
+ styles.useVariants({ selected, disabled: isDisabled, size, active });
58
+
59
+ const onPress = () => {
60
+ if (isDisabled) return;
61
+ select(value);
62
+ };
63
+
64
+ const accessibleLabel =
65
+ typeof children === 'string' || typeof children === 'number' ? String(children) : value;
66
+
67
+ return (
68
+ <Pressable
69
+ {...props}
70
+ accessibilityRole="radio"
71
+ accessibilityState={{ checked: selected, disabled: isDisabled }}
72
+ accessibilityLabel={accessibilityLabel ?? accessibleLabel}
73
+ onPress={onPress}
74
+ onLayout={e => registerOptionLayout(value, e.nativeEvent.layout)}
75
+ disabled={isDisabled}
76
+ style={[styles.option, style]}
77
+ {...(Platform.OS === 'web'
78
+ ? ({ 'aria-label': accessibilityLabel ?? accessibleLabel } as any)
79
+ : null)}
80
+ >
81
+ <View
82
+ style={styles.labelWrap}
83
+ accessible={false}
84
+ accessibilityElementsHidden
85
+ importantForAccessibility="no-hide-descendants"
86
+ {...(Platform.OS === 'web' ? ({ 'aria-hidden': true } as any) : null)}
87
+ >
88
+ <BodyText
89
+ size="md"
90
+ weight="semibold"
91
+ style={styles.labelSizer}
92
+ accessible={false}
93
+ accessibilityElementsHidden
94
+ importantForAccessibility="no-hide-descendants"
95
+ {...(Platform.OS === 'web' ? ({ 'aria-hidden': true } as any) : null)}
96
+ >
97
+ {children}
98
+ </BodyText>
99
+ <AnimatedView
100
+ pointerEvents="none"
101
+ style={[styles.textLayer, regularLabelStyle]}
102
+ accessible={false}
103
+ accessibilityElementsHidden
104
+ importantForAccessibility="no-hide-descendants"
105
+ {...(Platform.OS === 'web' ? ({ 'aria-hidden': true } as any) : null)}
106
+ >
107
+ <BodyText size="md" weight="regular" style={styles.textRegular}>
108
+ {children}
109
+ </BodyText>
110
+ </AnimatedView>
111
+ <AnimatedView
112
+ pointerEvents="none"
113
+ style={[styles.textLayer, selectedLabelStyle]}
114
+ accessible={false}
115
+ accessibilityElementsHidden
116
+ importantForAccessibility="no-hide-descendants"
117
+ {...(Platform.OS === 'web' ? ({ 'aria-hidden': true } as any) : null)}
118
+ >
119
+ <BodyText size="md" weight="semibold" style={styles.textSelected}>
120
+ {children}
121
+ </BodyText>
122
+ </AnimatedView>
123
+ </View>
124
+ </Pressable>
125
+ );
126
+ };
127
+
128
+ const SegmentedControlOption = createPressable({ Root: SegmentedControlOptionRoot });
129
+
130
+ SegmentedControlOption.displayName = 'SegmentedControlOption';
131
+
132
+ const styles = StyleSheet.create(theme => ({
133
+ option: {
134
+ minWidth: theme.components.segmentedControl.minWidth,
135
+ height: theme.components.segmentedControl.height,
136
+ borderRadius: theme.components.segmentedControl.borderRadius,
137
+ paddingHorizontal: theme.components.segmentedControl.paddingHorizontal,
138
+ paddingVertical: theme.components.segmentedControl.paddingVertical,
139
+ justifyContent: 'center',
140
+ alignItems: 'center',
141
+ backgroundColor: 'transparent',
142
+ zIndex: 1,
143
+ variants: {
144
+ size: {
145
+ sm: {
146
+ height: 28,
147
+ paddingHorizontal: theme.space[150],
148
+ paddingVertical: 0,
149
+ },
150
+ md: {
151
+ height: 44,
152
+ paddingHorizontal: theme.components.segmentedControl.paddingHorizontal,
153
+ paddingVertical: theme.components.segmentedControl.paddingVertical,
154
+ },
155
+ },
156
+ selected: {
157
+ true: {
158
+ backgroundColor: 'transparent',
159
+ _web: {
160
+ _active: {
161
+ backgroundColor: theme.color.interactive.brand.surface.strong.active,
162
+ },
163
+ },
164
+ },
165
+ false: {
166
+ _web: {
167
+ _hover: {
168
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.hover,
169
+ },
170
+ _active: {
171
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.active,
172
+ },
173
+ },
174
+ },
175
+ },
176
+ active: {
177
+ true: {
178
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.active,
179
+ },
180
+ },
181
+ },
182
+ },
183
+ labelWrap: {
184
+ position: 'relative',
185
+ alignItems: 'center',
186
+ justifyContent: 'center',
187
+ },
188
+ labelSizer: {
189
+ opacity: 0,
190
+ },
191
+ textLayer: {
192
+ position: 'absolute',
193
+ left: 0,
194
+ right: 0,
195
+ alignItems: 'center',
196
+ justifyContent: 'center',
197
+ },
198
+ textRegular: {
199
+ color: theme.color.text.primary,
200
+ },
201
+ textSelected: {
202
+ color: theme.color.text.inverted,
203
+ variants: {
204
+ disabled: {
205
+ true: {
206
+ opacity: 1,
207
+ },
208
+ },
209
+ },
210
+ },
211
+ }));
212
+
213
+ export default SegmentedControlOption;
@@ -0,0 +1,4 @@
1
+ export { default as SegmentedControl } from './SegmentedControl';
2
+ export type { SegmentedControlProps } from './SegmentedControl.props';
3
+ export { default as SegmentedControlOption } from './SegmentedControlOption';
4
+ export type { SegmentedControlOptionProps } from './SegmentedControlOption.props';
@@ -46,6 +46,7 @@ export * from './ProgressStepper';
46
46
  export * from './Radio';
47
47
  export * from './RadioCard';
48
48
  export * from './SectionHeader';
49
+ export * from './SegmentedControl';
49
50
  export * from './Select';
50
51
  export * from './Skeleton';
51
52
  export * from './Spinner';