summaryrefslogtreecommitdiff
path: root/frontend/app/common
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2021-03-22 16:06:13 +0100
committerJules Laplace <julescarbon@gmail.com>2021-03-22 16:06:13 +0100
commit285bc89a400c2faa7b6c7c327300c7842711935b (patch)
tree5d6d3c6e2f6b844a5cd4ef980c8c3237a806dabe /frontend/app/common
parent30265efd64167e9fd6b5a489bd7f8239b496ed35 (diff)
fix proportional sizing
Diffstat (limited to 'frontend/app/common')
-rw-r--r--frontend/app/common/form.component.js69
1 files changed, 54 insertions, 15 deletions
diff --git a/frontend/app/common/form.component.js b/frontend/app/common/form.component.js
index d0ebea3..de1020a 100644
--- a/frontend/app/common/form.component.js
+++ b/frontend/app/common/form.component.js
@@ -23,21 +23,60 @@ export const LabelDescription = props => (
</label>
)
-export const NumberInput = props => (
- <label className={props.error ? 'error' : 'text'}>
- <span>{props.title}</span>
- <input
- type="number"
- required={props.required}
- onChange={props.onChange}
- name={props.name}
- value={props.data[props.name]}
- min={props.min}
- max={props.max}
- step={props.step || 1}
- />
- </label>
-)
+export class NumberInput extends Component {
+ constructor(props) {
+ super(props)
+ this.handleKeyDown = this.handleKeyDown.bind(this)
+ }
+ handleKeyDown(e) {
+ const { min, max, step, data, name, onChange } = this.props
+ const value = data[name]
+ // console.log(e.keyCode)
+ switch (e.keyCode) {
+ case 38: // up
+ if (e.shiftKey) {
+ e.preventDefault()
+ onChange({
+ target: {
+ name,
+ value: Math.min(max, parseFloat(value) + ((step || 1) * 10))
+ }
+ })
+ }
+ break
+ case 40: // down
+ if (e.shiftKey) {
+ e.preventDefault()
+ onChange({
+ target: {
+ name,
+ value: Math.max(min, parseFloat(value) - ((step || 1) * 10))
+ }
+ })
+ }
+ break
+ }
+ }
+ render() {
+ const { props } = this
+ return (
+ <label className={props.error ? 'error' : 'text'}>
+ <span>{props.title}</span>
+ <input
+ type="number"
+ required={props.required}
+ onKeyDown={this.handleKeyDown}
+ onChange={props.onChange}
+ name={props.name}
+ value={props.data[props.name]}
+ min={props.min}
+ max={props.max}
+ step={props.step || 1}
+ />
+ </label>
+ )
+ }
+}
export const ColorInput = props => (
<label className={props.error ? 'error color' : 'text color'}>