@ovotech/element-native 5.6.0 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Accordion/styles.d.ts +3 -1734
- package/dist/components/ActionList/ActionListItems/DataListItem.js +3 -1
- package/dist/components/ActionList/ActionListItems/ToggleListItem.js +3 -4
- package/dist/components/ActionList/ActionListItems/styles.d.ts +22 -10404
- package/dist/components/ActionList/ActionListItems/styles.js +18 -16
- package/dist/components/ActionList/styled.d.ts +12 -6936
- package/dist/components/Badge/Badge.d.ts +1 -578
- package/dist/components/BottomActionBar/BottomActionBar.d.ts +12 -0
- package/dist/components/BottomActionBar/BottomActionBar.js +80 -0
- package/dist/components/BottomActionBar/OverlayProvider.d.ts +8 -0
- package/dist/components/BottomActionBar/OverlayProvider.js +38 -0
- package/dist/components/BottomActionBar/index.d.ts +2 -0
- package/dist/components/BottomActionBar/index.js +7 -0
- package/dist/components/Button/Button.styles.d.ts +5 -2312
- package/dist/components/Card/Card.styles.d.ts +3 -1734
- package/dist/components/Cards/AccountCard/AccountCard.styles.d.ts +8 -4624
- package/dist/components/Cards/BalanceCard/BalanceCard.styles.d.ts +15 -8670
- package/dist/components/Cards/DisruptiveCard/DisruptiveCard.styles.d.ts +1 -578
- package/dist/components/Cards/HeroImageCard/HeroImageCard.styles.d.ts +3 -1734
- package/dist/components/Cards/IconDataCard/IconDataCard.styles.d.ts +4 -2312
- package/dist/components/Cards/IconTextCard/IconTextCard.styles.d.ts +3 -1734
- package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.d.ts +5 -2890
- package/dist/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.js +1 -2
- package/dist/components/Cards/LinkTextCard/LinkTextCard.styles.d.ts +5 -2890
- package/dist/components/Cards/OfferCard/OfferCard.d.ts +22 -0
- package/dist/components/Cards/OfferCard/OfferCard.js +36 -0
- package/dist/components/Cards/OfferCard/OfferCard.styles.d.ts +34 -0
- package/dist/components/Cards/OfferCard/OfferCard.styles.js +61 -0
- package/dist/components/Cards/OfferCard/index.d.ts +1 -0
- package/dist/components/Cards/OfferCard/index.js +17 -0
- package/dist/components/Cards/ProgressBarCard/ProgressBarCard.styles.d.ts +9 -5202
- package/dist/components/Cards/QuickLinkCard/QuickLinkCard.styles.d.ts +5 -2890
- package/dist/components/Cards/ServicesImageCard/ServicesImageCard.styles.d.ts +5 -2890
- package/dist/components/Cards/shared.styles.d.ts +10 -5780
- package/dist/components/Checkbox/styled.d.ts +6 -3468
- package/dist/components/CurrencyInput/styled.d.ts +4 -2312
- package/dist/components/DataTable/styles.d.ts +13 -7514
- package/dist/components/Disclosure/Disclosure.d.ts +1 -578
- package/dist/components/Em/Em.d.ts +1 -578
- package/dist/components/EmptyState/styles.d.ts +2 -1156
- package/dist/components/ErrorText/ErrorText.d.ts +1 -578
- package/dist/components/Grid/Col.d.ts +1 -578
- package/dist/components/HintText/HintText.d.ts +1 -578
- package/dist/components/Input/styled.d.ts +3 -1734
- package/dist/components/LabelText/LabelText.d.ts +1 -578
- package/dist/components/LargeValueReference/styles.d.ts +3 -1734
- package/dist/components/LineThrough/LineThrough.d.ts +1 -578
- package/dist/components/List/styled.d.ts +4 -2312
- package/dist/components/Margin/Margin.d.ts +1 -578
- package/dist/components/NavHeader/NavHeader.styles.d.ts +11 -6358
- package/dist/components/Notification/Notification.d.ts +2 -2
- package/dist/components/Notification/Notification.js +20 -12
- package/dist/components/Notification/Notification.styles.d.ts +13 -5202
- package/dist/components/Notification/Notification.styles.js +21 -2
- package/dist/components/PasswordInput/PasswordInput.styled.d.ts +1 -578
- package/dist/components/Radio/Radio.d.ts +2 -2
- package/dist/components/Radio/Radio.js +5 -43
- package/dist/components/Radio/Radio.styles.d.ts +9 -0
- package/dist/components/Radio/Radio.styles.js +74 -0
- package/dist/components/RadioCard/RadioCard.styles.d.ts +5 -2890
- package/dist/components/Rail/Rail.d.ts +12 -0
- package/dist/components/Rail/Rail.js +58 -0
- package/dist/components/Rail/RailIndicator.d.ts +7 -0
- package/dist/components/Rail/RailIndicator.js +81 -0
- package/dist/components/Rail/index.d.ts +1 -0
- package/dist/components/Rail/index.js +5 -0
- package/dist/components/Rail/styles.d.ts +13 -0
- package/dist/components/Rail/styles.js +55 -0
- package/dist/components/Rail/useRailPaging.d.ts +13 -0
- package/dist/components/Rail/useRailPaging.js +95 -0
- package/dist/components/SelectField/styled.d.ts +8 -4624
- package/dist/components/Strong/Strong.d.ts +1 -578
- package/dist/components/SubLabelText/SubLabelText.d.ts +1 -578
- package/dist/components/Tabs/Tab.d.ts +1 -578
- package/dist/components/Toast/Toast.d.ts +10 -4
- package/dist/components/Toast/Toast.js +40 -27
- package/dist/components/Toggle/styles.d.ts +4 -2312
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/esm/components/ActionList/ActionListItems/DataListItem.js +3 -1
- package/dist/esm/components/ActionList/ActionListItems/ToggleListItem.js +5 -6
- package/dist/esm/components/ActionList/ActionListItems/styles.js +17 -15
- package/dist/esm/components/BottomActionBar/BottomActionBar.js +40 -0
- package/dist/esm/components/BottomActionBar/OverlayProvider.js +30 -0
- package/dist/esm/components/BottomActionBar/index.js +2 -0
- package/dist/esm/components/Cards/IllustrationTextCard/IllustrationTextCard.styles.js +1 -2
- package/dist/esm/components/Cards/OfferCard/OfferCard.js +32 -0
- package/dist/esm/components/Cards/OfferCard/OfferCard.styles.js +55 -0
- package/dist/esm/components/Cards/OfferCard/index.js +1 -0
- package/dist/esm/components/Notification/Notification.js +21 -13
- package/dist/esm/components/Notification/Notification.styles.js +20 -1
- package/dist/esm/components/Radio/Radio.js +4 -39
- package/dist/esm/components/Radio/Radio.styles.js +38 -0
- package/dist/esm/components/Rail/Rail.js +21 -0
- package/dist/esm/components/Rail/RailIndicator.js +44 -0
- package/dist/esm/components/Rail/index.js +1 -0
- package/dist/esm/components/Rail/styles.js +49 -0
- package/dist/esm/components/Rail/useRailPaging.js +92 -0
- package/dist/esm/components/Toast/Toast.js +40 -27
- package/dist/esm/components/index.js +2 -0
- package/dist/styled.native.d.ts +1 -3463
- package/package.json +2 -2
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IconNameExtended } from '../../providers';
|
|
3
|
+
type Props = {
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
indicator?: boolean;
|
|
6
|
+
heading?: string;
|
|
7
|
+
subHeading?: string;
|
|
8
|
+
icon?: IconNameExtended;
|
|
9
|
+
maxChildren?: number;
|
|
10
|
+
};
|
|
11
|
+
export declare const Rail: ({ children, indicator, icon, heading, subHeading, maxChildren, }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Rail = void 0;
|
|
37
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
const react_1 = __importStar(require("react"));
|
|
39
|
+
const react_native_1 = require("react-native");
|
|
40
|
+
const Icon_1 = require("../Icon");
|
|
41
|
+
const P_1 = require("../P");
|
|
42
|
+
const Strong_1 = require("../Strong");
|
|
43
|
+
const RailIndicator_1 = require("./RailIndicator");
|
|
44
|
+
const styles_1 = require("./styles");
|
|
45
|
+
const useRailPaging_1 = require("./useRailPaging");
|
|
46
|
+
const DEFAULT_MAX_CHILDREN = 6;
|
|
47
|
+
const Rail = ({ children, indicator = true, icon, heading, subHeading, maxChildren = DEFAULT_MAX_CHILDREN, }) => {
|
|
48
|
+
const allItems = (0, react_1.useMemo)(() => react_1.default.Children.toArray(children), [children]);
|
|
49
|
+
const items = (0, react_1.useMemo)(() => allItems.slice(0, Math.max(0, maxChildren)), [allItems, maxChildren]);
|
|
50
|
+
const paging = (0, useRailPaging_1.useRailPaging)({ itemCount: items.length });
|
|
51
|
+
const hasIndicator = indicator && paging.isScrollable;
|
|
52
|
+
return ((0, jsx_runtime_1.jsxs)(react_native_1.View, { children: [(0, jsx_runtime_1.jsxs)(styles_1.Header, { children: [icon && ((0, jsx_runtime_1.jsx)(styles_1.IconContainer, { children: (0, jsx_runtime_1.jsx)(Icon_1.Icon, { name: icon, size: 24 }) })), (heading || subHeading) && ((0, jsx_runtime_1.jsxs)(styles_1.HeadingText, { children: [heading && ((0, jsx_runtime_1.jsx)(P_1.P, { size: "lg", children: (0, jsx_runtime_1.jsx)(Strong_1.Strong, { children: heading }) })), subHeading && (0, jsx_runtime_1.jsx)(P_1.P, { size: "sm", children: subHeading })] }))] }), (0, jsx_runtime_1.jsxs)(react_native_1.View, { onLayout: e => paging.onContainerLayout(e.nativeEvent.layout.width), children: [(0, jsx_runtime_1.jsx)(styles_1.StyledRail, { horizontal: true, hasIndicator: hasIndicator, showsHorizontalScrollIndicator: false, contentContainerStyle: { flexDirection: 'row' }, decelerationRate: "fast", snapToOffsets: paging.snapOffsets, snapToAlignment: "start", disableIntervalMomentum: true, scrollEventThrottle: 16, onMomentumScrollEnd: (e) => paging.onMomentumEnd(e.nativeEvent.contentOffset.x), onContentSizeChange: w => paging.onContentSizeChange(w), children: items.map((child, index) => ((0, jsx_runtime_1.jsx)(styles_1.RailItemWrapper, { onLayout: (e) => {
|
|
53
|
+
if (index !== 0)
|
|
54
|
+
return;
|
|
55
|
+
paging.onItemLayout(e.nativeEvent.layout.width);
|
|
56
|
+
}, children: child }, `Rail-item-${index}`))) }), hasIndicator && ((0, jsx_runtime_1.jsx)(RailIndicator_1.RailIndicator, { dotCount: items.length, activeStartIndex: paging.activeStartIndex, visibleCount: paging.visibleCount }))] })] }));
|
|
57
|
+
};
|
|
58
|
+
exports.Rail = Rail;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.RailIndicator = void 0;
|
|
37
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
38
|
+
const react_1 = require("react");
|
|
39
|
+
const react_native_reanimated_1 = __importStar(require("react-native-reanimated"));
|
|
40
|
+
const styled_native_1 = require("../../styled.native");
|
|
41
|
+
const styles_1 = require("./styles");
|
|
42
|
+
const RailIndicator = ({ dotCount, activeStartIndex, visibleCount, }) => {
|
|
43
|
+
const theme = (0, styled_native_1.useTheme)();
|
|
44
|
+
const DOT = theme.space[200];
|
|
45
|
+
const GAP = theme.space[200];
|
|
46
|
+
const PADDING = theme.space[350];
|
|
47
|
+
const [containerWidth, setContainerWidth] = (0, react_1.useState)(0);
|
|
48
|
+
const onContainerLayout = (0, react_1.useCallback)((e) => {
|
|
49
|
+
var _a, _b, _c;
|
|
50
|
+
const w = (_c = (_b = (_a = e === null || e === void 0 ? void 0 : e.nativeEvent) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.width) !== null && _c !== void 0 ? _c : 0;
|
|
51
|
+
if (w > 0)
|
|
52
|
+
setContainerWidth(w);
|
|
53
|
+
}, []);
|
|
54
|
+
if (dotCount <= 0)
|
|
55
|
+
return null;
|
|
56
|
+
const start = Math.min(Math.max(0, activeStartIndex), dotCount - 1);
|
|
57
|
+
const visible = Math.max(1, Math.min(visibleCount, dotCount - start));
|
|
58
|
+
const rowWidth = (0, react_1.useMemo)(() => {
|
|
59
|
+
return dotCount * DOT + (dotCount - 1) * GAP;
|
|
60
|
+
}, [dotCount, DOT, GAP]);
|
|
61
|
+
const step = DOT + GAP;
|
|
62
|
+
const animatedLeft = (0, react_native_reanimated_1.useDerivedValue)(() => {
|
|
63
|
+
if (containerWidth <= 0)
|
|
64
|
+
return 0;
|
|
65
|
+
const innerWidth = Math.max(0, containerWidth - 2 * PADDING);
|
|
66
|
+
const rowLeft = PADDING + Math.max(0, (innerWidth - rowWidth) / 2);
|
|
67
|
+
return (0, react_native_reanimated_1.withTiming)(rowLeft + start * step, { duration: 150 });
|
|
68
|
+
}, [containerWidth, PADDING, rowWidth, start, step]);
|
|
69
|
+
const animatedWidth = (0, react_native_reanimated_1.useDerivedValue)(() => {
|
|
70
|
+
const w = visible * DOT + Math.max(0, visible - 1) * GAP;
|
|
71
|
+
return (0, react_native_reanimated_1.withTiming)(w, { duration: 150 });
|
|
72
|
+
}, [visible, DOT, GAP]);
|
|
73
|
+
const pillStyle = (0, react_native_reanimated_1.useAnimatedStyle)(() => ({
|
|
74
|
+
position: 'absolute',
|
|
75
|
+
left: animatedLeft.value,
|
|
76
|
+
width: animatedWidth.value,
|
|
77
|
+
opacity: containerWidth > 0 ? 1 : 0,
|
|
78
|
+
}));
|
|
79
|
+
return ((0, jsx_runtime_1.jsxs)(styles_1.RailIndicatorContainer, { onLayout: onContainerLayout, children: [Array.from({ length: dotCount }).map((_, index) => ((0, jsx_runtime_1.jsx)(styles_1.DotContainer, { isActive: false }, `dot-${index}`))), (0, jsx_runtime_1.jsx)(react_native_reanimated_1.default.View, { pointerEvents: "none", style: pillStyle, children: (0, jsx_runtime_1.jsx)(styles_1.DotContainer, { isActive: true, style: { width: '100%' } }) })] }));
|
|
80
|
+
};
|
|
81
|
+
exports.RailIndicator = RailIndicator;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Rail } from './Rail';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { View } from 'react-native';
|
|
2
|
+
import Animated from 'react-native-reanimated';
|
|
3
|
+
export declare const StyledRail: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("react-native-reanimated").AnimatedScrollViewProps & import("react").RefAttributes<Animated.ScrollView>>, import("@ovotech/element-core/dist/tokens-build/theme-native.types").ThemeNative, {
|
|
4
|
+
hasIndicator: boolean;
|
|
5
|
+
}, never>;
|
|
6
|
+
export declare const RailItemWrapper: import("styled-components").StyledComponent<typeof import("react-native").View, import("@ovotech/element-core/dist/tokens-build/theme-native.types").ThemeNative, {}, never>;
|
|
7
|
+
export declare const RailIndicatorContainer: import("styled-components").StyledComponent<typeof import("react-native").View, import("@ovotech/element-core/dist/tokens-build/theme-native.types").ThemeNative, {}, never>;
|
|
8
|
+
export declare const DotContainer: import("styled-components").StyledComponent<import("react").ComponentClass<import("react-native-reanimated").AnimateProps<import("react-native").ViewProps>, any>, import("@ovotech/element-core/dist/tokens-build/theme-native.types").ThemeNative, {
|
|
9
|
+
isActive: boolean;
|
|
10
|
+
}, never>;
|
|
11
|
+
export declare const Header: import("styled-components").StyledComponent<typeof View, import("@ovotech/element-core/dist/tokens-build/theme-native.types").ThemeNative, {}, never>;
|
|
12
|
+
export declare const HeadingText: import("styled-components").StyledComponent<typeof View, import("@ovotech/element-core/dist/tokens-build/theme-native.types").ThemeNative, {}, never>;
|
|
13
|
+
export declare const IconContainer: import("styled-components").StyledComponent<typeof View, import("@ovotech/element-core/dist/tokens-build/theme-native.types").ThemeNative, {}, never>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.IconContainer = exports.HeadingText = exports.Header = exports.DotContainer = exports.RailIndicatorContainer = exports.RailItemWrapper = exports.StyledRail = void 0;
|
|
7
|
+
const react_native_1 = require("react-native");
|
|
8
|
+
const react_native_reanimated_1 = __importDefault(require("react-native-reanimated"));
|
|
9
|
+
const styled_native_1 = __importDefault(require("../../styled.native"));
|
|
10
|
+
exports.StyledRail = (0, styled_native_1.default)(react_native_reanimated_1.default.ScrollView)(({ theme, hasIndicator }) => ({
|
|
11
|
+
paddingVertical: theme.space[350],
|
|
12
|
+
paddingHorizontal: theme.space[50],
|
|
13
|
+
marginBottom: hasIndicator ? 0 : theme.space[900],
|
|
14
|
+
}));
|
|
15
|
+
exports.RailItemWrapper = styled_native_1.default.View(({ theme }) => ({
|
|
16
|
+
paddingHorizontal: theme.space[100],
|
|
17
|
+
}));
|
|
18
|
+
exports.RailIndicatorContainer = styled_native_1.default.View(({ theme }) => ({
|
|
19
|
+
flexDirection: 'row',
|
|
20
|
+
alignItems: 'center',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
alignSelf: 'center',
|
|
23
|
+
backgroundColor: theme.color.surface.dim,
|
|
24
|
+
borderRadius: theme.border.radius['2xl'],
|
|
25
|
+
padding: theme.space[350],
|
|
26
|
+
gap: theme.space[200],
|
|
27
|
+
}));
|
|
28
|
+
exports.DotContainer = (0, styled_native_1.default)(react_native_reanimated_1.default.View)(({ theme, isActive }) => ({
|
|
29
|
+
height: theme.space[200],
|
|
30
|
+
width: theme.space[200],
|
|
31
|
+
borderRadius: 9999,
|
|
32
|
+
backgroundColor: isActive
|
|
33
|
+
? theme.color.surface.onSurface
|
|
34
|
+
: theme.color.surface.onSurfaceVariant,
|
|
35
|
+
}));
|
|
36
|
+
exports.Header = (0, styled_native_1.default)(react_native_1.View)(({ theme }) => ({
|
|
37
|
+
flexDirection: 'row',
|
|
38
|
+
gap: theme.space[300],
|
|
39
|
+
marginBottom: -theme.space[100],
|
|
40
|
+
marginLeft: theme.space[100],
|
|
41
|
+
}));
|
|
42
|
+
exports.HeadingText = (0, styled_native_1.default)(react_native_1.View)({
|
|
43
|
+
flex: 1,
|
|
44
|
+
flexShrink: 1,
|
|
45
|
+
});
|
|
46
|
+
exports.IconContainer = (0, styled_native_1.default)(react_native_1.View)(({ theme }) => ({
|
|
47
|
+
borderRadius: theme.border.radius['2xl'],
|
|
48
|
+
backgroundColor: theme.color.surface.bright,
|
|
49
|
+
borderWidth: 0,
|
|
50
|
+
padding: theme.space[200],
|
|
51
|
+
width: theme.space[1100],
|
|
52
|
+
height: theme.space[1100],
|
|
53
|
+
alignItems: 'center',
|
|
54
|
+
justifyContent: 'center',
|
|
55
|
+
}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type UseRailPagingArgs = {
|
|
2
|
+
itemCount: number;
|
|
3
|
+
};
|
|
4
|
+
export declare function useRailPaging({ itemCount }: UseRailPagingArgs): {
|
|
5
|
+
snapOffsets: number[];
|
|
6
|
+
isScrollable: boolean;
|
|
7
|
+
activeStartIndex: number;
|
|
8
|
+
visibleCount: number;
|
|
9
|
+
onContainerLayout: (width: number) => void;
|
|
10
|
+
onContentSizeChange: (width: number) => void;
|
|
11
|
+
onItemLayout: (width: number) => void;
|
|
12
|
+
onMomentumEnd: (offsetX: number) => void;
|
|
13
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useRailPaging = useRailPaging;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
//Epsilon allowable margin for nearly equal comparisons
|
|
6
|
+
const EPS = 0.5;
|
|
7
|
+
function nearlyEqual(a, b, eps = EPS) {
|
|
8
|
+
return Math.abs(a - b) <= eps;
|
|
9
|
+
}
|
|
10
|
+
function clamp(n, lo, hi) {
|
|
11
|
+
return Math.max(lo, Math.min(n, hi));
|
|
12
|
+
}
|
|
13
|
+
function uniqueNearlyEqual(values, eps = EPS) {
|
|
14
|
+
const out = [];
|
|
15
|
+
for (const v of values) {
|
|
16
|
+
if (out.length === 0 || !nearlyEqual(out[out.length - 1], v, eps))
|
|
17
|
+
out.push(v);
|
|
18
|
+
}
|
|
19
|
+
return out;
|
|
20
|
+
}
|
|
21
|
+
function useRailPaging({ itemCount }) {
|
|
22
|
+
const safeItemCount = Math.max(0, itemCount);
|
|
23
|
+
const [containerWidth, setContainerWidth] = (0, react_1.useState)(0);
|
|
24
|
+
const [contentWidth, setContentWidth] = (0, react_1.useState)(0);
|
|
25
|
+
const [itemWidth, setItemWidth] = (0, react_1.useState)(0);
|
|
26
|
+
const [activeStartIndex, setActiveStartIndex] = (0, react_1.useState)(0);
|
|
27
|
+
const stride = itemWidth;
|
|
28
|
+
const isScrollable = containerWidth > 0 && contentWidth > containerWidth + 1;
|
|
29
|
+
const visibleCount = (0, react_1.useMemo)(() => {
|
|
30
|
+
const maxVisible = Math.max(1, safeItemCount);
|
|
31
|
+
if (safeItemCount === 0)
|
|
32
|
+
return 1;
|
|
33
|
+
if (containerWidth <= 0 || stride <= 0)
|
|
34
|
+
return 1;
|
|
35
|
+
return clamp(Math.ceil(containerWidth / stride), 1, maxVisible);
|
|
36
|
+
}, [containerWidth, stride, safeItemCount]);
|
|
37
|
+
const maxStartIndex = (0, react_1.useMemo)(() => {
|
|
38
|
+
if (safeItemCount <= 0)
|
|
39
|
+
return 0;
|
|
40
|
+
return clamp(safeItemCount - visibleCount, 0, safeItemCount - 1);
|
|
41
|
+
}, [safeItemCount, visibleCount]);
|
|
42
|
+
(0, react_1.useEffect)(() => {
|
|
43
|
+
setActiveStartIndex(prev => clamp(prev, 0, maxStartIndex));
|
|
44
|
+
}, [maxStartIndex]);
|
|
45
|
+
(0, react_1.useEffect)(() => {
|
|
46
|
+
setActiveStartIndex(0);
|
|
47
|
+
}, [safeItemCount]);
|
|
48
|
+
const snapOffsets = (0, react_1.useMemo)(() => {
|
|
49
|
+
var _a;
|
|
50
|
+
if (safeItemCount === 0)
|
|
51
|
+
return [0];
|
|
52
|
+
if (containerWidth <= 0 || contentWidth <= 0 || stride <= 0)
|
|
53
|
+
return [0];
|
|
54
|
+
const maxScrollX = Math.max(0, contentWidth - containerWidth);
|
|
55
|
+
const offsets = [];
|
|
56
|
+
for (let index = 0; index <= maxStartIndex; index++) {
|
|
57
|
+
offsets.push(index * stride);
|
|
58
|
+
}
|
|
59
|
+
const last = (_a = offsets[offsets.length - 1]) !== null && _a !== void 0 ? _a : 0;
|
|
60
|
+
if (!nearlyEqual(last, maxScrollX))
|
|
61
|
+
offsets.push(maxScrollX);
|
|
62
|
+
return uniqueNearlyEqual(offsets);
|
|
63
|
+
}, [safeItemCount, containerWidth, contentWidth, stride, maxStartIndex]);
|
|
64
|
+
const onContainerLayout = (0, react_1.useCallback)((width) => {
|
|
65
|
+
setContainerWidth(width > 0 ? width : 0);
|
|
66
|
+
}, []);
|
|
67
|
+
const onContentSizeChange = (0, react_1.useCallback)((width) => {
|
|
68
|
+
setContentWidth(width > 0 ? width : 0);
|
|
69
|
+
}, []);
|
|
70
|
+
/**
|
|
71
|
+
* NOTE: This measures ONE item width (e.g. the first child) and assumes all
|
|
72
|
+
* items are the same width.
|
|
73
|
+
*/
|
|
74
|
+
const onItemLayout = (0, react_1.useCallback)((width) => {
|
|
75
|
+
if (width > 0)
|
|
76
|
+
setItemWidth(width);
|
|
77
|
+
}, []);
|
|
78
|
+
const onMomentumEnd = (0, react_1.useCallback)((offsetX) => {
|
|
79
|
+
if (stride <= 0)
|
|
80
|
+
return;
|
|
81
|
+
const raw = Math.round(offsetX / stride);
|
|
82
|
+
const nextStart = clamp(raw, 0, maxStartIndex);
|
|
83
|
+
setActiveStartIndex(prev => (prev === nextStart ? prev : nextStart));
|
|
84
|
+
}, [stride, maxStartIndex]);
|
|
85
|
+
return {
|
|
86
|
+
snapOffsets,
|
|
87
|
+
isScrollable,
|
|
88
|
+
activeStartIndex,
|
|
89
|
+
visibleCount,
|
|
90
|
+
onContainerLayout,
|
|
91
|
+
onContentSizeChange,
|
|
92
|
+
onItemLayout,
|
|
93
|
+
onMomentumEnd,
|
|
94
|
+
};
|
|
95
|
+
}
|