Coder Social home page Coder Social logo

mtnorthrop / craft-storybook-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ben-rogerson/craft-storybook-starter

0.0 1.0 0.0 654 KB

๐Ÿฃ Everything you need to create a beautiful living style guide with Twig components.

License: The Unlicense

JavaScript 25.42% HTML 33.53% PHP 31.33% Batchfile 1.80% CSS 7.91%

craft-storybook-starter's Introduction

Craft CMS

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

Create a new project based on this template using degit:

npx degit ben-rogerson/craft-storybook-starter craft-storybook && cd $_ && npm install

Start Storybook with:

npm run storybook

Start Craft CMS setup:

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

craft-storybook-starter's People

Contributors

brandonkelly avatar ben-rogerson avatar carlcs avatar angrybrad avatar benjamindavid avatar mildlygeeky avatar tam avatar jasonmccallister avatar geenious avatar cromwellryan avatar

Watchers

Mark Northrop 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.