@ledgerhq/native-ui 0.9.1-nightly.0 → 0.10.0-nightly.2

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.
@@ -4,7 +4,11 @@ export declare type Props = {
4
4
  size?: number;
5
5
  color?: string;
6
6
  backgroundColor?: string;
7
+ circleIcon?: boolean;
8
+ disabled?: boolean;
9
+ tokenIcon?: string;
10
+ fallbackIcon?: JSX.Element;
7
11
  };
8
12
  export declare const iconNames: string[];
9
- declare const CryptoIcon: ({ name, size, color, backgroundColor }: Props) => JSX.Element | null;
13
+ declare const CryptoIcon: ({ name, size, color, backgroundColor, circleIcon, disabled, tokenIcon, fallbackIcon, }: Props) => JSX.Element;
10
14
  export default CryptoIcon;
@@ -1,23 +1,77 @@
1
1
  import * as icons from "@ledgerhq/crypto-icons-ui/native";
2
2
  import React from "react";
3
3
  import { ensureContrast } from "../../styles";
4
- import { useTheme } from "styled-components/native";
4
+ import styled, { useTheme } from "styled-components/native";
5
+ import Text from "../Text/index";
6
+ import Flex from "../Layout/Flex";
5
7
  export const iconNames = Array.from(Object.keys(icons).reduce((set, rawKey) => {
6
8
  const key = rawKey;
7
9
  if (!set.has(key))
8
10
  set.add(key);
9
11
  return set;
10
12
  }, new Set()));
11
- const CryptoIcon = ({ name, size = 16, color, backgroundColor }) => {
12
- const maybeIconName = `${name}`;
13
+ const Container = styled(Flex).attrs((p) => ({
14
+ heigth: p.size,
15
+ width: p.size,
16
+ alignItems: "center",
17
+ justifyContent: "center",
18
+ position: "relative",
19
+ })) ``;
20
+ const Circle = styled(Flex).attrs((p) => ({
21
+ heigth: p.size,
22
+ width: p.size,
23
+ alignItems: "center",
24
+ justifyContent: "center",
25
+ position: "relative",
26
+ borderRadius: "50%",
27
+ backgroundColor: p.backgroundColor,
28
+ })) ``;
29
+ const TokenContainer = styled(Flex).attrs((p) => ({
30
+ position: "absolute",
31
+ bottom: "-2px",
32
+ right: "-5px",
33
+ alignItems: "center",
34
+ justifyContent: "center",
35
+ heigth: p.size,
36
+ width: p.size,
37
+ borderRadius: "50%",
38
+ border: `2px solid ${p.borderColor}`,
39
+ backgroundColor: p.backgroundColor,
40
+ zIndex: 0,
41
+ })) ``;
42
+ function Fallback({ name }) {
43
+ return (React.createElement(Text, { uppercase: true, color: "neutral.c70" }, name.slice(0, 1)));
44
+ }
45
+ const IconBox = ({ children, color, backgroundColor, disabled, size = 16, tokenIcon = "", }) => {
46
+ const { colors } = useTheme();
47
+ if (tokenIcon in icons) {
48
+ // @ts-expect-error FIXME I don't know how to make you happy ts
49
+ const Component = icons[tokenIcon];
50
+ const defaultColor = Component.DefaultColor;
51
+ const iconColor = disabled ? colors.neutral.c70 : color || defaultColor;
52
+ const contrastedColor = ensureContrast(iconColor, backgroundColor || colors.background.main);
53
+ return (React.createElement(Container, { size: size },
54
+ children,
55
+ tokenIcon && (React.createElement(TokenContainer, { size: size / 3, borderColor: colors.background.main, backgroundColor: contrastedColor },
56
+ React.createElement(Component, { size: size, color: colors.background.main })))));
57
+ }
58
+ return children;
59
+ };
60
+ const CryptoIcon = ({ name, size = 16, color, backgroundColor, circleIcon, disabled, tokenIcon, fallbackIcon, }) => {
13
61
  const { colors } = useTheme();
62
+ const maybeIconName = `${name}`;
14
63
  if (maybeIconName in icons) {
15
64
  // @ts-expect-error FIXME I don't know how to make you happy ts
16
65
  const Component = icons[maybeIconName];
17
66
  const defaultColor = Component.DefaultColor;
18
- const contrastedColor = ensureContrast(color || defaultColor, backgroundColor || colors.background.main);
19
- return React.createElement(Component, { size: size, color: contrastedColor });
67
+ const iconColor = disabled ? colors.neutral.c70 : color || defaultColor;
68
+ const contrastedColor = ensureContrast(iconColor, backgroundColor || colors.background.main);
69
+ return (React.createElement(IconBox, { size: size, tokenIcon: tokenIcon, color: color, disabled: disabled, name: name }, tokenIcon || circleIcon ? (React.createElement(Circle, { backgroundColor: contrastedColor, size: size },
70
+ React.createElement(Component, { size: size, color: colors.background.main }))) : (React.createElement(Component, { size: size, color: contrastedColor }))));
71
+ }
72
+ if (fallbackIcon) {
73
+ return fallbackIcon;
20
74
  }
21
- return null;
75
+ return React.createElement(Fallback, { name: name });
22
76
  };
23
77
  export default CryptoIcon;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ledgerhq/native-ui",
3
- "version": "0.9.1-nightly.0",
3
+ "version": "0.10.0-nightly.2",
4
4
  "description": "Ledger Live - Mobile UI",
5
5
  "repository": {
6
6
  "type": "git",