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
31 changes: 31 additions & 0 deletions playground/src/components/BadgeDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,33 @@ export function BadgeDemo() {
</div>
</section>

<section className="demo-section">
<h2 className="demo-section-title">With Count</h2>
<p className="demo-label">
A monospace count sits on the leading edge for flags, or the trailing
edge for category tags.
</p>
<div className="demo-row">
<Badge variant="warning" count={10}>
sessions flagged as anomalous
</Badge>
<Badge variant="error" count={16}>
stalled sessions
</Badge>
</div>
<div className="demo-row">
<Badge variant="neutral" count={525} countPosition="trailing">
other
</Badge>
<Badge variant="neutral" count={186} countPosition="trailing">
outcome
</Badge>
<Badge variant="info" count={42} countPosition="trailing">
planning
</Badge>
</div>
</section>

<section className="demo-section">
<h2 className="demo-section-title">With Icons</h2>
<div className="demo-row">
Expand Down Expand Up @@ -168,6 +195,10 @@ import { Check } from 'lucide-react'
// With icon
<Badge variant="success" icon={<Check />}>Synced</Badge>

// With a count (leading for flags, trailing for tags)
<Badge variant="warning" count={10}>flagged sessions</Badge>
<Badge variant="neutral" count={525} countPosition="trailing">other</Badge>

// Different sizes
<Badge size="sm">Small</Badge>
<Badge size="md">Medium</Badge>`}</pre>
Expand Down
37 changes: 36 additions & 1 deletion playground/src/components/StatCardDemo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,38 @@ export function StatCardDemo() {
</div>
</section>

<section className="demo-section">
<h2 className="demo-section-title">Surface: muted vs plain</h2>
<p className="text-sm text-navy-600 dark:text-navy-400 mb-4">
Default tiles are <code>surface="muted"</code> (filled) — the right look on a
page background. Inside a Card/SectionCard the fill goes muddy grey-on-white,
so pass <code>surface="plain"</code> to make the tile transparent and inherit
the card behind it.
</p>
<div className="grid gap-4 sm:grid-cols-2">
<div>
<div className="demo-label">muted (default) inside a card — muddy</div>
<div className="bg-white dark:bg-navy-800 rounded-lg p-4 shadow-sm">
<div className="grid grid-cols-3 gap-3">
<StatCard label="Sent" value={142} variant="centered" />
<StatCard label="Received" value={98} variant="centered" />
<StatCard label="Threads" value={45} variant="centered" />
</div>
</div>
</div>
<div>
<div className="demo-label">plain inside a card — clean</div>
<div className="bg-white dark:bg-navy-800 rounded-lg p-4 shadow-sm">
<div className="grid grid-cols-3 gap-3">
<StatCard label="Sent" value={142} variant="centered" surface="plain" />
<StatCard label="Received" value={98} variant="centered" surface="plain" />
<StatCard label="Threads" value={45} variant="centered" surface="plain" />
</div>
</div>
</div>
</div>
</section>

<section className="demo-section">
<h2 className="demo-section-title">Real-world Example</h2>
<div className="bg-white dark:bg-navy-800 rounded-lg p-4 shadow-sm max-w-md">
Expand Down Expand Up @@ -161,7 +193,10 @@ import { Mail } from 'lucide-react'
value="150"
variant="inline"
color="accent"
/>`}</pre>
/>

// Plain surface — transparent tile for nesting inside a Card
<StatCard label="Sent" value={142} variant="centered" surface="plain" />`}</pre>
</section>
</div>
)
Expand Down
58 changes: 58 additions & 0 deletions src/components/Badge/Badge.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { describe, it, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import { Check } from 'lucide-react'
import { Badge } from './Badge'

describe('Badge', () => {
describe('variants', () => {
it('applies the variant class for the chosen variant', () => {
render(<Badge variant="warning">Pending</Badge>)
expect(screen.getByText('Pending')).toHaveClass('gp-badge-warning')
})

it('defaults to the neutral variant', () => {
render(<Badge>Draft</Badge>)
expect(screen.getByText('Draft')).toHaveClass('gp-badge-neutral')
})
})

describe('count', () => {
it('renders the count when provided', () => {
render(<Badge count={10}>flagged</Badge>)
expect(screen.getByText('10')).toBeInTheDocument()
})

it('omits the count element when count is not provided', () => {
const { container } = render(<Badge>plain</Badge>)
expect(container.querySelector('.font-mono')).toBeNull()
})

it('renders a zero count (count={0} is not treated as absent)', () => {
render(<Badge count={0}>none</Badge>)
expect(screen.getByText('0')).toBeInTheDocument()
})

it('places the count before the label by default (leading)', () => {
const { container } = render(<Badge count={7}>items</Badge>)
expect(container.firstChild?.textContent).toBe('7items')
})

it('places the count after the label when countPosition="trailing"', () => {
const { container } = render(
<Badge count={525} countPosition="trailing">
other
</Badge>
)
expect(container.firstChild?.textContent).toBe('other525')
})
})

describe('icon', () => {
it('renders an icon in the leading slot', () => {
render(
<Badge icon={<Check data-testid="badge-icon" />}>Synced</Badge>
)
expect(screen.getByTestId('badge-icon')).toBeInTheDocument()
})
})
})
32 changes: 30 additions & 2 deletions src/components/Badge/Badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ export interface BadgeProps {
*/
icon?: ReactNode

/**
* Optional monospace count rendered inside the badge (e.g. a session or
* item total). Tabular figures keep it aligned across rows.
*/
count?: number | string

/**
* Which edge the count sits on.
* - leading: before the label (default) — reads as "10 flagged"
* - trailing: after the label — reads as "other 525"
*/
countPosition?: 'leading' | 'trailing'

/**
* Badge content
*/
Expand All @@ -50,6 +63,8 @@ export function Badge({
variant = 'neutral',
size = 'sm',
icon,
count,
countPosition = 'leading',
children,
className = '',
}: BadgeProps) {
Expand All @@ -61,19 +76,30 @@ export function Badge({
neutral: 'gp-badge-neutral',
}

// Geometry only — color and weight come from the gp-badge-* variant classes.
const baseClasses = 'inline-flex items-center rounded-full'

const sizeClasses = {
sm: 'px-1.5 py-0.5 text-xs',
md: 'px-2 py-1 text-sm',
sm: 'gap-1.5 px-3 py-[5px] text-xs',
md: 'gap-2 px-3.5 py-1.5 text-sm',
}

const iconSizeClasses = {
sm: 'w-3 h-3',
md: 'w-3.5 h-3.5',
}

const countEl =
count != null ? (
<span className="font-mono text-[11px] tabular-nums opacity-80">
{count}
</span>
) : null

return (
<span
className={cn(
baseClasses,
variantClasses[variant],
sizeClasses[size],
className
Expand All @@ -84,7 +110,9 @@ export function Badge({
{icon}
</span>
)}
{countPosition === 'leading' && countEl}
{children}
{countPosition === 'trailing' && countEl}
</span>
)
}
42 changes: 42 additions & 0 deletions src/components/StatCard/StatCard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { describe, it, expect } from 'vitest'
import { render, screen } from '@testing-library/react'
import { StatCard } from './StatCard'

describe('StatCard', () => {
const tile = (label: string) =>
// the tile is the nearest element carrying the gp-stat-card class
screen.getByText(label).closest('.gp-stat-card') as HTMLElement

describe('surface', () => {
it('defaults to the muted fill', () => {
render(<StatCard label="Sent" value={42} />)
expect(tile('Sent')).toHaveClass('bg-gray-50')
})

it('renders a transparent tile when surface="plain"', () => {
render(<StatCard label="Sent" value={42} surface="plain" />)
const el = tile('Sent')
expect(el).toHaveClass('bg-transparent')
expect(el).not.toHaveClass('bg-gray-50')
})

it('applies plain across tiled variants (centered)', () => {
render(<StatCard label="Sent" value={42} variant="centered" surface="plain" />)
expect(tile('Sent')).toHaveClass('bg-transparent')
})

it('drops the accent fill when accent color is plain', () => {
render(<StatCard label="Sync" value={5} color="accent" surface="plain" />)
const el = tile('Sync')
expect(el).toHaveClass('bg-transparent')
expect(el).not.toHaveClass('bg-white/80')
})
})

describe('display variant', () => {
it('renders no tile chrome regardless of surface', () => {
render(<StatCard label="Founders" value={99} variant="display" surface="plain" />)
expect(screen.getByText('Founders').closest('.gp-stat-card')).toBeNull()
})
})
})
33 changes: 28 additions & 5 deletions src/components/StatCard/StatCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ export interface StatCardProps {
*/
color?: 'default' | 'accent'

/**
* Tile surface treatment.
* - muted: filled tile (default) — the standalone look, reads on a page background
* - plain: transparent, inherits the parent surface — use when nesting inside a
* Card / SectionCard so the tile doesn't go muddy grey-on-white
*
* Ignored by `variant="display"`, which is always chrome-less.
*/
surface?: 'muted' | 'plain'

/**
* Additional CSS classes
*/
Expand Down Expand Up @@ -90,6 +100,7 @@ export function StatCard({
trend,
variant = 'default',
color = 'default',
surface = 'muted',
className = '',
}: StatCardProps) {
const isNumeric = typeof value === 'number' || !isNaN(Number(value))
Expand All @@ -99,17 +110,29 @@ export function StatCard({
default: {
label: 'text-navy-500 dark:text-navy-300',
value: 'text-navy-900 dark:text-navy-100',
bg: 'bg-gray-50 dark:bg-navy-800/50',
icon: 'text-navy-400 dark:text-navy-400',
},
accent: {
label: 'text-orange-600 dark:text-orange-400',
value: 'text-orange-800 dark:text-orange-200',
bg: 'bg-white/80 dark:bg-navy-800/80',
icon: 'text-orange-500 dark:text-orange-400',
},
}

// Surface fill by color × surface. `plain` is transparent so a nested tile
// inherits the card behind it instead of stacking grey-on-white.
const surfaceClasses = {
default: {
muted: 'bg-gray-50 dark:bg-navy-800/50',
plain: 'bg-transparent',
},
accent: {
muted: 'bg-white/80 dark:bg-navy-800/80',
plain: 'bg-transparent',
},
}
const surfaceBg = surfaceClasses[color][surface]

// Display variant: huge cream numeral above tiny uppercase caption, no chrome.
// Used in Hero blocks and marketing-style number callouts.
if (variant === 'display') {
Expand Down Expand Up @@ -148,7 +171,7 @@ export function StatCard({
// Inline variant: label on top, value below, left-aligned.
if (variant === 'inline') {
return (
<div className={cn('gp-stat-card flex flex-col items-start gap-0.5', colorClasses[color].bg, className)}>
<div className={cn('gp-stat-card flex flex-col items-start gap-0.5', surfaceBg, className)}>
{/* Label on top */}
<span className={cn('text-xs leading-tight', colorClasses[color].label)}>
{label}
Expand All @@ -165,7 +188,7 @@ export function StatCard({
// Centered variant: label on top, value below, centered.
if (variant === 'centered') {
return (
<div className={cn('gp-stat-card flex flex-col items-center text-center gap-1', colorClasses[color].bg, className)}>
<div className={cn('gp-stat-card flex flex-col items-center text-center gap-1', surfaceBg, className)}>
{/* Label on top */}
<span className={cn('text-xs leading-tight', colorClasses[color].label)}>
{label}
Expand All @@ -186,7 +209,7 @@ export function StatCard({
}

return (
<div className={cn('gp-stat-card flex flex-col items-start', colorClasses[color].bg, variantClasses[variant], className)}>
<div className={cn('gp-stat-card flex flex-col items-start', surfaceBg, variantClasses[variant], className)}>
{/* Value and icon row */}
<div className="flex items-center gap-2 min-w-0">
{icon && (
Expand Down
Loading
Loading