Code Monkey home page Code Monkey logo

astrobook's Introduction

Astrobook

NPM version

A minimal and fast Storybook alternative. Powered by Astro.

astrobook

Quick start

Note

Astrobook supports React, Vue, Preact, Svelte, Solid, Lit and Astro components out of the box. We use React as an example here. Check the Astro docs for other integrations.

  1. Install the packages

    npm install astro @astrojs/react astrobook
  2. Create astro.config.mjs and add the astrobook integration

    // astro.config.mjs
    import { defineConfig } from 'astro/config'
    import react from '@astrojs/react'
    import astrobook from 'astrobook'
    
    // https://astro.build/config
    export default defineConfig({
      integrations: [react(), astrobook()],
    })
  3. Add scripts to your package.json

    "scripts": {
      "dev": "astro dev",
      "build": "astro build"
    }
  4. Write stories. Astrobook will scan all .stories.{ts,tsx,js,jsx,mts,mtsx,mjs,mjsx} files.

    // 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,
    }
  5. Run npm run dev and open http://localhost:4321 to see your stories.

Options

You can use the directory option to specify the directory to scan for stories. The default directory is current working directory.

// astro.config.mjs
import { defineConfig } from 'astro/config'
import astrobook from 'astrobook'

export default defineConfig({
  integrations: [
    astrobook({
      directory: 'src/components',
    }),
    /* ...other integrations */
  ],
})

Advanced

Toggle theme via message

If you're running Astrobook in an iframe, you can toggle the theme via a message.

const theme = 'light' // or "dark"
iframe.contentWindow.postMessage({ type: 'astrobook:set-theme', theme }, '*')

License

MIT

astrobook's People

Contributors

ocavue avatar github-actions[bot] avatar renovate[bot] avatar

Stargazers

Pink Champagne avatar Winston Fassett avatar  avatar 北雁云依 avatar Eva1ent avatar  avatar fwio avatar S.T.P avatar Yuhei Yasuda avatar 白熱 avatar P-Chan avatar Mirone avatar  avatar  avatar Naoya Yamamoto avatar Alexandr Zahatski avatar Roland avatar Sandalots avatar Chris Swithinbank avatar Miguel Colmenarez avatar Jaime Alan Gutiérrez Cruz avatar Felix Icaza avatar Vlad Gerasimov avatar Michael Shilman avatar Florian Lefebvre avatar Lubomir Anastasov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.