@makigamestudio/ui-core 0.1.7 → 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.
@@ -1,5 +1,5 @@
1
1
  import * as _angular_core from '@angular/core';
2
- import { ElementRef } from '@angular/core';
2
+ import { ElementRef, Signal } from '@angular/core';
3
3
 
4
4
  /**
5
5
  * TestInterface - Example interface exported from ui-core library.
@@ -50,6 +50,224 @@ declare class TestClass implements TestInterface {
50
50
  toJSON(): TestInterface;
51
51
  }
52
52
 
53
+ /**
54
+ * @file Action button configuration interface
55
+ * @description Configuration options for styling and behavior of action buttons
56
+ */
57
+ /**
58
+ * Configuration interface for action button styling and behavior.
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const config: ActionButtonConfig = {
63
+ * fill: 'outline',
64
+ * size: 'small',
65
+ * color: 'primary',
66
+ * shape: 'round'
67
+ * };
68
+ * ```
69
+ */
70
+ interface ActionButtonConfig {
71
+ /**
72
+ * The fill style of the button.
73
+ * - `'clear'`: Transparent background
74
+ * - `'outline'`: Transparent background with border
75
+ * - `'solid'`: Filled background (default Ionic behavior)
76
+ * - `'default'`: Uses Ionic default
77
+ */
78
+ readonly fill?: 'clear' | 'outline' | 'solid' | 'default';
79
+ /**
80
+ * The size of the button.
81
+ * - `'small'`: Smaller button
82
+ * - `'default'`: Standard size
83
+ * - `'large'`: Larger button
84
+ */
85
+ readonly size?: 'small' | 'default' | 'large';
86
+ /**
87
+ * The color of the button. Can be an Ionic color name
88
+ * (primary, secondary, tertiary, success, warning, danger, light, medium, dark)
89
+ * or a custom color defined in your theme.
90
+ */
91
+ readonly color?: string;
92
+ /**
93
+ * The shape of the button.
94
+ * - `'round'`: Fully rounded corners
95
+ */
96
+ readonly shape?: 'round';
97
+ /**
98
+ * How the button should expand to fill its container.
99
+ * - `'block'`: Full width with rounded corners
100
+ * - `'full'`: Full width with square corners
101
+ */
102
+ readonly expand?: 'block' | 'full';
103
+ /**
104
+ * Whether the button is disabled.
105
+ */
106
+ readonly disabled?: boolean;
107
+ /**
108
+ * Whether to use a stronger font weight.
109
+ */
110
+ readonly strong?: boolean;
111
+ /**
112
+ * Whether to hide the dropdown chevron icon for dropdown type buttons.
113
+ * Only applies when `type` is `ActionButtonType.Dropdown`.
114
+ * @default false
115
+ */
116
+ readonly hideDropdownIcon?: boolean;
117
+ }
118
+
119
+ /**
120
+ * @file Action button type enumeration
121
+ * @description Defines the display types for action buttons
122
+ */
123
+ /**
124
+ * Enumeration of action button display types.
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const button: ActionButton = {
129
+ * id: 'save-btn',
130
+ * label: 'Save',
131
+ * type: ActionButtonType.Default,
132
+ * handler: () => console.log('Saved!')
133
+ * };
134
+ * ```
135
+ */
136
+ declare enum ActionButtonType {
137
+ /**
138
+ * Standard button with label and optional icon.
139
+ */
140
+ Default = "default",
141
+ /**
142
+ * Button displaying only an icon, no label.
143
+ */
144
+ IconOnly = "icon-only",
145
+ /**
146
+ * Button that opens a dropdown popover with child actions.
147
+ */
148
+ Dropdown = "dropdown"
149
+ }
150
+
151
+ /**
152
+ * @file Action button interface
153
+ * @description Main interface for configuring action buttons
154
+ */
155
+
156
+ /**
157
+ * Interface representing an action button configuration.
158
+ *
159
+ * @typeParam T - The type of data passed to the handler function. Defaults to `void`.
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // Simple button
164
+ * const saveButton: ActionButton = {
165
+ * id: 'save',
166
+ * label: 'Save',
167
+ * icon: 'saveOutline',
168
+ * type: ActionButtonType.Default,
169
+ * handler: () => console.log('Saved!')
170
+ * };
171
+ *
172
+ * // Async button with auto-loading
173
+ * const submitButton: ActionButton = {
174
+ * id: 'submit',
175
+ * label: 'Submit',
176
+ * type: ActionButtonType.Default,
177
+ * handler: async () => {
178
+ * await api.submit();
179
+ * }
180
+ * };
181
+ *
182
+ * // Dropdown button with children
183
+ * const menuButton: ActionButton = {
184
+ * id: 'menu',
185
+ * label: 'Actions',
186
+ * type: ActionButtonType.Dropdown,
187
+ * handler: () => {}, // Not called for dropdowns
188
+ * children: [
189
+ * { id: 'edit', label: 'Edit', type: ActionButtonType.Default, handler: () => edit() },
190
+ * { id: 'delete', label: 'Delete', type: ActionButtonType.Default, handler: () => delete() }
191
+ * ]
192
+ * };
193
+ *
194
+ * // Button with generic data parameter
195
+ * const itemButton: ActionButton<Item> = {
196
+ * id: 'select',
197
+ * label: 'Select',
198
+ * type: ActionButtonType.Default,
199
+ * handler: (item) => selectItem(item)
200
+ * };
201
+ * ```
202
+ */
203
+ interface ActionButton<T = void> {
204
+ /**
205
+ * Unique identifier for the button.
206
+ */
207
+ readonly id: string;
208
+ /**
209
+ * Icon name to display in the button.
210
+ * Should be an Ionicon name registered with `addIcons()`.
211
+ */
212
+ readonly icon?: string;
213
+ /**
214
+ * Text label to display in the button.
215
+ * Required for `Default` type, optional for `IconOnly` and `Dropdown`.
216
+ */
217
+ readonly label?: string;
218
+ /**
219
+ * Handler function called when the button is clicked.
220
+ * Can be synchronous or asynchronous. For async handlers,
221
+ * the component will automatically manage the loading state.
222
+ *
223
+ * @param data - Optional data parameter of type T
224
+ * @returns void or Promise<void>
225
+ */
226
+ readonly handler: (data?: T) => void | Promise<void>;
227
+ /**
228
+ * External loading state. When true, the button shows a loading spinner.
229
+ * The component also manages an internal loading state for async handlers.
230
+ * The button shows loading if either this or the internal state is true.
231
+ */
232
+ readonly loading?: boolean;
233
+ /**
234
+ * Controls whether to display the loading spinner when the button is in a loading state.
235
+ * Defaults to `true` if not specified.
236
+ *
237
+ * When `false`, the button will still be disabled during loading, but the spinner will not be shown.
238
+ * This is useful when you want to indicate loading state without replacing the button's visual content.
239
+ *
240
+ * For dropdown buttons, this also controls loading state propagation from children:
241
+ * - If both parent and child have `showLoadingSpinner !== false`, the parent will show a spinner when ANY child is loading.
242
+ * - The parent dropdown remains clickable even when showing inherited child loading state.
243
+ *
244
+ * @default true
245
+ */
246
+ readonly showLoadingSpinner?: boolean;
247
+ /**
248
+ * Child action buttons for dropdown menus.
249
+ * Only used when `type` is `ActionButtonType.Dropdown`.
250
+ */
251
+ readonly children?: readonly ActionButton<T>[];
252
+ /**
253
+ * The display type of the button.
254
+ */
255
+ readonly type: ActionButtonType;
256
+ /**
257
+ * Optional configuration for button styling.
258
+ */
259
+ readonly config?: ActionButtonConfig;
260
+ /**
261
+ * Accessible label for screen readers.
262
+ * Recommended for `IconOnly` buttons.
263
+ */
264
+ readonly ariaLabel?: string;
265
+ /**
266
+ * Tooltip text shown on hover.
267
+ */
268
+ readonly tooltip?: string;
269
+ }
270
+
53
271
  /**
54
272
  * TestService - Example service using Angular Signals for reactive state management.
55
273
  * Provided in root, demonstrating singleton service pattern with signal-based state.
@@ -140,5 +358,249 @@ declare class TestCardComponent {
140
358
  static ɵcmp: _angular_core.ɵɵComponentDeclaration<TestCardComponent, "maki-test-card", never, { "item": { "alias": "item"; "required": true; "isSignal": true; }; "showActions": { "alias": "showActions"; "required": false; "isSignal": true; }; }, { "itemClick": "itemClick"; "editClick": "editClick"; "deleteClick": "deleteClick"; }, never, never, true, never>;
141
359
  }
142
360
 
143
- export { TestCardComponent, TestClass, TestService };
144
- export type { TestInterface };
361
+ /**
362
+ * Component that renders a list of action buttons for use in popovers/dropdowns.
363
+ *
364
+ * This component is designed to be used as the content of an `ion-popover`
365
+ * created via `PopoverController`. When a button is selected, it dismisses
366
+ * the popover and returns the selected button.
367
+ *
368
+ * @example
369
+ * ```typescript
370
+ * // Used internally by maki-button for dropdowns
371
+ * // Can also be used standalone:
372
+ * const popover = await popoverCtrl.create({
373
+ * component: ActionButtonListComponent,
374
+ * componentProps: { buttons: myButtons },
375
+ * event: clickEvent
376
+ * });
377
+ * await popover.present();
378
+ *
379
+ * const { data } = await popover.onDidDismiss();
380
+ * if (data) {
381
+ * data.handler();
382
+ * }
383
+ * ```
384
+ *
385
+ * @usageNotes
386
+ * ### Inputs
387
+ * - `buttons` (required): Array of `ActionButton` objects to display
388
+ *
389
+ * ### Outputs
390
+ * - `buttonSelect`: Emits the selected `ActionButton` when clicked
391
+ */
392
+ declare class ActionButtonListComponent {
393
+ /**
394
+ * Reference to ActionButtonType.Dropdown for template comparison.
395
+ * @internal
396
+ */
397
+ protected readonly dropdownType = ActionButtonType.Dropdown;
398
+ /**
399
+ * Popover controller for dismissing the popover when an item is selected.
400
+ */
401
+ private readonly popoverCtrl;
402
+ /**
403
+ * Internal signal to store buttons passed via componentProps.
404
+ * PopoverController.create() sets properties directly, bypassing signal inputs.
405
+ */
406
+ private readonly _buttonsFromProps;
407
+ /**
408
+ * Internal signal to store the Set of currently loading child button IDs.
409
+ */
410
+ private readonly _loadingChildIdsFromProps;
411
+ /**
412
+ * The list of action buttons to display (when used via template binding).
413
+ */
414
+ readonly buttons: _angular_core.InputSignal<readonly ActionButton<void>[]>;
415
+ /**
416
+ * Computed button list that works with both signal input and componentProps.
417
+ * PopoverController passes buttons as a direct property, not through Angular's input system.
418
+ */
419
+ protected readonly buttonList: () => readonly ActionButton[];
420
+ /**
421
+ * Setter to capture buttons passed via PopoverController.create({ componentProps }).
422
+ * This is called when Ionic sets the property directly on the component instance.
423
+ */
424
+ set buttonsFromPopover(value: readonly ActionButton[]);
425
+ /**
426
+ * Setter to capture loading child IDs signal passed via PopoverController.create({ componentProps }).
427
+ */
428
+ set loadingChildIds(value: Signal<ReadonlySet<string>>);
429
+ /**
430
+ * Checks if a specific button is currently loading.
431
+ */
432
+ protected isButtonLoading(button: ActionButton): boolean;
433
+ /**
434
+ * Emits when a button is selected from the list.
435
+ */
436
+ readonly buttonSelect: _angular_core.OutputEmitterRef<ActionButton<void>>;
437
+ constructor();
438
+ /**
439
+ * Handles click on a button item.
440
+ * Emits the selected button and dismisses the popover.
441
+ *
442
+ * @param button - The clicked action button
443
+ */
444
+ protected onButtonClick(button: ActionButton): void;
445
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<ActionButtonListComponent, never>;
446
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<ActionButtonListComponent, "maki-action-button-list", never, { "buttons": { "alias": "buttons"; "required": false; "isSignal": true; }; }, { "buttonSelect": "buttonSelect"; }, never, never, true, never>;
447
+ }
448
+
449
+ /**
450
+ * A configurable button component that renders an `ion-button` based on
451
+ * an `ActionButton` configuration object.
452
+ *
453
+ * Features:
454
+ * - Three display types: Default (label + icon), IconOnly, and Dropdown
455
+ * - Automatic loading state management for async handlers
456
+ * - Dropdown support via PopoverController with child actions
457
+ * - Full Ionic button styling configuration (fill, size, color, shape, expand)
458
+ * - Automatic chevron icon for dropdown buttons
459
+ *
460
+ * @example
461
+ * ```html
462
+ * <!-- Simple button -->
463
+ * <maki-button [button]="saveButton" />
464
+ *
465
+ * <!-- Icon-only button -->
466
+ * <maki-button [button]="iconButton" />
467
+ *
468
+ * <!-- Dropdown button -->
469
+ * <maki-button [button]="menuButton" />
470
+ * ```
471
+ *
472
+ * @example
473
+ * ```typescript
474
+ * // In your component
475
+ * saveButton: ActionButton = {
476
+ * id: 'save',
477
+ * label: 'Save',
478
+ * icon: 'saveOutline',
479
+ * type: ActionButtonType.Default,
480
+ * config: { fill: 'solid', color: 'primary' },
481
+ * handler: async () => {
482
+ * await this.saveData();
483
+ * }
484
+ * };
485
+ *
486
+ * menuButton: ActionButton = {
487
+ * id: 'menu',
488
+ * label: 'Actions',
489
+ * type: ActionButtonType.Dropdown,
490
+ * handler: () => {},
491
+ * children: [
492
+ * { id: 'edit', label: 'Edit', icon: 'createOutline', type: ActionButtonType.Default, handler: () => this.edit() },
493
+ * { id: 'delete', label: 'Delete', icon: 'trashOutline', type: ActionButtonType.Default, handler: () => this.delete() }
494
+ * ]
495
+ * };
496
+ * ```
497
+ *
498
+ * @usageNotes
499
+ * ### Inputs
500
+ * - `button` (required): The `ActionButton` configuration object
501
+ *
502
+ * ### Outputs
503
+ * - `buttonClick`: Emits the button configuration when clicked (for non-dropdown buttons)
504
+ * - `childSelect`: Emits the selected child button (for dropdown buttons)
505
+ *
506
+ * ### Loading State
507
+ * The component automatically manages loading state for async handlers.
508
+ * When a handler returns a Promise, the button shows a spinner until it resolves/rejects.
509
+ * You can also manually control loading via the `button.loading` property.
510
+ *
511
+ * ### Dropdown Behavior
512
+ * For `ActionButtonType.Dropdown`, clicking the button opens an `ion-popover`
513
+ * containing an `ActionButtonListComponent` with the child buttons.
514
+ * When a child is selected, its handler is executed and `childSelect` is emitted.
515
+ */
516
+ declare class ButtonComponent {
517
+ /**
518
+ * Popover controller for creating dropdown popovers.
519
+ */
520
+ private readonly popoverCtrl;
521
+ /**
522
+ * Internal loading state for async handler execution.
523
+ */
524
+ private readonly _isLoading;
525
+ /**
526
+ * Set of child button IDs that are currently loading (for dropdowns).
527
+ * Tracks multiple concurrent loading operations.
528
+ */
529
+ private readonly _loadingChildIds;
530
+ /**
531
+ * The action button configuration.
532
+ */
533
+ readonly button: _angular_core.InputSignal<ActionButton<void>>;
534
+ /**
535
+ * Emits when the button is clicked (for non-dropdown buttons).
536
+ * Emits the button configuration that was clicked.
537
+ */
538
+ readonly buttonClick: _angular_core.OutputEmitterRef<ActionButton<void>>;
539
+ /**
540
+ * Emits when a child button is selected from a dropdown.
541
+ * Only emits for `ActionButtonType.Dropdown` buttons.
542
+ */
543
+ readonly childSelect: _angular_core.OutputEmitterRef<ActionButton<void>>;
544
+ /**
545
+ * Checks if any child button is in a loading state and has showLoadingSpinner enabled.
546
+ */
547
+ private readonly hasLoadingChild;
548
+ /**
549
+ * Combined loading state from external prop, internal async state, and child loading.
550
+ * Returns true if:
551
+ * - Internal loading state is active, OR
552
+ * - External loading prop is true, OR
553
+ * - Any child is loading AND parent has showLoadingSpinner !== false
554
+ */
555
+ readonly isLoading: _angular_core.Signal<boolean>;
556
+ /**
557
+ * Whether to display the loading spinner.
558
+ * Shows spinner only if button is loading AND showLoadingSpinner is not false.
559
+ */
560
+ readonly showLoadingSpinner: _angular_core.Signal<boolean>;
561
+ /**
562
+ * Whether the button is disabled.
563
+ * - Non-dropdown buttons: Disabled when loading or explicitly disabled in config
564
+ * - Dropdown buttons: Only disabled when explicitly disabled in config or when parent itself is loading
565
+ * (not disabled by inherited child loading - user can still open dropdown to see loading children)
566
+ */
567
+ readonly isDisabled: _angular_core.Signal<boolean>;
568
+ /**
569
+ * Determines the slot for the icon based on button type and label presence.
570
+ */
571
+ readonly iconSlot: _angular_core.Signal<"icon-only" | "start">;
572
+ /**
573
+ * Whether to show the label text.
574
+ */
575
+ readonly showLabel: _angular_core.Signal<string | false | undefined>;
576
+ /**
577
+ * Whether to show the dropdown chevron icon.
578
+ */
579
+ readonly showDropdownIcon: _angular_core.Signal<boolean>;
580
+ constructor();
581
+ /**
582
+ * Handles button click events.
583
+ * For dropdown buttons, opens a popover with child actions.
584
+ * For other buttons, executes the handler with auto-loading management.
585
+ *
586
+ * @param event - The click event
587
+ */
588
+ protected onClick(event: Event): Promise<void>;
589
+ /**
590
+ * Opens a dropdown popover with child action buttons.
591
+ *
592
+ * @param event - The triggering click event for popover positioning
593
+ */
594
+ private openDropdown;
595
+ /**
596
+ * Executes a button's handler with automatic loading state management.
597
+ *
598
+ * @param btn - The button whose handler to execute
599
+ */
600
+ private executeHandler;
601
+ static ɵfac: _angular_core.ɵɵFactoryDeclaration<ButtonComponent, never>;
602
+ static ɵcmp: _angular_core.ɵɵComponentDeclaration<ButtonComponent, "maki-button", never, { "button": { "alias": "button"; "required": true; "isSignal": true; }; }, { "buttonClick": "buttonClick"; "childSelect": "childSelect"; }, never, never, true, never>;
603
+ }
604
+
605
+ export { ActionButtonListComponent, ActionButtonType, ButtonComponent, TestCardComponent, TestClass, TestService };
606
+ export type { ActionButton, ActionButtonConfig, TestInterface };