From a684ee7ba888c0ab66c48a2a803b23fea6325c02 Mon Sep 17 00:00:00 2001 From: Giorgio Aquino Date: Wed, 24 Jul 2024 09:11:53 +0200 Subject: [PATCH] feat!: remove default left icon in the input component (#537) --- src/components/Input/index.tsx | 40 +++++++++++----- stories/Input/Docs.mdx | 47 +++++++++++++------ stories/Input/Input.example.tsx | 6 +-- .../{Input.stories.ts => Input.stories.tsx} | 16 +++++-- 4 files changed, 76 insertions(+), 33 deletions(-) rename stories/Input/{Input.stories.ts => Input.stories.tsx} (79%) diff --git a/src/components/Input/index.tsx b/src/components/Input/index.tsx index 8076fc3a..550da436 100644 --- a/src/components/Input/index.tsx +++ b/src/components/Input/index.tsx @@ -1,7 +1,7 @@ import React from 'react' import { cn } from '@/lib/utils' import { cva } from 'class-variance-authority' -import { BsX, BsPersonFill, BsSearch } from '@/assets' +import { BsX, BsSearch } from '@/assets' const leftSideVariants = cva(['flex', 'items-center', 'text-inherit']) @@ -70,9 +70,26 @@ const inputVariants = cva( } ) +type InputType = + | 'color' + | 'date' + | 'datetime-local' + | 'email' + | 'month' + | 'number' + | 'password' + | 'search' + | 'tel' + | 'text' + | 'time' + | 'url' + | 'week' + // eslint-disable-next-line @typescript-eslint/ban-types + | (string & {}) + interface InputProps extends React.HTMLProps { variant: 'primary' | 'error' | 'success' - type: 'text' | 'search' + type: InputType formClassName?: string leftSideClassName?: string leftSideChild?: React.ReactNode @@ -80,11 +97,11 @@ interface InputProps extends React.HTMLProps { onClear: () => void } -const convertTypeToComponent = { - left: { - text: , +const convertTypeToLeftComponent = (type: InputType) => { + const mapping: Partial> = { search: } + return mapping[type] ?? null } const Input = React.forwardRef( @@ -102,17 +119,18 @@ const Input = React.forwardRef( }, ref ) => { - const leftSideComponent = - leftSideChild ?? convertTypeToComponent.left[`${type}`] + const leftSideComponent = leftSideChild ?? convertTypeToLeftComponent(type) const rightSideComponent = rightSideChild ?? return (