@usequeek/theme-kit 0.1.2 → 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.
- package/LICENSE +21 -0
- package/hooks/use-announcement.ts +41 -0
- package/index.ts +1 -0
- package/package.json +4 -3
- package/types/theme.ts +11 -0
- package/utils/announcement.ts +15 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Queek
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -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,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usequeek/theme-kit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.4",
|
|
4
4
|
"private": false,
|
|
5
|
-
"license": "
|
|
5
|
+
"license": "MIT",
|
|
6
6
|
"description": "The framework a Queek storefront theme is built against.",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -24,7 +24,8 @@
|
|
|
24
24
|
"**/*.ts",
|
|
25
25
|
"**/*.tsx",
|
|
26
26
|
"**/*.css",
|
|
27
|
-
"README.md"
|
|
27
|
+
"README.md",
|
|
28
|
+
"LICENSE"
|
|
28
29
|
],
|
|
29
30
|
"peerDependencies": {
|
|
30
31
|
"next": ">=15",
|
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
|
+
}
|