@tekus/design-system 5.39.0 → 5.40.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.
@@ -0,0 +1,286 @@
1
+ import * as _angular_core from '@angular/core';
2
+ import { OnInit } from '@angular/core';
3
+ import { ControlValueAccessor, NgControl, FormControl } from '@angular/forms';
4
+
5
+ /**
6
+ * @component CounterComponent
7
+ * @description
8
+ * Compact control for selecting an integer value within a bounded range using
9
+ * icon-only decrement and increment buttons, with an editable value in the center.
10
+ * It has its own distinct visual identity so it reads as a standalone element rather
11
+ * than blending into the standard input family.
12
+ *
13
+ * This component supports:
14
+ * - `value`: the current integer. Never null; always rendered clamped into `[min, max]`.
15
+ * - `min` / `max`: the inclusive bounds. Buttons **disable** at a limit, never hide,
16
+ * and the value never wraps around.
17
+ * - `step`: the amount added or subtracted per action.
18
+ * - `disabled` / `readonly`: `disabled` blocks interaction and applies a distinct
19
+ * treatment to the value; `readonly` looks normal but cannot change.
20
+ * - Holding a button auto-repeats the step.
21
+ *
22
+ * It implements `ControlValueAccessor`, so it works with `[(ngModel)]` and reactive forms.
23
+ *
24
+ * @usage
25
+ * ### Basic Usage
26
+ * ```html
27
+ * <tk-counter [(ngModel)]="quantity" />
28
+ * <tk-counter [min]="1" [max]="10" [step]="2" [(value)]="servings" />
29
+ * <tk-counter [control]="quantityControl" (valueChange)="onQuantityChange($event)" />
30
+ * ```
31
+ */
32
+ declare class CounterComponent implements ControlValueAccessor, OnInit {
33
+ readonly ngControl: NgControl | null;
34
+ private readonly destroyRef;
35
+ constructor();
36
+ /**
37
+ * @property {ModelSignal<number>} value
38
+ * @description
39
+ * Current integer value. Never null; always rendered clamped into `[min, max]`.
40
+ * Supports two-way binding via `[(value)]` and emits `(valueChange)` after clamping.
41
+ *
42
+ * @default `0`
43
+ */
44
+ value: _angular_core.ModelSignal<number>;
45
+ /**
46
+ * @property {InputSignal<number>} min
47
+ * @description
48
+ * Lower bound, inclusive. The decrement button disables at this value.
49
+ *
50
+ * @default `0`
51
+ */
52
+ min: _angular_core.InputSignal<number>;
53
+ /**
54
+ * @property {InputSignal<number>} max
55
+ * @description
56
+ * Upper bound, inclusive. The increment button disables at this value.
57
+ *
58
+ * @default `99`
59
+ */
60
+ max: _angular_core.InputSignal<number>;
61
+ /**
62
+ * @property {InputSignal<number>} step
63
+ * @description
64
+ * Amount added or subtracted per action. `PageUp` / `PageDown` apply ten times this.
65
+ *
66
+ * @default `1`
67
+ */
68
+ step: _angular_core.InputSignal<number>;
69
+ /**
70
+ * @property {ModelSignal<boolean>} disabled
71
+ * @description
72
+ * Disables all interaction and applies the distinct disabled treatment to the value.
73
+ *
74
+ * @default `false`
75
+ */
76
+ disabled: _angular_core.ModelSignal<boolean>;
77
+ /**
78
+ * @property {InputSignal<boolean>} readonly
79
+ * @description
80
+ * The value is shown but cannot change. Visually normal, unlike `disabled`.
81
+ *
82
+ * @default `false`
83
+ */
84
+ readonly: _angular_core.InputSignal<boolean>;
85
+ /**
86
+ * @property {InputSignal<FormControl | undefined>} control
87
+ * @description
88
+ * External FormControl used to read/set the value. Optional: when omitted the
89
+ * counter keeps its value in the `value` model alone and creates no control.
90
+ * Not needed when using `formControlName` or `[(ngModel)]`.
91
+ *
92
+ * @default `undefined`
93
+ */
94
+ control: _angular_core.InputSignal<FormControl<any> | undefined>;
95
+ /**
96
+ * @property {InputSignal<string>} decreaseLabel
97
+ * @description
98
+ * Accessible label for the decrement button, which carries no visible text.
99
+ *
100
+ * @default `'Decrease'`
101
+ */
102
+ decreaseLabel: _angular_core.InputSignal<string>;
103
+ /**
104
+ * @property {InputSignal<string>} increaseLabel
105
+ * @description
106
+ * Accessible label for the increment button, which carries no visible text.
107
+ *
108
+ * @default `'Increase'`
109
+ */
110
+ increaseLabel: _angular_core.InputSignal<string>;
111
+ /**
112
+ * @property {InputSignal<string>} ariaLabel
113
+ * @description
114
+ * Accessible name for the value field. The counter renders no visible label, so
115
+ * either this or `ariaLabelledby` must be set unless surrounding text already
116
+ * names the control — otherwise the spinbutton is announced unnamed.
117
+ */
118
+ ariaLabel: _angular_core.InputSignal<string>;
119
+ /**
120
+ * @property {InputSignal<string>} ariaLabelledby
121
+ * @description
122
+ * Id of an existing element that names the value field. Use instead of
123
+ * `ariaLabel` when a visible label already exists elsewhere in the view.
124
+ */
125
+ ariaLabelledby: _angular_core.InputSignal<string>;
126
+ /** The value field, used to resync its text after the model clamps a typed entry. */
127
+ private readonly valueInput;
128
+ /**
129
+ * The effective upper bound. Guards against a `max` lower than `min` so the range
130
+ * is never inverted and `clamp` stays well defined.
131
+ */
132
+ readonly safeMax: _angular_core.Signal<number>;
133
+ /**
134
+ * The effective step. Guards against `0`, a negative, or a non-finite `step`, any
135
+ * of which would make stepping a no-op — and would let a held button repeat forever
136
+ * without ever reaching a limit.
137
+ */
138
+ readonly effectiveStep: _angular_core.Signal<number>;
139
+ /** The amount applied by `PageUp` / `PageDown`: ten times `step`. */
140
+ readonly pageStep: _angular_core.Signal<number>;
141
+ /**
142
+ * Character budget for the value field: the widest number the range can produce,
143
+ * never fewer than `MIN_VALUE_WIDTH_CH`.
144
+ *
145
+ * Derived from the **range**, not from the current value, so that every counter
146
+ * sharing a range renders exactly the same width. That is what keeps the buttons
147
+ * aligned down a column when one row shows `1` and the next shows `44` — sizing to
148
+ * the current value instead would make each row a different width.
149
+ */
150
+ readonly valueWidthCh: _angular_core.Signal<number>;
151
+ /**
152
+ * The rendered value: always a valid integer inside `[min, safeMax]`, even when a
153
+ * parent binds something out of range. Deliberately a `computed` rather than an
154
+ * `effect` writing back into `value`, which would fight a two-way `[(value)]`
155
+ * binding; the first interaction commits the clamped number and converges the two.
156
+ */
157
+ readonly displayValue: _angular_core.Signal<number>;
158
+ /** Whether the value sits at the lower bound, which disables the decrement button. */
159
+ readonly atMin: _angular_core.Signal<boolean>;
160
+ /** Whether the value sits at the upper bound, which disables the increment button. */
161
+ readonly atMax: _angular_core.Signal<boolean>;
162
+ /** Computed host class: the BEM block plus the disabled and readonly modifiers. */
163
+ readonly hostClass: _angular_core.Signal<string>;
164
+ get effectiveControl(): FormControl | null;
165
+ onChange: (value: number) => void;
166
+ onTouched: () => void;
167
+ private isWriting;
168
+ private holdTimeout;
169
+ private holdInterval;
170
+ ngOnInit(): void;
171
+ /**
172
+ * @method writeValue
173
+ * @description
174
+ * Writes a new value to the element, clamped into range.
175
+ * @param value The new value.
176
+ */
177
+ writeValue(value: number | null): void;
178
+ /**
179
+ * @method registerOnChange
180
+ * @description
181
+ * Registers a callback called when the value changes in the UI.
182
+ * @param fn The callback function.
183
+ */
184
+ registerOnChange(fn: (value: number) => void): void;
185
+ /**
186
+ * @method registerOnTouched
187
+ * @description
188
+ * Registers a callback called by the forms API to update the form model on blur.
189
+ * @param fn The callback function.
190
+ */
191
+ registerOnTouched(fn: () => void): void;
192
+ /**
193
+ * @method setDisabledState
194
+ * @description
195
+ * Called by the forms API when the control status changes to or from 'DISABLED'.
196
+ * @param isDisabled The disabled status to set on the element.
197
+ */
198
+ setDisabledState(isDisabled: boolean): void;
199
+ /**
200
+ * @method stepBy
201
+ * @description
202
+ * Moves the value by `step` in the given direction, clamped into range.
203
+ * @param direction `1` to increment, `-1` to decrement.
204
+ */
205
+ stepBy(direction: 1 | -1): void;
206
+ /**
207
+ * @method startHold
208
+ * @description
209
+ * Steps once immediately, then begins auto-repeating after `HOLD_DELAY_MS`.
210
+ * No-ops when the counter cannot change or is already at that limit.
211
+ * @param direction `1` to increment, `-1` to decrement.
212
+ */
213
+ startHold(direction: 1 | -1): void;
214
+ /**
215
+ * @method stopHold
216
+ * @description
217
+ * Cancels any pending or running auto-repeat. Safe to call when none is active.
218
+ */
219
+ stopHold(): void;
220
+ /**
221
+ * @method onButtonKeydown
222
+ * @description
223
+ * Handles keyboard activation of a stepper button. `Enter` and `Space` are handled
224
+ * here — and their default prevented — so the button steps exactly once per press
225
+ * and relies on native key auto-repeat while held.
226
+ * @param event The keyboard event.
227
+ * @param direction `1` to increment, `-1` to decrement.
228
+ */
229
+ onButtonKeydown(event: KeyboardEvent, direction: 1 | -1): void;
230
+ /**
231
+ * @method onValueKeydown
232
+ * @description
233
+ * Handles the spinbutton keyboard contract: arrows step by `step`, Home / End jump
234
+ * to the bounds, PageUp / PageDown apply a larger step, and Enter commits the
235
+ * currently typed text.
236
+ * @param event The keyboard event.
237
+ */
238
+ onValueKeydown(event: KeyboardEvent): void;
239
+ /**
240
+ * @method onInput
241
+ * @description
242
+ * Rejects non-numeric characters as they are typed, without clamping — clamping
243
+ * mid-keystroke would fight the user on the way to a valid number (typing `1`
244
+ * toward `12` when `min` is `5`). The value is committed on blur or Enter.
245
+ * @param event The input event.
246
+ */
247
+ onInput(event: Event): void;
248
+ /**
249
+ * @method onValueBlur
250
+ * @description
251
+ * Commits the typed text, marks the control touched, and resyncs the field so its
252
+ * text always matches the clamped value.
253
+ */
254
+ onValueBlur(): void;
255
+ /**
256
+ * Keeps digits only, plus a single leading `-` when the range includes negatives.
257
+ * Applied to whatever lands in the field, so it also covers paste and drop.
258
+ */
259
+ private sanitize;
260
+ /** Whether the counter currently accepts changes. */
261
+ private canInteract;
262
+ /** Whether stepping in `direction` would move past an already-reached bound. */
263
+ private isAtLimit;
264
+ /**
265
+ * Rounds and clamps an arbitrary value into `[min, safeMax]`. Non-finite input
266
+ * (an empty or unparseable field) falls back to `min`, so the value is never empty.
267
+ */
268
+ private clamp;
269
+ /**
270
+ * The single write path: clamps, updates the model, notifies the forms API, and
271
+ * emits `(valueChange)` — so clamping and emission happen in exactly one place.
272
+ */
273
+ private commit;
274
+ /** Parses the field's current text, commits it, and resyncs the displayed text. */
275
+ private commitTypedValue;
276
+ /**
277
+ * Rewrites the field's text from `displayValue`. Required because the `[value]`
278
+ * binding will not update the DOM when the model is unchanged — typing `150` with
279
+ * `max` `99` while the value is already `99` leaves stale text behind otherwise.
280
+ */
281
+ private syncInputText;
282
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<CounterComponent, never>;
283
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<CounterComponent, "tk-counter", never, { "value": { "alias": "value"; "required": false; "isSignal": true; }; "min": { "alias": "min"; "required": false; "isSignal": true; }; "max": { "alias": "max"; "required": false; "isSignal": true; }; "step": { "alias": "step"; "required": false; "isSignal": true; }; "disabled": { "alias": "disabled"; "required": false; "isSignal": true; }; "readonly": { "alias": "readonly"; "required": false; "isSignal": true; }; "control": { "alias": "control"; "required": false; "isSignal": true; }; "decreaseLabel": { "alias": "decreaseLabel"; "required": false; "isSignal": true; }; "increaseLabel": { "alias": "increaseLabel"; "required": false; "isSignal": true; }; "ariaLabel": { "alias": "ariaLabel"; "required": false; "isSignal": true; }; "ariaLabelledby": { "alias": "ariaLabelledby"; "required": false; "isSignal": true; }; }, { "value": "valueChange"; "disabled": "disabledChange"; }, never, never, true, never>;
284
+ }
285
+
286
+ export { CounterComponent };
@@ -4,7 +4,7 @@ import { TagSeverity } from '@tekus/design-system/components/tag';
4
4
  import { SortEvent } from 'primeng/api';
5
5
  import { TkAction } from '@tekus/design-system/components/action-group';
6
6
 
7
- type TableColumnType = 'text' | 'tag' | 'actions' | 'selection' | 'checkbox' | 'action-group' | 'connection-status' | 'image';
7
+ type TableColumnType = 'text' | 'tag' | 'actions' | 'selection' | 'checkbox' | 'action-group' | 'connection-status' | 'image' | 'counter';
8
8
  interface TableColumn<T = unknown> {
9
9
  field?: string;
10
10
  header: string;
@@ -32,6 +32,19 @@ interface TableColumn<T = unknown> {
32
32
  imageHeight?: string;
33
33
  imageFallback?: string;
34
34
  imageAction?: (row: T) => void;
35
+ counterMin?: number;
36
+ counterMax?: number;
37
+ counterStep?: number;
38
+ counterDisabled?: boolean | ((row: T) => boolean);
39
+ /** Accessible name for the cell's counter. Falls back to the column `header`. */
40
+ counterAriaLabel?: (row: T) => string;
41
+ counterDecreaseLabel?: string;
42
+ counterIncreaseLabel?: string;
43
+ /**
44
+ * Called after the cell has written the clamped value into `row[field]`.
45
+ * The hook to persist a quantity change.
46
+ */
47
+ counterChange?: (row: T, value: number) => void;
35
48
  }
36
49
 
37
50
  declare class TableComponent<T = unknown> {
@@ -215,6 +228,27 @@ declare class TableComponent<T = unknown> {
215
228
  * @param row {T} - The data row associated with the clicked image.
216
229
  */
217
230
  handleImageClick(event: Event, col: TableColumn<T>, row: T): void;
231
+ /**
232
+ * @method isCounterDisabled
233
+ * @description
234
+ * Resolves a counter column's `counterDisabled`, which may be a boolean or a
235
+ * per-row predicate — the same shape `getActionGroup` already accepts.
236
+ * @param col {TableColumn<T>} - The counter column definition.
237
+ * @param row {T} - The data row being rendered.
238
+ * @returns Whether this row's counter should be disabled.
239
+ */
240
+ isCounterDisabled(col: TableColumn<T>, row: T): boolean;
241
+ /**
242
+ * @method onCounterChange
243
+ * @description
244
+ * Writes a counter cell's new value into the row and notifies the consumer.
245
+ * The value arrives already clamped into the column's range by `tk-counter`.
246
+ * Mutating the row in place matches how the `checkbox` column type behaves.
247
+ * @param col {TableColumn<T>} - The counter column definition.
248
+ * @param row {T} - The data row being edited.
249
+ * @param value {number} - The new, clamped value.
250
+ */
251
+ onCounterChange(col: TableColumn<T>, row: T, value: number): void;
218
252
  /**
219
253
  * @method onImageError
220
254
  * @description