GithubHelp home page GithubHelp logo

trendingtechnology / react-component-octicons Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rhysd/react-component-octicons

0.0 2.0 0.0 853 KB

Zero-dependency React component for Octicons

Home Page: https://rhysd.github.io/react-component-octicons

License: Other

JavaScript 3.51% HTML 1.48% TypeScript 95.00%

react-component-octicons's Introduction

React Component for Octicons

Build Status NPM Version codecov

react-component-octicons is a React component library for the latest Octicons (v7.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

Watchers

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