From c3fc645b2e0de5179d91fa168ab59f1e13a94464 Mon Sep 17 00:00:00 2001 From: Alexis Le Dinh Date: Mon, 21 Dec 2020 18:17:28 +0100 Subject: [PATCH 1/9] Prettier: remove singleQuote statement --- .prettierrc | 1 - 1 file changed, 1 deletion(-) diff --git a/.prettierrc b/.prettierrc index 52d65b1cbb..fa38fabd37 100644 --- a/.prettierrc +++ b/.prettierrc @@ -1,5 +1,4 @@ { - "singleQuote": true, "tabWidth": 2, "trailingComma": "all" } From baf5dda694371403d71319a2ad030d5d4b7458a5 Mon Sep 17 00:00:00 2001 From: Alexis Le Dinh Date: Mon, 21 Dec 2020 18:17:59 +0100 Subject: [PATCH 2/9] Input: Add number input type Refs: #211 --- src/lib/components/input/Input.component.js | 90 ++++++++++++++++--- .../components/input/Input.component.style.js | 41 +++++++++ 2 files changed, 121 insertions(+), 10 deletions(-) diff --git a/src/lib/components/input/Input.component.js b/src/lib/components/input/Input.component.js index 733603152f..3b2380a78b 100644 --- a/src/lib/components/input/Input.component.js +++ b/src/lib/components/input/Input.component.js @@ -1,5 +1,5 @@ //@flow -import React from "react"; +import React, { useRef } from "react"; import { DebounceInput } from "react-debounce-input"; import Checkbox from "../checkbox/Checkbox.component"; import Select from "../select/Select.component"; @@ -8,12 +8,12 @@ import { InputContainer, LabelStyle, InputErrorMessage, - InputWrapper + InputWrapper, } from "./Input.component.style"; export type Item = { label: string, - value: string | number + value: string | number, }; type Items = Array; @@ -26,8 +26,10 @@ type Props = { error?: string, id?: string, checked?: boolean, - onChange: () => void, - options?: Items + onChange: (e?: any) => void, + options?: Items, + min?: string, + max?: string, }; const InputRenderer = ({ @@ -37,8 +39,48 @@ const InputRenderer = ({ checked, onChange, options = [], + min, + max, ...rest }) => { + const inputEl = useRef(null); + + const handleNumberClick = (e) => { + /* + ** Since react is using Synthetic event we have to do the following to be + ** able to programmatically dispatch the onChange event from the input + */ + const valuePropDescriptor = Object.getOwnPropertyDescriptor( + window.HTMLInputElement.prototype, + "value", + ); + if (valuePropDescriptor && inputEl.current) { + const nativeInputValueSetter = valuePropDescriptor.set; + if (nativeInputValueSetter) { + if (e.target.dataset.core === "up") + nativeInputValueSetter.call( + inputEl.current, + max + ? max && parseInt(value) + 1 <= parseInt(max) + ? parseInt(value) + 1 + : parseInt(value) + : parseInt(value) + 1, + ); + else + nativeInputValueSetter.call( + inputEl.current, + min + ? min && parseInt(value) - 1 >= parseInt(min) + ? parseInt(value) - 1 + : parseInt(value) + : parseInt(value) - 1, + ); + } + const event = new Event("input", { bubbles: true }); + inputEl.current.dispatchEvent(event); + } + }; + const input = { select: (