diff --git a/packages/common/src/locales/en/app.ts b/packages/common/src/locales/en/app.ts index 2e5558a5..1e4bb864 100644 --- a/packages/common/src/locales/en/app.ts +++ b/packages/common/src/locales/en/app.ts @@ -30,6 +30,13 @@ export const en = { displayName: 'Short answer', maxLength: 'Maximum length', }, + textarea: { + ...defaults, + displayName: 'Long answer', + maxLength: 'Maximum length', + hintLabel: 'Hint Text (optional)', + hint: 'The more specific you can be, the better. Use the space below and/or attach additional pages.', + }, packageDownload: { ...defaults, displayName: 'Package download', diff --git a/packages/design/src/Form/components/TextArea/TextArea.stories.tsx b/packages/design/src/Form/components/TextArea/TextArea.stories.tsx new file mode 100644 index 00000000..7e0e1d52 --- /dev/null +++ b/packages/design/src/Form/components/TextArea/TextArea.stories.tsx @@ -0,0 +1,81 @@ +import React from 'react'; +import { FormProvider, useForm } from 'react-hook-form'; +import type { Meta, StoryObj } from '@storybook/react'; + +import TextArea from './index.js'; + +const meta: Meta = { + title: 'patterns/TextArea', + component: TextArea, + decorators: [ + (Story, args) => { + const FormDecorator = () => { + const formMethods = useForm(); + return ( +
+ + + +
+ ); + }; + return ; + }, + ], + tags: ['autodocs'], +}; + +export default meta; + +export const Required: StoryObj = { + args: { + _patternId: '', + type: 'text-area', + inputId: 'test-textarea', + value: '', + label: 'Please enter your comments', + required: true, + maxLength: 500, + }, +}; + +export const NotRequired: StoryObj = { + args: { + _patternId: '', + type: 'text-area', + inputId: 'test-textarea', + value: '', + label: 'Please enter your comments', + required: false, + maxLength: 500, + }, +}; + +export const ErrorState: StoryObj = { + args: { + _patternId: '', + type: 'text-area', + inputId: 'test-textarea', + value: '', + label: 'Please enter your comments', + required: true, + maxLength: 500, + error: { + type: 'required', + message: 'This field is required', + }, + }, +}; + +export const WithHint: StoryObj = { + args: { + _patternId: '', + type: 'text-area', + inputId: 'test-textarea', + value: '', + label: 'Please enter your comments', + required: false, + maxLength: 500, + hint: 'This is a hint that provides additional context to the user.', + }, +}; diff --git a/packages/design/src/Form/components/TextArea/index.tsx b/packages/design/src/Form/components/TextArea/index.tsx new file mode 100644 index 00000000..4d13960a --- /dev/null +++ b/packages/design/src/Form/components/TextArea/index.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +import classNames from 'classnames'; +import { useFormContext } from 'react-hook-form'; + +import { type TextAreaProps } from '@atj/forms'; +import { type PatternComponent } from '../../../Form/index.js'; + +const TextArea: PatternComponent = ({ + inputId, + label, + required, + error, + value, + hint, + maxLength, +}) => { + const { register } = useFormContext(); + const errorId = `input-error-message-${inputId}`; + const hintId = `input-hint-${inputId}`; + + return ( +
+
+
+ + {hint && ( +
+ {hint} +
+ )} + {error && ( + + )} +