2022-07-26 14:48:11 +02:00
|
|
|
import { UntypedFormBuilder, FormsModule, ReactiveFormsModule, Validators } from "@angular/forms";
|
2022-06-02 09:34:13 +02:00
|
|
|
import { Meta, moduleMetadata, Story } from "@storybook/angular";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
2022-06-03 18:01:07 +02:00
|
|
|
|
2022-06-02 09:34:13 +02:00
|
|
|
import { ButtonModule } from "../button";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { InputModule } from "../input/input.module";
|
|
|
|
import { I18nMockService } from "../utils/i18n-mock.service";
|
2022-06-02 09:34:13 +02:00
|
|
|
|
|
|
|
import { BitFormFieldComponent } from "./form-field.component";
|
|
|
|
import { FormFieldModule } from "./form-field.module";
|
|
|
|
|
|
|
|
export default {
|
2022-06-17 16:23:04 +02:00
|
|
|
title: "Component Library/Form/Error Summary",
|
2022-06-02 09:34:13 +02:00
|
|
|
component: BitFormFieldComponent,
|
|
|
|
decorators: [
|
|
|
|
moduleMetadata({
|
|
|
|
imports: [FormsModule, ReactiveFormsModule, FormFieldModule, InputModule, ButtonModule],
|
|
|
|
providers: [
|
|
|
|
{
|
|
|
|
provide: I18nService,
|
|
|
|
useFactory: () => {
|
|
|
|
return new I18nMockService({
|
|
|
|
required: "required",
|
|
|
|
inputRequired: "Input is required.",
|
|
|
|
inputEmail: "Input is not an email-address.",
|
|
|
|
fieldsNeedAttention: "$COUNT$ field(s) above need your attention.",
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
parameters: {
|
|
|
|
design: {
|
|
|
|
type: "figma",
|
2022-10-24 19:20:38 +02:00
|
|
|
url: "https://www.figma.com/file/Zt3YSeb6E6lebAffrNLa0h/Tailwind-Component-Library?node-id=1881%3A17689",
|
2022-06-02 09:34:13 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
} as Meta;
|
|
|
|
|
2022-07-26 14:48:11 +02:00
|
|
|
const fb = new UntypedFormBuilder();
|
2022-06-02 09:34:13 +02:00
|
|
|
|
|
|
|
const formObj = fb.group({
|
|
|
|
name: ["", [Validators.required]],
|
|
|
|
email: ["", [Validators.required, Validators.email]],
|
|
|
|
});
|
|
|
|
|
|
|
|
function submit() {
|
|
|
|
formObj.markAllAsTouched();
|
|
|
|
}
|
|
|
|
|
|
|
|
const Template: Story<BitFormFieldComponent> = (args: BitFormFieldComponent) => ({
|
|
|
|
props: {
|
|
|
|
formObj: formObj,
|
|
|
|
submit: submit,
|
|
|
|
...args,
|
|
|
|
},
|
|
|
|
template: `
|
|
|
|
<form [formGroup]="formObj" (ngSubmit)="submit()">
|
|
|
|
<bit-form-field>
|
|
|
|
<bit-label>Name</bit-label>
|
|
|
|
<input bitInput formControlName="name" />
|
|
|
|
</bit-form-field>
|
|
|
|
|
|
|
|
<bit-form-field>
|
|
|
|
<bit-label>Email</bit-label>
|
|
|
|
<input bitInput formControlName="email" />
|
|
|
|
</bit-form-field>
|
|
|
|
|
2022-06-02 11:16:59 +02:00
|
|
|
<button type="submit" bitButton buttonType="primary">Submit</button>
|
2022-06-02 09:34:13 +02:00
|
|
|
<bit-error-summary [formGroup]="formObj"></bit-error-summary>
|
|
|
|
</form>
|
|
|
|
`,
|
|
|
|
});
|
|
|
|
|
|
|
|
export const Default = Template.bind({});
|
|
|
|
Default.props = {};
|