Skip to content

Commit 5658529

Browse files
[DSR] Added Jazzicon (#469)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** This PR adds the `Jazzicon` component to the DSR <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> ## **Related issues** Fixes: #403 ## **Manual testing steps** 1. Run `yarn storybook` from root 2. Go to React Components > Jazzicon 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** https://github.com/user-attachments/assets/b11408a4-9b8d-457a-a89c-488aa4a94989 <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [x] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) - [x] I've completed the PR template to the best of my ability - [x] I’ve included tests if applicable - [x] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [x] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: georgewrmarshall <[email protected]>
1 parent b4063d2 commit 5658529

File tree

13 files changed

+790
-3
lines changed

13 files changed

+790
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare module '@metamask/jazzicon' {
2+
function jazzicon(diameter: number, seed: number | number[]): HTMLDivElement;
3+
export default jazzicon;
4+
}

packages/design-system-react/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@
5050
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
5151
},
5252
"dependencies": {
53+
"@metamask/jazzicon": "^2.0.0",
54+
"@metamask/utils": "^11.3.0",
5355
"@radix-ui/react-slot": "^1.1.0",
56+
"@solana/addresses": "^2.1.0",
57+
"bitcoin-address-validation": "^3.0.0",
5458
"blo": "^1.2.0",
5559
"tailwind-merge": "^2.0.0"
5660
},

packages/design-system-react/src/components/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@ export type { AvatarFaviconProps } from './avatar-favicon';
5050

5151
export { AvatarIcon, AvatarIconSize, AvatarIconSeverity } from './avatar-icon';
5252
export type { AvatarIconProps } from './avatar-icon';
53+
54+
export { Jazzicon } from './jazzicon';
55+
export type { JazziconProps } from './jazzicon';
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import type { Meta, StoryObj } from '@storybook/react';
2+
import React from 'react';
3+
4+
import { Jazzicon } from './Jazzicon';
5+
import type { JazziconProps } from './Jazzicon.types';
6+
import README from './README.mdx';
7+
8+
const meta: Meta<JazziconProps> = {
9+
title: 'React Components/Jazzicon',
10+
component: Jazzicon,
11+
parameters: {
12+
docs: {
13+
page: README,
14+
},
15+
},
16+
args: {
17+
address: '0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8',
18+
size: 32,
19+
},
20+
argTypes: {
21+
address: {
22+
control: 'text',
23+
description:
24+
'Required address used as a unique identifier to generate the Jazzicon.',
25+
},
26+
size: {
27+
control: 'number',
28+
description: 'Optional prop to control the size of the Jazzicon.',
29+
},
30+
className: {
31+
control: 'text',
32+
description:
33+
'Optional prop for additional CSS classes to be applied to the Jazzicon component.',
34+
},
35+
},
36+
};
37+
38+
export default meta;
39+
type Story = StoryObj<JazziconProps>;
40+
41+
const sampleAccountAddresses = [
42+
'0x9Cbf7c41B7787F6c621115010D3B044029FE2Ce8', // Standard Ethereum address
43+
'1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', // Bitcoin address
44+
'4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7', // Solana address
45+
'eip155:1:0xabc', // CAIP-10 formatted address
46+
'bip122:1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', // CAIP-10 Bitcoin address
47+
'solana:mainnet:4Nd1m3NnENa8h8Xte1Xr7s9jcvKqqm21z3FvY9hKg4s7', // CAIP-10 Solana address
48+
];
49+
50+
export const Default: Story = {};
51+
52+
export const Address: Story = {
53+
render: () => (
54+
<div className="flex flex-wrap gap-2">
55+
{sampleAccountAddresses.map((address) => (
56+
<Jazzicon key={address} address={address} size={32} />
57+
))}
58+
</div>
59+
),
60+
};
61+
62+
export const Size: Story = {
63+
render: () => (
64+
<div className="flex items-center gap-4">
65+
<Jazzicon address={sampleAccountAddresses[0]} size={16} />
66+
<Jazzicon address={sampleAccountAddresses[1]} size={24} />
67+
<Jazzicon address={sampleAccountAddresses[2]} size={32} />
68+
<Jazzicon address={sampleAccountAddresses[3]} size={48} />
69+
<Jazzicon address={sampleAccountAddresses[4]} size={64} />
70+
</div>
71+
),
72+
};

0 commit comments

Comments
 (0)