@utilitywarehouse/hearth-react-native 0.2.0 → 0.3.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 (187) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.turbo/turbo-lint.log +1 -1
  3. package/CHANGELOG.md +22 -0
  4. package/build/components/Badge/Badge.js +101 -14
  5. package/build/components/Badge/Badge.props.d.ts +2 -2
  6. package/build/components/Badge/BadgeIcon.js +5 -79
  7. package/build/components/Badge/BadgeText.js +7 -81
  8. package/build/components/Button/Button.d.ts +2 -2
  9. package/build/components/Button/ButtonGroupRoot.d.ts +3 -2
  10. package/build/components/Button/ButtonGroupRoot.js +9 -0
  11. package/build/components/Card/Card.props.d.ts +2 -2
  12. package/build/components/CurrencyInput/CurrencyInput.d.ts +6 -0
  13. package/build/components/CurrencyInput/CurrencyInput.js +47 -0
  14. package/build/components/CurrencyInput/CurrencyInput.props.d.ts +14 -0
  15. package/build/components/CurrencyInput/CurrencyInput.props.js +1 -0
  16. package/build/components/CurrencyInput/index.d.ts +1 -0
  17. package/build/components/CurrencyInput/index.js +1 -0
  18. package/build/components/DescriptionList/DescriptionList.context.d.ts +6 -0
  19. package/build/components/DescriptionList/DescriptionList.context.js +9 -0
  20. package/build/components/DescriptionList/DescriptionList.d.ts +6 -0
  21. package/build/components/DescriptionList/DescriptionList.js +25 -0
  22. package/build/components/DescriptionList/DescriptionList.props.d.ts +18 -0
  23. package/build/components/DescriptionList/DescriptionList.props.js +1 -0
  24. package/build/components/DescriptionList/DescriptionListItem.d.ts +6 -0
  25. package/build/components/DescriptionList/DescriptionListItem.js +49 -0
  26. package/build/components/DescriptionList/DescriptionListItem.props.d.ts +17 -0
  27. package/build/components/DescriptionList/DescriptionListItem.props.js +1 -0
  28. package/build/components/DescriptionList/index.d.ts +4 -0
  29. package/build/components/DescriptionList/index.js +2 -0
  30. package/build/components/Divider/Divider.js +46 -0
  31. package/build/components/Divider/Divider.props.d.ts +2 -2
  32. package/build/components/Flex/Flex.props.d.ts +3 -2
  33. package/build/components/Grid/Grid.props.d.ts +2 -2
  34. package/build/components/IconContainer/IconContainer.d.ts +5 -0
  35. package/build/components/IconContainer/IconContainer.js +161 -0
  36. package/build/components/IconContainer/IconContainer.props.d.ts +15 -0
  37. package/build/components/IconContainer/IconContainer.props.js +1 -0
  38. package/build/components/IconContainer/index.d.ts +2 -0
  39. package/build/components/IconContainer/index.js +1 -0
  40. package/build/components/Icons/CircleIcon.js +3 -3
  41. package/build/components/Input/Input.js +2 -34
  42. package/build/components/Input/Input.props.d.ts +1 -17
  43. package/build/components/Input/InputField.js +0 -7
  44. package/build/components/Modal/Modal.js +17 -1
  45. package/build/components/SectionHeader/SectionHeader.js +1 -0
  46. package/build/components/Tabs/Tab.d.ts +18 -0
  47. package/build/components/Tabs/Tab.js +74 -0
  48. package/build/components/Tabs/Tab.props.d.ts +14 -0
  49. package/build/components/Tabs/Tab.props.js +1 -0
  50. package/build/components/Tabs/TabPanel.d.ts +3 -0
  51. package/build/components/Tabs/TabPanel.js +34 -0
  52. package/build/components/Tabs/TabPanel.props.d.ts +8 -0
  53. package/build/components/Tabs/TabPanel.props.js +1 -0
  54. package/build/components/Tabs/Tabs.context.d.ts +23 -0
  55. package/build/components/Tabs/Tabs.context.js +8 -0
  56. package/build/components/Tabs/Tabs.d.ts +6 -0
  57. package/build/components/Tabs/Tabs.js +114 -0
  58. package/build/components/Tabs/Tabs.props.d.ts +19 -0
  59. package/build/components/Tabs/Tabs.props.js +1 -0
  60. package/build/components/Tabs/TabsList.d.ts +6 -0
  61. package/build/components/Tabs/TabsList.js +112 -0
  62. package/build/components/Tabs/TabsList.props.d.ts +6 -0
  63. package/build/components/Tabs/TabsList.props.js +1 -0
  64. package/build/components/Tabs/index.d.ts +8 -0
  65. package/build/components/Tabs/index.js +4 -0
  66. package/build/components/index.d.ts +4 -0
  67. package/build/components/index.js +4 -0
  68. package/build/core/themes.d.ts +416 -148
  69. package/build/core/themes.js +57 -1
  70. package/build/tokens/color.d.ts +76 -68
  71. package/build/tokens/color.js +38 -34
  72. package/build/tokens/components/dark/button.d.ts +1 -0
  73. package/build/tokens/components/dark/button.js +1 -0
  74. package/build/tokens/components/dark/checkbox.d.ts +1 -1
  75. package/build/tokens/components/dark/checkbox.js +1 -1
  76. package/build/tokens/components/dark/icon-button.d.ts +3 -3
  77. package/build/tokens/components/dark/icon-button.js +3 -3
  78. package/build/tokens/components/dark/radio.d.ts +1 -1
  79. package/build/tokens/components/dark/radio.js +1 -1
  80. package/build/tokens/components/dark/tabs.d.ts +2 -0
  81. package/build/tokens/components/dark/tabs.js +2 -0
  82. package/build/tokens/components/light/badge.d.ts +1 -1
  83. package/build/tokens/components/light/badge.js +1 -1
  84. package/build/tokens/components/light/button.d.ts +1 -0
  85. package/build/tokens/components/light/button.js +1 -0
  86. package/build/tokens/components/light/checkbox.d.ts +3 -3
  87. package/build/tokens/components/light/checkbox.js +3 -3
  88. package/build/tokens/components/light/icon-button.d.ts +1 -1
  89. package/build/tokens/components/light/icon-button.js +1 -1
  90. package/build/tokens/components/light/radio.d.ts +3 -3
  91. package/build/tokens/components/light/radio.js +3 -3
  92. package/build/tokens/components/light/tabs.d.ts +2 -0
  93. package/build/tokens/components/light/tabs.js +2 -0
  94. package/build/tokens/layout.d.ts +48 -30
  95. package/build/tokens/layout.js +24 -15
  96. package/build/tokens/semantic-dark.d.ts +21 -19
  97. package/build/tokens/semantic-dark.js +21 -19
  98. package/build/tokens/semantic-light.d.ts +17 -15
  99. package/build/tokens/semantic-light.js +17 -15
  100. package/build/types/values.d.ts +2 -1
  101. package/build/utils/formatThousands.d.ts +2 -0
  102. package/build/utils/formatThousands.js +16 -0
  103. package/build/utils/index.d.ts +1 -0
  104. package/build/utils/index.js +1 -0
  105. package/docs/components/AllComponents.web.tsx +97 -8
  106. package/docs/components/NextPrevPage.tsx +11 -3
  107. package/docs/components/UsageWrap.tsx +2 -2
  108. package/docs/heplers/addReactNativePrefix.ts +8 -0
  109. package/docs/heplers/index.ts +1 -0
  110. package/docs/theme-tokens.mdx +42 -0
  111. package/package.json +2 -3
  112. package/src/components/Badge/Badge.docs.mdx +7 -7
  113. package/src/components/Badge/Badge.props.ts +3 -2
  114. package/src/components/Badge/Badge.stories.tsx +81 -92
  115. package/src/components/Badge/Badge.tsx +101 -14
  116. package/src/components/Badge/BadgeIcon.tsx +5 -79
  117. package/src/components/Badge/BadgeText.tsx +7 -81
  118. package/src/components/Button/ButtonGroupRoot.tsx +12 -2
  119. package/src/components/Card/Card.docs.mdx +1 -1
  120. package/src/components/Card/Card.props.ts +2 -2
  121. package/src/components/CurrencyInput/CurrencyInput.docs.mdx +120 -0
  122. package/src/components/CurrencyInput/CurrencyInput.props.ts +19 -0
  123. package/src/components/CurrencyInput/CurrencyInput.stories.tsx +116 -0
  124. package/src/components/CurrencyInput/CurrencyInput.tsx +91 -0
  125. package/src/components/CurrencyInput/index.ts +1 -0
  126. package/src/components/DescriptionList/DescriptionList.context.ts +18 -0
  127. package/src/components/DescriptionList/DescriptionList.docs.mdx +98 -0
  128. package/src/components/DescriptionList/DescriptionList.props.ts +20 -0
  129. package/src/components/DescriptionList/DescriptionList.stories.tsx +154 -0
  130. package/src/components/DescriptionList/DescriptionList.tsx +64 -0
  131. package/src/components/DescriptionList/DescriptionListItem.props.ts +19 -0
  132. package/src/components/DescriptionList/DescriptionListItem.tsx +101 -0
  133. package/src/components/DescriptionList/index.ts +4 -0
  134. package/src/components/Divider/Divider.props.ts +2 -2
  135. package/src/components/Divider/Divider.stories.tsx +3 -3
  136. package/src/components/Divider/Divider.tsx +46 -0
  137. package/src/components/Flex/Flex.docs.mdx +4 -4
  138. package/src/components/Flex/Flex.props.ts +3 -2
  139. package/src/components/Flex/Flex.stories.tsx +1 -1
  140. package/src/components/Grid/Grid.docs.mdx +12 -12
  141. package/src/components/Grid/Grid.props.ts +2 -2
  142. package/src/components/Grid/Grid.stories.tsx +2 -2
  143. package/src/components/IconContainer/IconContainer.docs.mdx +90 -0
  144. package/src/components/IconContainer/IconContainer.props.ts +17 -0
  145. package/src/components/IconContainer/IconContainer.stories.tsx +130 -0
  146. package/src/components/IconContainer/IconContainer.tsx +180 -0
  147. package/src/components/IconContainer/index.tsx +2 -0
  148. package/src/components/Icons/CircleIcon.tsx +9 -11
  149. package/src/components/Input/Input.docs.mdx +3 -3
  150. package/src/components/Input/Input.props.ts +0 -20
  151. package/src/components/Input/Input.stories.tsx +0 -6
  152. package/src/components/Input/Input.tsx +2 -49
  153. package/src/components/Input/InputField.tsx +0 -7
  154. package/src/components/Modal/Modal.tsx +18 -0
  155. package/src/components/SectionHeader/SectionHeader.tsx +1 -0
  156. package/src/components/Tabs/Tab.props.ts +16 -0
  157. package/src/components/Tabs/Tab.tsx +113 -0
  158. package/src/components/Tabs/TabPanel.props.ts +10 -0
  159. package/src/components/Tabs/TabPanel.tsx +46 -0
  160. package/src/components/Tabs/Tabs.context.ts +26 -0
  161. package/src/components/Tabs/Tabs.docs.mdx +214 -0
  162. package/src/components/Tabs/Tabs.props.ts +21 -0
  163. package/src/components/Tabs/Tabs.stories.tsx +270 -0
  164. package/src/components/Tabs/Tabs.tsx +139 -0
  165. package/src/components/Tabs/TabsList.props.ts +8 -0
  166. package/src/components/Tabs/TabsList.tsx +194 -0
  167. package/src/components/Tabs/index.ts +8 -0
  168. package/src/components/index.ts +4 -0
  169. package/src/core/themes.ts +57 -1
  170. package/src/tokens/color.ts +38 -34
  171. package/src/tokens/components/dark/button.ts +1 -0
  172. package/src/tokens/components/dark/checkbox.ts +1 -1
  173. package/src/tokens/components/dark/icon-button.ts +3 -3
  174. package/src/tokens/components/dark/radio.ts +1 -1
  175. package/src/tokens/components/dark/tabs.ts +2 -0
  176. package/src/tokens/components/light/badge.ts +1 -1
  177. package/src/tokens/components/light/button.ts +1 -0
  178. package/src/tokens/components/light/checkbox.ts +3 -3
  179. package/src/tokens/components/light/icon-button.ts +1 -1
  180. package/src/tokens/components/light/radio.ts +3 -3
  181. package/src/tokens/components/light/tabs.ts +2 -0
  182. package/src/tokens/layout.ts +24 -15
  183. package/src/tokens/semantic-dark.ts +21 -19
  184. package/src/tokens/semantic-light.ts +17 -15
  185. package/src/types/values.ts +3 -1
  186. package/src/utils/formatThousands.ts +14 -0
  187. package/src/utils/index.ts +1 -0
@@ -0,0 +1,18 @@
1
+ import type TabProps from './Tab.props';
2
+ declare const PressableTab: import("react").ForwardRefExoticComponent<TabProps & {
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 PressableTab;
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useCallback, useRef } from 'react';
3
+ import { Platform, Pressable, View } from 'react-native';
4
+ import { StyleSheet } from 'react-native-unistyles';
5
+ import { DetailText } from '../DetailText';
6
+ import { Icon } from '../Icon';
7
+ import { useTabsContext } from './Tabs.context';
8
+ import { createPressable } from '@gluestack-ui/pressable';
9
+ const Tab = ({ value, children, icon, disabled, style, states, ...props }) => {
10
+ const { value: active, select, size, disabled: allDisabled, registerTabLayout, } = useTabsContext();
11
+ const { active: pressed } = states || { active: false };
12
+ const isActive = active === value;
13
+ styles.useVariants({ size, pressed });
14
+ const ref = useRef(null);
15
+ const handlePress = () => {
16
+ if (disabled || allDisabled)
17
+ return;
18
+ select(value);
19
+ };
20
+ const handleLayout = useCallback((e) => {
21
+ const { x, y, width, height } = e.nativeEvent.layout;
22
+ registerTabLayout(value, { x, y, width, height });
23
+ }, [value, registerTabLayout]);
24
+ return (_jsx(Pressable, { ref: ref, accessibilityRole: "tab", accessibilityState: { selected: isActive, disabled: !!(disabled || allDisabled) }, onPress: handlePress, onLayout: handleLayout, style: [styles.tab, style], ...(Platform.OS === 'web'
25
+ ? { id: `tab-${value}`, 'aria-controls': `tabpanel-${value}` }
26
+ : null), ...props, children: _jsxs(View, { style: styles.content, children: [icon ? _jsx(Icon, { as: icon }) : null, _jsx(DetailText, { size: size, children: children })] }) }));
27
+ };
28
+ Tab.displayName = 'Tab';
29
+ const styles = StyleSheet.create(theme => ({
30
+ tab: {
31
+ position: 'relative',
32
+ backgroundColor: 'transparent',
33
+ alignItems: 'center',
34
+ justifyContent: 'center',
35
+ paddingHorizontal: theme.components.tabs.item.paddingHorizontal,
36
+ paddingVertical: theme.components.tabs.item.paddingVertical,
37
+ _web: {
38
+ _hover: {
39
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.hover,
40
+ },
41
+ '_focus-visible': {
42
+ ...theme.helpers.focusVisible,
43
+ outlineOffset: -2,
44
+ borderRadius: theme.borderRadius.sm,
45
+ },
46
+ _active: {
47
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.active,
48
+ },
49
+ },
50
+ variants: {
51
+ size: {
52
+ md: { height: theme.components.tabs.md.height },
53
+ lg: { height: theme.components.tabs.lg.height },
54
+ },
55
+ pressed: {
56
+ true: {
57
+ backgroundColor: theme.color.interactive.neutral.surface.subtle.active,
58
+ },
59
+ false: {},
60
+ },
61
+ },
62
+ },
63
+ content: {
64
+ flexDirection: 'row',
65
+ alignItems: 'center',
66
+ gap: theme.components.tabs.item.gap,
67
+ },
68
+ badge: {
69
+ marginLeft: theme.space[25],
70
+ },
71
+ }));
72
+ const PressableTab = createPressable({ Root: Tab });
73
+ PressableTab.displayName = 'Tab';
74
+ export default PressableTab;
@@ -0,0 +1,14 @@
1
+ import type { ComponentType, ReactNode } from 'react';
2
+ import type { PressableProps, ViewProps } from 'react-native';
3
+ export interface TabProps extends PressableProps {
4
+ /** Unique value for the tab */
5
+ value: string;
6
+ /** Tab label */
7
+ children: ReactNode;
8
+ /** Optional leading icon */
9
+ icon?: ComponentType<any>;
10
+ /** Whether the tab is disabled */
11
+ disabled?: boolean;
12
+ style?: ViewProps['style'];
13
+ }
14
+ export default TabProps;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import type TabPanelProps from './TabPanel.props';
2
+ declare const _default: import("react").MemoExoticComponent<({ value, children, keepMounted, style, ...rest }: TabPanelProps) => import("react/jsx-runtime").JSX.Element | null>;
3
+ export default _default;
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { memo } from 'react';
3
+ import { Platform, View } from 'react-native';
4
+ import { StyleSheet } from 'react-native-unistyles';
5
+ import { useTabsContext } from './Tabs.context';
6
+ const TabPanel = ({ value, children, keepMounted, style, ...rest }) => {
7
+ const { value: active } = useTabsContext();
8
+ const isActive = active === value;
9
+ if (!isActive && !keepMounted)
10
+ return null;
11
+ styles.useVariants({ active: isActive });
12
+ return (_jsx(View, { ...(Platform.OS === 'web'
13
+ ? {
14
+ id: `tabpanel-${value}`,
15
+ role: 'tabpanel',
16
+ 'aria-labelledby': `tab-${value}`,
17
+ hidden: !isActive || undefined,
18
+ }
19
+ : { accessibilityRole: 'summary' }), importantForAccessibility: isActive ? undefined : 'no-hide-descendants', accessibilityElementsHidden: isActive ? undefined : true, style: [styles.panel, style], ...rest, children: children }));
20
+ };
21
+ const styles = StyleSheet.create(theme => ({
22
+ panel: {
23
+ flex: 1,
24
+ width: '100%',
25
+ paddingTop: theme.space[100],
26
+ variants: {
27
+ active: {
28
+ true: { display: 'flex' },
29
+ false: { display: 'none' },
30
+ },
31
+ },
32
+ },
33
+ }));
34
+ export default memo(TabPanel);
@@ -0,0 +1,8 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ViewProps } from 'react-native';
3
+ export interface TabPanelProps extends ViewProps {
4
+ value: string;
5
+ children: ReactNode;
6
+ keepMounted?: boolean;
7
+ }
8
+ export default TabPanelProps;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import { SharedValue } from 'react-native-reanimated';
2
+ export interface TabsContextValue {
3
+ value: string | undefined;
4
+ size: 'md' | 'lg';
5
+ disabled?: boolean;
6
+ select: (value: string) => void;
7
+ registerTabLayout: (value: string, layout: {
8
+ x: number;
9
+ y: number;
10
+ width: number;
11
+ height: number;
12
+ }) => void;
13
+ getTabLayout: (value: string) => {
14
+ x: number;
15
+ y: number;
16
+ width: number;
17
+ height: number;
18
+ } | undefined;
19
+ indicatorXSV: SharedValue<number>;
20
+ indicatorSizeSV: SharedValue<number>;
21
+ }
22
+ export declare const TabsContext: import("react").Context<TabsContextValue | undefined>;
23
+ export declare const useTabsContext: () => TabsContextValue;
@@ -0,0 +1,8 @@
1
+ import { createContext, useContext } from 'react';
2
+ export const TabsContext = createContext(undefined);
3
+ export const useTabsContext = () => {
4
+ const ctx = useContext(TabsContext);
5
+ if (!ctx)
6
+ throw new Error('Tab / TabPanel must be used within Tabs');
7
+ return ctx;
8
+ };
@@ -0,0 +1,6 @@
1
+ import type TabsProps from './Tabs.props';
2
+ declare const Tabs: {
3
+ ({ value: controlledValue, defaultValue, onValueChange, size, disabled, children, withPanels, ...props }: TabsProps): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ };
6
+ export default Tabs;
@@ -0,0 +1,114 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Children, isValidElement, useCallback, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { View } from 'react-native';
4
+ import { Easing, useSharedValue, withTiming } from 'react-native-reanimated';
5
+ import { TabsContext } from './Tabs.context';
6
+ const Tabs = ({ value: controlledValue, defaultValue, onValueChange, size = 'md', disabled, children, withPanels, ...props }) => {
7
+ // Collect child tab values
8
+ const tabValues = useMemo(() => {
9
+ const vals = [];
10
+ const walk = (node) => {
11
+ Children.forEach(node, child => {
12
+ if (!isValidElement(child))
13
+ return;
14
+ const props = child.props;
15
+ const type = child.type;
16
+ if (type?.displayName === 'Tab' && typeof props?.value === 'string') {
17
+ vals.push(props.value);
18
+ }
19
+ if (props?.children)
20
+ walk(props.children);
21
+ });
22
+ };
23
+ walk(children);
24
+ return vals;
25
+ }, [children]);
26
+ const getInitial = () => {
27
+ if (controlledValue !== undefined)
28
+ return controlledValue;
29
+ if (defaultValue)
30
+ return defaultValue;
31
+ return tabValues[0];
32
+ };
33
+ const [uncontrolled, setUncontrolled] = useState(getInitial);
34
+ useEffect(() => {
35
+ if (controlledValue !== undefined)
36
+ setUncontrolled(controlledValue);
37
+ }, [controlledValue]);
38
+ // Ensure value remains valid if tabs change
39
+ useEffect(() => {
40
+ setUncontrolled(prev => {
41
+ if (!prev)
42
+ return tabValues[0];
43
+ if (!tabValues.includes(prev))
44
+ return tabValues[0];
45
+ return prev;
46
+ });
47
+ }, [tabValues.join('|')]);
48
+ const currentValue = controlledValue !== undefined ? controlledValue : uncontrolled;
49
+ const select = useCallback((val) => {
50
+ if (disabled)
51
+ return;
52
+ if (controlledValue === undefined)
53
+ setUncontrolled(val);
54
+ onValueChange?.(val);
55
+ }, [controlledValue, disabled, onValueChange]);
56
+ // Indicator shared values (declared early so registerTabLayout can reference)
57
+ const indicatorX = useSharedValue(0);
58
+ const indicatorSize = useSharedValue(0);
59
+ // Layout registry for animated indicator
60
+ const layoutsRef = useRef(new Map());
61
+ const prevValueRef = useRef(undefined);
62
+ const initialisedRef = useRef(false);
63
+ const registerTabLayout = useCallback((value, layout) => {
64
+ layoutsRef.current.set(value, layout);
65
+ const active = controlledValue !== undefined ? controlledValue : uncontrolled;
66
+ if (!active)
67
+ return;
68
+ // Initial active tab: seed indicator & prevValue so first change animates
69
+ if (!initialisedRef.current && value === active) {
70
+ indicatorX.value = layout.x;
71
+ indicatorSize.value = layout.width;
72
+ prevValueRef.current = active;
73
+ initialisedRef.current = true;
74
+ }
75
+ }, [controlledValue, uncontrolled, indicatorX, indicatorSize]);
76
+ const getTabLayout = useCallback((v) => layoutsRef.current.get(v), []);
77
+ const contextValue = useMemo(() => ({
78
+ value: currentValue,
79
+ size,
80
+ select,
81
+ disabled,
82
+ registerTabLayout,
83
+ getTabLayout,
84
+ indicatorXSV: indicatorX,
85
+ indicatorSizeSV: indicatorSize,
86
+ }), [
87
+ currentValue,
88
+ size,
89
+ select,
90
+ disabled,
91
+ registerTabLayout,
92
+ getTabLayout,
93
+ tabValues,
94
+ indicatorX,
95
+ indicatorSize,
96
+ ]);
97
+ // Animate indicator only on value changes after initialisation
98
+ useEffect(() => {
99
+ if (!currentValue || !initialisedRef.current)
100
+ return;
101
+ if (prevValueRef.current === undefined || prevValueRef.current === currentValue)
102
+ return;
103
+ const layout = getTabLayout(currentValue);
104
+ if (!layout)
105
+ return;
106
+ const cfg = { duration: 250, easing: Easing.out(Easing.ease) };
107
+ indicatorX.value = withTiming(layout.x, cfg);
108
+ indicatorSize.value = withTiming(layout.width, cfg);
109
+ prevValueRef.current = currentValue;
110
+ }, [currentValue, getTabLayout, indicatorX, indicatorSize, tabValues.join('|')]);
111
+ return (_jsx(TabsContext.Provider, { value: contextValue, children: _jsx(View, { ...props, children: children }) }));
112
+ };
113
+ Tabs.displayName = 'Tabs';
114
+ export default Tabs;
@@ -0,0 +1,19 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ViewProps } from 'react-native';
3
+ export interface TabsProps extends ViewProps {
4
+ /** Controlled active tab value */
5
+ value?: string;
6
+ /** Uncontrolled initial value */
7
+ defaultValue?: string;
8
+ /** Callback when active tab changes */
9
+ onValueChange?: (value: string) => void;
10
+ /** Size variant */
11
+ size?: 'md' | 'lg';
12
+ /** Tabs (Tab components) */
13
+ children: ReactNode;
14
+ /** Disable all tabs */
15
+ disabled?: boolean;
16
+ /** If true, expect sibling TabPanel components and manage their rendering/ARIA linkage */
17
+ withPanels?: boolean;
18
+ }
19
+ export default TabsProps;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import type TabsListProps from './TabsList.props';
2
+ declare const TabsList: {
3
+ ({ children, style, ...rest }: TabsListProps): import("react/jsx-runtime").JSX.Element;
4
+ displayName: string;
5
+ };
6
+ export default TabsList;
@@ -0,0 +1,112 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ChevronLeftSmallIcon, ChevronRightSmallIcon, } from '@utilitywarehouse/hearth-react-native-icons';
3
+ import { useCallback, useEffect, useRef, useState } from 'react';
4
+ import { Platform, View } from 'react-native';
5
+ import Animated, { runOnJS, useAnimatedScrollHandler, useAnimatedStyle, useSharedValue, } from 'react-native-reanimated';
6
+ import { StyleSheet } from 'react-native-unistyles';
7
+ import { UnstyledIconButton } from '../UnstyledIconButton';
8
+ import { useTabsContext } from './Tabs.context';
9
+ const Indicator = Animated.createAnimatedComponent(View);
10
+ const SCROLL_STEP_RATIO = 0.6;
11
+ const SCROLL_BUTTON_HITSLOP = { top: 10, bottom: 10, left: 10, right: 10 };
12
+ const TabsList = ({ children, style, ...rest }) => {
13
+ const { indicatorSizeSV, indicatorXSV } = useTabsContext();
14
+ const scrollRef = useRef(null);
15
+ const [canScrollLeft, setCanScrollLeft] = useState(false);
16
+ const [canScrollRight, setCanScrollRight] = useState(false);
17
+ const containerWidthRef = useRef(0);
18
+ const contentWidthRef = useRef(0);
19
+ const scrollX = useSharedValue(0);
20
+ const indicatorStyle = useAnimatedStyle(() => ({
21
+ transform: [{ translateX: indicatorXSV.value }],
22
+ width: indicatorSizeSV.value,
23
+ }));
24
+ const updateScrollState = useCallback(() => {
25
+ const cw = containerWidthRef.current;
26
+ const contentW = contentWidthRef.current;
27
+ const x = scrollX.value;
28
+ const overflow = contentW > cw + 1;
29
+ setCanScrollLeft(overflow && x > 0);
30
+ setCanScrollRight(overflow && x + cw < contentW - 1);
31
+ }, [scrollX]);
32
+ const onLayoutContainer = (e) => {
33
+ containerWidthRef.current = e.nativeEvent.layout.width;
34
+ updateScrollState();
35
+ };
36
+ const onContentSizeChange = (w) => {
37
+ contentWidthRef.current = w;
38
+ updateScrollState();
39
+ };
40
+ const onScrollHandler = useAnimatedScrollHandler({
41
+ onScroll: (e) => {
42
+ scrollX.value = e.contentOffset.x;
43
+ runOnJS(updateScrollState)();
44
+ },
45
+ });
46
+ const scrollBy = (direction) => {
47
+ const viewW = containerWidthRef.current;
48
+ const step = viewW * SCROLL_STEP_RATIO;
49
+ const current = scrollX.value;
50
+ const max = Math.max(0, contentWidthRef.current - viewW);
51
+ const target = Math.max(0, Math.min(current + direction * step, max));
52
+ scrollRef.current?.scrollTo({ x: target, animated: true });
53
+ };
54
+ useEffect(() => {
55
+ if (Platform.OS === 'web') {
56
+ const handler = () => updateScrollState();
57
+ window.addEventListener('resize', handler);
58
+ return () => window.removeEventListener('resize', handler);
59
+ }
60
+ return;
61
+ }, [updateScrollState]);
62
+ return (_jsxs(View, { style: [styles.wrapper, style], ...rest, accessibilityRole: "tablist", children: [canScrollLeft && (_jsx(View, { style: [styles.iconButtonWrap, styles.scrollButtonLeft], accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", ...(Platform.OS === 'web' ? { 'aria-hidden': true } : {}), children: _jsx(UnstyledIconButton, { accessibilityLabel: undefined, icon: ChevronLeftSmallIcon, onPress: () => scrollBy(-1), style: styles.iconButton, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", hitSlop: SCROLL_BUTTON_HITSLOP, ...(Platform.OS === 'web' ? { 'aria-hidden': true, tabIndex: -1 } : {}) }) })), _jsx(Animated.ScrollView, { ref: scrollRef, horizontal: true, showsHorizontalScrollIndicator: false, onLayout: onLayoutContainer, onContentSizeChange: onContentSizeChange, onScroll: onScrollHandler, scrollEventThrottle: 16, bounces: false, contentContainerStyle: styles.scrollContent, children: _jsxs(View, { style: styles.container, children: [children, _jsx(Indicator, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: [styles.indicator, indicatorStyle] })] }) }), canScrollRight && (_jsx(View, { style: [styles.iconButtonWrap, styles.scrollButtonRight], accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", ...(Platform.OS === 'web' ? { 'aria-hidden': true } : {}), children: _jsx(UnstyledIconButton, { accessibilityLabel: undefined, icon: ChevronRightSmallIcon, onPress: () => scrollBy(1), style: styles.iconButton, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", hitSlop: SCROLL_BUTTON_HITSLOP, ...(Platform.OS === 'web' ? { 'aria-hidden': true, tabIndex: -1 } : {}) }) }))] }));
63
+ };
64
+ TabsList.displayName = 'TabsList';
65
+ const styles = StyleSheet.create(theme => ({
66
+ wrapper: {
67
+ position: 'relative',
68
+ width: '100%',
69
+ borderBottomWidth: theme.components.tabs.divider.borderWidth,
70
+ borderColor: theme.components.tabs.divider.color,
71
+ },
72
+ scrollContent: {
73
+ paddingBottom: 0,
74
+ },
75
+ container: {
76
+ position: 'relative',
77
+ flexDirection: 'row',
78
+ gap: theme.components.tabs.gap,
79
+ },
80
+ indicator: {
81
+ position: 'absolute',
82
+ height: 6,
83
+ borderTopLeftRadius: theme.components.tabs.item.selected.borderTopRadius,
84
+ borderTopRightRadius: theme.components.tabs.item.selected.borderTopRadius,
85
+ borderBottomLeftRadius: theme.components.tabs.item.selected.borderBottomRadius,
86
+ borderBottomRightRadius: theme.components.tabs.item.selected.borderBottomRadius,
87
+ backgroundColor: theme.color.surface.brand.default,
88
+ bottom: 0,
89
+ left: 0,
90
+ },
91
+ scrollButtonLeft: {
92
+ position: 'absolute',
93
+ left: 0,
94
+ top: '50%',
95
+ transform: [{ translateY: -theme.space[150] }],
96
+ zIndex: 10,
97
+ },
98
+ scrollButtonRight: {
99
+ position: 'absolute',
100
+ right: 0,
101
+ top: '50%',
102
+ transform: [{ translateY: -theme.space[150] }],
103
+ zIndex: 10,
104
+ },
105
+ iconButtonWrap: {},
106
+ iconButton: {
107
+ backgroundColor: theme.color.surface.neutral.subtle,
108
+ width: theme.space[300],
109
+ height: theme.space[300],
110
+ },
111
+ }));
112
+ export default TabsList;
@@ -0,0 +1,6 @@
1
+ import type { ReactNode } from 'react';
2
+ import type { ViewProps } from 'react-native';
3
+ export interface TabsListProps extends ViewProps {
4
+ children: ReactNode;
5
+ }
6
+ export default TabsListProps;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,8 @@
1
+ export { default as Tab } from './Tab';
2
+ export type { TabProps } from './Tab.props';
3
+ export { default as TabPanel } from './TabPanel';
4
+ export type { TabPanelProps } from './TabPanel.props';
5
+ export { default as Tabs } from './Tabs';
6
+ export type { TabsProps } from './Tabs.props';
7
+ export { default as TabsList } from './TabsList';
8
+ export type { TabsListProps } from './TabsList.props';
@@ -0,0 +1,4 @@
1
+ export { default as Tab } from './Tab';
2
+ export { default as TabPanel } from './TabPanel';
3
+ export { default as Tabs } from './Tabs';
4
+ export { default as TabsList } from './TabsList';
@@ -8,6 +8,8 @@ export * from './Button';
8
8
  export * from './Card';
9
9
  export * from './Center';
10
10
  export * from './Checkbox';
11
+ export * from './CurrencyInput';
12
+ export * from './DescriptionList';
11
13
  export * from './DetailText';
12
14
  export * from './Divider';
13
15
  export * from './Flex';
@@ -18,6 +20,7 @@ export * from './Helper';
18
20
  export * from './HTMLElements';
19
21
  export * from './Icon';
20
22
  export * from './IconButton';
23
+ export * from './IconContainer';
21
24
  export * from './InlineLink';
22
25
  export * from './Input';
23
26
  export * from './Label';
@@ -31,6 +34,7 @@ export * from './Select';
31
34
  export * from './Skeleton';
32
35
  export * from './Spinner';
33
36
  export * from './Switch';
37
+ export * from './Tabs';
34
38
  export * from './Textarea';
35
39
  export * from './ToggleButtonCard';
36
40
  export { FlatList, Image, KeyboardAvoidingView, ScrollView, SectionList, StatusBar, View, } from 'react-native';
@@ -9,6 +9,8 @@ export * from './Button';
9
9
  export * from './Card';
10
10
  export * from './Center';
11
11
  export * from './Checkbox';
12
+ export * from './CurrencyInput';
13
+ export * from './DescriptionList';
12
14
  export * from './DetailText';
13
15
  export * from './Divider';
14
16
  export * from './Flex';
@@ -19,6 +21,7 @@ export * from './Helper';
19
21
  export * from './HTMLElements';
20
22
  export * from './Icon';
21
23
  export * from './IconButton';
24
+ export * from './IconContainer';
22
25
  export * from './InlineLink';
23
26
  export * from './Input';
24
27
  export * from './Label';
@@ -32,6 +35,7 @@ export * from './Select';
32
35
  export * from './Skeleton';
33
36
  export * from './Spinner';
34
37
  export * from './Switch';
38
+ export * from './Tabs';
35
39
  export * from './Textarea';
36
40
  export * from './ToggleButtonCard';
37
41
  export { FlatList, Image, KeyboardAvoidingView, ScrollView, SectionList, StatusBar, View, } from 'react-native';