From 0a5d56e4a2d9755560e105861cc0d48a554bd374 Mon Sep 17 00:00:00 2001 From: Nick Ovchinnikov Date: Thu, 31 Mar 2022 10:38:00 +0400 Subject: [PATCH] Input refactoring --- README.md | 6 +- components/Input/Input.tsx | 52 +++++++----- .../Input/__snapshots__/Input.test.tsx.snap | 82 +++++++++++-------- 3 files changed, 82 insertions(+), 58 deletions(-) diff --git a/README.md b/README.md index 730b195..2ec4212 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,10 @@ [pull request](https://github.com/nickovchinnikov/coursesbox/pull/18) -### IconButton component +### Input component [pull request](https://github.com/nickovchinnikov/coursesbox/pull/19) + +### Input component refactoring + +[pull request](https://github.com/nickovchinnikov/coursesbox/pull/20) diff --git a/components/Input/Input.tsx b/components/Input/Input.tsx index 145033f..767ee2a 100644 --- a/components/Input/Input.tsx +++ b/components/Input/Input.tsx @@ -3,19 +3,14 @@ import styled from "@emotion/styled"; import { Icon, AvailableIcons } from "@/components/Icon"; import { boxShadow } from "@/components/styles"; -import { useId } from "@/components/hooks/useId"; -type StyledInputProps = { - withIcon: boolean; -}; - -const StyledInput = styled.input` +const StyledInput = styled.input` all: unset; - width: 20rem; - height: 4rem; + width: ${({ width }) => width}rem; + height: ${({ height }) => height}rem; border-radius: 1rem; font-size: 1.4rem; - padding-left: ${({ withIcon }) => (withIcon ? 2.8 : 1.4)}rem; + padding: 0 2.6rem 0 1.4rem; color: ${({ theme }) => theme.font.regular}; ${({ theme }) => boxShadow(theme.components.shadow1, theme.components.shadow2, true)} @@ -33,44 +28,59 @@ const StyledInput = styled.input` `; const Label = styled.label` + display: flex; + justify-content: flex-start; + flex-direction: column; color: ${({ theme }) => theme.font.regular}; font-size: 1rem; - padding-left: 1.4rem; `; const StyledIcon = styled(Icon)` - display: block; - margin-top: -3rem; - padding-left: 0.5rem; + margin-left: -2.5rem; color: ${({ theme }) => theme.font.placeholder}; opacity: 0.7; `; +const InputWrapper = styled.div` + display: flex; + align-items: center; +`; + +const Text = styled.span` + padding-left: 1.4rem; +`; + export type Props = { - /** Input label */ - label: string; /** Placeholder */ placeholder: string; /** onChange handler */ onChange: ChangeEventHandler; + /** Input label */ + label?: string; /** Icon */ icon?: AvailableIcons; /** Feedback for input */ feedback?: ReactChild; + /** Input height */ + height?: number; + /** Input width */ + width?: number; }; export const Input: FC> = ({ label, + height = 4, + width = 20, icon, feedback, ...props }) => ( ); diff --git a/components/Input/__snapshots__/Input.test.tsx.snap b/components/Input/__snapshots__/Input.test.tsx.snap index add51e1..f82b7fb 100644 --- a/components/Input/__snapshots__/Input.test.tsx.snap +++ b/components/Input/__snapshots__/Input.test.tsx.snap @@ -3,18 +3,23 @@ exports[`Input test cases Render check 1`] = ` `; @@ -22,34 +27,39 @@ exports[`Input test cases Render check 1`] = ` exports[`Input test cases Render check with icon 1`] = ` `;