项目作者: reviz

项目描述 :
SVG prop types for React
高级语言: JavaScript
项目地址: git://github.com/reviz/svg-prop-types.git
创建时间: 2017-09-04T15:24:21Z
项目社区:https://github.com/reviz/svg-prop-types

开源协议:MIT License

下载


svg-prop-types

Build Status

Custom SVG prop types for React.

SVG content type:

SVG and HTML attributes sets:

  • shape contains common shapes attributes
  • conditionalProcessing
  • core contains core HTML attributes
  • graphicalEvent contains graphical events attributes
  • documentEvent contains document events attributes
  • presentation contains presentational attributes

SVG elements:

  • SVG
  • circle
  • line

Usage

  1. import React, { Component } from 'react';
  2. import { circle as circlePropType } from 'svg-prop-types';
  3. class Circle extends Component {
  4. static propTypes = circlePropType;
  5. render() {
  6. return (
  7. <circle
  8. {...this.props}
  9. ></circle>
  10. );
  11. }
  12. }
  13. export default Circle;

Production

Build pipeline is borrowed from https://github.com/airbnb/prop-types

Since PropTypes are typically not included in production builds of React, this library’s functionality serves no useful purpose. As such, when the NODE_ENV environment variable is “production”, instead of exporting the implementations of all these prop types, we export mock functions - in other words, something that ensures that no exceptions are thrown, but does no validation. When environment variables are inlined (via a browserify transform or webpack plugin), then tools like webpack or uglify are able to determine that only the mocks will be imported - and can avoid including the entire implementations in the final bundle that is sent to the browser. This allows for a much smaller ultimate file size, and faster in-browser performance, without sacrificing the benefits of PropTypes themselves.

Tests

Simply clone the repo, npm install, and run npm test