From 285bc89a400c2faa7b6c7c327300c7842711935b Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 22 Mar 2021 16:06:13 +0100 Subject: fix proportional sizing --- frontend/app/common/form.component.js | 69 +++++++++++++++++++++++++++-------- 1 file changed, 54 insertions(+), 15 deletions(-) (limited to 'frontend/app/common') 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 => ( ) -export const NumberInput = props => ( - -) +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 ( + + ) + } +} export const ColorInput = props => (