From cc084cb2473f684fbf72f778d7c0c6454c819bd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Tue, 1 Mar 2022 13:56:26 +0100 Subject: [PATCH] Improve input props handling --- .../ui-toolkit/src/components/input/input.tsx | 57 ++++++++----------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/libs/ui-toolkit/src/components/input/input.tsx b/libs/ui-toolkit/src/components/input/input.tsx index 60fe0da4e..4bdc586f5 100644 --- a/libs/ui-toolkit/src/components/input/input.tsx +++ b/libs/ui-toolkit/src/components/input/input.tsx @@ -1,14 +1,11 @@ +import { InputHTMLAttributes, forwardRef } from 'react'; import classNames from 'classnames'; -/* eslint-disable-next-line */ -export interface InputProps { - onChange?: React.FormEventHandler; +interface InputProps extends InputHTMLAttributes { hasError?: boolean; disabled?: boolean; className?: string; - value?: string | number; } - export const inputClassNames = ({ hasError, disabled, @@ -42,34 +39,28 @@ export const inputClassNames = ({ className ); -export const inputStyle = ({ disabled }: { disabled?: boolean }) => { - const style: React.CSSProperties = {}; - if (disabled) { - style.backgroundImage = - 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAYAAADgzO9IAAAAAXNSR0IArs4c6QAAACNJREFUGFdjtLS0/M8ABcePH2eEsRlJl4BpBdHIuuFmEi0BABqjEQVjx/LTAAAAAElFTkSuQmCC)'; - } - return style; -}; - -export function Input({ - hasError, - onChange, +export const inputStyle = ({ + style, disabled, - className, - value, -}: InputProps) { - return ( - - ); -} +}: { + style?: React.CSSProperties; + disabled?: boolean; +}) => + disabled + ? { + ...style, + backgroundImage: + 'url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAYAAAAGCAYAAADgzO9IAAAAAXNSR0IArs4c6QAAACNJREFUGFdjtLS0/M8ABcePH2eEsRlJl4BpBdHIuuFmEi0BABqjEQVjx/LTAAAAAElFTkSuQmCC)', + } + : style; + +export const Input = forwardRef((props, ref) => ( + +)); export default Input;