Skip to content

Commit

Permalink
default skin, README, LICENSE
Browse files Browse the repository at this point in the history
  • Loading branch information
hugozap committed Feb 13, 2018
1 parent 0879a02 commit e992b52
Show file tree
Hide file tree
Showing 10 changed files with 223 additions and 49 deletions.
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2018 Hugo Zapata

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 changes: 17 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# [WIP] React Rotary Knob

[Demo](https://github.io/hugozap/react-rotary-knob/storybook)

(Work in progress, please come back in a few days)


Precise rotary knob for React

## Features

- Drag away from knob to increase precision.
- Skinnable with SVG

### TODO

* Mobile touch events
Binary file added docs/storybook/favicon.ico
Binary file not shown.
20 changes: 20 additions & 0 deletions docs/storybook/iframe.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
<base target="_parent">
<script>
if (window.parent !== window) {
window.__REACT_DEVTOOLS_GLOBAL_HOOK__ = window.parent.__REACT_DEVTOOLS_GLOBAL_HOOK__;
}
</script>
<title>Storybook</title>

</head>
<body>
<div id="root"></div>
<div id="error-display"></div>
<script type="text/javascript" src="static/preview.a39257acbe7841c5219b.bundle.js"></script></body>
</html>
44 changes: 44 additions & 0 deletions docs/storybook/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="storybook-version" content="3.3.13">
<meta content="IE=edge" http-equiv="X-UA-Compatible" />
<title>Storybook</title>
<style>
/*
When resizing panels, the drag event breaks if the cursor
moves over the iframe. Add the 'dragging' class to the body
at drag start and remove it when the drag ends.
*/
.dragging iframe {
pointer-events: none;
}

/* Styling the fuzzy search box placeholders */
.searchBox::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: #ddd;
font-size: 16px;
}

.searchBox::-moz-placeholder { /* Firefox 19+ */
color: #ddd;
font-size: 16px;
}

.searchBox:focus{
border-color: #EEE !important;
}

.btn:hover{
background-color: #eee
}
</style>


</head>
<body style="margin: 0;">
<div id="root"></div>
<script type="text/javascript" src="static/manager.203683b1e4aa1432ca87.bundle.js"></script></body>
</html>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-progress-set1",
"name": "react-rotary-knob",
"version": "0.0.1",
"description": "Set of activity progress components",
"description": "Skinnable Rotary Knob",
"main": "build/commonjs/index.js",
"peerDependencies": {
"react": "^16.2.0"
Expand All @@ -21,7 +21,8 @@
"build": "npm run clean && npm run build:umd && npm run build:commonjs",
"build:commonjs": "webpack --config=webpack.config.js",
"build:umd": "webpack --config=webpack.config.umd.js",
"storybook": "start-storybook -p 9001 -c .storybook"
"storybook": "start-storybook -p 9001 -c .storybook",
"buildstorybook": "build-storybook -c .storybook -o ./docs/storybook"
},
"author": {
"name": "Hugo Zapata"
Expand All @@ -45,5 +46,6 @@
"webpack": "^2.6.1",
"webpack-dev-server": "^2.10.1",
"yarn": "^1.3.2"
}
},
"license": "MIT"
}
69 changes: 24 additions & 45 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,24 @@
import React, { Component } from "react";
import * as d3 from "d3";
import * as u from "./utils";
import uuid from 'uuid'
import uuid from 'uuid';
import {Samy, SvgProxy} from 'react-samy-svg';
import defaultSkin from './knobdefaultskin'

/**
* A skin consists of the svg code
* and the knob element centerx and y (knobX, knobY)
*/
type Skin = {
svg: string,
knobX: number,
knobY: number
}
type KnobProps = {
value: number,
min: number,
max: number,
skin: Skin,
onChange: (val: number) => void
};

Expand All @@ -30,7 +42,8 @@ class Knob extends Component<KnobProps, KnobState> {
};

static defaultProps = {
onChange: function() {}
onChange: function() {},
skin: defaultSkin
}
componentDidMount() {}

Expand All @@ -41,7 +54,7 @@ class Knob extends Component<KnobProps, KnobState> {
}

render() {
const { value, min, max, onChange, ...rest } = this.props;
const { value, min, max, onChange, skin, ...rest } = this.props;
const scale = d3
.scaleLinear()
.domain([min, max])
Expand All @@ -54,24 +67,24 @@ class Knob extends Component<KnobProps, KnobState> {
this.props.onChange(domainValue);
};
return (
<svg ref={this.saveRef.bind(this)} {...rest}>
<Samy svgXML={skin.svg} onSVGReady={this.saveRef.bind(this)} {...rest}>
{this.state.svgRef && (
<RotateView
svg={this.state.svgRef}
r={40}
angle={angle}
cx={50}
cy={50}
cx={100}
cy={100}
onAngleChange={onAngleChange}
/>
)}
</svg>
<SvgProxy selector="#knob" transform={`$ORIGINAL rotate(${angle}, ${skin.knobX}, ${skin.knobY})`}/>
<SvgProxy selector="tspan">{value}</SvgProxy>
</Samy>
);
}
}

type RotateViewProps = {
r: number,
angle: number,
cx: number,
cy: number,
Expand Down Expand Up @@ -105,42 +118,8 @@ class RotateView extends Component<RotateViewProps> {
renderControls(props: RotateViewProps) {
const { r, cx, cy, angle } = props;
const svgRef = d3.select(props.svg || ".main-svg");
let container = svgRef.select(this.controlSelector);
if (container.node() == null) {
container = svgRef
.append("g")
.classed("rotate-controls-" + this.controlId, true);
}
//container.selectAll("*").remove();
//outer circle
let outer = container.select(".rotate-circle");
if (!outer.node()) {
outer = container.append("circle").classed("rotate-circle", true);
}

outer
.attr("cx", cx)
.attr("cy", cy)
.attr("fill", "#D7D4D4")
.attr("stroke", "black")
.attr("stroke-width", "2")
.attr("r", r);

//angle drag handle
const hx = r * Math.cos(u.toRadians(angle));
const hy = r * Math.sin(u.toRadians(angle));

let handle = container.select(".handle");
if (!handle.node()) {
handle = container.append("circle").classed("handle", true);
}

handle
.attr("cx", hx + cx)
.attr("cy", hy + cy)
.attr("r", 8)
.attr("fill", "green");

let container = svgRef.select('#knob');

this.setupDragging(container);
}

Expand Down
103 changes: 103 additions & 0 deletions src/knobdefaultskin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
export default {
knobX: 83.5,
knobY: 83.5,
svg:`
<svg width="208px" height="208px" viewBox="0 0 208 208" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Generator: Sketch 47.1 (45422) - http://www.bohemiancoding.com/sketch -->
<desc>Created with Sketch.</desc>
<defs>
<linearGradient x1="50%" y1="50%" x2="50%" y2="100%" id="linearGradient-1">
<stop stop-color="#FFFFFF" stop-opacity="0.5" offset="0%"></stop>
<stop stop-color="#000000" stop-opacity="0.5" offset="100%"></stop>
</linearGradient>
<circle id="path-2" cx="100" cy="100" r="100"></circle>
<filter x="-3.5%" y="-3.0%" width="107.0%" height="107.0%" filterUnits="objectBoundingBox" id="filter-3">
<feMorphology radius="0.5" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="1" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-4" cx="100" cy="100" r="88"></circle>
<filter x="-4.0%" y="-3.4%" width="108.0%" height="108.0%" filterUnits="objectBoundingBox" id="filter-5">
<feMorphology radius="0.5" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="1" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-6">
<stop stop-color="#EEEEEE" offset="0%"></stop>
<stop stop-color="#EDEDED" offset="50.0553592%"></stop>
<stop stop-color="#D8D8D8" offset="100%"></stop>
</linearGradient>
<circle id="path-7" cx="83.5" cy="83.5" r="83.5"></circle>
<filter x="-4.2%" y="-3.6%" width="108.4%" height="108.4%" filterUnits="objectBoundingBox" id="filter-8">
<feMorphology radius="0.5" operator="dilate" in="SourceAlpha" result="shadowSpreadOuter1"></feMorphology>
<feOffset dx="0" dy="1" in="shadowSpreadOuter1" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feComposite in="shadowBlurOuter1" in2="SourceAlpha" operator="out" result="shadowBlurOuter1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
<circle id="path-9" cx="84" cy="11" r="5"></circle>
<filter x="-25.0%" y="-25.0%" width="150.0%" height="150.0%" filterUnits="objectBoundingBox" id="filter-10">
<feGaussianBlur stdDeviation="1.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
<feOffset dx="0" dy="1" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
<feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
</filter>
<circle id="path-11" cx="36" cy="36" r="36"></circle>
<filter x="-3.5%" y="-3.5%" width="106.9%" height="106.9%" filterUnits="objectBoundingBox" id="filter-12">
<feGaussianBlur stdDeviation="1.5" in="SourceAlpha" result="shadowBlurInner1"></feGaussianBlur>
<feOffset dx="0" dy="1" in="shadowBlurInner1" result="shadowOffsetInner1"></feOffset>
<feComposite in="shadowOffsetInner1" in2="SourceAlpha" operator="arithmetic" k2="-1" k3="1" result="shadowInnerInner1"></feComposite>
<feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.5 0" type="matrix" in="shadowInnerInner1"></feColorMatrix>
</filter>
<text id="text-13" font-family="Helvetica" font-size="20" font-weight="normal" fill="#F5A623">
<tspan x="19.3154297" y="41">100</tspan>
</text>
<filter x="-17.6%" y="-25.0%" width="135.3%" height="150.0%" filterUnits="objectBoundingBox" id="filter-14">
<feOffset dx="0" dy="0" in="SourceAlpha" result="shadowOffsetOuter1"></feOffset>
<feGaussianBlur stdDeviation="2" in="shadowOffsetOuter1" result="shadowBlurOuter1"></feGaussianBlur>
<feColorMatrix values="0 0 0 0 0.960784314 0 0 0 0 0.650980392 0 0 0 0 0.137254902 0 0 0 1 0" type="matrix" in="shadowBlurOuter1"></feColorMatrix>
</filter>
</defs>
<g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g id="Group-3-Copy" transform="translate(4.000000, 3.000000)">
<g id="container">
<g id="Oval-2">
<use fill="black" fill-opacity="1" filter="url(#filter-3)" xlink:href="#path-2"></use>
<use stroke="#979797" stroke-width="1" fill="url(#linearGradient-1)" fill-rule="evenodd" xlink:href="#path-2"></use>
</g>
<g id="Oval-2">
<use fill="black" fill-opacity="1" filter="url(#filter-5)" xlink:href="#path-4"></use>
<use stroke="#4A4A4A" stroke-width="1" fill="#4A4A4A" fill-rule="evenodd" xlink:href="#path-4"></use>
</g>
<g id="knob" transform="translate(17.000000, 17.000000)">
<g id="Oval-2">
<use fill="black" fill-opacity="1" filter="url(#filter-8)" xlink:href="#path-7"></use>
<use stroke="#979797" stroke-width="1" fill="url(#linearGradient-6)" fill-rule="evenodd" xlink:href="#path-7"></use>
</g>
<g id="Oval-3">
<use fill="#AAA8A8" fill-rule="evenodd" xlink:href="#path-9"></use>
<use fill="black" fill-opacity="1" filter="url(#filter-10)" xlink:href="#path-9"></use>
<use stroke="#757171" stroke-width="1" xlink:href="#path-9"></use>
</g>
</g>
<g id="label" transform="translate(65.000000, 65.000000)">
<g id="Oval">
<use fill="#3D3D3D" fill-rule="evenodd" xlink:href="#path-11"></use>
<use fill="black" fill-opacity="1" filter="url(#filter-12)" xlink:href="#path-11"></use>
<use stroke="#454545" stroke-width="1" xlink:href="#path-11"></use>
</g>
<g id="100" fill-opacity="1" fill="#F5A623">
<use filter="url(#filter-14)" xlink:href="#text-13"></use>
<use xlink:href="#text-13"></use>
</g>
</g>
</g>
</g>
</g>
</svg>
`
}

0 comments on commit e992b52

Please sign in to comment.