From afa8c160a3841c7c6df0bca7ca6a188af30eebbc Mon Sep 17 00:00:00 2001 From: Maciej Lenartowicz Date: Mon, 7 Oct 2019 09:18:25 +0000 Subject: [PATCH] Resolve "Increment/decrement value in NumberInput when +/- button is kept pushed." --- package-lock.json | 2 +- package.json | 2 +- src/bootstrap/NumberInput.js | 22 ++++++++++++---- src/bootstrap/__tests__/NumberInput.test.js | 28 ++++++++++----------- src/utils/hooks.js | 20 +++++++++++++++ 5 files changed, 53 insertions(+), 21 deletions(-) create mode 100644 src/utils/hooks.js diff --git a/package-lock.json b/package-lock.json index dad8c2c..a4b339c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "0.1.0-beta.7", + "version": "0.1.0-beta.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 0646b86..c2ded42 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "foris", - "version": "0.1.0-beta.7", + "version": "0.1.0-beta.8", "description": "Set of components and utils for Foris and its plugins.", "author": "CZ.NIC, z.s.p.o.", "repository": { diff --git a/src/bootstrap/NumberInput.js b/src/bootstrap/NumberInput.js index 63139da..e841622 100644 --- a/src/bootstrap/NumberInput.js +++ b/src/bootstrap/NumberInput.js @@ -6,8 +6,9 @@ */ import React from "react"; - import PropTypes from "prop-types"; + +import { useConditionalTimeout } from "utils/hooks"; import { Input } from "./Input"; import "./NumberInput.css"; @@ -33,15 +34,25 @@ NumberInput.defaultProps = { value: 0, }; -export function NumberInput({ onChange, inlineText, ...props }) { +export function NumberInput({ + onChange, inlineText, value, ...props +}) { + function updateValue(initialValue, difference) { + onChange({ target: { value: initialValue + difference } }); + } + + const enableIncrease = useConditionalTimeout({ callback: updateValue }, value, 1); + const enableDecrease = useConditionalTimeout({ callback: updateValue }, value, -1); + return ( - +
{inlineText &&

{inlineText}

}