@cngx/ui 0.0.1-rc.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.
Files changed (60) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +550 -0
  3. package/action-button/README.md +98 -0
  4. package/empty-state/README.md +103 -0
  5. package/feedback/README.md +33 -0
  6. package/fesm2022/cngx-ui-action-button.mjs +319 -0
  7. package/fesm2022/cngx-ui-action-button.mjs.map +1 -0
  8. package/fesm2022/cngx-ui-empty-state.mjs +138 -0
  9. package/fesm2022/cngx-ui-empty-state.mjs.map +1 -0
  10. package/fesm2022/cngx-ui-feedback.mjs +2962 -0
  11. package/fesm2022/cngx-ui-feedback.mjs.map +1 -0
  12. package/fesm2022/cngx-ui-layout.mjs +89 -0
  13. package/fesm2022/cngx-ui-layout.mjs.map +1 -0
  14. package/fesm2022/cngx-ui-mat-stepper.mjs +567 -0
  15. package/fesm2022/cngx-ui-mat-stepper.mjs.map +1 -0
  16. package/fesm2022/cngx-ui-mat-tabs.mjs +1405 -0
  17. package/fesm2022/cngx-ui-mat-tabs.mjs.map +1 -0
  18. package/fesm2022/cngx-ui-material.mjs +79 -0
  19. package/fesm2022/cngx-ui-material.mjs.map +1 -0
  20. package/fesm2022/cngx-ui-overlay.mjs +91 -0
  21. package/fesm2022/cngx-ui-overlay.mjs.map +1 -0
  22. package/fesm2022/cngx-ui-sidenav.mjs +521 -0
  23. package/fesm2022/cngx-ui-sidenav.mjs.map +1 -0
  24. package/fesm2022/cngx-ui-skeleton.mjs +158 -0
  25. package/fesm2022/cngx-ui-skeleton.mjs.map +1 -0
  26. package/fesm2022/cngx-ui-speak.mjs +112 -0
  27. package/fesm2022/cngx-ui-speak.mjs.map +1 -0
  28. package/fesm2022/cngx-ui-stepper.mjs +312 -0
  29. package/fesm2022/cngx-ui-stepper.mjs.map +1 -0
  30. package/fesm2022/cngx-ui-tabs.mjs +507 -0
  31. package/fesm2022/cngx-ui-tabs.mjs.map +1 -0
  32. package/fesm2022/cngx-ui.mjs +45 -0
  33. package/fesm2022/cngx-ui.mjs.map +1 -0
  34. package/layout/README.md +133 -0
  35. package/mat-stepper/README.md +34 -0
  36. package/mat-tabs/README.md +163 -0
  37. package/mat-tabs/styles/mat-tabs.css +233 -0
  38. package/material/README.md +90 -0
  39. package/overlay/README.md +99 -0
  40. package/package.json +98 -0
  41. package/sidenav/README.md +127 -0
  42. package/skeleton/README.md +98 -0
  43. package/speak/README.md +93 -0
  44. package/speak/speak-button-theme.scss +78 -0
  45. package/stepper/README.md +40 -0
  46. package/tabs/README.md +28 -0
  47. package/types/cngx-ui-action-button.d.ts +126 -0
  48. package/types/cngx-ui-empty-state.d.ts +41 -0
  49. package/types/cngx-ui-feedback.d.ts +1174 -0
  50. package/types/cngx-ui-layout.d.ts +56 -0
  51. package/types/cngx-ui-mat-stepper.d.ts +234 -0
  52. package/types/cngx-ui-mat-tabs.d.ts +664 -0
  53. package/types/cngx-ui-material.d.ts +36 -0
  54. package/types/cngx-ui-overlay.d.ts +57 -0
  55. package/types/cngx-ui-sidenav.d.ts +209 -0
  56. package/types/cngx-ui-skeleton.d.ts +97 -0
  57. package/types/cngx-ui-speak.d.ts +31 -0
  58. package/types/cngx-ui-stepper.d.ts +129 -0
  59. package/types/cngx-ui-tabs.d.ts +165 -0
  60. package/types/cngx-ui.d.ts +18 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Christian Weiss
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,550 @@
1
+ # @cngx/ui
2
+
3
+ Finished, styled Angular components that compose headless directives from
4
+ `@cngx/common` with opinionated rendering. These are the "organism" layer —
5
+ ready to drop into an application without additional template work.
6
+
7
+ ## Theming
8
+
9
+ Every component supports two theming paths:
10
+
11
+ 1. **CSS Custom Properties** — override `--cngx-*` variables on any parent
12
+ element. Works without Angular Material.
13
+
14
+ 2. **Material Theme SCSS** — each component ships a `*-theme.scss` file with
15
+ `base()`, `color($theme)`, `density($theme)`, and `theme($theme)` mixins
16
+ that map Material design tokens to the CSS custom properties.
17
+
18
+ ```scss
19
+ @use '@angular/material' as mat;
20
+ @use '@cngx/ui/speak/speak-button-theme' as speak;
21
+
22
+ $theme: mat.define-theme((...));
23
+
24
+ html {
25
+ @include mat.all-component-themes($theme);
26
+ @include speak.theme($theme);
27
+ }
28
+ ```
29
+
30
+ M3 themes use `var(--mat-sys-*)` tokens. M2 themes derive from the palette.
31
+ Density scales sizes from default (0) to compact (-4).
32
+
33
+ ## Components
34
+
35
+ ### CngxMatPaginator
36
+
37
+ Material paginator wrapper that connects to `CngxPaginate` (headless,
38
+ `@cngx/common`) via `[cngxPaginateRef]`.
39
+
40
+ ```html
41
+ <div cngxPaginate #pg="cngxPaginate" [total]="items().length">
42
+ <!-- table / list -->
43
+ </div>
44
+ <cngx-mat-paginator [cngxPaginateRef]="pg" [pageSizeOptions]="[5, 10, 25]" />
45
+ ```
46
+
47
+ **Inputs:** `cngxPaginateRef` (required, CngxPaginate instance), `pageSizeOptions` (number[])
48
+
49
+ ### CngxSpeakButton
50
+
51
+ Ready-made speaker button that connects to `CngxSpeak` (headless,
52
+ `@cngx/common`) via `[speakRef]`.
53
+
54
+ ```html
55
+ <span [cngxSpeak]="text" #tts="cngxSpeak">{{ text }}</span>
56
+ <cngx-speak-button [speakRef]="tts" />
57
+ ```
58
+
59
+ **Inputs:** `speakRef` (required, CngxSpeak instance)
60
+
61
+ **CSS Custom Properties:**
62
+
63
+ | Variable | Default | Description |
64
+ |-|-|-|
65
+ | `--cngx-speak-btn-size` | `28px` | Button width and height |
66
+ | `--cngx-speak-btn-icon-size` | `14px` | SVG icon size |
67
+ | `--cngx-speak-btn-radius` | `4px` | Border radius |
68
+ | `--cngx-speak-btn-border-width` | `1px` | Border width |
69
+ | `--cngx-speak-btn-bg` | `--cngx-surface` / `#fff` | Background color |
70
+ | `--cngx-speak-btn-color` | `--cngx-text-secondary` / `#666` | Icon color |
71
+ | `--cngx-speak-btn-active-color` | `--cngx-accent` / `#f5a623` | Icon color while speaking or on hover |
72
+ | `--cngx-speak-btn-transition` | `0.15s` | Color transition duration |
73
+
74
+ **Material theme:** `@use '@cngx/ui/speak/speak-button-theme'`
75
+
76
+ ### CngxSkeletonContainer
77
+
78
+ Skeleton loading container with built-in placeholder repetition. Wraps the
79
+ headless `CngxSkeleton` atom with template projection so the consumer doesn't
80
+ need `@if`/`@for` boilerplate.
81
+
82
+ ```html
83
+ <cngx-skeleton [loading]="loading()" [count]="3">
84
+ <ng-template cngxSkeletonPlaceholder let-i let-last="last">
85
+ <div class="skeleton-card" [style.width]="last ? '60%' : '100%'"></div>
86
+ </ng-template>
87
+ <app-real-content />
88
+ </cngx-skeleton>
89
+ ```
90
+
91
+ **Inputs:** `loading` (boolean), `shimmer` (boolean, respects `prefers-reduced-motion`), `count` (number)
92
+
93
+ **Template:** project `<ng-template cngxSkeletonPlaceholder>` for loading state; default `<ng-content>` for loaded state. Context: `$implicit` (index), `index`, `count`, `first`, `last`.
94
+
95
+ **CSS Classes:** `cngx-skeleton`, `cngx-skeleton--loading`, `cngx-skeleton--shimmer`
96
+
97
+ **Selector:** `cngx-skeleton` -- exportAs `"cngxSkeletonContainer"`
98
+
99
+ ### CngxActionButton
100
+
101
+ Action button molecule with built-in async status communication. Composes
102
+ `CngxAsyncClick` internally, adding template projection for pending/succeeded/failed
103
+ states, an `aria-live` region for screen reader announcements, optional toast
104
+ integration, and a `state` property for downstream feedback consumers.
105
+
106
+ ```html
107
+ <!-- Minimal -->
108
+ <cngx-action-button [action]="save">Save</cngx-action-button>
109
+
110
+ <!-- With template slots -->
111
+ <cngx-action-button [action]="save">
112
+ Save
113
+ <ng-template cngxPending><mat-spinner diameter="18" /> Saving...</ng-template>
114
+ <ng-template cngxSucceeded>Saved!</ng-template>
115
+ <ng-template cngxFailed let-err>{{ err }} -- retry?</ng-template>
116
+ </cngx-action-button>
117
+
118
+ <!-- With toast feedback -->
119
+ <cngx-action-button [action]="save" toastSuccess="Saved" toastError="Save failed">
120
+ Save
121
+ </cngx-action-button>
122
+
123
+ <!-- Downstream state binding -->
124
+ <cngx-action-button [action]="save" #btn="cngxActionButton">Save</cngx-action-button>
125
+ <cngx-alert [state]="btn.state" severity="error" title="Details" />
126
+ ```
127
+
128
+ **Inputs:**
129
+
130
+ | Input | Type | Default | Description |
131
+ |-|-|-|-|
132
+ | `action` | `AsyncAction` | required | Async action to execute on click |
133
+ | `feedbackDuration` | `number` | `2000` | Duration in ms to show feedback state |
134
+ | `enabled` | `boolean` | `true` | When `false`, clicks are ignored |
135
+ | `type` | `'button' \| 'submit' \| 'reset'` | `'button'` | Button type attribute |
136
+ | `variant` | `ActionButtonVariant` | `'primary'` | Visual variant (`'primary'`, `'secondary'`, `'ghost'`) |
137
+ | `pendingLabel` | `string` | -- | Fallback text while pending (when no `cngxPending` template) |
138
+ | `succeededLabel` | `string` | -- | Fallback text after success (when no `cngxSucceeded` template) |
139
+ | `failedLabel` | `string` | -- | Fallback text after failure (when no `cngxFailed` template) |
140
+ | `succeededAnnouncement` | `string` | -- | SR announcement on success (falls back to `succeededLabel`) |
141
+ | `failedAnnouncement` | `string` | -- | SR announcement on failure (falls back to `failedLabel`) |
142
+ | `externalState` | `CngxAsyncState<unknown>` | -- | External state override for visual status |
143
+ | `toastSuccess` | `string` | -- | Toast message on success (requires `CngxToaster`) |
144
+ | `toastError` | `string` | -- | Toast message on error (requires `CngxToaster`) |
145
+ | `toastErrorDetail` | `boolean` | `false` | Append error message to error toast |
146
+ | `toastSuccessDuration` | `number` | `3000` | Success toast duration in ms |
147
+ | `toastErrorDuration` | `number \| 'persistent'` | `'persistent'` | Error toast duration |
148
+
149
+ **State producer:** `readonly state: CngxAsyncState<unknown>` -- the effective
150
+ lifecycle state (internal or external). Bind to any `[state]` consumer.
151
+
152
+ **Toast integration:** When `toastSuccess` or `toastError` inputs are set and
153
+ `CngxToaster` is provided (via `provideFeedback(withToasts())` or `provideToasts()`),
154
+ toasts fire automatically on status transitions. If `CngxToaster` is not provided,
155
+ toast inputs are silently ignored. Do not combine with `[cngxToastOn]` on the same
156
+ element -- a dev-mode warning is emitted if both are active.
157
+
158
+ **Template directives:** `cngxPending`, `cngxSucceeded`, `cngxFailed` (project `<ng-template>` for each state)
159
+
160
+ **CSS Classes:** `cngx-action-button`, `cngx-action-button--{variant}`
161
+
162
+ **Selector:** `cngx-action-button` -- exportAs `"cngxActionButton"`
163
+
164
+ ### CngxSidenav
165
+
166
+ Declarative sidebar organism with dual-sidebar support, responsive mode
167
+ switching, mini/rail mode, resize handle, and keyboard shortcut toggle.
168
+
169
+ ```html
170
+ <cngx-sidenav-layout>
171
+ <cngx-sidenav position="start" [(opened)]="navOpen" mode="side"
172
+ [resizable]="true" shortcut="mod+b" width="240px">
173
+ <cngx-sidenav-header>Workspace</cngx-sidenav-header>
174
+ <a cngxNavLink [active]="true">Dashboard</a>
175
+ <a cngxNavLink>Settings</a>
176
+ <cngx-sidenav-footer>v1.0</cngx-sidenav-footer>
177
+ </cngx-sidenav>
178
+ <cngx-sidenav-content>
179
+ <router-outlet />
180
+ </cngx-sidenav-content>
181
+ </cngx-sidenav-layout>
182
+ ```
183
+
184
+ **Modes:** `'over'` (overlay + backdrop), `'push'` (pushes content), `'side'` (permanent), `'mini'` (collapsed rail, expands on hover)
185
+
186
+ **CngxSidenav inputs:**
187
+
188
+ | Input | Type | Default | Description |
189
+ |-|-|-|-|
190
+ | `ariaLabel` | `string` | — | Accessible label for the complementary landmark |
191
+ | `position` | `'start' \| 'end'` | `'start'` | Logical position (flips in RTL) |
192
+ | `mode` | `SidenavMode` | `'over'` | Interaction mode |
193
+ | `responsive` | `string` | — | CSS media query; matches = `'side'`, else falls back to `mode` |
194
+ | `width` | `string` (model) | `'280px'` | Panel width, two-way `[(width)]` for resize |
195
+ | `miniWidth` | `string` | `'56px'` | Collapsed rail width in mini mode |
196
+ | `expandOnHover` | `boolean` | `true` | Expand mini rail on mouse hover |
197
+ | `resizable` | `boolean` | `false` | Show drag handle for user resize |
198
+ | `minWidth` | `string` | `'120px'` | Min width constraint during resize |
199
+ | `maxWidth` | `string` | `'600px'` | Max width constraint during resize |
200
+ | `shortcut` | `string` | — | Keyboard shortcut, e.g. `'mod+b'` (`mod` = Cmd on Mac, Ctrl elsewhere) |
201
+
202
+ **CngxSidenav signals:** `opened` (model), `expanded` (mini hover state), `effectiveMode`, `effectiveWidth`, `resizing`, `isOverlay`
203
+ **Methods:** `open()`, `close()`, `toggle()`, `expand()`, `collapse()`
204
+
205
+ **Slot components:** `CngxSidenavHeader`, `CngxSidenavFooter` (projected into named slots)
206
+ **Layout:** `CngxSidenavLayout` (container, manages backdrop + scroll lock), `CngxSidenavContent` (main area)
207
+
208
+ **CSS Custom Properties:**
209
+
210
+ | Variable | Default | Description |
211
+ |-|-|-|
212
+ | `--cngx-sidenav-width` | `280px` | Panel width |
213
+ | `--cngx-sidenav-mini-width` | `56px` | Mini mode rail width |
214
+ | `--cngx-sidenav-bg` | M3 surface-container | Background |
215
+ | `--cngx-sidenav-color` | M3 on-surface | Text color |
216
+ | `--cngx-sidenav-border-color` | M3 outline-variant | Border color |
217
+ | `--cngx-sidenav-padding` | density-dependent | Header/footer padding |
218
+ | `--cngx-sidenav-header-bg` | M3 surface-container-low | Header background |
219
+ | `--cngx-sidenav-footer-bg` | M3 surface-container-low | Footer background |
220
+ | `--cngx-sidenav-backdrop-bg` | M3 scrim | Backdrop color |
221
+ | `--cngx-sidenav-backdrop-opacity` | `0.5` | Backdrop opacity |
222
+ | `--cngx-sidenav-transition-duration` | `0.25s` | Animation duration |
223
+ | `--cngx-sidenav-resize-handle-width` | `4px` | Resize handle hit area |
224
+ | `--cngx-sidenav-resize-handle-color` | M3 primary | Handle highlight color |
225
+ | `--cngx-sidenav-expanded-shadow` | `4px 0 12px rgba(0,0,0,0.1)` | Mini expanded shadow |
226
+
227
+ **Nav link theming** (applied inside sidenavs via `sidenav.theme()`):
228
+
229
+ | Variable | Description |
230
+ |-|-|
231
+ | `--cngx-nav-link-color` | Default text color |
232
+ | `--cngx-nav-link-hover-color` | Hover text color |
233
+ | `--cngx-nav-link-active-color` | Active text color |
234
+ | `--cngx-nav-link-active-bg` | Active background (M3 secondary-container) |
235
+ | `--cngx-nav-link-radius` | Border radius (default 8px) |
236
+ | `--cngx-nav-link-padding` | Padding (density-dependent) |
237
+
238
+ **Animated nav group expand/collapse:**
239
+
240
+ Replace `@if` with the `.cngx-nav-group-content` wrapper for smooth height animation
241
+ via the CSS `grid-template-rows: 0fr/1fr` trick (no `@angular/animations` needed):
242
+
243
+ ```html
244
+ <button cngxNavGroup #group="cngxNavGroup" [controls]="'items'">Settings</button>
245
+ <div class="cngx-nav-group-content"
246
+ [class.cngx-nav-group-content--open]="group.disclosure.opened()">
247
+ <div id="items" role="group">
248
+ <a cngxNavLink [depth]="1">General</a>
249
+ <a cngxNavLink [depth]="1">Security</a>
250
+ </div>
251
+ </div>
252
+ ```
253
+
254
+ **Material theme:** `@use '@cngx/ui/sidenav/sidenav-theme'` — includes nav-link theme automatically
255
+
256
+ ### CngxToaster — Toast API (`@cngx/ui/feedback`)
257
+
258
+ Programmatic toast service. Not `providedIn: 'root'` — provide via
259
+ `provideFeedback(withToasts())` or `provideToasts()`.
260
+
261
+ #### ToastConfig
262
+
263
+ ```typescript
264
+ this.toaster.show({
265
+ message: 'Saved', // Required — sole text when title not set
266
+ title: 'Save successful', // Optional — bold primary text
267
+ description: 'Profile updated.', // Optional — secondary text below title
268
+ severity: 'success', // 'info' | 'success' | 'warning' | 'error'
269
+ duration: 5000, // ms or 'persistent'
270
+ action: { label: 'Undo', handler: () => this.undo() },
271
+ dismissible: true, // default: true
272
+ content: MyCustomToastBody, // Optional — component as toast body
273
+ contentInputs: { error: err }, // Inputs for the content component
274
+ });
275
+ ```
276
+
277
+ **Layout rules:**
278
+ - `message` only (no `title`): single-line text (backwards-compatible)
279
+ - `title` + `description`/`message`: two-line layout (title bold, description muted)
280
+ - `title` + `content`: title above custom component
281
+ - `content` only: custom component fills the body
282
+
283
+ **A11y:** Avoid focusable elements (`<a>`, `<button>`) inside `content` components
284
+ — they are unreachable inside a `role="status"` live region.
285
+
286
+ **Dedup:** Toasts with same `message + severity + title` within `dedupWindow` (default
287
+ 1000ms) are merged (count incremented). `description` is intentionally excluded from
288
+ dedup — same event with different context detail is still the same event.
289
+
290
+ #### Toast CSS Custom Properties
291
+
292
+ | Property | Default | Description |
293
+ |-|-|-|
294
+ | `--cngx-toast-title-font-weight` | `600` | Title font weight |
295
+ | `--cngx-toast-title-color` | inherit | Title text color |
296
+ | `--cngx-toast-title-font-size` | `--cngx-toast-font-size` | Title font size |
297
+ | `--cngx-toast-description-color` | `#64748b` | Description text color (muted) |
298
+ | `--cngx-toast-description-font-size` | `0.8125rem` | Description font size |
299
+ | `--cngx-toast-description-line-height` | `1.4` | Description line height |
300
+ | `--cngx-toast-description-max-lines` | `3` | Line-clamp for description |
301
+
302
+ ### CngxAlert — Inline Alert Atom (`@cngx/ui/feedback`)
303
+
304
+ Inline alert with enter/exit animations, state-driven visibility, auto-dismiss
305
+ with pause-on-hover/focus (WCAG 2.2.1), optional auto-collapse, and action buttons.
306
+
307
+ Three visibility modes:
308
+ - **Static** (no `[state]` or `[when]`): always visible
309
+ - **State-driven** (`[state]`): auto-shows on error/success/loading, auto-hides on idle
310
+ - **Boolean-driven** (`[when]`): visible when true, hidden when false
311
+
312
+ ```html
313
+ <!-- Static -->
314
+ <cngx-alert severity="warning" title="Unsaved changes" [closable]="true">
315
+ Your changes will be lost if you leave.
316
+ <button cngxAlertAction (click)="save()">Save now</button>
317
+ </cngx-alert>
318
+
319
+ <!-- State-driven -->
320
+ <cngx-alert [state]="saveState" severity="error" title="Save failed" [closable]="true">
321
+ {{ saveState.error() }}
322
+ </cngx-alert>
323
+
324
+ <!-- Boolean-driven -->
325
+ <cngx-alert [when]="showTip()" severity="info" title="Tip">
326
+ Press Ctrl+S to save.
327
+ </cngx-alert>
328
+
329
+ <!-- Collapsible (collapses body after delay, expands on hover/focus) -->
330
+ <cngx-alert [state]="state" severity="error" title="Errors"
331
+ [collapsible]="true" [collapseDelay]="3000">
332
+ Detailed error description...
333
+ </cngx-alert>
334
+ ```
335
+
336
+ **Inputs:**
337
+
338
+ | Input | Type | Default | Description |
339
+ |-|-|-|-|
340
+ | `severity` | `AlertSeverity` | `'info'` | Visual style + ARIA role |
341
+ | `title` | `string` | -- | Bold title above content |
342
+ | `closable` | `boolean` | `false` | Show dismiss button |
343
+ | `dismissible` | `boolean` | `false` | Deprecated alias for `closable` |
344
+ | `state` | `CngxAsyncState<unknown>` | -- | State-driven visibility |
345
+ | `when` | `boolean` | -- | Boolean visibility trigger |
346
+ | `autoDismissDelay` | `number` | `5000` | Auto-dismiss delay for success state (ms) |
347
+ | `collapsible` | `boolean` | `false` | Enable auto-collapse |
348
+ | `collapseDelay` | `number` | `autoDismissDelay` | Delay before collapse (ms) |
349
+
350
+ **Slot directives:** `CngxAlertAction` (restricts to `button, a`), `CngxAlertIcon` (custom icon)
351
+
352
+ **ARIA:** `role="alert"` (error/warning), `role="status"` (info/success), `aria-busy` (loading),
353
+ `aria-expanded` (collapsible), `aria-atomic="false"` when `CngxAlertAction` is present.
354
+
355
+ **Animation:** CSS keyframes with `prefers-reduced-motion` support. Enter: `ease-out 200ms`.
356
+ Exit: `ease-in 150ms`. Icon pulse on enter (one-shot, 300ms).
357
+
358
+ **Collapse:** `grid-template-rows: 1fr/0fr` transition. Hover/focus expands, leave restarts timer.
359
+
360
+ **CSS Custom Properties:**
361
+
362
+ | Variable | Default | Description |
363
+ |-|-|-|
364
+ | `--cngx-alert-gap` | `12px` | Gap between icon, body, dismiss |
365
+ | `--cngx-alert-padding` | `12px 16px` | Alert padding |
366
+ | `--cngx-alert-border-radius` | `8px` | Corner radius |
367
+ | `--cngx-alert-icon-size` | `20px` | Default icon size |
368
+ | `--cngx-alert-title-weight` | `600` | Title font weight |
369
+ | `--cngx-alert-enter-duration` | `200ms` | Enter animation duration |
370
+ | `--cngx-alert-exit-duration` | `150ms` | Exit animation duration |
371
+ | `--cngx-alert-collapse-duration` | `200ms` | Collapse transition duration |
372
+ | `--cngx-alert-{severity}-bg` | per severity | Background color |
373
+ | `--cngx-alert-{severity}-border` | per severity | Border color |
374
+ | `--cngx-alert-{severity}-icon` | per severity | Icon color |
375
+
376
+ ### CngxAlertStack + CngxAlerter — Scoped Alert System (`@cngx/ui/feedback`)
377
+
378
+ Scoped inline alert stacking with programmatic service. Each `CngxAlertStack` provides
379
+ its own `CngxAlerter` via `viewProviders` — nested stacks (e.g. in dialogs) are fully
380
+ isolated.
381
+
382
+ ```html
383
+ <!-- In a dialog -->
384
+ <dialog cngxDialog [submitAction]="save">
385
+ <header cngxDialogTitle>Edit User</header>
386
+ <cngx-alert-stack scope="user-form" [maxVisible]="5" />
387
+ <form>...</form>
388
+ </dialog>
389
+ ```
390
+
391
+ ```typescript
392
+ // In a child component inside the dialog
393
+ private readonly alerter = inject(CngxAlerter);
394
+
395
+ handleErrors(errors: string[]) {
396
+ this.alerter.dismissAll();
397
+ errors.forEach(e => this.alerter.show({ message: e, severity: 'error' }));
398
+ }
399
+ ```
400
+
401
+ For root-level injection (outside a stack), add `withAlerts()` to `provideFeedback()`.
402
+
403
+ **CngxAlertStack inputs:**
404
+
405
+ | Input | Type | Default | Description |
406
+ |-|-|-|-|
407
+ | `scope` | `string` | -- | Scope filter for alerts |
408
+ | `maxVisible` | `number` | `5` | Max visible before overflow collapse |
409
+ | `position` | `'top' \| 'bottom'` | `'top'` | Where new alerts insert |
410
+ | `reserveSpace` | `boolean` | `false` | Reserve min-height to prevent layout shift |
411
+ | `autoScroll` | `boolean` | `true` | Scroll stack into view on new alert |
412
+
413
+ **CngxAlerter API:**
414
+
415
+ | Method | Returns | Description |
416
+ |-|-|-|
417
+ | `show(config)` | `AlertRef` | Show an alert |
418
+ | `dismiss(id)` | `void` | Dismiss by id |
419
+ | `dismissAll(scope?)` | `void` | Dismiss all (optionally filtered by scope) |
420
+
421
+ **AlertConfig:** `message` (required), `severity`, `title`, `persistent` (default `true`),
422
+ `duration`, `dismissible` (default `true`), `scope`.
423
+
424
+ **Dedup:** `message + severity + scope` within `alertDedupWindow` (default 1s).
425
+
426
+ **ARIA:** `role="log"` + `aria-live="polite"` on container. `aria-expanded` + `aria-controls`
427
+ on overflow button.
428
+
429
+ #### CngxAlertOn — State Bridge
430
+
431
+ ```html
432
+ <button [cngxAsyncClick]="save"
433
+ [cngxAlertOn]="saveState"
434
+ alertError="Save failed"
435
+ [alertErrorDetail]="true">
436
+ Save
437
+ </button>
438
+ ```
439
+
440
+ **Inputs:** `cngxAlertOn` (required `CngxAsyncState`), `alertSuccess`, `alertError`,
441
+ `alertErrorDetail` (boolean), `alertScope`.
442
+
443
+ ### CngxBanner + CngxBannerOutlet — Global Banner System (`@cngx/ui/feedback`)
444
+
445
+ System-level banners for session timeout, maintenance, offline status. Sticky top,
446
+ always persistent (no auto-dismiss), dedup by required `id`.
447
+
448
+ ```html
449
+ <!-- Once in app shell, above layout -->
450
+ <cngx-banner-outlet />
451
+ <div class="layout">...</div>
452
+ ```
453
+
454
+ ```typescript
455
+ private readonly banner = inject(CngxBanner);
456
+
457
+ this.banner.show({
458
+ message: 'Session expires in 5 minutes',
459
+ id: 'auth:session-timeout',
460
+ severity: 'warning',
461
+ action: {
462
+ label: 'Extend',
463
+ handler: () => this.extendSession(), // returns Promise<void>
464
+ },
465
+ });
466
+
467
+ // Update in-place (same id)
468
+ this.banner.update('auth:session-timeout', {
469
+ message: 'Session expires in 2 minutes',
470
+ severity: 'error',
471
+ });
472
+
473
+ // Dismiss when condition resolves
474
+ this.banner.dismiss('auth:session-timeout');
475
+ ```
476
+
477
+ Requires `provideFeedback(withBanners())`.
478
+
479
+ **CngxBanner API:**
480
+
481
+ | Method | Returns | Description |
482
+ |-|-|-|
483
+ | `show(config)` | `BannerRef` | Show or update (if id exists) |
484
+ | `update(id, patch)` | `void` | Patch an existing banner |
485
+ | `dismiss(id)` | `void` | Dismiss by id |
486
+ | `dismissAll()` | `void` | Dismiss all banners |
487
+ | `executeAction(id)` | `Promise<void>` | Execute the banner's action handler with async lifecycle |
488
+
489
+ **BannerConfig:** `message` (required), `id` (required), `severity`, `dismissible`
490
+ (default `true`), `action` (`{ label, handler: () => void | Promise<void> }`).
491
+
492
+ **Async actions:** When `action.handler` returns a `Promise`, the button shows `aria-busy`,
493
+ disables during execution. Success: banner dismissed. Error: banner stays open.
494
+
495
+ **ID uniqueness:** Caller's responsibility. Recommended prefix convention:
496
+ `'auth:session-timeout'`, `'billing:payment-failed'`.
497
+
498
+ **ARIA:** `role="alert"` (error/warning), `role="status"` (info/success).
499
+ `aria-live="assertive"` for error only, `polite` for others.
500
+
501
+ **First-render:** Banners present at initial render skip enter animation (no layout jump).
502
+
503
+ **Layout:** `position: sticky; top: 0; z-index: 900` (below Material dialogs at 1000).
504
+ `:empty` hides the outlet completely (`display: none`).
505
+
506
+ #### CngxBannerTrigger — Declarative Banner
507
+
508
+ ```html
509
+ <cngx-banner-trigger
510
+ [when]="isOffline()"
511
+ message="You are offline."
512
+ id="net:offline"
513
+ severity="error" />
514
+ ```
515
+
516
+ Renders nothing. Shows banner when `[when]` is true, dismisses when false.
517
+ Dismissed on component destroy.
518
+
519
+ **Inputs:** `when` (required), `message` (required), `id` (required), `severity`,
520
+ `dismissible`, `actionLabel`, `actionHandler`.
521
+
522
+ #### CngxBannerOn — State Bridge
523
+
524
+ ```html
525
+ <div [cngxBannerOn]="connectionState"
526
+ bannerId="net:offline"
527
+ bannerError="Connection lost">
528
+ </div>
529
+ ```
530
+
531
+ Shows banner on `error` transition, auto-dismisses on `success`/`idle`.
532
+
533
+ **Inputs:** `cngxBannerOn` (required `CngxAsyncState`), `bannerId` (required),
534
+ `bannerError`, `bannerSeverity` (default `'error'`), `bannerErrorDetail` (boolean).
535
+
536
+ #### Banner CSS Custom Properties
537
+
538
+ | Variable | Default | Description |
539
+ |-|-|-|
540
+ | `--cngx-banner-z-index` | `900` | Stacking order |
541
+ | `--cngx-banner-gap` | `12px` | Gap between elements |
542
+ | `--cngx-banner-padding` | `10px 16px` | Banner padding |
543
+ | `--cngx-banner-font-size` | `0.9375rem` | Message font size |
544
+ | `--cngx-banner-action-min-size` | `44px` | Min touch target for action button |
545
+ | `--cngx-banner-pending-opacity` | `0.85` | Opacity during async action |
546
+ | `--cngx-banner-{severity}-bg` | per severity | Background |
547
+ | `--cngx-banner-{severity}-border` | per severity | Border |
548
+ | `--cngx-banner-{severity}-icon` | per severity | Icon color |
549
+
550
+ **Material theme:** Included in `@use '@cngx/ui/feedback/feedback-theme'` — `theme($theme)` covers alert, alert-stack, banner, toast, loading, and progress.
@@ -0,0 +1,98 @@
1
+ # CngxActionButton
2
+
3
+ Action button molecule combining async state tracking, visual feedback, and optional toast notifications.
4
+
5
+ ## Import
6
+
7
+ ```typescript
8
+ import { CngxActionButton } from '@cngx/ui';
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```typescript
14
+ import { Component } from '@angular/core';
15
+ import { CngxActionButton } from '@cngx/ui';
16
+
17
+ @Component({
18
+ selector: 'app-example',
19
+ template: ` <cngx-action-button [action]="save"> Save Draft </cngx-action-button> `,
20
+ imports: [CngxActionButton],
21
+ })
22
+ export class ExampleComponent {
23
+ save = () => this.http.post('/api/draft', {});
24
+ }
25
+ ```
26
+
27
+ ## Overview
28
+
29
+ `CngxActionButton` is a molecule wrapping the `CngxAsyncClick` directive with built-in state communication, template slots, and optional toast integration. It uses `display: contents` — the host produces no DOM box; the inner `<button>` carries the directive directly.
30
+
31
+ The component supports three visual feedback pathways:
32
+
33
+ 1. **Fallback labels** — `pendingLabel`, `succeededLabel`, `failedLabel` strings
34
+ 2. **Template slots** — `cngxPending`, `cngxSucceeded`, `cngxFailed` directives
35
+ 3. **Automatic state prop** — bind `btn.state` to any state consumer
36
+
37
+ A screen-reader-only `aria-live` region announces state transitions without visual noise.
38
+
39
+ ## Accessibility
40
+
41
+ `CngxActionButton` is fully accessible out of the box:
42
+
43
+ - **ARIA roles:** The inner `<button>` carries all ARIA attributes from `CngxAsyncClick` — `aria-busy` when pending, no explicit role (semantic `<button>`).
44
+ - **Keyboard interaction:**
45
+ - `Enter` / `Space` — Activate the action
46
+ - `Escape` — No special behavior (standard button)
47
+ - **Screen reader:** `aria-live="polite"` region announces state transitions: "Action succeeded", "Action failed", and the optional custom announcements via `succeededAnnouncement` / `failedAnnouncement`.
48
+ - **Focus management:** Focus remains on the button throughout the lifecycle — no focus trap or restoration.
49
+
50
+ ## Composition
51
+
52
+ `CngxActionButton` is built from these atomic units and integrates with:
53
+
54
+ - **Host directives:** Applies `CngxAsyncClick` directly on the inner `<button>` (not exposed as hostDirective).
55
+ - **Combines with:** `CngxPending`, `CngxSucceeded`, `CngxFailed` template marker directives; `CngxToaster` for toast integration.
56
+ - **Provides:** The `state` signal export for binding to any async state consumer.
57
+
58
+ ### Example: Composition Pattern
59
+
60
+ ```typescript
61
+ // Bind button state to an alert
62
+ <cngx-action-button #btn="cngxActionButton" [action]="save">
63
+ Save
64
+ </cngx-action-button>
65
+ <cngx-alert [state]="btn.state" title="Save Status" />
66
+ ```
67
+
68
+ ## Styling
69
+
70
+ All colors and spacing use CSS Custom Properties with Material 3 defaults. Override at any scope:
71
+
72
+ ```scss
73
+ // Override defaults in your component or global styles
74
+ :host {
75
+ --cngx-action-btn-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
76
+ --cngx-action-btn-radius: 8px;
77
+ --cngx-action-btn-primary-bg: #1565c0;
78
+ --cngx-action-btn-primary-color: #fff;
79
+ }
80
+ ```
81
+
82
+ ## Material Theme
83
+
84
+ To apply Material Design 3 theme colors, include the theme SCSS in your global stylesheet:
85
+
86
+ ```scss
87
+ @use '@angular/material' as mat;
88
+ @use '@cngx/ui/action-button/action-button-theme' as action-btn;
89
+
90
+ $theme: mat.define-theme((...));
91
+
92
+ html {
93
+ @include mat.all-component-themes($theme);
94
+ @include action-btn.theme($theme);
95
+ }
96
+ ```
97
+
98
+ The theme mixin automatically derives success/error colors from Material's primary and error palettes. Both Material 3 (M3) and Material 2 (M2) are supported; colors adapt to the theme version automatically.