Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joshjg/react-canvas-knob
Flexible knob/dial input component
https://github.com/joshjg/react-canvas-knob
Last synced: 3 months ago
JSON representation
Flexible knob/dial input component
- Host: GitHub
- URL: https://github.com/joshjg/react-canvas-knob
- Owner: joshjg
- License: mit
- Created: 2016-10-04T04:01:17.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-01T10:14:38.000Z (about 6 years ago)
- Last Synced: 2024-07-19T15:12:11.743Z (4 months ago)
- Language: JavaScript
- Homepage:
- Size: 79.1 KB
- Stars: 44
- Watchers: 3
- Forks: 30
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# react-canvas-knob
[jQuery Knob](https://github.com/aterrien/jQuery-Knob) rebuilt with React (no jQuery). This is an HTML5 Canvas-based component that serves as a circular range input. Accepts mouse, touch, scrollwheel, and keyboard input.
## Installation
`npm install react-canvas-knob --save`## Example usage
Please note that react-canvas-knob must be used as a [controlled input](https://facebook.github.io/react/docs/forms.html#controlled-components).
```js
import React from 'react';
import Knob from 'react-canvas-knob';class MyComponent extends React.Component {
state = {value: 50};handleChange = (newValue) => {
this.setState({value: newValue});
};render() {
return (
);
}
}
```## Properties
| name | description | default |
|------|-------------|---------|
|`value`|numeric value of knob|n/a|
|`onChange`|function to be called on user input with the current numerical value|n/a|
|`onChangeEnd`|function to be called on mouseUp or touchEnd with the current numerical value|n/a|
|`min`|min value|`0`|
|`max`|max value|`100`|
|`step`|step size|`1`|
|`log`|enable logarithmic scale (must use non-zero `min` and `max`, `step` > 1)|`false`|
|`width` or `height`|dimension of square (px)|`200`|
|`thickness`|gauge thickness|`0.35`|
|`lineCap`|gauge stroke ending style (`butt` or `round`)|`'butt'`|
|`bgColor`|background color|`'#EEE'`|
|`fgColor`|foreground color|`'#EA2'`|
|`inputColor`|text color|`fgColor`|
|`font`|font family|`'Arial'`|
|`fontWeight`|font weight|`'bold'`|
|`clockwise`|direction of progression|`true`|
|`cursor`|use cursor display mode - give width value or `true` which uses the default cursor width (30)|`false`|
|`stopper`|stop at min & max on keydown/mousewheel|`true`|
|`readOnly`|disable all user input|`false`|
|`disableTextInput`|disable manual text input only|`false`|
|`displayInput`|show numeric input box|`true`|
|`displayCustom`|function that will render your custom component in the centre. (Make sure to set `displayInput` as `false`, as that takes priority)|n/a|
|`angleArc`|arc size in degrees|`360`|
|`angleOffset`|starting angle in degrees|`0`|
|`disableMouseWheel`|disable changes on mouse wheel use|`false`|
|`title`|adds title attribute to the wheel|`value`|
|`className`|custom className to be applied to the container element|`null`|
|`canvasClassName`|custom className to be applied to the canvas element|`null`|## Contributing
* Make changes to Knob.js, then run `npm run babel` to transpile.## Todo
- [ ] Fix for height > width condition
- [ ] Port `displayPrevious` feature
- [ ] Downwards compatibility
- [ ] Implement some of the existing [pull requests](https://github.com/aterrien/jQuery-Knob/pulls)
- [ ] Improve manual text input