Git Product home page Git Product logo

progress-indicator's Introduction

React w/ Storybook Starter

Want to get up and running with a React application and Storybook?

This repo is a combination of Create React App and the Storybook CLI. The stories folder has been changed to components and a new Button component has been scaffolded and used in the application.

Using This Repo

  • git clone https://github.com/micahgodbolt/react-with-storybook-starter.git && cd react-with-storybook-starter
  • npm install
  • npm start (for the application)

or

  • npm run storybook (for storybook)

Below are the steps taken to get to where this repo is now. If you're starting a new application I'd recommend following them, as the CLI's may have been updated since this repo was created.

New Project Setup

  • npm install -g create-react-app
  • npm i -g @storybook/cli
  • create-react-app my-app
  • cd my-app
  • getstorybook
  • changed src/stories folder to src/components

Import all stories

The default configuration of Storybook only imports a single index file. Lets change that to import all of our story files.

Change ./.storybook/config.js to import all files matching *.stories.js as follows:

const req = require.context("../src/components", true, /.stories.js$/);
function loadStories() {
  req.keys().forEach(filename => req(filename));
}

Building components

Start building in the components folder with this folder structure

- ComponentName
  - Component.css
  - ComponentName.stories.js
  - ComponentName.jsx

Create src/components/Button and add Button.css, Button.jsx and Button.stories.js

Button.jsx will be:

import React, { Component } from 'react';
import './Button.scss';

export class Button extends Component {
  render() {
    return (
      <button className="Button" {...this.props}> {this.props.children} </button>
    );
  }
}

Button.stories.js will be:

import React from 'react';
import { storiesOf } from '@storybook/react';
import { Button } from './Button';

let stories = storiesOf('Button', module);

stories.add('Default', () =>
  <Button onClick={() => console.log("clicked!!")}>
    Hello Button
  </Button>
);

Button.css is just CSS, but will automatically be loaded when the component is used.

Run Storybook

npm run storybook

Add Button to App.js

import React, { Component } from 'react';
import './App.css';
import { Button } from './components/Button/Button';

class App extends Component {
  render() {
    return (
      <div className="App">
        <Button onClick={() => alert('i was clicked!')} > Click Me Please </Button>
      </div>
    );
  }
}

export default App;

Run the application

npm start

Adding Sass

Adding Sass isn't very difficult, but it does involve "ejecting" out of create react app. This process is out of the scope of this demo, but I'll include some links below.

progress-indicator's People

Contributors

micahgodbolt avatar oilus19 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.