GithubHelp home page GithubHelp logo

kryndex / ui-components Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weaveworks/ui-components

0.0 1.0 0.0 659 KB

A collection of UI components that are shared across Weaveworks projects

JavaScript 93.30% CSS 6.70%

ui-components's Introduction

npm version Circle CI

See it in action:

http://weaveworks-ui-components.s3-website-us-west-2.amazonaws.com/

Prerequisites

  • React & ReactDOM ^16.0.0
  • lodash ^4.0.0
  • styled-components ^2.0.0
  • moment ^2.0.0
  • font-awesome ^4.0.0

Installation

yarn add weaveworks-ui-components

import React from 'react';
import ReactDOM from 'react-dom';

import { WeaveLogo } from 'weaveworks-ui-components';

ReactDOM.render(
  <WeaveLogo />,
  document.getElementById('logo')
);

Importing Styles

To import the stylesheets, you must have a webpack Sass loader configured:

module.exports = {
  ...
  module: {
    loaders: [
      {
        test: /\.(scss|css)$/,
        loader: 'style-loader!css-loader!sass-loader'
      }
    ]
  },
  sassLoader: {
    includePaths: [
      path.resolve(__dirname, './node_modules/weaveworks-ui-components')
    ]
  }
  ...
}

To import styles:

@import "~weaveworks-ui-components/styles.scss";

Development

Adding a component

  1. Place your component in a src/components/<component name>/ directory.
  2. Add a file called index.js to your component directory. Add export statements, like so:
export Menu from './Menu';
export MenuItem from './MenuItem';

export default from './Menu';
  1. Add some tests to the same directory with a .test.js suffix.
  2. Document your module by adding comments. See the <Button /> component for an example. The react-docgen library is used to parse comments, which are then rendered as markdown.
  3. (Optional) Add an example implementation of your component in its directory. Call the file example.js. If no example.js file is added, the component itself (with default props) will be rendered in the component library UI.
  4. Export the component from the library by adding an export statement to src/components/index.js. There is a unit test that will check that all components are exported; run tests using npm test.

To develop a component locally, start the webpack-dev-server using npm start. Any components in the src/components directory will auto-magically be visible in the left-hand navigation. Editing a component will hot-reload it in the page. NOTE: when adding a component file for the first time, you will need to restart the webpack-dev-server to see the component appear in the navigation.

Parallel development with LocalModuleProxy

It is possible to proxy module imports to a local copy of the weaveworks-ui-components repository to allow for parallel development. For example, if you want to add a new component to your project, but you want to re-use the component on other projects, you can do you can add a component in the ui-components/src/components directory, then add the LocalModuleProxy resolver plugin to your webpack config:

const webpack = require('webpack');
const LocalModuleProxy = require('weaveworks-ui-components/resolvers').LocalModuleProxy;
const COMPONENT_LIB_PATH = '/Users/myusername/path/to/ui-components';

module.exports = {
  ...
  plugins: [
    new webpack.ResolverPlugin(new LocalModuleProxy({
      moduleName: 'weaveworks-ui-components',
      path: `${COMPONENT_LIB_PATH}/src/components/index.js`
    }))
  ]
}

You can also proxy multiple modules by adding a lookup to the modules key in the LocalModuleProxy constructor:

plugins: [
  new webpack.ResolverPlugin(new LocalModuleProxy({
    enabled: true,
    modules: {
      'weave-scope/reducer': `${SCOPE_COMPONENT_PATH}/client/app/scripts/reducers/root.js`,
      'weave-scope/component' : `${SCOPE_COMPONENT_PATH}/client/app/scripts/components/app.js`
    }
  }))
]

Webpack will resolve imports that match moduleName from the path supplied to the path key. This should work for all webpack-related functionality, including hot reload.

One weird trick to remove the COMPONENT_LIB_PATH variable from version control:

In your .bash_profile or equivalent:

export COMPONENT_LIB_PATH="/absolute/path/to/ui-components"

In your webpack.config.js:

module.exports = {
  ...
  plugins: [
    new webpack.ResolverPlugin(new LocalModuleProxy({
      moduleName: 'weaveworks-ui-components',
      path: `${process.env.COMPONENT_LIB_PATH}/src/components/index.js`
    }))
  ]
}

Exclude proxied modules from preLoaders

Since the request for weaveworks-ui-components is no longer resolving to node_modules, you may need to add an additional clause to the exclude option in your webpack preLoaders:

// Change this:
preLoaders: [
  {
    test: /\.js$/,
    exclude: /node_modules|vendor/,
    loader: 'eslint-loader'
  }
]

// To this:
preLoaders: [
  {
    test: /\.js$/,
    exclude: new RegExp(`node_modules|vendor|${process.env.COMPONENT_LIB_PATH}`),
    loader: 'eslint-loader'
  }
],

Releasing this repo

Configure your AWS CLI tools: http://docs.aws.amazon.com/cli/latest/userguide/installing.html.

Run yarn publish and enter the new version. This will build and publish the new version, as well as pushing static files to S3.

After publishing, commit the version change and push to master.

Adding Style Guide articles

To add a page to the style guide:

  1. Add a markdown file to the /styleguide directory of this repo
  2. ???
  3. Profit

ui-components's People

Contributors

aaron7 avatar bia avatar bowenli avatar davkal avatar fbarl avatar foot avatar jpellizzari avatar rndstr 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.