From 6f6df00673b7929f10439696ed2ada5b1fc6aed8 Mon Sep 17 00:00:00 2001 From: eupthere Date: Sat, 24 Jan 2026 20:51:44 +0900 Subject: [PATCH 1/2] feat: add Textarea component and tests - Implement Textarea component with customizable props - Add stories for Textarea showcasing various states - Create tests for Textarea to ensure proper rendering and functionality - Update index files to export the new Textarea component --- .../src/__tests__/index.browser.test.ts | 1 + .../components/Textarea/Textarea.stories.tsx | 79 +++++++++ .../__snapshots__/index.browser.test.tsx.snap | 49 ++++++ .../Textarea/__tests__/index.browser.test.tsx | 153 ++++++++++++++++++ .../src/components/Textarea/index.tsx | 122 ++++++++++++++ packages/components/src/index.ts | 1 + 6 files changed, 405 insertions(+) create mode 100644 packages/components/src/components/Textarea/Textarea.stories.tsx create mode 100644 packages/components/src/components/Textarea/__tests__/__snapshots__/index.browser.test.tsx.snap create mode 100644 packages/components/src/components/Textarea/__tests__/index.browser.test.tsx create mode 100644 packages/components/src/components/Textarea/index.tsx diff --git a/packages/components/src/__tests__/index.browser.test.ts b/packages/components/src/__tests__/index.browser.test.ts index 36a2cc3e..fbd6e483 100644 --- a/packages/components/src/__tests__/index.browser.test.ts +++ b/packages/components/src/__tests__/index.browser.test.ts @@ -6,6 +6,7 @@ describe('export', () => { expect({ ...index }).toEqual({ Button: expect.any(Function), Input: expect.any(Function), + Textarea: expect.any(Function), Stepper: expect.any(Function), Select: expect.any(Function), Radio: expect.any(Function), diff --git a/packages/components/src/components/Textarea/Textarea.stories.tsx b/packages/components/src/components/Textarea/Textarea.stories.tsx new file mode 100644 index 00000000..be58f664 --- /dev/null +++ b/packages/components/src/components/Textarea/Textarea.stories.tsx @@ -0,0 +1,79 @@ +import { Meta, StoryObj } from '@storybook/react-vite' + +import { Textarea } from './index' + +type Story = StoryObj + +const meta: Meta = { + title: 'Devfive/Textarea', + component: Textarea, + decorators: [ + (Story) => ( +
+ +
+ ), + ], +} + +export const Default: Story = { + args: { + placeholder: 'Enter your message...', + }, +} + +export const WithDefaultValue: Story = { + args: { + defaultValue: 'This is some default text in the textarea.', + placeholder: 'Enter your message...', + }, +} + +export const Disabled: Story = { + args: { + placeholder: 'Disabled textarea', + disabled: true, + }, +} + +export const DisabledWithValue: Story = { + args: { + defaultValue: 'This textarea is disabled', + disabled: true, + }, +} + +export const Error: Story = { + args: { + placeholder: 'Enter your message...', + error: true, + }, +} + +export const ErrorWithMessage: Story = { + args: { + placeholder: 'Enter your message...', + error: true, + errorMessage: 'Please enter a valid message.', + }, +} + +export const CustomRows: Story = { + args: { + placeholder: 'This textarea has 6 rows', + rows: 6, + }, +} + +export const CustomColors: Story = { + args: { + placeholder: 'Custom themed textarea', + colors: { + primary: '#8B5CF6', + border: '#E5E7EB', + background: '#F9FAFB', + }, + }, +} + +export default meta diff --git a/packages/components/src/components/Textarea/__tests__/__snapshots__/index.browser.test.tsx.snap b/packages/components/src/components/Textarea/__tests__/__snapshots__/index.browser.test.tsx.snap new file mode 100644 index 00000000..7a376e1c --- /dev/null +++ b/packages/components/src/components/Textarea/__tests__/__snapshots__/index.browser.test.tsx.snap @@ -0,0 +1,49 @@ +// Bun Snapshot v1, https://bun.sh/docs/test/snapshots + +exports[`Textarea should render with default props 1`] = ` +"
+
+ +
+
" +`; + +exports[`Textarea should render with disabled prop 1`] = ` +"
+
+ +
+
" +`; + +exports[`Textarea should render error style when error is true 1`] = ` +"
+
+ +
+
" +`; + +exports[`Textarea should render with error message 1`] = ` +"
+
+ + + Error message + +
+
" +`; + +exports[`Textarea should have typography when typography is provided 1`] = ` +"
+
+ +
+
" +`; diff --git a/packages/components/src/components/Textarea/__tests__/index.browser.test.tsx b/packages/components/src/components/Textarea/__tests__/index.browser.test.tsx new file mode 100644 index 00000000..2f463d07 --- /dev/null +++ b/packages/components/src/components/Textarea/__tests__/index.browser.test.tsx @@ -0,0 +1,153 @@ +import { DevupThemeTypography } from '@devup-ui/react' +import { describe, expect, it } from 'bun:test' +import { render, userEvent } from 'bun-test-env-dom' + +import { Textarea } from '..' + +describe('Textarea', () => { + it('should render with default props', () => { + const { container } = render( " @@ -12,7 +12,7 @@ exports[`Textarea should render with default props 1`] = ` exports[`Textarea should render with disabled prop 1`] = ` "
-
" @@ -21,7 +21,7 @@ exports[`Textarea should render with disabled prop 1`] = ` exports[`Textarea should render error style when error is true 1`] = ` "
-
" @@ -30,9 +30,9 @@ exports[`Textarea should render error style when error is true 1`] = ` exports[`Textarea should render with error message 1`] = ` "
- - + Error message
@@ -42,7 +42,7 @@ exports[`Textarea should render with error message 1`] = ` exports[`Textarea should have typography when typography is provided 1`] = ` "
-
" diff --git a/packages/components/src/components/Textarea/__tests__/index.browser.test.tsx b/packages/components/src/components/Textarea/__tests__/index.browser.test.tsx index 2f463d07..6571c898 100644 --- a/packages/components/src/components/Textarea/__tests__/index.browser.test.tsx +++ b/packages/components/src/components/Textarea/__tests__/index.browser.test.tsx @@ -33,7 +33,7 @@ describe('Textarea', () => { const { container } = render(