From 0924171c0f108f59c858c73362367f0f13cccc08 Mon Sep 17 00:00:00 2001 From: diondiondion Date: Thu, 22 Jan 2026 17:08:57 +0100 Subject: [PATCH] Add form field components: `TextInputField`, `TextAreaField`, `SelectField` (#37578) --- .../mastodon/components/form_fields/index.ts | 3 + .../form_fields/select_field.stories.tsx | 55 ++++++++++ .../components/form_fields/select_field.tsx | 38 +++++++ .../form_fields/text_area_field.stories.tsx | 45 ++++++++ .../form_fields/text_area_field.tsx | 31 ++++++ .../form_fields/text_input_field.stories.tsx | 45 ++++++++ .../form_fields/text_input_field.tsx | 36 +++++++ .../components/form_fields/wrapper.tsx | 100 ++++++++++++++++++ .../mastodon/features/lists/new.tsx | 100 +++++++----------- .../mastodon/features/onboarding/profile.tsx | 60 ++++------- app/javascript/mastodon/locales/en.json | 1 + 11 files changed, 418 insertions(+), 96 deletions(-) create mode 100644 app/javascript/mastodon/components/form_fields/index.ts create mode 100644 app/javascript/mastodon/components/form_fields/select_field.stories.tsx create mode 100644 app/javascript/mastodon/components/form_fields/select_field.tsx create mode 100644 app/javascript/mastodon/components/form_fields/text_area_field.stories.tsx create mode 100644 app/javascript/mastodon/components/form_fields/text_area_field.tsx create mode 100644 app/javascript/mastodon/components/form_fields/text_input_field.stories.tsx create mode 100644 app/javascript/mastodon/components/form_fields/text_input_field.tsx create mode 100644 app/javascript/mastodon/components/form_fields/wrapper.tsx diff --git a/app/javascript/mastodon/components/form_fields/index.ts b/app/javascript/mastodon/components/form_fields/index.ts new file mode 100644 index 0000000000..2aa8764514 --- /dev/null +++ b/app/javascript/mastodon/components/form_fields/index.ts @@ -0,0 +1,3 @@ +export { TextInputField } from './text_input_field'; +export { TextAreaField } from './text_area_field'; +export { SelectField } from './select_field'; diff --git a/app/javascript/mastodon/components/form_fields/select_field.stories.tsx b/app/javascript/mastodon/components/form_fields/select_field.stories.tsx new file mode 100644 index 0000000000..30897adda1 --- /dev/null +++ b/app/javascript/mastodon/components/form_fields/select_field.stories.tsx @@ -0,0 +1,55 @@ +import type { Meta, StoryObj } from '@storybook/react-vite'; + +import { SelectField } from './select_field'; + +const meta = { + title: 'Components/Form Fields/SelectField', + component: SelectField, + args: { + label: 'Fruit preference', + hint: 'Select your favourite fruit or not. Up to you.', + }, + render(args) { + // Component styles require a wrapper class at the moment + return ( +
+ + + + + + + + + + + +
+ ); + }, +} satisfies Meta; + +export default meta; + +type Story = StoryObj; + +export const Simple: Story = {}; + +export const Required: Story = { + args: { + required: true, + }, +}; + +export const Optional: Story = { + args: { + required: false, + }, +}; + +export const WithError: Story = { + args: { + required: false, + hasError: true, + }, +}; diff --git a/app/javascript/mastodon/components/form_fields/select_field.tsx b/app/javascript/mastodon/components/form_fields/select_field.tsx new file mode 100644 index 0000000000..aa058fc782 --- /dev/null +++ b/app/javascript/mastodon/components/form_fields/select_field.tsx @@ -0,0 +1,38 @@ +import type { ComponentPropsWithoutRef } from 'react'; +import { forwardRef } from 'react'; + +import { FormFieldWrapper } from './wrapper'; +import type { CommonFieldWrapperProps } from './wrapper'; + +interface Props + extends ComponentPropsWithoutRef<'select'>, CommonFieldWrapperProps {} + +/** + * A simple form field for single-item selections. + * Provide selectable items via nested `