@molecule/app-cookie-banner-angular 0.0.0-stage → 0.0.1-stage
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +202 -0
- package/README.md +406 -2
- package/dist/cookie-banner.component.d.ts +244 -0
- package/dist/cookie-banner.component.d.ts.map +1 -0
- package/dist/cookie-banner.component.js +633 -0
- package/dist/cookie-banner.component.js.map +1 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +69 -0
- package/dist/index.js.map +1 -0
- package/dist/slot-dom.d.ts +31 -0
- package/dist/slot-dom.d.ts.map +1 -0
- package/dist/slot-dom.js +64 -0
- package/dist/slot-dom.js.map +1 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +69 -4
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { type AfterViewInit, type DoCheck, ElementRef, type OnDestroy, type OnInit, type TemplateRef } from '@angular/core';
|
|
2
|
+
import type { UIClassMap } from '@molecule/app-ui';
|
|
3
|
+
import type { CookieCategory } from './types.js';
|
|
4
|
+
import * as i0 from "@angular/core";
|
|
5
|
+
/**
|
|
6
|
+
* CookieBanner component.
|
|
7
|
+
*
|
|
8
|
+
* GDPR / cookie-consent banner: two modes, Accept / Reject only or per-category
|
|
9
|
+
* switches behind "Customize" when `categories` are supplied. The host IS the
|
|
10
|
+
* root `<div>` (`div[mol-cookie-banner]`), matching React's root exactly, so the
|
|
11
|
+
* banner's ClassMap classes, `role`, `aria-label` and inline style are the
|
|
12
|
+
* host's.
|
|
13
|
+
*
|
|
14
|
+
* React renders `null` while `visible` is false — Angular's host element always
|
|
15
|
+
* exists, so it is detached from the DOM in that state and restored when the
|
|
16
|
+
* banner is shown again. The node props are projected slots: `title` renders
|
|
17
|
+
* inside the `<h3>`, `description` inside the `<p>`; plain string inputs render
|
|
18
|
+
* as text instead, the same values React renders.
|
|
19
|
+
*/
|
|
20
|
+
export declare class CookieBanner implements OnInit, AfterViewInit, DoCheck, OnDestroy {
|
|
21
|
+
/** Cookie categories to offer (omit for a simple accept/reject banner). */
|
|
22
|
+
categories?: CookieCategory[];
|
|
23
|
+
/** Called when accept-all is clicked. */
|
|
24
|
+
onAcceptAll?: () => void;
|
|
25
|
+
/** Called when reject-non-essential is clicked. */
|
|
26
|
+
onRejectAll?: () => void;
|
|
27
|
+
/** Called when "Save preferences" is clicked. */
|
|
28
|
+
onSave?: (enabled: Record<string, boolean>) => void;
|
|
29
|
+
/** Optional title (string/number renders as text; nodes are `[slot=title]` content). */
|
|
30
|
+
title?: unknown;
|
|
31
|
+
/** Optional description (string/number as text; nodes are `[slot=description]` content). */
|
|
32
|
+
description?: unknown;
|
|
33
|
+
/** Privacy policy link URL. */
|
|
34
|
+
policyHref?: string;
|
|
35
|
+
/** Whether the banner is visible (controlled; true unless this is `false`). */
|
|
36
|
+
visible?: boolean;
|
|
37
|
+
/** Called when dismissed via Save / Accept / Reject. */
|
|
38
|
+
onDismiss?: () => void;
|
|
39
|
+
/** Extra classes. */
|
|
40
|
+
className?: string;
|
|
41
|
+
/** The title's text capture point. */
|
|
42
|
+
titleFallback?: ElementRef<HTMLElement>;
|
|
43
|
+
/** The title's projected-nodes capture point. */
|
|
44
|
+
titleSlot?: ElementRef<HTMLElement>;
|
|
45
|
+
/** The description's text capture point. */
|
|
46
|
+
descriptionFallback?: ElementRef<HTMLElement>;
|
|
47
|
+
/** The description's projected-nodes capture point. */
|
|
48
|
+
descriptionSlot?: ElementRef<HTMLElement>;
|
|
49
|
+
/** Whether the user opened the granular details (React's `showDetails`). */
|
|
50
|
+
showDetails: boolean;
|
|
51
|
+
/** React's `{' '}` between the description and the policy link. */
|
|
52
|
+
readonly leadingSpace = " ";
|
|
53
|
+
/** Per-instance counter backing the generated ids (React numbers `useId()` ids). */
|
|
54
|
+
private static nextId;
|
|
55
|
+
/** The details list's id, which the Customize/Hide details button's `aria-controls` names while the list renders. */
|
|
56
|
+
readonly detailsId: string;
|
|
57
|
+
/** Base of each category row's label/description ids, which name and describe that row's switch. */
|
|
58
|
+
private readonly nameBase;
|
|
59
|
+
/** The reactive i18n binding, read in the injection context. */
|
|
60
|
+
private readonly i18n;
|
|
61
|
+
/** The host element (the root `<div>`), for the null-render detach. */
|
|
62
|
+
private readonly el;
|
|
63
|
+
/** React's `useState` map: captured once, at mount. */
|
|
64
|
+
private readonly enabled;
|
|
65
|
+
/** Whether `[slot=title]` content was projected (read once). */
|
|
66
|
+
private hasTitleSlot;
|
|
67
|
+
/** Whether `[slot=description]` content was projected (read once). */
|
|
68
|
+
private hasDescriptionSlot;
|
|
69
|
+
/** Whether the node-props layout was applied (React renders it once). */
|
|
70
|
+
private nodeLayoutApplied;
|
|
71
|
+
/** Where the detached host lives, for the restore. */
|
|
72
|
+
private detachedParent;
|
|
73
|
+
/** The node the detached host is restored before. */
|
|
74
|
+
private detachedAnchor;
|
|
75
|
+
/**
|
|
76
|
+
* The current class map.
|
|
77
|
+
* @returns The UIClassMap.
|
|
78
|
+
*/
|
|
79
|
+
cm(): UIClassMap;
|
|
80
|
+
/** Reads React's `useState` initial enabled map, once the inputs are bound. */
|
|
81
|
+
ngOnInit(): void;
|
|
82
|
+
/**
|
|
83
|
+
* Reads the projected slots' presence (view queries resolve only at view
|
|
84
|
+
* init), applies the node-prop layout and the visible-state host detach.
|
|
85
|
+
*/
|
|
86
|
+
ngAfterViewInit(): void;
|
|
87
|
+
/** Re-reconciles after input writes (a props step) and state changes. */
|
|
88
|
+
ngDoCheck(): void;
|
|
89
|
+
/** Restores the host before Angular removes it (unmount). */
|
|
90
|
+
ngOnDestroy(): void;
|
|
91
|
+
/**
|
|
92
|
+
* Computes the banner's class list (React's `cm.cn(cm.stack(3), cm.sp('p', 4), className)`).
|
|
93
|
+
* @returns The class string.
|
|
94
|
+
*/
|
|
95
|
+
classes(): string;
|
|
96
|
+
/**
|
|
97
|
+
* The banner's inline style text (React's fixed-position surface).
|
|
98
|
+
* @returns The style attribute text.
|
|
99
|
+
*/
|
|
100
|
+
hostStyle(): string | null;
|
|
101
|
+
/**
|
|
102
|
+
* The translated dialog label (React's `aria-label`).
|
|
103
|
+
* @returns The label text.
|
|
104
|
+
*/
|
|
105
|
+
ariaLabel(): string;
|
|
106
|
+
/**
|
|
107
|
+
* The title heading's class (`cm.cn(cm.textSize('base'), cm.fontWeight('semibold'))`).
|
|
108
|
+
* @returns The class string.
|
|
109
|
+
*/
|
|
110
|
+
titleClasses(): string;
|
|
111
|
+
/**
|
|
112
|
+
* A category row's class (`cm.flex({ align: 'center', justify: 'between', gap: 'sm' })`).
|
|
113
|
+
* @returns The class string.
|
|
114
|
+
*/
|
|
115
|
+
rowClasses(): string;
|
|
116
|
+
/**
|
|
117
|
+
* A category's text column class (`cm.cn(cm.flex1, cm.stack(0))`).
|
|
118
|
+
* @returns The class string.
|
|
119
|
+
*/
|
|
120
|
+
textColumnClasses(): string;
|
|
121
|
+
/**
|
|
122
|
+
* A category label's class (`cm.cn(cm.textSize('sm'), cm.fontWeight('semibold'))`).
|
|
123
|
+
* @returns The class string.
|
|
124
|
+
*/
|
|
125
|
+
labelClasses(): string;
|
|
126
|
+
/**
|
|
127
|
+
* A category row's label id, which its switch is named by
|
|
128
|
+
* (React's `${nameId()}-${index}`).
|
|
129
|
+
* @param index - The category's index in the list.
|
|
130
|
+
* @returns The id.
|
|
131
|
+
*/
|
|
132
|
+
labelId(index: number): string;
|
|
133
|
+
/**
|
|
134
|
+
* A category row's description id, which its switch is described by
|
|
135
|
+
* (React's `${nameId()}-${index}-description`).
|
|
136
|
+
* @param index - The category's index in the list.
|
|
137
|
+
* @returns The id.
|
|
138
|
+
*/
|
|
139
|
+
descriptionId(index: number): string;
|
|
140
|
+
/**
|
|
141
|
+
* The footer's class (`cm.flex({ align: 'center', justify: 'end', gap: 'sm', wrap: 'wrap' })`).
|
|
142
|
+
* @returns The class string.
|
|
143
|
+
*/
|
|
144
|
+
footerClasses(): string;
|
|
145
|
+
/**
|
|
146
|
+
* The title input's text (React's `{title ?? t('cookieBanner.title')}`): the
|
|
147
|
+
* input for strings and numbers, the i18n default when it is nullish, and
|
|
148
|
+
* nothing while node content is projected.
|
|
149
|
+
* @returns The text to render.
|
|
150
|
+
*/
|
|
151
|
+
titleText(): string;
|
|
152
|
+
/**
|
|
153
|
+
* The description input's text (React's `{description ?? t('cookieBanner.description')}`).
|
|
154
|
+
* @returns The text to render.
|
|
155
|
+
*/
|
|
156
|
+
descriptionText(): string;
|
|
157
|
+
/**
|
|
158
|
+
* The policy link's label (React's `t('cookieBanner.learnMore')`).
|
|
159
|
+
* @returns The label text.
|
|
160
|
+
*/
|
|
161
|
+
learnMoreText(): string;
|
|
162
|
+
/**
|
|
163
|
+
* The Customize/Hide-details button's label.
|
|
164
|
+
* @returns The label text.
|
|
165
|
+
*/
|
|
166
|
+
detailsLabel(): string;
|
|
167
|
+
/**
|
|
168
|
+
* The Reject button's label.
|
|
169
|
+
* @returns The label text.
|
|
170
|
+
*/
|
|
171
|
+
rejectText(): string;
|
|
172
|
+
/**
|
|
173
|
+
* The Save button's label.
|
|
174
|
+
* @returns The label text.
|
|
175
|
+
*/
|
|
176
|
+
saveText(): string;
|
|
177
|
+
/**
|
|
178
|
+
* The Accept button's label.
|
|
179
|
+
* @returns The label text.
|
|
180
|
+
*/
|
|
181
|
+
acceptText(): string;
|
|
182
|
+
/**
|
|
183
|
+
* Whether React's `categories &&` branches render (a nullish list does not).
|
|
184
|
+
* @returns True when categories were supplied.
|
|
185
|
+
*/
|
|
186
|
+
hasCategories(): boolean;
|
|
187
|
+
/**
|
|
188
|
+
* Whether React's `showDetails && categories && onSave` Save branch renders.
|
|
189
|
+
* @returns True when the Save button renders.
|
|
190
|
+
*/
|
|
191
|
+
saveVisible(): boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Whether a value is one of the cases' projected node templates.
|
|
194
|
+
* @param value - The field value.
|
|
195
|
+
* @returns True for a projected node template.
|
|
196
|
+
*/
|
|
197
|
+
isTemplate(value: unknown): value is TemplateRef<unknown>;
|
|
198
|
+
/**
|
|
199
|
+
* The value as a template (call under {@link CookieBanner.isTemplate}).
|
|
200
|
+
* @param value - The field value.
|
|
201
|
+
* @returns The template.
|
|
202
|
+
*/
|
|
203
|
+
asTemplate(value: unknown): TemplateRef<unknown>;
|
|
204
|
+
/**
|
|
205
|
+
* Whether a category's switch is on (React's `!!enabled[c.id] || !!c.required`).
|
|
206
|
+
* @param category - The category.
|
|
207
|
+
* @returns Whether the switch is checked.
|
|
208
|
+
*/
|
|
209
|
+
isChecked(category: CookieCategory): boolean;
|
|
210
|
+
/** Flips the details block, as React's `setShowDetails((x) => !x)` does. */
|
|
211
|
+
toggleDetails(): void;
|
|
212
|
+
/**
|
|
213
|
+
* Toggles one category, as React's `setEnabled` does.
|
|
214
|
+
* @param category - The category whose switch changed.
|
|
215
|
+
* @param event - The native change event the UI Switch re-emitted.
|
|
216
|
+
*/
|
|
217
|
+
toggle(category: CookieCategory, event: Event): void;
|
|
218
|
+
/**
|
|
219
|
+
* The enabled categories as React's plain `Record<string, boolean>`.
|
|
220
|
+
* @returns The enabled map.
|
|
221
|
+
*/
|
|
222
|
+
enabledMap(): Record<string, boolean>;
|
|
223
|
+
/** Calls `onRejectAll`, then `onDismiss`. */
|
|
224
|
+
reject(): void;
|
|
225
|
+
/** Calls `onSave(enabled)`, then `onDismiss`. */
|
|
226
|
+
save(): void;
|
|
227
|
+
/** Calls `onAcceptAll`, then `onDismiss`. */
|
|
228
|
+
accept(): void;
|
|
229
|
+
/**
|
|
230
|
+
* Calls the optional callback then the shared onDismiss handler.
|
|
231
|
+
* @param fn - The mode-specific callback.
|
|
232
|
+
*/
|
|
233
|
+
private dismissAfter;
|
|
234
|
+
/** Applies React's node-prop DOM: whichever capture span React would render is unwrapped. */
|
|
235
|
+
private applyNodeProps;
|
|
236
|
+
/**
|
|
237
|
+
* Removes the host element from the DOM while React would render null
|
|
238
|
+
* (`visible === false`), and restores it when the banner is shown again.
|
|
239
|
+
*/
|
|
240
|
+
private syncHostVisibility;
|
|
241
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CookieBanner, never>;
|
|
242
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<CookieBanner, "div[mol-cookie-banner]", never, { "categories": { "alias": "categories"; "required": false; }; "onAcceptAll": { "alias": "onAcceptAll"; "required": false; }; "onRejectAll": { "alias": "onRejectAll"; "required": false; }; "onSave": { "alias": "onSave"; "required": false; }; "title": { "alias": "title"; "required": false; }; "description": { "alias": "description"; "required": false; }; "policyHref": { "alias": "policyHref"; "required": false; }; "visible": { "alias": "visible"; "required": false; }; "onDismiss": { "alias": "onDismiss"; "required": false; }; "className": { "alias": "className"; "required": false; }; }, {}, never, ["[slot=title]", "[slot=description]"], true, never>;
|
|
243
|
+
}
|
|
244
|
+
//# sourceMappingURL=cookie-banner.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cookie-banner.component.d.ts","sourceRoot":"","sources":["../src/cookie-banner.component.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,OAAO,EACZ,UAAU,EAEV,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,WAAW,EAEjB,MAAM,eAAe,CAAA;AAGtB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAKlD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;;AA4BhD;;;;;;;;;;;;;;GAcG;AACH,qBAyBa,YAAa,YAAW,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,SAAS;IAC5E,2EAA2E;IAC3E,UAAU,CAAC,EAAE,cAAc,EAAE,CAAA;IAC7B,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,mDAAmD;IACnD,WAAW,CAAC,EAAE,MAAM,IAAI,CAAA;IACxB,iDAA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