discourse/app/assets/stylesheets/common
chapoi 2ca06ba236
DEV: form-kit
This PR introduces FormKit, a component-based form library designed to simplify form creation and management. This library provides a single `Form` component, various field components, controls, validation mechanisms, and customization options. Additionally, it includes helpers to facilitate testing and writing specifications for forms.

1. **Form Component**:
   - The main component that encapsulates form logic and structure.
   - Yields various utilities like `Field`, `Submit`, `Alert`, etc.

   **Example Usage**:
   ```gjs
   import Form from "discourse/form";

   <template>
     <Form as |form|>
       <form.Field
         @name="username"
         @title="Username"
         @validation="required"
         as |field|
       >
         <field.Input />
       </form.Field>

       <form.Field @name="age" @title="Age" as |field|>
         <field.Input @type="number" />
       </form.Field>

       <form.Submit />
     </Form>
   </template>
   ```

2. **Validation**:
   - Built-in validation rules such as `required`, `number`, `length`, and `url`.
   - Custom validation callbacks for more complex validation logic.

   **Example Usage**:
   ```javascript
   validateUsername(name, value, data, { addError }) {
     if (data.bar / 2 === value) {
       addError(name, "That's not how maths work.");
     }
   }
   ```

   ```hbs
   <form.Field @name="username" @validate={{this.validateUsername}} />
   ```

3. **Customization**:
   - Plugin outlets for extending form functionality.
   - Styling capabilities through propagated attributes.
   - Custom controls with properties provided by `form` and `field`.

   **Example Usage**:
   ```hbs
   <Form class="my-form" as |form|>
     <form.Field class="my-field" as |field|>
       <MyCustomControl id={{field.id}} @onChange={{field.set}} />
     </form.Field>
   </Form>
   ```

4. **Helpers for Testing**:
   - Test assertions for form and field validation.

   **Example usage**:
   ```javascript
   assert.form().hasErrors("the form shows errors");
   assert.form().field("foo").hasValue("bar", "user has set the value");
   ```

   - Helper for interacting with he form

   **Example usage**:
   ```javascript
   await formKit().field("foo").fillIn("bar");
   ```

5. **Page Object for System Specs**:
   - Page objects for interacting with forms in system specs.
   - Methods for submitting forms, checking alerts, and interacting with fields.

   **Example Usage**:
   ```ruby
   form = PageObjects::Components::FormKit.new(".my-form")
   form.submit
   expect(form).to have_an_alert("message")
   ```

   **Field Interactions**:
   ```ruby
   field = form.field("foo")
   expect(field).to have_value("bar")
   field.fill_in("bar")
   ```


6. **Collections handling**:
   - A specific component to handle array of objects

   **Example Usage**:
   ```gjs
    <Form @data={{hash foo=(array (hash bar=1) (hash bar=2))}} as |form|>
      <form.Collection @name="foo" as |collection|>
        <collection.Field @name="bar" @title="Bar" as |field|>
          <field.Input />
        </collection.Field>
      </form.Collection>
    </Form>
   ```
2024-07-17 11:59:35 +02:00
..
admin DEV: form-kit 2024-07-17 11:59:35 +02:00
base DEV: form-kit 2024-07-17 11:59:35 +02:00
components DEV: form-kit 2024-07-17 11:59:35 +02:00
float-kit DEV: allows for multiple menus/tooltips (#26823) 2024-05-07 23:48:44 +02:00
form-kit DEV: form-kit 2024-07-17 11:59:35 +02:00
foundation DEV: form-kit 2024-07-17 11:59:35 +02:00
login UX: cleaning up some invite page styles (#25247) 2024-01-12 17:15:01 -05:00
modal UX: add max-width to social auth section (#27771) 2024-07-08 13:20:18 -04:00
select-kit UX: allow category names in select-kit to truncate if needed (#27941) 2024-07-16 17:52:17 -04:00
table-builder DEV: update classes, remove unused CSS (#25825) 2024-02-23 09:14:37 -05:00
d-editor.scss UX: move composer image controls below image (#27610) 2024-06-25 15:51:52 -04:00
font-variables.scss UX: increase base font-size to 16px (#27087) 2024-05-20 21:08:20 +02:00
input_tip.scss UX: Hide the error tooltip when focusing the topic title (#27531) 2024-06-19 11:55:29 -03:00
loading-slider.scss FIX: better supports ipad and hub footer nav (#25518) 2024-02-01 10:24:44 +01:00
post-action-feedback.scss FIX: allow styling of feedback on mobile (#25072) 2023-12-30 08:57:16 +11:00
printer-friendly.scss FEATURE: remove category badge style options, set bullet style as default (#24198) 2023-11-13 10:46:15 -05:00
software-update-prompt.scss REFACTOR: move shadow vars to css custom props (#22094) 2023-06-13 16:38:31 -04:00
topic-entrance.scss DEV: Implement glimmer topic-list (#26743) 2024-05-21 14:36:15 +02:00
topic-timeline.scss UX: topic admin button should match height of siblings (#26973) 2024-05-13 11:23:00 -04:00
whcm.scss A11Y: Improve accessibility in WHCM themes (#18606) 2022-10-17 07:07:46 -07:00