Code Monkey home page Code Monkey logo

react-component-octicons's Introduction

React Component for Octicons

Build Status NPM Version codecov

Octicons now support React officially. I recommend to try it at first.

react-component-octicons is a React component library for the latest Octicons (v8.x). This library wraps SVG icons and provides one React component <Octicon/>. Built by and ready for TypeScript.

This library has no dependency because all <svg> elements for octicons are embedded in library. You don't need any source code bundler to use this library.

To see the catalog of icons, please visit the document page built with Storybook.

Installation

$ npm install --save react-component-octicons

Usage

<Octicon/> component has a required property name and optional properties zoom, style.

import * as React from 'react';
import { render } from 'react-dom';
import Octicon from 'react-component-octicons';

render(
    <div>
        // Normal size
        <Octicon name="alert" />

        // Twice bigger
        <Octicon name="star" zoom="x2" />

        // Size 100px x 100px
        <div style={{width: '100px', height: '100px'}}>
            <Octicon name="flame" zoom="100%" />
        </div>

        // Styled icon
        <Octicon name="flame" zoom="100%" style={{color: 'blue'}}/>
    </div>,
    document.getElementById('root'),
);

name property (required)

name is a symbol name for an icon. Symbol names are described in Octicons document.

zoom property (optional)

zoom is a string value and it represents the zoom factor of the icon.

  • x{N}: N is a number (integer or float). Zoom the icon by xN (i.e. x4 means 4 times bigger than normal).
  • N%: N is a number between 0~100. It means N% size of its parent element. So 100% means to fit to the parent element.

style property (optional)

style is a CSS property to specify the style of the icon itself. The styles are applied to underlying <svg> element.

className property (optional)

className is a class name of underlying <svg> element.

Typo Safety for Icon Names

name property of <Octicon/> is restricted to actual symbol names. For example, following code contains typo allow-right (arrow-right is correct).

// ERROR! 'allow-right' is typo of 'arrow-right'
render(
    <Octicon name="allow-right" />,
    document.getElementById('root'),
);

It falls into a compilation error.

test.tsx(5,17): error TS2322: Type '{ name: "allow-right"; }' is not assignable to type 'IntrinsicAttributes & IntrinsicClassAttributes<Octicon> & Readonly<{ children?: ReactNode; }> & R...'.
  Type '{ name: "allow-right"; }' is not assignable to type 'Readonly<OcticonProps>'.
    Types of property 'name' are incompatible.
      Type '"allow-right"' is not assignable to type 'OcticonSymbol'.

Development

Following is a process to develop this library.

$ # Install all development dependencies
$ npm install

$ # Build the library and run all unit tests
$ npm test

$ # See manually if the library is working
$ # Open http://localhost:4321 in your browser
$ npm run smoke-test

$ # Run storybook locally on port 6006
$ npm run storybook

$ # Build storybook (catalog site) in docs/ directory
$ npm run build-storybook

License

Distributed under the MIT License.

react-component-octicons's People

Contributors

rhysd avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-component-octicons's Issues

Version 1.7.0 can't be minified with `create-react-app`

I have build an app using create-react-app (using a TS variant of it. Specifically react-scripts-ts version 2.13.0), and when running the latest version of react-component-octicons, I am getting a build time error when create-react-app tries to minify the code:

Failed to minify the code from this file:

 	./node_modules/react-component-octicons/index.js:4

Read more here: http://bit.ly/2tRViJ9

error Command failed with exit code 1.

This worked fine on version 1.6.0, let me know if you need any more information :)

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.