Skip to content

Commit

Permalink
📝 Add docs + ♻️ Rework component
Browse files Browse the repository at this point in the history
  • Loading branch information
mcayuelas-ledger committed Sep 16, 2022
1 parent a21af77 commit b0a7e35
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 36 deletions.
6 changes: 6 additions & 0 deletions .changeset/tiny-plants-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@ledgerhq/native-ui": patch
"@ledgerhq/react-ui": patch
---

Improvements for the crypto icons library
36 changes: 18 additions & 18 deletions libs/ui/packages/native/src/components/Icon/CryptoIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,15 @@ export type Props = {
circleIcon?: boolean;
disabled?: boolean;
tokenIcon?: string;
fallbackIcon?: React.ReactNode;
fallbackIcon?: JSX.Element;
};

type IconBoxProps = {
children: JSX.Element;
} & Props;

type FallbackProps = {
name: string;
};

export const iconNames = Array.from(
Expand Down Expand Up @@ -59,11 +67,15 @@ const TokenContainer = styled(Flex).attrs(
}),
)<{ size: number }>``;

type IconBoxProps = {
children: JSX.Element;
} & Props;
function Fallback({ name }: FallbackProps) {
return (
<Text uppercase color="neutral.c70">
{name.slice(0, 1)}
</Text>
);
}

export const IconBox = ({
const IconBox = ({
children,
color,
backgroundColor,
Expand Down Expand Up @@ -96,18 +108,6 @@ export const IconBox = ({
return children;
};

type FallbackProps = {
name: string;
};

function Fallback({ name }: FallbackProps) {
return (
<Text uppercase color="neutral.c70">
{name.slice(0, 1)}
</Text>
);
}

const CryptoIcon = ({
name,
size = 16,
Expand Down Expand Up @@ -140,7 +140,7 @@ const CryptoIcon = ({
);
}
if (fallbackIcon) {
return <>{fallbackIcon}</>;
return fallbackIcon;
}
return <Fallback name={name} />;
};
Expand Down
37 changes: 19 additions & 18 deletions libs/ui/packages/react/src/components/asorted/Icon/CryptoIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ export type Props = {
circleIcon?: boolean;
disabled?: boolean;
tokenIcon?: string;
fallbackIcon?: React.ReactNode;
fallbackIcon?: JSX.Element;
};

type IconBoxProps = {
children: JSX.Element;
} & Props;

type FallbackProps = {
name: string;
};

export const iconNames = Array.from(
Expand Down Expand Up @@ -57,11 +65,16 @@ const TokenContainer = styled(Flex).attrs(
zIndex: 0,
}),
)<{ size: number }>``;
type IconBoxProps = {
children: JSX.Element;
} & Props;

export const IconBox = ({
function Fallback({ name }: FallbackProps) {
return (
<Text uppercase color="neutral.c70">
{name.slice(0, 1)}
</Text>
);
}

const IconBox = ({
children,
color,
backgroundColor,
Expand Down Expand Up @@ -94,18 +107,6 @@ export const IconBox = ({
return children;
};

type FallbackProps = {
name: string;
};

function Fallback({ name }: FallbackProps) {
return (
<Text uppercase color="neutral.c70">
{name.slice(0, 1)}
</Text>
);
}

const CryptoIcon = ({
name,
size = 16,
Expand Down Expand Up @@ -138,7 +139,7 @@ const CryptoIcon = ({
);
}
if (fallbackIcon) {
return <>{fallbackIcon}</>;
return fallbackIcon;
}
return <Fallback name={name} />;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@ import styled from "styled-components";
import { Text, SearchInput, Flex, Grid, CryptoIcon } from "../../..";
import * as cryptoIcons from "@ledgerhq/crypto-icons-ui/react";

const description = `
### A customizable crypto-icon component.
### Props
\`\`\`tsx
type Props = {
name: string;
size?: number;
color?: string;
backgroundColor?: string; // overrides background color to ensure contrast with icon color
circleIcon?: boolean; // if icon is in a circle or not
tokenIcon?: string; // ref to the token icon to show as a sub icon
disabled?: boolean;
fallback?: JSX.Element; // fallback element if no icon found - defaults to an icon with first letter of icon name
};
\`\`\`
`;

type CryptoIconsProps = {
name: keyof typeof cryptoIcons;
size?: number;
Expand Down Expand Up @@ -82,6 +101,13 @@ const Story = {
defaultValue: "",
},
},
parameters: {
docs: {
description: {
component: description,
},
},
},
};
export default Story;

Expand Down

0 comments on commit b0a7e35

Please sign in to comment.