Skip to content

Commit df23d88

Browse files
authored
Merge pull request #13 from make-software/refactoring-components-and-cleanup
Refactoring components and cleanup
2 parents 111547e + 85e29a8 commit df23d88

25 files changed

Lines changed: 579 additions & 191 deletions

package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@make-software/cspr-design",
3-
"version": "2.0.1",
3+
"version": "2.0.2",
44
"description": "React-based UI component library powering Casper Blockchain applications",
55
"homepage": "https://cspr.design",
66
"repository": "git://github.com/make-software/cspr-design",
@@ -37,7 +37,6 @@
3737
"downshift": "^9.0.4",
3838
"facepaint": "^1.2.1",
3939
"i18next": "^25.3.2",
40-
"prettier": "^3.6.2",
4140
"react-inlinesvg": "^4.2.0",
4241
"react-loading-skeleton": "^3.5.0",
4342
"react-modal": "^3.16.1",
@@ -95,6 +94,7 @@
9594
"@types/react-modal": "^3.16.3",
9695
"@types/styled-components": "^5.1.34",
9796
"@vitejs/plugin-react": "^4.7.0",
97+
"prettier": "^3.6.2",
9898
"babel-plugin-named-exports-order": "^0.0.2",
9999
"eslint-plugin-storybook": "^9.0.18",
100100
"remark-gfm": "^4.0.1",

src/lib/components/account-info-row/account-info-row.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default {
77
component: AccountInfoRow,
88
excludeStories: ['Primary'],
99
// tags: ['autodocs', '!dev'],
10-
title: 'Components/Display/AccountInfoRow',
10+
title: 'Components/Form/AccountInfoRow',
1111
parameters: {
1212
controls: {
1313
sort: 'requiredFirst',

src/lib/components/account-info-row/account-info-row.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export function AccountInfoRow(props: AccountInfoRowProps) {
155155
{publicKey && (
156156
<>
157157
<FlexRow align="center">
158-
<Tooltip title={publicKey}>
158+
<Tooltip tooltipContent={publicKey}>
159159
<BodyText size={3} variation={'black'} monotype>
160160
{formatHash(publicKey, responsiveHashSize)}
161161
</BodyText>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { Meta } from '@storybook/react';
2+
import { StoryObj } from '@storybook/react-vite';
3+
import { Address } from './address.tsx';
4+
5+
const meta = {
6+
component: Address,
7+
title: 'Components/Display/Address',
8+
// tags: ['autodocs', '!dev'],
9+
args: {
10+
hash: '01f5f1fa995ab7e966428e5a1aed797526ad5b2454c50a63a7aaa2dfeae6a996c2',
11+
minifiedCopyNotification: true,
12+
tooltipCaption: 'public key',
13+
avatarSize: 'default',
14+
},
15+
argTypes: {
16+
avatarSize: {
17+
control: { type: 'select' },
18+
options: ['default', 'big', 'average', 'medium', 'small'],
19+
description: 'The size of the avatar',
20+
},
21+
hash: { control: 'text' },
22+
csprName: { control: 'text' },
23+
logo: { control: 'text' },
24+
name: { control: 'text' },
25+
tooltipCaption: { control: 'text' },
26+
minifiedCopyNotification: { control: 'boolean' },
27+
},
28+
} as Meta<typeof Address>;
29+
30+
export default meta;
31+
32+
type Story = StoryObj<typeof meta>;
33+
34+
export const Primary: Story = {};
35+
36+
export const withName: Story = {
37+
args: {
38+
name: 'Faucet',
39+
csprName: 'faucet.cspr',
40+
logo: 'https://cspr-image-proxy-cdn.dev.make.services/64,fit,ttl86400/https://casper-assets.s3.amazonaws.com/accounts/faucet.svg',
41+
},
42+
};
43+
44+
export const withLogo: Story = {
45+
args: {
46+
name: 'Casper Space DJ',
47+
logo: 'https://image-proxy-cdn.make.services/64,fit,ttl86400/https://makegroup.io/wp-content/uploads/2024/04/logo.svg',
48+
},
49+
};
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
import React from 'react';
2+
import { Avatar, AvatarProps } from '../avatar/avatar';
3+
4+
import styled from 'styled-components';
5+
import BodyText from '../body-text/body-text.tsx';
6+
import Tooltip from '../tooltip/tooltip.tsx';
7+
import { HashLink } from '../hash-link/hash-link.tsx';
8+
import FlexRow from '../flex-row/flex-row.tsx';
9+
import FlexColumn from '../flex-column/flex-column.tsx';
10+
import { HashLength, shortenCsprName } from '../../utils/formatters.ts';
11+
import { Size } from '../../types.ts';
12+
import TruncateBox from '../truncate-box/truncate-box.tsx';
13+
14+
/**
15+
* Address component can be used to display a public key or hash associated with an account.
16+
* It supports various configurations, including loading state, logo, name, csprName, and tooltip.
17+
*
18+
* Properties:
19+
* @property {boolean} loading - Specifies whether the address component is in a loading state.
20+
* @property {string | null} logo - The logo associated with the address, if available.
21+
* @property {string | undefined} name - The display name of the address.
22+
* @property {string | undefined} [csprName] - The CSPR.name associated with the address, if applicable.
23+
* @property {string | null | undefined} hash - The public key or hash associated with the address.
24+
* @property {string} [tooltipCaption] - Text to be displayed in a tooltip for additional context.
25+
* @property {string} [navigateToPath] - The path to navigate to when interacting with the address.
26+
* @property {HashLength} [hashLength] - Specifies the length of the hash representation.
27+
* @property {Size} [nameTruncateSize] - Defines the size of the name text.
28+
* @property {AvatarProps['size']} [avatarSize] - The size of the avatar related to the address.
29+
* @property {HashFontSize} [hashFontSize] - Specifies the font size to display the hash.
30+
* @property {boolean} [minifiedCopyNotification] - Determines if the address component should be rendered in a minimized style.
31+
* @property {keyof any} [navigationPath] - **@deprecated** Use `navigateToPath` instead.
32+
* @property {'full' | 'tiny'} [copyNotifyingStyle] - **@deprecated** Use `minifiedCopyNotification` instead.
33+
*/
34+
interface AddressProps {
35+
loading: boolean;
36+
logo: string | null;
37+
name: string | undefined;
38+
hash: string | null | undefined;
39+
csprName?: string | undefined;
40+
tooltipCaption?: string;
41+
additionalTooltipBlock?: React.ReactElement;
42+
navigateToPath?: string;
43+
hashLength?: HashLength;
44+
nameTruncateSize?: Size;
45+
avatarSize?: AvatarProps['size'];
46+
hashFontSize?: HashFontSize;
47+
minifiedCopyNotification?: boolean;
48+
/** @deprecated use *navigateToPath* instead */
49+
navigationPath?: keyof any;
50+
/** @deprecated use *minifiedCopyNotification* instead */
51+
copyNotifyingStyle?: 'full' | 'tiny';
52+
}
53+
54+
const StyledTruncateBox = styled(TruncateBox)(() => ({
55+
height: '20px',
56+
}));
57+
58+
const StyledBodyText = styled(BodyText)(({ theme }) => ({
59+
color: theme.styleguideColors.contentBlue,
60+
'& > *': {
61+
color: theme.styleguideColors.contentBlue,
62+
},
63+
'&:hover > *': {
64+
color: theme.styleguideColors.fillPrimaryRed,
65+
},
66+
'&:active > *': {
67+
color: theme.styleguideColors.fillPrimaryRedClick,
68+
},
69+
}));
70+
71+
export enum HashFontSize {
72+
'default' = 'default',
73+
'big' = 'big',
74+
}
75+
76+
export const Address = ({
77+
hash,
78+
csprName,
79+
logo,
80+
name,
81+
loading,
82+
hashLength,
83+
minifiedCopyNotification,
84+
navigateToPath,
85+
tooltipCaption,
86+
additionalTooltipBlock,
87+
nameTruncateSize = 5,
88+
avatarSize = 'default',
89+
hashFontSize = HashFontSize.default,
90+
}: AddressProps) => {
91+
if (loading || !hash) {
92+
return (
93+
<FlexRow align="center" itemsSpacing={12}>
94+
<Avatar hash={hash} loading={loading} size={avatarSize} />
95+
</FlexRow>
96+
);
97+
}
98+
99+
if (hash === '00') {
100+
// hash == '00' means that it is a Immediate Switch Block
101+
// NOTE: as part of Casper network node v1.5, the node software now creates an "immediate switch block" on upgrades;
102+
// there are no rewards for this block. it simply captures the information after application of the upgrade,
103+
// which allows this to be deterministically detected
104+
return (
105+
<FlexRow align="center" itemsSpacing={12}>
106+
<Avatar hash={hash} loading={loading} size={avatarSize} />
107+
<FlexColumn>
108+
<BodyText size={2} monotype>
109+
{hash}
110+
</BodyText>
111+
<BodyText size={3} variation="darkGray" noWrap>
112+
System
113+
</BodyText>
114+
</FlexColumn>
115+
</FlexRow>
116+
);
117+
}
118+
119+
return (
120+
<FlexRow align="center" itemsSpacing={12}>
121+
{logo ? (
122+
<Avatar
123+
src={logo}
124+
loading={loading}
125+
size={avatarSize}
126+
alt={'Account logo'}
127+
/>
128+
) : (
129+
<Avatar hash={hash} loading={loading} size={avatarSize} />
130+
)}
131+
132+
<Tooltip
133+
caption={tooltipCaption}
134+
tooltipContent={hash}
135+
additionalBlock={additionalTooltipBlock}
136+
>
137+
<FlexColumn>
138+
{name ? (
139+
<>
140+
<StyledBodyText
141+
size={3}
142+
scale={hashFontSize === HashFontSize.big ? 'sm' : undefined}
143+
monotype={!csprName}
144+
>
145+
<HashLink
146+
minified={minifiedCopyNotification}
147+
href={navigateToPath}
148+
hash={hash}
149+
csprName={
150+
csprName && shortenCsprName(csprName, HashLength.TINY)
151+
}
152+
hashLength={hashLength}
153+
/>
154+
</StyledBodyText>
155+
<FlexRow itemsSpacing={6} align={'center'}>
156+
<StyledTruncateBox size={nameTruncateSize}>
157+
<BodyText size={3} variation="darkGray" noWrap>
158+
{name}
159+
</BodyText>
160+
</StyledTruncateBox>
161+
</FlexRow>
162+
</>
163+
) : (
164+
<StyledBodyText
165+
size={3}
166+
scale={hashFontSize === HashFontSize.big ? 'sm' : undefined}
167+
monotype={!csprName}
168+
>
169+
<HashLink
170+
href={navigateToPath}
171+
hash={hash}
172+
csprName={
173+
csprName && shortenCsprName(csprName, HashLength.TINY)
174+
}
175+
hashLength={hashLength}
176+
minified={minifiedCopyNotification}
177+
/>
178+
</StyledBodyText>
179+
)}
180+
</FlexColumn>
181+
</Tooltip>
182+
</FlexRow>
183+
);
184+
};

0 commit comments

Comments
 (0)