项目作者: scriptex

项目描述 :
SVG donut component for React
高级语言: JavaScript
项目地址: git://github.com/scriptex/react-svg-donuts.git
创建时间: 2018-10-31T05:59:24Z
项目社区:https://github.com/scriptex/react-svg-donuts

开源协议:MIT License

下载


Travis CI
Github Build
Codacy Badge
Codebeat Badge
CodeFactor Badge
DeepScan grade
Analytics

React SVG Donuts

A React component for simple (and complex) SVG donuts.

The current version depends on the Hooks API introduced with React 16.8. If you need legacy React support, please use a 1.x.x version.

Visitor stats

GitHub stars
GitHub forks
GitHub watchers
GitHub followers

Code stats

GitHub code size in bytes
GitHub repo size
GitHub language count
GitHub top language
GitHub last commit

Demo

TL;DR here is the demo

Dependencies

  1. NodeJS
  2. NPM / Yarn
  3. React and ReactDOM
  4. A ReactJS application

Usage

First install the package

  1. $ npm i react-svg-donuts
  2. # or
  3. $ yarn add react-svg-donuts

Then

  1. import React from 'react';
  2. import { Donut, ComplexDonut } from 'react-svg-donuts';
  3. // The donut will be half filled
  4. const progress = 50;
  5. // The value will be wrapped inside a <strong> tag.
  6. const renderProgress = progress => <strong>{progress}%</strong>;
  7. const MyComponent = () => (
  8. <>
  9. <Donut progress={progress} onRender={renderProgress} ></Donut>, document.getElementById('demo')
  10. <ComplexDonut
  11. size={200}
  12. parts={[
  13. {
  14. color: '#FF8A80',
  15. value: 230
  16. },
  17. {
  18. color: '#FF80AB',
  19. value: 308
  20. },
  21. {
  22. color: '#B9F6CA',
  23. value: 520
  24. },
  25. {
  26. color: '#B388FF',
  27. value: 130
  28. },
  29. {
  30. color: '#8C9EFF',
  31. value: 200
  32. }
  33. ]}
  34. radius={80}
  35. thickness={40}
  36. startAngle={-90}
  37. ></ComplexDonut>
  38. </>
  39. );

Props

Donut props

Prop Type Required Default Description
prefix string false ‘donut’ String used as a prefix for the CSS class names
progress number false 0 A number between 0 and 100
onRender Function false (progress) => {progress} Function which runs after the Donut is rendered and returns a ReactNode

Complex donut props

Prop Type Required Default Description
size number false 160 The width and height of the donut
parts { color: string; value: number; }[] false [] The donut parts
radius number false 60 The radius of the element
className string false ‘’ Custom CSS class name for the Donut
thickness number false 30 Stroke width of the element
textProps SVGProps for SVGTextElement false {} Additional props for the element
startAngle number false -90 Number between -360 and 360
circleProps SVGProps for SVGCircleElement false {} Additional props for the element

CSS

There is a predefined stylesheet which can be used as is.
If you want it, just import it:

  1. @import 'react-svg-donuts/src/index.css';

or

  1. import 'react-svg-donuts/src/index.css';

LICENSE

MIT



Connect with me:




Support and sponsor my work: