@usequeek/theme-kit 0.5.8 → 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 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
 
@@ -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 = mount === 'floating';
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 ? `core-follow-card--floating ${posClass}` : 'core-follow-card--inline';
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';
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.5.8",
3
+ "version": "0.5.9",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The runtime a Queek storefront theme is built on: hooks, stores, page renderer, navigation, shared blocks and locale strings.",