OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Add form-field stories
Benjamin Bädorf012e98e4d5a9
diff --git a/frontend/.storybook/main.js b/frontend/.storybook/main.jsindex d351ae716ec..11fcea1a452 100644--- a/frontend/.storybook/main.js+++ b/frontend/.storybook/main.js@@ -19,7 +19,7 @@ module.exports = {},features: {previewMdx2: true,- modernInlineRender: true,+ // modernInlineRender: true,},staticDirs: [{ from: '../src/stories/assets', to: '/assets' },diff --git a/frontend/.storybook/preview.js b/frontend/.storybook/preview.jsindex 94dd8e2fff0..32e4f6932dc 100644--- a/frontend/.storybook/preview.js+++ b/frontend/.storybook/preview.js@@ -1,15 +1,13 @@import { setCompodocJson } from "@storybook/addon-docs/angular";-import { addParameters } from '@storybook/client-api';import { themes } from '@storybook/theming';import docJson from "../documentation.json";setCompodocJson(docJson);-addParameters({- viewMode: 'docs',-});-export const parameters = {+ parameters: {+ viewMode: 'docs',+ },actions: { argTypesRegex: "^on[A-Z].*" },controls: {matchers: {diff --git a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.htmlindex cfd46505b67..2f4b8bf0099 100644--- a/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html+++ b/frontend/src/app/features/user-preferences/notifications-settings/page/notifications-settings-page.component.html@@ -40,12 +40,12 @@[label]="text.watched"[control]="form.get('watched')">- <input- disabled- checked- type="checkbox"- slot="input"- />+ <input+ disabled+ checked+ type="checkbox"+ slot="input"+ /></spot-selector-field><spot-selector-fielddiff --git a/frontend/src/app/spot/components/form-field/form-field.component.html b/frontend/src/app/spot/components/form-field/form-field.component.htmlindex 0b936e04aae..0206c6c4b1e 100644--- a/frontend/src/app/spot/components/form-field/form-field.component.html+++ b/frontend/src/app/spot/components/form-field/form-field.component.html@@ -23,6 +23,13 @@<ng-container *ngTemplateOutlet="inputTemplate"></ng-container></ng-container>+ <div+ class="spot-form-field--description"+ [id]="descriptionID"+ >+ <ng-content select="[slot=description]"></ng-content>+ </div>+<divclass="spot-form-field--errors"*ngIf="showErrorMessage"@@ -31,21 +38,12 @@<ng-content select="[slot=errors]"></ng-content></div>- <div- class="spot-form-field--action"- >+ <div class="spot-form-field--actions"><ng-content select="[slot=action]"></ng-content></div></ng-container><ng-template #inputTemplate>- <div- class="spot-form-field--description"- [id]="descriptionID"- >- <ng-content select="[slot=description]"></ng-content>- </div>-<divclass="spot-form-field--input"[attr.aria-describedby]="describedByID"diff --git a/frontend/src/app/spot/components/form-field/stories/FormField.stories.mdx b/frontend/src/app/spot/components/form-field/stories/FormField.stories.mdxindex 8c267ec9418..d8353c6914a 100644--- a/frontend/src/app/spot/components/form-field/stories/FormField.stories.mdx+++ b/frontend/src/app/spot/components/form-field/stories/FormField.stories.mdx@@ -1,15 +1,22 @@import { moduleMetadata } from '@storybook/angular';+import { ReactiveFormsModule } from '@angular/forms';import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';import { OpSpotModule } from '../../../spot.module';import { SpotFormFieldComponent } from '../form-field.component';+import { SbFormFieldInputSlotExample } from './FormFieldInputSlot.example';+import { SbFormFieldDescriptionSlotExample } from './FormFieldDescriptionSlot.example';+import { SbFormFieldErrorSlotExample } from './FormFieldErrorSlot.example';+import { SbFormFieldActionSlotExample } from './FormFieldActionSlot.example';+<Metatitle="Patterns/Form Field"component={SpotFormFieldComponent}decorators={[moduleMetadata({imports: [+ ReactiveFormsModule,OpSpotModule,],}),@@ -24,4 +31,93 @@ import { SpotFormFieldComponent } from '../form-field.component';# Form Field+Form fields are a smart wrapper around input fields. Form fields handle labels, validation messages, help texts, and+extra actions around an input field.++## Basic usage++Form fields work with `ng-content` a lot, which we call `slot` in SPOT. There are four slots in which content can be+fitted:++1. `input` holds the input. It can be a text input or select dropdown, or anything else that is not a+ selection toggle.+2. `help-text` holds the attribute help text. To achieve separation of concerns, if you want to show an attribute help+ text this is where the `attribute-help-text` component goes.+3. `errors` holds validation errors.+4. `description` holds a short description of the input field. Oftentimes these are short, helpful guidelines about how+ or what to input into the field.+5. `action` holds extra input actions. Most often, these are `button` elements styled as a `spot-link` that allow the user to+ perform an action related to the input.++Some of these require adding an extra class on that element, so watch the examples carefully!++## Adding an input++Use `slot="input"` to select the input element:++<Canvas>+ <Story name="Input slot">+ {{ component: SbFormFieldInputSlotExample }}+ </Story>+</Canvas>++## Adding a description++Use `slot="description"` to select the input element:++<Canvas>+ <Story name="Description slot">+ {{ component: SbFormFieldDescriptionSlotExample }}+ </Story>+</Canvas>+++## Adding a help text++Use `slot="help-text"` to select the `attribute-help-text` component:++```html+<spot-form-field label="Form field with help text">+ <spot-text-field slot="input"></spot-text-field>+ <attribute-help-text+ slot="help-text"+ class="spot-form-field--help-text"+ ></attribute-help-text>+</spot-form-field>+```++The example above cannot currently be rendered in Storybook, because the `attribute-help-text` component requires the+API to be available. They are in use in the project and work package dynamic form. So if you add an attribute help text,+they will show up there.++## Handling validation++SPOT works best with reactive forms. If you have a `FormControl` for your input, `spot-form-field` will be able to+figure out the validation state automagically.++Use `slot="errors"` to set validation errors. You can set multiple errors independently by all giving them the `slot`+attribute.++<Canvas>+ <Story name="Basic validation">+ {{ component: SbFormFieldErrorSlotExample }}+ </Story>+</Canvas>++As you can see, by default validation messages will only be shown on submit. You can change this behavior by changing+the `showValidationErrorOn` input to the `spot-form-field` component.++The `required` input only makes sure the asterisk at the end of the label is shown, it does not add any validation to+the form or input.++## Adding extra input actions++Form field actions allow you to add extra action buttons to the context of an input field.++<Canvas>+ <Story name="Actions">+ {{ component: SbFormFieldActionSlotExample }}+ </Story>+</Canvas>+<ArgsTable of={SpotFormFieldComponent} />diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldActionSlot.example.html b/frontend/src/app/spot/components/form-field/stories/FormFieldActionSlot.example.htmlnew file mode 100644index 00000000000..0598d685cd9--- /dev/null+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldActionSlot.example.html@@ -0,0 +1,15 @@+<spot-form-field label="Form field with input">+ <spot-text-field slot="input"></spot-text-field>+ <button+ type="button"+ (click)="alert('Some action')"+ class="spot-link"+ slot="action"+ >Some action</button>+ <button+ type="button"+ (click)="alert('Another action')"+ class="spot-link"+ slot="action"+ >Another action</button>+</spot-form-field>diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldActionSlot.example.ts b/frontend/src/app/spot/components/form-field/stories/FormFieldActionSlot.example.tsnew file mode 100644index 00000000000..0721014c690--- /dev/null+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldActionSlot.example.ts@@ -0,0 +1,10 @@+import { Component } from '@angular/core';++@Component({+ templateUrl: './FormFieldActionSlot.example.html',+})+export class SbFormFieldActionSlotExample {+ alert(s:string){+ alert(s);+ }+}diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.html b/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.htmldeleted file mode 100644index 8ac5222eef4..00000000000--- a/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.html+++ /dev/null@@ -1,8 +0,0 @@-<spot-form-field- [label]="label"- [disabled]="disabled"->- <spot-text-field- slot="input"- ></spot-text-field>-</spot-form-field>diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.ts b/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.tsdeleted file mode 100644index 288525dd513..00000000000--- a/frontend/src/app/spot/components/form-field/stories/FormFieldBasic.example.ts+++ /dev/null@@ -1,14 +0,0 @@-import {- Component,- Input,-} from '@angular/core';--@Component({- selector: 'sb-form-field-basic',- templateUrl: './FormFieldBasic.example.html',-})-export class SbFormFieldBasicExampleComponent {- @Input('label') public label = '';- @Input('disabled') public disabled = false;- @Input('open') public dropModalOpen = false;-}diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldDescriptionSlot.example.html b/frontend/src/app/spot/components/form-field/stories/FormFieldDescriptionSlot.example.htmlnew file mode 100644index 00000000000..01e3eed9159--- /dev/null+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldDescriptionSlot.example.html@@ -0,0 +1,6 @@+<spot-form-field label="Form field with description">+ <spot-text-field slot="input"></spot-text-field>+ <span slot="description">+ Helpful guidelines so the user can be confident about their input.+ </span>+</spot-form-field>diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldDescriptionSlot.example.ts b/frontend/src/app/spot/components/form-field/stories/FormFieldDescriptionSlot.example.tsnew file mode 100644index 00000000000..526f07936c4--- /dev/null+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldDescriptionSlot.example.ts@@ -0,0 +1,6 @@+import { Component } from '@angular/core';++@Component({+ templateUrl: './FormFieldDescriptionSlot.example.html',+})+export class SbFormFieldDescriptionSlotExample { }diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldErrorSlot.example.html b/frontend/src/app/spot/components/form-field/stories/FormFieldErrorSlot.example.htmlnew file mode 100644index 00000000000..7ab42b8ea37--- /dev/null+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldErrorSlot.example.html@@ -0,0 +1,40 @@+<form+ [formGroup]="myForm"+ (ngSubmit)="onSubmit($event)"+ class="spot-container"+>+ <spot-form-field+ label="Form field with validation"+ [required]="true"+ >+ <spot-text-field+ formControlName="myInput"+ slot="input"+ ></spot-text-field>++ <div+ slot="errors"+ class="spot-form-field--error"+ *ngIf="myInputControl.errors?.required"+ >+ This input is required.+ </div>++ <div+ slot="errors"+ class="spot-form-field--error"+ *ngIf="myInputControl.errors?.minlength"+ >+ This input needs to be at least 8 characters long.+ </div>+ </spot-form-field>++ <div class="spot-action-bar">+ <div class="spot-action-bar--right">+ <button+ type="submit"+ class="button -highlight spot-action-bar--action"+ >Submit data</button>+ </div>+ </div>+</form>diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldErrorSlot.example.ts b/frontend/src/app/spot/components/form-field/stories/FormFieldErrorSlot.example.tsnew file mode 100644index 00000000000..82e68a2f871--- /dev/null+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldErrorSlot.example.ts@@ -0,0 +1,25 @@+import { Component } from '@angular/core';+import {+ FormGroup,+ FormControl,+ Validators,+} from '@angular/forms';++@Component({+ templateUrl: './FormFieldErrorSlot.example.html',+})+export class SbFormFieldErrorSlotExample {+ public myForm = new FormGroup({+ myInput: new FormControl(null, [Validators.required, Validators.minLength(8)]),+ });++ get myInputControl() {+ return this.myForm.get('myInput')!;+ }++ onSubmit(event:Event) {+ event.preventDefault();+ console.log('submitted!');+ console.log(this.myInputControl);+ }+}diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldInputSlot.example.html b/frontend/src/app/spot/components/form-field/stories/FormFieldInputSlot.example.htmlnew file mode 100644index 00000000000..6deb2d24889--- /dev/null+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldInputSlot.example.html@@ -0,0 +1,3 @@+<spot-form-field label="Form field with input">+ <spot-text-field slot="input"></spot-text-field>+</spot-form-field>diff --git a/frontend/src/app/spot/components/form-field/stories/FormFieldInputSlot.example.ts b/frontend/src/app/spot/components/form-field/stories/FormFieldInputSlot.example.tsnew file mode 100644index 00000000000..f43222c2e78--- /dev/null+++ b/frontend/src/app/spot/components/form-field/stories/FormFieldInputSlot.example.ts@@ -0,0 +1,6 @@+import { Component } from '@angular/core';++@Component({+ templateUrl: './FormFieldInputSlot.example.html',+})+export class SbFormFieldInputSlotExample { }diff --git a/frontend/src/app/spot/styles/sass/components/form-field.sass b/frontend/src/app/spot/styles/sass/components/form-field.sassindex 0d42cf5b765..228e25508a6 100644--- a/frontend/src/app/spot/styles/sass/components/form-field.sass+++ b/frontend/src/app/spot/styles/sass/components/form-field.sass@@ -26,10 +26,16 @@color: $spot-color-basic-black&--help-text- padding-left: $spot-spacing-0-25+ padding-left: $spot-spacing-0_25- &--action+ &--actions@include spot-body-small+ display: flex+ flex-direction: row+ flex-wrap: wrap++ > *+ margin-right: $spot-spacing-0_5&--inputmargin-bottom: $spot-spacing-0_25