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
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,28 @@ why anything looks the way it does, and export the result.
### Components & labs

- A full component library (buttons, inputs, selection, navigation, feedback,
overlays, data display, tables, notifications) and SVG charts (line, area,
overlays, data display, tables, notifications, content and marketing blocks,
mobile patterns) and SVG charts (line, area,
bar, donut, radial, sparkline, scatter, waveform) that all read the active
style.
- Components Lab with desktop / tablet / mobile / custom viewports, rulers,
a responsive inspector and three-way style comparison.
- Labs for SVG backdrops, data visualisation, tables, notifications, motion,
materials and icons.

### Templates

- One fictional product, Orbit, in three templates built only from the
component library: a desktop landing site (7 pages), the same site on a
phone, and a mobile app (17 screens across onboarding, home, goals, wallet,
chat and account). Every style restyles all of them.
- Fully clickable with no backend: links, forms, dialogs, sheets, menus,
toasts, loading and empty states.
- Screen, Flow (every screen on one board) and A / B / C views, a live list of
the components on screen that outlines them in the frame, share links, a
full-screen preview, and an optional image of your own that stays in the
tab's memory.

### Generation

- Procedural engine 2.0: seed → personality → semantic recipe → compatibility
Expand Down Expand Up @@ -72,6 +86,7 @@ why anything looks the way it does, and export the result.
| ![Style detail](docs/public/screenshots/styles-detail.png) | ![Relationship map](docs/public/screenshots/styles-map.png) |
| ![Generator](docs/public/screenshots/generator.png) | ![Components Lab](docs/public/screenshots/components-lab.png) |
| ![Customizer](docs/public/screenshots/customizer.png) | ![Labs](docs/public/screenshots/labs.png) |
| ![Templates](docs/public/screenshots/templates.png) | ![Templates compared in three styles](docs/public/screenshots/templates-compare.png) |

**Live:** <https://chinto-lgtm.github.io/ui-explorer/> · **Docs:** <https://chinto-lgtm.github.io/ui-explorer/docs/> — both built from `main` by GitHub Actions.

Expand Down Expand Up @@ -119,7 +134,8 @@ src/
styles/ 30 built-in style definitions, treatments, docs, community loader
components/ ui primitives, charts, svg, layout, preview
features/ anatomy, compare, diff, inspector, mixer, export, search, shortcuts
pages/ Welcome, Dashboard, Styles, Generator, Components Lab, Labs, Customizer
pages/ Welcome, Dashboard, Styles, Generator, Components Lab, Templates, Labs, Customizer
templates/ the Orbit landing site and mobile app, their content and the component catalogue
styles/community/ community style packages + index.json
schemas/ JSON schema for a style definition
tools/style-engine/ Python engine + validator (see its README)
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default defineConfig({
items: [
{ text: 'Styles', link: '/guide/styles' },
{ text: 'Components', link: '/guide/components' },
{ text: 'Templates', link: '/guide/templates' },
{ text: 'Style Anatomy', link: '/guide/style-anatomy' },
{ text: 'Customizer', link: '/guide/customizer' },
{ text: 'Style Mixer', link: '/guide/style-mixer' },
Expand Down
3 changes: 2 additions & 1 deletion docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ generation, validation and sharing all run in the browser, and state lives in
▼
component library + treatments.css (bespoke construction per family)
│
pages: Dashboard · Styles · Generator · Components Lab · Labs · Customizer
pages: Dashboard · Styles · Generator · Components Lab · Templates · Labs · Customizer
```

## Layers
Expand All @@ -38,6 +38,7 @@ generation, validation and sharing all run in the browser, and state lives in
| Generator | `src/engine/generator/` | Seeded procedural engine (see [procedural-generation.md](procedural-generation.md)) |
| Sharing | `src/engine/share.ts` | `?style=<id>` / `?style=j.<payload>` links; generated styles carry seed + lineage |
| Components | `src/components/ui`, `charts`, `svg`, `preview` | Everything reads tokens; nothing hard-codes a style |
| Templates | `src/templates/`, `src/pages/Templates/` | Product screens (landing site, mobile app) built from the components; see [Templates](guide/templates.md) |
| Features | `src/features/*` | Anatomy, compare, diff, inspector, mixer, export, search, shortcuts |
| Pages | `src/pages/*` | Routed views; tool pages are code-split |
| Python engine | `tools/style-engine/` | Same algorithm for batch generation, CI validation and determinism tests |
Expand Down
6 changes: 5 additions & 1 deletion docs/guide/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,12 @@ focus behaviour.
| Feedback | Alerts, toasts, progress bars and rings, skeletons, spinners, empty states |
| Overlays | Modal, drawer, tooltip, popover, dropdown menu, context menu |
| Data | Avatars, lists, timeline, activity feed, stats, tables, charts |
| Content & marketing | Accordion, chips and chip groups, carousel, rating, pricing card, testimonial |
| Mobile patterns | Status bar, app bar, bottom tab bar, chat bubble, code input, bottom sheet |

Use the search box in the left panel to jump to a component.
Use the search box in the left panel to jump to a component. To see the
components working together in real product screens, open
[Templates](/guide/templates).

## Interaction states

Expand Down
125 changes: 125 additions & 0 deletions docs/guide/templates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
# Templates

**Templates** shows what a style looks like on a real product. Orbit is a
fictional personal-money app with three templates: a desktop landing site, the
same site on a phone, and the mobile app. Every screen is built only from the
component library, so switching the style in the header restyles all of them.

![Templates](/screenshots/templates.png)

## The three templates

| Template | Frame | Screens |
| --- | --- | --- |
| Desktop landing | 1440px browser | Home, Features, Pricing, About, Blog, Contact, Sign in |
| Mobile landing | 390px phone browser | The same seven pages, laid out for a phone |
| Mobile app | 390px phone | 17 screens in six flows (below) |

The landing site is **one responsive site**. Its layout responds to the width
of the frame through CSS container queries, not to the browser window. The
phone version is therefore the real responsive behaviour: a menu button that
opens a side drawer, stacked sections, swipeable testimonials and a compact
product demo.

The app screens are grouped into the flows a person walks through:

| Flow | Screens |
| --- | --- |
| Onboarding | Splash, Welcome (carousel), Sign in, Verify (6-digit code), Permissions |
| Everyday | Home, Discover, Notifications |
| Goals | Goal, New goal (three steps), Goal created |
| Money | Wallet: cards, card designer, charts, transactions, statements |
| Social | Chats, Chat with a playable voice note |
| Account | Profile, Settings, App states (loading, empty, error, offline) |

## Everything is clickable

There is no backend, but everything responds the way the real product would:

- Links and tabs move between screens.
- Forms validate.
- Dialogs, sheets, menus and popovers open and close.
- Toasts confirm actions.
- Loading and empty states appear when you filter.

A few examples to try:

- **Pricing:** switch to yearly or student pricing, then start a trial.
- **Sign in:** sign in with any password of six or more characters, then paste
any six digits as the code.
- **Blog:** filter or search until nothing matches.
- **Chat (app):** play the voice note, send a message, or right-click a
message for its menu.

## Viewing modes

The toolbar above the frame switches between three views:

- **Screen:** one screen at its true size, zoomed to fit. Use **Fit** or a
fixed zoom (50%, 75%, 100%) and the arrows to step through the screens.
- **Flow:** every screen of the template on one board, grouped by flow.
Click a thumbnail to open it.
- **A / B / C:** the same screen in three styles side by side. Pick each style
above its frame. Links you follow apply to all three frames.

![Comparing three styles](/screenshots/templates-compare.png)

## Components on this screen

The **Components** panel lists every library component rendered in the frame,
with a count for each. The list updates live as you interact, for example when
a dialog opens.

- Hover a name to outline those components in the frame.
- Click a name to scroll to the first one.
- **Opens on interaction** lists components behind a button, such as a modal
or a sheet.

In the Flow view the panel covers the whole template. Each template uses every
component in the library. The one exception is the desktop navigation bar,
which the app replaces with its tab bar. A test fails if a template stops
using a component.

Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>X</kbd> to turn on the token
inspector, then click any element in a frame to see the tokens behind it.

![The flow board](/screenshots/templates-flow.png)

## Sharing and full screen

- **Copy link** copies a URL that opens the same template, screen, view and
style. A custom or generated style travels inside the link, as everywhere
else in UI Explorer.
- **Full screen** opens `/preview/<template>/<screen>`, which shows only the
template. A small bar lets you change screen and style or go back. On a
phone, the app and the mobile site fill the screen edge to edge.

## Your own image

The templates ship without photos. Every picture slot draws art generated
from the active style instead. To see a real picture, use **Add an image** in
the left panel and every picture slot shows it. The image is never uploaded:
it stays in this browser tab's memory and is gone when you reload or press
**Remove**.

## How it is built

| Part | Where |
| --- | --- |
| Templates, screens and flows | `src/templates/registry.ts` |
| Story content (copy, numbers, people) | `src/templates/content.ts` |
| Landing site | `src/templates/landing/` with `landing.css` (container queries) |
| Mobile app | `src/templates/app/` with `app.css` |
| Themed screen container | `src/templates/TemplateScreen.tsx` |
| Component catalogue for the panel and tests | `src/templates/catalog.ts` |
| Viewer, frames, flow board, panel, full screen | `src/pages/Templates/` |

Template code reads only style tokens (`var(--color-*)`, `var(--radius-*)`
and so on), never literal colours. A test enforces this the same way the app
chrome is guarded. Overlays portal into the screen container, so modals and
sheets stay inside the device frame and carry that frame's style.

To add a screen, write a component that uses the library components and add
it to a template's screen list in `registry.ts`. Links inside a template call
`go('<screen id>')` from `useTemplateNav()`. The tests check that every
target exists.
3 changes: 3 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ features:
details: Switching a style changes radius, depth, borders, motion, icons, SVG language and component behaviour — not just colours. Every one of the 30 built-ins is documented.
- title: A real component library
details: Buttons, inputs, selection, navigation, feedback, overlays, tables, notifications and SVG charts all read the active style, with desktop, tablet and mobile framing.
- title: Real product templates
details: A landing site for desktop and mobile and a 17-screen mobile app, built only from the library and fully clickable, so you can judge a style on a real product.
- title: A procedural engine you can read
details: Seed → personality → recipe → compatibility → repair → tokens. Every decision is recorded and explained; the same seed reproduces the same style in the browser and in Python.
- title: Tools for understanding
Expand All @@ -38,6 +40,7 @@ features:
| --- | --- |
| Browse and compare the styles | [Styles](/guide/styles) |
| See how components change per style | [Components](/guide/components) |
| See a style on a whole product (site and app) | [Templates](/guide/templates) |
| Understand *why* a style looks the way it does | [Style Anatomy](/guide/style-anatomy) |
| Make my own style | [Creating a style](/creating-a-style) |
| Submit a style to the registry | [Community styles](/community-styles) · [Contributing](/contributing) |
Expand Down
Binary file added docs/public/screenshots/templates-compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/screenshots/templates-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/public/screenshots/templates.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 47 additions & 1 deletion src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react';
import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { beforeEach, describe, expect, it } from 'vitest';
import App from './App';
import { registry } from './engine/registry';
Expand Down Expand Up @@ -54,6 +54,52 @@ describe('UI Explorer — Integration & Engine Tests', () => {
expect(vars['--radius-md']).toBe('16px');
});

describe('Templates', () => {
beforeEach(() => { localStorage.setItem('ui_explorer_onboarded', '1'); });

it('opens the first landing page and lists the screens and components', async () => {
window.history.replaceState({}, '', '/templates');
render(<App />);
expect(await screen.findByRole('heading', { name: 'Templates' }, { timeout: 5000 })).toBeInTheDocument();
expect(window.location.pathname).toBe('/templates/landing-desktop/home');
expect(screen.getByRole('button', { name: /desktop landing/i })).toHaveAttribute('aria-pressed', 'true');
expect(await screen.findByRole('heading', { name: /money that moves with you/i })).toBeInTheDocument();
expect(screen.getByRole('complementary', { name: 'Components used' })).toBeInTheDocument();
// Frames carry their own treatment attributes; the shell canvas must not, or its rules would leak into them.
expect(document.querySelector('.style-preview-canvas')).not.toHaveAttribute('data-family');
expect(document.querySelector('.tpl-screen')).toHaveAttribute('data-family', 'neumorphic');
});

it('switches template and follows links inside a screen', async () => {
window.history.replaceState({}, '', '/templates/landing-desktop/home');
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: /mobile app/i }));
expect(window.location.pathname).toBe('/templates/app/home');
const tabs = await screen.findByRole('navigation', { name: 'Tabs' });
fireEvent.click(within(tabs).getByText('Wallet').closest('button')!);
expect(window.location.pathname).toBe('/templates/app/wallet');
});

it('shows every screen on the flow board', async () => {
window.history.replaceState({}, '', '/templates/app/home?view=flow');
render(<App />);
// Seventeen full screens make a large DOM, so query it directly rather than by role.
await waitFor(() => expect(document.querySelectorAll('.tp-thumb__open')).toHaveLength(17), { timeout: 8000 });
fireEvent.click(document.querySelector('.tp-thumb__open[aria-label="Open Wallet"]')!);
expect(window.location.pathname).toBe('/templates/app/wallet');
expect(window.location.search).toBe('');
}, 20000);

it('renders a full-screen preview outside the shell', async () => {
window.history.replaceState({}, '', '/preview/landing-desktop/pricing?style=cyberpunk');
render(<App />);
expect(await screen.findByRole('heading', { name: /simple, fair pricing/i })).toBeInTheDocument();
expect(screen.queryByText('UI Explorer')).toBeNull();
expect(document.querySelector('.tpl-screen')).toHaveAttribute('data-style', 'cyberpunk');
expect(screen.getByRole('link', { name: /templates/i })).toHaveAttribute('href', '/templates/landing-desktop/pricing');
});
});

describe('Procedural Engine & PRNG Determinism', () => {
it('guarantees identical PRNG output for identical seeds', () => {
const rng1 = createSeededRandom(847291);
Expand Down
6 changes: 5 additions & 1 deletion src/components/layout/AppShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export const AppShell: React.FC<AppShellProps> = ({ children }) => {
return () => window.removeEventListener('ui-explorer:open-diff', onOpenDiff);
}, []);

// Templates theme each frame themselves (three styles at once in A/B/C). The canvas must not carry
// the current style's treatment attributes there, or its descendant rules would leak into every frame.
const themedCanvas = !location.pathname.startsWith('/templates');

// Close the mobile drawer whenever the route changes.
useEffect(() => { setIsSidebarOpen(false); }, [location.pathname]);

Expand Down Expand Up @@ -142,7 +146,7 @@ export const AppShell: React.FC<AppShellProps> = ({ children }) => {
{isCompareActive ? (
<CompareView onOpenDiff={() => setIsDiffOpen(true)} />
) : (
<div className="style-preview-canvas" style={resolvedCssVars as React.CSSProperties} {...getStyleDataAttributes(renderedStyle)} data-experimental={settings.experimental ? '1' : undefined}>
<div className="style-preview-canvas" style={resolvedCssVars as React.CSSProperties} {...(themedCanvas ? getStyleDataAttributes(renderedStyle) : {})} data-experimental={settings.experimental ? '1' : undefined}>
{children}
</div>
)}
Expand Down
6 changes: 4 additions & 2 deletions src/components/svg/Backdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
className?: string;
/** Visual height of the decoration. */
height?: number;
/** stretch (default) fills any box by distorting the art; cover keeps its proportions and crops. */
fit?: 'stretch' | 'cover';
}

/** Map a generated SVG language to the most representative preset. */
export function presetForLanguage(svg: GeneratedSvgLanguage): BackdropPreset {

Check warning on line 25 in src/components/svg/Backdrop.tsx

View workflow job for this annotation

GitHub Actions / web

react(only-export-components)

src/components/svg/Backdrop.tsx:25:17: Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components.
if (svg.gradientType === 'aurora') return 'aurora';
if (svg.gradientType === 'mesh') return 'mesh';
if (svg.gradientType === 'metallic' || svg.metallicReflection > 0.5) return 'chrome';
Expand All @@ -39,14 +41,14 @@
* Procedural decorative SVG. The generator (or a style) chooses a preset and
* parameters; this component turns them into geometry. No raw markup is stored.
*/
export const Backdrop: React.FC<BackdropProps> = ({ preset, seed = 1, intensity = 0.6, density = 0.5, curve = 0.6, animate = true, className = '', height = H }) => {
export const Backdrop: React.FC<BackdropProps> = ({ preset, seed = 1, intensity = 0.6, density = 0.5, curve = 0.6, animate = true, className = '', height = H, fit = 'stretch' }) => {
const id = useId();
const rnd = useMemo(() => mulberry(seed + preset.length * 7919), [seed, preset]);
const shapes = useMemo(() => buildShapes(preset, rnd, intensity, density, curve), [preset, rnd, intensity, density, curve]);

return (
<div className={`ui-backdrop ui-backdrop--${preset} ${animate ? 'ui-backdrop--animate' : ''} ${className}`} style={{ height }} aria-hidden="true">
<svg viewBox={`0 0 ${W} ${H}`} preserveAspectRatio="none" className="ui-backdrop__svg">
<svg viewBox={`0 0 ${W} ${H}`} preserveAspectRatio={fit === 'cover' ? 'xMidYMid slice' : 'none'} className="ui-backdrop__svg">
<defs>
<linearGradient id={`${id}-a`} x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" stopColor="var(--color-accent)" stopOpacity={0.9} />
Expand Down
Loading
Loading