@usequeek/theme-kit 0.5.7 → 0.5.9
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 +1 -0
- package/apps/apps.css +78 -8
- package/apps/consent-preferences-link.tsx +3 -1
- package/apps/follow-card.tsx +9 -2
- package/client.ts +1 -0
- package/components/powered-by-queek.tsx +5 -3
- package/hooks/use-footer-in-view.ts +74 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -135,6 +135,7 @@ they keep the data already on screen. They return `isLoading`, except
|
|
|
135
135
|
| `useAuth()` | `hooks/use-auth` | The signed-in customer and sign-in modal controls |
|
|
136
136
|
| `useVariantSelection(product, preferredVariantPId?)` | `hooks/use-variant-selection` | Option selection state and the add-to-cart gate; opens on a linked `?variant=` |
|
|
137
137
|
| `useSearch(query, products, collections)` | `hooks/use-search` | Instant search over data you hold |
|
|
138
|
+
| `useFooterInView(active?)` | `hooks/use-footer-in-view` | True while the page's own `<footer>` is on screen; a card pinned to the bottom hides while it is true |
|
|
138
139
|
| `useHref()` | `hooks/use-href` | Builds a store-relative link |
|
|
139
140
|
| `useLocales()` | `hooks/use-locales` | The store's languages and the active one |
|
|
140
141
|
| `useStorefront()` / `useStorefrontLocale()` / `useThemeStrings()` | `provider` | The store, the request locale, the bound `t` |
|
package/apps/apps.css
CHANGED
|
@@ -46,6 +46,31 @@
|
|
|
46
46
|
border-radius: 12px;
|
|
47
47
|
padding: 1rem;
|
|
48
48
|
box-shadow: 0 8px 30px rgba(0,0,0,0.12);
|
|
49
|
+
transition: opacity 0.18s ease, visibility 0s;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* The page footer is on screen (useFooterInView): the card steps aside so it never sits on the footer's links. It keeps its box
|
|
53
|
+
(visibility, not display), so the buttons that stack above it (WhatsApp, an app's bubble) do not jump, and it is out of the tab
|
|
54
|
+
order while hidden. The floating subscribe card does the same (below). */
|
|
55
|
+
.core-follow-card--tucked {
|
|
56
|
+
opacity: 0;
|
|
57
|
+
visibility: hidden;
|
|
58
|
+
pointer-events: none;
|
|
59
|
+
transition: opacity 0.18s ease, visibility 0s linear 0.18s;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/* A card the shopper is typing in (the email box, the consent tick) stays put: hiding it would drop their focus. */
|
|
63
|
+
.core-follow-card--tucked:focus-within {
|
|
64
|
+
opacity: 1;
|
|
65
|
+
visibility: visible;
|
|
66
|
+
pointer-events: auto;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@media (prefers-reduced-motion: reduce) {
|
|
70
|
+
.core-follow-card--floating,
|
|
71
|
+
.core-follow-card--tucked {
|
|
72
|
+
transition: none;
|
|
73
|
+
}
|
|
49
74
|
}
|
|
50
75
|
|
|
51
76
|
/* Follow Card positions */
|
|
@@ -215,7 +240,7 @@ div button.core-follow-card__btn {
|
|
|
215
240
|
left: 1rem;
|
|
216
241
|
right: 1rem;
|
|
217
242
|
width: auto;
|
|
218
|
-
bottom: 5rem;
|
|
243
|
+
bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
|
|
219
244
|
}
|
|
220
245
|
/* The compact following state stays a small chip at the right edge. */
|
|
221
246
|
.core-follow-card--compact.core-follow-card--floating {
|
|
@@ -230,7 +255,7 @@ div button.core-follow-card__btn {
|
|
|
230
255
|
left: 1rem;
|
|
231
256
|
right: 1rem;
|
|
232
257
|
width: auto;
|
|
233
|
-
bottom: 5rem;
|
|
258
|
+
bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
|
|
234
259
|
top: auto;
|
|
235
260
|
transform: none;
|
|
236
261
|
}
|
|
@@ -367,6 +392,28 @@ form button.core-subscribe__button:disabled { opacity: 0.6; cursor: default; }
|
|
|
367
392
|
border-radius: 12px;
|
|
368
393
|
padding: 1rem;
|
|
369
394
|
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
|
|
395
|
+
transition: opacity 0.18s ease, visibility 0s;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
/* The page footer is on screen (useFooterInView): same hidden state as the follow card, after the base rule so its transition wins. */
|
|
399
|
+
.core-subscribe-floating--tucked {
|
|
400
|
+
opacity: 0;
|
|
401
|
+
visibility: hidden;
|
|
402
|
+
pointer-events: none;
|
|
403
|
+
transition: opacity 0.18s ease, visibility 0s linear 0.18s;
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
.core-subscribe-floating--tucked:focus-within {
|
|
407
|
+
opacity: 1;
|
|
408
|
+
visibility: visible;
|
|
409
|
+
pointer-events: auto;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
@media (prefers-reduced-motion: reduce) {
|
|
413
|
+
.core-subscribe-floating,
|
|
414
|
+
.core-subscribe-floating--tucked {
|
|
415
|
+
transition: none;
|
|
416
|
+
}
|
|
370
417
|
}
|
|
371
418
|
|
|
372
419
|
.core-subscribe-floating__dismiss {
|
|
@@ -395,7 +442,7 @@ form button.core-subscribe__button:disabled { opacity: 0.6; cursor: default; }
|
|
|
395
442
|
left: 1rem;
|
|
396
443
|
right: 1rem;
|
|
397
444
|
width: auto;
|
|
398
|
-
bottom: 5rem;
|
|
445
|
+
bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
|
|
399
446
|
}
|
|
400
447
|
|
|
401
448
|
/* 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
|
|
@@ -406,7 +453,7 @@ form button.core-subscribe__button:disabled { opacity: 0.6; cursor: default; }
|
|
|
406
453
|
|
|
407
454
|
/* The small "Following" chip sits at the right edge at the same height: lift this card above it. */
|
|
408
455
|
.core-follow-card--compact.core-follow-card--floating ~ .core-subscribe-floating {
|
|
409
|
-
bottom: 8rem;
|
|
456
|
+
bottom: calc(8rem + env(safe-area-inset-bottom, 0px));
|
|
410
457
|
}
|
|
411
458
|
}
|
|
412
459
|
|
|
@@ -587,27 +634,50 @@ form button.core-subscribe__button:disabled { opacity: 0.6; cursor: default; }
|
|
|
587
634
|
.core-consent-banner .core-consent-banner__decline:hover,
|
|
588
635
|
.core-consent-banner .core-consent-banner__accept:hover { opacity: 0.85; }
|
|
589
636
|
|
|
590
|
-
/* The footer attribution slot: the cookie preferences link, then "Powered by Queek". No positioning, so a footer row keeps its layout. */
|
|
637
|
+
/* The footer attribution slot: the cookie preferences link, a middle dot, then "Powered by Queek". No positioning, so a footer row keeps its layout. */
|
|
591
638
|
.core-powered-by-group {
|
|
592
639
|
display: inline-flex;
|
|
593
640
|
align-items: baseline;
|
|
594
641
|
flex-wrap: wrap;
|
|
595
|
-
gap: 0.
|
|
642
|
+
gap: 0.6em;
|
|
596
643
|
}
|
|
597
644
|
|
|
598
|
-
/*
|
|
645
|
+
/* Reads as one of the footer's small links (Dawn's policy links): same size and colour as the row around it, no underline at rest, underline on hover.
|
|
646
|
+
A theme whose `.core-powered-by` has its own size or colour must give `.core-consent-link` the same values in one selector list. */
|
|
599
647
|
.core-consent-link {
|
|
648
|
+
appearance: none;
|
|
600
649
|
background: none;
|
|
601
650
|
border: 0;
|
|
602
651
|
padding: 0;
|
|
603
652
|
margin: 0;
|
|
604
653
|
font: inherit;
|
|
605
654
|
color: inherit;
|
|
655
|
+
letter-spacing: inherit;
|
|
656
|
+
text-transform: inherit;
|
|
657
|
+
line-height: inherit;
|
|
606
658
|
text-align: start;
|
|
607
|
-
text-decoration:
|
|
659
|
+
text-decoration: none;
|
|
608
660
|
cursor: pointer;
|
|
609
661
|
}
|
|
610
662
|
|
|
663
|
+
.core-consent-link:hover {
|
|
664
|
+
text-decoration: underline;
|
|
665
|
+
text-underline-offset: 0.2em;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
.core-consent-link:focus-visible {
|
|
669
|
+
outline: 2px solid currentColor;
|
|
670
|
+
outline-offset: 2px;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
/* Dawn's middle dot between the link and the credit. The empty alt text keeps it silent for screen readers; with the credit hidden the bare link has no group, so no dot. */
|
|
674
|
+
.core-powered-by-group > .core-consent-link::after {
|
|
675
|
+
content: "\00B7" / "";
|
|
676
|
+
display: inline-block;
|
|
677
|
+
margin-inline-start: 0.6em;
|
|
678
|
+
text-decoration: none;
|
|
679
|
+
}
|
|
680
|
+
|
|
611
681
|
@media (max-width: 600px) {
|
|
612
682
|
.core-consent-banner {
|
|
613
683
|
flex-direction: column;
|
|
@@ -18,7 +18,9 @@ function ConsentPreferencesButton({ onReset }: { onReset: () => void }): JSX.Ele
|
|
|
18
18
|
/**
|
|
19
19
|
* The shopper's way back into their cookie choice, rendered by
|
|
20
20
|
* `PoweredByQueek` in every theme footer (withdrawing consent must be as easy
|
|
21
|
-
* as giving it). A plain inline button, never a floating one
|
|
21
|
+
* as giving it). A plain inline button, never a floating one, that reads as one
|
|
22
|
+
* of the footer's small links: a theme that sizes or colours `.core-powered-by`
|
|
23
|
+
* must give `.core-consent-link` the same values.
|
|
22
24
|
*
|
|
23
25
|
* Shown only when the store uses analytics or an ad pixel, the shopper has
|
|
24
26
|
* answered every question it asks, and the browser is not sending Global
|
package/apps/follow-card.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { useAuthModalStore } from '../stores/auth-modal-store';
|
|
|
8
8
|
import { getQueekClient } from '../sdk/queek-client';
|
|
9
9
|
import { formatCount } from '../utils/format';
|
|
10
10
|
import { Image } from '../components/image';
|
|
11
|
+
import { useFooterInView } from '../hooks/use-footer-in-view';
|
|
11
12
|
|
|
12
13
|
interface FollowData {
|
|
13
14
|
following: boolean;
|
|
@@ -131,6 +132,10 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
131
132
|
}
|
|
132
133
|
}, [vendor.id]);
|
|
133
134
|
|
|
135
|
+
const isFloatingMount = mount === 'floating';
|
|
136
|
+
const onScreen = !!followConfig?.enabled && shows && checked && (isFollowing || !dismissed);
|
|
137
|
+
const tucked = useFooterInView(isFloatingMount && onScreen);
|
|
138
|
+
|
|
134
139
|
const handleFollow = useCallback(async () => {
|
|
135
140
|
if (isThemePreview) {
|
|
136
141
|
setPreviewMessage(true);
|
|
@@ -185,11 +190,13 @@ export function FollowCard({ display }: { display?: 'floating' | 'inline' } = {}
|
|
|
185
190
|
if (!followConfig?.enabled || !shows || !checked) return null;
|
|
186
191
|
|
|
187
192
|
const storeName = vendor.name ?? t('follow.thisstore');
|
|
188
|
-
const isFloating =
|
|
193
|
+
const isFloating = isFloatingMount;
|
|
189
194
|
const posClass = isFloating
|
|
190
195
|
? POSITION_CLASS[followConfig.position ?? 'bottom-right'] ?? POSITION_CLASS['bottom-right']
|
|
191
196
|
: '';
|
|
192
|
-
const placement = isFloating
|
|
197
|
+
const placement = isFloating
|
|
198
|
+
? `core-follow-card--floating ${posClass}${tucked ? ' core-follow-card--tucked' : ''}`
|
|
199
|
+
: 'core-follow-card--inline';
|
|
193
200
|
|
|
194
201
|
// A shopper who follows still sees the card, compact, with the way out: Unfollow. Dismissing the prompt never hides it.
|
|
195
202
|
if (isFollowing) {
|
package/client.ts
CHANGED
|
@@ -38,6 +38,7 @@ export * from './api/orders';
|
|
|
38
38
|
export * from './hooks/use-href';
|
|
39
39
|
export * from './hooks/use-locales';
|
|
40
40
|
export * from './hooks/use-markets';
|
|
41
|
+
export * from './hooks/use-footer-in-view';
|
|
41
42
|
export * from './hooks/use-auth';
|
|
42
43
|
export * from './hooks/use-cart';
|
|
43
44
|
export * from './hooks/use-shop-cart';
|
|
@@ -42,9 +42,11 @@ export interface PoweredByQueekProps {
|
|
|
42
42
|
* keeps its child count, and the preferences link sits directly before the
|
|
43
43
|
* attribution. The link renders only when the store uses analytics or an ad
|
|
44
44
|
* pixel and the shopper has chosen; otherwise the group holds just the
|
|
45
|
-
* attribution. A footer needs no extra markup
|
|
46
|
-
*
|
|
47
|
-
*
|
|
45
|
+
* attribution. A footer needs no extra markup. The link reads as one of the
|
|
46
|
+
* footer's small links (inherited size and colour, no underline at rest, a
|
|
47
|
+
* middle dot before the credit), so a theme that sizes or colours
|
|
48
|
+
* `.core-powered-by` must give `.core-consent-link` the same values in one
|
|
49
|
+
* selector list.
|
|
48
50
|
*/
|
|
49
51
|
export function PoweredByQueek({ className, hidden = false }: PoweredByQueekProps): JSX.Element | null {
|
|
50
52
|
const store = useContext(StorefrontContext);
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
|
|
5
|
+
/** Ancestors that make a `<footer>` part of a content block rather than the page footer. */
|
|
6
|
+
const PAGE_FOOTER_EXCLUDE = 'main, article, section, aside, nav, header';
|
|
7
|
+
|
|
8
|
+
function pageFooters(): HTMLElement[] {
|
|
9
|
+
return Array.from(document.querySelectorAll<HTMLElement>('footer')).filter((node) => !node.closest(PAGE_FOOTER_EXCLUDE));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** A page that cannot scroll has no "end" to reach: a card on it never overlaps the footer by scrolling, so it is never hidden. */
|
|
13
|
+
function pageScrolls(): boolean {
|
|
14
|
+
return document.documentElement.scrollHeight > window.innerHeight;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* True while the page's own footer is on screen and the page scrolls. A card pinned to the viewport bottom (the follow card, the
|
|
19
|
+
* floating subscribe card) would sit on the footer's links once the shopper scrolls to the end, so it hides for as long as this is
|
|
20
|
+
* true. Hide it with `visibility: hidden` and keep its box, so whatever is stacked above it does not jump. Only the shell's footer
|
|
21
|
+
* counts: a `<footer>` inside `main`, an article, section, aside, nav or header (a product card, a blog post) is not the page footer.
|
|
22
|
+
*
|
|
23
|
+
* The footers are looked up again whenever the page's DOM changes, so a footer that mounts late (the editor's regions) or is
|
|
24
|
+
* replaced (the footer variant switched) is watched too. Pass `active` false while the caller renders nothing: no observer is held
|
|
25
|
+
* and the answer is false.
|
|
26
|
+
*/
|
|
27
|
+
export function useFooterInView(active = true): boolean {
|
|
28
|
+
const [inView, setInView] = useState(false);
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!active || typeof IntersectionObserver === 'undefined') {
|
|
32
|
+
setInView(false);
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
const visible = new Set<Element>();
|
|
36
|
+
let watched: HTMLElement[] = [];
|
|
37
|
+
let observer: IntersectionObserver | null = null;
|
|
38
|
+
let frame = 0;
|
|
39
|
+
|
|
40
|
+
const watch = (): void => {
|
|
41
|
+
const footers = pageFooters();
|
|
42
|
+
if (footers.length === watched.length && footers.every((node, index) => node === watched[index])) return;
|
|
43
|
+
observer?.disconnect();
|
|
44
|
+
observer = null;
|
|
45
|
+
visible.clear();
|
|
46
|
+
watched = footers;
|
|
47
|
+
if (footers.length === 0) {
|
|
48
|
+
setInView(false);
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
observer = new IntersectionObserver((entries) => {
|
|
52
|
+
entries.forEach((entry) => (entry.isIntersecting ? visible.add(entry.target) : visible.delete(entry.target)));
|
|
53
|
+
setInView(visible.size > 0 && pageScrolls());
|
|
54
|
+
});
|
|
55
|
+
footers.forEach((node) => observer?.observe(node));
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
watch();
|
|
59
|
+
const mutations = new MutationObserver(() => {
|
|
60
|
+
window.cancelAnimationFrame(frame);
|
|
61
|
+
frame = window.requestAnimationFrame(watch);
|
|
62
|
+
});
|
|
63
|
+
mutations.observe(document.body, { childList: true, subtree: true });
|
|
64
|
+
|
|
65
|
+
return () => {
|
|
66
|
+
window.cancelAnimationFrame(frame);
|
|
67
|
+
mutations.disconnect();
|
|
68
|
+
observer?.disconnect();
|
|
69
|
+
setInView(false);
|
|
70
|
+
};
|
|
71
|
+
}, [active]);
|
|
72
|
+
|
|
73
|
+
return inView;
|
|
74
|
+
}
|
package/package.json
CHANGED