diff --git a/demo/src/Demo.tsx b/demo/src/Demo.tsx index ce641cd..be2b158 100644 --- a/demo/src/Demo.tsx +++ b/demo/src/Demo.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import CircularProgressbar from 'react-circular-progressbar'; +import CircularProgressbar, { buildStyles } from 'react-circular-progressbar'; import classNames from 'classnames'; import { easeSinOut, easeQuadIn, easeQuadInOut, easeLinear, easeCubicInOut } from 'd3-ease'; @@ -41,17 +41,7 @@ function Demo() {
- { - const alpha = (100 + percentage) / 200; - return { - path: { - stroke: `rgba(62, 152, 199, ${alpha})`, - }, - }; - }} - /> +
@@ -64,8 +54,8 @@ function Demo() { - Customize props.text and props.className based on - percentage. + Customize props.text, props.styles, and{' '} + props.className based on percentage. } > @@ -88,7 +78,19 @@ function Demo() { } > - + { + const alpha = (100 + percentage) / 200; + return { + path: { + stroke: `rgba(62, 152, 199, ${alpha})`, + }, + }; + }} + /> diff --git a/src/buildStyles.ts b/src/buildStyles.ts new file mode 100644 index 0000000..9182768 --- /dev/null +++ b/src/buildStyles.ts @@ -0,0 +1,46 @@ +export default function buildStyles({ + rotation, + strokeLinecap, + textColor, + textSize, + pathColor, + pathTransitionDuration, + trailColor, + backgroundColor, +}: { + rotation?: number; + strokeLinecap?: string; + textColor?: string; + textSize?: string | number; + pathColor?: string | number; + pathTransitionDuration?: string | number; + trailColor?: string | number; + backgroundColor?: string | number; +}) { + const rotationTransform = rotation == null ? undefined : `rotate(${rotation}turn)`; + const rotationTransformOrigin = rotation == null ? undefined : 'center center'; + + return { + root: {}, + path: { + stroke: pathColor, + strokeLinecap: strokeLinecap, + transform: rotationTransform, + transformOrigin: rotationTransformOrigin, + transitionDuration: pathTransitionDuration, + }, + trail: { + stroke: trailColor, + strokeLinecap: strokeLinecap, + transform: rotationTransform, + transformOrigin: rotationTransformOrigin, + }, + text: { + fill: textColor, + fontSize: textSize, + }, + background: { + fill: backgroundColor, + }, + }; +} diff --git a/src/index.ts b/src/index.ts index 9cc6e50..21ffa40 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,5 @@ import CircularProgressbar from './CircularProgressbar'; +import buildStyles from './buildStyles'; +export { buildStyles }; export default CircularProgressbar;