### Install Astrobook Packages Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Install the necessary packages for Astrobook integration with Astro and React. This command assumes you are using npm. ```bash npm install astro @astrojs/react astrobook ``` -------------------------------- ### Configure Custom CSS Files Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Example of using the 'css' option to include custom CSS files in the Astrobook site. This allows for site-wide style customization. ```js import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ astrobook({ css: [ // Relative path to your custom CSS file './src/styles/custom.css', ], }), ], }) ``` -------------------------------- ### Configure Story Directory Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Example of configuring the 'directory' option in astrobook to specify a custom directory for scanning stories. Defaults to the current working directory. ```js import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ astrobook({ directory: 'src/components', }), /* ...other integrations */ ], }) ``` -------------------------------- ### Single Story Hoisting Example Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Demonstrates how to configure a story to be automatically hoisted in the UI when its name matches the module name and it's the only story exported. This avoids redundant nesting in the sidebar. ```ts // Button.stories.ts import { Button as ButtonComponent } from './Button.tsx' export default { component: ButtonComponent, } // Single named export. // Export name matches module name (Button.stories.ts) export const Button = {} ``` -------------------------------- ### Story File Format (CSF3) Example Source: https://context7.com/ocavue/astrobook/llms.txt Story files must have a default export with a `component` property and named exports for individual stories. Named exports can include `args` and `decorators`. ```typescript // src/components/Button.stories.ts import { Button, type ButtonProps } from './Button.tsx' // Default export: declares which component this file documents export default { component: Button, } // Named export: a story with specific args export const PrimaryButton = { args: { variant: 'primary', label: 'Click me' } satisfies ButtonProps, } export const SecondaryButton = { args: { variant: 'secondary', label: 'Cancel' } satisfies ButtonProps, } export const DisabledButton = { args: { variant: 'primary', label: 'Disabled', disabled: true } satisfies ButtonProps, } ``` -------------------------------- ### Vue Story Example with Different Steps Source: https://context7.com/ocavue/astrobook/llms.txt Define stories for a Vue component, including a default state and a state with a custom step value. Ensure the component is imported. ```typescript // src/components/vue/VueCounter.stories.ts import VueCounter from './VueCounter.vue' export default { component: VueCounter } export const Default = { args: {} } export const LargeStep = { args: { step: 5 } } ``` -------------------------------- ### React Story Example with Different Steps Source: https://context7.com/ocavue/astrobook/llms.txt Define stories for a React component, including a default state and a state with a custom step value. Ensure the component and its props type are imported. ```typescript // src/components/react/ReactCounter.stories.ts import { ReactCounter, type ReactCounterProps } from './ReactCounter' export default { component: ReactCounter } export const Default = { args: {} satisfies ReactCounterProps, } export const LargeStep = { args: { step: 5 } satisfies ReactCounterProps, } ``` -------------------------------- ### Configure Astrobook Subpath Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Example of configuring the 'subpath' option to specify the URL subpath for Astrobook within an existing Astro project. This allows Astrobook to be accessed at a custom route. ```js import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ astrobook({ subpath: '/playground', }), ], }) ``` -------------------------------- ### Story with Multiple Decorators Source: https://github.com/ocavue/astrobook/blob/master/README.md Example of how to apply multiple decorators to a story in Astrobook. The order of decorators in the array determines the nesting order of the applied styles. ```tsx // Button.stories.tsx import RedBorderDecorator from './AstroRedBorderDecorator.astro' import { Button, type ButtonProps } from './Button.tsx' import { GreenBorderDecorator } from './ReactGreenBorderDecorator.tsx' export default { component: Button, } export const PrimaryButton = { args: { variant: 'primary' } satisfies ButtonProps, decorators: [ { component: GreenBorderDecorator, props: { width: 10 } }, { component: RedBorderDecorator }, ], } ``` -------------------------------- ### Story with Multiple Decorators Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Example of applying multiple decorators (Astro and React) to a component within a story. The order of decorators in the list determines the nesting order of the applied styles. ```tsx import RedBorderDecorator from './AstroRedBorderDecorator.astro' import { Button, type ButtonProps } from './Button.tsx' import { GreenBorderDecorator } from './ReactGreenBorderDecorator.tsx' export default { component: Button, } export const PrimaryButton = { args: { variant: 'primary' } satisfies ButtonProps, decorators: [ { component: GreenBorderDecorator, props: { width: 10 } }, { component: RedBorderDecorator }, ], } ``` -------------------------------- ### Custom Head Component for Astrobook Source: https://github.com/ocavue/astrobook/blob/master/README.md Provide a path to an Astro component to inject custom tags into the `
` of your Astrobook site. This example shows how to load custom fonts and apply global styles. ```astro ``` -------------------------------- ### No Hoisting Example with Multiple Exports Source: https://context7.com/ocavue/astrobook/llms.txt If a story file exports multiple named stories, or if the single story name does not match the module name, hoisting will not occur. Both exports will appear under the module name in the sidebar. ```typescript // NoHoistMultiple.stories.ts — multiple exports: no hoisting import Counter from '../astro/AstroCounter.astro' export default { component: Counter } // Two exports → no hoisting, both appear under "NoHoistMultiple" export const Default = {} export const NoHoistMultiple = {} ``` -------------------------------- ### Write Astrobook Stories Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Example of a component story file using Astrobook's compatible subset of Storybook's Component Story Format v3. It defines a default export for the component and named exports for different story states with arguments. ```typescript // src/components/Button.stories.ts import { Button, type ButtonProps } from './Button.tsx' export default { component: Button, } export const PrimaryButton = { args: { variant: 'primary' } satisfies ButtonProps, } export const SecondaryButton = { args: { variant: 'secondary' } satisfies ButtonProps, } ``` -------------------------------- ### Configure Astrobook Subpath with Base Path Source: https://github.com/ocavue/astrobook/blob/master/README.md Demonstrates configuring both Astro's `base` path and Astrobook's `subpath`. Astrobook will be available at the combined path (e.g., `/docs/playground`). ```js // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ base: '/docs', integrations: [ astrobook({ subpath: '/playground', }), ], }) ``` -------------------------------- ### Configure Astro Project Base and Astrobook Subpath Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Illustrates how Astro's 'base' configuration interacts with Astrobook's 'subpath' option. Astrobook will be available at '/docs/playground' if the Astro project's base is '/docs'. ```js import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ base: '/docs', integrations: [ astrobook({ subpath: '/playground', }), ], }) ``` -------------------------------- ### Add Package Scripts Source: https://github.com/ocavue/astrobook/blob/master/README.md Add development, build, and preview scripts to your `package.json` file to manage your Astro project and Astrobook. ```json "scripts": { "dev": "astro dev", "build": "astro build", "preview": "astro preview" } ``` -------------------------------- ### Customize Built-In Home Page with `homeContent` Option Source: https://context7.com/ocavue/astrobook/llms.txt Tweak the title, subtitle, version badge, and GitHub badge of the default home page. Each field can be a string, object, or `false` to hide. ```typescript // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' import { version } from './package.json' export default defineConfig({ integrations: [ astrobook({ homeContent: { title: 'Acme UI', subtitle: 'Internal component library for Acme Corp', version: { label: `v${version}`, href: 'https://github.com/acme/ui/blob/main/CHANGELOG.md', }, repo: { href: 'https://github.com/acme/ui', label: 'View on GitHub', }, // To hide a field: set it to false // subtitle: false, }, }), ], }) ``` -------------------------------- ### Customize Built-in Homepage Content Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Configure the title, subtitle, version badge, and repository badge for the default home page. Fields can be set to custom values, `false` to hide, or omitted for defaults. This option is ignored if a custom `home` component is used. ```javascript // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' import { version } from './package.json' export default defineConfig({ integrations: [ astrobook({ homeContent: { title: 'Acme UI', subtitle: 'Internal component library', // Display your project's own version and link to your own changelog. version: { label: `v${version}`, href: 'https://example.com/CHANGELOG', }, // Customize the repository badge. repo: { href: 'https://github.com/acme/ui', label: 'View on GitHub', }, }, }), ], }) ``` -------------------------------- ### Development-Only Activation Source: https://context7.com/ocavue/astrobook/llms.txt Conditionally include Astrobook using `process.env.NODE_ENV` to prevent it from being bundled into production builds when embedded in an existing Astro site. ```typescript // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ // Astrobook available at /astrobook during development only process.env.NODE_ENV === 'development' ? astrobook({ subpath: '/astrobook' }) : null, ], }) ``` -------------------------------- ### Configure Custom CSS Source: https://github.com/ocavue/astrobook/blob/master/README.md Applies custom CSS to the Astrobook site by providing a path to a CSS file using the `css` option in `astro.config.mjs`. The path is relative to the project root. ```js // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ astrobook({ css: [ // Relative path to your custom CSS file './src/styles/custom.css', ], }), ], }) ``` -------------------------------- ### Activate Astrobook Integration Source: https://context7.com/ocavue/astrobook/llms.txt Call the `astrobook()` integration within `defineConfig.integrations` to activate Astrobook. This scans for stories, injects routes, and sets up necessary Vite virtual modules. ```typescript // astro.config.mjs import react from '@astrojs/react' import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ react(), astrobook(), // activates Astrobook at http://localhost:4321 ], }) ``` -------------------------------- ### Configure Astrobook Integration Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Add the astrobook integration to your Astro project's configuration file. This enables Astrobook's features within your project. ```javascript // astro.config.mjs import react from '@astrojs/react' import { defineConfig } from 'astro/config' import astrobook from 'astrobook' // https://astro.build/config export default defineConfig({ integrations: [react(), astrobook()], }) ``` -------------------------------- ### Inject Global CSS with `css` Option Source: https://context7.com/ocavue/astrobook/llms.txt Pass an array of CSS file paths to inject global styles into every Astrobook page. Supports local files and npm packages. ```typescript // astro.config.mjs — TailwindCSS integration import tailwindcss from '@tailwindcss/vite' import preact from '@astrojs/preact' import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ vite: { plugins: [tailwindcss()], }, integrations: [ preact(), astrobook({ css: [ './src/styles/global.css', // local file with @import 'tailwindcss' '@fontsource/inter', // npm font package ], }), ], }) ``` -------------------------------- ### Configure Astrobook Head Integration Source: https://github.com/ocavue/astrobook/blob/master/README.md Integrate Astrobook into your Astro project and specify a custom head component using the `head` option in `astro.config.mjs`. ```javascript // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ astrobook({ // Relative path to your custom head component head: './src/components/CustomHead.astro', }), ], }) ``` -------------------------------- ### Configure Multi-Framework Integrations in Astro Source: https://context7.com/ocavue/astrobook/llms.txt Register framework integrations like React, Preact, Solid, Svelte, and Vue in `astro.config.mjs` alongside `astrobook()` to enable multi-framework component support. ```typescript // astro.config.mjs — multi-framework setup import preact from '@astrojs/preact' import react from '@astrojs/react' import solid from '@astrojs/solid-js' import svelte from '@astrojs/svelte' import vue from '@astrojs/vue' import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ react({ include: ['**/react/*'] }), preact({ include: ['**/preact/*'] }), solid({ include: ['**/solid/*'] }), svelte(), vue(), astrobook({ directory: 'src/components' }), ], }) ``` -------------------------------- ### Configure Story Directory Source: https://github.com/ocavue/astrobook/blob/master/README.md Configures the directory Astrobook scans for stories using the `directory` option in `astro.config.mjs`. Defaults to the current working directory. ```js // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ astrobook({ directory: 'src/components', }), /* ...other integrations */ ], }) ``` -------------------------------- ### Customize Homepage with Astro Component Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Specify a path to an Astro component to replace the default dashboard homepage. If set to `false` or if a custom component is provided, `homeContent` is ignored. ```javascript // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ astrobook({ home: './src/components/CustomHome.astro', }), ], }) ``` -------------------------------- ### Story with Cross-Framework Decorator Chains Source: https://context7.com/ocavue/astrobook/llms.txt Stack decorators from various frameworks (Astro, React, Preact, Svelte, Vue) in a single story to create realistic rendering environments with per-framework context providers. ```typescript // decorators.stories.ts import { ReactCounter } from '../react/ReactCounter' import AstroDecorator from './AstroDecorator.astro' import PreactDecorator from './PreactDecorator' import ReactDecorator from './ReactDecorator' import SvelteDecorator from './SvelteDecorator.svelte' import VueDecorator from './VueDecorator.vue' export default { component: ReactCounter } export const MixedDecorators = { args: { step: 10 }, decorators: [ { component: AstroDecorator, props: { label: 'Astro' } }, { component: ReactDecorator, props: { label: 'React' } }, { component: PreactDecorator, props: { label: 'Preact' } }, { component: SvelteDecorator, props: { label: 'Svelte' } }, { component: VueDecorator, props: { label: 'Vue' } }, ], } ``` -------------------------------- ### Add Package Scripts Source: https://github.com/ocavue/astrobook/blob/master/packages/astrobook/README.md Include these scripts in your package.json to easily manage development, building, and previewing your Astro project with Astrobook. ```json "scripts": { "dev": "astro dev", "build": "astro build", "preview": "astro preview" } ``` -------------------------------- ### Add Custom `` Tags with `head` Option Source: https://context7.com/ocavue/astrobook/llms.txt Provide a path to an `.astro` or `.html` file to inject its content into the `` of every Astrobook page. Useful for fonts, analytics, or meta tags. ```astro ``` ```typescript // astro.config.mjs import { defineConfig } from 'astro/config' import astrobook from 'astrobook' export default defineConfig({ integrations: [ astrobook({ head: './src/components/CustomHead.astro', }), ], }) ``` -------------------------------- ### Replace Home Page with `home` Option Source: https://context7.com/ocavue/astrobook/llms.txt Replace the default Astrobook home page with a custom Astro component or disable it entirely by setting the option to `false`. ```astroBrowse and preview all UI components in one place.
Select a component from the sidebar to get started.