@slotted/angular 0.1.0-beta.33 → 0.1.0-beta.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -317,6 +317,173 @@ Excerpt — not a complete module
317
317
  </sl-drawer>
318
318
  ```
319
319
 
320
+ ### A drawer that is a form
321
+
322
+ A drawer that edits a record submits with Enter from any field and with the footer’s submit. A form written around the header, the body and the footer draws no box of its own, so the parts stay the panel’s rows and keep its inset.
323
+
324
+ Example
325
+
326
+ ```ts
327
+ import { Component, computed, signal } from '@angular/core';
328
+ import { SlButton } from '@slotted/angular/button';
329
+ import {
330
+ SlDrawer,
331
+ SlDrawerBody,
332
+ SlDrawerClose,
333
+ SlDrawerDescription,
334
+ SlDrawerFooter,
335
+ SlDrawerHeader,
336
+ SlDrawerTitle,
337
+ SlDrawerTrigger,
338
+ } from '@slotted/angular/drawer';
339
+ import { SlField, SlFieldError, SlFieldLabel } from '@slotted/angular/field';
340
+ import { SlInline } from '@slotted/angular/inline';
341
+ import { SlSelect, SlSelectItem } from '@slotted/angular/select';
342
+ import { SlStack } from '@slotted/angular/stack';
343
+ import { SlTextField, SlTextFieldInput } from '@slotted/angular/text-field';
344
+ import { SlText } from '@slotted/angular/typography';
345
+
346
+ const TERMS = [
347
+ { value: 'due', label: 'Due on receipt' },
348
+ { value: 'net-15', label: 'Net 15' },
349
+ { value: 'net-30', label: 'Net 30' },
350
+ { value: 'net-60', label: 'Net 60' },
351
+ ];
352
+
353
+ const CUSTOMER = { name: 'Contoso Foods', email: 'ap@contoso.com', terms: 'net-30' };
354
+
355
+ const termsLabel = (value: string) => TERMS.find((option) => option.value === value)?.label;
356
+
357
+ function nameError(value: string): string {
358
+ return value.trim() === '' ? 'Enter the name printed on invoices.' : '';
359
+ }
360
+
361
+ function emailError(value: string): string {
362
+ if (value.trim() === '') return 'Enter the address invoices are sent to.';
363
+ if (!/^\S+@\S+\.\S+$/.test(value)) return 'Enter an address like ap@contoso.com.';
364
+ return '';
365
+ }
366
+
367
+ @Component({
368
+ selector: 'app-drawer-form',
369
+ imports: [
370
+ SlButton,
371
+ SlDrawer,
372
+ SlDrawerBody,
373
+ SlDrawerClose,
374
+ SlDrawerDescription,
375
+ SlDrawerFooter,
376
+ SlDrawerHeader,
377
+ SlDrawerTitle,
378
+ SlDrawerTrigger,
379
+ SlField,
380
+ SlFieldError,
381
+ SlFieldLabel,
382
+ SlInline,
383
+ SlSelect,
384
+ SlSelectItem,
385
+ SlStack,
386
+ SlText,
387
+ SlTextField,
388
+ SlTextFieldInput,
389
+ ],
390
+ template: `
391
+ <div slInline align="center" [gap]="3">
392
+ <span slText role="status" size="sm" tone="muted">
393
+ {{ customer().name }}, {{ customer().email }}, {{ termsLabel(customer().terms) }}
394
+ </span>
395
+ <button slButton [slDrawerTrigger]="drawer">Edit customer</button>
396
+ <sl-drawer #drawer="slDrawer" [open]="open()" (openChange)="toggle($event)">
397
+ <header slDrawerHeader>
398
+ <h2 slDrawerTitle>Edit customer</h2>
399
+ <p slDrawerDescription>Account C-0042, customer since March 2021.</p>
400
+ <button slDrawerClose></button>
401
+ </header>
402
+ <div slDrawerBody>
403
+ <form id="edit-customer" novalidate (submit)="submit($event)">
404
+ <div slStack [gap]="4">
405
+ <div slField required [invalid]="errors()?.name ? true : undefined">
406
+ <label slFieldLabel>Company name</label>
407
+ <div slTextField>
408
+ <input
409
+ slTextFieldInput
410
+ autocomplete="organization"
411
+ [value]="name()"
412
+ (valueChange)="name.set($event.value)"
413
+ />
414
+ </div>
415
+ <span slFieldError live="polite" reserve>{{ errors()?.name }}</span>
416
+ </div>
417
+ <div slField required [invalid]="errors()?.email ? true : undefined">
418
+ <label slFieldLabel>Billing email</label>
419
+ <div slTextField>
420
+ <input
421
+ slTextFieldInput
422
+ type="email"
423
+ [value]="email()"
424
+ (valueChange)="email.set($event.value)"
425
+ />
426
+ </div>
427
+ <span slFieldError live="polite" reserve>{{ errors()?.email }}</span>
428
+ </div>
429
+ <div slField>
430
+ <label slFieldLabel>Payment terms</label>
431
+ <sl-select [items]="terms" [(value)]="term">
432
+ @for (option of terms; track option.value) {
433
+ <sl-select-item [value]="option.value">{{ option.label }}</sl-select-item>
434
+ }
435
+ </sl-select>
436
+ </div>
437
+ </div>
438
+ </form>
439
+ </div>
440
+ <footer slDrawerFooter>
441
+ <button slButton variant="ghost" tone="secondary" (click)="open.set(false)">
442
+ Cancel
443
+ </button>
444
+ <button slButton type="submit" form="edit-customer">Save customer</button>
445
+ </footer>
446
+ </sl-drawer>
447
+ </div>
448
+ `,
449
+ })
450
+ export class DrawerForm {
451
+ readonly terms = TERMS;
452
+ readonly termsLabel = termsLabel;
453
+ readonly open = signal(false);
454
+ readonly customer = signal(CUSTOMER);
455
+ readonly name = signal(CUSTOMER.name);
456
+ readonly email = signal(CUSTOMER.email);
457
+ readonly term = signal<string | null>(CUSTOMER.terms);
458
+ readonly submitted = signal(false);
459
+ readonly errors = computed(() =>
460
+ this.submitted() ? { name: nameError(this.name()), email: emailError(this.email()) } : null,
461
+ );
462
+
463
+ toggle(next: boolean): void {
464
+ if (next) {
465
+ this.name.set(this.customer().name);
466
+ this.email.set(this.customer().email);
467
+ this.term.set(this.customer().terms);
468
+ this.submitted.set(false);
469
+ }
470
+ this.open.set(next);
471
+ }
472
+
473
+ submit(event: Event): void {
474
+ event.preventDefault();
475
+ this.submitted.set(true);
476
+ if (nameError(this.name()) !== '' || emailError(this.email()) !== '') return;
477
+ this.customer.set({
478
+ name: this.name().trim(),
479
+ email: this.email().trim(),
480
+ terms: this.term() ?? this.customer().terms,
481
+ });
482
+ this.open.set(false);
483
+ }
484
+ }
485
+ ```
486
+
320
487
  ### Refusing a close, and refusing it once
321
488
 
322
489
  Five ways to close and one output. A guard on openChangeRequest covers Escape, an outside press, the close button, the trigger and the imperative call together; Angular Material’s disableClose refuses two of them.
@@ -1006,171 +1173,6 @@ export class DrawerFilters {
1006
1173
  }
1007
1174
  ```
1008
1175
 
1009
- ### form.ts
1010
-
1011
- Example
1012
-
1013
- ```ts
1014
- import { Component, computed, signal } from '@angular/core';
1015
- import { SlButton } from '@slotted/angular/button';
1016
- import {
1017
- SlDrawer,
1018
- SlDrawerBody,
1019
- SlDrawerClose,
1020
- SlDrawerDescription,
1021
- SlDrawerFooter,
1022
- SlDrawerHeader,
1023
- SlDrawerTitle,
1024
- SlDrawerTrigger,
1025
- } from '@slotted/angular/drawer';
1026
- import { SlField, SlFieldError, SlFieldLabel } from '@slotted/angular/field';
1027
- import { SlInline } from '@slotted/angular/inline';
1028
- import { SlSelect, SlSelectItem } from '@slotted/angular/select';
1029
- import { SlStack } from '@slotted/angular/stack';
1030
- import { SlTextField, SlTextFieldInput } from '@slotted/angular/text-field';
1031
- import { SlText } from '@slotted/angular/typography';
1032
-
1033
- const TERMS = [
1034
- { value: 'due', label: 'Due on receipt' },
1035
- { value: 'net-15', label: 'Net 15' },
1036
- { value: 'net-30', label: 'Net 30' },
1037
- { value: 'net-60', label: 'Net 60' },
1038
- ];
1039
-
1040
- const CUSTOMER = { name: 'Contoso Foods', email: 'ap@contoso.com', terms: 'net-30' };
1041
-
1042
- const termsLabel = (value: string) => TERMS.find((option) => option.value === value)?.label;
1043
-
1044
- function nameError(value: string): string {
1045
- return value.trim() === '' ? 'Enter the name printed on invoices.' : '';
1046
- }
1047
-
1048
- function emailError(value: string): string {
1049
- if (value.trim() === '') return 'Enter the address invoices are sent to.';
1050
- if (!/^\S+@\S+\.\S+$/.test(value)) return 'Enter an address like ap@contoso.com.';
1051
- return '';
1052
- }
1053
-
1054
- @Component({
1055
- selector: 'app-drawer-form',
1056
- imports: [
1057
- SlButton,
1058
- SlDrawer,
1059
- SlDrawerBody,
1060
- SlDrawerClose,
1061
- SlDrawerDescription,
1062
- SlDrawerFooter,
1063
- SlDrawerHeader,
1064
- SlDrawerTitle,
1065
- SlDrawerTrigger,
1066
- SlField,
1067
- SlFieldError,
1068
- SlFieldLabel,
1069
- SlInline,
1070
- SlSelect,
1071
- SlSelectItem,
1072
- SlStack,
1073
- SlText,
1074
- SlTextField,
1075
- SlTextFieldInput,
1076
- ],
1077
- template: `
1078
- <div slInline align="center" [gap]="3">
1079
- <span slText role="status" size="sm" tone="muted">
1080
- {{ customer().name }}, {{ customer().email }}, {{ termsLabel(customer().terms) }}
1081
- </span>
1082
- <button slButton [slDrawerTrigger]="drawer">Edit customer</button>
1083
- <sl-drawer #drawer="slDrawer" [open]="open()" (openChange)="toggle($event)">
1084
- <header slDrawerHeader>
1085
- <h2 slDrawerTitle>Edit customer</h2>
1086
- <p slDrawerDescription>Account C-0042, customer since March 2021.</p>
1087
- <button slDrawerClose></button>
1088
- </header>
1089
- <div slDrawerBody>
1090
- <form id="edit-customer" novalidate (submit)="submit($event)">
1091
- <div slStack [gap]="4">
1092
- <div slField required [invalid]="errors()?.name ? true : undefined">
1093
- <label slFieldLabel>Company name</label>
1094
- <div slTextField>
1095
- <input
1096
- slTextFieldInput
1097
- autocomplete="organization"
1098
- [value]="name()"
1099
- (valueChange)="name.set($event.value)"
1100
- />
1101
- </div>
1102
- <span slFieldError live="polite" reserve>{{ errors()?.name }}</span>
1103
- </div>
1104
- <div slField required [invalid]="errors()?.email ? true : undefined">
1105
- <label slFieldLabel>Billing email</label>
1106
- <div slTextField>
1107
- <input
1108
- slTextFieldInput
1109
- type="email"
1110
- [value]="email()"
1111
- (valueChange)="email.set($event.value)"
1112
- />
1113
- </div>
1114
- <span slFieldError live="polite" reserve>{{ errors()?.email }}</span>
1115
- </div>
1116
- <div slField>
1117
- <label slFieldLabel>Payment terms</label>
1118
- <sl-select [items]="terms" [(value)]="term">
1119
- @for (option of terms; track option.value) {
1120
- <sl-select-item [value]="option.value">{{ option.label }}</sl-select-item>
1121
- }
1122
- </sl-select>
1123
- </div>
1124
- </div>
1125
- </form>
1126
- </div>
1127
- <footer slDrawerFooter>
1128
- <button slButton variant="ghost" tone="secondary" (click)="open.set(false)">
1129
- Cancel
1130
- </button>
1131
- <button slButton type="submit" form="edit-customer">Save customer</button>
1132
- </footer>
1133
- </sl-drawer>
1134
- </div>
1135
- `,
1136
- })
1137
- export class DrawerForm {
1138
- readonly terms = TERMS;
1139
- readonly termsLabel = termsLabel;
1140
- readonly open = signal(false);
1141
- readonly customer = signal(CUSTOMER);
1142
- readonly name = signal(CUSTOMER.name);
1143
- readonly email = signal(CUSTOMER.email);
1144
- readonly term = signal<string | null>(CUSTOMER.terms);
1145
- readonly submitted = signal(false);
1146
- readonly errors = computed(() =>
1147
- this.submitted() ? { name: nameError(this.name()), email: emailError(this.email()) } : null,
1148
- );
1149
-
1150
- toggle(next: boolean): void {
1151
- if (next) {
1152
- this.name.set(this.customer().name);
1153
- this.email.set(this.customer().email);
1154
- this.term.set(this.customer().terms);
1155
- this.submitted.set(false);
1156
- }
1157
- this.open.set(next);
1158
- }
1159
-
1160
- submit(event: Event): void {
1161
- event.preventDefault();
1162
- this.submitted.set(true);
1163
- if (nameError(this.name()) !== '' || emailError(this.email()) !== '') return;
1164
- this.customer.set({
1165
- name: this.name().trim(),
1166
- email: this.email().trim(),
1167
- terms: this.term() ?? this.customer().terms,
1168
- });
1169
- this.open.set(false);
1170
- }
1171
- }
1172
- ```
1173
-
1174
1176
  ### inline.ts
1175
1177
 
1176
1178
  Example
package/docs/drawer.json CHANGED
@@ -616,6 +616,14 @@
616
616
  "source": "<sl-drawer [modal]=\"false\" [(open)]=\"open\">\n <div slDrawerBody>…</div>\n</sl-drawer>\n",
617
617
  "verdict": "excerpt"
618
618
  },
619
+ {
620
+ "id": "form",
621
+ "title": "A drawer that is a form",
622
+ "note": "A drawer that edits a record submits with Enter from any field and with the footer’s submit. A form written around the header, the body and the footer draws no box of its own, so the parts stay the panel’s rows and keep its inset.",
623
+ "language": "ts",
624
+ "source": "import { Component, computed, signal } from '@angular/core';\nimport { SlButton } from '@slotted/angular/button';\nimport {\n SlDrawer,\n SlDrawerBody,\n SlDrawerClose,\n SlDrawerDescription,\n SlDrawerFooter,\n SlDrawerHeader,\n SlDrawerTitle,\n SlDrawerTrigger,\n} from '@slotted/angular/drawer';\nimport { SlField, SlFieldError, SlFieldLabel } from '@slotted/angular/field';\nimport { SlInline } from '@slotted/angular/inline';\nimport { SlSelect, SlSelectItem } from '@slotted/angular/select';\nimport { SlStack } from '@slotted/angular/stack';\nimport { SlTextField, SlTextFieldInput } from '@slotted/angular/text-field';\nimport { SlText } from '@slotted/angular/typography';\n\nconst TERMS = [\n { value: 'due', label: 'Due on receipt' },\n { value: 'net-15', label: 'Net 15' },\n { value: 'net-30', label: 'Net 30' },\n { value: 'net-60', label: 'Net 60' },\n];\n\nconst CUSTOMER = { name: 'Contoso Foods', email: 'ap@contoso.com', terms: 'net-30' };\n\nconst termsLabel = (value: string) => TERMS.find((option) => option.value === value)?.label;\n\nfunction nameError(value: string): string {\n return value.trim() === '' ? 'Enter the name printed on invoices.' : '';\n}\n\nfunction emailError(value: string): string {\n if (value.trim() === '') return 'Enter the address invoices are sent to.';\n if (!/^\\S+@\\S+\\.\\S+$/.test(value)) return 'Enter an address like ap@contoso.com.';\n return '';\n}\n\n@Component({\n selector: 'app-drawer-form',\n imports: [\n SlButton,\n SlDrawer,\n SlDrawerBody,\n SlDrawerClose,\n SlDrawerDescription,\n SlDrawerFooter,\n SlDrawerHeader,\n SlDrawerTitle,\n SlDrawerTrigger,\n SlField,\n SlFieldError,\n SlFieldLabel,\n SlInline,\n SlSelect,\n SlSelectItem,\n SlStack,\n SlText,\n SlTextField,\n SlTextFieldInput,\n ],\n template: `\n <div slInline align=\"center\" [gap]=\"3\">\n <span slText role=\"status\" size=\"sm\" tone=\"muted\">\n {{ customer().name }}, {{ customer().email }}, {{ termsLabel(customer().terms) }}\n </span>\n <button slButton [slDrawerTrigger]=\"drawer\">Edit customer</button>\n <sl-drawer #drawer=\"slDrawer\" [open]=\"open()\" (openChange)=\"toggle($event)\">\n <header slDrawerHeader>\n <h2 slDrawerTitle>Edit customer</h2>\n <p slDrawerDescription>Account C-0042, customer since March 2021.</p>\n <button slDrawerClose></button>\n </header>\n <div slDrawerBody>\n <form id=\"edit-customer\" novalidate (submit)=\"submit($event)\">\n <div slStack [gap]=\"4\">\n <div slField required [invalid]=\"errors()?.name ? true : undefined\">\n <label slFieldLabel>Company name</label>\n <div slTextField>\n <input\n slTextFieldInput\n autocomplete=\"organization\"\n [value]=\"name()\"\n (valueChange)=\"name.set($event.value)\"\n />\n </div>\n <span slFieldError live=\"polite\" reserve>{{ errors()?.name }}</span>\n </div>\n <div slField required [invalid]=\"errors()?.email ? true : undefined\">\n <label slFieldLabel>Billing email</label>\n <div slTextField>\n <input\n slTextFieldInput\n type=\"email\"\n [value]=\"email()\"\n (valueChange)=\"email.set($event.value)\"\n />\n </div>\n <span slFieldError live=\"polite\" reserve>{{ errors()?.email }}</span>\n </div>\n <div slField>\n <label slFieldLabel>Payment terms</label>\n <sl-select [items]=\"terms\" [(value)]=\"term\">\n @for (option of terms; track option.value) {\n <sl-select-item [value]=\"option.value\">{{ option.label }}</sl-select-item>\n }\n </sl-select>\n </div>\n </div>\n </form>\n </div>\n <footer slDrawerFooter>\n <button slButton variant=\"ghost\" tone=\"secondary\" (click)=\"open.set(false)\">\n Cancel\n </button>\n <button slButton type=\"submit\" form=\"edit-customer\">Save customer</button>\n </footer>\n </sl-drawer>\n </div>\n `,\n})\nexport class DrawerForm {\n readonly terms = TERMS;\n readonly termsLabel = termsLabel;\n readonly open = signal(false);\n readonly customer = signal(CUSTOMER);\n readonly name = signal(CUSTOMER.name);\n readonly email = signal(CUSTOMER.email);\n readonly term = signal<string | null>(CUSTOMER.terms);\n readonly submitted = signal(false);\n readonly errors = computed(() =>\n this.submitted() ? { name: nameError(this.name()), email: emailError(this.email()) } : null,\n );\n\n toggle(next: boolean): void {\n if (next) {\n this.name.set(this.customer().name);\n this.email.set(this.customer().email);\n this.term.set(this.customer().terms);\n this.submitted.set(false);\n }\n this.open.set(next);\n }\n\n submit(event: Event): void {\n event.preventDefault();\n this.submitted.set(true);\n if (nameError(this.name()) !== '' || emailError(this.email()) !== '') return;\n this.customer.set({\n name: this.name().trim(),\n email: this.email().trim(),\n terms: this.term() ?? this.customer().terms,\n });\n this.open.set(false);\n }\n}\n",
625
+ "verdict": "example"
626
+ },
619
627
  {
620
628
  "id": "policy",
621
629
  "title": "Refusing a close, and refusing it once",
@@ -704,14 +712,6 @@
704
712
  "source": "import { Component, computed, signal } from '@angular/core';\nimport { SlButton } from '@slotted/angular/button';\nimport { SlCheckbox } from '@slotted/angular/checkbox';\nimport { SlCheckboxGroup } from '@slotted/angular/checkbox-group';\nimport {\n SlDrawer,\n SlDrawerBody,\n SlDrawerClose,\n SlDrawerFooter,\n SlDrawerHeader,\n SlDrawerTitle,\n SlDrawerTrigger,\n} from '@slotted/angular/drawer';\nimport { SlFieldGroup, SlFieldGroupLegend } from '@slotted/angular/field-group';\nimport { SlInline } from '@slotted/angular/inline';\nimport { SlRadio, SlRadioGroup } from '@slotted/angular/radio-group';\nimport { SlStack } from '@slotted/angular/stack';\nimport { SlText } from '@slotted/angular/typography';\n\nconst ORDERS = [\n { id: 'SO-1182', status: 'processing', warehouse: 'RNO' },\n { id: 'SO-1183', status: 'shipped', warehouse: 'CMH' },\n { id: 'SO-1184', status: 'on-hold', warehouse: 'RNO' },\n { id: 'SO-1185', status: 'processing', warehouse: 'SAV' },\n { id: 'SO-1186', status: 'shipped', warehouse: 'RNO' },\n { id: 'SO-1187', status: 'processing', warehouse: 'CMH' },\n { id: 'SO-1188', status: 'on-hold', warehouse: 'SAV' },\n { id: 'SO-1189', status: 'processing', warehouse: 'RNO' },\n];\n\ninterface Filters {\n statuses: readonly string[];\n warehouse: string;\n}\n\nconst ALL: Filters = { statuses: ['processing', 'shipped', 'on-hold'], warehouse: 'any' };\n\nconst matching = (filters: Filters) =>\n ORDERS.filter(\n (order) =>\n filters.statuses.includes(order.status) &&\n (filters.warehouse === 'any' || order.warehouse === filters.warehouse),\n ).length;\n\n@Component({\n selector: 'app-drawer-filters',\n imports: [\n SlButton,\n SlCheckbox,\n SlCheckboxGroup,\n SlDrawer,\n SlDrawerBody,\n SlDrawerClose,\n SlDrawerFooter,\n SlDrawerHeader,\n SlDrawerTitle,\n SlDrawerTrigger,\n SlFieldGroup,\n SlFieldGroupLegend,\n SlInline,\n SlRadio,\n SlRadioGroup,\n SlStack,\n SlText,\n ],\n template: `\n <div slInline align=\"center\" [gap]=\"3\">\n <span slText size=\"sm\">{{ shown() }} of {{ total }} orders</span>\n <button slButton size=\"sm\" tone=\"secondary\" variant=\"outline\" [slDrawerTrigger]=\"drawer\">\n Filters\n </button>\n <sl-drawer #drawer=\"slDrawer\" size=\"sm\" [open]=\"open()\" (openChange)=\"toggle($event)\">\n <header slDrawerHeader>\n <h2 slDrawerTitle>Filter orders</h2>\n <button slDrawerClose></button>\n </header>\n <div slDrawerBody>\n <div slStack [gap]=\"6\">\n <fieldset slFieldGroup>\n <legend slFieldGroupLegend>Status</legend>\n <div\n slCheckboxGroup\n [value]=\"draft().statuses\"\n (valueChange)=\"draft.set({ statuses: $event.value, warehouse: draft().warehouse })\"\n >\n <div slCheckbox value=\"processing\">Processing</div>\n <div slCheckbox value=\"shipped\">Shipped</div>\n <div slCheckbox value=\"on-hold\">On hold</div>\n </div>\n </fieldset>\n <fieldset slFieldGroup>\n <legend slFieldGroupLegend>Warehouse</legend>\n <div\n slRadioGroup\n [value]=\"draft().warehouse\"\n (valueChange)=\"\n draft.set({ statuses: draft().statuses, warehouse: $event.value ?? 'any' })\n \"\n >\n <div slRadio value=\"any\">Any warehouse</div>\n <div slRadio value=\"RNO\">Reno, NV</div>\n <div slRadio value=\"CMH\">Columbus, OH</div>\n <div slRadio value=\"SAV\">Savannah, GA</div>\n </div>\n </fieldset>\n </div>\n </div>\n <footer slDrawerFooter>\n <button slButton variant=\"ghost\" tone=\"secondary\" (click)=\"draft.set(all)\">Reset</button>\n <button slButton (click)=\"apply()\">Show {{ count() }} orders</button>\n </footer>\n </sl-drawer>\n </div>\n `,\n})\nexport class DrawerFilters {\n readonly all = ALL;\n readonly total = ORDERS.length;\n readonly open = signal(false);\n readonly applied = signal<Filters>(ALL);\n readonly draft = signal<Filters>(ALL);\n readonly shown = computed(() => matching(this.applied()));\n readonly count = computed(() => matching(this.draft()));\n\n toggle(next: boolean): void {\n if (next) this.draft.set(this.applied());\n this.open.set(next);\n }\n\n apply(): void {\n this.applied.set(this.draft());\n this.open.set(false);\n }\n}\n",
705
713
  "verdict": "example"
706
714
  },
707
- {
708
- "id": "form",
709
- "title": "form.ts",
710
- "note": null,
711
- "language": "ts",
712
- "source": "import { Component, computed, signal } from '@angular/core';\nimport { SlButton } from '@slotted/angular/button';\nimport {\n SlDrawer,\n SlDrawerBody,\n SlDrawerClose,\n SlDrawerDescription,\n SlDrawerFooter,\n SlDrawerHeader,\n SlDrawerTitle,\n SlDrawerTrigger,\n} from '@slotted/angular/drawer';\nimport { SlField, SlFieldError, SlFieldLabel } from '@slotted/angular/field';\nimport { SlInline } from '@slotted/angular/inline';\nimport { SlSelect, SlSelectItem } from '@slotted/angular/select';\nimport { SlStack } from '@slotted/angular/stack';\nimport { SlTextField, SlTextFieldInput } from '@slotted/angular/text-field';\nimport { SlText } from '@slotted/angular/typography';\n\nconst TERMS = [\n { value: 'due', label: 'Due on receipt' },\n { value: 'net-15', label: 'Net 15' },\n { value: 'net-30', label: 'Net 30' },\n { value: 'net-60', label: 'Net 60' },\n];\n\nconst CUSTOMER = { name: 'Contoso Foods', email: 'ap@contoso.com', terms: 'net-30' };\n\nconst termsLabel = (value: string) => TERMS.find((option) => option.value === value)?.label;\n\nfunction nameError(value: string): string {\n return value.trim() === '' ? 'Enter the name printed on invoices.' : '';\n}\n\nfunction emailError(value: string): string {\n if (value.trim() === '') return 'Enter the address invoices are sent to.';\n if (!/^\\S+@\\S+\\.\\S+$/.test(value)) return 'Enter an address like ap@contoso.com.';\n return '';\n}\n\n@Component({\n selector: 'app-drawer-form',\n imports: [\n SlButton,\n SlDrawer,\n SlDrawerBody,\n SlDrawerClose,\n SlDrawerDescription,\n SlDrawerFooter,\n SlDrawerHeader,\n SlDrawerTitle,\n SlDrawerTrigger,\n SlField,\n SlFieldError,\n SlFieldLabel,\n SlInline,\n SlSelect,\n SlSelectItem,\n SlStack,\n SlText,\n SlTextField,\n SlTextFieldInput,\n ],\n template: `\n <div slInline align=\"center\" [gap]=\"3\">\n <span slText role=\"status\" size=\"sm\" tone=\"muted\">\n {{ customer().name }}, {{ customer().email }}, {{ termsLabel(customer().terms) }}\n </span>\n <button slButton [slDrawerTrigger]=\"drawer\">Edit customer</button>\n <sl-drawer #drawer=\"slDrawer\" [open]=\"open()\" (openChange)=\"toggle($event)\">\n <header slDrawerHeader>\n <h2 slDrawerTitle>Edit customer</h2>\n <p slDrawerDescription>Account C-0042, customer since March 2021.</p>\n <button slDrawerClose></button>\n </header>\n <div slDrawerBody>\n <form id=\"edit-customer\" novalidate (submit)=\"submit($event)\">\n <div slStack [gap]=\"4\">\n <div slField required [invalid]=\"errors()?.name ? true : undefined\">\n <label slFieldLabel>Company name</label>\n <div slTextField>\n <input\n slTextFieldInput\n autocomplete=\"organization\"\n [value]=\"name()\"\n (valueChange)=\"name.set($event.value)\"\n />\n </div>\n <span slFieldError live=\"polite\" reserve>{{ errors()?.name }}</span>\n </div>\n <div slField required [invalid]=\"errors()?.email ? true : undefined\">\n <label slFieldLabel>Billing email</label>\n <div slTextField>\n <input\n slTextFieldInput\n type=\"email\"\n [value]=\"email()\"\n (valueChange)=\"email.set($event.value)\"\n />\n </div>\n <span slFieldError live=\"polite\" reserve>{{ errors()?.email }}</span>\n </div>\n <div slField>\n <label slFieldLabel>Payment terms</label>\n <sl-select [items]=\"terms\" [(value)]=\"term\">\n @for (option of terms; track option.value) {\n <sl-select-item [value]=\"option.value\">{{ option.label }}</sl-select-item>\n }\n </sl-select>\n </div>\n </div>\n </form>\n </div>\n <footer slDrawerFooter>\n <button slButton variant=\"ghost\" tone=\"secondary\" (click)=\"open.set(false)\">\n Cancel\n </button>\n <button slButton type=\"submit\" form=\"edit-customer\">Save customer</button>\n </footer>\n </sl-drawer>\n </div>\n `,\n})\nexport class DrawerForm {\n readonly terms = TERMS;\n readonly termsLabel = termsLabel;\n readonly open = signal(false);\n readonly customer = signal(CUSTOMER);\n readonly name = signal(CUSTOMER.name);\n readonly email = signal(CUSTOMER.email);\n readonly term = signal<string | null>(CUSTOMER.terms);\n readonly submitted = signal(false);\n readonly errors = computed(() =>\n this.submitted() ? { name: nameError(this.name()), email: emailError(this.email()) } : null,\n );\n\n toggle(next: boolean): void {\n if (next) {\n this.name.set(this.customer().name);\n this.email.set(this.customer().email);\n this.term.set(this.customer().terms);\n this.submitted.set(false);\n }\n this.open.set(next);\n }\n\n submit(event: Event): void {\n event.preventDefault();\n this.submitted.set(true);\n if (nameError(this.name()) !== '' || emailError(this.email()) !== '') return;\n this.customer.set({\n name: this.name().trim(),\n email: this.email().trim(),\n terms: this.term() ?? this.customer().terms,\n });\n this.open.set(false);\n }\n}\n",
713
- "verdict": "example"
714
- },
715
715
  {
716
716
  "id": "inline",
717
717
  "title": "inline.ts",
package/docs/form.json CHANGED
@@ -309,7 +309,7 @@
309
309
  {
310
310
  "id": "playground",
311
311
  "title": "Playground",
312
- "note": "A form of two fields with the family’s whole lifecycle on it. Submit it empty: the platform’s own messages appear in the summary, focus moves there, and each link jumps to the field it names. Two fields written one after the other inside the form stand apart by --slotted-form-field-gap (space-6 by default), and two field groups by --slotted-form-section-gap (space-9 by default); a layout the page draws itself — a Grid, a Stack — keeps its own gap.",
312
+ "note": "A form of two fields with the family’s whole lifecycle on it. Submit it empty: the platform’s own messages appear in the summary, focus moves there, and each link jumps to the field it names. Two fields written one after the other inside the form stand apart by --slotted-form-field-gap (space-6 by default), and two field groups by --slotted-form-section-gap (space-9 by default); any other child, such as a row of two fields the page draws itself, stands apart and keeps to --slotted-form-measure the same way, and the gap inside a Grid or a Stack stays its own.",
313
313
  "language": "html",
314
314
  "source": "<form slForm (formSubmit)=\"save($event.values)\">\n <div slField>\n <label slFieldLabel>Nome completo</label>\n <div slTextField><input slTextFieldInput name=\"nome\" required /></div>\n </div>\n <div slFormActions>\n <button slButton type=\"submit\">Save</button>\n </div>\n</form>\n",
315
315
  "verdict": "excerpt"