Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d658c04
Add Storybook and a design system to the Vue and React stacks
roble Nov 24, 2026
b4bcb6b
Storybook: module stories, and server docgen in contributor checkouts
roble Nov 24, 2026
2b9534d
Show the welcome page's stories in contributor mode only
roble Nov 25, 2026
b1f3867
Header and Footer docs: room to scroll, open menus and the full water…
roble Nov 25, 2026
940e3ca
Wider docs pages, so full-width stories show their desktop layout
roble Nov 25, 2026
ef068df
Review fixes: node_modules link support, light tokens under a dark page
roble Nov 25, 2026
8f8a278
Merge nightly/2026-11-24-storybook: Storybook setup (Vue)
roble Nov 25, 2026
53aafcb
React Storybook: catch up with Vue's setup
roble Nov 25, 2026
33eaa48
React stories for every core component, with the QA fixes Vue got
roble Nov 25, 2026
310ceb6
Docs pages: one dialog per example, a label per checkbox
roble Nov 25, 2026
5081f2a
Merge nightly/2026-11-25-storybook-react: Storybook for React
roble Nov 25, 2026
45b2e20
feat: dashboard::sidebar.content slot between the nav and the bottom …
roble Nov 25, 2026
d97dae3
Tests run within 256M: the suite peaks at 129 MB, over PHP's default
roble Nov 25, 2026
50da127
fix: a contributor build has one copy of each package
roble Nov 25, 2026
821ecef
fix: translatable:export finds React's strings
roble Nov 25, 2026
de3e263
fix: an indeterminate checkbox shows a dash, filled like a checked one
roble Nov 25, 2026
c9cb1f9
feat: React InputField and InputPassword, as in Vue
roble Nov 25, 2026
f36f191
chore: Sonar findings on the Storybook PR
roble Nov 26, 2026
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
9 changes: 9 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,15 @@ jobs:
timeout-minutes: 2
run: ./node_modules/.bin/playwright install chromium --with-deps

# The design system: every story renders, and its play function passes.
- name: Execute the story tests
working-directory: app
run: npm run test:stories

- name: Build Storybook
working-directory: app
run: npm run storybook:build

# Playwright serves .env.e2e itself (laravelServer() in playwright.config.ts).
- name: Prepare the E2E environment
working-directory: app
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ tests/Fixtures/modules/*/resources/js/
/node_modules/
/resources/js/node_modules/
/stubs/stack/*/config/node_modules/

# Written by `saucebase stack --dev` in a contributor checkout: this machine's paths.
/stubs/stack/*/js/tsconfig.json
/stubs/stack/*/js/node_modules
6 changes: 4 additions & 2 deletions .sonarcloud.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Test files are tests, not product code: they are not measured for duplication.
# Test files are tests, not product code: they are not measured for duplication. Stories
# run as tests (`npm run test:stories`), and each stack has its own copy of them and of
# their Vitest config.
sonar.sources=.
sonar.tests=.
sonar.test.inclusions=tests/**,**/*.test.ts,**/*.test.tsx
sonar.test.inclusions=tests/**,**/*.test.ts,**/*.test.tsx,**/*.stories.ts,**/*.stories.tsx,stubs/stack/*/js/vitest.config.ts

# shadcn components are generated by its CLI and never edited by hand, so their findings
# are not ours to fix. `saucebase/` and `sonner/` hold our own components and stay
Expand Down
4 changes: 4 additions & 0 deletions config/laravel-translatable-string-exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
'*.vue',
'*.blade.php',
'*.ts',
'*.tsx',
],

// Indicates whether new lines are allowed in translations.
Expand All @@ -49,6 +50,9 @@
'@lang',
'\$t',
'trans',
// React's t(): each name goes into the exporter's regex with nothing before it, so
// a bare `t` would also match import('./x') and emit('submit').
'(?<![\w$.])t',
],

// Indicates whether you need to sort the translations alphabetically
Expand Down
4 changes: 4 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
<directory>src</directory>
</include>
</source>
<php>
<!-- The full suite peaks at about 129 MB, over PHP's default 128M. Tests only. -->
<ini name="memory_limit" value="256M"/>
</php>
</phpunit>
17 changes: 17 additions & 0 deletions resources/boost/skills/saucebase-module-development/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,23 @@ through `@/components`, `@/layouts` and `@/lib/utils`. The app's
`saucebase-frontend-development` skill lists exactly what is available. Never import a
`vendor/` path.

## Stories

A module's components get Storybook stories beside them, as core's do:
`resources/js/vue/components/Banner.stories.ts` and `resources/js/react/components/Banner.stories.tsx`.
Storybook and `npm run test:stories` find every module's stories for the app's stack; they list
under `Modules/`.

- Set `title: '<Module>/<Component>'`. Storybook adds the `Modules/` prefix.
- Import the preview as core's stories do (`import preview from '@/.storybook/preview'`) and
page fixtures from `@/.storybook/page`.
- A component that reads page props gets them per story with `parameters: { inertia: { … } }`.
Storybook merges parameters, so a story can override a meta's prop but not remove it.
- Every story is a test: it must render, and its `play` function must pass. Inertia visits are
cancelled and logged in the Actions panel, so a story never needs a server.
- A story of a component that fetches on render needs a network mock; there is none, so don't
write one for it.

## npm Packages

Every module has a `package.json` (the recipe creates it), with only `name` and `private` until
Expand Down
18 changes: 18 additions & 0 deletions resources/js/settings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import fs from 'node:fs';
import path from 'node:path';

/**
* The app's `saucebase.json`: its framework, contributor mode, server rendering and
* template. Read by the Vite preset and by Storybook's config, so both agree.
*/
export function readSettings(root: string): {
contributor?: boolean;
ssr?: boolean;
template?: string;
} {
const file = path.join(root, 'saucebase.json');

return fs.existsSync(file)
? JSON.parse(fs.readFileSync(file, 'utf-8'))
: {};
}
45 changes: 45 additions & 0 deletions resources/js/tests/design-system-colour.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { describe, expect, it } from 'vitest';
import * as react from '../../../stubs/stack/react/js/.storybook/design-system/colour.ts';
import * as vue from '../../../stubs/stack/vue/js/.storybook/design-system/colour.ts';

// The design-system pages grade each token pair against WCAG AA with these. The colours
// below are fixed samples, not read from theme.css: changing the theme never fails this.
describe.each([
['vue', vue],
['react', react],
])('%s design-system colour', (_, colour) => {
it('rates black on white 21 and a colour on itself 1', () => {
expect(colour.contrast([0, 0, 0], [255, 255, 255])).toBeCloseTo(21, 1);
expect(colour.contrast([239, 68, 68], [239, 68, 68])).toBe(1);
});

it("agrees with axe's ratios", () => {
// Pairs axe (Storybook's accessibility check) rated: white on red-500, and
// red-500 on a light grey.
expect(colour.contrast([255, 255, 255], [239, 68, 68])).toBeCloseTo(
3.76,
2,
);
expect(colour.contrast([239, 68, 68], [232, 235, 237])).toBeCloseTo(
3.14,
2,
);
});

it('is the same whichever colour comes first', () => {
expect(colour.contrast([107, 114, 128], [232, 235, 237])).toBe(
colour.contrast([232, 235, 237], [107, 114, 128]),
);
});

it('passes AA at 4.5 for text and 3 for interface parts', () => {
expect(colour.passes(4.5, 'text')).toBe(true);
expect(colour.passes(4.49, 'text')).toBe(false);
expect(colour.passes(3, 'ui')).toBe(true);
expect(colour.passes(2.99, 'ui')).toBe(false);
});

it('writes a colour as hex', () => {
expect(colour.hex([255, 107, 0])).toBe('#ff6b00');
});
});
30 changes: 30 additions & 0 deletions resources/js/tests/settings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import fs from 'node:fs';
import os from 'node:os';
import path from 'node:path';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { readSettings } from '../settings.ts';

let root: string;

beforeEach(() => {
root = fs.mkdtempSync(path.join(os.tmpdir(), 'saucebase-'));
});

afterEach(() => {
fs.rmSync(root, { recursive: true, force: true });
});

describe('readSettings()', () => {
it("reads the app's saucebase.json", () => {
fs.writeFileSync(
path.join(root, 'saucebase.json'),
'{"contributor": true, "ssr": false}',
);

expect(readSettings(root)).toEqual({ contributor: true, ssr: false });
});

it('is empty for an app without one', () => {
expect(readSettings(root)).toEqual({});
});
});
112 changes: 112 additions & 0 deletions resources/js/tests/stories-docs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import fs from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';

const STACKS = path.resolve(import.meta.dirname, '../../../stubs/stack');

describe.each([
['vue', 'ts'],
['react', 'tsx'],
])('%s Storybook', (stack, ext) => {
const PREVIEW = path.join(STACKS, stack, `js/.storybook/preview.${ext}`);

// Storybook reads the preview's tags without running it, and only from
// `const preview = definePreview({...}); export default preview;`. Any other
// export hides them, and every component silently loses its docs page.
it('gives every component a docs page', () => {
const source = fs.readFileSync(PREVIEW, 'utf8');

expect(source).toMatch(/tags:\s*\['autodocs'\]/);
expect(source).not.toMatch(/export (const|\{)/);
});

// Server docgen finds components by their real path. In a contributor checkout that
// is saucebase/core, outside the app's tsconfig: no props table, and "Show code"
// shows the story's source. There, the builder's docgen reads them instead.
it('documents components in a contributor checkout too', () => {
const source = fs.readFileSync(
path.resolve(path.dirname(PREVIEW), 'main.ts'),
'utf8',
);

// Installed apps, and contributor checkouts whose `saucebase stack --dev` wrote
// core a tsconfig (js/tsconfig.json): there server docgen reaches the components.
expect(source).toContain("fs.existsSync('resources/js/.storybook')");
expect(source).toContain(
"fs.existsSync(path.resolve(import.meta.dirname, '../tsconfig.json'))",
);
// vue-docgen-api, the builder's default, can't follow imported prop types
// (SidebarProps): their controls would be JSON boxes, or missing.
if (stack === 'vue') {
expect(source).toContain("docgen: 'vue-component-meta'");
}
});

// A full-width story (Header, Footer, layouts) renders in a frame as wide as the docs
// column. Storybook's 1000px column is under `lg` (1024px): every one of them would
// show its phone layout.
it('gives docs pages room for the desktop layout', () => {
const head = fs.readFileSync(
path.resolve(path.dirname(PREVIEW), 'preview-head.html'),
'utf8',
);
const width = Number(
/\.sbdocs\.sbdocs-content\s*\{[^}]*max-width:\s*(\d+)px/.exec(
head,
)?.[1],
);

expect(width).toBeGreaterThan(1024 + 100);
});

// In a contributor checkout `saucebase stack --dev` links node_modules beside the
// stories, where `../**/*.stories.ts` finds Storybook's own template stories.
it('runs no story tests from node_modules', () => {
const source = fs.readFileSync(
path.resolve(path.dirname(PREVIEW), '../vitest.config.ts'),
'utf8',
);

expect(source).toContain("exclude: ['**/node_modules/**']");
});

// Stories of the welcome page's parts are for Saucebase's own team. Contributor mode
// comes from saucebase.json, never from core being symlinked: a contributor checkout
// can run a released core.
it('shows contributor-only stories in contributor mode alone', () => {
const dir = path.dirname(PREVIEW);
const main = fs.readFileSync(path.resolve(dir, 'main.ts'), 'utf8');

expect(main).toContain('readSettings(process.cwd())');
expect(main).toMatch(
/contributor:\s*\{\s*hideFromSidebar:\s*!contributor\s*\}/,
);
expect(main).not.toMatch(/isSymbolicLink/);

for (const name of ['ModuleCard', 'ModuleModal']) {
const story = fs.readFileSync(
path.resolve(
dir,
`../components/ui/saucebase/${name}.stories.${ext}`,
),
'utf8',
);
expect(story).toMatch(/tags:\s*\['contributor'\]/);
}
});
});

// The design-system pages are MDX, rendered by Storybook's React whatever the stack: one
// page, kept the same in both.
it('has the same design-system pages in both stacks', () => {
const dir = (stack: string) =>
path.join(STACKS, stack, 'js/.storybook/design-system');
const files = fs.readdirSync(dir('vue'));

expect(fs.readdirSync(dir('react'))).toEqual(files);
for (const file of files) {
expect(fs.readFileSync(path.join(dir('react'), file), 'utf8')).toBe(
fs.readFileSync(path.join(dir('vue'), file), 'utf8'),
);
}
});
32 changes: 32 additions & 0 deletions resources/js/tests/ui-boundary.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import fs from 'node:fs';
import path from 'node:path';
import { describe, expect, it } from 'vitest';

const STACK = path.resolve(import.meta.dirname, '../../../stubs/stack');

// App composites and app glue may know the app; the primitives under them may not.
const EXEMPT = [/\/ui\/saucebase\//, /\/ui\/sonner\/Wrapper\.vue$/];

function primitives(framework: 'vue' | 'react'): string[] {
const ui = path.join(STACK, framework, 'js/components/ui');

return (fs.readdirSync(ui, { recursive: true }) as string[])
.map((file) => path.join(ui, file))
.filter(
(file) => /\.(vue|ts|tsx)$/.test(file) && !/\.stories\./.test(file),
)
.filter((file) => !EXEMPT.some((pattern) => pattern.test(file)));
}

describe.each(['vue', 'react'] as const)('%s ui/ primitives', (framework) => {
// Props in, events out: they render in Storybook and in any page without an Inertia app.
it('take their data as props, not from Inertia or Ziggy', () => {
const coupled = primitives(framework).filter((file) =>
/from ['"](@inertiajs\/|ziggy-js)/.test(
fs.readFileSync(file, 'utf8'),
),
);

expect(coupled.map((file) => path.relative(STACK, file))).toEqual([]);
});
});
Loading