From 8ce65896d9189d3f6a00e7ba0304b490fa806550 Mon Sep 17 00:00:00 2001 From: Virtute90 Date: Fri, 28 Jun 2024 21:41:32 +0000 Subject: [PATCH] feat: add icon and button to input --- src/Input/Input.tsx | 38 +++++-- src/Input/InputContainer.tsx | 33 ++++++ stories/Components/Form/Input.stories.tsx | 130 +++++----------------- stories/Documentation/Form/Input.mdx | 94 ---------------- 4 files changed, 90 insertions(+), 205 deletions(-) diff --git a/src/Input/Input.tsx b/src/Input/Input.tsx index 6f1882734..fff6350b7 100644 --- a/src/Input/Input.tsx +++ b/src/Input/Input.tsx @@ -1,21 +1,21 @@ +import isNumber from 'is-number'; import React, { - InputHTMLAttributes, ElementType, - Ref, + InputHTMLAttributes, ReactNode, + Ref, useCallback, - useState, + useEffect, useRef, - useEffect + useState } from 'react'; -import isNumber from 'is-number'; -import { InputContainer } from './InputContainer'; -import { Icon } from '../Icon/Icon'; -import { getTag, getFormControlClass, getClasses, getValidationTextControlClass, useFocus } from './utils'; +import classNames from 'classnames'; import type { CSSModule } from 'reactstrap/types/lib/utils'; +import { Icon } from '../Icon/Icon'; import { notifyDeprecation } from '../utils'; -import classNames from 'classnames'; +import { InputContainer } from './InputContainer'; +import { getClasses, getFormControlClass, getTag, getValidationTextControlClass, useFocus } from './utils'; // taken from reactstrap types type InputType = @@ -101,6 +101,14 @@ export interface InputProps extends InputHTMLAttributes { static?: boolean; /** Quando attivo rimuove il componente contenitore dell'Input. Utile per un controllo maggiore dello styling */ noWrapper?: boolean; + /** Indica che il componente ha un bottone a destra rispetto all'input */ + hasButtonRight?: boolean; + /** Componente per il bottone */ + buttonRight?: ReactNode; + /** Indica che il componente ha una icona a sinistra rispetto all'input */ + hasIconLeft?: boolean; + /** Componente per l'icona */ + iconLeft?: ReactNode; testId?: string; } @@ -128,6 +136,10 @@ export const Input = ({ size, testId, noWrapper = false, + hasButtonRight, + buttonRight, + hasIconLeft, + iconLeft, ...attributes }: InputProps) => { const [isHidden, setHidden] = useState(true); @@ -249,7 +261,11 @@ export const Input = ({ label, validationTextClass, validationText, - wrapperClass + wrapperClass, + hasButtonRight, + buttonRight, + hasIconLeft, + iconLeft }; if (noWrapper) { @@ -399,4 +415,4 @@ export const Input = ({ } return ; -}; +}; \ No newline at end of file diff --git a/src/Input/InputContainer.tsx b/src/Input/InputContainer.tsx index 3ea8dd85d..5b135f048 100644 --- a/src/Input/InputContainer.tsx +++ b/src/Input/InputContainer.tsx @@ -10,6 +10,14 @@ export interface InputContainerProps extends HTMLAttributes { id: string | undefined; infoId: string | undefined; infoText: string | undefined; + /** Indica che il componente ha un bottone a destra rispetto all'input */ + hasButtonRight?: boolean; + /** Componente per il bottone */ + buttonRight?: ReactNode; + /** Indica che il componente ha una icona a sinistra rispetto all'input */ + hasIconLeft?: boolean; + /** Componente per l'icona */ + iconLeft?: ReactNode; testId?: string; } @@ -24,8 +32,33 @@ export const InputContainer: FC = ({ validationTextClass, validationText, wrapperClass, + hasButtonRight, + buttonRight, + hasIconLeft, + iconLeft, children }) => { + + if (hasButtonRight || hasIconLeft) { + return ( +
+
+ {hasIconLeft && {iconLeft}} + + {children} + {infoText && ( + + {infoText} + + )} +
{validationText}
+ {hasButtonRight &&
{buttonRight}
} +
+
+ ); + } return (