@lookiero/checkout 0.2.4 → 0.2.5

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.
@@ -0,0 +1,14 @@
1
+ import { FC } from "react";
2
+ import { StyleProp, ViewStyle } from "react-native";
3
+ interface PaginationProps {
4
+ readonly touchable?: boolean;
5
+ readonly paginationStyle?: StyleProp<ViewStyle>;
6
+ readonly paginationItemStyle?: StyleProp<ViewStyle>;
7
+ readonly paginationActiveItemStyle?: StyleProp<ViewStyle>;
8
+ readonly count?: number;
9
+ readonly activeIndex?: number;
10
+ readonly onChange: (index: number) => void;
11
+ readonly renderItem?: (index: number) => JSX.Element;
12
+ }
13
+ declare const Pagination: FC<PaginationProps>;
14
+ export { Pagination };
@@ -0,0 +1,11 @@
1
+ import React from "react";
2
+ import { Pressable, View } from "react-native";
3
+ import { style } from "./Pagination.style";
4
+ const Pagination = ({ touchable = true, paginationStyle, paginationItemStyle, paginationActiveItemStyle, count = 0, activeIndex = 0, renderItem, onChange, }) => (React.createElement(View, { style: [style.paginationWrapper, paginationStyle], testID: "slider-pagination" }, Array.from(Array(count).keys()).map((index) => (React.createElement(View, { key: index, style: style.paginationContainer },
5
+ React.createElement(Pressable, { onPress: !touchable ? undefined : () => onChange(index), style: [
6
+ style.paginationItem,
7
+ activeIndex === index && style.active,
8
+ paginationItemStyle,
9
+ activeIndex === index && paginationActiveItemStyle,
10
+ ], testID: "slider-pagination-item" }, renderItem?.(index)))))));
11
+ export { Pagination };
@@ -0,0 +1,23 @@
1
+ declare const style: {
2
+ paginationWrapper: {
3
+ alignItems: "center";
4
+ bottom: number;
5
+ flexDirection: "row";
6
+ justifyContent: "center";
7
+ position: "absolute";
8
+ width: string;
9
+ };
10
+ paginationContainer: {
11
+ margin: number;
12
+ };
13
+ paginationItem: {
14
+ width: number;
15
+ height: number;
16
+ borderRadius: number;
17
+ backgroundColor: string;
18
+ };
19
+ active: {
20
+ backgroundColor: string;
21
+ };
22
+ };
23
+ export { style };
@@ -0,0 +1,27 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { theme } from "../../../theme/theme";
3
+ const { colorGrayscaleS, colorGrayscaleXL } = theme();
4
+ const DOT_SIZE = 8;
5
+ const style = StyleSheet.create({
6
+ paginationWrapper: {
7
+ alignItems: "center",
8
+ bottom: 10,
9
+ flexDirection: "row",
10
+ justifyContent: "center",
11
+ position: "absolute",
12
+ width: "100%",
13
+ },
14
+ paginationContainer: {
15
+ margin: 3,
16
+ },
17
+ paginationItem: {
18
+ width: DOT_SIZE,
19
+ height: DOT_SIZE,
20
+ borderRadius: DOT_SIZE / 2,
21
+ backgroundColor: colorGrayscaleS,
22
+ },
23
+ active: {
24
+ backgroundColor: colorGrayscaleXL,
25
+ },
26
+ });
27
+ export { style };
@@ -0,0 +1,20 @@
1
+ import { FC, ReactNode } from "react";
2
+ import { StyleProp, ViewStyle } from "react-native";
3
+ interface SliderProps {
4
+ readonly children: ReactNode[];
5
+ readonly active?: number;
6
+ readonly loop?: boolean;
7
+ readonly minDistanceToCapture?: number;
8
+ readonly minDistanceForAction?: number;
9
+ readonly gesturesEnabled?: boolean;
10
+ readonly paginationEnabled?: boolean;
11
+ readonly paginationStyle?: StyleProp<ViewStyle>;
12
+ readonly paginationItemStyle?: StyleProp<ViewStyle>;
13
+ readonly paginationActiveItemStyle?: StyleProp<ViewStyle>;
14
+ readonly onSliderStart?: () => void;
15
+ readonly onSliderEnd?: () => void;
16
+ readonly onChanged?: (index: number) => void;
17
+ readonly paginationRenderItem?: (index: number) => JSX.Element;
18
+ }
19
+ declare const Slider: FC<SliderProps>;
20
+ export { Slider };
@@ -0,0 +1,140 @@
1
+ import React, { useCallback, useEffect, useRef, useState } from "react";
2
+ import { Animated, I18nManager, PanResponder, StyleSheet, View, } from "react-native";
3
+ import { Pagination } from "./Pagination";
4
+ import { style } from "./Slider.style";
5
+ const DEFAULT_WIDTH = 200;
6
+ const Slider = ({ children, active = 0, loop = false, minDistanceToCapture = 5, minDistanceForAction = 0.2, gesturesEnabled = true, paginationEnabled = true, paginationStyle, paginationItemStyle, paginationActiveItemStyle, onSliderStart, onSliderEnd, onChanged, paginationRenderItem, }) => {
7
+ const flatennedChildren = children.flat();
8
+ const count = flatennedChildren.length;
9
+ const [width, setWidth] = useState(0);
10
+ const widthRef = useRef(width);
11
+ const activeIndex = useRef(active);
12
+ const animatedValueX = useRef(0);
13
+ const animatedValueY = useRef(0);
14
+ const pan = useRef(new Animated.ValueXY()).current;
15
+ const started = useRef(false);
16
+ const panResponder = useRef(PanResponder.create({
17
+ onPanResponderTerminationRequest: () => false,
18
+ onMoveShouldSetPanResponder: () => gesturesEnabled,
19
+ // eslint-disable-next-line @typescript-eslint/naming-convention
20
+ onMoveShouldSetPanResponderCapture: (_e, gestureState) => {
21
+ if (!gesturesEnabled) {
22
+ return false;
23
+ }
24
+ startAnimation();
25
+ const allow = Math.abs(gestureState.dx) > minDistanceToCapture;
26
+ return allow;
27
+ },
28
+ onPanResponderGrant: () => fixState(),
29
+ onPanResponderMove: Animated.event([null, { dx: pan.x }], {
30
+ useNativeDriver: false,
31
+ }),
32
+ // eslint-disable-next-line @typescript-eslint/naming-convention
33
+ onPanResponderRelease: (_e, gesture) => {
34
+ const correction = gesture.moveX - gesture.x0;
35
+ if (Math.abs(correction) < widthRef.current * minDistanceForAction) {
36
+ spring({ x: 0, y: 0 });
37
+ }
38
+ else {
39
+ changeIndex(correction > 0 ? (I18nManager.isRTL ? 1 : -1) : I18nManager.isRTL ? -1 : 1);
40
+ }
41
+ },
42
+ onPanResponderEnd: () => endAnimation(),
43
+ })).current;
44
+ const startAnimation = useCallback(() => {
45
+ if (!started.current) {
46
+ onSliderStart?.();
47
+ started.current = true;
48
+ }
49
+ }, [onSliderStart]);
50
+ const endAnimation = useCallback(() => {
51
+ if (started.current) {
52
+ onSliderEnd?.();
53
+ started.current = false;
54
+ }
55
+ }, [onSliderEnd]);
56
+ const fixState = useCallback(() => {
57
+ animatedValueX.current = widthRef.current * activeIndex.current * (I18nManager.isRTL ? 1 : -1);
58
+ animatedValueY.current = 0;
59
+ pan.setOffset({
60
+ x: animatedValueX.current,
61
+ y: animatedValueY.current,
62
+ });
63
+ pan.setValue({ x: 0, y: 0 });
64
+ }, [pan]);
65
+ const spring = useCallback((toValue) => {
66
+ Animated.spring(pan, {
67
+ toValue,
68
+ useNativeDriver: false,
69
+ }).start();
70
+ }, [pan]);
71
+ const changeIndex = useCallback((delta = 1) => {
72
+ const toValue = { x: 0, y: 0 };
73
+ let skipChanges = !delta;
74
+ let calcDelta = delta;
75
+ if (activeIndex.current <= 0 && delta < 0) {
76
+ skipChanges = !loop;
77
+ calcDelta = count + delta;
78
+ }
79
+ else if (activeIndex.current + 1 >= count && delta > 0) {
80
+ skipChanges = !loop;
81
+ calcDelta = -1 * activeIndex.current + delta - 1;
82
+ }
83
+ if (skipChanges) {
84
+ return spring(toValue);
85
+ }
86
+ const index = activeIndex.current + calcDelta;
87
+ activeIndex.current = index;
88
+ toValue.x = widthRef.current * (I18nManager.isRTL ? 1 : -1) * calcDelta;
89
+ spring(toValue);
90
+ onChanged?.(index);
91
+ }, [count, loop, onChanged, spring]);
92
+ const fixAndGo = useCallback((delta) => {
93
+ fixState();
94
+ startAnimation();
95
+ changeIndex(delta);
96
+ }, [changeIndex, fixState, startAnimation]);
97
+ const goTo = useCallback((index = 0) => {
98
+ const delta = index - activeIndex.current;
99
+ if (delta) {
100
+ fixAndGo(delta);
101
+ }
102
+ }, [fixAndGo]);
103
+ const getActiveIndex = useCallback(() => activeIndex.current, []);
104
+ useEffect(() => {
105
+ pan.x.addListener(({ value }) => (animatedValueX.current = value));
106
+ pan.y.addListener(({ value }) => (animatedValueY.current = value));
107
+ return () => {
108
+ pan.x.removeAllListeners();
109
+ pan.y.removeAllListeners();
110
+ };
111
+ }, [pan.x, pan.y]);
112
+ useEffect(() => {
113
+ if (activeIndex.current !== active) {
114
+ goTo(active);
115
+ }
116
+ }, [active, goTo]);
117
+ const onLayoutWrapper = useCallback(({ nativeEvent: { layout: { width: wrapperWidth }, }, }) => {
118
+ const width = wrapperWidth || DEFAULT_WIDTH;
119
+ setWidth(width);
120
+ widthRef.current = width;
121
+ fixState();
122
+ }, [fixState]);
123
+ return (React.createElement(View, { onLayout: onLayoutWrapper, testID: "slider" },
124
+ React.createElement(View, { style: StyleSheet.flatten([
125
+ {
126
+ width,
127
+ },
128
+ style.container,
129
+ ]) },
130
+ React.createElement(Animated.View, { style: StyleSheet.flatten([
131
+ {
132
+ width: width * count,
133
+ transform: [{ translateX: pan.x }, { translateY: pan.y }],
134
+ },
135
+ style.sliderAreaStyle,
136
+ ]), ...panResponder.panHandlers }, flatennedChildren.map((child, index) => (React.createElement(View, { key: index, style: { width } },
137
+ React.createElement(View, { testID: "slider-child" }, child))))),
138
+ paginationEnabled && (React.createElement(Pagination, { count: count, activeIndex: getActiveIndex(), onChange: (index) => goTo(index), paginationStyle: paginationStyle, paginationItemStyle: paginationItemStyle, paginationActiveItemStyle: paginationActiveItemStyle, renderItem: paginationRenderItem })))));
139
+ };
140
+ export { Slider };
@@ -0,0 +1,9 @@
1
+ declare const style: {
2
+ container: {
3
+ overflow: "hidden";
4
+ };
5
+ sliderAreaStyle: {
6
+ flexDirection: "row";
7
+ };
8
+ };
9
+ export { style };
@@ -0,0 +1,10 @@
1
+ import { StyleSheet } from "react-native";
2
+ const style = StyleSheet.create({
3
+ container: {
4
+ overflow: "hidden",
5
+ },
6
+ sliderAreaStyle: {
7
+ flexDirection: "row",
8
+ },
9
+ });
10
+ export { style };
@@ -0,0 +1,7 @@
1
+ interface CdnImageUrlParameters {
2
+ url: string;
3
+ width: number;
4
+ dpi?: number;
5
+ }
6
+ declare const useMediaImage: () => ({ url, width, dpi }: CdnImageUrlParameters) => string;
7
+ export { useMediaImage };
@@ -0,0 +1,12 @@
1
+ import { useCallback } from "react";
2
+ import { PixelRatio } from "react-native";
3
+ const DEFAULT_DPI = 1;
4
+ const HIGHDPI = 2;
5
+ const useMediaImage = () => {
6
+ const cdnImageUrl = useCallback(({ url, width, dpi = PixelRatio.get() }) => {
7
+ const imageDpi = dpi > DEFAULT_DPI ? HIGHDPI : DEFAULT_DPI;
8
+ return `${url}?w=${Math.ceil(width * imageDpi)}&f=auto`;
9
+ }, []);
10
+ return cdnImageUrl;
11
+ };
12
+ export { useMediaImage };
@@ -0,0 +1,7 @@
1
+ import { FC } from "react";
2
+ import { MediaProjection } from "../../../../../../projection/checkout/viewFirstAvailableCheckoutByCustomerId";
3
+ interface ProductVariantSlider {
4
+ readonly producVariantMedia: MediaProjection[];
5
+ }
6
+ declare const ProductVariantSlider: FC<ProductVariantSlider>;
7
+ export { ProductVariantSlider };
@@ -0,0 +1,22 @@
1
+ import React, { useCallback, useState } from "react";
2
+ import { Image } from "react-native";
3
+ import { Slider } from "../../../../components/layouts/slider/Slider";
4
+ import { useMediaImage } from "../../../../hooks/useMediaImage";
5
+ import { style } from "./ProductVariantSlider.style";
6
+ const ProductVariantSlider = ({ producVariantMedia }) => {
7
+ const cdnImageUrl = useMediaImage();
8
+ const [active, setActive] = useState(0);
9
+ const handleOnActiveChanged = useCallback((activeIndex) => setActive(activeIndex), []);
10
+ return (React.createElement(Slider, { active: active, onChanged: handleOnActiveChanged, paginationStyle: style.paginationStyle, paginationItemStyle: style.paginationItemStyle, paginationActiveItemStyle: style.paginationActiveItemStyle, paginationRenderItem: (index) => (React.createElement(Image, { key: producVariantMedia[index]?.perspective, style: style.paginationImage, resizeMode: "contain", source: {
11
+ uri: cdnImageUrl({
12
+ url: producVariantMedia[index]?.url,
13
+ width: 80,
14
+ }),
15
+ }, testID: "product-variant-pagination-image" })) }, producVariantMedia.map((media) => (React.createElement(Image, { key: media.perspective, style: style.image, source: {
16
+ uri: cdnImageUrl({
17
+ url: media.url,
18
+ width: 200,
19
+ }),
20
+ }, testID: "product-variant-image" })))));
21
+ };
22
+ export { ProductVariantSlider };
@@ -0,0 +1,26 @@
1
+ declare const style: {
2
+ image: {
3
+ aspectRatio: number;
4
+ flex: number;
5
+ };
6
+ paginationImage: {
7
+ flex: number;
8
+ };
9
+ paginationStyle: {
10
+ bottom: number;
11
+ marginTop: number;
12
+ position: "relative";
13
+ };
14
+ paginationItemStyle: {
15
+ backgroundColor: string;
16
+ borderColor: string;
17
+ borderRadius: number;
18
+ borderWidth: number;
19
+ height: number;
20
+ width: number;
21
+ };
22
+ paginationActiveItemStyle: {
23
+ borderColor: string;
24
+ };
25
+ };
26
+ export { style };
@@ -0,0 +1,30 @@
1
+ import { StyleSheet } from "react-native";
2
+ import { theme } from "../../../../theme/theme";
3
+ const { colorBase, colorGrayscaleL, colorContent, spaceM } = theme();
4
+ const PAGINATION_SIZE = 37;
5
+ const style = StyleSheet.create({
6
+ image: {
7
+ aspectRatio: 0.75,
8
+ flex: 1,
9
+ },
10
+ paginationImage: {
11
+ flex: 1,
12
+ },
13
+ paginationStyle: {
14
+ bottom: 0,
15
+ marginTop: spaceM,
16
+ position: "relative",
17
+ },
18
+ paginationItemStyle: {
19
+ backgroundColor: colorBase,
20
+ borderColor: colorGrayscaleL,
21
+ borderRadius: 0,
22
+ borderWidth: 1,
23
+ height: PAGINATION_SIZE,
24
+ width: PAGINATION_SIZE,
25
+ },
26
+ paginationActiveItemStyle: {
27
+ borderColor: colorContent,
28
+ },
29
+ });
30
+ export { style };
@@ -101,4 +101,4 @@ interface ViewFirstAvailableCheckoutByCustomerIdHandlerFunctionArgs extends Quer
101
101
  readonly view: FirstAvailableCheckoutByCustomerIdView;
102
102
  }
103
103
  declare const viewFirstAvailableCheckoutByCustomerIdHandler: QueryHandlerFunction<ViewFirstAvailableCheckoutByCustomerId, ViewFirstAvailableCheckoutByCustomerIdResult, ViewFirstAvailableCheckoutByCustomerIdHandlerFunctionArgs>;
104
- export { CheckoutProjection, CheckoutStatus, CheckoutItemProjection, CheckoutItemStatus, MediaPerspective, Currency, VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, viewFirstAvailableCheckoutByCustomerId, FirstAvailableCheckoutByCustomerIdView, viewFirstAvailableCheckoutByCustomerIdHandler, };
104
+ export { CheckoutProjection, CheckoutStatus, CheckoutItemProjection, CheckoutItemStatus, MediaPerspective, MediaProjection, Currency, VIEW_FIRST_AVAILABLE_CHECKOUT_BY_CUSTOMER_ID, viewFirstAvailableCheckoutByCustomerId, FirstAvailableCheckoutByCustomerIdView, viewFirstAvailableCheckoutByCustomerIdHandler, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lookiero/checkout",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [