2022-12-09 14:33:15 -05:00
|
|
|
// These CSS custom properties are added here instead of in variables.scss
|
|
|
|
// because variables.scss is injected into every theme CSS file
|
|
|
|
// which causes problems when overriding custom properties in themes
|
|
|
|
|
|
|
|
:root {
|
|
|
|
--topic-body-width: #{$topic-body-width};
|
|
|
|
--topic-body-width-padding: #{$topic-body-width-padding};
|
|
|
|
--topic-avatar-width: #{$topic-avatar-width};
|
2024-04-08 16:21:57 -04:00
|
|
|
--d-border-radius: 2px;
|
|
|
|
--d-border-radius-large: 2px;
|
2022-12-09 14:33:15 -05:00
|
|
|
--d-nav-pill-border-radius: var(--d-border-radius);
|
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 05:59:35 -04:00
|
|
|
--d-button-border-radius: 2px;
|
|
|
|
--d-input-border-radius: 2px;
|
2023-09-08 12:07:04 -04:00
|
|
|
--d-content-background: initial;
|
2023-12-07 09:51:14 -05:00
|
|
|
--d-font-family--monospace: Consolas, Menlo, Monaco, "Lucida Console",
|
|
|
|
"Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono",
|
|
|
|
"Courier New", monospace;
|
2024-06-20 13:51:20 -04:00
|
|
|
--d-button-transition: none;
|
2022-12-09 14:33:15 -05:00
|
|
|
}
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
// --------------------------------------------------
|
|
|
|
// Base styles for HTML elements
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
html {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--primary);
|
2022-10-12 10:05:42 -04:00
|
|
|
font-family: var(--font-family);
|
|
|
|
font-size: var(--base-font-size);
|
|
|
|
line-height: var(--line-height-large);
|
2020-08-03 22:57:10 -04:00
|
|
|
background-color: var(--secondary);
|
2013-02-05 14:16:51 -05:00
|
|
|
overflow-y: scroll;
|
2015-04-14 22:07:23 -04:00
|
|
|
direction: ltr;
|
2019-01-14 08:21:46 -05:00
|
|
|
|
2020-07-07 13:08:19 -04:00
|
|
|
&.text-size-smallest {
|
2022-10-12 10:05:42 -04:00
|
|
|
font-size: var(--base-font-size-smallest);
|
2020-07-07 13:08:19 -04:00
|
|
|
}
|
|
|
|
|
2019-01-17 10:30:34 -05:00
|
|
|
&.text-size-smaller {
|
2022-10-12 10:05:42 -04:00
|
|
|
font-size: var(--base-font-size-smaller);
|
2019-01-17 10:30:34 -05:00
|
|
|
}
|
|
|
|
|
2019-01-14 08:21:46 -05:00
|
|
|
&.text-size-larger {
|
2022-10-12 10:05:42 -04:00
|
|
|
font-size: var(--base-font-size-larger);
|
2019-01-14 08:21:46 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
&.text-size-largest {
|
2022-10-12 10:05:42 -04:00
|
|
|
font-size: var(--base-font-size-largest);
|
2019-01-14 08:21:46 -05:00
|
|
|
}
|
2014-07-02 10:55:43 -04:00
|
|
|
}
|
2013-02-05 14:16:51 -05:00
|
|
|
|
|
|
|
// Links
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
a {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--tertiary);
|
2013-02-05 14:16:51 -05:00
|
|
|
text-decoration: none;
|
2013-06-16 23:43:30 -04:00
|
|
|
cursor: pointer;
|
2013-02-05 14:16:51 -05:00
|
|
|
&:visited {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--tertiary);
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
&:hover {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--tertiary);
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
&:active {
|
2020-08-03 22:57:10 -04:00
|
|
|
color: var(--tertiary);
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Typography
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
hr {
|
|
|
|
display: block;
|
|
|
|
height: 1px;
|
|
|
|
margin: 1em 0;
|
|
|
|
border: 0;
|
2020-08-03 22:57:10 -04:00
|
|
|
border-top: 1px solid var(--primary-low);
|
2013-02-05 14:16:51 -05:00
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Lists
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
ul,
|
2022-02-22 16:17:41 -05:00
|
|
|
ol,
|
2013-02-05 14:16:51 -05:00
|
|
|
dd {
|
2021-05-25 23:52:33 -04:00
|
|
|
margin: 1em 0 1em 1.25em;
|
2013-02-05 14:16:51 -05:00
|
|
|
padding: 0;
|
|
|
|
}
|
|
|
|
|
2018-06-08 05:49:31 -04:00
|
|
|
.cooked ul,
|
|
|
|
.cooked ol,
|
|
|
|
.cooked dd {
|
2014-03-27 15:36:14 -04:00
|
|
|
clear: both;
|
2014-03-15 12:01:17 -04:00
|
|
|
}
|
|
|
|
|
2022-02-22 16:17:41 -05:00
|
|
|
.cooked,
|
|
|
|
.d-editor-preview {
|
|
|
|
ul,
|
|
|
|
ol {
|
|
|
|
padding-left: 1.25em;
|
|
|
|
}
|
2017-07-25 18:24:11 -04:00
|
|
|
}
|
|
|
|
|
2021-05-25 23:52:33 -04:00
|
|
|
li,
|
|
|
|
.cooked li,
|
|
|
|
.d-editor-preview li {
|
2013-02-05 14:16:51 -05:00
|
|
|
> ul,
|
|
|
|
> ol {
|
2021-05-25 23:52:33 -04:00
|
|
|
margin: 0;
|
2013-02-05 14:16:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Embedded content
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
img {
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
|
|
|
|
2023-12-13 09:34:29 -05:00
|
|
|
.svg-icon {
|
|
|
|
color: inherit;
|
|
|
|
}
|
|
|
|
|
2013-02-05 14:16:51 -05:00
|
|
|
// Forms
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
fieldset {
|
|
|
|
margin: 0;
|
|
|
|
border: 0;
|
|
|
|
padding: 0;
|
2013-06-16 23:43:30 -04:00
|
|
|
}
|
2013-06-20 03:46:18 -04:00
|
|
|
|
|
|
|
pre code {
|
|
|
|
overflow: auto;
|
2020-05-05 21:00:40 -04:00
|
|
|
-moz-tab-size: 4;
|
2017-01-10 04:06:53 -05:00
|
|
|
tab-size: 4;
|
2020-07-08 20:50:42 -04:00
|
|
|
&.lang-markdown {
|
|
|
|
white-space: pre-wrap;
|
|
|
|
}
|
2013-06-20 03:46:18 -04:00
|
|
|
}
|
2014-08-25 17:41:14 -04:00
|
|
|
|
2018-04-30 20:45:49 -04:00
|
|
|
// Tables
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
2020-07-06 09:25:41 -04:00
|
|
|
table {
|
|
|
|
border-collapse: collapse;
|
|
|
|
}
|
|
|
|
|
2018-04-30 20:45:49 -04:00
|
|
|
tbody {
|
2020-08-03 22:57:10 -04:00
|
|
|
border-top: 3px solid var(--primary-low);
|
2018-04-30 20:45:49 -04:00
|
|
|
}
|
|
|
|
|
2021-11-15 15:49:45 -05:00
|
|
|
.topic-list-item,
|
2018-04-30 20:45:49 -04:00
|
|
|
tr {
|
2020-08-03 22:57:10 -04:00
|
|
|
border-bottom: 1px solid var(--primary-low);
|
2023-09-14 17:31:43 -04:00
|
|
|
@media (prefers-reduced-motion: no-preference) {
|
|
|
|
&.highlighted {
|
|
|
|
animation: background-fade-highlight 2.5s ease-out;
|
|
|
|
}
|
2018-06-08 05:49:31 -04:00
|
|
|
}
|
|
|
|
}
|
2018-08-03 13:37:08 -04:00
|
|
|
|
|
|
|
// https://en.wikipedia.org/wiki/Ruby_character
|
|
|
|
ruby > rt {
|
|
|
|
font-size: 72%; // ~10px with 14px base
|
|
|
|
}
|
2020-07-06 07:15:31 -04:00
|
|
|
|
|
|
|
// Buttons (was in normalized)
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
button,
|
|
|
|
html input[type="button"],
|
|
|
|
input[type="reset"],
|
|
|
|
input[type="submit"] {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
2021-09-09 11:01:56 -04:00
|
|
|
|
|
|
|
// Inline form
|
|
|
|
// --------------------------------------------------
|
|
|
|
|
|
|
|
.inline-form {
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
&.full-width {
|
|
|
|
display: flex;
|
|
|
|
}
|
|
|
|
|
2022-02-03 07:50:24 -05:00
|
|
|
> input[type="text"],
|
2023-10-13 12:24:06 -04:00
|
|
|
> input[type="search"],
|
|
|
|
> input[type="password"] {
|
2021-09-09 11:01:56 -04:00
|
|
|
display: inline-flex;
|
|
|
|
flex: 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .select-kit,
|
|
|
|
> input[type="text"],
|
2022-02-03 07:50:24 -05:00
|
|
|
> input[type="search"],
|
2023-10-13 12:24:06 -04:00
|
|
|
> input[type="password"],
|
2021-09-09 11:01:56 -04:00
|
|
|
> label,
|
2021-09-20 10:01:11 -04:00
|
|
|
> .btn,
|
|
|
|
> .d-date-input {
|
2021-09-09 11:01:56 -04:00
|
|
|
margin-bottom: 0.5em; // for when items wrap (mobile, narrow windows)
|
|
|
|
margin-right: 0.5em;
|
|
|
|
&:last-child {
|
|
|
|
margin-right: 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|