@ledgerhq/native-ui 0.10.0 → 0.11.0-nightly.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.
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { Props as FlexProps } from "../../Flex";
3
+ import { ItemStatus } from ".";
4
+ export declare type Props = FlexProps & {
5
+ status: ItemStatus;
6
+ isFirstItem?: boolean;
7
+ isLastItem?: boolean;
8
+ };
9
+ export default function TimelineIndicator({ status, isFirstItem, isLastItem, ...props }: Props): JSX.Element;
@@ -0,0 +1,67 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React from "react";
13
+ import { CircledCheckSolidMedium } from "@ledgerhq/icons-ui/native";
14
+ import styled, { useTheme } from "styled-components/native";
15
+ import Flex from "../../Flex";
16
+ const TopSegment = styled(Flex) `
17
+ height: 20px;
18
+ border-width: ${(p) => (p.hidden ? 0 : 1)}px;
19
+ border-style: solid;
20
+ border-color: ${(p) => p.status === "inactive" ? p.theme.colors.neutral.c50 : p.theme.colors.primary.c80};
21
+ background: ${(p) => p.status === "inactive" ? p.theme.colors.neutral.c50 : p.theme.colors.primary.c80};
22
+ `;
23
+ const BottomSegment = styled(Flex) `
24
+ flex: 1;
25
+ border-width: ${(p) => (p.hidden ? 0 : 1)}px;
26
+ border-style: solid;
27
+ border-color: ${(p) => p.status === "completed" ? p.theme.colors.primary.c80 : p.theme.colors.neutral.c50};
28
+ background: ${(p) => p.status === "completed" ? p.theme.colors.primary.c80 : p.theme.colors.neutral.c50};
29
+ `;
30
+ const getIconBackground = (theme, status, isLastItem) => {
31
+ if (status === "completed") {
32
+ return "transparent";
33
+ }
34
+ else if (isLastItem) {
35
+ return theme.colors.success.c10;
36
+ }
37
+ else if (status === "active") {
38
+ return theme.colors.neutral.c40;
39
+ }
40
+ return theme.colors.background.main;
41
+ };
42
+ const getIconBorder = (theme, status, isLastItem) => {
43
+ if (isLastItem) {
44
+ return theme.colors.success.c100;
45
+ }
46
+ else if (status === "inactive") {
47
+ return theme.colors.neutral.c50;
48
+ }
49
+ return theme.colors.primary.c80;
50
+ };
51
+ const CenterSegment = styled(Flex) `
52
+ border-radius: 9999px;
53
+ width: 20px;
54
+ height: 20px;
55
+ background: ${(p) => getIconBackground(p.theme, p.status, p.isLastItem)};
56
+ border: 2px solid ${(p) => getIconBorder(p.theme, p.status, p.isLastItem)};
57
+ align-items: center;
58
+ justify-content: center;
59
+ `;
60
+ export default function TimelineIndicator(_a) {
61
+ var { status, isFirstItem, isLastItem } = _a, props = __rest(_a, ["status", "isFirstItem", "isLastItem"]);
62
+ const { colors } = useTheme();
63
+ return (React.createElement(Flex, Object.assign({ flexDirection: "column", alignItems: "center" }, props),
64
+ React.createElement(TopSegment, { status: status, hidden: isFirstItem }),
65
+ React.createElement(CenterSegment, { status: status, isLastItem: isLastItem }, status === "completed" && (React.createElement(CircledCheckSolidMedium, { color: isLastItem ? colors.success.c100 : colors.primary.c80, size: 24 }))),
66
+ React.createElement(BottomSegment, { status: status, hidden: isLastItem })));
67
+ }
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ import { Item } from ".";
3
+ export declare type Props = {
4
+ item: Item;
5
+ formatEstimatedTime?: (_: number) => string;
6
+ isFirstItem?: boolean;
7
+ isLastItem?: boolean;
8
+ setActiveIndex?: (_: number) => void;
9
+ index: number;
10
+ };
11
+ export default function TimelineItem({ item, formatEstimatedTime, isFirstItem, isLastItem, setActiveIndex, index, }: Props): JSX.Element;
@@ -0,0 +1,83 @@
1
+ import React, { useCallback } from "react";
2
+ import { Pressable } from "react-native";
3
+ import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
4
+ import styled from "styled-components/native";
5
+ import { Flex } from "../..";
6
+ import { Text, Tag } from "../../..";
7
+ import TimelineIndicator from "./TimelineIndicator";
8
+ const getContainerBackground = (theme, status, isLastItem) => {
9
+ if (isLastItem && status === "completed") {
10
+ return theme.colors.success.c30;
11
+ }
12
+ else if (status === "completed") {
13
+ return theme.colors.primary.c20;
14
+ }
15
+ else if (status === "active") {
16
+ return theme.colors.neutral.c20;
17
+ }
18
+ return theme.colors.neutral.c30;
19
+ };
20
+ const getContainerBorder = (theme, status, isLastItem) => {
21
+ if (isLastItem && status === "completed") {
22
+ return theme.colors.success.c30;
23
+ }
24
+ else if (isLastItem && status === "active") {
25
+ return theme.colors.success.c100;
26
+ }
27
+ else if (status === "completed") {
28
+ return theme.colors.primary.c20;
29
+ }
30
+ else if (status === "active") {
31
+ return theme.colors.primary.c80;
32
+ }
33
+ return theme.colors.neutral.c30;
34
+ };
35
+ const Container = styled(Flex) `
36
+ flex: 1;
37
+ border-radius: ${(p) => p.theme.radii[2]}px;
38
+ background: ${(p) => getContainerBackground(p.theme, p.status, p.isLastItem)};
39
+ border: 1px solid ${(p) => getContainerBorder(p.theme, p.status, p.isLastItem)};
40
+ padding: 20px 16px;
41
+ `;
42
+ export default function TimelineItem({ item, formatEstimatedTime, isFirstItem, isLastItem, setActiveIndex, index, }) {
43
+ /**
44
+ * Having an initial value of null will prevent having "height: 0" before the
45
+ * initial call of onLayout.
46
+ * The component will just layout normally without an animation which is ok
47
+ * since this will happen only on the first step.
48
+ * Without this default behavior, there are issues on iOS where sometimes the
49
+ * height is stuck at 0.
50
+ */
51
+ const sharedHeight = useSharedValue(null);
52
+ const handleLayout = useCallback(({ nativeEvent: { layout } }) => {
53
+ sharedHeight.value = withTiming(layout.height, { duration: 300 });
54
+ }, [sharedHeight]);
55
+ const animatedStyle = useAnimatedStyle(() => {
56
+ var _a;
57
+ return ({
58
+ /**
59
+ * If it's null the component still renders normally at its full height
60
+ * without its height being derived from an animated value.
61
+ */
62
+ height: (_a = sharedHeight.value) !== null && _a !== void 0 ? _a : undefined,
63
+ });
64
+ }, []);
65
+ const handlePress = useCallback(() => {
66
+ setActiveIndex && setActiveIndex(index);
67
+ }, [setActiveIndex, index]);
68
+ return (React.createElement(Pressable, { onPress: handlePress },
69
+ React.createElement(Flex, { flexDirection: "row" },
70
+ React.createElement(TimelineIndicator, { status: item.status, isFirstItem: isFirstItem, isLastItem: isLastItem, mr: 4 }),
71
+ React.createElement(Container, { status: item.status, isLastItem: isLastItem, mb: 4 },
72
+ React.createElement(Flex, { flexDirection: "row", justifyContent: "space-between" },
73
+ React.createElement(Text, { variant: "body", color: item.status === "inactive"
74
+ ? "neutral.c80"
75
+ : isLastItem
76
+ ? "success.c100"
77
+ : "primary.c90" }, item.title),
78
+ (item === null || item === void 0 ? void 0 : item.estimatedTime) && item.status === "active" && (React.createElement(Tag, null, formatEstimatedTime
79
+ ? formatEstimatedTime(item.estimatedTime)
80
+ : `${item.estimatedTime / 60} min`))),
81
+ React.createElement(Animated.ScrollView, { style: animatedStyle },
82
+ React.createElement(Animated.View, { onLayout: handleLayout }, item.renderBody && item.status === "active" ? (React.createElement(Flex, { pt: 6 }, item.renderBody(true))) : null))))));
83
+ }
@@ -0,0 +1,23 @@
1
+ import { ReactNode } from "react";
2
+ import { BaseStyledProps } from "src/components/styled";
3
+ export declare enum ItemStatus {
4
+ inactive = "inactive",
5
+ active = "active",
6
+ completed = "completed"
7
+ }
8
+ export declare type Item = {
9
+ status: ItemStatus;
10
+ title: string;
11
+ estimatedTime?: number;
12
+ renderBody?: (isDisplayed?: boolean) => ReactNode;
13
+ };
14
+ export declare type Props = BaseStyledProps & {
15
+ steps?: Item[];
16
+ formatEstimatedTime?: (_: number) => string;
17
+ setActiveIndex?: (arg0: number) => void;
18
+ };
19
+ declare function VerticalTimeline({ steps, formatEstimatedTime, setActiveIndex, ...props }: Props): JSX.Element;
20
+ declare namespace VerticalTimeline {
21
+ var ItemStatus: typeof import(".").ItemStatus;
22
+ }
23
+ export default VerticalTimeline;
@@ -0,0 +1,25 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import React from "react";
13
+ import TimelineItem from "./TimelineItem";
14
+ import { Flex } from "../..";
15
+ export var ItemStatus;
16
+ (function (ItemStatus) {
17
+ ItemStatus["inactive"] = "inactive";
18
+ ItemStatus["active"] = "active";
19
+ ItemStatus["completed"] = "completed";
20
+ })(ItemStatus || (ItemStatus = {}));
21
+ export default function VerticalTimeline(_a) {
22
+ var { steps, formatEstimatedTime, setActiveIndex } = _a, props = __rest(_a, ["steps", "formatEstimatedTime", "setActiveIndex"]);
23
+ return (React.createElement(Flex, Object.assign({}, props, { flexDirection: "column" }), steps === null || steps === void 0 ? void 0 : steps.map((step, index) => (React.createElement(TimelineItem, { key: step.title, item: step, formatEstimatedTime: formatEstimatedTime, isFirstItem: index === 0, isLastItem: index === steps.length - 1, setActiveIndex: setActiveIndex, index: index })))));
24
+ }
25
+ VerticalTimeline.ItemStatus = ItemStatus;
@@ -2,3 +2,4 @@ export { default as List } from "./List";
2
2
  export { default as IconBoxList } from "./IconBoxList";
3
3
  export { default as TipList } from "./TipList";
4
4
  export { default as NumberedList } from "./NumberedList";
5
+ export { default as VerticalTimeline } from "./VerticalTimeline";
@@ -2,3 +2,4 @@ export { default as List } from "./List";
2
2
  export { default as IconBoxList } from "./IconBoxList";
3
3
  export { default as TipList } from "./TipList";
4
4
  export { default as NumberedList } from "./NumberedList";
5
+ export { default as VerticalTimeline } from "./VerticalTimeline";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/native-ui",
3
- "version": "0.10.0",
3
+ "version": "0.11.0-nightly.1",
4
4
  "description": "Ledger Live - Mobile UI",
5
5
  "repository": {
6
6
  "type": "git",