Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/smart-routing-address-react-ui/.storybook/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { StorybookConfig } from '@storybook/react-vite'

const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: ['@storybook/addon-a11y', '@storybook/addon-docs'],
framework: '@storybook/react-vite',
}
export default config
15 changes: 15 additions & 0 deletions packages/smart-routing-address-react-ui/.storybook/preview.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import type { Preview } from '@storybook/react-vite'
import '../src/styles.css'

const preview: Preview = {
parameters: {
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i,
},
},
},
}

export default preview
33 changes: 27 additions & 6 deletions packages/smart-routing-address-react-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"name": "@zerodev/smart-routing-address-react-ui",
"version": "0.0.1",
"private": true,
"description": "React hooks + provider for ZeroDev Smart Routing Address deposits",
"description": "React hooks, provider, and UI for ZeroDev Smart Routing Address deposits",
"repository": {
"type": "git",
"url": "git+https://github.com/zerodevapp/zerodev-wallet-sdk.git",
"directory": "packages/smart-routing-address-react-ui"
},
"sideEffects": false,
"sideEffects": [
"**/*.css"
],
"main": "./dist/index.cjs",
"module": "./dist/index.mjs",
"types": "./dist/_types/index.d.ts",
Expand All @@ -17,50 +19,69 @@
"types": "./dist/_types/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"./styles.css": "./dist/styles.css"
},
"files": [
"dist",
"src/**/*.ts",
"src/**/*.tsx",
"!dist/**/*.tsbuildinfo",
"!src/**/*.test.ts",
"!src/**/*.test.tsx"
"!src/**/*.test.tsx",
"!src/**/*.stories.ts",
"!src/**/*.stories.tsx"
],
"scripts": {
"build": "pnpm run clean && pnpm run build:js && pnpm run build:types",
"build": "pnpm run clean && pnpm run build:css && pnpm run build:js && pnpm run build:types",
"build:css": "npx @tailwindcss/cli -i ./src/styles.css -o ./dist/styles.css --minify",
"build:js": "vite build",
"build:types": "tsc --project ./tsconfig.build.json --outDir ./dist/_types --emitDeclarationOnly --declaration --declarationMap",
"dev": "tsc --watch",
"dev:css": "npx @tailwindcss/cli -i ./src/styles.css -o ./dist/styles.css --watch",
"typecheck": "tsc --noEmit --project ./tsconfig.build.json",
"clean": "rm -rf dist",
"test": "vitest run",
"test:watch": "vitest"
"test:watch": "vitest",
"storybook": "storybook dev -p 6008",
"build-storybook": "storybook build"
},
"keywords": [
"react",
"hooks",
"components",
"smart-routing",
"deposit",
"zerodev",
"web3"
],
"dependencies": {
"@zerodev/react-ui": "workspace:*"
},
"peerDependencies": {
"@zerodev/smart-routing-address": "^0.2.5",
"react": "^18.0.0 || ^19.0.0",
"react-dom": "^18.0.0 || ^19.0.0",
"viem": "^2.47.18"
},
"devDependencies": {
"@storybook/addon-a11y": "^10.3.3",
"@storybook/addon-docs": "^10.3.3",
"@storybook/react-vite": "^10.3.3",
"@tailwindcss/cli": "^4.2.2",
"@tailwindcss/postcss": "^4.2.2",
"@testing-library/react": "^16.3.0",
"@types/react": "~19.2.14",
"@types/react-dom": "^19",
"@vitejs/plugin-react": "^4.7.0",
"@vitest/coverage-v8": "^4.0.18",
"@zerodev/smart-routing-address": "^0.2.5",
"happy-dom": "^20.6.0",
"postcss": "^8.5.8",
"react": "19.2.0",
"react-dom": "19.2.0",
"storybook": "^10.3.3",
"tailwindcss": "^4.2.2",
"typescript": "5.9.3",
"viem": "^2.47.18",
"vite": "^6.4.1",
Expand Down
5 changes: 5 additions & 0 deletions packages/smart-routing-address-react-ui/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
plugins: {
'@tailwindcss/postcss': {},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import type { Meta, StoryObj } from '@storybook/react-vite'
import { TokenChainPill } from './index'

const meta: Meta<typeof TokenChainPill> = {
title: 'SmartRoutingAddress/TokenChainPill',
component: TokenChainPill,
parameters: { layout: 'centered' },
decorators: [
(Story) => (
<div style={{ width: 162 }}>
<Story />
</div>
),
],
argTypes: {
logoBg: { control: 'color' },
onClick: { action: 'clicked' },
},
}

export default meta
type Story = StoryObj<typeof meta>

/** Interactive source-token pill — the default variant shown in Figma. */
export const InteractiveToken: Story = {
args: {
label: 'USDC',
logoBg: '#2775CA',
logoInitial: 'U',
onClick: () => {},
},
}

/** Interactive source-chain pill. */
export const InteractiveChain: Story = {
args: {
label: 'Base',
logoBg: '#0052FF',
logoInitial: 'B',
onClick: () => {},
},
}

/**
* Display variant — the destination pill from the "Arrives as" card
* (Figma 17777:81278). Renders on a 5% white surface with no chevron.
* Achieved by omitting `onClick`; setting `disabled: true` alongside an
* `onClick` handler produces the same visual.
*/
export const Display: Story = {
args: {
label: 'Arbitrum One',
logoBg: '#28A0F0',
logoInitial: 'A',
},
}

/** Same display variant, but with `disabled: true` forcing a passed
* `onClick` handler to be ignored — useful for "temporarily unavailable"
* states without unmounting/remounting props. */
export const DisplayForcedDisabled: Story = {
args: {
label: 'Arbitrum One',
logoBg: '#28A0F0',
logoInitial: 'A',
onClick: () => {},
disabled: true,
},
}

/** With an external logo image supplied. */
export const WithLogoImage: Story = {
args: {
label: 'USDC',
logoUri:
'https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48/logo.png',
onClick: () => {},
},
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* @vitest-environment happy-dom
*/
import { cleanup, fireEvent, render, screen } from '@testing-library/react'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { TokenChainPill } from './index'

afterEach(cleanup)

describe('TokenChainPill', () => {
it('renders the label', () => {
render(<TokenChainPill label="USDC" />)
expect(screen.getByText('USDC')).toBeDefined()
})

it('renders the logo image when logoUri is provided', () => {
render(
<TokenChainPill label="USDC" logoUri="https://example.com/usdc.png" />,
)
const img = screen.getByTestId('token-chain-pill-logo')
expect(img.getAttribute('src')).toBe('https://example.com/usdc.png')
})

it('renders the initial placeholder when logoUri is absent', () => {
render(<TokenChainPill label="Base" logoInitial="B" />)
expect(screen.getByText('B')).toBeDefined()
})

it('is not interactive by default (no chevron, no button role)', () => {
render(<TokenChainPill label="USDC" />)
expect(screen.queryByTestId('token-chain-pill-chevron')).toBeNull()
expect(screen.queryByRole('button')).toBeNull()
})

it('becomes an interactive button when onClick is supplied', () => {
const onClick = vi.fn()
render(<TokenChainPill label="USDC" onClick={onClick} />)
const button = screen.getByRole('button')
expect(button).toBeDefined()
expect(screen.getByTestId('token-chain-pill-chevron')).toBeDefined()
fireEvent.click(button)
expect(onClick).toHaveBeenCalledTimes(1)
})

it('triggers onClick on Enter and Space keys', () => {
const onClick = vi.fn()
render(<TokenChainPill label="USDC" onClick={onClick} />)
const button = screen.getByRole('button')
fireEvent.keyDown(button, { key: 'Enter' })
fireEvent.keyDown(button, { key: ' ' })
expect(onClick).toHaveBeenCalledTimes(2)
})

it('ignores unrelated keys', () => {
const onClick = vi.fn()
render(<TokenChainPill label="USDC" onClick={onClick} />)
fireEvent.keyDown(screen.getByRole('button'), { key: 'a' })
expect(onClick).not.toHaveBeenCalled()
})

it('renders as non-interactive when disabled, even with onClick', () => {
const onClick = vi.fn()
render(<TokenChainPill label="Arbitrum One" onClick={onClick} disabled />)
expect(screen.queryByRole('button')).toBeNull()
expect(screen.queryByTestId('token-chain-pill-chevron')).toBeNull()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { cn, Icon, Text, Wrapper } from '@zerodev/react-ui'
import type { KeyboardEvent } from 'react'

export interface TokenChainPillProps {
/** Text label rendered next to the logo (e.g., "USDC", "Base"). */
label: string
/** URL of the logo image; when omitted, a `logoBg` + `logoInitial` placeholder is drawn. */
logoUri?: string
/** Fallback background color when no `logoUri` is supplied. */
logoBg?: string
/** Fallback initial letter shown inside the placeholder circle. */
logoInitial?: string
/** Click handler; when supplied and not `disabled`, the pill becomes a keyboard-accessible button. */
onClick?: () => void
/** When true, renders as a dimmed, non-interactive pill (no chevron). */
disabled?: boolean
className?: string
}

export function TokenChainPill({

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this basically a Select primitive with an optional image? Based on its looks and function, it seems like it should be part of react-ui?

@brtkx brtkx Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we did that, we could have this component as Select as well. It just disabled and has chevron hidden.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That component is already included

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this basically a Select primitive with an optional image? Based on its looks and function, it seems like it should be part of react-ui?

Currently it is being used in SRA only. If we needed somewhere else, it can then be refactored to react-ui

label,
logoUri,
logoBg = '#E6EFFB',
logoInitial,
onClick,
disabled,
className,
}: TokenChainPillProps) {
const interactive = Boolean(onClick) && !disabled

const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
if (!interactive) return
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault()
onClick?.()
}
}

return (
<Wrapper
variant="solid"
// Override Wrapper's variant-based bg color for the display variant —
// Figma spec is exactly rgba(255,255,255,0.05), which none of the
// Wrapper variants match. Inline style beats Wrapper's own style.
style={
interactive
? undefined
: { backgroundColor: 'rgba(255, 255, 255, 0.05)' }
}
className={cn(
// Sizing/padding matches Figma: outer pl-1 pr-2 py-1, rounded-2xl.
// Height is content-driven — 44px logo + 4px vertical padding = 52px.
'zd:relative zd:flex zd:w-full zd:items-center zd:justify-between zd:overflow-hidden zd:rounded-2xl zd:pl-1 zd:pr-2 zd:py-1',
// Universal inner shadow from the Figma design token.
'zd:shadow-[inset_0_-4px_4px_0_rgba(255,255,255,0.1),inset_0_3px_4px_0_rgba(0,0,0,0.02)]',
interactive && 'zd:cursor-pointer',
className,
)}
{...(interactive && {
role: 'button',
tabIndex: 0,
onClick,
onKeyDown: handleKeyDown,
})}
>
<div className="zd:flex zd:items-center zd:gap-1.5">
{/* 44×44 logo well with a 34×34 centered inner disc. Figma places the
image with translate-1/2 offsets so the smaller disc sits inside
the larger well — the 10px reveal reads as the pill's "logo pad". */}
<div
className="zd:relative zd:size-11 zd:shrink-0 zd:rounded-xl"
aria-hidden={!logoUri}
>
<div
className={cn(
'zd:absolute zd:top-1/2 zd:left-1/2 zd:-translate-x-1/2 zd:-translate-y-1/2',
'zd:flex zd:size-8.5 zd:items-center zd:justify-center zd:overflow-hidden zd:rounded-full',
)}
style={logoUri ? undefined : { backgroundColor: logoBg }}
>
{logoUri ? (
<img
alt=""
src={logoUri}
className="zd:size-full zd:object-cover"
data-testid="token-chain-pill-logo"
/>
) : logoInitial ? (
<span className="zd:text-body2 zd:font-medium zd:text-white">
{logoInitial}
</span>
) : null}
</div>
</div>
<Text className="zd:whitespace-nowrap zd:text-body1">{label}</Text>
</div>
{interactive && (
<div className="zd:flex zd:shrink-0 zd:items-center zd:rounded-full zd:p-2">
<Icon
name="chevronDown"
className="zd:size-4 zd:text-greyScale"
data-testid="token-chain-pill-chevron"
/>
</div>
)}
</Wrapper>
)
}
6 changes: 5 additions & 1 deletion packages/smart-routing-address-react-ui/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
/**
* @zerodev/smart-routing-address-react-ui
* React hooks + provider for ZeroDev Smart Routing Address deposits.
* React hooks, provider, and UI for ZeroDev Smart Routing Address deposits.
*/

// Components
export type { TokenChainPillProps } from './components/TokenChainPill'
export { TokenChainPill } from './components/TokenChainPill'

// Provider
export type { SmartRoutingAddressProviderProps } from './context/SmartRoutingAddressProvider'
export { SmartRoutingAddressProvider } from './context/SmartRoutingAddressProvider'
Expand Down
Loading
Loading