@kraft.stitch/angular 0.0.1 → 0.0.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.
Files changed (53) hide show
  1. package/fesm2022/kraft.stitch-angular.mjs +2873 -0
  2. package/fesm2022/kraft.stitch-angular.mjs.map +1 -0
  3. package/package.json +17 -16
  4. package/types/kraft.stitch-angular.d.ts +2247 -0
  5. package/.github/workflows/npm-publish.yml +0 -33
  6. package/ng-package.json +0 -10
  7. package/src/lib/Buttons/button/button.ts +0 -152
  8. package/src/lib/Buttons/button-group/button-group.ts +0 -129
  9. package/src/lib/Buttons/chips/chips.ts +0 -131
  10. package/src/lib/Buttons/fab/fab.ts +0 -96
  11. package/src/lib/Calendars/datepicker/datepicker.ts +0 -105
  12. package/src/lib/Calendars/daterange/daterange.ts +0 -112
  13. package/src/lib/Calendars/timepicker/timepicker.ts +0 -117
  14. package/src/lib/Dropdowns/dropdown/dropdown.ts +0 -121
  15. package/src/lib/Dropdowns/listbox/listbox.ts +0 -116
  16. package/src/lib/Inputs/checkbox/checkbox.ts +0 -126
  17. package/src/lib/Inputs/colour-picker/colour-picker.ts +0 -101
  18. package/src/lib/Inputs/input/input.ts +0 -139
  19. package/src/lib/Inputs/otp-input/otp-input.ts +0 -113
  20. package/src/lib/Inputs/radio/radio.ts +0 -115
  21. package/src/lib/Inputs/rating/rating.ts +0 -104
  22. package/src/lib/Inputs/slider/slider.ts +0 -121
  23. package/src/lib/Inputs/switch/switch.ts +0 -100
  24. package/src/lib/Inputs/textarea/textarea.ts +0 -129
  25. package/src/lib/Inputs/theme-switch/theme-switch.ts +0 -61
  26. package/src/lib/Inputs/uploader/uploader.ts +0 -97
  27. package/src/lib/Layout/avatar/avatar.ts +0 -66
  28. package/src/lib/Layout/card/card.ts +0 -88
  29. package/src/lib/Layout/code-view/code-view.ts +0 -77
  30. package/src/lib/Layout/dialog/dialog.ts +0 -80
  31. package/src/lib/Layout/not-found/not-found.ts +0 -73
  32. package/src/lib/Layout/sidebar/sidebar.ts +0 -97
  33. package/src/lib/Layout/table/table.ts +0 -81
  34. package/src/lib/Layout/tooltip/tooltip.ts +0 -48
  35. package/src/lib/Navigation/accordion/accordion.ts +0 -80
  36. package/src/lib/Navigation/breadcrumb/breadcrumb.ts +0 -58
  37. package/src/lib/Navigation/carousel/carousel.ts +0 -70
  38. package/src/lib/Navigation/context-menu/context-menu.ts +0 -79
  39. package/src/lib/Navigation/nav-bar/nav-bar.ts +0 -72
  40. package/src/lib/Navigation/pagination/pagination.ts +0 -82
  41. package/src/lib/Navigation/stepper/stepper.ts +0 -77
  42. package/src/lib/Navigation/tab/tab.ts +0 -71
  43. package/src/lib/Navigation/toolbar/toolbar.ts +0 -60
  44. package/src/lib/Navigation/top-nav-bar/top-nav-bar.ts +0 -71
  45. package/src/lib/Navigation/tree-view/tree-view.ts +0 -75
  46. package/src/lib/Notification/badge/badge.ts +0 -55
  47. package/src/lib/Notification/loader/loader.ts +0 -41
  48. package/src/lib/Notification/message/message.ts +0 -60
  49. package/src/lib/Notification/progress/progress.ts +0 -65
  50. package/src/lib/Notification/spinner/spinner.ts +0 -50
  51. package/src/lib/Notification/toast/toast.ts +0 -56
  52. package/src/public-api.ts +0 -62
  53. package/tsconfig.json +0 -23
@@ -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
- }
@@ -1,104 +0,0 @@
1
- // Side-effect import: registers the `ks-rating` tag — see
2
- // `Buttons/button/button.ts` for the full explanation of this pattern.
3
- import '@kraft.stitch/core/dist/components/ks-rating.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 { KsBaseSize } from '@kraft.stitch/core';
8
-
9
- /** DOM shape of the real `<ks-rating>` custom element, typed for the wrapper. */
10
- type KsRatingElement = HTMLElement & {
11
- max: number;
12
- size: KsBaseSize;
13
- readOnly: boolean;
14
- showLabel: boolean;
15
- label: string;
16
- disabled: boolean;
17
- value: number;
18
- writeValue(val: number): Promise<void>;
19
- };
20
-
21
- /**
22
- * Angular wrapper around the `<ks-rating>` Stencil custom element.
23
- *
24
- * Two-way binding is via `ControlValueAccessor` — use `[(ngModel)]` or
25
- * `formControlName`. See `Buttons/chips/chips.ts` for the full rationale.
26
- *
27
- * For plain (non-forms) two-way use, bind explicitly instead:
28
- * `[value]="v" (ksValueChange)="v = $event"`.
29
- *
30
- * `template: ''` — no `<slot>` in the wrapped Stencil render.
31
- */
32
- @Component({
33
- selector: 'ks-rating',
34
- standalone: true,
35
- template: '',
36
- changeDetection: ChangeDetectionStrategy.OnPush,
37
- providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: KsRatingComponent, multi: true }],
38
- })
39
- export class KsRatingComponent implements ControlValueAccessor {
40
- private readonly el: KsRatingElement;
41
- private onChange: (value: number) => void = () => {};
42
- private onTouched: () => void = () => {};
43
-
44
- /** Total number of stars */
45
- readonly max = input(5);
46
-
47
- /** Size */
48
- readonly size = input<KsBaseSize>('md');
49
-
50
- /** Read-only / non-interactive */
51
- readonly readOnly = input(false);
52
-
53
- /** Show numeric label */
54
- readonly showLabel = input(false);
55
-
56
- /** Field label */
57
- readonly label = input('');
58
-
59
- /** Disabled */
60
- readonly disabled = input(false);
61
-
62
- /** Initial/controlled value. Prefer `[(ngModel)]` / `formControlName`. */
63
- readonly value = input(0);
64
-
65
- /** Emits the newly-picked rating. From the native `valueChange` event. */
66
- readonly ksValueChange = output<number>();
67
-
68
- constructor(ref: ElementRef<KsRatingElement>) {
69
- this.el = ref.nativeElement;
70
-
71
- effect(() => (this.el.max = this.max()));
72
- effect(() => (this.el.size = this.size()));
73
- effect(() => (this.el.readOnly = this.readOnly()));
74
- effect(() => (this.el.showLabel = this.showLabel()));
75
- effect(() => (this.el.label = this.label()));
76
- effect(() => (this.el.disabled = this.disabled()));
77
- effect(() => void this.el.writeValue(this.value()));
78
-
79
- const onNativeValueChange = (event: Event): void => {
80
- const detail = (event as CustomEvent<number>).detail;
81
- this.ksValueChange.emit(detail);
82
- this.onChange(detail);
83
- this.onTouched();
84
- };
85
- this.el.addEventListener('valueChange', onNativeValueChange);
86
- inject(DestroyRef).onDestroy(() => this.el.removeEventListener('valueChange', onNativeValueChange));
87
- }
88
-
89
- writeValue(value: number): void {
90
- void this.el.writeValue(value ?? 0);
91
- }
92
-
93
- registerOnChange(fn: (value: number) => void): void {
94
- this.onChange = fn;
95
- }
96
-
97
- registerOnTouched(fn: () => void): void {
98
- this.onTouched = fn;
99
- }
100
-
101
- setDisabledState(isDisabled: boolean): void {
102
- this.el.disabled = isDisabled;
103
- }
104
- }
@@ -1,121 +0,0 @@
1
- // Side-effect import: registers the `ks-slider` tag — see
2
- // `Buttons/button/button.ts` for the full explanation of this pattern.
3
- import '@kraft.stitch/core/dist/components/ks-slider.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-slider>` custom element, typed for the wrapper. */
9
- type KsSliderElement = HTMLElement & {
10
- min: number;
11
- max: number;
12
- step: number;
13
- showTooltip: boolean;
14
- showLabels: boolean;
15
- label: string;
16
- disabled: boolean;
17
- value: number;
18
- writeValue(val: number): Promise<void>;
19
- };
20
-
21
- /**
22
- * Angular wrapper around the `<ks-slider>` Stencil custom element.
23
- *
24
- * Two-way binding is via `ControlValueAccessor` — use `[(ngModel)]` or
25
- * `formControlName`. See `Buttons/chips/chips.ts` for the full rationale.
26
- * The native `ksBlur` event (already `ks`-prefixed by the Stencil author)
27
- * is re-exposed as `ksBlurred` — see `Inputs/input/input.ts` for why the
28
- * literal name can't be reused.
29
- *
30
- * For plain (non-forms) two-way use, bind explicitly instead:
31
- * `[value]="v" (ksValueChange)="v = $event"`.
32
- *
33
- * `template: ''` — no `<slot>` in the wrapped Stencil render.
34
- */
35
- @Component({
36
- selector: 'ks-slider',
37
- standalone: true,
38
- template: '',
39
- changeDetection: ChangeDetectionStrategy.OnPush,
40
- providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: KsSliderComponent, multi: true }],
41
- })
42
- export class KsSliderComponent implements ControlValueAccessor {
43
- private readonly el: KsSliderElement;
44
- private onChange: (value: number) => void = () => {};
45
- private onTouched: () => void = () => {};
46
-
47
- /** Minimum value */
48
- readonly min = input(0);
49
-
50
- /** Maximum value */
51
- readonly max = input(100);
52
-
53
- /** Step increment */
54
- readonly step = input(1);
55
-
56
- /** Show value tooltip */
57
- readonly showTooltip = input(true);
58
-
59
- /** Show min/max labels */
60
- readonly showLabels = input(false);
61
-
62
- /** Field label */
63
- readonly label = input('');
64
-
65
- /** Disabled state */
66
- readonly disabled = input(false);
67
-
68
- /** Initial/controlled value. Prefer `[(ngModel)]` / `formControlName`. */
69
- readonly value = input(0);
70
-
71
- /** Emits the newly-picked value. From the native `valueChange` event. */
72
- readonly ksValueChange = output<number>();
73
-
74
- /** Emitted on native blur. From the native `ksBlur` event. */
75
- readonly ksBlurred = output<void>();
76
-
77
- constructor(ref: ElementRef<KsSliderElement>) {
78
- this.el = ref.nativeElement;
79
-
80
- effect(() => (this.el.min = this.min()));
81
- effect(() => (this.el.max = this.max()));
82
- effect(() => (this.el.step = this.step()));
83
- effect(() => (this.el.showTooltip = this.showTooltip()));
84
- effect(() => (this.el.showLabels = this.showLabels()));
85
- effect(() => (this.el.label = this.label()));
86
- effect(() => (this.el.disabled = this.disabled()));
87
- effect(() => void this.el.writeValue(this.value()));
88
-
89
- const onNativeValueChange = (event: Event): void => {
90
- const detail = (event as CustomEvent<number>).detail;
91
- this.ksValueChange.emit(detail);
92
- this.onChange(detail);
93
- };
94
- const onNativeBlur = (): void => {
95
- this.ksBlurred.emit();
96
- this.onTouched();
97
- };
98
- this.el.addEventListener('valueChange', onNativeValueChange);
99
- this.el.addEventListener('ksBlur', onNativeBlur);
100
- inject(DestroyRef).onDestroy(() => {
101
- this.el.removeEventListener('valueChange', onNativeValueChange);
102
- this.el.removeEventListener('ksBlur', onNativeBlur);
103
- });
104
- }
105
-
106
- writeValue(value: number): void {
107
- void this.el.writeValue(value ?? 0);
108
- }
109
-
110
- registerOnChange(fn: (value: number) => void): void {
111
- this.onChange = fn;
112
- }
113
-
114
- registerOnTouched(fn: () => void): void {
115
- this.onTouched = fn;
116
- }
117
-
118
- setDisabledState(isDisabled: boolean): void {
119
- this.el.disabled = isDisabled;
120
- }
121
- }
@@ -1,100 +0,0 @@
1
- // Side-effect import: registers the `ks-switch` tag — see
2
- // `Buttons/button/button.ts` for the full explanation of this pattern.
3
- import '@kraft.stitch/core/dist/components/ks-switch.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 } from '@kraft.stitch/core';
8
-
9
- /** DOM shape of the real `<ks-switch>` custom element, typed for the wrapper. */
10
- type KsSwitchElement = HTMLElement & {
11
- label: string;
12
- variant: KsBaseVariant;
13
- disabled: boolean;
14
- checked: boolean;
15
- labelPosition: 'left' | 'right';
16
- formDisabled: boolean;
17
- setDisabledState(isDisabled: boolean): Promise<void>;
18
- };
19
-
20
- /**
21
- * Angular wrapper around the `<ks-switch>` Stencil custom element.
22
- *
23
- * Two-way binding is via `ControlValueAccessor` — use `[(ngModel)]` or
24
- * `formControlName`. Unlike most other form-control wrappers here,
25
- * `<ks-switch>` has no `@Method() writeValue()`, so `writeValue` below
26
- * sets `el.checked` directly; it DOES expose a real
27
- * `@Method() setDisabledState()` (mirroring CVA exactly), which
28
- * `setDisabledState` below delegates to instead of setting a plain prop.
29
- *
30
- * For plain (non-forms) two-way use, bind explicitly instead:
31
- * `[checked]="c" (ksCheckedChange)="c = $event"`.
32
- *
33
- * `template: ''` — no `<slot>` in the wrapped Stencil render.
34
- */
35
- @Component({
36
- selector: 'ks-switch',
37
- standalone: true,
38
- template: '',
39
- changeDetection: ChangeDetectionStrategy.OnPush,
40
- providers: [{ provide: NG_VALUE_ACCESSOR, useExisting: KsSwitchComponent, multi: true }],
41
- })
42
- export class KsSwitchComponent implements ControlValueAccessor {
43
- private readonly el: KsSwitchElement;
44
- private onChange: (value: boolean) => void = () => {};
45
- private onTouched: () => void = () => {};
46
-
47
- /** Label text */
48
- readonly label = input('');
49
-
50
- /** Colour variant */
51
- readonly variant = input<KsBaseVariant>('brand');
52
-
53
- /** Disabled */
54
- readonly disabled = input(false);
55
-
56
- /** Initial/controlled checked value. Prefer `[(ngModel)]` / `formControlName`. */
57
- readonly checked = input(false);
58
-
59
- /** Label position relative to the switch track */
60
- readonly labelPosition = input<'left' | 'right'>('left');
61
-
62
- /** Emits whenever `checked` changes. From the native `checkedChange` event. */
63
- readonly ksCheckedChange = output<boolean>();
64
-
65
- constructor(ref: ElementRef<KsSwitchElement>) {
66
- this.el = ref.nativeElement;
67
-
68
- effect(() => (this.el.label = this.label()));
69
- effect(() => (this.el.variant = this.variant()));
70
- effect(() => (this.el.disabled = this.disabled()));
71
- effect(() => (this.el.checked = this.checked()));
72
- effect(() => (this.el.labelPosition = this.labelPosition()));
73
-
74
- const onNativeCheckedChange = (event: Event): void => {
75
- const detail = (event as CustomEvent<boolean>).detail;
76
- this.ksCheckedChange.emit(detail);
77
- this.onChange(detail);
78
- this.onTouched();
79
- };
80
- this.el.addEventListener('checkedChange', onNativeCheckedChange);
81
- inject(DestroyRef).onDestroy(() => this.el.removeEventListener('checkedChange', onNativeCheckedChange));
82
- }
83
-
84
- writeValue(value: boolean): void {
85
- this.el.checked = value ?? false;
86
- }
87
-
88
- registerOnChange(fn: (value: boolean) => void): void {
89
- this.onChange = fn;
90
- }
91
-
92
- registerOnTouched(fn: () => void): void {
93
- this.onTouched = fn;
94
- }
95
-
96
- /** Delegates to `<ks-switch>`'s own `@Method() setDisabledState()`. */
97
- setDisabledState(isDisabled: boolean): void {
98
- void this.el.setDisabledState(isDisabled);
99
- }
100
- }