@usequeek/theme-kit 0.4.0 → 0.5.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/README.md +8 -0
- package/apps/apps.css +37 -7
- package/apps/consent-preferences-link.tsx +2 -1
- package/apps/use-analytics-consent.ts +63 -14
- package/demo.ts +3 -2
- package/package.json +1 -1
- package/types/vendor.ts +5 -0
package/README.md
CHANGED
|
@@ -590,6 +590,14 @@ the footer control live in the kit so every theme gets them:
|
|
|
590
590
|
ids from `config.apps.analytics` (the patterns are exported too); an id that
|
|
591
591
|
fails its pattern counts as not set.
|
|
592
592
|
|
|
593
|
+
`config.apps.consent_banner` (typed in `types/vendor.ts`) carries the store's own `message` (replaces the banner's lead sentence) and `show` (`required` or `everywhere`); the storefront reads them.
|
|
594
|
+
|
|
595
|
+
`ConsentRegimeProvider` (`.../apps/use-analytics-consent`) takes `required`. The storefront sets it per request (the
|
|
596
|
+
visitor's country, the store's own `show` setting). Without it every shopper must answer. With `required={false}` a shopper
|
|
597
|
+
with no stored answer reads as granted for both categories (nothing is written to the record), Global Privacy Control still
|
|
598
|
+
reads as declined, and `reset()` does not delete the stored answer: it marks the question reopened (`decision` and
|
|
599
|
+
`marketing` read `null`) until `decide()` runs. The footer link therefore shows in that region and reopens the banner.
|
|
600
|
+
|
|
593
601
|
Style the button through `core-consent-link`; the kit ships a neutral style.
|
|
594
602
|
|
|
595
603
|
## Locales
|
package/apps/apps.css
CHANGED
|
@@ -162,7 +162,11 @@
|
|
|
162
162
|
margin: 0;
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
|
|
165
|
+
/* One class and two elements on purpose (`div button.…`, specificity 0,1,2): it beats a theme's `button { color: inherit }` reset (0,1,1), which
|
|
166
|
+
left the label in the card's text colour on the accent fill (dark maroon on crimson, Beaurify, 16/11/26), and still loses to a theme's own
|
|
167
|
+
two-class rule such as `.theme-carat .core-follow-card__btn` (0,2,0), which is meant to restyle it. The fill and the label are the readable
|
|
168
|
+
pair the tokens guarantee at 4.5:1: `--brand-accent-fill` (the accent, deepened only when it had to be) and `--brand-on-accent`. */
|
|
169
|
+
div button.core-follow-card__btn {
|
|
166
170
|
width: 100%;
|
|
167
171
|
padding: 0.5rem 1rem;
|
|
168
172
|
border: 0;
|
|
@@ -171,8 +175,8 @@
|
|
|
171
175
|
font-weight: 600;
|
|
172
176
|
cursor: pointer;
|
|
173
177
|
transition: background 0.15s, transform 0.1s;
|
|
174
|
-
background: var(--brand-
|
|
175
|
-
color: var(--brand-
|
|
178
|
+
background: var(--brand-accent-fill, var(--brand-accent, #000));
|
|
179
|
+
color: var(--brand-on-accent, #fff);
|
|
176
180
|
}
|
|
177
181
|
|
|
178
182
|
.core-follow-card__btn:hover {
|
|
@@ -313,7 +317,8 @@
|
|
|
313
317
|
outline-offset: 1px;
|
|
314
318
|
}
|
|
315
319
|
|
|
316
|
-
|
|
320
|
+
/* `form button.…` (0,1,2) for the same reason as the follow card button: beats a theme's `button` reset, yields to a theme's own two-class rule. */
|
|
321
|
+
form button.core-subscribe__button {
|
|
317
322
|
padding: 0.7rem 1.25rem;
|
|
318
323
|
font: inherit;
|
|
319
324
|
font-size: 0.9375rem;
|
|
@@ -326,8 +331,8 @@
|
|
|
326
331
|
transition: opacity 0.2s ease;
|
|
327
332
|
}
|
|
328
333
|
|
|
329
|
-
.core-subscribe__button:hover:not(:disabled) { opacity: 0.88; }
|
|
330
|
-
.core-subscribe__button:disabled { opacity: 0.6; cursor: default; }
|
|
334
|
+
form button.core-subscribe__button:hover:not(:disabled) { opacity: 0.88; }
|
|
335
|
+
form button.core-subscribe__button:disabled { opacity: 0.6; cursor: default; }
|
|
331
336
|
|
|
332
337
|
.core-subscribe__error {
|
|
333
338
|
margin: 0.6rem 0 0;
|
|
@@ -392,6 +397,23 @@
|
|
|
392
397
|
width: auto;
|
|
393
398
|
bottom: 5rem;
|
|
394
399
|
}
|
|
400
|
+
|
|
401
|
+
/* One floating card at a time on a phone: the follow card and this one are both full width at the same height, and the shell
|
|
402
|
+
renders them as siblings. A full follow card keeps the bottom; this card shows once it is dismissed or the shopper follows. */
|
|
403
|
+
.core-follow-card--floating:not(.core-follow-card--compact) ~ .core-subscribe-floating {
|
|
404
|
+
display: none;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
/* The small "Following" chip sits at the right edge at the same height: lift this card above it. */
|
|
408
|
+
.core-follow-card--compact.core-follow-card--floating ~ .core-subscribe-floating {
|
|
409
|
+
bottom: 8rem;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/* Another prompt is open (the storefront's overlay gate sets the attribute): the floating cards wait, the compact "Following" chip stays. */
|
|
414
|
+
[data-overlay-held] .core-follow-card--floating:not(.core-follow-card--compact),
|
|
415
|
+
[data-overlay-held] .core-subscribe-floating {
|
|
416
|
+
display: none;
|
|
395
417
|
}
|
|
396
418
|
|
|
397
419
|
/* ── Subscribe — modal variant ───────────────────────────── */
|
|
@@ -595,8 +617,16 @@
|
|
|
595
617
|
.core-consent-banner__text {
|
|
596
618
|
flex: 0 1 auto;
|
|
597
619
|
}
|
|
620
|
+
/* Stacked full width, in markup order (Accept first, Decline last, so focus order is the visual order): the labels ("Accept analytics
|
|
621
|
+
only", "Decline all") never wrap in cramped columns, and every button is the same size, Decline as easy to press as Accept. */
|
|
598
622
|
.core-consent-banner__actions {
|
|
599
|
-
|
|
623
|
+
flex-direction: column;
|
|
624
|
+
align-items: stretch;
|
|
625
|
+
}
|
|
626
|
+
.core-consent-banner .core-consent-banner__decline,
|
|
627
|
+
.core-consent-banner .core-consent-banner__accept {
|
|
628
|
+
width: 100%;
|
|
629
|
+
text-align: center;
|
|
600
630
|
}
|
|
601
631
|
}
|
|
602
632
|
|
|
@@ -23,7 +23,8 @@ function ConsentPreferencesButton({ onReset }: { onReset: () => void }): JSX.Ele
|
|
|
23
23
|
* Shown only when the store uses analytics or an ad pixel, the shopper has
|
|
24
24
|
* answered every question it asks, and the browser is not sending Global
|
|
25
25
|
* Privacy Control (that is already a decline: there is nothing to reopen).
|
|
26
|
-
* Clicking it
|
|
26
|
+
* Clicking it brings the banner back for this store only: where consent is required it forgets the stored choice, and outside
|
|
27
|
+
* those regions (`ConsentRegimeProvider required={false}`) it marks the question reopened and keeps the stored choice until the shopper decides.
|
|
27
28
|
* Renders nothing on the server and while hydrating (the decision is read from
|
|
28
29
|
* the browser), outside a `StorefrontProvider`, and for a store with no consent
|
|
29
30
|
* category. Reads the context directly so it never throws without a provider.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { useCallback, useSyncExternalStore } from 'react';
|
|
3
|
+
import { createContext, createElement, useCallback, useContext, useLayoutEffect, useSyncExternalStore, type JSX, type ReactNode } from 'react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Consent is keyed by vendor id inside one shared localStorage record — the
|
|
@@ -75,11 +75,50 @@ function subscribe(onChange: () => void): () => void {
|
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Whether the shopper must answer before anything non-essential runs. The storefront decides it per request
|
|
80
|
+
* (the visitor's country, the store's own `show` setting) and tells the kit through `ConsentRegimeProvider`;
|
|
81
|
+
* without a provider every visitor must answer, exactly as before.
|
|
82
|
+
*/
|
|
83
|
+
const ConsentRegimeContext = createContext<boolean>(true);
|
|
84
|
+
|
|
85
|
+
/** The React-free readers' copy of the regime (the ad-pixel event subscribers fire outside React). Set only in the browser. */
|
|
86
|
+
let regimeRequired = true;
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Stores whose shopper opened "Cookie preferences" while consent is not required. A reopened question must read
|
|
90
|
+
* unanswered even though an earlier answer is still stored: the stored answer stays untouched until the shopper
|
|
91
|
+
* decides again, so closing the tab mid-review loses nothing. In memory on purpose.
|
|
92
|
+
*/
|
|
93
|
+
const reviewing = new Set<string>();
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Tells the kit whether this visitor must answer before analytics or ad pixels run. `required={false}` means a
|
|
97
|
+
* shopper with no stored answer reads as granted (never written to the record: only a click writes it), Global
|
|
98
|
+
* Privacy Control still reads as declined, and "Cookie preferences" in the footer reopens the question so the
|
|
99
|
+
* shopper can decline. Default (no provider) is `required`.
|
|
100
|
+
*/
|
|
101
|
+
export function ConsentRegimeProvider({ required, children }: { required: boolean; children: ReactNode }): JSX.Element {
|
|
102
|
+
useLayoutEffect(() => {
|
|
103
|
+
regimeRequired = required;
|
|
104
|
+
return () => {
|
|
105
|
+
regimeRequired = true;
|
|
106
|
+
};
|
|
107
|
+
}, [required]);
|
|
108
|
+
|
|
109
|
+
return createElement(ConsentRegimeContext.Provider, { value: required }, children);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* One category's answer. Order matters: Global Privacy Control declines; a question the shopper reopened is
|
|
114
|
+
* unanswered; a stored answer wins; with no answer, a region that does not require consent grants and the rest ask.
|
|
115
|
+
*/
|
|
116
|
+
function readDecision(vendorId: string, category: keyof ConsentChoice, required: boolean): boolean | null {
|
|
79
117
|
if (hasGlobalPrivacyControl()) return false;
|
|
118
|
+
if (reviewing.has(vendorId)) return null;
|
|
80
119
|
const record = readStore()[vendorId];
|
|
81
|
-
if (
|
|
82
|
-
return
|
|
120
|
+
if (record && record.version === CONSENT_VERSION && typeof record[category] === 'boolean') return record[category];
|
|
121
|
+
return required ? null : true;
|
|
83
122
|
}
|
|
84
123
|
|
|
85
124
|
/**
|
|
@@ -90,16 +129,20 @@ function readDecision(vendorId: string, category: keyof ConsentChoice): boolean
|
|
|
90
129
|
*/
|
|
91
130
|
export function readStoredMarketingConsent(vendorId: string | undefined): boolean {
|
|
92
131
|
if (!vendorId || typeof window === 'undefined') return false;
|
|
93
|
-
return readDecision(vendorId, 'marketing') === true;
|
|
132
|
+
return readDecision(vendorId, 'marketing', regimeRequired) === true;
|
|
94
133
|
}
|
|
95
134
|
|
|
96
135
|
/**
|
|
97
136
|
* Per-vendor consent in two independent categories. `decision` (analytics) and
|
|
98
137
|
* `marketing` are each `null` until the visitor has chosen (or GPC decided for
|
|
99
138
|
* them) — the banner and Consent Mode's default state both key off that.
|
|
100
|
-
* Granting analytics never grants marketing.
|
|
101
|
-
* default
|
|
102
|
-
* vendor's record
|
|
139
|
+
* Granting analytics never grants marketing. Where consent is required (the
|
|
140
|
+
* default, no provider) marketing (ad pixels) is denied until an explicit accept
|
|
141
|
+
* and `reset` forgets this vendor's record, which reopens the banner. Under
|
|
142
|
+
* `ConsentRegimeProvider required={false}` a category with no stored answer reads
|
|
143
|
+
* as granted (marketing included, nothing is written to the record), GPC still
|
|
144
|
+
* declines, and `reset` leaves the stored record in place and marks the question
|
|
145
|
+
* reopened (both read `null`) until `decide` runs.
|
|
103
146
|
*/
|
|
104
147
|
export function useAnalyticsConsent(vendorId: string | undefined): {
|
|
105
148
|
decision: boolean | null;
|
|
@@ -119,14 +162,15 @@ export function useAnalyticsConsent(vendorId: string | undefined): {
|
|
|
119
162
|
// change event — a decision in the banner reaches the analytics loader
|
|
120
163
|
// without a reload, which per-instance state never did. `null` on the
|
|
121
164
|
// server and during hydration.
|
|
165
|
+
const required = useContext(ConsentRegimeContext);
|
|
122
166
|
const decision = useSyncExternalStore(
|
|
123
167
|
subscribe,
|
|
124
|
-
() => (vendorId ? readDecision(vendorId, 'analytics') : null),
|
|
168
|
+
() => (vendorId ? readDecision(vendorId, 'analytics', required) : null),
|
|
125
169
|
() => null,
|
|
126
170
|
);
|
|
127
171
|
const marketing = useSyncExternalStore(
|
|
128
172
|
subscribe,
|
|
129
|
-
() => (vendorId ? readDecision(vendorId, 'marketing') : null),
|
|
173
|
+
() => (vendorId ? readDecision(vendorId, 'marketing', required) : null),
|
|
130
174
|
() => null,
|
|
131
175
|
);
|
|
132
176
|
|
|
@@ -135,6 +179,7 @@ export function useAnalyticsConsent(vendorId: string | undefined): {
|
|
|
135
179
|
const decide = useCallback(
|
|
136
180
|
(choice: ConsentChoice) => {
|
|
137
181
|
if (!vendorId) return;
|
|
182
|
+
reviewing.delete(vendorId);
|
|
138
183
|
const store = readStore();
|
|
139
184
|
const previous = store[vendorId]?.version === CONSENT_VERSION ? store[vendorId] : undefined;
|
|
140
185
|
store[vendorId] = {
|
|
@@ -152,11 +197,15 @@ export function useAnalyticsConsent(vendorId: string | undefined): {
|
|
|
152
197
|
|
|
153
198
|
const reset = useCallback(() => {
|
|
154
199
|
if (!vendorId) return;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
200
|
+
if (required) {
|
|
201
|
+
const store = readStore();
|
|
202
|
+
delete store[vendorId];
|
|
203
|
+
writeStore(store);
|
|
204
|
+
} else {
|
|
205
|
+
reviewing.add(vendorId);
|
|
206
|
+
}
|
|
158
207
|
window.dispatchEvent(new Event(CHANGE_EVENT));
|
|
159
|
-
}, [vendorId]);
|
|
208
|
+
}, [vendorId, required]);
|
|
160
209
|
|
|
161
210
|
return { decision, marketing, gpc, decide, reset };
|
|
162
211
|
}
|
package/demo.ts
CHANGED
|
@@ -24,7 +24,8 @@ import type { StorefrontConfig, VendorProfile } from './types/vendor';
|
|
|
24
24
|
* code should import from here directly.
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
/** A demo store's category; `description` is the collection's own copy, shown as written (none when absent). */
|
|
28
|
+
export type DemoCategory = { id: string; slug: string; name: string; image?: string | null; description?: string | null };
|
|
28
29
|
|
|
29
30
|
export interface PreviewDemoData {
|
|
30
31
|
profile: VendorProfile;
|
|
@@ -174,7 +175,7 @@ export function getCollections(demo: PreviewDemoData): Collection[] {
|
|
|
174
175
|
id: category.id,
|
|
175
176
|
slug: category.slug,
|
|
176
177
|
name: category.name,
|
|
177
|
-
description:
|
|
178
|
+
description: category.description?.trim() || null,
|
|
178
179
|
image: category.image ?? null,
|
|
179
180
|
mode: 'manual',
|
|
180
181
|
products_count: products.filter((product) => product.categories.some((item) => item.slug === category.slug)).length,
|
package/package.json
CHANGED
package/types/vendor.ts
CHANGED
|
@@ -246,6 +246,11 @@ export interface StorefrontConfig {
|
|
|
246
246
|
/** `modal` variant only — when it should pop up. Defaults to 'scroll' when unset. */
|
|
247
247
|
trigger?: 'immediate' | 'delay' | 'scroll';
|
|
248
248
|
};
|
|
249
|
+
/**
|
|
250
|
+
* The cookie banner. `message` replaces the banner's lead sentence (plain text); `show` is `everywhere` when the merchant
|
|
251
|
+
* wants the banner for every visitor instead of only where consent is required.
|
|
252
|
+
*/
|
|
253
|
+
consent_banner?: { message?: string; show?: 'required' | 'everywhere' };
|
|
249
254
|
};
|
|
250
255
|
followers_count?: number;
|
|
251
256
|
}
|