feat(client): add Timestamp component, ESLint 10 + Prettier, and code quality fixes
- add Timestamp component with moment relative time and ISO tooltip - add Timestamp stories (JustNow, MinutesAgo, HoursAgo, DaysAgo, MonthsAgo) - add ESLint 10 with typescript-eslint, react-hooks, react-refresh, prettier - add Prettier config with singleQuote, semi, trailingComma all, printWidth 100 - add lint, lint:fix, format, test:storybook scripts to package.json - fix react-hooks/set-state-in-effect in all page components - auto-fix 113 Prettier formatting issues across src and .storybook
This commit is contained in:
+11
-14
@@ -1,26 +1,23 @@
|
||||
import type { StorybookConfig } from '@storybook/react-vite';
|
||||
|
||||
import { dirname } from "path"
|
||||
import { dirname } from 'path';
|
||||
|
||||
import { fileURLToPath } from "url"
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
/**
|
||||
* This function is used to resolve the absolute path of a package.
|
||||
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
|
||||
*/
|
||||
* This function is used to resolve the absolute path of a package.
|
||||
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
|
||||
*/
|
||||
function getAbsolutePath(value: string) {
|
||||
return dirname(fileURLToPath(import.meta.resolve(`${value}/package.json`)))
|
||||
return dirname(fileURLToPath(import.meta.resolve(`${value}/package.json`)));
|
||||
}
|
||||
const config: StorybookConfig = {
|
||||
"stories": [
|
||||
"./stories/**/*.mdx",
|
||||
"./stories/**/*.stories.@(js|jsx|mjs|ts|tsx)"
|
||||
],
|
||||
"addons": [
|
||||
stories: ['./stories/**/*.mdx', './stories/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
|
||||
addons: [
|
||||
getAbsolutePath('@storybook/addon-vitest'),
|
||||
getAbsolutePath('@storybook/addon-a11y'),
|
||||
getAbsolutePath('@storybook/addon-docs')
|
||||
getAbsolutePath('@storybook/addon-docs'),
|
||||
],
|
||||
"framework": getAbsolutePath('@storybook/react-vite')
|
||||
framework: getAbsolutePath('@storybook/react-vite'),
|
||||
};
|
||||
export default config;
|
||||
export default config;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react'
|
||||
import type { Preview } from '@storybook/react-vite'
|
||||
import '../src/ui/tokens.css'
|
||||
import React from 'react';
|
||||
import type { Preview } from '@storybook/react-vite';
|
||||
import '../src/ui/tokens.css';
|
||||
|
||||
const preview: Preview = {
|
||||
globalTypes: {
|
||||
@@ -12,7 +12,7 @@ const preview: Preview = {
|
||||
icon: 'circlehollow',
|
||||
items: [
|
||||
{ value: 'light', icon: 'sun', title: 'Light' },
|
||||
{ value: 'dark', icon: 'moon', title: 'Dark' },
|
||||
{ value: 'dark', icon: 'moon', title: 'Dark' },
|
||||
],
|
||||
dynamicTitle: true,
|
||||
},
|
||||
@@ -20,13 +20,13 @@ const preview: Preview = {
|
||||
},
|
||||
decorators: [
|
||||
(Story, context) => {
|
||||
const theme = (context.globals['theme'] as string) ?? 'light'
|
||||
document.documentElement.setAttribute('data-theme', theme)
|
||||
const theme = (context.globals['theme'] as string) ?? 'light';
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
return (
|
||||
<div style={{ background: 'var(--color-bg)', minHeight: '100vh', padding: 0 }}>
|
||||
<Story />
|
||||
</div>
|
||||
)
|
||||
);
|
||||
},
|
||||
],
|
||||
parameters: {
|
||||
@@ -40,6 +40,6 @@ const preview: Preview = {
|
||||
test: 'todo',
|
||||
},
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export default preview
|
||||
export default preview;
|
||||
|
||||
@@ -12,10 +12,7 @@ type Story = StoryObj<typeof Breadcrumbs>;
|
||||
|
||||
export const Default: Story = {
|
||||
args: {
|
||||
items: [
|
||||
{ label: 'Scenarios', href: '#' },
|
||||
{ label: 'Login flow' },
|
||||
],
|
||||
items: [{ label: 'Scenarios', href: '#' }, { label: 'Login flow' }],
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -30,16 +30,29 @@ export const Default: Story = {
|
||||
export const ScenarioCard: Story = {
|
||||
render: () => (
|
||||
<Card>
|
||||
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', marginBottom: 8 }}>
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
justifyContent: 'space-between',
|
||||
alignItems: 'flex-start',
|
||||
marginBottom: 8,
|
||||
}}
|
||||
>
|
||||
<span style={{ fontWeight: 600, fontSize: 14 }}>Login flow</span>
|
||||
<Badge variant="success" dot>Passed</Badge>
|
||||
<Badge variant="success" dot>
|
||||
Passed
|
||||
</Badge>
|
||||
</div>
|
||||
<p style={{ margin: '0 0 16px', fontSize: 13, color: 'var(--color-text-muted)' }}>
|
||||
Last run 2 minutes ago · 4 steps
|
||||
</p>
|
||||
<div style={{ display: 'flex', gap: 8 }}>
|
||||
<Button size="sm" variant="primary">Run</Button>
|
||||
<Button size="sm" variant="ghost">Edit</Button>
|
||||
<Button size="sm" variant="primary">
|
||||
Run
|
||||
</Button>
|
||||
<Button size="sm" variant="ghost">
|
||||
Edit
|
||||
</Button>
|
||||
</div>
|
||||
</Card>
|
||||
),
|
||||
|
||||
@@ -32,27 +32,51 @@ const surfaceColors = [
|
||||
{ name: 'Primary fg', token: '--color-primary-fg', hex: '#2D3339' },
|
||||
];
|
||||
|
||||
function Swatch({ name, token, hex, role }: { name: string; token: string; hex: string; role?: string }) {
|
||||
function Swatch({
|
||||
name,
|
||||
token,
|
||||
hex,
|
||||
role,
|
||||
}: {
|
||||
name: string;
|
||||
token: string;
|
||||
hex: string;
|
||||
role?: string;
|
||||
}) {
|
||||
return (
|
||||
<div style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
overflow: 'hidden',
|
||||
borderRadius: 8,
|
||||
border: 'var(--border-width) solid var(--color-border)',
|
||||
minWidth: 160,
|
||||
flex: '1 1 160px',
|
||||
maxWidth: 220,
|
||||
}}>
|
||||
<div style={{
|
||||
background: `var(${token}, ${hex})`,
|
||||
height: 80,
|
||||
}} />
|
||||
<div
|
||||
style={{
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
overflow: 'hidden',
|
||||
borderRadius: 8,
|
||||
border: 'var(--border-width) solid var(--color-border)',
|
||||
minWidth: 160,
|
||||
flex: '1 1 160px',
|
||||
maxWidth: 220,
|
||||
}}
|
||||
>
|
||||
<div
|
||||
style={{
|
||||
background: `var(${token}, ${hex})`,
|
||||
height: 80,
|
||||
}}
|
||||
/>
|
||||
<div style={{ padding: '10px 12px', background: 'var(--color-bg)' }}>
|
||||
<div style={{ fontWeight: 600, fontSize: 13, color: 'var(--color-text)', marginBottom: 2 }}>{name}</div>
|
||||
{role && <div style={{ fontSize: 11, color: 'var(--color-text-muted)', marginBottom: 4 }}>{role}</div>}
|
||||
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>{hex}</div>
|
||||
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>{token}</div>
|
||||
<div style={{ fontWeight: 600, fontSize: 13, color: 'var(--color-text)', marginBottom: 2 }}>
|
||||
{name}
|
||||
</div>
|
||||
{role && (
|
||||
<div style={{ fontSize: 11, color: 'var(--color-text-muted)', marginBottom: 4 }}>
|
||||
{role}
|
||||
</div>
|
||||
)}
|
||||
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>
|
||||
{hex}
|
||||
</div>
|
||||
<div style={{ fontSize: 11, fontFamily: 'monospace', color: 'var(--color-text-muted)' }}>
|
||||
{token}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -61,12 +85,20 @@ function Swatch({ name, token, hex, role }: { name: string; token: string; hex:
|
||||
function Section({ title, children }: { title: string; children: React.ReactNode }) {
|
||||
return (
|
||||
<div style={{ marginBottom: 40 }}>
|
||||
<h2 style={{ fontFamily: 'var(--font-family)', color: 'var(--color-text)', fontSize: 14, fontWeight: 600, marginBottom: 16, textTransform: 'uppercase', letterSpacing: '0.08em' }}>
|
||||
<h2
|
||||
style={{
|
||||
fontFamily: 'var(--font-family)',
|
||||
color: 'var(--color-text)',
|
||||
fontSize: 14,
|
||||
fontWeight: 600,
|
||||
marginBottom: 16,
|
||||
textTransform: 'uppercase',
|
||||
letterSpacing: '0.08em',
|
||||
}}
|
||||
>
|
||||
{title}
|
||||
</h2>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12 }}>
|
||||
{children}
|
||||
</div>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: 12 }}>{children}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -74,18 +106,27 @@ function Section({ title, children }: { title: string; children: React.ReactNode
|
||||
function ColorPalette() {
|
||||
return (
|
||||
<div style={{ padding: 32, fontFamily: 'var(--font-family)' }}>
|
||||
<h1 style={{ color: 'var(--color-text)', fontSize: 22, fontWeight: 700, marginBottom: 8 }}>Color Palette</h1>
|
||||
<h1 style={{ color: 'var(--color-text)', fontSize: 22, fontWeight: 700, marginBottom: 8 }}>
|
||||
Color Palette
|
||||
</h1>
|
||||
<p style={{ color: 'var(--color-text-muted)', fontSize: 14, marginBottom: 40 }}>
|
||||
All colors are exposed as CSS custom properties on <code>:root</code> via <code>tokens.css</code>.
|
||||
All colors are exposed as CSS custom properties on <code>:root</code> via{' '}
|
||||
<code>tokens.css</code>.
|
||||
</p>
|
||||
<Section title="Brand">
|
||||
{palette.map(c => <Swatch key={c.token} {...c} />)}
|
||||
{palette.map((c) => (
|
||||
<Swatch key={c.token} {...c} />
|
||||
))}
|
||||
</Section>
|
||||
<Section title="Semantic">
|
||||
{semanticColors.map(c => <Swatch key={c.token} {...c} />)}
|
||||
{semanticColors.map((c) => (
|
||||
<Swatch key={c.token} {...c} />
|
||||
))}
|
||||
</Section>
|
||||
<Section title="Surface & Action">
|
||||
{surfaceColors.map(c => <Swatch key={c.token} {...c} />)}
|
||||
{surfaceColors.map((c) => (
|
||||
<Swatch key={c.token} {...c} />
|
||||
))}
|
||||
</Section>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -5,7 +5,16 @@ const NAV_ITEMS = ['Dashboard', 'Scenarios', 'Environments', 'Reports', 'Setting
|
||||
|
||||
function NavList() {
|
||||
return (
|
||||
<ul style={{ listStyle: 'none', margin: 0, padding: 0, display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||
<ul
|
||||
style={{
|
||||
listStyle: 'none',
|
||||
margin: 0,
|
||||
padding: 0,
|
||||
display: 'flex',
|
||||
flexDirection: 'column',
|
||||
gap: 2,
|
||||
}}
|
||||
>
|
||||
{NAV_ITEMS.map((item) => (
|
||||
<li key={item}>
|
||||
<button
|
||||
@@ -41,7 +50,14 @@ const meta: Meta<typeof SidePanel> = {
|
||||
(Story) => (
|
||||
<div style={{ display: 'flex', height: 420, background: 'var(--color-bg)' }}>
|
||||
<Story />
|
||||
<div style={{ flex: 1, padding: 'var(--space-6)', color: 'var(--color-text-muted)', fontSize: 'var(--font-size-sm)' }}>
|
||||
<div
|
||||
style={{
|
||||
flex: 1,
|
||||
padding: 'var(--space-6)',
|
||||
color: 'var(--color-text-muted)',
|
||||
fontSize: 'var(--font-size-sm)',
|
||||
}}
|
||||
>
|
||||
Main content area
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -18,9 +18,9 @@ interface User {
|
||||
}
|
||||
|
||||
const users: User[] = [
|
||||
{ id: 1, name: 'Alice Müller', email: 'alice@example.com', status: 'active' },
|
||||
{ id: 2, name: 'Bob Nguyen', email: 'bob@example.com', status: 'inactive' },
|
||||
{ id: 3, name: 'Carol Santos', email: 'carol@example.com', status: 'active' },
|
||||
{ id: 1, name: 'Alice Müller', email: 'alice@example.com', status: 'active' },
|
||||
{ id: 2, name: 'Bob Nguyen', email: 'bob@example.com', status: 'inactive' },
|
||||
{ id: 3, name: 'Carol Santos', email: 'carol@example.com', status: 'active' },
|
||||
];
|
||||
|
||||
export const Default: StoryObj<typeof Table<User>> = {
|
||||
@@ -29,17 +29,15 @@ export const Default: StoryObj<typeof Table<User>> = {
|
||||
rowKey: (u) => u.id,
|
||||
emptyMessage: 'No users found.',
|
||||
columns: [
|
||||
{ key: 'id', header: 'ID', render: (u) => u.id, width: 60 },
|
||||
{ key: 'name', header: 'Name', render: (u) => u.name },
|
||||
{ key: 'email', header: 'Email', render: (u) => u.email },
|
||||
{ key: 'id', header: 'ID', render: (u) => u.id, width: 60 },
|
||||
{ key: 'name', header: 'Name', render: (u) => u.name },
|
||||
{ key: 'email', header: 'Email', render: (u) => u.email },
|
||||
{
|
||||
key: 'status',
|
||||
header: 'Status',
|
||||
width: 110,
|
||||
render: (u) => (
|
||||
<Badge variant={u.status === 'active' ? 'success' : 'neutral'}>
|
||||
{u.status}
|
||||
</Badge>
|
||||
<Badge variant={u.status === 'active' ? 'success' : 'neutral'}>{u.status}</Badge>
|
||||
),
|
||||
},
|
||||
],
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { Timestamp } from '../../src/ui/Timestamp/Timestamp';
|
||||
|
||||
const meta: Meta<typeof Timestamp> = {
|
||||
title: 'UI/Timestamp',
|
||||
component: Timestamp,
|
||||
parameters: { layout: 'centered' },
|
||||
tags: ['autodocs'],
|
||||
};
|
||||
export default meta;
|
||||
type Story = StoryObj<typeof Timestamp>;
|
||||
|
||||
const minutesAgo = (n: number) => new Date(Date.now() - n * 60_000).toISOString();
|
||||
const hoursAgo = (n: number) => new Date(Date.now() - n * 3_600_000).toISOString();
|
||||
const daysAgo = (n: number) => new Date(Date.now() - n * 86_400_000).toISOString();
|
||||
|
||||
export const JustNow: Story = { args: { value: minutesAgo(1) } };
|
||||
export const MinutesAgo: Story = { args: { value: minutesAgo(15) } };
|
||||
export const HoursAgo: Story = { args: { value: hoursAgo(3) } };
|
||||
export const DaysAgo: Story = { args: { value: daysAgo(5) } };
|
||||
export const MonthsAgo: Story = { args: { value: daysAgo(90) } };
|
||||
Reference in New Issue
Block a user