diff --git a/resources/boost/skills/saucebase-filament-development/SKILL.md b/resources/boost/skills/saucebase-filament-development/SKILL.md index 417ee72..38a6d39 100644 --- a/resources/boost/skills/saucebase-filament-development/SKILL.md +++ b/resources/boost/skills/saucebase-filament-development/SKILL.md @@ -98,6 +98,20 @@ and limits the form width. It also asks for `manage settings`, the permission fo page whose settings belong to the module's own admin area overrides `canAccess()` with that area's permission. +The form is written for the admin who opens it cold: + +- Every field sits in a `Section`, one per decision the admin makes (Billing: Payment provider, + Checkout, Subscriptions). Each section has a short heading, a one-line `description()` saying what + it controls, and an outlined Heroicon (`->icon(Heroicon::OutlinedPhoto)`). +- Help texts say what happens, in the admin's words. An `.env` key appears only as the way to change + something; class, tool and package names stay out. +- Empty fields show an example with `placeholder()`, and a select whose options come from another + field says what to fill in first. +- When something else overrides the page (test mode, a value in `.env`), a `Callout` at the top of + its section says so, visible only while it applies. + +Billing's and AI chat's settings pages follow this. + ## Admin Permission `access admin panel` only opens the panel. Every module's admin area is closed by its own permission, diff --git a/resources/js/tests/stories-docs.test.ts b/resources/js/tests/stories-docs.test.ts index 0048afe..5ab52a4 100644 --- a/resources/js/tests/stories-docs.test.ts +++ b/resources/js/tests/stories-docs.test.ts @@ -96,6 +96,24 @@ describe.each([ }); }); +// The toolbar's theme reaches a story through withThemeByClassName, a decorator: docs +// pages without stories (the design system's) never ran it and stayed light. A docs +// container, React like every docs page, follows the toolbar instead: one file for both. +it('gives every docs page the toolbar theme', () => { + const file = (stack: string, name: string) => + fs.readFileSync(path.join(STACKS, stack, 'js/.storybook', name), 'utf8'); + const container = file('vue', 'docs-theme.ts'); + + expect(file('react', 'docs-theme.ts')).toBe(container); + expect(container).toContain('GLOBALS_UPDATED'); + expect(container).toMatch(/classList\.toggle\('dark'/); + expect(container).toMatch(/base: 'dark'/); + for (const preview of [file('vue', 'preview.ts'), file('react', 'preview.tsx')]) { + expect(preview).toContain("from './docs-theme'"); + expect(preview).toMatch(/container:\s*DocsThemeContainer/); + } +}); + // 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', () => { diff --git a/stubs/stack/react/js/.storybook/docs-theme.ts b/stubs/stack/react/js/.storybook/docs-theme.ts new file mode 100644 index 0000000..8a52a52 --- /dev/null +++ b/stubs/stack/react/js/.storybook/docs-theme.ts @@ -0,0 +1,59 @@ +import { + DocsContainer, + type DocsContainerProps, +} from '@storybook/addon-docs/blocks'; +import { + createElement, + type PropsWithChildren, + useEffect, + useState, +} from 'react'; +import { GLOBALS_UPDATED } from 'storybook/internal/core-events'; +import { create } from 'storybook/theming'; + +// Docs pages in the app's own fonts, not Storybook's. +const fonts = { fontBase: 'var(--font-sans)', fontCode: 'var(--font-mono)' }; +const themes = { + light: create({ base: 'light', ...fonts }), + dark: create({ base: 'dark', ...fonts }), +}; + +type Globals = { theme?: string }; + +// The toolbar's value when the page opens. Docs contexts keep the globals in their store, +// which they don't declare: read it if it is there. +const initialTheme = (context: DocsContainerProps['context']) => + (context as unknown as { store?: { userGlobals?: { globals?: Globals } } }) + .store?.userGlobals?.globals?.theme; + +/** + * Every docs page in the toolbar's theme. The toolbar reaches a story through + * withThemeByClassName, a decorator, so pages without stories (the design system's) + * stayed light. Here Storybook's own blocks follow it through the docs theme, and the + * app's tokens through `.dark` on . A file of its own, the same in both stacks: + * docs pages are React whatever the stack. + */ +export function DocsThemeContainer({ + context, + children, +}: PropsWithChildren) { + const [theme, setTheme] = useState(() => initialTheme(context)); + + useEffect(() => { + const follow = ({ globals }: { globals: Globals }) => + setTheme(globals.theme); + context.channel.on(GLOBALS_UPDATED, follow); + + return () => context.channel.off(GLOBALS_UPDATED, follow); + }, [context.channel]); + + useEffect(() => { + document.documentElement.classList.toggle('dark', theme === 'dark'); + }, [theme]); + + return createElement( + DocsContainer, + { context, theme: themes[theme === 'dark' ? 'dark' : 'light'] }, + children, + ); +} diff --git a/stubs/stack/react/js/.storybook/preview.tsx b/stubs/stack/react/js/.storybook/preview.tsx index f3974e2..f99acd8 100644 --- a/stubs/stack/react/js/.storybook/preview.tsx +++ b/stubs/stack/react/js/.storybook/preview.tsx @@ -6,12 +6,12 @@ import addonDocs from '@storybook/addon-docs'; import addonThemes, { withThemeByClassName } from '@storybook/addon-themes'; import addonVitest from '@storybook/addon-vitest'; import { action } from 'storybook/actions'; -import { create } from 'storybook/theming'; import addonPseudoStates from 'storybook-addon-pseudo-states'; import addonTagBadges from 'storybook-addon-tag-badges'; import { definePreview } from '@storybook/react-vite'; import { registerNavigationDefaults } from '@/lib/navigation'; import { I18nProvider } from '@saucebase/react/i18n'; +import { DocsThemeContainer } from './docs-theme'; import { page } from './page'; // Ziggy's route(): Storybook has no routes, so every name exists, none is current, and a @@ -87,14 +87,8 @@ const preview = definePreview({ exclude: /^(asChild|testId|defaultValue|defaultOpen|defaultChecked)$/, }, - // Docs pages in the app's own fonts, not Storybook's. - docs: { - theme: create({ - base: 'light', - fontBase: 'var(--font-sans)', - fontCode: 'var(--font-mono)', - }), - }, + // Docs pages in the toolbar's theme and the app's own fonts. + docs: { container: DocsThemeContainer }, }, decorators: [ // Every story renders inside Inertia's App, so usePage() works, and inside the diff --git a/stubs/stack/vue/js/.storybook/docs-theme.ts b/stubs/stack/vue/js/.storybook/docs-theme.ts new file mode 100644 index 0000000..8a52a52 --- /dev/null +++ b/stubs/stack/vue/js/.storybook/docs-theme.ts @@ -0,0 +1,59 @@ +import { + DocsContainer, + type DocsContainerProps, +} from '@storybook/addon-docs/blocks'; +import { + createElement, + type PropsWithChildren, + useEffect, + useState, +} from 'react'; +import { GLOBALS_UPDATED } from 'storybook/internal/core-events'; +import { create } from 'storybook/theming'; + +// Docs pages in the app's own fonts, not Storybook's. +const fonts = { fontBase: 'var(--font-sans)', fontCode: 'var(--font-mono)' }; +const themes = { + light: create({ base: 'light', ...fonts }), + dark: create({ base: 'dark', ...fonts }), +}; + +type Globals = { theme?: string }; + +// The toolbar's value when the page opens. Docs contexts keep the globals in their store, +// which they don't declare: read it if it is there. +const initialTheme = (context: DocsContainerProps['context']) => + (context as unknown as { store?: { userGlobals?: { globals?: Globals } } }) + .store?.userGlobals?.globals?.theme; + +/** + * Every docs page in the toolbar's theme. The toolbar reaches a story through + * withThemeByClassName, a decorator, so pages without stories (the design system's) + * stayed light. Here Storybook's own blocks follow it through the docs theme, and the + * app's tokens through `.dark` on . A file of its own, the same in both stacks: + * docs pages are React whatever the stack. + */ +export function DocsThemeContainer({ + context, + children, +}: PropsWithChildren) { + const [theme, setTheme] = useState(() => initialTheme(context)); + + useEffect(() => { + const follow = ({ globals }: { globals: Globals }) => + setTheme(globals.theme); + context.channel.on(GLOBALS_UPDATED, follow); + + return () => context.channel.off(GLOBALS_UPDATED, follow); + }, [context.channel]); + + useEffect(() => { + document.documentElement.classList.toggle('dark', theme === 'dark'); + }, [theme]); + + return createElement( + DocsContainer, + { context, theme: themes[theme === 'dark' ? 'dark' : 'light'] }, + children, + ); +} diff --git a/stubs/stack/vue/js/.storybook/preview.ts b/stubs/stack/vue/js/.storybook/preview.ts index 73654b2..5c4c23c 100644 --- a/stubs/stack/vue/js/.storybook/preview.ts +++ b/stubs/stack/vue/js/.storybook/preview.ts @@ -5,7 +5,6 @@ import addonDocs from '@storybook/addon-docs'; import addonThemes, { withThemeByClassName } from '@storybook/addon-themes'; import addonVitest from '@storybook/addon-vitest'; import { action } from 'storybook/actions'; -import { create } from 'storybook/theming'; import addonPseudoStates from 'storybook-addon-pseudo-states'; import addonTagBadges from 'storybook-addon-tag-badges'; import { definePreview, setup } from '@storybook/vue3-vite'; @@ -21,6 +20,7 @@ import { import { registerNavigationDefaults } from '@/lib/navigation'; import { resolveLanguage } from '@saucebase/vue/lib/language'; import { i18nVue } from 'laravel-vue-i18n'; +import { DocsThemeContainer } from './docs-theme'; import { page } from './page'; // Ziggy's route(): Storybook has no routes, so every name exists, none is current, and a @@ -123,14 +123,8 @@ const preview = definePreview({ // control can't change it. Stories still set them in args. exclude: /^(as|asChild|by|testId|defaultValue|modelValue)$/, }, - // Docs pages in the app's own fonts, not Storybook's. - docs: { - theme: create({ - base: 'light', - fontBase: 'var(--font-sans)', - fontCode: 'var(--font-mono)', - }), - }, + // Docs pages in the toolbar's theme and the app's own fonts. + docs: { container: DocsThemeContainer }, }, decorators: [ // Every story renders inside Inertia's App, so usePage() works. A story sets its