From 2e41e0bbbf8d4fc3b70a0c7a7661f70bf1a9bd5e Mon Sep 17 00:00:00 2001 From: shervinchen Date: Sat, 26 Oct 2024 15:28:48 +0300 Subject: [PATCH] feat(Input): add more size type --- demo/input/index.tsx | 2 ++ packages/Input/Input.styles.ts | 22 +++++++++++++++---- packages/Input/Input.types.ts | 3 ++- packages/Input/__tests__/Input.test.tsx | 14 +++++++----- .../__snapshots__/Input.test.tsx.snap | 2 +- src/app/(article)/components/input/input.mdx | 6 +++++ 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/demo/input/index.tsx b/demo/input/index.tsx index d3635a6..d956231 100644 --- a/demo/input/index.tsx +++ b/demo/input/index.tsx @@ -17,9 +17,11 @@ export function DemoInputTypes() { export function DemoInputSizes() { return ( + + ); } diff --git a/packages/Input/Input.styles.ts b/packages/Input/Input.styles.ts index 5c23621..18df807 100644 --- a/packages/Input/Input.styles.ts +++ b/packages/Input/Input.styles.ts @@ -20,17 +20,30 @@ export const useInputStyles = ({ const sizes: { [key in InputSizes]: InputSizeStyles; } = { + xs: { + fontSize: '12px', + height: '24px', + horizontalPadding: '8px', + }, sm: { fontSize: '14px', - height: '32px', + height: '28px', + horizontalPadding: '12px', }, md: { fontSize: '14px', - height: '40px', + height: '32px', + horizontalPadding: '12px', }, lg: { + fontSize: '14px', + height: '36px', + horizontalPadding: '12px', + }, + xl: { fontSize: '16px', - height: '48px', + height: '40px', + horizontalPadding: '16px', }, }; const styles: { @@ -103,6 +116,7 @@ export const useInputCSS = ({ type, size, width, disabled }: InputProps) => { const { fontSize, height, + horizontalPadding, color, borderColor, backgroundColor = 'transparent', @@ -118,7 +132,7 @@ export const useInputCSS = ({ type, size, width, disabled }: InputProps) => { box-sizing: border-box; display: inline-flex; height: ${height}; - padding: 0 12px; + padding: 0 ${horizontalPadding}; line-height: normal; box-shadow: none; font-size: ${fontSize}; diff --git a/packages/Input/Input.types.ts b/packages/Input/Input.types.ts index 8bdd939..65fdb39 100644 --- a/packages/Input/Input.types.ts +++ b/packages/Input/Input.types.ts @@ -2,7 +2,7 @@ import { InputHTMLAttributes, ChangeEvent, FocusEvent } from 'react'; export type InputTypes = 'default' | 'primary' | 'warning' | 'error'; -export type InputSizes = 'sm' | 'md' | 'lg'; +export type InputSizes = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; export interface BaseInputProps { value?: string; @@ -31,6 +31,7 @@ export type InputProps = BaseInputProps & NativeInputProps; export interface InputSizeStyles { fontSize?: string; height?: string; + horizontalPadding?: string; } export interface InputBasicStyles { diff --git a/packages/Input/__tests__/Input.test.tsx b/packages/Input/__tests__/Input.test.tsx index 53ecca9..db6f15c 100644 --- a/packages/Input/__tests__/Input.test.tsx +++ b/packages/Input/__tests__/Input.test.tsx @@ -12,9 +12,11 @@ const typeColorMap = { }; const sizeHeightMap = { - sm: '32px', - md: '40px', - lg: '48px', + xs: '24px', + sm: '28px', + md: '32px', + lg: '36px', + xl: '40px', }; const user = userEvent.setup({ advanceTimers: jest.advanceTimersByTime }); @@ -107,7 +109,7 @@ describe('Input', () => { } ); - ['sm', 'md', 'lg'].forEach((item: InputSizes) => { + ['xs', 'sm', 'md', 'lg', 'xl'].forEach((item: InputSizes) => { test(`should render ${item} size`, () => { render(); expect(screen.getByRole('textbox')).toHaveStyle( @@ -231,8 +233,8 @@ describe('Input', () => { disabled: false, }) ); - expect(result1.current.height).toBe('40px'); - expect(result2.current.height).toBe('40px'); + expect(result1.current.height).toBe('32px'); + expect(result2.current.height).toBe('32px'); }); test('should get default focus style when type is unknown or falsy', () => { diff --git a/packages/Input/__tests__/__snapshots__/Input.test.tsx.snap b/packages/Input/__tests__/__snapshots__/Input.test.tsx.snap index cd3de2e..b54dda3 100644 --- a/packages/Input/__tests__/__snapshots__/Input.test.tsx.snap +++ b/packages/Input/__tests__/__snapshots__/Input.test.tsx.snap @@ -4,7 +4,7 @@ exports[`Input should match the snapshot 1`] = ` + + + @@ -49,6 +52,9 @@ import { Input } from 'raw-ui'; + + + `} />