Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Form component #409

Merged
merged 18 commits into from
Jul 23, 2024
Merged

Add Form component #409

merged 18 commits into from
Jul 23, 2024

Conversation

mkernohanbc
Copy link
Contributor

@mkernohanbc mkernohanbc commented Jul 18, 2024

Cherry-picked from #401 so that we can test with new components. Scope of this PR is the same:

This PR adds a new Form component, based on RAC Form. An example instance and documentation page in Storybook is also included.

The Form component is intended to be used as a wrapper around other components, to provide additional support for data validation and submission and form styling. It renders an HTML <form> element.

By default, the Form component renders without any styling of its own. The className prop can be used to style the form as a whole.

Some boilerplate CSS is included (see Form.css). This is currently only used to style the example form in Storybook.

@mkernohanbc mkernohanbc linked an issue Jul 18, 2024 that may be closed by this pull request
@mkernohanbc mkernohanbc added the enhancement New feature or request label Jul 18, 2024
@mkernohanbc mkernohanbc self-assigned this Jul 18, 2024
@mkernohanbc mkernohanbc mentioned this pull request Jul 18, 2024
@mkernohanbc mkernohanbc requested a review from ty2k July 18, 2024 22:01
@mkernohanbc
Copy link
Contributor Author

c19a71d simplifies the component structure:

  • removes explicit prop declarations and CSS import from the component itself
  • adds props as argTypes in Form.stories.tsx instead
  • moves boilerplate CSS used for Storybook example into /src/stories
  • expands documentation page in Storybook, in a separate 'Utility' section

This component is a convenience, that simply enables the user to import the RAC Form component without needing to add an additional dependency.

With that, I think this is ready for review!

@mkernohanbc mkernohanbc marked this pull request as ready for review July 22, 2024 22:38
Copy link
Contributor

@ty2k ty2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great addition! 🚀 Just one small change to the MDX file to make the code sample more readable.

When testing this component, I find the HTML validation is super easy to use. Features like passing type="email" to an input field or type="reset" to a button just work.

Example:

<Form>
  <TextField label="Name" isRequired />
  <TextField type="email" label="Email" isRequired />
  <Select
    label="Employment status"
    items={[
      { id: "employee", label: "Employee" },
      { id: "contractor", label: "Contractor" },
    ]}
    isRequired
  />
  <Button type="submit" variant="primary">
    Submit
  </Button>
  <Button type="reset" variant="secondary">
    Reset
  </Button>
</Form>

After interacting with each field:
Validation error example

With valid data in each field:
Valid data example

Invalid email:
Invalid email example


### CSS for this example form

<Source
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of using the <Source> block, let's use a code fence so that the whitespace within the CSS snippet won't get mangled on save:

Screenshot 2024-07-23 at 1 41 54 PM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 78cf1c9!

@mkernohanbc mkernohanbc requested a review from ty2k July 23, 2024 20:55
Copy link
Contributor

@ty2k ty2k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! ✅

Form component CSS

@mkernohanbc mkernohanbc merged commit 94931bf into main Jul 23, 2024
4 checks passed
@mkernohanbc mkernohanbc deleted the feature/form-wrapper branch July 24, 2024 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Form wrapper
2 participants