@utilitywarehouse/hearth-react-native 0.26.0 → 0.27.1

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 (39) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-lint.log +11 -11
  3. package/CHANGELOG.md +82 -0
  4. package/build/components/Banner/Banner.js +12 -1
  5. package/build/components/Modal/Modal.js +1 -1
  6. package/build/components/PillGroup/Pill.js +0 -1
  7. package/build/components/PillGroup/PillGroup.js +4 -1
  8. package/build/components/SegmentedControl/SegmentedControl.context.d.ts +14 -0
  9. package/build/components/SegmentedControl/SegmentedControl.context.js +9 -0
  10. package/build/components/SegmentedControl/SegmentedControl.d.ts +6 -0
  11. package/build/components/SegmentedControl/SegmentedControl.js +196 -0
  12. package/build/components/SegmentedControl/SegmentedControl.props.d.ts +18 -0
  13. package/build/components/SegmentedControl/SegmentedControl.props.js +1 -0
  14. package/build/components/SegmentedControl/SegmentedControlOption.d.ts +18 -0
  15. package/build/components/SegmentedControl/SegmentedControlOption.js +141 -0
  16. package/build/components/SegmentedControl/SegmentedControlOption.props.d.ts +14 -0
  17. package/build/components/SegmentedControl/SegmentedControlOption.props.js +1 -0
  18. package/build/components/SegmentedControl/index.d.ts +4 -0
  19. package/build/components/SegmentedControl/index.js +2 -0
  20. package/build/components/index.d.ts +1 -0
  21. package/build/components/index.js +1 -0
  22. package/docs/changelog.mdx +136 -0
  23. package/docs/components/AllComponents.web.tsx +14 -0
  24. package/package.json +4 -4
  25. package/src/components/Banner/Banner.tsx +12 -1
  26. package/src/components/Modal/Modal.tsx +1 -1
  27. package/src/components/PillGroup/Pill.tsx +0 -1
  28. package/src/components/PillGroup/PillGroup.tsx +4 -0
  29. package/src/components/SegmentedControl/SegmentedControl.context.ts +22 -0
  30. package/src/components/SegmentedControl/SegmentedControl.docs.mdx +117 -0
  31. package/src/components/SegmentedControl/SegmentedControl.figma.tsx +39 -0
  32. package/src/components/SegmentedControl/SegmentedControl.props.ts +20 -0
  33. package/src/components/SegmentedControl/SegmentedControl.stories.tsx +98 -0
  34. package/src/components/SegmentedControl/SegmentedControl.tsx +257 -0
  35. package/src/components/SegmentedControl/SegmentedControlOption.props.ts +16 -0
  36. package/src/components/SegmentedControl/SegmentedControlOption.tsx +236 -0
  37. package/src/components/SegmentedControl/index.ts +4 -0
  38. package/src/components/Select/SelectOption.figma.tsx +2 -2
  39. package/src/components/index.ts +1 -0
@@ -1,4 +1,4 @@
1
1
 
2
- > @utilitywarehouse/hearth-react-native@0.26.0 build /home/runner/work/hearth/hearth/packages/react-native
2
+ > @utilitywarehouse/hearth-react-native@0.27.1 build /home/runner/work/hearth/hearth/packages/react-native
3
3
  > tsc
4
4
 
@@ -1,5 +1,5 @@
1
1
 
2
- > @utilitywarehouse/hearth-react-native@0.26.0 lint /home/runner/work/hearth/hearth/packages/react-native
2
+ > @utilitywarehouse/hearth-react-native@0.27.1 lint /home/runner/work/hearth/hearth/packages/react-native
3
3
  > TIMING=1 eslint .
4
4
 
5
5
 
@@ -60,13 +60,13 @@
60
60
 
61
61
  Rule | Time (ms) | Relative
62
62
  :-----------------------------------------|----------:|--------:
63
- @typescript-eslint/no-unused-vars | 1316.387 | 59.6%
64
- react-hooks/exhaustive-deps | 96.698 | 4.4%
65
- no-global-assign | 93.436 | 4.2%
66
- react-hooks/rules-of-hooks | 81.760 | 3.7%
67
- no-unexpected-multiline | 47.972 | 2.2%
68
- no-misleading-character-class | 43.286 | 2.0%
69
- @typescript-eslint/triple-slash-reference | 33.417 | 1.5%
70
- @typescript-eslint/ban-ts-comment | 32.258 | 1.5%
71
- no-regex-spaces | 29.418 | 1.3%
72
- no-loss-of-precision | 25.945 | 1.2%
63
+ @typescript-eslint/no-unused-vars | 1499.293 | 61.6%
64
+ react-hooks/exhaustive-deps | 127.430 | 5.2%
65
+ react-hooks/rules-of-hooks | 84.158 | 3.5%
66
+ no-global-assign | 65.981 | 2.7%
67
+ no-unexpected-multiline | 44.926 | 1.8%
68
+ @typescript-eslint/ban-ts-comment | 39.212 | 1.6%
69
+ @typescript-eslint/triple-slash-reference | 36.913 | 1.5%
70
+ no-misleading-character-class | 36.268 | 1.5%
71
+ no-useless-escape | 28.431 | 1.2%
72
+ @typescript-eslint/no-unused-expressions | 25.564 | 1.1%
package/CHANGELOG.md CHANGED
@@ -1,5 +1,87 @@
1
1
  # @utilitywarehouse/hearth-react-native
2
2
 
3
+ ## 0.27.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#990](https://github.com/utilitywarehouse/hearth/pull/990) [`958e0e1`](https://github.com/utilitywarehouse/hearth/commit/958e0e1a9d5451d1e11fecadc69ae3c5ad9d42ca) Thanks [@declanelcocks](https://github.com/declanelcocks)! - 🐛 [FIX]: Fix `Modal` layout when `inNavModal` and `stickyFooter={false}`.
8
+
9
+ Corrects the container flex style for `inNavModal` modals with a non-sticky footer, where the UX was not great when scrolling.
10
+
11
+ **Components affected**:
12
+ - `Modal`
13
+
14
+ **Developer changes**:
15
+
16
+ No changes required.
17
+
18
+ - [#992](https://github.com/utilitywarehouse/hearth/pull/992) [`2560b3d`](https://github.com/utilitywarehouse/hearth/commit/2560b3dcba7ed4981fad585628f96afd07d8de4f) Thanks [@jordmccord](https://github.com/jordmccord)! - 💅 [ENHANCEMENT]: Add optional leading `icon` support to `SegmentedControlOption`.
19
+
20
+ This adds an optional `icon` prop to `SegmentedControlOption`, allowing icons to be displayed before option labels in segmented controls.
21
+
22
+ Docs and stories were updated to include icon usage examples.
23
+
24
+ **Components affected**:
25
+ - `SegmentedControlOption`
26
+
27
+ **Developer changes**:
28
+
29
+ No changes required for existing usage.
30
+
31
+ To use the new optional icon prop:
32
+
33
+ ```tsx
34
+ import { SegmentedControl, SegmentedControlOption } from '@utilitywarehouse/hearth-react-native';
35
+ import { ElectricitySmallIcon } from '@utilitywarehouse/hearth-react-native-icons';
36
+
37
+ <SegmentedControl defaultValue="energy">
38
+ <SegmentedControlOption value="energy" icon={ElectricitySmallIcon}>
39
+ Energy
40
+ </SegmentedControlOption>
41
+ <SegmentedControlOption value="broadband">Broadband</SegmentedControlOption>
42
+ </SegmentedControl>;
43
+ ```
44
+
45
+ ## 0.27.0
46
+
47
+ ### Minor Changes
48
+
49
+ - [#987](https://github.com/utilitywarehouse/hearth/pull/987) [`eb962d2`](https://github.com/utilitywarehouse/hearth/commit/eb962d2f33b63fa3aeda0b291fd41ace90d04c41) Thanks [@jordmccord](https://github.com/jordmccord)! - 🌟 [FEATURE]: Add `SegmentedControl` and `SegmentedControlOption` components.
50
+
51
+ This introduces a new segmented control component for switching between a small set of related options.
52
+ The component includes controlled and uncontrolled usage, size variants (`sm`, `md`), animated selected indicator movement, and improved accessibility semantics for screen readers.
53
+
54
+ **Components affected**:
55
+ - `SegmentedControl`
56
+ - `SegmentedControlOption`
57
+
58
+ **Developer changes**:
59
+
60
+ Import and compose the new components as follows:
61
+
62
+ ```tsx
63
+ import { SegmentedControl, SegmentedControlOption } from '@utilitywarehouse/hearth-react-native';
64
+
65
+ <SegmentedControl defaultValue="day" size="sm">
66
+ <SegmentedControlOption value="day">Day</SegmentedControlOption>
67
+ <SegmentedControlOption value="week">Week</SegmentedControlOption>
68
+ <SegmentedControlOption value="month">Month</SegmentedControlOption>
69
+ </SegmentedControl>;
70
+ ```
71
+
72
+ ### Patch Changes
73
+
74
+ - [#989](https://github.com/utilitywarehouse/hearth/pull/989) [`c97122e`](https://github.com/utilitywarehouse/hearth/commit/c97122eb429ec4adef656fb245a9256a5619df61) Thanks [@jordmccord](https://github.com/jordmccord)! - 🐛 [FIX]: Ensure horizontal `Banner` fills available width when `onPress` is not provided.
75
+
76
+ Fixed a layout issue where a horizontal `Banner` without `onPress` could fail to stretch correctly within its parent container.
77
+
78
+ **Components affected**:
79
+ - `Banner`
80
+
81
+ **Developer changes**:
82
+
83
+ No changes required.
84
+
3
85
  ## 0.26.0
4
86
 
5
87
  ### Minor Changes
@@ -11,7 +11,7 @@ import { UnstyledIconButton } from '../UnstyledIconButton';
11
11
  import BannerContext from './Banner.context';
12
12
  const Banner = ({ icon, iconContainerVariant = 'subtle', iconContainerSize = 'md', iconContainerColor = 'pig', illustration, image, heading, description, direction = 'horizontal', link, button, onPress, onClose, variant = 'subtle', style, ...props }) => {
13
13
  const hasIllustration = Boolean(illustration);
14
- styles.useVariants({ direction, hasIllustration });
14
+ styles.useVariants({ direction, hasIllustration, isPressable: Boolean(onPress) });
15
15
  const context = useMemo(() => ({
16
16
  direction,
17
17
  }), [direction]);
@@ -66,6 +66,10 @@ const styles = StyleSheet.create(theme => ({
66
66
  true: {},
67
67
  false: {},
68
68
  },
69
+ isPressable: {
70
+ true: {},
71
+ false: {},
72
+ },
69
73
  },
70
74
  compoundVariants: [
71
75
  {
@@ -82,6 +86,13 @@ const styles = StyleSheet.create(theme => ({
82
86
  alignItems: 'center',
83
87
  },
84
88
  },
89
+ {
90
+ direction: 'horizontal',
91
+ isPressable: false,
92
+ styles: {
93
+ flex: 1,
94
+ },
95
+ },
85
96
  ],
86
97
  },
87
98
  media: {
@@ -120,7 +120,7 @@ const Modal = ({ ref, children, heading, description, showCloseButton = true, pr
120
120
  });
121
121
  const footer = (_jsxs(View, { style: styles.footer, children: [onPressPrimaryButton && primaryButtonText ? (_jsx(Button, { onPress: handlePrimaryButtonPress, text: primaryButtonText, inverted: isBrandBackground && inNavModal, ...primaryButtonProps, variant: primaryButtonProps?.variant ?? 'solid', colorScheme: primaryButtonProps?.colorScheme ?? 'highlight' })) : null, onPressSecondaryButton && secondaryButtonText ? (_jsx(Button, { onPress: handleSecondaryButtonPress, text: secondaryButtonText, inverted: isBrandBackground && inNavModal, ...secondaryButtonProps, variant: secondaryButtonProps?.variant ?? 'outline', colorScheme: secondaryButtonProps?.colorScheme ?? 'functional' })) : null] }));
122
122
  const InNavModalContainer = scrollable ? ScrollView : View;
123
- const content = (_jsx(_Fragment, { children: loading ? (_jsxs(View, { style: styles.loadingContainer, accessible: Platform.OS === 'android' ? true : undefined, accessibilityLabel: Platform.OS === 'android' ? 'Loading' : undefined, screenReaderFocusable: true, ref: viewRef, children: [_jsx(Spinner, { size: "lg", color: isBrandBackground && inNavModal ? theme.color.icon.inverted : undefined }), _jsx(Heading, { size: "lg", textAlign: "center", inverted: isBrandBackground && inNavModal, children: loadingHeading })] })) : (_jsxs(View, { style: styles.container, accessible: Platform.OS === 'android' ? true : undefined, accessibilityLabel: Platform.OS === 'android' ? 'Modal content' : undefined, screenReaderFocusable: true, ref: viewRef, children: [_jsxs(View, { style: styles.header, children: [_jsxs(View, { style: styles.headerTextContent, children: [heading && !image ? (_jsx(Heading, { size: "lg", accessible: true, inverted: isBrandBackground && inNavModal, children: heading })) : null, description && !image ? (_jsx(BodyText, { accessible: true, inverted: isBrandBackground && inNavModal, children: description })) : null] }), showCloseButton ? (_jsx(UnstyledIconButton, { icon: CloseMediumIcon, onPress: handleCloseButtonPress, accessibilityLabel: "Close modal", inverted: isBrandBackground && inNavModal, ...closeButtonProps })) : null] }), image ? (_jsxs(View, { style: styles.imageContainer, children: [image, _jsxs(View, { style: styles.textContent, children: [heading ? (_jsx(Heading, { size: "lg", textAlign: "center", accessible: true, inverted: isBrandBackground && inNavModal, children: heading })) : null, description ? (_jsx(BodyText, { textAlign: "center", accessible: true, inverted: isBrandBackground && inNavModal, children: description })) : null] })] })) : null, inNavModal && (_jsxs(InNavModalContainer, { style: { flexGrow: stickyFooter ? 1 : 0 }, children: [children, !stickyFooter ? _jsx(View, { style: styles.inNavModalFooterContainer, children: footer }) : null] })), !inNavModal && children, ((!stickyFooter && !inNavModal) || (inNavModal && stickyFooter)) && !noButtons ? footer : null] })) }));
123
+ const content = (_jsx(_Fragment, { children: loading ? (_jsxs(View, { style: styles.loadingContainer, accessible: Platform.OS === 'android' ? true : undefined, accessibilityLabel: Platform.OS === 'android' ? 'Loading' : undefined, screenReaderFocusable: true, ref: viewRef, children: [_jsx(Spinner, { size: "lg", color: isBrandBackground && inNavModal ? theme.color.icon.inverted : undefined }), _jsx(Heading, { size: "lg", textAlign: "center", inverted: isBrandBackground && inNavModal, children: loadingHeading })] })) : (_jsxs(View, { style: styles.container, accessible: Platform.OS === 'android' ? true : undefined, accessibilityLabel: Platform.OS === 'android' ? 'Modal content' : undefined, screenReaderFocusable: true, ref: viewRef, children: [_jsxs(View, { style: styles.header, children: [_jsxs(View, { style: styles.headerTextContent, children: [heading && !image ? (_jsx(Heading, { size: "lg", accessible: true, inverted: isBrandBackground && inNavModal, children: heading })) : null, description && !image ? (_jsx(BodyText, { accessible: true, inverted: isBrandBackground && inNavModal, children: description })) : null] }), showCloseButton ? (_jsx(UnstyledIconButton, { icon: CloseMediumIcon, onPress: handleCloseButtonPress, accessibilityLabel: "Close modal", inverted: isBrandBackground && inNavModal, ...closeButtonProps })) : null] }), image ? (_jsxs(View, { style: styles.imageContainer, children: [image, _jsxs(View, { style: styles.textContent, children: [heading ? (_jsx(Heading, { size: "lg", textAlign: "center", accessible: true, inverted: isBrandBackground && inNavModal, children: heading })) : null, description ? (_jsx(BodyText, { textAlign: "center", accessible: true, inverted: isBrandBackground && inNavModal, children: description })) : null] })] })) : null, inNavModal && (_jsxs(InNavModalContainer, { style: { flex: stickyFooter ? 1 : 0 }, children: [children, !stickyFooter ? _jsx(View, { style: styles.inNavModalFooterContainer, children: footer }) : null] })), !inNavModal && children, ((!stickyFooter && !inNavModal) || (inNavModal && stickyFooter)) && !noButtons ? footer : null] })) }));
124
124
  const renderFooter = useCallback((props) => (_jsx(BottomSheetFooter, { ...props, children: _jsx(View, { style: styles.footerWrap, children: footer }) })), [
125
125
  onPressPrimaryButton,
126
126
  primaryButtonText,
@@ -35,7 +35,6 @@ const styles = StyleSheet.create(theme => ({
35
35
  _hover: {
36
36
  backgroundColor: theme.color.interactive.neutral.surface.subtle.hover,
37
37
  },
38
- // '_focus-visible': theme.helpers.focusVisible,
39
38
  },
40
39
  variants: {
41
40
  active: {
@@ -20,10 +20,13 @@ export const PillGroup = ({ children, value, multiple = false, wrap = true, onCh
20
20
  }
21
21
  },
22
22
  }), [normalizedValue, multiple, onChange]);
23
- return (_jsx(PillGroupContext.Provider, { value: contextValue, children: wrap ? (_jsx(Box, { style: [styles.group, styles.wrap, style], ...props, children: children })) : (_jsx(ScrollView, { horizontal: true, contentContainerStyle: [styles.group, style], showsHorizontalScrollIndicator: false, ...props, children: children })) }));
23
+ return (_jsx(PillGroupContext.Provider, { value: contextValue, children: wrap ? (_jsx(Box, { style: [styles.group, styles.wrap, style], ...props, children: children })) : (_jsx(ScrollView, { horizontal: true, style: styles.scrollView, contentContainerStyle: [styles.group, style], showsHorizontalScrollIndicator: false, ...props, children: children })) }));
24
24
  };
25
25
  PillGroup.displayName = 'PillGroup';
26
26
  const styles = StyleSheet.create(theme => ({
27
+ scrollView: {
28
+ flexGrow: 0,
29
+ },
27
30
  group: {
28
31
  flexDirection: 'row',
29
32
  gap: theme.components.pill.group.gap,
@@ -0,0 +1,14 @@
1
+ export type SegmentedControlContextValue = {
2
+ value?: string;
3
+ select: (value: string) => void;
4
+ disabled?: boolean;
5
+ size: 'sm' | 'md';
6
+ registerOptionLayout: (value: string, layout: {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ }) => void;
12
+ };
13
+ export declare const SegmentedControlContext: import("react").Context<SegmentedControlContextValue | null>;
14
+ export declare const useSegmentedControlContext: () => SegmentedControlContextValue;
@@ -0,0 +1,9 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const SegmentedControlContext = createContext(null);
3
+ export const useSegmentedControlContext = () => {
4
+ const context = useContext(SegmentedControlContext);
5
+ if (!context) {
6
+ throw new Error('SegmentedControlOption must be used within SegmentedControl');
7
+ }
8
+ return context;
9
+ };
@@ -0,0 +1,6 @@
1
+ import type SegmentedControlProps from './SegmentedControl.props';
2
+ declare const SegmentedControl: {
3
+ ({ value: controlledValue, defaultValue, onValueChange, size, disabled, children, style, ...props }: SegmentedControlProps): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ };
6
+ export default SegmentedControl;
@@ -0,0 +1,196 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Children, isValidElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { View } from 'react-native';
4
+ import Animated, { Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withTiming, } from 'react-native-reanimated';
5
+ import { StyleSheet } from 'react-native-unistyles';
6
+ import { useStyleProps } from '../../hooks';
7
+ import { SegmentedControlContext } from './SegmentedControl.context';
8
+ const Indicator = Animated.createAnimatedComponent(View);
9
+ const GROUP_BORDER_WIDTH = 1;
10
+ const SegmentedControl = ({ value: controlledValue, defaultValue, onValueChange, size = 'sm', disabled = false, children, style, ...props }) => {
11
+ const { computedStyles, remainingProps } = useStyleProps(props);
12
+ const isReducedMotion = useReducedMotion();
13
+ const indicatorPositionOffset = GROUP_BORDER_WIDTH;
14
+ const optionValues = useMemo(() => {
15
+ const values = [];
16
+ const walk = (node) => {
17
+ Children.forEach(node, child => {
18
+ if (!isValidElement(child))
19
+ return;
20
+ const childType = child.type;
21
+ const childProps = child.props;
22
+ if (childType?.displayName === 'SegmentedControlOption' &&
23
+ typeof childProps?.value === 'string') {
24
+ values.push(childProps.value);
25
+ }
26
+ if (childProps?.children) {
27
+ walk(childProps.children);
28
+ }
29
+ });
30
+ };
31
+ walk(children);
32
+ return values;
33
+ }, [children]);
34
+ const optionValuesKey = useMemo(() => optionValues.join('|'), [optionValues]);
35
+ const optionValuesRef = useRef(optionValues);
36
+ useEffect(() => {
37
+ optionValuesRef.current = optionValues;
38
+ }, [optionValues]);
39
+ const getInitialValue = () => {
40
+ if (controlledValue !== undefined)
41
+ return controlledValue;
42
+ if (defaultValue !== undefined)
43
+ return defaultValue;
44
+ return optionValues[0];
45
+ };
46
+ const [uncontrolledValue, setUncontrolledValue] = useState(getInitialValue);
47
+ useEffect(() => {
48
+ if (controlledValue !== undefined) {
49
+ setUncontrolledValue(controlledValue);
50
+ }
51
+ }, [controlledValue]);
52
+ useEffect(() => {
53
+ const currentOptionValues = optionValuesRef.current;
54
+ setUncontrolledValue(prev => {
55
+ if (!prev)
56
+ return currentOptionValues[0];
57
+ if (!currentOptionValues.includes(prev))
58
+ return currentOptionValues[0];
59
+ return prev;
60
+ });
61
+ }, [optionValuesKey]);
62
+ const currentValue = controlledValue !== undefined ? controlledValue : uncontrolledValue;
63
+ const indicatorX = useSharedValue(0);
64
+ const indicatorWidth = useSharedValue(0);
65
+ const indicatorY = useSharedValue(0);
66
+ const indicatorHeight = useSharedValue(0);
67
+ const [hasIndicator, setHasIndicator] = useState(false);
68
+ const layoutsRef = useRef(new Map());
69
+ const prevValueRef = useRef(undefined);
70
+ const initialisedRef = useRef(false);
71
+ const select = useCallback((nextValue) => {
72
+ if (disabled)
73
+ return;
74
+ if (controlledValue === undefined) {
75
+ setUncontrolledValue(nextValue);
76
+ }
77
+ onValueChange?.(nextValue);
78
+ }, [controlledValue, disabled, onValueChange]);
79
+ const registerOptionLayout = useCallback((value, layout) => {
80
+ layoutsRef.current.set(value, layout);
81
+ const activeValue = controlledValue !== undefined ? controlledValue : uncontrolledValue;
82
+ if (!activeValue || activeValue !== value)
83
+ return;
84
+ if (!initialisedRef.current) {
85
+ indicatorX.value = Math.max(0, layout.x - indicatorPositionOffset);
86
+ indicatorWidth.value = layout.width;
87
+ indicatorY.value = Math.max(0, layout.y - indicatorPositionOffset);
88
+ indicatorHeight.value = layout.height;
89
+ prevValueRef.current = activeValue;
90
+ initialisedRef.current = true;
91
+ setHasIndicator(true);
92
+ return;
93
+ }
94
+ if (prevValueRef.current === activeValue)
95
+ return;
96
+ const config = {
97
+ delay: 200,
98
+ duration: isReducedMotion ? 0 : 220,
99
+ easing: Easing.out(Easing.cubic),
100
+ };
101
+ indicatorX.value = withTiming(Math.max(0, layout.x - indicatorPositionOffset), config);
102
+ indicatorWidth.value = withTiming(layout.width, config);
103
+ indicatorY.value = withTiming(Math.max(0, layout.y - indicatorPositionOffset), config);
104
+ indicatorHeight.value = withTiming(layout.height, config);
105
+ prevValueRef.current = activeValue;
106
+ }, [
107
+ controlledValue,
108
+ indicatorHeight,
109
+ indicatorWidth,
110
+ indicatorX,
111
+ indicatorY,
112
+ indicatorPositionOffset,
113
+ isReducedMotion,
114
+ uncontrolledValue,
115
+ ]);
116
+ useEffect(() => {
117
+ if (!currentValue || !initialisedRef.current)
118
+ return;
119
+ if (prevValueRef.current === undefined || prevValueRef.current === currentValue)
120
+ return;
121
+ const layout = layoutsRef.current.get(currentValue);
122
+ if (!layout)
123
+ return;
124
+ const config = {
125
+ duration: isReducedMotion ? 0 : 220,
126
+ easing: Easing.out(Easing.cubic),
127
+ };
128
+ indicatorX.value = withTiming(Math.max(0, layout.x - indicatorPositionOffset), config);
129
+ indicatorWidth.value = withTiming(layout.width, config);
130
+ indicatorY.value = withTiming(Math.max(0, layout.y - indicatorPositionOffset), config);
131
+ indicatorHeight.value = withTiming(layout.height, config);
132
+ prevValueRef.current = currentValue;
133
+ }, [
134
+ currentValue,
135
+ indicatorHeight,
136
+ indicatorWidth,
137
+ indicatorX,
138
+ indicatorY,
139
+ indicatorPositionOffset,
140
+ isReducedMotion,
141
+ optionValuesKey,
142
+ ]);
143
+ const indicatorStyle = useAnimatedStyle(() => ({
144
+ transform: [{ translateX: indicatorX.value }, { translateY: indicatorY.value }],
145
+ width: indicatorWidth.value,
146
+ height: indicatorHeight.value,
147
+ }));
148
+ styles.useVariants({ disabled, size });
149
+ const contextValue = useMemo(() => ({
150
+ value: currentValue,
151
+ select,
152
+ disabled,
153
+ size,
154
+ registerOptionLayout,
155
+ }), [currentValue, select, disabled, size, registerOptionLayout]);
156
+ return (_jsx(SegmentedControlContext.Provider, { value: contextValue, children: _jsxs(View, { accessibilityRole: "radiogroup", accessibilityState: { disabled }, style: [styles.container, computedStyles, style], ...remainingProps, children: [hasIndicator ? (_jsx(Indicator, { pointerEvents: "none", style: [styles.indicator, indicatorStyle] })) : null, children] }) }));
157
+ };
158
+ SegmentedControl.displayName = 'SegmentedControl';
159
+ const styles = StyleSheet.create(theme => ({
160
+ container: {
161
+ flexDirection: 'row',
162
+ alignItems: 'center',
163
+ alignSelf: 'flex-start',
164
+ gap: theme.components.segmentedControl.group.gap,
165
+ height: theme.components.segmentedControl.group.height,
166
+ borderRadius: theme.components.segmentedControl.group.borderRadius,
167
+ borderWidth: theme.components.segmentedControl.group.borderWidth,
168
+ backgroundColor: theme.color.surface.neutral.subtle,
169
+ borderColor: theme.color.border.strong,
170
+ variants: {
171
+ size: {
172
+ sm: {
173
+ height: 32,
174
+ padding: 2,
175
+ },
176
+ md: {
177
+ height: theme.components.segmentedControl.group.height,
178
+ padding: 2,
179
+ },
180
+ },
181
+ disabled: {
182
+ true: {
183
+ opacity: theme.opacity.disabled,
184
+ },
185
+ },
186
+ },
187
+ },
188
+ indicator: {
189
+ position: 'absolute',
190
+ left: 0,
191
+ top: 0,
192
+ borderRadius: theme.components.segmentedControl.borderRadius,
193
+ backgroundColor: theme.color.interactive.brand.surface.strong.default,
194
+ },
195
+ }));
196
+ export default SegmentedControl;
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ViewProps } from 'react-native';
3
+ import type { FlexLayoutProps } from '../../types';
4
+ export interface SegmentedControlProps extends ViewProps, FlexLayoutProps {
5
+ /** Controlled selected option value. */
6
+ value?: string;
7
+ /** Initial selected option value for uncontrolled mode. */
8
+ defaultValue?: string;
9
+ /** Called when selected option changes. */
10
+ onValueChange?: (value: string) => void;
11
+ /** Size variant. */
12
+ size?: 'sm' | 'md';
13
+ /** Disables all options in the control. */
14
+ disabled?: boolean;
15
+ /** SegmentedControlOption children. */
16
+ children: ReactNode;
17
+ }
18
+ export default SegmentedControlProps;
@@ -0,0 +1,18 @@
1
+ import type SegmentedControlOptionProps from './SegmentedControlOption.props';
2
+ declare const SegmentedControlOption: import("react").ForwardRefExoticComponent<SegmentedControlOptionProps & {
3
+ states?: {
4
+ active?: boolean;
5
+ disabled?: boolean;
6
+ };
7
+ } & Omit<import("react-native").PressableProps, "children"> & {
8
+ tabIndex?: 0 | -1 | undefined;
9
+ } & {
10
+ children?: import("react").ReactNode | (({ hovered, pressed, focused, focusVisible, disabled, }: {
11
+ hovered?: boolean | undefined;
12
+ pressed?: boolean | undefined;
13
+ focused?: boolean | undefined;
14
+ focusVisible?: boolean | undefined;
15
+ disabled?: boolean | undefined;
16
+ }) => import("react").ReactNode);
17
+ } & import("react").RefAttributes<unknown>>;
18
+ export default SegmentedControlOption;
@@ -0,0 +1,141 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createPressable } from '@gluestack-ui/pressable';
3
+ import { useEffect } from 'react';
4
+ import { Platform, Pressable, View } from 'react-native';
5
+ import Animated, { Easing, useAnimatedStyle, useReducedMotion, useSharedValue, withTiming, } from 'react-native-reanimated';
6
+ import { StyleSheet } from 'react-native-unistyles';
7
+ import { BodyText } from '../BodyText';
8
+ import { Icon } from '../Icon';
9
+ import { useSegmentedControlContext } from './SegmentedControl.context';
10
+ const AnimatedView = Animated.createAnimatedComponent(View);
11
+ const SegmentedControlOptionRoot = ({ value, children, icon, accessibilityLabel, disabled = false, style, states = {}, ...props }) => {
12
+ const { value: selectedValue, select, disabled: allDisabled, size, registerOptionLayout, } = useSegmentedControlContext();
13
+ const { active = false } = states;
14
+ const reducedMotion = useReducedMotion();
15
+ const selected = selectedValue === value;
16
+ const isDisabled = disabled || !!allDisabled;
17
+ const selectedProgress = useSharedValue(selected ? 1 : 0);
18
+ useEffect(() => {
19
+ selectedProgress.value = withTiming(selected ? 1 : 0, {
20
+ duration: reducedMotion ? 0 : 220,
21
+ easing: Easing.out(Easing.cubic),
22
+ });
23
+ }, [reducedMotion, selected, selectedProgress]);
24
+ const regularLabelStyle = useAnimatedStyle(() => ({
25
+ opacity: 1 - selectedProgress.value,
26
+ }));
27
+ const selectedLabelStyle = useAnimatedStyle(() => ({
28
+ opacity: selectedProgress.value,
29
+ }));
30
+ styles.useVariants({ selected, disabled: isDisabled, size, active });
31
+ const onPress = () => {
32
+ if (isDisabled)
33
+ return;
34
+ select(value);
35
+ };
36
+ const accessibleLabel = typeof children === 'string' || typeof children === 'number' ? String(children) : value;
37
+ return (_jsx(Pressable, { ...props, accessibilityRole: "radio", accessibilityState: { checked: selected, disabled: isDisabled }, accessibilityLabel: accessibilityLabel ?? accessibleLabel, onPress: onPress, onLayout: e => registerOptionLayout(value, e.nativeEvent.layout), disabled: isDisabled, style: [styles.option, style], ...(Platform.OS === 'web'
38
+ ? { 'aria-label': accessibilityLabel ?? accessibleLabel }
39
+ : null), children: _jsxs(View, { style: styles.contentWrap, accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", ...(Platform.OS === 'web' ? { 'aria-hidden': true } : null), children: [icon ? _jsx(Icon, { as: icon, size: "sm", style: styles.icon }) : null, _jsxs(View, { style: styles.labelWrap, children: [_jsx(BodyText, { size: "md", weight: "semibold", style: styles.labelSizer, accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", ...(Platform.OS === 'web' ? { 'aria-hidden': true } : null), children: children }), _jsx(AnimatedView, { pointerEvents: "none", style: [styles.textLayer, regularLabelStyle], accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", ...(Platform.OS === 'web' ? { 'aria-hidden': true } : null), children: _jsx(BodyText, { size: "md", weight: "regular", style: styles.textRegular, children: children }) }), _jsx(AnimatedView, { pointerEvents: "none", style: [styles.textLayer, selectedLabelStyle], accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", ...(Platform.OS === 'web' ? { 'aria-hidden': true } : null), children: _jsx(BodyText, { size: "md", weight: "semibold", style: styles.textSelected, children: children }) })] })] }) }));
40
+ };
41
+ const SegmentedControlOption = createPressable({ Root: SegmentedControlOptionRoot });
42
+ SegmentedControlOption.displayName = 'SegmentedControlOption';
43
+ const styles = StyleSheet.create(theme => ({
44
+ option: {
45
+ minWidth: theme.components.segmentedControl.minWidth,
46
+ height: theme.components.segmentedControl.height,
47
+ borderRadius: theme.components.segmentedControl.borderRadius,
48
+ paddingHorizontal: theme.components.segmentedControl.paddingHorizontal,
49
+ paddingVertical: theme.components.segmentedControl.paddingVertical,
50
+ justifyContent: 'center',
51
+ alignItems: 'center',
52
+ backgroundColor: 'transparent',
53
+ zIndex: 1,
54
+ variants: {
55
+ size: {
56
+ sm: {
57
+ height: 28,
58
+ paddingHorizontal: theme.space[150],
59
+ paddingVertical: 0,
60
+ },
61
+ md: {
62
+ height: 44,
63
+ paddingHorizontal: theme.components.segmentedControl.paddingHorizontal,
64
+ paddingVertical: theme.components.segmentedControl.paddingVertical,
65
+ },
66
+ },
67
+ selected: {
68
+ true: {
69
+ backgroundColor: 'transparent',
70
+ _web: {
71
+ _active: {
72
+ backgroundColor: theme.color.interactive.brand.surface.strong.active,
73
+ },
74
+ },
75
+ },
76
+ false: {
77
+ _web: {
78
+ _hover: {
79
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.hover,
80
+ },
81
+ _active: {
82
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.active,
83
+ },
84
+ },
85
+ },
86
+ },
87
+ active: {
88
+ true: {
89
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.active,
90
+ },
91
+ },
92
+ },
93
+ },
94
+ contentWrap: {
95
+ flexDirection: 'row',
96
+ alignItems: 'center',
97
+ justifyContent: 'center',
98
+ gap: theme.components.segmentedControl.gap,
99
+ },
100
+ labelWrap: {
101
+ position: 'relative',
102
+ alignItems: 'center',
103
+ justifyContent: 'center',
104
+ },
105
+ labelSizer: {
106
+ opacity: 0,
107
+ },
108
+ textLayer: {
109
+ position: 'absolute',
110
+ left: 0,
111
+ right: 0,
112
+ alignItems: 'center',
113
+ justifyContent: 'center',
114
+ },
115
+ icon: {
116
+ variants: {
117
+ selected: {
118
+ true: {
119
+ color: theme.color.icon.inverted,
120
+ },
121
+ false: {
122
+ color: theme.color.icon.primary,
123
+ },
124
+ },
125
+ },
126
+ },
127
+ textRegular: {
128
+ color: theme.color.text.primary,
129
+ },
130
+ textSelected: {
131
+ color: theme.color.text.inverted,
132
+ variants: {
133
+ disabled: {
134
+ true: {
135
+ opacity: 1,
136
+ },
137
+ },
138
+ },
139
+ },
140
+ }));
141
+ export default SegmentedControlOption;
@@ -0,0 +1,14 @@
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ import type { PressableProps, ViewProps } from 'react-native';
3
+ export interface SegmentedControlOptionProps extends Omit<PressableProps, 'children'> {
4
+ /** Unique option value. */
5
+ value: string;
6
+ /** Option label/content. */
7
+ children: ReactNode;
8
+ /** Optional leading icon. */
9
+ icon?: ComponentType<any>;
10
+ /** Disables only this option. */
11
+ disabled?: boolean;
12
+ style?: ViewProps['style'];
13
+ }
14
+ export default SegmentedControlOptionProps;
@@ -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';
@@ -0,0 +1,2 @@
1
+ export { default as SegmentedControl } from './SegmentedControl';
2
+ export { default as SegmentedControlOption } from './SegmentedControlOption';
@@ -45,6 +45,7 @@ export * from './ProgressStepper';
45
45
  export * from './Radio';
46
46
  export * from './RadioCard';
47
47
  export * from './SectionHeader';
48
+ export * from './SegmentedControl';
48
49
  export * from './Select';
49
50
  export * from './Skeleton';
50
51
  export * from './Spinner';