discourse/app/assets/stylesheets/common/admin/badges.scss
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

199 lines
3.6 KiB
SCSS

// Styles for admin/badges
.admin-badges {
// flex page layout
.badges {
display: flex;
flex-wrap: wrap;
.badges-header {
display: flex;
align-items: center;
flex: 1 0 100%;
.create-new-badge {
margin-left: auto;
display: flex;
align-items: center;
gap: 0.5em;
}
}
.content-list {
flex: 0 0 27%;
}
.current-badges {
display: flex;
justify-content: center;
flex: 1 1 72%;
}
}
.badges-header {
padding: 10px 0;
border-top: 1px solid var(--primary-low);
border-bottom: 1px solid var(--primary-low);
.badges-heading {
margin: 0;
padding: 0 10px;
}
}
.content-list {
.admin-badge-list {
height: 70vh;
overflow-y: scroll;
border-right: 1px solid var(--primary-low);
border-left: 1px solid var(--primary-low);
border-bottom: 1px solid var(--primary-low);
.admin-badge-list-item {
&:first-child {
border-top: none;
}
&:last-child {
border-top: none;
}
}
.list-badge {
float: right;
font-size: var(--font-down-1);
font-weight: normal;
padding: 0 6px;
color: var(--secondary);
background-color: var(--tertiary-medium);
border-radius: 3px;
}
}
.user-badge {
border: none;
background-color: unset;
}
}
.current-badge-header {
display: flex;
gap: 1em;
align-items: center;
font-size: var(--font-up-2-rem);
img {
border-radius: var(--d-border-radius-large);
max-width: 36px;
}
.d-icon {
font-size: 36px;
}
.badge-display-name {
font-size: var(--font-up-1);
font-weight: bold;
word-break: break-word;
}
}
.current-badge {
margin: 20px;
.form-kit__field-question {
.form-kit__control-radio-label {
text-transform: capitalize;
}
}
.readonly-field {
color: var(--primary-high);
}
}
.current-badge-actions {
margin: 10px;
padding: 10px;
border-top: 1px solid var(--primary-low);
}
}
.award-badge {
margin: 15px 0 0 15px;
float: left;
max-width: 70%;
.bulk-award-status-icon {
margin-right: 3px;
&.success {
color: var(--success);
}
&.failure {
color: var(--danger);
}
}
.badge-preview {
min-height: 110px;
max-width: 300px;
display: flex;
align-items: center;
background-color: var(--primary-very-low);
border: 1px solid var(--primary-low);
padding: 0 10px 0 10px;
img,
svg {
width: 60px;
height: 60px;
}
.badge-display-name {
margin-left: 5px;
}
}
.badge-required {
font-weight: bold;
}
}
// badge-grouping modal
.badge-groupings-modal {
.badge-groupings {
margin-bottom: 10px;
}
.badge-groupings-list {
list-style: none;
margin: 0;
.badge-grouping-item {
border-bottom: 1px solid var(--primary-low);
display: flex;
justify-content: space-between;
align-items: center;
padding: 5px 0;
}
.badge-grouping {
.badge-grouping-name-input {
margin: 0;
}
}
}
}
// badge preview modal
.badge-query-preview {
.badge-query-plan {
overflow-x: auto;
}
.badge-errors,
.badge-query-plan {
padding: 5px;
background-color: var(--primary-low);
white-space: pre-wrap;
}
.count-warning {
background-color: var(--danger-low);
margin-bottom: 5px;
padding: 10px;
p {
margin: 0;
}
.heading {
color: var(--danger);
font-weight: bold;
}
}
}