@ledgerhq/native-ui 0.8.1 → 0.8.2-next.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.
|
@@ -61,7 +61,15 @@ export declare type Props = React.PropsWithChildren<{
|
|
|
61
61
|
* Number of milliseconds a tap should not exceed to scroll to the netxt or precedent item.
|
|
62
62
|
*/
|
|
63
63
|
maxDurationOfTap?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Called when the active carousel index is updated automaticly.
|
|
66
|
+
*/
|
|
67
|
+
onAutoChange?: (index: number) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Called when the active carousel index is updated manually.
|
|
70
|
+
*/
|
|
71
|
+
onManualChange?: (index: number) => void;
|
|
64
72
|
}>;
|
|
65
|
-
declare function Carousel({ activeIndex, autoDelay, restartAfterEnd, scrollOnSidePress, containerProps, slideIndicatorContainerProps, scrollViewProps, onChange, onOverflow, IndicatorComponent, maxDurationOfTap, children, }: Props): JSX.Element;
|
|
73
|
+
declare function Carousel({ activeIndex, autoDelay, restartAfterEnd, scrollOnSidePress, containerProps, slideIndicatorContainerProps, scrollViewProps, onChange, onOverflow, IndicatorComponent, maxDurationOfTap, children, onAutoChange, onManualChange, }: Props): JSX.Element;
|
|
66
74
|
declare const _default: React.MemoExoticComponent<typeof Carousel>;
|
|
67
75
|
export default _default;
|
|
@@ -5,7 +5,7 @@ import { Flex, SlideIndicator } from "../index";
|
|
|
5
5
|
const HorizontalScrollView = styled.ScrollView.attrs({ horizontal: true }) `
|
|
6
6
|
flex: 1;
|
|
7
7
|
`;
|
|
8
|
-
function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOnSidePress = false, containerProps, slideIndicatorContainerProps, scrollViewProps, onChange, onOverflow, IndicatorComponent = SlideIndicator, maxDurationOfTap, children, }) {
|
|
8
|
+
function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOnSidePress = false, containerProps, slideIndicatorContainerProps, scrollViewProps, onChange, onOverflow, IndicatorComponent = SlideIndicator, maxDurationOfTap, children, onAutoChange, onManualChange, }) {
|
|
9
9
|
const [init, setInit] = useState(false);
|
|
10
10
|
const [activeIndexState, setActiveIndexState] = useState(activeIndex);
|
|
11
11
|
const disableTimer = useRef(false);
|
|
@@ -45,6 +45,7 @@ function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOn
|
|
|
45
45
|
if (tapPositionXPercent > 0.25) {
|
|
46
46
|
if (slidesLength > activeIndexState + 1) {
|
|
47
47
|
scrollToIndex(activeIndexState + 1, false);
|
|
48
|
+
onManualChange && onManualChange(activeIndexState + 1);
|
|
48
49
|
}
|
|
49
50
|
else {
|
|
50
51
|
onOverflow && onOverflow("end", false);
|
|
@@ -52,11 +53,12 @@ function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOn
|
|
|
52
53
|
}
|
|
53
54
|
else if (activeIndexState > 0) {
|
|
54
55
|
scrollToIndex(activeIndexState - 1, false);
|
|
56
|
+
onManualChange && onManualChange(activeIndexState - 1);
|
|
55
57
|
}
|
|
56
58
|
else {
|
|
57
59
|
onOverflow && onOverflow("start", false);
|
|
58
60
|
}
|
|
59
|
-
}, [slidesLength, activeIndexState, scrollToIndex, onOverflow, itemWidth]);
|
|
61
|
+
}, [slidesLength, activeIndexState, scrollToIndex, onOverflow, itemWidth, onManualChange]);
|
|
60
62
|
const onScroll = ({ nativeEvent: { contentOffset, contentSize }, }) => {
|
|
61
63
|
const newIndex = Math.abs(Math.round((contentOffset.x / contentSize.width) * slidesLength));
|
|
62
64
|
setActiveIndexState(newIndex);
|
|
@@ -68,6 +70,7 @@ function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOn
|
|
|
68
70
|
const interval = setTimeout(() => {
|
|
69
71
|
if (!disableTimer.current) {
|
|
70
72
|
const newIndex = typeof activeIndexState !== "undefined" ? (activeIndexState + 1) % slidesLength : 0;
|
|
73
|
+
onAutoChange && onAutoChange(newIndex);
|
|
71
74
|
if (restartAfterEnd || newIndex !== 0) {
|
|
72
75
|
scrollToIndex(newIndex);
|
|
73
76
|
}
|
|
@@ -88,6 +91,7 @@ function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOn
|
|
|
88
91
|
activeIndexState,
|
|
89
92
|
onOverflow,
|
|
90
93
|
restartAfterEnd,
|
|
94
|
+
onAutoChange,
|
|
91
95
|
]);
|
|
92
96
|
// Timestamp of start of click on the Carrousel
|
|
93
97
|
const [tapTime, setTapTime] = useState(0);
|
|
@@ -109,6 +113,7 @@ function Carousel({ activeIndex = 0, autoDelay, restartAfterEnd = true, scrollOn
|
|
|
109
113
|
React.createElement(Flex, Object.assign({ my: 8 }, slideIndicatorContainerProps), React.isValidElement(IndicatorComponent) ? (IndicatorComponent) : (React.createElement(IndicatorComponent, { activeIndex: activeIndexState || 0, onChange: (index) => {
|
|
110
114
|
scrollToIndex(index);
|
|
111
115
|
setResetTimer({});
|
|
116
|
+
onManualChange && onManualChange(index);
|
|
112
117
|
}, slidesLength: slidesLength, duration: autoDelay })))));
|
|
113
118
|
}
|
|
114
119
|
export default React.memo(Carousel);
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { TextProps, TouchableOpacityProps } from "react-native";
|
|
3
|
+
declare type NotificationVariant = "primary" | "secondary" | "success" | "warning" | "error" | string;
|
|
3
4
|
declare type Props = {
|
|
4
5
|
Icon?: React.ComponentType<{
|
|
5
6
|
size: number;
|
|
6
7
|
color?: string;
|
|
7
8
|
}>;
|
|
8
9
|
iconColor?: string;
|
|
9
|
-
variant?:
|
|
10
|
+
variant?: NotificationVariant;
|
|
10
11
|
title: string;
|
|
11
12
|
subtitle?: string;
|
|
12
13
|
numberOfLines?: TextProps["numberOfLines"];
|
|
@@ -7,18 +7,50 @@ import CloseMedium from "@ledgerhq/icons-ui/native/CloseMedium";
|
|
|
7
7
|
import { Flex } from "../../Layout";
|
|
8
8
|
import { space } from "styled-system";
|
|
9
9
|
import { ExternalLinkMedium } from "@ledgerhq/icons-ui/native";
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
const variantProps = {
|
|
11
|
+
primary: {
|
|
12
|
+
bg: "primary.c90",
|
|
13
|
+
color: "neutral.c00",
|
|
14
|
+
padding: 6,
|
|
15
|
+
},
|
|
16
|
+
success: {
|
|
17
|
+
bg: "success.c100",
|
|
18
|
+
color: "neutral.c00",
|
|
19
|
+
padding: 6,
|
|
20
|
+
},
|
|
21
|
+
warning: {
|
|
22
|
+
bg: "warning.c100",
|
|
23
|
+
color: "neutral.c00",
|
|
24
|
+
padding: 6,
|
|
25
|
+
},
|
|
26
|
+
error: {
|
|
27
|
+
bg: "error.c100",
|
|
28
|
+
color: "neutral.c00",
|
|
29
|
+
padding: 6,
|
|
30
|
+
},
|
|
31
|
+
neutral: {
|
|
32
|
+
bg: "neutral.c30",
|
|
33
|
+
color: "neutral.c100",
|
|
34
|
+
linkColor: "primary.c80",
|
|
35
|
+
padding: 6,
|
|
36
|
+
},
|
|
37
|
+
secondary: {
|
|
38
|
+
bg: "transparent",
|
|
39
|
+
color: "neutral.c100",
|
|
40
|
+
padding: 0,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const NotificationContainer = styled(FlexBox).attrs((p) => {
|
|
44
|
+
var _a, _b, _c;
|
|
45
|
+
return ({
|
|
46
|
+
width: "100%",
|
|
47
|
+
flexDirection: "row",
|
|
48
|
+
alignItems: "center",
|
|
49
|
+
bg: (_b = (_a = variantProps[p.variant]) === null || _a === void 0 ? void 0 : _a.bg) !== null && _b !== void 0 ? _b : variantProps.primary.bg,
|
|
50
|
+
p: (_c = variantProps[p.variant]) === null || _c === void 0 ? void 0 : _c.padding,
|
|
51
|
+
borderRadius: 1,
|
|
52
|
+
});
|
|
53
|
+
}) ``;
|
|
22
54
|
const ClosePressableExtendedBounds = styled.TouchableOpacity.attrs({
|
|
23
55
|
p: 5,
|
|
24
56
|
m: -5,
|
|
@@ -26,8 +58,10 @@ const ClosePressableExtendedBounds = styled.TouchableOpacity.attrs({
|
|
|
26
58
|
${space};
|
|
27
59
|
`;
|
|
28
60
|
export default function Notification({ Icon, iconColor, variant = "primary", numberOfLines, title, subtitle, onClose, linkText, onLinkPress, }) {
|
|
61
|
+
var _a, _b, _c;
|
|
29
62
|
const { colors } = useTheme();
|
|
30
|
-
const textColor = variant ===
|
|
63
|
+
const textColor = (_b = (_a = variantProps[variant]) === null || _a === void 0 ? void 0 : _a.color) !== null && _b !== void 0 ? _b : variantProps.primary.color;
|
|
64
|
+
const linkColor = ((_c = variantProps[variant]) === null || _c === void 0 ? void 0 : _c.linkColor) || textColor;
|
|
31
65
|
return (React.createElement(NotificationContainer, { variant: variant },
|
|
32
66
|
Icon && (React.createElement(FlexBox, { mr: 16 },
|
|
33
67
|
React.createElement(Icon, { size: 20, color: iconColor || textColor }))),
|
|
@@ -37,8 +71,8 @@ export default function Notification({ Icon, iconColor, variant = "primary", num
|
|
|
37
71
|
linkText && onLinkPress && (React.createElement(Flex, { mt: 3 },
|
|
38
72
|
React.createElement(TouchableOpacity, { onPress: onLinkPress },
|
|
39
73
|
React.createElement(Flex, { flexDirection: "row", alignItems: "center" },
|
|
40
|
-
React.createElement(Text, { variant: "body", fontWeight: "semiBold", color:
|
|
41
|
-
React.createElement(ExternalLinkMedium, { size: 16, color:
|
|
74
|
+
React.createElement(Text, { variant: "body", fontWeight: "semiBold", color: linkColor, mr: 3 }, linkText),
|
|
75
|
+
React.createElement(ExternalLinkMedium, { size: 16, color: linkColor })))))),
|
|
42
76
|
onClose && (React.createElement(FlexBox, { marginLeft: "auto", pl: 16 },
|
|
43
77
|
React.createElement(ClosePressableExtendedBounds, { onPress: onClose },
|
|
44
78
|
React.createElement(CloseMedium, { size: 14, color: textColor }))))));
|
package/package.json
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ledgerhq/native-ui",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.2-next.0",
|
|
4
4
|
"description": "Ledger Live - Mobile UI",
|
|
5
|
-
"repository":
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/LedgerHQ/ledger-live.git"
|
|
8
|
+
},
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://github.com/LedgerHQ/ledger-live/issues"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/LedgerHQ/ledger-live/tree/develop/libs/ui/packages/native",
|
|
6
13
|
"license": "MIT",
|
|
7
14
|
"author": "Ledger Live Team <team-live@ledger.fr>",
|
|
8
15
|
"main": "lib/index.js",
|
|
@@ -25,7 +32,7 @@
|
|
|
25
32
|
"lib/**/*"
|
|
26
33
|
],
|
|
27
34
|
"dependencies": {
|
|
28
|
-
"@ledgerhq/icons-ui": "^0.2.
|
|
35
|
+
"@ledgerhq/icons-ui": "^0.2.7-next.0",
|
|
29
36
|
"@ledgerhq/ui-shared": "^0.1.9",
|
|
30
37
|
"@types/color": "^3.0.3",
|
|
31
38
|
"@types/react": "^17.0.39",
|