@kraft.stitch/angular 0.0.4-beta.1 → 0.0.4-beta.2
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/fesm2022/kraft.stitch-angular.mjs +3043 -0
- package/fesm2022/kraft.stitch-angular.mjs.map +1 -0
- package/package.json +17 -16
- package/types/kraft.stitch-angular.d.ts +2395 -0
- package/.github/workflows/npm-publish.yml +0 -41
- package/ng-package.json +0 -10
- package/src/lib/Buttons/button/button.ts +0 -152
- package/src/lib/Buttons/button-group/button-group.ts +0 -129
- package/src/lib/Buttons/chips/chips.ts +0 -131
- package/src/lib/Buttons/fab/fab.ts +0 -96
- package/src/lib/Buttons/split-button/split-button.ts +0 -111
- package/src/lib/Calendars/datepicker/datepicker.ts +0 -105
- package/src/lib/Calendars/daterange/daterange.ts +0 -112
- package/src/lib/Calendars/timepicker/timepicker.ts +0 -117
- package/src/lib/Dropdowns/dropdown/dropdown.ts +0 -121
- package/src/lib/Dropdowns/listbox/listbox.ts +0 -116
- package/src/lib/Inputs/checkbox/checkbox.ts +0 -126
- package/src/lib/Inputs/colour-picker/colour-picker.ts +0 -101
- package/src/lib/Inputs/input/input.ts +0 -139
- package/src/lib/Inputs/otp-input/otp-input.ts +0 -113
- package/src/lib/Inputs/radio/radio.ts +0 -115
- package/src/lib/Inputs/rating/rating.ts +0 -104
- package/src/lib/Inputs/rolling-number/rolling-number.ts +0 -136
- package/src/lib/Inputs/slider/slider.ts +0 -121
- package/src/lib/Inputs/switch/switch.ts +0 -100
- package/src/lib/Inputs/textarea/textarea.ts +0 -129
- package/src/lib/Inputs/theme-switch/theme-switch.ts +0 -61
- package/src/lib/Inputs/uploader/uploader.ts +0 -97
- package/src/lib/Layout/avatar/avatar.ts +0 -66
- package/src/lib/Layout/card/card.ts +0 -88
- package/src/lib/Layout/code-view/code-view.ts +0 -77
- package/src/lib/Layout/dialog/dialog.ts +0 -80
- package/src/lib/Layout/not-found/not-found.ts +0 -73
- package/src/lib/Layout/sidebar/sidebar.ts +0 -97
- package/src/lib/Layout/table/table.ts +0 -81
- package/src/lib/Layout/tooltip/tooltip.ts +0 -48
- package/src/lib/Navigation/accordion/accordion.ts +0 -80
- package/src/lib/Navigation/breadcrumb/breadcrumb.ts +0 -58
- package/src/lib/Navigation/carousel/carousel.ts +0 -70
- package/src/lib/Navigation/context-menu/context-menu.ts +0 -79
- package/src/lib/Navigation/nav-bar/nav-bar.ts +0 -72
- package/src/lib/Navigation/pagination/pagination.ts +0 -82
- package/src/lib/Navigation/stepper/stepper.ts +0 -77
- package/src/lib/Navigation/tab/tab.ts +0 -71
- package/src/lib/Navigation/toolbar/toolbar.ts +0 -60
- package/src/lib/Navigation/top-nav-bar/top-nav-bar.ts +0 -71
- package/src/lib/Navigation/tree-view/tree-view.ts +0 -75
- package/src/lib/Notification/badge/badge.ts +0 -55
- package/src/lib/Notification/loader/loader.ts +0 -41
- package/src/lib/Notification/message/message.ts +0 -60
- package/src/lib/Notification/progress/progress.ts +0 -65
- package/src/lib/Notification/spinner/spinner.ts +0 -50
- package/src/lib/Notification/toast/toast.ts +0 -56
- package/src/public-api.ts +0 -68
- package/src/utils/theme-service.ts +0 -11
- package/tsconfig.json +0 -23
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
// Side-effect import: registers the `ks-checkbox` tag — see
|
|
2
|
-
// `Buttons/button/button.ts` for the full explanation of this pattern.
|
|
3
|
-
import '@kraft.stitch/core/dist/components/ks-checkbox.js';
|
|
4
|
-
|
|
5
|
-
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, effect, inject, input, output } from '@angular/core';
|
|
6
|
-
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Mirrors `KsCheckboxOption` exported by
|
|
10
|
-
* `core/src/components/Inputs/checkbox/checkbox.tsx`. Duplicated locally
|
|
11
|
-
* — see the note in `Buttons/button-group/button-group.ts` for why.
|
|
12
|
-
*/
|
|
13
|
-
export interface KsCheckboxOption {
|
|
14
|
-
value: string;
|
|
15
|
-
label?: string;
|
|
16
|
-
disabled?: boolean;
|
|
17
|
-
checked?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** DOM shape of the real `<ks-checkbox>` custom element, typed for the wrapper. */
|
|
21
|
-
type KsCheckboxElement = HTMLElement & {
|
|
22
|
-
label: string;
|
|
23
|
-
options: KsCheckboxOption[];
|
|
24
|
-
disabled: boolean;
|
|
25
|
-
checked: boolean;
|
|
26
|
-
selected: string[];
|
|
27
|
-
writeValue(val: unknown): Promise<void>;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Angular wrapper around the `<ks-checkbox>` Stencil custom element.
|
|
32
|
-
*
|
|
33
|
-
* Supports two modes, mirroring the Stencil source:
|
|
34
|
-
* - **Single** mode (no `options`): two-way bind `checked` (boolean).
|
|
35
|
-
* - **Group** mode (`options` set): two-way bind `selected` (string[]).
|
|
36
|
-
*
|
|
37
|
-
* Two-way binding for either mode is via `ControlValueAccessor` — use
|
|
38
|
-
* `[(ngModel)]`/`formControlName` and it works for whichever mode is
|
|
39
|
-
* active (see `Buttons/chips/chips.ts` for the full rationale on why CVA
|
|
40
|
-
* is used instead of reusing a native event name as an Angular output).
|
|
41
|
-
*
|
|
42
|
-
* For plain (non-forms) two-way use, bind explicitly instead:
|
|
43
|
-
* `[checked]="c" (ksCheckedChange)="c = $event"` or
|
|
44
|
-
* `[selected]="s" (ksSelectedChange)="s = $event"`.
|
|
45
|
-
*
|
|
46
|
-
* `template: ''` — no `<slot>` in the wrapped Stencil render.
|
|
47
|
-
*/
|
|
48
|
-
@Component({
|
|
49
|
-
selector: 'ks-checkbox',
|
|
50
|
-
standalone: true,
|
|
51
|
-
template: '',
|
|
52
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
53
|
-
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: KsCheckboxComponent, multi: true }],
|
|
54
|
-
})
|
|
55
|
-
export class KsCheckboxComponent implements ControlValueAccessor {
|
|
56
|
-
private readonly el: KsCheckboxElement;
|
|
57
|
-
private onChange: (value: unknown) => void = () => {};
|
|
58
|
-
private onTouched: () => void = () => {};
|
|
59
|
-
|
|
60
|
-
/** Label shown next to the control (single mode) */
|
|
61
|
-
readonly label = input('');
|
|
62
|
-
|
|
63
|
-
/** Optional set of multiple options (multi-select / group mode) */
|
|
64
|
-
readonly options = input<KsCheckboxOption[]>([]);
|
|
65
|
-
|
|
66
|
-
/** Disabled state */
|
|
67
|
-
readonly disabled = input(false);
|
|
68
|
-
|
|
69
|
-
/** Single mode: initial/controlled checked value. Prefer `[(ngModel)]` / `formControlName`. */
|
|
70
|
-
readonly checked = input(false);
|
|
71
|
-
|
|
72
|
-
/** Group mode: initial/controlled selected values. Prefer `[(ngModel)]` / `formControlName`. */
|
|
73
|
-
readonly selected = input<string[]>([]);
|
|
74
|
-
|
|
75
|
-
/** Emits whenever `checked` changes (single mode). From the native `checkedChange` event. */
|
|
76
|
-
readonly ksCheckedChange = output<boolean>();
|
|
77
|
-
|
|
78
|
-
/** Emits whenever `selected` changes (group mode). From the native `selectedChange` event. */
|
|
79
|
-
readonly ksSelectedChange = output<string[]>();
|
|
80
|
-
|
|
81
|
-
constructor(ref: ElementRef<KsCheckboxElement>) {
|
|
82
|
-
this.el = ref.nativeElement;
|
|
83
|
-
|
|
84
|
-
effect(() => (this.el.label = this.label()));
|
|
85
|
-
effect(() => (this.el.options = this.options()));
|
|
86
|
-
effect(() => (this.el.disabled = this.disabled()));
|
|
87
|
-
effect(() => (this.el.checked = this.checked()));
|
|
88
|
-
effect(() => (this.el.selected = this.selected()));
|
|
89
|
-
|
|
90
|
-
const onNativeCheckedChange = (event: Event): void => {
|
|
91
|
-
const detail = (event as CustomEvent<boolean>).detail;
|
|
92
|
-
this.ksCheckedChange.emit(detail);
|
|
93
|
-
this.onChange(detail);
|
|
94
|
-
this.onTouched();
|
|
95
|
-
};
|
|
96
|
-
const onNativeSelectedChange = (event: Event): void => {
|
|
97
|
-
const detail = (event as CustomEvent<string[]>).detail;
|
|
98
|
-
this.ksSelectedChange.emit(detail);
|
|
99
|
-
this.onChange(detail);
|
|
100
|
-
this.onTouched();
|
|
101
|
-
};
|
|
102
|
-
this.el.addEventListener('checkedChange', onNativeCheckedChange);
|
|
103
|
-
this.el.addEventListener('selectedChange', onNativeSelectedChange);
|
|
104
|
-
inject(DestroyRef).onDestroy(() => {
|
|
105
|
-
this.el.removeEventListener('checkedChange', onNativeCheckedChange);
|
|
106
|
-
this.el.removeEventListener('selectedChange', onNativeSelectedChange);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** `ControlValueAccessor` — called by `ngModel`/`formControl` to push a value in (either mode). */
|
|
111
|
-
writeValue(value: unknown): void {
|
|
112
|
-
void this.el.writeValue(value);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
registerOnChange(fn: (value: unknown) => void): void {
|
|
116
|
-
this.onChange = fn;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
registerOnTouched(fn: () => void): void {
|
|
120
|
-
this.onTouched = fn;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
setDisabledState(isDisabled: boolean): void {
|
|
124
|
-
this.el.disabled = isDisabled;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
// Side-effect import: registers the `ks-colour-picker` tag — see
|
|
2
|
-
// `Buttons/button/button.ts` for the full explanation of this pattern.
|
|
3
|
-
import '@kraft.stitch/core/dist/components/ks-colour-picker.js';
|
|
4
|
-
|
|
5
|
-
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, effect, inject, input, output } from '@angular/core';
|
|
6
|
-
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
7
|
-
|
|
8
|
-
/** Mirrors the inline union used by `core/src/components/Inputs/colour-picker/colour-picker.tsx`. */
|
|
9
|
-
export type KsColourPickerVariant = 'input' | 'swatch';
|
|
10
|
-
|
|
11
|
-
const DEFAULT_SWATCHES = ['#ef4444', '#f97316', '#eab308', '#22c55e', '#3b82f6', '#8b5cf6', '#ec4899', '#64748b', '#000000', '#ffffff'];
|
|
12
|
-
|
|
13
|
-
/** DOM shape of the real `<ks-colour-picker>` custom element, typed for the wrapper. */
|
|
14
|
-
type KsColourPickerElement = HTMLElement & {
|
|
15
|
-
label: string;
|
|
16
|
-
variant: KsColourPickerVariant;
|
|
17
|
-
swatches: string[];
|
|
18
|
-
disabled: boolean;
|
|
19
|
-
value: string;
|
|
20
|
-
writeValue(val: string): Promise<void>;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Angular wrapper around the `<ks-colour-picker>` Stencil custom element.
|
|
25
|
-
*
|
|
26
|
-
* Two-way binding is via `ControlValueAccessor` — use `[(ngModel)]` or
|
|
27
|
-
* `formControlName`. See `Buttons/chips/chips.ts` for the full rationale
|
|
28
|
-
* (the native `valueChange` event can't be reused verbatim as an Angular
|
|
29
|
-
* output name without a double-fire risk).
|
|
30
|
-
*
|
|
31
|
-
* For plain (non-forms) two-way use, bind explicitly instead:
|
|
32
|
-
* `[value]="hex" (ksValueChange)="hex = $event"`.
|
|
33
|
-
*
|
|
34
|
-
* `template: ''` — the panel is rendered into the internal
|
|
35
|
-
* `<ks-overlay-field>`; there is no slot on `<ks-colour-picker>` itself.
|
|
36
|
-
*/
|
|
37
|
-
@Component({
|
|
38
|
-
selector: 'ks-colour-picker',
|
|
39
|
-
standalone: true,
|
|
40
|
-
template: '',
|
|
41
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
42
|
-
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: KsColourPickerComponent, multi: true }],
|
|
43
|
-
})
|
|
44
|
-
export class KsColourPickerComponent implements ControlValueAccessor {
|
|
45
|
-
private readonly el: KsColourPickerElement;
|
|
46
|
-
private onChange: (value: string) => void = () => {};
|
|
47
|
-
private onTouched: () => void = () => {};
|
|
48
|
-
|
|
49
|
-
/** Field label */
|
|
50
|
-
readonly label = input('');
|
|
51
|
-
|
|
52
|
-
/** Picker UI variant */
|
|
53
|
-
readonly variant = input<KsColourPickerVariant>('input');
|
|
54
|
-
|
|
55
|
-
/** Preset swatch colours */
|
|
56
|
-
readonly swatches = input<string[]>(DEFAULT_SWATCHES);
|
|
57
|
-
|
|
58
|
-
/** Disabled */
|
|
59
|
-
readonly disabled = input(false);
|
|
60
|
-
|
|
61
|
-
/** Initial/controlled hex value. Prefer `[(ngModel)]` / `formControlName`. */
|
|
62
|
-
readonly value = input('#3b82f6');
|
|
63
|
-
|
|
64
|
-
/** Emits the newly-picked hex colour. From the native `valueChange` event. */
|
|
65
|
-
readonly ksValueChange = output<string>();
|
|
66
|
-
|
|
67
|
-
constructor(ref: ElementRef<KsColourPickerElement>) {
|
|
68
|
-
this.el = ref.nativeElement;
|
|
69
|
-
|
|
70
|
-
effect(() => (this.el.label = this.label()));
|
|
71
|
-
effect(() => (this.el.variant = this.variant()));
|
|
72
|
-
effect(() => (this.el.swatches = this.swatches()));
|
|
73
|
-
effect(() => (this.el.disabled = this.disabled()));
|
|
74
|
-
effect(() => void this.el.writeValue(this.value()));
|
|
75
|
-
|
|
76
|
-
const onNativeValueChange = (event: Event): void => {
|
|
77
|
-
const detail = (event as CustomEvent<string>).detail;
|
|
78
|
-
this.ksValueChange.emit(detail);
|
|
79
|
-
this.onChange(detail);
|
|
80
|
-
this.onTouched();
|
|
81
|
-
};
|
|
82
|
-
this.el.addEventListener('valueChange', onNativeValueChange);
|
|
83
|
-
inject(DestroyRef).onDestroy(() => this.el.removeEventListener('valueChange', onNativeValueChange));
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
writeValue(value: string): void {
|
|
87
|
-
void this.el.writeValue(value ?? '#3b82f6');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
registerOnChange(fn: (value: string) => void): void {
|
|
91
|
-
this.onChange = fn;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
registerOnTouched(fn: () => void): void {
|
|
95
|
-
this.onTouched = fn;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
setDisabledState(isDisabled: boolean): void {
|
|
99
|
-
this.el.disabled = isDisabled;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
// Side-effect import: registers the `ks-input` tag — see
|
|
2
|
-
// `Buttons/button/button.ts` for the full explanation of this pattern.
|
|
3
|
-
import '@kraft.stitch/core/dist/components/ks-input.js';
|
|
4
|
-
|
|
5
|
-
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, effect, inject, input, model, output } from '@angular/core';
|
|
6
|
-
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
7
|
-
import type { KsSize } from '@kraft.stitch/core';
|
|
8
|
-
|
|
9
|
-
/** Mirrors `KsInputType` exported by `core/src/components/Inputs/input/input.tsx`. */
|
|
10
|
-
export type KsInputType = 'text' | 'password' | 'email' | 'number' | 'search' | 'tel' | 'url';
|
|
11
|
-
|
|
12
|
-
/** DOM shape of the real `<ks-input>` custom element, typed for the wrapper. */
|
|
13
|
-
type KsInputElement = HTMLElement & {
|
|
14
|
-
type: KsInputType;
|
|
15
|
-
placeholder: string;
|
|
16
|
-
label: string;
|
|
17
|
-
hint: string;
|
|
18
|
-
error: string;
|
|
19
|
-
prefixIcon: string;
|
|
20
|
-
suffixIcon: string;
|
|
21
|
-
size: KsSize;
|
|
22
|
-
value: string;
|
|
23
|
-
disabled: boolean;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Angular wrapper around the `<ks-input>` Stencil custom element.
|
|
28
|
-
*
|
|
29
|
-
* Two-way binding is via `ControlValueAccessor` — use `[(ngModel)]` or
|
|
30
|
-
* `formControlName`. `<ks-input>` has no `@Method() writeValue()` of its
|
|
31
|
-
* own (unlike `chips`/`dropdown`/…), so this wrapper's `writeValue` sets
|
|
32
|
-
* `el.value` directly instead of delegating to a Stencil method.
|
|
33
|
-
*
|
|
34
|
-
* The native `ksBlur` event is already prefixed `ks` by the Stencil
|
|
35
|
-
* author, so re-using that exact name here as the Angular output would
|
|
36
|
-
* still hit the double-fire collision described in `Buttons/button.ts`
|
|
37
|
-
* (Ivy's `tNode.outputs` match is purely by literal name, `ks`-prefix or
|
|
38
|
-
* not) — hence `ksBlurred` (distinct spelling) instead.
|
|
39
|
-
*
|
|
40
|
-
* For plain (non-forms) two-way use, bind explicitly instead:
|
|
41
|
-
* `[value]="v" (ksValueChange)="v = $event"`.
|
|
42
|
-
*
|
|
43
|
-
* `template: ''` — no `<slot>` in the wrapped Stencil render.
|
|
44
|
-
*/
|
|
45
|
-
@Component({
|
|
46
|
-
selector: 'ks-input',
|
|
47
|
-
standalone: true,
|
|
48
|
-
template: '',
|
|
49
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
50
|
-
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: KsInputComponent, multi: true }],
|
|
51
|
-
})
|
|
52
|
-
export class KsInputComponent implements ControlValueAccessor {
|
|
53
|
-
private readonly el: KsInputElement;
|
|
54
|
-
private onChange: (value: string) => void = () => {};
|
|
55
|
-
private onTouched: () => void = () => {};
|
|
56
|
-
|
|
57
|
-
/** HTML input type */
|
|
58
|
-
readonly type = input<KsInputType>('text');
|
|
59
|
-
|
|
60
|
-
/** Placeholder text */
|
|
61
|
-
readonly placeholder = input('');
|
|
62
|
-
|
|
63
|
-
/** Field label */
|
|
64
|
-
readonly label = input('');
|
|
65
|
-
|
|
66
|
-
/** Helper / hint text shown below the input */
|
|
67
|
-
readonly hint = input('');
|
|
68
|
-
|
|
69
|
-
/** Error message — also triggers the error state */
|
|
70
|
-
readonly error = input('');
|
|
71
|
-
|
|
72
|
-
/** Leading icon class (e.g. Material Symbol name) */
|
|
73
|
-
readonly prefixIcon = input('');
|
|
74
|
-
|
|
75
|
-
/** Trailing icon class */
|
|
76
|
-
readonly suffixIcon = input('');
|
|
77
|
-
|
|
78
|
-
/** Size variant */
|
|
79
|
-
readonly size = input<KsSize>('md');
|
|
80
|
-
|
|
81
|
-
/** Initial/controlled value. Prefer `[(ngModel)]` / `formControlName`. */
|
|
82
|
-
readonly value = model('');
|
|
83
|
-
|
|
84
|
-
/** Disabled state */
|
|
85
|
-
readonly disabled = input(false);
|
|
86
|
-
|
|
87
|
-
/** Emits the newly-typed value. From the native `valueChange` event. */
|
|
88
|
-
readonly ksValueChange = output<string>();
|
|
89
|
-
|
|
90
|
-
/** Emitted on native blur (mirrors Angular's onTouched callback). From the native `ksBlur` event. */
|
|
91
|
-
readonly ksBlurred = output<void>();
|
|
92
|
-
|
|
93
|
-
constructor(ref: ElementRef<KsInputElement>) {
|
|
94
|
-
this.el = ref.nativeElement;
|
|
95
|
-
|
|
96
|
-
effect(() => (this.el.type = this.type()));
|
|
97
|
-
effect(() => (this.el.placeholder = this.placeholder()));
|
|
98
|
-
effect(() => (this.el.label = this.label()));
|
|
99
|
-
effect(() => (this.el.hint = this.hint()));
|
|
100
|
-
effect(() => (this.el.error = this.error()));
|
|
101
|
-
effect(() => (this.el.prefixIcon = this.prefixIcon()));
|
|
102
|
-
effect(() => (this.el.suffixIcon = this.suffixIcon()));
|
|
103
|
-
effect(() => (this.el.size = this.size()));
|
|
104
|
-
effect(() => (this.el.disabled = this.disabled()));
|
|
105
|
-
effect(() => (this.el.value = this.value()));
|
|
106
|
-
|
|
107
|
-
const onNativeValueChange = (event: Event): void => {
|
|
108
|
-
const detail = (event as CustomEvent<string>).detail;
|
|
109
|
-
this.ksValueChange.emit(detail);
|
|
110
|
-
this.onChange(detail);
|
|
111
|
-
};
|
|
112
|
-
const onNativeBlur = (): void => {
|
|
113
|
-
this.ksBlurred.emit();
|
|
114
|
-
this.onTouched();
|
|
115
|
-
};
|
|
116
|
-
this.el.addEventListener('valueChange', onNativeValueChange);
|
|
117
|
-
this.el.addEventListener('ksBlur', onNativeBlur);
|
|
118
|
-
inject(DestroyRef).onDestroy(() => {
|
|
119
|
-
this.el.removeEventListener('valueChange', onNativeValueChange);
|
|
120
|
-
this.el.removeEventListener('ksBlur', onNativeBlur);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
writeValue(value: string): void {
|
|
125
|
-
this.el.value = value ?? '';
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
registerOnChange(fn: (value: string) => void): void {
|
|
129
|
-
this.onChange = fn;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
registerOnTouched(fn: () => void): void {
|
|
133
|
-
this.onTouched = fn;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
setDisabledState(isDisabled: boolean): void {
|
|
137
|
-
this.el.disabled = isDisabled;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
// Side-effect import: registers the `ks-otp-input` tag — see
|
|
2
|
-
// `Buttons/button/button.ts` for the full explanation of this pattern.
|
|
3
|
-
import '@kraft.stitch/core/dist/components/ks-otp-input.js';
|
|
4
|
-
|
|
5
|
-
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, effect, inject, input, output } from '@angular/core';
|
|
6
|
-
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
7
|
-
|
|
8
|
-
/** DOM shape of the real `<ks-otp-input>` custom element, typed for the wrapper. */
|
|
9
|
-
type KsOtpInputElement = HTMLElement & {
|
|
10
|
-
length: number;
|
|
11
|
-
inputType: 'number' | 'text';
|
|
12
|
-
label: string;
|
|
13
|
-
error: string;
|
|
14
|
-
masked: boolean;
|
|
15
|
-
disabled: boolean;
|
|
16
|
-
value: string;
|
|
17
|
-
writeValue(val: string): Promise<void>;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Angular wrapper around the `<ks-otp-input>` Stencil custom element.
|
|
22
|
-
*
|
|
23
|
-
* Two-way binding is via `ControlValueAccessor` — use `[(ngModel)]` or
|
|
24
|
-
* `formControlName`. See `Buttons/chips/chips.ts` for the full rationale.
|
|
25
|
-
*
|
|
26
|
-
* For plain (non-forms) two-way use, bind explicitly instead:
|
|
27
|
-
* `[value]="v" (ksValueChange)="v = $event"`.
|
|
28
|
-
*
|
|
29
|
-
* `template: ''` — no `<slot>` in the wrapped Stencil render.
|
|
30
|
-
*/
|
|
31
|
-
@Component({
|
|
32
|
-
selector: 'ks-otp-input',
|
|
33
|
-
standalone: true,
|
|
34
|
-
template: '',
|
|
35
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
36
|
-
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: KsOtpInputComponent, multi: true }],
|
|
37
|
-
})
|
|
38
|
-
export class KsOtpInputComponent implements ControlValueAccessor {
|
|
39
|
-
private readonly el: KsOtpInputElement;
|
|
40
|
-
private onChange: (value: string) => void = () => {};
|
|
41
|
-
private onTouched: () => void = () => {};
|
|
42
|
-
|
|
43
|
-
/** Number of digits */
|
|
44
|
-
readonly length = input(6);
|
|
45
|
-
|
|
46
|
-
/** Input type: 'number' | 'text' */
|
|
47
|
-
readonly inputType = input<'number' | 'text'>('number');
|
|
48
|
-
|
|
49
|
-
/** Field label */
|
|
50
|
-
readonly label = input('');
|
|
51
|
-
|
|
52
|
-
/** Error message */
|
|
53
|
-
readonly error = input('');
|
|
54
|
-
|
|
55
|
-
/** Mask the input (like a password) */
|
|
56
|
-
readonly masked = input(false);
|
|
57
|
-
|
|
58
|
-
/** Disabled */
|
|
59
|
-
readonly disabled = input(false);
|
|
60
|
-
|
|
61
|
-
/** Initial/controlled value. Prefer `[(ngModel)]` / `formControlName`. */
|
|
62
|
-
readonly value = input('');
|
|
63
|
-
|
|
64
|
-
/** Emits whenever `value` changes. From the native `valueChange` event. */
|
|
65
|
-
readonly ksValueChange = output<string>();
|
|
66
|
-
|
|
67
|
-
/** Emits the full OTP string when all digits are filled. From the native `completed` event. */
|
|
68
|
-
readonly ksCompleted = output<string>();
|
|
69
|
-
|
|
70
|
-
constructor(ref: ElementRef<KsOtpInputElement>) {
|
|
71
|
-
this.el = ref.nativeElement;
|
|
72
|
-
|
|
73
|
-
effect(() => (this.el.length = this.length()));
|
|
74
|
-
effect(() => (this.el.inputType = this.inputType()));
|
|
75
|
-
effect(() => (this.el.label = this.label()));
|
|
76
|
-
effect(() => (this.el.error = this.error()));
|
|
77
|
-
effect(() => (this.el.masked = this.masked()));
|
|
78
|
-
effect(() => (this.el.disabled = this.disabled()));
|
|
79
|
-
effect(() => void this.el.writeValue(this.value()));
|
|
80
|
-
|
|
81
|
-
const onNativeValueChange = (event: Event): void => {
|
|
82
|
-
const detail = (event as CustomEvent<string>).detail;
|
|
83
|
-
this.ksValueChange.emit(detail);
|
|
84
|
-
this.onChange(detail);
|
|
85
|
-
this.onTouched();
|
|
86
|
-
};
|
|
87
|
-
const onNativeCompleted = (event: Event): void => {
|
|
88
|
-
this.ksCompleted.emit((event as CustomEvent<string>).detail);
|
|
89
|
-
};
|
|
90
|
-
this.el.addEventListener('valueChange', onNativeValueChange);
|
|
91
|
-
this.el.addEventListener('completed', onNativeCompleted);
|
|
92
|
-
inject(DestroyRef).onDestroy(() => {
|
|
93
|
-
this.el.removeEventListener('valueChange', onNativeValueChange);
|
|
94
|
-
this.el.removeEventListener('completed', onNativeCompleted);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
writeValue(value: string): void {
|
|
99
|
-
void this.el.writeValue(value ?? '');
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
registerOnChange(fn: (value: string) => void): void {
|
|
103
|
-
this.onChange = fn;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
registerOnTouched(fn: () => void): void {
|
|
107
|
-
this.onTouched = fn;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
setDisabledState(isDisabled: boolean): void {
|
|
111
|
-
this.el.disabled = isDisabled;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
// Side-effect import: registers the `ks-radio` tag — see
|
|
2
|
-
// `Buttons/button/button.ts` for the full explanation of this pattern.
|
|
3
|
-
import '@kraft.stitch/core/dist/components/ks-radio.js';
|
|
4
|
-
|
|
5
|
-
import { ChangeDetectionStrategy, Component, DestroyRef, ElementRef, effect, inject, input, output } from '@angular/core';
|
|
6
|
-
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
|
|
7
|
-
import type { KsBaseVariant, KsSize } from '@kraft.stitch/core';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Mirrors `KsRadioOption` exported by
|
|
11
|
-
* `core/src/components/Inputs/radio/radio.tsx`. Duplicated locally — see
|
|
12
|
-
* the note in `Buttons/button-group/button-group.ts` for why.
|
|
13
|
-
*/
|
|
14
|
-
export interface KsRadioOption {
|
|
15
|
-
value: string;
|
|
16
|
-
label?: string;
|
|
17
|
-
disabled?: boolean;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** DOM shape of the real `<ks-radio>` custom element, typed for the wrapper. */
|
|
21
|
-
type KsRadioElement = HTMLElement & {
|
|
22
|
-
options: KsRadioOption[];
|
|
23
|
-
label: string;
|
|
24
|
-
name: string;
|
|
25
|
-
variant: KsBaseVariant;
|
|
26
|
-
size: KsSize;
|
|
27
|
-
disabled: boolean;
|
|
28
|
-
value: string;
|
|
29
|
-
writeValue(val: string): Promise<void>;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Angular wrapper around the `<ks-radio>` Stencil custom element.
|
|
34
|
-
*
|
|
35
|
-
* Two-way binding is via `ControlValueAccessor` — use `[(ngModel)]` or
|
|
36
|
-
* `formControlName`. See `Buttons/chips/chips.ts` for the full rationale.
|
|
37
|
-
*
|
|
38
|
-
* For plain (non-forms) two-way use, bind explicitly instead:
|
|
39
|
-
* `[value]="v" (ksValueChange)="v = $event"`.
|
|
40
|
-
*
|
|
41
|
-
* `template: ''` — no `<slot>` in the wrapped Stencil render.
|
|
42
|
-
*/
|
|
43
|
-
@Component({
|
|
44
|
-
selector: 'ks-radio',
|
|
45
|
-
standalone: true,
|
|
46
|
-
template: '',
|
|
47
|
-
changeDetection: ChangeDetectionStrategy.OnPush,
|
|
48
|
-
providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: KsRadioComponent, multi: true }],
|
|
49
|
-
})
|
|
50
|
-
export class KsRadioComponent implements ControlValueAccessor {
|
|
51
|
-
private readonly el: KsRadioElement;
|
|
52
|
-
private onChange: (value: string) => void = () => {};
|
|
53
|
-
private onTouched: () => void = () => {};
|
|
54
|
-
|
|
55
|
-
/** List of options — the component renders a radio group */
|
|
56
|
-
readonly options = input<KsRadioOption[]>([]);
|
|
57
|
-
|
|
58
|
-
/** Label shown above the group */
|
|
59
|
-
readonly label = input('');
|
|
60
|
-
|
|
61
|
-
/** Name attribute shared across all radio inputs in the group */
|
|
62
|
-
readonly name = input('ks-radio');
|
|
63
|
-
|
|
64
|
-
/** Colour variant applied to the selected indicator */
|
|
65
|
-
readonly variant = input<KsBaseVariant>('brand');
|
|
66
|
-
|
|
67
|
-
/** Size variant — affects label text size */
|
|
68
|
-
readonly size = input<KsSize>('md');
|
|
69
|
-
|
|
70
|
-
/** Disabled state */
|
|
71
|
-
readonly disabled = input(false);
|
|
72
|
-
|
|
73
|
-
/** Initial/controlled selected value. Prefer `[(ngModel)]` / `formControlName`. */
|
|
74
|
-
readonly value = input('');
|
|
75
|
-
|
|
76
|
-
/** Emits the selected value on every change. From the native `valueChange` event. */
|
|
77
|
-
readonly ksValueChange = output<string>();
|
|
78
|
-
|
|
79
|
-
constructor(ref: ElementRef<KsRadioElement>) {
|
|
80
|
-
this.el = ref.nativeElement;
|
|
81
|
-
|
|
82
|
-
effect(() => (this.el.options = this.options()));
|
|
83
|
-
effect(() => (this.el.label = this.label()));
|
|
84
|
-
effect(() => (this.el.name = this.name()));
|
|
85
|
-
effect(() => (this.el.variant = this.variant()));
|
|
86
|
-
effect(() => (this.el.size = this.size()));
|
|
87
|
-
effect(() => (this.el.disabled = this.disabled()));
|
|
88
|
-
effect(() => void this.el.writeValue(this.value()));
|
|
89
|
-
|
|
90
|
-
const onNativeValueChange = (event: Event): void => {
|
|
91
|
-
const detail = (event as CustomEvent<string>).detail;
|
|
92
|
-
this.ksValueChange.emit(detail);
|
|
93
|
-
this.onChange(detail);
|
|
94
|
-
this.onTouched();
|
|
95
|
-
};
|
|
96
|
-
this.el.addEventListener('valueChange', onNativeValueChange);
|
|
97
|
-
inject(DestroyRef).onDestroy(() => this.el.removeEventListener('valueChange', onNativeValueChange));
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
writeValue(value: string): void {
|
|
101
|
-
void this.el.writeValue(value ?? '');
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
registerOnChange(fn: (value: string) => void): void {
|
|
105
|
-
this.onChange = fn;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
registerOnTouched(fn: () => void): void {
|
|
109
|
-
this.onTouched = fn;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
setDisabledState(isDisabled: boolean): void {
|
|
113
|
-
this.el.disabled = isDisabled;
|
|
114
|
-
}
|
|
115
|
-
}
|