mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-20 12:23:22 +00:00
Add a two-dimensional theme system: Style (Clean/Playful) × Mode (Light/Dark/System). Theme infrastructure: - ThemeContext with style + mode state, matchMedia listener, localStorage persistence - ThemePopover in sidebar for switching style and mode - FOUC prevention via inline script in index.html - CSS custom properties for radius, shadows, fonts (resolved per theme) - design.ts migrated to CSS variable refs Playful theme features: - Wobbly border-radius on cards, buttons, badges, inputs, dialogs - Hard offset shadows (no blur) for sketch aesthetic - Caveat handwritten font for headings, DM Sans for body text - Dotted paper texture background - Skill cards as pastel sticky notes with masking tape strips - Wavy underlines on links - Dashed sidebar border with Caveat section headers - Per-card wobble variety (6 unique border-radius patterns) Component enhancements: - ss-* CSS class hooks on all themed components for CSS-only overrides - SegmentedControl: aria-pressed for theme targeting, clean defaults - SkillDetailSkeleton: custom loading skeleton matching detail page layout - Dashboard Quick Action cards: hover animations (pulse/bounce) - AuditPage: fix tour step targeting Clean theme unchanged — all Playful styles scoped under [data-theme="playful"].
111 lines
3.4 KiB
TypeScript
111 lines
3.4 KiB
TypeScript
import type { ReactNode } from 'react';
|
|
import { radius, shadows } from '../design';
|
|
|
|
interface Option<T extends string> {
|
|
value: T;
|
|
label: ReactNode;
|
|
count?: number;
|
|
}
|
|
|
|
interface SegmentedControlProps<T extends string> {
|
|
value: T;
|
|
onChange: (value: T) => void;
|
|
options: Option<T>[];
|
|
size?: 'sm' | 'md';
|
|
/** Connected mode: buttons share a border container (no gaps) */
|
|
connected?: boolean;
|
|
/** Custom active color per option (for severity tabs, etc.) */
|
|
colorFn?: (value: T) => string | undefined;
|
|
}
|
|
|
|
const sizeClasses = {
|
|
sm: 'px-3 py-1.5 text-sm',
|
|
md: 'px-4 py-2 text-sm',
|
|
};
|
|
|
|
export default function SegmentedControl<T extends string>({
|
|
value,
|
|
onChange,
|
|
options,
|
|
size = 'sm',
|
|
connected = false,
|
|
colorFn,
|
|
}: SegmentedControlProps<T>) {
|
|
if (connected) {
|
|
return (
|
|
<div
|
|
className="ss-segmented ss-segmented-connected inline-flex items-center gap-0.5 p-1 border border-muted bg-muted/40"
|
|
style={{ borderRadius: radius.sm }}
|
|
>
|
|
{options.map((opt) => {
|
|
const isActive = value === opt.value;
|
|
const color = colorFn?.(opt.value);
|
|
return (
|
|
<button
|
|
key={opt.value}
|
|
onClick={() => onChange(opt.value)}
|
|
className={`
|
|
ss-segmented-item inline-flex items-center ${sizeClasses[size]} transition-colors cursor-pointer font-medium
|
|
${isActive
|
|
? color ? '' : 'bg-surface text-pencil shadow-sm border border-muted'
|
|
: 'text-pencil-light hover:text-pencil border border-transparent'
|
|
}
|
|
`}
|
|
style={{
|
|
borderRadius: radius.sm,
|
|
...(isActive && color ? { backgroundColor: color, color: 'var(--color-paper)' } : {}),
|
|
}}
|
|
aria-pressed={isActive}
|
|
>
|
|
{opt.label}
|
|
{opt.count != null && (
|
|
<span className={`ml-1 ${isActive ? 'opacity-80' : 'opacity-50'}`}>
|
|
{opt.count}
|
|
</span>
|
|
)}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<div className="ss-segmented inline-flex items-center gap-1">
|
|
{options.map((opt) => {
|
|
const isActive = value === opt.value;
|
|
const color = colorFn?.(opt.value);
|
|
return (
|
|
<button
|
|
key={opt.value}
|
|
onClick={() => onChange(opt.value)}
|
|
className={`
|
|
ss-segmented-item inline-flex items-center ${sizeClasses[size]} border transition-all duration-150 cursor-pointer font-medium
|
|
${isActive
|
|
? color ? '' : 'bg-surface text-pencil border-muted-dark'
|
|
: 'bg-transparent text-pencil-light border-muted hover:border-muted-dark hover:text-pencil'
|
|
}
|
|
`}
|
|
style={{
|
|
borderRadius: radius.sm,
|
|
...(isActive
|
|
? color
|
|
? { backgroundColor: color, borderColor: color, color: 'var(--color-paper)', boxShadow: shadows.sm }
|
|
: {}
|
|
: {}),
|
|
}}
|
|
aria-pressed={isActive}
|
|
>
|
|
{opt.label}
|
|
{opt.count != null && (
|
|
<span className={`ml-1 ${isActive ? 'opacity-80' : 'opacity-50'}`}>
|
|
{opt.count}
|
|
</span>
|
|
)}
|
|
</button>
|
|
);
|
|
})}
|
|
</div>
|
|
);
|
|
}
|