@atomic-ui/ui-angular 0.0.0-stage → 0.3.0
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.
- package/README.md +49 -2
- package/dist/index.d.ts +121 -0
- package/dist/index.js +227 -0
- package/dist/index.js.map +1 -0
- package/package.json +44 -3
package/README.md
CHANGED
|
@@ -1,3 +1,50 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @atomic-ui/ui-angular
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Angular value accessors for the `@atomic-ui/ui` form elements, so they work with reactive forms and `ngModel`.
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
pnpm add @atomic-ui/ui @atomic-ui/ui-angular
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Angular renders custom elements as they are, so there is no wrapper per element. A component that uses them does two things. It declares `CUSTOM_ELEMENTS_SCHEMA`, which tells Angular that tags it does not know are custom elements. And it imports `ImpktFormsModule`, which gives the form elements a value accessor each:
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
|
|
13
|
+
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
|
|
14
|
+
import { ImpktFormsModule } from '@atomic-ui/ui-angular';
|
|
15
|
+
|
|
16
|
+
@Component({
|
|
17
|
+
selector: 'app-vehicle',
|
|
18
|
+
standalone: true,
|
|
19
|
+
imports: [ReactiveFormsModule, ImpktFormsModule],
|
|
20
|
+
schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
21
|
+
template: `
|
|
22
|
+
<form [formGroup]="form">
|
|
23
|
+
<impkt-text-input label="Full name" formControlName="name"></impkt-text-input>
|
|
24
|
+
<impkt-date-input label="Arrival date" formControlName="arrival"></impkt-date-input>
|
|
25
|
+
<impkt-money-input label="Value of the vehicle" formControlName="value"></impkt-money-input>
|
|
26
|
+
<impkt-file-upload label="Proof of ownership" formControlName="proof" many-files></impkt-file-upload>
|
|
27
|
+
</form>
|
|
28
|
+
<impkt-table caption="Open cases" [columns]="columns" [rows]="rows" stack (impkt-sort)="sortBy($event.detail)"></impkt-table>
|
|
29
|
+
`,
|
|
30
|
+
})
|
|
31
|
+
export class VehicleComponent {
|
|
32
|
+
form = new FormGroup({ name: new FormControl(''), arrival: new FormControl(''), value: new FormControl(''), proof: new FormControl<File[]>([]) });
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Importing this package defines the elements, so nothing else needs importing first.
|
|
37
|
+
|
|
38
|
+
`CUSTOM_ELEMENTS_SCHEMA` stays the app's to declare. It stops Angular checking unknown tags for the whole component, which loosens its template checking, and a library should not switch that off on an app's behalf. Declare it only on the components that use the elements.
|
|
39
|
+
|
|
40
|
+
## The accessors
|
|
41
|
+
|
|
42
|
+
Every form element has one: `impkt-text-input`, `impkt-textarea`, `impkt-select`, `impkt-checkbox`, `impkt-radio-group`, `impkt-checkbox-group`, `impkt-date-input`, `impkt-money-input`, `impkt-range-input`, `impkt-file-upload`, `impkt-address-lookup` and `impkt-slot-picker`. Each listens for the element's `impkt-change` and writes the form's value back to the element's `value`. Leaving the field marks the control touched.
|
|
43
|
+
|
|
44
|
+
Three differ. A checkbox's value is a boolean. A money input's value is the plain number as text, such as `250000`. A file upload's value is the files, as `File[]`, and writing an empty value clears it; a browser does not let code choose files.
|
|
45
|
+
|
|
46
|
+
A test checks that every form element in the component manifest has an accessor.
|
|
47
|
+
|
|
48
|
+
## Events and properties
|
|
49
|
+
|
|
50
|
+
Bind arrays and objects with `[property]`, which sets a DOM property, and listen with `(impkt-sort)`, which receives the event with its `detail`.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Angular bindings for `@atomic-ui/ui`.
|
|
3
|
+
*
|
|
4
|
+
* ## What Angular actually needs
|
|
5
|
+
*
|
|
6
|
+
* Not wrappers. Angular renders custom elements as-is once a component
|
|
7
|
+
* declares `CUSTOM_ELEMENTS_SCHEMA`, and `[options]="…"` already sets a DOM
|
|
8
|
+
* property rather than an attribute, so arrays arrive intact. Writing a
|
|
9
|
+
* component per element would add a layer that does nothing.
|
|
10
|
+
*
|
|
11
|
+
* What does not work without help is **forms**. `formControlName` and
|
|
12
|
+
* `ngModel` need a `ControlValueAccessor`, and Angular ships one for `<input>`
|
|
13
|
+
* and `<select>` and nothing else. Without one, a reactive form containing
|
|
14
|
+
* `<impkt-text-input>` silently never receives a value — the control stays
|
|
15
|
+
* `null`, validation passes, and the bug surfaces as an empty field in an order
|
|
16
|
+
* request.
|
|
17
|
+
*
|
|
18
|
+
* So this package is value accessors, and that is the whole of it.
|
|
19
|
+
*
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { ImpktFormsModule } from '@atomic-ui/ui-angular';
|
|
22
|
+
*
|
|
23
|
+
* @Component({
|
|
24
|
+
* standalone: true,
|
|
25
|
+
* imports: [ReactiveFormsModule, ImpktFormsModule],
|
|
26
|
+
* schemas: [CUSTOM_ELEMENTS_SCHEMA],
|
|
27
|
+
* template: `<impkt-text-input label="Postcode" formControlName="postcode"></impkt-text-input>`,
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* `CUSTOM_ELEMENTS_SCHEMA` stays the consumer's to declare. It tells Angular
|
|
32
|
+
* to stop checking unknown tags for a whole component, which is a real
|
|
33
|
+
* loosening of its template checking, and a library should not switch that off
|
|
34
|
+
* on an application's behalf.
|
|
35
|
+
*/
|
|
36
|
+
import { ElementRef } from '@angular/core';
|
|
37
|
+
import { type ControlValueAccessor } from '@angular/forms';
|
|
38
|
+
import '@atomic-ui/ui';
|
|
39
|
+
interface ValueElement extends HTMLElement {
|
|
40
|
+
value: string;
|
|
41
|
+
disabled: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* The shared accessor.
|
|
45
|
+
*
|
|
46
|
+
* It listens for `impkt-change` — the one event every control in the library
|
|
47
|
+
* dispatches — and writes back to the element's `value` property. One
|
|
48
|
+
* implementation covers every control because they all agree on that contract,
|
|
49
|
+
* which is the payoff for having settled it in the component base rather than
|
|
50
|
+
* per component.
|
|
51
|
+
*/
|
|
52
|
+
declare abstract class ImpktValueAccessor implements ControlValueAccessor {
|
|
53
|
+
protected readonly ref: ElementRef<ValueElement>;
|
|
54
|
+
protected onChange: (value: string) => void;
|
|
55
|
+
protected onTouched: () => void;
|
|
56
|
+
constructor(ref: ElementRef<ValueElement>);
|
|
57
|
+
handleChange(event: CustomEvent<{
|
|
58
|
+
value: string;
|
|
59
|
+
}>): void;
|
|
60
|
+
/**
|
|
61
|
+
* Blur marks the control touched, which is what makes "required" errors
|
|
62
|
+
* appear after someone leaves a field rather than while they are still
|
|
63
|
+
* typing in it. A form that reports an error on the first keystroke gets
|
|
64
|
+
* worked around.
|
|
65
|
+
*/
|
|
66
|
+
handleBlur(): void;
|
|
67
|
+
writeValue(value: string | null): void;
|
|
68
|
+
registerOnChange(fn: (value: string) => void): void;
|
|
69
|
+
registerOnTouched(fn: () => void): void;
|
|
70
|
+
setDisabledState(isDisabled: boolean): void;
|
|
71
|
+
}
|
|
72
|
+
export declare class ImpktTextInputAccessor extends ImpktValueAccessor {
|
|
73
|
+
}
|
|
74
|
+
export declare class ImpktTextareaAccessor extends ImpktValueAccessor {
|
|
75
|
+
}
|
|
76
|
+
export declare class ImpktSelectAccessor extends ImpktValueAccessor {
|
|
77
|
+
}
|
|
78
|
+
export declare class ImpktRadioGroupAccessor extends ImpktValueAccessor {
|
|
79
|
+
}
|
|
80
|
+
export declare class ImpktCheckboxGroupAccessor extends ImpktValueAccessor {
|
|
81
|
+
}
|
|
82
|
+
export declare class ImpktDateInputAccessor extends ImpktValueAccessor {
|
|
83
|
+
}
|
|
84
|
+
/** An amount, as the plain number typed, such as `250000`. */
|
|
85
|
+
export declare class ImpktMoneyInputAccessor extends ImpktValueAccessor {
|
|
86
|
+
}
|
|
87
|
+
export declare class ImpktRangeInputAccessor extends ImpktValueAccessor {
|
|
88
|
+
}
|
|
89
|
+
/** The address chosen or typed, on one line. */
|
|
90
|
+
export declare class ImpktAddressLookupAccessor extends ImpktValueAccessor {
|
|
91
|
+
}
|
|
92
|
+
export declare class ImpktSlotPickerAccessor extends ImpktValueAccessor {
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A file upload's form value is the files themselves, as `File[]`, because that
|
|
96
|
+
* is what a form uploads. The element's own `impkt-change` carries only their
|
|
97
|
+
* names, so this listens for `impkt-files` instead. A file input cannot be given
|
|
98
|
+
* files from code, so writing a value can only clear it, as a form reset does.
|
|
99
|
+
*/
|
|
100
|
+
export declare class ImpktFileUploadAccessor extends ImpktValueAccessor {
|
|
101
|
+
handleChange(): void;
|
|
102
|
+
handleFiles(event: CustomEvent<{
|
|
103
|
+
files: File[];
|
|
104
|
+
}>): void;
|
|
105
|
+
writeValue(value: unknown): void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* A checkbox is the one that differs: its form value is a boolean to Angular
|
|
109
|
+
* and a string to the element, so it translates rather than passing through.
|
|
110
|
+
*/
|
|
111
|
+
export declare class ImpktCheckboxAccessor extends ImpktValueAccessor {
|
|
112
|
+
handleChange(event: CustomEvent<{
|
|
113
|
+
value: string;
|
|
114
|
+
}>): void;
|
|
115
|
+
writeValue(value: unknown): void;
|
|
116
|
+
}
|
|
117
|
+
export declare const IMPKT_FORM_ACCESSORS: readonly [typeof ImpktTextInputAccessor, typeof ImpktTextareaAccessor, typeof ImpktSelectAccessor, typeof ImpktCheckboxAccessor, typeof ImpktRadioGroupAccessor, typeof ImpktCheckboxGroupAccessor, typeof ImpktDateInputAccessor, typeof ImpktMoneyInputAccessor, typeof ImpktRangeInputAccessor, typeof ImpktFileUploadAccessor, typeof ImpktAddressLookupAccessor, typeof ImpktSlotPickerAccessor];
|
|
118
|
+
/** Import this where you use the elements in a form. */
|
|
119
|
+
export declare class ImpktFormsModule {
|
|
120
|
+
}
|
|
121
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
// packages/ui-angular/src/index.ts
|
|
13
|
+
import { Directive, HostListener, NgModule, forwardRef } from "@angular/core";
|
|
14
|
+
import { NG_VALUE_ACCESSOR } from "@angular/forms";
|
|
15
|
+
import "@atomic-ui/ui";
|
|
16
|
+
var ImpktValueAccessor = class {
|
|
17
|
+
constructor(ref) {
|
|
18
|
+
this.ref = ref;
|
|
19
|
+
this.onChange = () => {
|
|
20
|
+
};
|
|
21
|
+
this.onTouched = () => {
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
handleChange(event) {
|
|
25
|
+
this.onChange(event.detail.value);
|
|
26
|
+
}
|
|
27
|
+
handleBlur() {
|
|
28
|
+
this.onTouched();
|
|
29
|
+
}
|
|
30
|
+
writeValue(value) {
|
|
31
|
+
this.ref.nativeElement.value = value ?? "";
|
|
32
|
+
}
|
|
33
|
+
registerOnChange(fn) {
|
|
34
|
+
this.onChange = fn;
|
|
35
|
+
}
|
|
36
|
+
registerOnTouched(fn) {
|
|
37
|
+
this.onTouched = fn;
|
|
38
|
+
}
|
|
39
|
+
setDisabledState(isDisabled) {
|
|
40
|
+
this.ref.nativeElement.disabled = isDisabled;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
__decorateClass([
|
|
44
|
+
HostListener("impkt-change", ["$event"])
|
|
45
|
+
], ImpktValueAccessor.prototype, "handleChange", 1);
|
|
46
|
+
__decorateClass([
|
|
47
|
+
HostListener("blur")
|
|
48
|
+
], ImpktValueAccessor.prototype, "handleBlur", 1);
|
|
49
|
+
ImpktValueAccessor = __decorateClass([
|
|
50
|
+
Directive()
|
|
51
|
+
], ImpktValueAccessor);
|
|
52
|
+
var accessor = (directive) => ({
|
|
53
|
+
provide: NG_VALUE_ACCESSOR,
|
|
54
|
+
useExisting: forwardRef(() => directive),
|
|
55
|
+
multi: true
|
|
56
|
+
});
|
|
57
|
+
var ImpktTextInputAccessor = class extends ImpktValueAccessor {
|
|
58
|
+
};
|
|
59
|
+
ImpktTextInputAccessor = __decorateClass([
|
|
60
|
+
Directive({
|
|
61
|
+
selector: "impkt-text-input",
|
|
62
|
+
standalone: true,
|
|
63
|
+
providers: [accessor(ImpktTextInputAccessor)]
|
|
64
|
+
})
|
|
65
|
+
], ImpktTextInputAccessor);
|
|
66
|
+
var ImpktTextareaAccessor = class extends ImpktValueAccessor {
|
|
67
|
+
};
|
|
68
|
+
ImpktTextareaAccessor = __decorateClass([
|
|
69
|
+
Directive({
|
|
70
|
+
selector: "impkt-textarea",
|
|
71
|
+
standalone: true,
|
|
72
|
+
providers: [accessor(ImpktTextareaAccessor)]
|
|
73
|
+
})
|
|
74
|
+
], ImpktTextareaAccessor);
|
|
75
|
+
var ImpktSelectAccessor = class extends ImpktValueAccessor {
|
|
76
|
+
};
|
|
77
|
+
ImpktSelectAccessor = __decorateClass([
|
|
78
|
+
Directive({
|
|
79
|
+
selector: "impkt-select",
|
|
80
|
+
standalone: true,
|
|
81
|
+
providers: [accessor(ImpktSelectAccessor)]
|
|
82
|
+
})
|
|
83
|
+
], ImpktSelectAccessor);
|
|
84
|
+
var ImpktRadioGroupAccessor = class extends ImpktValueAccessor {
|
|
85
|
+
};
|
|
86
|
+
ImpktRadioGroupAccessor = __decorateClass([
|
|
87
|
+
Directive({
|
|
88
|
+
selector: "impkt-radio-group",
|
|
89
|
+
standalone: true,
|
|
90
|
+
providers: [accessor(ImpktRadioGroupAccessor)]
|
|
91
|
+
})
|
|
92
|
+
], ImpktRadioGroupAccessor);
|
|
93
|
+
var ImpktCheckboxGroupAccessor = class extends ImpktValueAccessor {
|
|
94
|
+
};
|
|
95
|
+
ImpktCheckboxGroupAccessor = __decorateClass([
|
|
96
|
+
Directive({
|
|
97
|
+
selector: "impkt-checkbox-group",
|
|
98
|
+
standalone: true,
|
|
99
|
+
providers: [accessor(ImpktCheckboxGroupAccessor)]
|
|
100
|
+
})
|
|
101
|
+
], ImpktCheckboxGroupAccessor);
|
|
102
|
+
var ImpktDateInputAccessor = class extends ImpktValueAccessor {
|
|
103
|
+
};
|
|
104
|
+
ImpktDateInputAccessor = __decorateClass([
|
|
105
|
+
Directive({
|
|
106
|
+
selector: "impkt-date-input",
|
|
107
|
+
standalone: true,
|
|
108
|
+
providers: [accessor(ImpktDateInputAccessor)]
|
|
109
|
+
})
|
|
110
|
+
], ImpktDateInputAccessor);
|
|
111
|
+
var ImpktMoneyInputAccessor = class extends ImpktValueAccessor {
|
|
112
|
+
};
|
|
113
|
+
ImpktMoneyInputAccessor = __decorateClass([
|
|
114
|
+
Directive({
|
|
115
|
+
selector: "impkt-money-input",
|
|
116
|
+
standalone: true,
|
|
117
|
+
providers: [accessor(ImpktMoneyInputAccessor)]
|
|
118
|
+
})
|
|
119
|
+
], ImpktMoneyInputAccessor);
|
|
120
|
+
var ImpktRangeInputAccessor = class extends ImpktValueAccessor {
|
|
121
|
+
};
|
|
122
|
+
ImpktRangeInputAccessor = __decorateClass([
|
|
123
|
+
Directive({
|
|
124
|
+
selector: "impkt-range-input",
|
|
125
|
+
standalone: true,
|
|
126
|
+
providers: [accessor(ImpktRangeInputAccessor)]
|
|
127
|
+
})
|
|
128
|
+
], ImpktRangeInputAccessor);
|
|
129
|
+
var ImpktAddressLookupAccessor = class extends ImpktValueAccessor {
|
|
130
|
+
};
|
|
131
|
+
ImpktAddressLookupAccessor = __decorateClass([
|
|
132
|
+
Directive({
|
|
133
|
+
selector: "impkt-address-lookup",
|
|
134
|
+
standalone: true,
|
|
135
|
+
providers: [accessor(ImpktAddressLookupAccessor)]
|
|
136
|
+
})
|
|
137
|
+
], ImpktAddressLookupAccessor);
|
|
138
|
+
var ImpktSlotPickerAccessor = class extends ImpktValueAccessor {
|
|
139
|
+
};
|
|
140
|
+
ImpktSlotPickerAccessor = __decorateClass([
|
|
141
|
+
Directive({
|
|
142
|
+
selector: "impkt-slot-picker",
|
|
143
|
+
standalone: true,
|
|
144
|
+
providers: [accessor(ImpktSlotPickerAccessor)]
|
|
145
|
+
})
|
|
146
|
+
], ImpktSlotPickerAccessor);
|
|
147
|
+
var ImpktFileUploadAccessor = class extends ImpktValueAccessor {
|
|
148
|
+
handleChange() {
|
|
149
|
+
}
|
|
150
|
+
handleFiles(event) {
|
|
151
|
+
this.onChange(event.detail.files);
|
|
152
|
+
}
|
|
153
|
+
writeValue(value) {
|
|
154
|
+
const el = this.ref.nativeElement;
|
|
155
|
+
if (!Array.isArray(value) || !value.length) {
|
|
156
|
+
el.files = [];
|
|
157
|
+
el.value = "";
|
|
158
|
+
} else el.files = value;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
__decorateClass([
|
|
162
|
+
HostListener("impkt-files", ["$event"])
|
|
163
|
+
], ImpktFileUploadAccessor.prototype, "handleFiles", 1);
|
|
164
|
+
ImpktFileUploadAccessor = __decorateClass([
|
|
165
|
+
Directive({
|
|
166
|
+
selector: "impkt-file-upload",
|
|
167
|
+
standalone: true,
|
|
168
|
+
providers: [accessor(ImpktFileUploadAccessor)]
|
|
169
|
+
})
|
|
170
|
+
], ImpktFileUploadAccessor);
|
|
171
|
+
var ImpktCheckboxAccessor = class extends ImpktValueAccessor {
|
|
172
|
+
handleChange(event) {
|
|
173
|
+
this.onChange(Boolean(event.detail.value));
|
|
174
|
+
}
|
|
175
|
+
writeValue(value) {
|
|
176
|
+
this.ref.nativeElement.checked = Boolean(value);
|
|
177
|
+
}
|
|
178
|
+
};
|
|
179
|
+
__decorateClass([
|
|
180
|
+
HostListener("impkt-change", ["$event"])
|
|
181
|
+
], ImpktCheckboxAccessor.prototype, "handleChange", 1);
|
|
182
|
+
ImpktCheckboxAccessor = __decorateClass([
|
|
183
|
+
Directive({
|
|
184
|
+
selector: "impkt-checkbox",
|
|
185
|
+
standalone: true,
|
|
186
|
+
providers: [accessor(ImpktCheckboxAccessor)]
|
|
187
|
+
})
|
|
188
|
+
], ImpktCheckboxAccessor);
|
|
189
|
+
var IMPKT_FORM_ACCESSORS = [
|
|
190
|
+
ImpktTextInputAccessor,
|
|
191
|
+
ImpktTextareaAccessor,
|
|
192
|
+
ImpktSelectAccessor,
|
|
193
|
+
ImpktCheckboxAccessor,
|
|
194
|
+
ImpktRadioGroupAccessor,
|
|
195
|
+
ImpktCheckboxGroupAccessor,
|
|
196
|
+
ImpktDateInputAccessor,
|
|
197
|
+
ImpktMoneyInputAccessor,
|
|
198
|
+
ImpktRangeInputAccessor,
|
|
199
|
+
ImpktFileUploadAccessor,
|
|
200
|
+
ImpktAddressLookupAccessor,
|
|
201
|
+
ImpktSlotPickerAccessor
|
|
202
|
+
];
|
|
203
|
+
var ImpktFormsModule = class {
|
|
204
|
+
};
|
|
205
|
+
ImpktFormsModule = __decorateClass([
|
|
206
|
+
NgModule({
|
|
207
|
+
imports: [...IMPKT_FORM_ACCESSORS],
|
|
208
|
+
exports: [...IMPKT_FORM_ACCESSORS]
|
|
209
|
+
})
|
|
210
|
+
], ImpktFormsModule);
|
|
211
|
+
export {
|
|
212
|
+
IMPKT_FORM_ACCESSORS,
|
|
213
|
+
ImpktAddressLookupAccessor,
|
|
214
|
+
ImpktCheckboxAccessor,
|
|
215
|
+
ImpktCheckboxGroupAccessor,
|
|
216
|
+
ImpktDateInputAccessor,
|
|
217
|
+
ImpktFileUploadAccessor,
|
|
218
|
+
ImpktFormsModule,
|
|
219
|
+
ImpktMoneyInputAccessor,
|
|
220
|
+
ImpktRadioGroupAccessor,
|
|
221
|
+
ImpktRangeInputAccessor,
|
|
222
|
+
ImpktSelectAccessor,
|
|
223
|
+
ImpktSlotPickerAccessor,
|
|
224
|
+
ImpktTextInputAccessor,
|
|
225
|
+
ImpktTextareaAccessor
|
|
226
|
+
};
|
|
227
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["/**\n * Angular bindings for `@atomic-ui/ui`.\n *\n * ## What Angular actually needs\n *\n * Not wrappers. Angular renders custom elements as-is once a component\n * declares `CUSTOM_ELEMENTS_SCHEMA`, and `[options]=\"…\"` already sets a DOM\n * property rather than an attribute, so arrays arrive intact. Writing a\n * component per element would add a layer that does nothing.\n *\n * What does not work without help is **forms**. `formControlName` and\n * `ngModel` need a `ControlValueAccessor`, and Angular ships one for `<input>`\n * and `<select>` and nothing else. Without one, a reactive form containing\n * `<impkt-text-input>` silently never receives a value — the control stays\n * `null`, validation passes, and the bug surfaces as an empty field in an order\n * request.\n *\n * So this package is value accessors, and that is the whole of it.\n *\n * ```ts\n * import { ImpktFormsModule } from '@atomic-ui/ui-angular';\n *\n * @Component({\n * standalone: true,\n * imports: [ReactiveFormsModule, ImpktFormsModule],\n * schemas: [CUSTOM_ELEMENTS_SCHEMA],\n * template: `<impkt-text-input label=\"Postcode\" formControlName=\"postcode\"></impkt-text-input>`,\n * })\n * ```\n *\n * `CUSTOM_ELEMENTS_SCHEMA` stays the consumer's to declare. It tells Angular\n * to stop checking unknown tags for a whole component, which is a real\n * loosening of its template checking, and a library should not switch that off\n * on an application's behalf.\n */\nimport { Directive, ElementRef, HostListener, NgModule, forwardRef } from '@angular/core';\nimport { NG_VALUE_ACCESSOR, type ControlValueAccessor } from '@angular/forms';\nimport '@atomic-ui/ui';\n\ninterface ValueElement extends HTMLElement {\n value: string;\n disabled: boolean;\n}\n\n/**\n * The shared accessor.\n *\n * It listens for `impkt-change` — the one event every control in the library\n * dispatches — and writes back to the element's `value` property. One\n * implementation covers every control because they all agree on that contract,\n * which is the payoff for having settled it in the component base rather than\n * per component.\n */\n@Directive()\nabstract class ImpktValueAccessor implements ControlValueAccessor {\n protected onChange: (value: string) => void = () => {};\n protected onTouched: () => void = () => {};\n\n constructor(protected readonly ref: ElementRef<ValueElement>) {}\n\n @HostListener('impkt-change', ['$event'])\n handleChange(event: CustomEvent<{ value: string }>): void {\n this.onChange(event.detail.value);\n }\n\n /**\n * Blur marks the control touched, which is what makes \"required\" errors\n * appear after someone leaves a field rather than while they are still\n * typing in it. A form that reports an error on the first keystroke gets\n * worked around.\n */\n @HostListener('blur')\n handleBlur(): void {\n this.onTouched();\n }\n\n writeValue(value: string | null): void {\n this.ref.nativeElement.value = value ?? '';\n }\n\n registerOnChange(fn: (value: string) => void): void {\n this.onChange = fn;\n }\n\n registerOnTouched(fn: () => void): void {\n this.onTouched = fn;\n }\n\n setDisabledState(isDisabled: boolean): void {\n this.ref.nativeElement.disabled = isDisabled;\n }\n}\n\nconst accessor = (directive: unknown) => ({\n provide: NG_VALUE_ACCESSOR,\n useExisting: forwardRef(() => directive),\n multi: true,\n});\n\n@Directive({\n selector: 'impkt-text-input',\n standalone: true,\n providers: [accessor(ImpktTextInputAccessor)],\n})\nexport class ImpktTextInputAccessor extends ImpktValueAccessor {}\n\n@Directive({\n selector: 'impkt-textarea',\n standalone: true,\n providers: [accessor(ImpktTextareaAccessor)],\n})\nexport class ImpktTextareaAccessor extends ImpktValueAccessor {}\n\n@Directive({\n selector: 'impkt-select',\n standalone: true,\n providers: [accessor(ImpktSelectAccessor)],\n})\nexport class ImpktSelectAccessor extends ImpktValueAccessor {}\n\n@Directive({\n selector: 'impkt-radio-group',\n standalone: true,\n providers: [accessor(ImpktRadioGroupAccessor)],\n})\nexport class ImpktRadioGroupAccessor extends ImpktValueAccessor {}\n\n@Directive({\n selector: 'impkt-checkbox-group',\n standalone: true,\n providers: [accessor(ImpktCheckboxGroupAccessor)],\n})\nexport class ImpktCheckboxGroupAccessor extends ImpktValueAccessor {}\n\n@Directive({\n selector: 'impkt-date-input',\n standalone: true,\n providers: [accessor(ImpktDateInputAccessor)],\n})\nexport class ImpktDateInputAccessor extends ImpktValueAccessor {}\n\n/** An amount, as the plain number typed, such as `250000`. */\n@Directive({\n selector: 'impkt-money-input',\n standalone: true,\n providers: [accessor(ImpktMoneyInputAccessor)],\n})\nexport class ImpktMoneyInputAccessor extends ImpktValueAccessor {}\n\n@Directive({\n selector: 'impkt-range-input',\n standalone: true,\n providers: [accessor(ImpktRangeInputAccessor)],\n})\nexport class ImpktRangeInputAccessor extends ImpktValueAccessor {}\n\n/** The address chosen or typed, on one line. */\n@Directive({\n selector: 'impkt-address-lookup',\n standalone: true,\n providers: [accessor(ImpktAddressLookupAccessor)],\n})\nexport class ImpktAddressLookupAccessor extends ImpktValueAccessor {}\n\n@Directive({\n selector: 'impkt-slot-picker',\n standalone: true,\n providers: [accessor(ImpktSlotPickerAccessor)],\n})\nexport class ImpktSlotPickerAccessor extends ImpktValueAccessor {}\n\n/**\n * A file upload's form value is the files themselves, as `File[]`, because that\n * is what a form uploads. The element's own `impkt-change` carries only their\n * names, so this listens for `impkt-files` instead. A file input cannot be given\n * files from code, so writing a value can only clear it, as a form reset does.\n */\n@Directive({\n selector: 'impkt-file-upload',\n standalone: true,\n providers: [accessor(ImpktFileUploadAccessor)],\n})\nexport class ImpktFileUploadAccessor extends ImpktValueAccessor {\n override handleChange(): void {\n // The names are not the value; impkt-files below carries the files.\n }\n\n @HostListener('impkt-files', ['$event'])\n handleFiles(event: CustomEvent<{ files: File[] }>): void {\n (this.onChange as unknown as (v: File[]) => void)(event.detail.files);\n }\n\n override writeValue(value: unknown): void {\n const el = this.ref.nativeElement as ValueElement & { files: File[] };\n if (!Array.isArray(value) || !value.length) {\n el.files = [];\n el.value = '';\n } else el.files = value as File[];\n }\n}\n\n/**\n * A checkbox is the one that differs: its form value is a boolean to Angular\n * and a string to the element, so it translates rather than passing through.\n */\n@Directive({\n selector: 'impkt-checkbox',\n standalone: true,\n providers: [accessor(ImpktCheckboxAccessor)],\n})\nexport class ImpktCheckboxAccessor extends ImpktValueAccessor {\n @HostListener('impkt-change', ['$event'])\n override handleChange(event: CustomEvent<{ value: string }>): void {\n (this.onChange as unknown as (v: boolean) => void)(Boolean(event.detail.value));\n }\n\n override writeValue(value: unknown): void {\n (this.ref.nativeElement as ValueElement & { checked: boolean }).checked = Boolean(value);\n }\n}\n\nexport const IMPKT_FORM_ACCESSORS = [\n ImpktTextInputAccessor,\n ImpktTextareaAccessor,\n ImpktSelectAccessor,\n ImpktCheckboxAccessor,\n ImpktRadioGroupAccessor,\n ImpktCheckboxGroupAccessor,\n ImpktDateInputAccessor,\n ImpktMoneyInputAccessor,\n ImpktRangeInputAccessor,\n ImpktFileUploadAccessor,\n ImpktAddressLookupAccessor,\n ImpktSlotPickerAccessor,\n] as const;\n\n/** Import this where you use the elements in a form. */\n@NgModule({\n imports: [...IMPKT_FORM_ACCESSORS],\n exports: [...IMPKT_FORM_ACCESSORS],\n})\nexport class ImpktFormsModule {}\n"],"mappings":";;;;;;;;;;;;AAmCA,SAAS,WAAuB,cAAc,UAAU,kBAAkB;AAC1E,SAAS,yBAAoD;AAC7D,OAAO;AAiBP,IAAe,qBAAf,MAAkE;AAAA,EAIhE,YAA+B,KAA+B;AAA/B;AAH/B,SAAU,WAAoC,MAAM;AAAA,IAAC;AACrD,SAAU,YAAwB,MAAM;AAAA,IAAC;AAAA,EAEsB;AAAA,EAG/D,aAAa,OAA6C;AACxD,SAAK,SAAS,MAAM,OAAO,KAAK;AAAA,EAClC;AAAA,EASA,aAAmB;AACjB,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,WAAW,OAA4B;AACrC,SAAK,IAAI,cAAc,QAAQ,SAAS;AAAA,EAC1C;AAAA,EAEA,iBAAiB,IAAmC;AAClD,SAAK,WAAW;AAAA,EAClB;AAAA,EAEA,kBAAkB,IAAsB;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,SAAG,QAAQ;AAAA,IACb,MAAO,IAAG,QAAQ;AAAA,EACpB;AACF;AAXE;AAAA,EADC,aAAa,eAAe,CAAC,QAAQ,CAAC;AAAA,GAL5B,wBAMX;AANW,0BAAN;AAAA,EALN,UAAU;AAAA,IACT,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,WAAW,CAAC,SAAS,uBAAuB,CAAC;AAAA,EAC/C,CAAC;AAAA,GACY;AA4BN,IAAM,wBAAN,cAAoC,mBAAmB;AAAA,EAEnD,aAAa,OAA6C;AACjE,IAAC,KAAK,SAA6C,QAAQ,MAAM,OAAO,KAAK,CAAC;AAAA,EAChF;AAAA,EAES,WAAW,OAAsB;AACxC,IAAC,KAAK,IAAI,cAAsD,UAAU,QAAQ,KAAK;AAAA,EACzF;AACF;AAPW;AAAA,EADR,aAAa,gBAAgB,CAAC,QAAQ,CAAC;AAAA,GAD7B,sBAEF;AAFE,wBAAN;AAAA,EALN,UAAU;AAAA,IACT,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,WAAW,CAAC,SAAS,qBAAqB,CAAC;AAAA,EAC7C,CAAC;AAAA,GACY;AAWN,IAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAOO,IAAM,mBAAN,MAAuB;AAAC;AAAlB,mBAAN;AAAA,EAJN,SAAS;AAAA,IACR,SAAS,CAAC,GAAG,oBAAoB;AAAA,IACjC,SAAS,CAAC,GAAG,oBAAoB;AAAA,EACnC,CAAC;AAAA,GACY;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atomic-ui/ui-angular",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Angular bindings for @atomic-ui/ui: value accessors so the elements work with reactive forms and ngModel.",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/matthill8286/impkt-design-system.git",
|
|
8
|
+
"directory": "packages/ui-angular"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"main": "./dist/index.js",
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@atomic-ui/ui": "^0.3.0"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"@angular/core": ">=17",
|
|
24
|
+
"@angular/forms": ">=17"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@angular/core": "^18.2.0",
|
|
28
|
+
"@angular/forms": "^18.2.0",
|
|
29
|
+
"rxjs": "^7.8.0",
|
|
30
|
+
"typescript": "^5.5.0",
|
|
31
|
+
"vitest": "^2.0.0",
|
|
32
|
+
"zone.js": "^0.14.0"
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"registry": "https://registry.npmjs.org",
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"scripts": {
|
|
43
|
+
"build": "tsc -p tsconfig.json",
|
|
44
|
+
"typecheck": "tsc -p tsconfig.json",
|
|
45
|
+
"test": "vitest run"
|
|
46
|
+
}
|
|
6
47
|
}
|