@usequeek/theme-kit 0.1.3 → 0.1.4

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.
@@ -0,0 +1,41 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import type { HeaderProps } from '../types/theme';
3
+ import { splitAnnouncement } from '../utils/announcement';
4
+
5
+ const ROTATE_EVERY_MS = 6000;
6
+
7
+ /**
8
+ * Turns the stored announcement into the rotating one every header receives:
9
+ * `text` is the message currently showing (so a header that only ever read
10
+ * `text` rotates with no change), `messages`/`index`/`next`/`prev` let a
11
+ * header draw its own pager (roast). Auto-advances while there is more than
12
+ * one message; a manual step restarts the clock so the message just chosen
13
+ * gets its full turn.
14
+ */
15
+ export function useRotatingAnnouncement(announcement: HeaderProps['announcement']): HeaderProps['announcement'] {
16
+ const messages = announcement?.enabled ? splitAnnouncement(announcement.text) : [];
17
+ const count = messages.length;
18
+ const [index, setIndex] = useState(0);
19
+
20
+ const next = useCallback(() => setIndex((i) => (count > 0 ? (i + 1) % count : 0)), [count]);
21
+ const prev = useCallback(() => setIndex((i) => (count > 0 ? (i - 1 + count) % count : 0)), [count]);
22
+
23
+ useEffect(() => {
24
+ if (count < 2) return undefined;
25
+ const timer = window.setInterval(next, ROTATE_EVERY_MS);
26
+ return () => window.clearInterval(timer);
27
+ }, [count, index, next]);
28
+
29
+ if (!announcement) return announcement;
30
+
31
+ const current = count > 0 ? index % count : 0;
32
+
33
+ return {
34
+ ...announcement,
35
+ text: messages[current] ?? '',
36
+ messages,
37
+ index: current,
38
+ next,
39
+ prev,
40
+ };
41
+ }
package/index.ts CHANGED
@@ -47,6 +47,7 @@ export * from './utils/contact-location';
47
47
  export * from './utils/benefit-icon';
48
48
  export * from './utils/video-embed';
49
49
  export * from './utils/match-variant';
50
+ export * from './utils/announcement';
50
51
 
51
52
  // Rendering a theme's own demo.json — what makes local preview possible.
52
53
  export * from './demo';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@usequeek/theme-kit",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "description": "The framework a Queek storefront theme is built against.",
package/types/theme.ts CHANGED
@@ -82,10 +82,21 @@ export interface SubscribeFormProps {
82
82
  export interface HeaderProps {
83
83
  menu: MenuItem[];
84
84
  logo?: string | null;
85
+ /**
86
+ * `text` is the message currently showing — the shell rotates it through
87
+ * the `|`/newline-separated list the vendor wrote (see
88
+ * hooks/use-announcement). A header that wants its own pager reads
89
+ * `messages`/`index` and calls `next`/`prev`; outside the shell (style
90
+ * guide, variant previews) only `text` is set.
91
+ */
85
92
  announcement?: {
86
93
  enabled: boolean;
87
94
  text: string;
88
95
  link?: string | null;
96
+ messages?: string[];
97
+ index?: number;
98
+ next?: () => void;
99
+ prev?: () => void;
89
100
  } | null;
90
101
  /** Site-wide header icon visibility — all default true (see config.header.show_*). */
91
102
  showSearch?: boolean;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * The announcement bar is ONE text field on the backend
3
+ * (`header.announcement.text`). A vendor writes several messages into it
4
+ * separated by `|` or a line break and the bar rotates them; a single
5
+ * message renders static. Roast's masthead set the convention; the merchant
6
+ * editor and Qee teach it. Split here, once, so every theme rotates the same
7
+ * list — a theme-local split meant the other themes showed the literal pipes
8
+ * after a switch.
9
+ */
10
+ export function splitAnnouncement(text: string | null | undefined): string[] {
11
+ return (text ?? '')
12
+ .split(/\s*(?:\||\n)\s*/)
13
+ .map((s) => s.trim())
14
+ .filter(Boolean);
15
+ }