Skip to content

Commit

Permalink
Added track width as optional props (#34)
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas Berg <andreas@edupihi.eu>
  • Loading branch information
andreas-berg and pihiandreas committed Dec 1, 2023
1 parent e56e97f commit f8a4502
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default () => {
return (
<CircularSlider
size={200}
trackWidth={4}
minValue={0}
maxValue={100}
startAngle={40}
Expand Down
7 changes: 7 additions & 0 deletions docs-src/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export const ApiDocs: React.FunctionComponent = () => {
type: "number",
description: "Width and height of slider",
},
{
name: "trackWidth",
required: false,
default: "4",
type: "number",
description: "Width of the track",
},
{
name: "handle1",
required: true,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"postpublish": "PACKAGE_VERSION=$(echo 'const p = require(\"./package.json\"); process.stdout.write(p.version)' | node) && git tag v$PACKAGE_VERSION && git push --tags",
"test": "eslint src/** && prettier --check src/**",
"build": "rm -rf ./dist ./docs && prettier --write src/** docs-src/** && webpack && tsc",
"watch-docs": "webpack serve"
"watch-docs": "webpack serve",
"prepare": "npm run build"
},
"repository": {
"type": "git",
Expand Down
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { arcPathWithRoundedEnds } from "./svgPaths";

type Props = {
size: number;
trackWidth: number;
minValue: number;
maxValue: number;
startAngle: number; // 0 - 360 degrees
Expand Down Expand Up @@ -38,6 +39,7 @@ export class CircularSlider extends React.Component<
static defaultProps: Pick<
Props,
| "size"
| "trackWidth"
| "minValue"
| "maxValue"
| "startAngle"
Expand All @@ -47,6 +49,7 @@ export class CircularSlider extends React.Component<
| "handleSize"
> = {
size: 200,
trackWidth: 4,
minValue: 0,
maxValue: 100,
startAngle: 0,
Expand Down Expand Up @@ -185,6 +188,7 @@ export class CircularSlider extends React.Component<
render() {
const {
size,
trackWidth,
handle1,
handle2,
handleSize,
Expand All @@ -198,7 +202,6 @@ export class CircularSlider extends React.Component<
arcBackgroundColor,
outerShadow,
} = this.props;
const trackWidth = 4;
const shadowWidth = 20;
const trackInnerRadius = size / 2 - trackWidth - shadowWidth;
const handle1Angle = valueToAngle({
Expand Down

0 comments on commit f8a4502

Please sign in to comment.