@molecule/app-cookie-banner-vue 0.0.0-stage → 1.1.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.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,215 @@
1
- # Temporary Holding Version
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-11-18T23:41:41.042Z
7
+ -->
2
8
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
9
+ # @molecule/app-cookie-banner-vue
10
+
11
+ Vue GDPR cookie consent banner.
12
+
13
+ Exports `<CookieBanner>` and the `CookieCategory` type. It is the Vue
14
+ counterpart of `@molecule/app-cookie-banner-react`: the same props (React
15
+ names), the same DOM for the same input, and the same callback calls.
16
+
17
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
18
+ > It is written to be read by coding agents as much as by people, and is generated from this
19
+ > package's source — edit `src/index.ts` JSDoc, not this file.
20
+
21
+ ## Quick Start
22
+
23
+ ```ts
24
+ import { createApp, defineComponent, h, ref } from 'vue'
25
+ import { CookieBanner } from '@molecule/app-cookie-banner-vue'
26
+
27
+ const App = defineComponent({
28
+ setup() {
29
+ const consentGiven = ref(false)
30
+ return () =>
31
+ h(CookieBanner, {
32
+ visible: !consentGiven.value,
33
+ policyHref: '/privacy',
34
+ categories: [
35
+ { id: 'essential', label: 'Essential', required: true },
36
+ { id: 'analytics', label: 'Analytics', defaultEnabled: false },
37
+ ],
38
+ onAcceptAll: () => saveConsent('all'),
39
+ onRejectAll: () => saveConsent('essential'),
40
+ onSave: (enabled) => saveConsent(enabled),
41
+ onDismiss: () => {
42
+ consentGiven.value = true
43
+ },
44
+ })
45
+ },
46
+ })
47
+
48
+ createApp(App).mount('#app')
49
+ ```
50
+
51
+ ## Type
52
+
53
+ `feature`
54
+
55
+ ## Installation
56
+
57
+ ```bash
58
+ npm install @molecule/app-cookie-banner-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
59
+ ```
60
+
61
+ ## API
62
+
63
+ ### Interfaces
64
+
65
+ #### `CookieCategory`
66
+
67
+ Describes a single cookie category offered in the granular consent UI.
68
+
69
+ ```typescript
70
+ interface CookieCategory {
71
+ /** Stable category id (also the key of the consent map). */
72
+ id: string
73
+ /** Display label (a VNode, a string, or null). */
74
+ label: VNodeChild
75
+ /** Optional explanation (a VNode, a string, or null). */
76
+ description?: VNodeChild
77
+ /** Whether this category is required (always on). */
78
+ required?: boolean
79
+ /** Initial enabled state. */
80
+ defaultEnabled?: boolean
81
+ }
82
+ ```
83
+
84
+ #### `CookieBannerProps`
85
+
86
+ Props accepted by {@link CookieBanner} — the same props
87
+ `@molecule/app-cookie-banner-react` accepts. Node-valued props (`title`,
88
+ `description`, category `label`/`description`) take a Vue `VNodeChild` (or a
89
+ string) instead of a React node.
90
+
91
+ ```typescript
92
+ interface CookieBannerProps {
93
+ /** Cookie categories to offer (omit for a simple accept/reject banner). */
94
+ categories?: CookieCategory[]
95
+ /** Called when accept-all is clicked. */
96
+ onAcceptAll?: () => void
97
+ /** Called when reject-non-essential is clicked. */
98
+ onRejectAll?: () => void
99
+ /** Called when "Save preferences" is clicked. */
100
+ onSave?: (enabled: Record<string, boolean>) => void
101
+ /** Optional title. */
102
+ title?: VNodeChild
103
+ /** Optional description. */
104
+ description?: VNodeChild
105
+ /** Privacy policy link URL. */
106
+ policyHref?: string
107
+ /** Whether the banner is visible (controlled). */
108
+ visible?: boolean
109
+ /** Called when dismissed via Save / Accept / Reject. */
110
+ onDismiss?: () => void
111
+ /** Extra classes. */
112
+ className?: string
113
+ }
114
+ ```
115
+
116
+ ### Constants
117
+
118
+ #### `CookieBanner`
119
+
120
+ GDPR / cookie-consent banner. Two modes:
121
+
122
+ - Simple: Accept / Reject buttons.
123
+ - Granular: Per-category toggles + "Save preferences".
124
+
125
+ Apps own the actual cookie storage logic. Category toggle state is captured
126
+ from `categories` once, at mount — later prop changes do not reset it.
127
+
128
+ ```typescript
129
+ const CookieBanner: DefineComponent<
130
+ ExtractPropTypes<{
131
+ categories: { type: PropType<CookieCategory[]>; default: undefined }
132
+ onAcceptAll: PropType<CookieBannerProps['onAcceptAll']>
133
+ onRejectAll: PropType<CookieBannerProps['onRejectAll']>
134
+ onSave: PropType<CookieBannerProps['onSave']>
135
+ title: null
136
+ description: null
137
+ policyHref: StringConstructor
138
+ visible: { type: PropType<boolean | undefined>; default: boolean }
139
+ onDismiss: PropType<CookieBannerProps['onDismiss']>
140
+ className: StringConstructor
141
+ }>,
142
+ () => VNode | null,
143
+ {},
144
+ {},
145
+ {},
146
+ ComponentOptionsMixin,
147
+ ComponentOptionsMixin,
148
+ {},
149
+ string,
150
+ PublicProps,
151
+ Readonly<
152
+ ExtractPropTypes<{
153
+ categories: { type: PropType<CookieCategory[]>; default: undefined }
154
+ onAcceptAll: PropType<CookieBannerProps['onAcceptAll']>
155
+ onRejectAll: PropType<CookieBannerProps['onRejectAll']>
156
+ onSave: PropType<CookieBannerProps['onSave']>
157
+ title: null
158
+ description: null
159
+ policyHref: StringConstructor
160
+ visible: { type: PropType<boolean | undefined>; default: boolean }
161
+ onDismiss: PropType<CookieBannerProps['onDismiss']>
162
+ className: StringConstructor
163
+ }>
164
+ > &
165
+ Readonly<{}>,
166
+ { categories: CookieCategory[]; visible: boolean | undefined },
167
+ {},
168
+ {},
169
+ {},
170
+ string,
171
+ ComponentProvideOptions,
172
+ true,
173
+ {},
174
+ any
175
+ >
176
+ ```
177
+
178
+ - `props` — Component props (see {@link CookieBannerProps}).
179
+
180
+ **Returns:** The banner component.
181
+
182
+ ## Injection Notes
183
+
184
+ ### Requirements
185
+
186
+ Peer dependencies:
187
+
188
+ - `@molecule/app-ui` ^1.0.1
189
+ - `@molecule/app-ui-vue` ^1.1.0
190
+ - `@molecule/app-vue` ^3.5.0
191
+ - `vue` ^3.4.0
192
+
193
+ ### Runtime Dependencies
194
+
195
+ - `@molecule/app-ui`
196
+ - `@molecule/app-ui-vue`
197
+ - `@molecule/app-vue`
198
+ - `vue`
199
+
200
+ The banner is UI-only — it stores nothing. `onAcceptAll` / `onRejectAll`
201
+ receive NO arguments (derive "all on"/"essential only" yourself); only
202
+ `onSave` receives the per-category `Record<string, boolean>`, and the
203
+ "Save preferences" button renders only when `categories` AND `onSave` are
204
+ provided and the user opened "Customize". Category toggle state is
205
+ captured from `categories` on first render — later prop changes do not
206
+ reset it. Visibility is controlled: keep `visible` false once consent is
207
+ stored. Text uses `cookieBanner.*` i18n keys (companion bond:
208
+ `@molecule/app-locales-cookie-banner`); `title`/`description`/category
209
+ labels you pass in should already be translated. Node-valued props
210
+ (`title`, `description`) arrive as a prop AND as a same-named slot;
211
+ the component accepts either.
212
+
213
+ ## Translations
214
+
215
+ Translation strings are provided by `@molecule/app-locales-cookie-banner`.
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Vue GDPR cookie-consent banner.
3
+ *
4
+ * Vue counterpart of `@molecule/app-cookie-banner-react`'s `CookieBanner` —
5
+ * the same props (React names), the same DOM for the same input, the same
6
+ * callback calls. Two modes: Accept / Reject only, or per-category switches
7
+ * behind "Customize" when `categories` are supplied.
8
+ *
9
+ * @module
10
+ */
11
+ import { type PropType, type VNode } from 'vue';
12
+ import type { CookieBannerProps, CookieCategory } from './types.js';
13
+ /**
14
+ * GDPR / cookie-consent banner. Two modes:
15
+ * - Simple: Accept / Reject buttons.
16
+ * - Granular: Per-category toggles + "Save preferences".
17
+ *
18
+ * Apps own the actual cookie storage logic. Category toggle state is captured
19
+ * from `categories` once, at mount — later prop changes do not reset it.
20
+ *
21
+ * @param props - Component props (see {@link CookieBannerProps}).
22
+ * @returns The banner component.
23
+ */
24
+ export declare const CookieBanner: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
25
+ categories: {
26
+ type: PropType<CookieCategory[]>;
27
+ default: undefined;
28
+ };
29
+ onAcceptAll: PropType<CookieBannerProps["onAcceptAll"]>;
30
+ onRejectAll: PropType<CookieBannerProps["onRejectAll"]>;
31
+ onSave: PropType<CookieBannerProps["onSave"]>;
32
+ title: null;
33
+ description: null;
34
+ policyHref: StringConstructor;
35
+ visible: {
36
+ type: PropType<boolean | undefined>;
37
+ default: boolean;
38
+ };
39
+ onDismiss: PropType<CookieBannerProps["onDismiss"]>;
40
+ className: StringConstructor;
41
+ }>, () => VNode | null, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
42
+ categories: {
43
+ type: PropType<CookieCategory[]>;
44
+ default: undefined;
45
+ };
46
+ onAcceptAll: PropType<CookieBannerProps["onAcceptAll"]>;
47
+ onRejectAll: PropType<CookieBannerProps["onRejectAll"]>;
48
+ onSave: PropType<CookieBannerProps["onSave"]>;
49
+ title: null;
50
+ description: null;
51
+ policyHref: StringConstructor;
52
+ visible: {
53
+ type: PropType<boolean | undefined>;
54
+ default: boolean;
55
+ };
56
+ onDismiss: PropType<CookieBannerProps["onDismiss"]>;
57
+ className: StringConstructor;
58
+ }>> & Readonly<{}>, {
59
+ categories: CookieCategory[];
60
+ visible: boolean | undefined;
61
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
62
+ //# sourceMappingURL=CookieBanner.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieBanner.d.ts","sourceRoot":"","sources":["../src/CookieBanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAGL,KAAK,QAAQ,EAIb,KAAK,KAAK,EAEX,MAAM,KAAK,CAAA;AAMZ,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AA0DnE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY;;cAIJ,QAAQ,CAAC,cAAc,EAAE,CAAC;;;iBAGlB,QAAQ,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;iBAC1C,QAAQ,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;YAC/C,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;;;;;cAKtC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;;;eAGzB,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;;UAqCpD,KAAK,GAAG,IAAI;;cAlDN,QAAQ,CAAC,cAAc,EAAE,CAAC;;;iBAGlB,QAAQ,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;iBAC1C,QAAQ,CAAC,iBAAiB,CAAC,aAAa,CAAC,CAAC;YAC/C,QAAQ,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;;;;;cAKtC,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAC;;;eAGzB,QAAQ,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC;;;;;4EA+MjE,CAAA"}
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Vue GDPR cookie-consent banner.
3
+ *
4
+ * Vue counterpart of `@molecule/app-cookie-banner-react`'s `CookieBanner` —
5
+ * the same props (React names), the same DOM for the same input, the same
6
+ * callback calls. Two modes: Accept / Reject only, or per-category switches
7
+ * behind "Customize" when `categories` are supplied.
8
+ *
9
+ * @module
10
+ */
11
+ import { defineComponent, h, ref, toRaw, useId, } from 'vue';
12
+ import { getClassMap } from '@molecule/app-ui';
13
+ import { Button, Switch } from '@molecule/app-ui-vue';
14
+ import { useTranslation } from '@molecule/app-vue';
15
+ /**
16
+ * Normalizes a node-valued prop to a child list: an array stays as it is, a
17
+ * single node becomes a one-item list, and the values React renders as nothing
18
+ * (`null`, `undefined`, `false`) contribute nothing.
19
+ *
20
+ * The value is unwrapped with `toRaw` first: a node carried inside a data prop
21
+ * may sit in a reactive object (Vue deep-proxies props an app keeps reactive),
22
+ * and rendering a proxied VNode both tracks its properties in the render effect
23
+ * and writes them back while the VNode mounts — a reactive loop. Vue keeps
24
+ * VNodes out of reactivity (its own `markRaw` guidance), so render the
25
+ * underlying node.
26
+ *
27
+ * @param value - The node-valued field.
28
+ * @returns The children to render.
29
+ */
30
+ const childList = (value) => {
31
+ const raw = toRaw(value);
32
+ if (raw === null || raw === undefined || raw === false)
33
+ return [];
34
+ return Array.isArray(raw) ? raw : [raw];
35
+ };
36
+ /**
37
+ * Resolves a node-valued prop that may also arrive as a same-named slot: the
38
+ * slot wins, then a non-nullish prop, and the fallback contributes when
39
+ * neither is given.
40
+ *
41
+ * @param slot - The slot render function, when the caller passed the slot.
42
+ * @param prop - The prop value, when the caller passed the prop.
43
+ * @param fallback - The value React renders when the prop is nullish.
44
+ * @returns The children to render.
45
+ */
46
+ const slotOrProp = (slot, prop, fallback) => {
47
+ if (slot)
48
+ return slot();
49
+ return prop != null ? [prop] : [fallback()];
50
+ };
51
+ /** React's inline style for the banner, written the way React writes it. */
52
+ const bannerStyle = {
53
+ position: 'fixed',
54
+ left: '16px',
55
+ right: '16px',
56
+ bottom: '16px',
57
+ zIndex: '60',
58
+ background: 'var(--color-surface, #fff)',
59
+ border: '1px solid rgba(0,0,0,0.1)',
60
+ borderRadius: '12px',
61
+ boxShadow: '0 12px 36px rgba(0,0,0,0.18)',
62
+ maxWidth: '720px',
63
+ marginLeft: 'auto',
64
+ marginRight: 'auto',
65
+ };
66
+ /**
67
+ * GDPR / cookie-consent banner. Two modes:
68
+ * - Simple: Accept / Reject buttons.
69
+ * - Granular: Per-category toggles + "Save preferences".
70
+ *
71
+ * Apps own the actual cookie storage logic. Category toggle state is captured
72
+ * from `categories` once, at mount — later prop changes do not reset it.
73
+ *
74
+ * @param props - Component props (see {@link CookieBannerProps}).
75
+ * @returns The banner component.
76
+ */
77
+ export const CookieBanner = defineComponent({
78
+ name: 'CookieBanner',
79
+ props: {
80
+ categories: {
81
+ type: Array,
82
+ default: undefined,
83
+ },
84
+ onAcceptAll: Function,
85
+ onRejectAll: Function,
86
+ onSave: Function,
87
+ title: null,
88
+ description: null,
89
+ policyHref: String,
90
+ visible: {
91
+ type: Boolean,
92
+ default: true,
93
+ },
94
+ onDismiss: Function,
95
+ className: String,
96
+ },
97
+ setup(props, { slots }) {
98
+ const cm = getClassMap();
99
+ const { t } = useTranslation();
100
+ // Generated ids (never derived from data): the details list's id, wired to
101
+ // the Customize/Hide details button's `aria-controls`, and the base of each
102
+ // category row's label/description ids, which name and describe that row's
103
+ // switch so every `role="switch"` has an accessible name.
104
+ const detailsId = useId();
105
+ const nameId = useId();
106
+ const showDetails = ref(false);
107
+ // React's `useState` initializer: captured once, from the mount-time
108
+ // categories — a later `categories` change keeps the toggled state.
109
+ const enabled = ref({});
110
+ for (const category of props.categories ?? [])
111
+ enabled.value[category.id] = category.required === true || !!category.defaultEnabled;
112
+ /**
113
+ * Calls the optional callback then fires the shared onDismiss handler.
114
+ * @param fn - The mode-specific callback.
115
+ */
116
+ function dismissAfter(fn) {
117
+ fn?.();
118
+ props.onDismiss?.();
119
+ }
120
+ /**
121
+ * Flips one category's enabled state, as React's `setEnabled` does.
122
+ * @param id - The category id.
123
+ * @param checked - The switch's new checked state.
124
+ */
125
+ function setCategory(id, checked) {
126
+ enabled.value = { ...enabled.value, [id]: checked };
127
+ }
128
+ return () => {
129
+ if (!props.visible)
130
+ return null;
131
+ const descriptionChildren = [
132
+ ...slotOrProp(slots.description, props.description, () => t('cookieBanner.description', {}, { defaultValue: 'We use cookies to improve your experience and analyse traffic.' })),
133
+ ];
134
+ if (props.policyHref) {
135
+ descriptionChildren.push(' ', h('a', { href: props.policyHref, class: cm.link }, t('cookieBanner.learnMore', {}, { defaultValue: 'Learn more' })), '.');
136
+ }
137
+ const footer = [];
138
+ if (props.categories) {
139
+ footer.push(h(Button, {
140
+ variant: 'ghost',
141
+ size: 'sm',
142
+ // The button names the list only while the list renders (the
143
+ // same `showDetails && categories` branch that renders it).
144
+ 'aria-expanded': showDetails.value,
145
+ 'aria-controls': showDetails.value && props.categories ? detailsId : undefined,
146
+ onClick: () => {
147
+ showDetails.value = !showDetails.value;
148
+ },
149
+ }, {
150
+ default: () => [
151
+ showDetails.value
152
+ ? t('cookieBanner.hideDetails', {}, { defaultValue: 'Hide details' })
153
+ : t('cookieBanner.customize', {}, { defaultValue: 'Customize' }),
154
+ ],
155
+ }));
156
+ }
157
+ footer.push(h(Button, {
158
+ variant: 'ghost',
159
+ onClick: () => {
160
+ dismissAfter(props.onRejectAll);
161
+ },
162
+ }, { default: () => [t('cookieBanner.reject', {}, { defaultValue: 'Reject all' })] }));
163
+ const save = props.onSave;
164
+ if (showDetails.value && props.categories && save) {
165
+ footer.push(h(Button, {
166
+ variant: 'outline',
167
+ onClick: () => {
168
+ dismissAfter(() => save(enabled.value));
169
+ },
170
+ }, { default: () => [t('cookieBanner.save', {}, { defaultValue: 'Save preferences' })] }));
171
+ }
172
+ footer.push(h(Button, {
173
+ variant: 'solid',
174
+ color: 'primary',
175
+ onClick: () => {
176
+ dismissAfter(props.onAcceptAll);
177
+ },
178
+ }, { default: () => [t('cookieBanner.accept', {}, { defaultValue: 'Accept all' })] }));
179
+ const details = showDetails.value && props.categories
180
+ ? h('div', { id: detailsId, class: cm.stack(2) }, props.categories.map((category, index) => h('div', {
181
+ key: category.id,
182
+ class: cm.flex({ align: 'center', justify: 'between', gap: 'sm' }),
183
+ }, [
184
+ h('div', { class: cm.cn(cm.flex1, cm.stack(0)) }, [
185
+ h('span', {
186
+ id: `${nameId}-${index}`,
187
+ class: cm.cn(cm.textSize('sm'), cm.fontWeight('semibold')),
188
+ }, childList(category.label)),
189
+ category.description
190
+ ? h('span', {
191
+ id: `${nameId}-${index}-description`,
192
+ class: cm.textSize('xs'),
193
+ }, childList(category.description))
194
+ : null,
195
+ ]),
196
+ h(Switch, {
197
+ checked: !!enabled.value[category.id] || !!category.required,
198
+ disabled: category.required,
199
+ 'aria-labelledby': `${nameId}-${index}`,
200
+ 'aria-describedby': category.description
201
+ ? `${nameId}-${index}-description`
202
+ : undefined,
203
+ onChange: (event) => {
204
+ setCategory(category.id, event.target.checked);
205
+ },
206
+ }),
207
+ ])))
208
+ : null;
209
+ return h('div', {
210
+ role: 'dialog',
211
+ 'aria-label': t('cookieBanner.title', {}, { defaultValue: 'Cookie preferences' }),
212
+ class: cm.cn(cm.stack(3), cm.sp('p', 4), props.className),
213
+ style: bannerStyle,
214
+ }, [
215
+ h('header', { class: cm.stack(1) }, [
216
+ h('h3', { class: cm.cn(cm.textSize('base'), cm.fontWeight('semibold')) }, slotOrProp(slots.title, props.title, () => t('cookieBanner.title', {}, { defaultValue: 'Cookie preferences' }))),
217
+ h('p', { class: cm.textSize('sm') }, descriptionChildren),
218
+ ]),
219
+ details,
220
+ h('footer', { class: cm.flex({ align: 'center', justify: 'end', gap: 'sm', wrap: 'wrap' }) }, footer),
221
+ ]);
222
+ };
223
+ },
224
+ });
225
+ //# sourceMappingURL=CookieBanner.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieBanner.js","sourceRoot":"","sources":["../src/CookieBanner.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EACL,eAAe,EACf,CAAC,EAED,GAAG,EACH,KAAK,EACL,KAAK,GAGN,MAAM,KAAK,CAAA;AAEZ,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAIlD;;;;;;;;;;;;;;GAcG;AACH,MAAM,SAAS,GAAG,CAAC,KAAoC,EAAgB,EAAE;IACvE,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAA;IACxB,IAA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AAC;iBAC1D,CAAC;gBACF,OAAO;gBACP,CAAC,CACC,QAAQ,EACR,EAAE,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,EAChF,MAAM,CACP;aACF,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Vue GDPR cookie consent banner.
3
+ *
4
+ * Exports `<CookieBanner>` and the `CookieCategory` type. It is the Vue
5
+ * counterpart of `@molecule/app-cookie-banner-react`: the same props (React
6
+ * names), the same DOM for the same input, and the same callback calls.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { createApp, defineComponent, h, ref } from 'vue'
11
+ * import { CookieBanner } from '@molecule/app-cookie-banner-vue'
12
+ *
13
+ * const App = defineComponent({
14
+ * setup() {
15
+ * const consentGiven = ref(false)
16
+ * return () =>
17
+ * h(CookieBanner, {
18
+ * visible: !consentGiven.value,
19
+ * policyHref: '/privacy',
20
+ * categories: [
21
+ * { id: 'essential', label: 'Essential', required: true },
22
+ * { id: 'analytics', label: 'Analytics', defaultEnabled: false },
23
+ * ],
24
+ * onAcceptAll: () => saveConsent('all'),
25
+ * onRejectAll: () => saveConsent('essential'),
26
+ * onSave: (enabled) => saveConsent(enabled),
27
+ * onDismiss: () => {
28
+ * consentGiven.value = true
29
+ * },
30
+ * })
31
+ * },
32
+ * })
33
+ *
34
+ * createApp(App).mount('#app')
35
+ * ```
36
+ *
37
+ * @remarks
38
+ * The banner is UI-only — it stores nothing. `onAcceptAll` / `onRejectAll`
39
+ * receive NO arguments (derive "all on"/"essential only" yourself); only
40
+ * `onSave` receives the per-category `Record<string, boolean>`, and the
41
+ * "Save preferences" button renders only when `categories` AND `onSave` are
42
+ * provided and the user opened "Customize". Category toggle state is
43
+ * captured from `categories` on first render — later prop changes do not
44
+ * reset it. Visibility is controlled: keep `visible` false once consent is
45
+ * stored. Text uses `cookieBanner.*` i18n keys (companion bond:
46
+ * `@molecule/app-locales-cookie-banner`); `title`/`description`/category
47
+ * labels you pass in should already be translated. Node-valued props
48
+ * (`title`, `description`) arrive as a prop AND as a same-named slot;
49
+ * the component accepts either.
50
+ *
51
+ * @module
52
+ */
53
+ export * from './CookieBanner.js';
54
+ export * from './types.js';
55
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Vue GDPR cookie consent banner.
3
+ *
4
+ * Exports `<CookieBanner>` and the `CookieCategory` type. It is the Vue
5
+ * counterpart of `@molecule/app-cookie-banner-react`: the same props (React
6
+ * names), the same DOM for the same input, and the same callback calls.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { createApp, defineComponent, h, ref } from 'vue'
11
+ * import { CookieBanner } from '@molecule/app-cookie-banner-vue'
12
+ *
13
+ * const App = defineComponent({
14
+ * setup() {
15
+ * const consentGiven = ref(false)
16
+ * return () =>
17
+ * h(CookieBanner, {
18
+ * visible: !consentGiven.value,
19
+ * policyHref: '/privacy',
20
+ * categories: [
21
+ * { id: 'essential', label: 'Essential', required: true },
22
+ * { id: 'analytics', label: 'Analytics', defaultEnabled: false },
23
+ * ],
24
+ * onAcceptAll: () => saveConsent('all'),
25
+ * onRejectAll: () => saveConsent('essential'),
26
+ * onSave: (enabled) => saveConsent(enabled),
27
+ * onDismiss: () => {
28
+ * consentGiven.value = true
29
+ * },
30
+ * })
31
+ * },
32
+ * })
33
+ *
34
+ * createApp(App).mount('#app')
35
+ * ```
36
+ *
37
+ * @remarks
38
+ * The banner is UI-only — it stores nothing. `onAcceptAll` / `onRejectAll`
39
+ * receive NO arguments (derive "all on"/"essential only" yourself); only
40
+ * `onSave` receives the per-category `Record<string, boolean>`, and the
41
+ * "Save preferences" button renders only when `categories` AND `onSave` are
42
+ * provided and the user opened "Customize". Category toggle state is
43
+ * captured from `categories` on first render — later prop changes do not
44
+ * reset it. Visibility is controlled: keep `visible` false once consent is
45
+ * stored. Text uses `cookieBanner.*` i18n keys (companion bond:
46
+ * `@molecule/app-locales-cookie-banner`); `title`/`description`/category
47
+ * labels you pass in should already be translated. Node-valued props
48
+ * (`title`, `description`) arrive as a prop AND as a same-named slot;
49
+ * the component accepts either.
50
+ *
51
+ * @module
52
+ */
53
+ export * from './CookieBanner.js';
54
+ export * from './types.js';
55
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AAEH,cAAc,mBAAmB,CAAA;AACjC,cAAc,YAAY,CAAA"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Types for the Vue GDPR cookie-consent banner.
3
+ *
4
+ * @module
5
+ */
6
+ import type { VNodeChild } from 'vue';
7
+ /** Describes a single cookie category offered in the granular consent UI. */
8
+ export interface CookieCategory {
9
+ /** Stable category id (also the key of the consent map). */
10
+ id: string;
11
+ /** Display label (a VNode, a string, or null). */
12
+ label: VNodeChild;
13
+ /** Optional explanation (a VNode, a string, or null). */
14
+ description?: VNodeChild;
15
+ /** Whether this category is required (always on). */
16
+ required?: boolean;
17
+ /** Initial enabled state. */
18
+ defaultEnabled?: boolean;
19
+ }
20
+ /**
21
+ * Props accepted by {@link CookieBanner} — the same props
22
+ * `@molecule/app-cookie-banner-react` accepts. Node-valued props (`title`,
23
+ * `description`, category `label`/`description`) take a Vue `VNodeChild` (or a
24
+ * string) instead of a React node.
25
+ */
26
+ export interface CookieBannerProps {
27
+ /** Cookie categories to offer (omit for a simple accept/reject banner). */
28
+ categories?: CookieCategory[];
29
+ /** Called when accept-all is clicked. */
30
+ onAcceptAll?: () => void;
31
+ /** Called when reject-non-essential is clicked. */
32
+ onRejectAll?: () => void;
33
+ /** Called when "Save preferences" is clicked. */
34
+ onSave?: (enabled: Record<string, boolean>) => void;
35
+ /** Optional title. */
36
+ title?: VNodeChild;
37
+ /** Optional description. */
38
+ description?: VNodeChild;
39
+ /** Privacy policy link URL. */
40
+ policyHref?: string;
41
+ /** Whether the banner is visible (controlled). */
42
+ visible?: boolean;
43
+ /** Called when dismissed via Save / Accept / Reject. */
44
+ onDismiss?: () => void;
45
+ /** Extra classes. */
46
+ className?: string;
47
+ }
48
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAErC,6EAA6E;AAC7E,MAAM,WAAW,cAAc;IAC7B,4DAA4D;IAC5D,EAAE,EAAE,MAAM,CAAA;IACV,kDAAkD;IAClD,KAAK,EAAE,UAAU,CAAA;IACjB,yDAAyD;IACzD,WAAW,CAAC,EAAE,UAAU,CAAA;IACxB,qDAAqD;IACrD,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,6BAA6B;IAC7B,cAAc,CAAC,EAAE,OAAO,CAAA;CACzB;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC,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,iDAAiD;IACjD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAA;IACnD,sBAAsB;IACtB,KAAK,CAAC,EAAE,UAAU,CAAA;IAClB,4BAA4B;IAC5B,WAAW,CAAC,EAAE,UAAU,CAAA;IACxB,+BAA+B;IAC/B,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kDAAkD;IAClD,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,wDAAwD;IACxD,SAAS,CAAC,EAAE,MAAM,IAAI,CAAA;IACtB,qBAAqB;IACrB,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Types for the Vue GDPR cookie-consent banner.
3
+ *
4
+ * @module
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG"}
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "@molecule/app-cookie-banner-vue",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.1.0",
4
+ "description": "GDPR / cookie consent banner with accept/reject + per-category controls",
5
+ "homepage": "https://www.molecule.dev/packages/app-cookie-banner-vue",
6
+ "type": "module",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist",
17
+ "README.md"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "dev": "vue-tsc --watch",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "keywords": [
26
+ "molecule",
27
+ "cookie-banner",
28
+ "vue"
29
+ ],
30
+ "author": "Molecule Dev, Inc. (https://molecule.dev)",
31
+ "license": "Apache-2.0",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/molecule-dev/molecule.git",
35
+ "directory": "packages/app/features/cookie-banner-vue"
36
+ },
37
+ "engines": {
38
+ "node": ">=20"
39
+ },
40
+ "bugs": "https://github.com/molecule-dev/molecule/issues",
41
+ "publishConfig": {
42
+ "access": "public"
43
+ },
44
+ "peerDependencies": {
45
+ "@molecule/app-ui": "^1.0.1",
46
+ "@molecule/app-ui-vue": "^1.1.0",
47
+ "@molecule/app-vue": "^3.5.0",
48
+ "vue": "^3.4.0"
49
+ },
50
+ "devDependencies": {
51
+ "@molecule/app-framework-conformance": "0.0.0",
52
+ "@molecule/app-i18n": "1.2.2",
53
+ "@molecule/app-icons": "1.0.4",
54
+ "@molecule/app-ui": "1.4.0",
55
+ "@molecule/app-ui-vue": "1.1.5",
56
+ "@molecule/app-vue": "3.7.2",
57
+ "@types/node": "26.6.5",
58
+ "jsdom": "30.1.3",
59
+ "typescript": "6.0.3",
60
+ "vite": "8.3.5",
61
+ "vitest": "4.1.12",
62
+ "vue": "3.5.44",
63
+ "vue-tsc": "3.3.13"
64
+ }
65
+ }