npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

craft-storybook-starter

v1.1.1

Published

<p><img width="100%" src="https://i.imgur.com/79NC4st.png" alt="Craft CMS"></p>

Downloads

16

Readme

Craft Storybook Starter

Storybook is an open source tool for developing UI components in isolation. It makes building stunning UIs organized and efficient.

🎉 Storybook runs outside Craft in JavaScript and doesn't require a Craft plugin 🎉 Storybook works with the same Twig files from your project with some differences

This starter sets up everything for you to be productive in Storybook.Use Storybook to create a living styleguide from of your existing site/app. Take advantage of the excellent Webpack dev server to create solid components with mock data.

Storybook Features

This starter has many modern features including:

👍 Hot module reloading 👍 Automatic accessibility tests 👍 Color accessibility tests 👍 Fake data generator (Faker) 👍 Sass support 👍 Device previews 👍 Extendable Webpack config 👍 Static site generator

View the Storybook demo 👉

Getting Started

Create a new project

  1. In your terminal, cd into your projects directory then run: git clone https://github.com/ben-rogerson/craft-storybook-starter.git craft-storybook && cd $_ && npm install
  2. Start Storybook with: npm run storybook

To setup Craft CMS, run this command and follow the instructions: composer install && ./craft setup

Bring into an existing project

Adding Storybook into your project is a quick process:

  1. Grab the repository:git clone https://github.com/ben-rogerson/craft-storybook-starter.git

  2. Copy these folders into your project: .storybook stories templates/components

  3. Install the Storybook devDependencies:

    npm i -D @babel/core @babel/preset-env @storybook/addon-a11y @storybook/addon-knobs @storybook/addon-viewport @storybook/html faker babel-loader css-loader node-sass sass-loader style-loader twig twig-loader webpack-cli
  4. Add these script definitions into your package.json:

    "scripts": {
        "storybook": "start-storybook",
        "build-storybook": "build-storybook -c .storybook -o build"
    },
  5. Start Storybook with: npm run storybook

Working with Storybook

  1. Create a normal Twig file somewhere in your templates folder: Eg: /templates/components/[component].twig
  2. Add a matching story in the stories folder: Eg: /stories/[component].stories.js
  3. Start Storybook with: npm run storybook

Hosting your Storybook

Storybook builds static file previews for your components. This means you can leverage easy (and free) hosting services like Netlify.

Configure it to run npm run build-storybook and serve from the /build folder.

You could also use Github pages to host your storybook.

A heads up: Storybook Twig != Craft Twig

Storybook uses a JavaScript implementation of Twig and you may come across some of its limitations.

  • Any Craft or Craft Plugin functions, or Twig tags or filters will throw an error
  • String interpolation isn’t supported
  • ~~Importing components within components isn't supported (perhaps fixable with Webpack adjustments)~~Importing now works correctly

While I agree that this isn’t ideal, there is an upside to it. It forces small and basic components. You see this same technique constantly in modern JavaScript apps and it’s a good thing! It’s a technique you can also bring to many of your Craft Components. If you’re interested in the concept check out Atomic design.

If you’re bringing components into Storybook and you’re having compatibility issues you may need to break it up into a presentational and logic component. The presentational component would have the basic component html and wouldn’t contain the incompatible Twig code. This would be the component you’d display in Storybook.

Links