fragment-headless-sdk 2.1.7 → 2.1.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.
@@ -1,28 +1,23 @@
1
1
  import React from "react";
2
2
  import { ButtonType } from "../../constants";
3
- import { fireClickMetric, mergeSlotAttributes, mergeSlotClasses, mergeSlotStyles, resolveToken, resolveTokenByCategory, } from "../../utils";
3
+ import { fireClickMetric, mergeSlotAttributes, mergeSlotClasses, mergeSlotStyles, resolveAnnouncementColors, } from "../../utils";
4
4
  export default function AnnouncementButton({ content, buttonHref, clickHref, }) {
5
5
  // Don’t render if no button or explicitly None
6
6
  if (!content?.buttonText || content.buttonType === ButtonType.None)
7
7
  return null;
8
- // If we werent given a usable href, dont render a broken link
8
+ // If we weren't given a usable href, don't render a broken link
9
9
  if (!buttonHref)
10
10
  return null;
11
11
  const styling = content.styling;
12
- const baseTextColor = resolveTokenByCategory(styling, "colors", "text") ||
13
- resolveToken(styling, "textColor");
14
- const buttonBgColor = resolveTokenByCategory(styling, "colors", "button") ||
15
- resolveToken(styling, "buttonColor");
16
- const buttonTextColor = resolveTokenByCategory(styling, "colors", "buttonText") ||
17
- resolveToken(styling, "buttonTextColor");
12
+ const colors = resolveAnnouncementColors(content);
18
13
  const baseStyle = content.buttonType === ButtonType.Text
19
14
  ? {
20
15
  textDecoration: "underline",
21
- color: baseTextColor,
16
+ color: colors.text,
22
17
  }
23
18
  : {
24
- backgroundColor: buttonBgColor,
25
- color: buttonTextColor,
19
+ backgroundColor: colors.button,
20
+ color: colors.buttonText,
26
21
  };
27
22
  const style = mergeSlotStyles(baseStyle, styling, "announcementButton", "button");
28
23
  const className = mergeSlotClasses("whitespace-nowrap rounded-md px-3 py-2 text-sm font-semibold no-underline hover:cursor-pointer hover:opacity-70", styling, "announcementButton", "button");
@@ -1,5 +1,5 @@
1
1
  import React, { useEffect, useState } from "react";
2
- import { mergeSlotAttributes, mergeSlotClasses, mergeSlotStyles, resolveToken, } from "../../utils";
2
+ import { mergeSlotAttributes, mergeSlotClasses, mergeSlotStyles, resolveCountdownColors, } from "../../utils";
3
3
  export default function CountdownTimer({ content, }) {
4
4
  const [timeLeft, setTimeLeft] = useState({
5
5
  days: "00",
@@ -33,24 +33,25 @@ export default function CountdownTimer({ content, }) {
33
33
  const blockClass = mergeSlotClasses("flex flex-col items-center", styling, "countdownBlock");
34
34
  const blockStyle = mergeSlotStyles(undefined, styling, "countdownBlock");
35
35
  const blockAttributes = mergeSlotAttributes(styling, "countdownBlock");
36
- const digitClass = mergeSlotClasses("text-white text-xl font-bold flex items-center justify-center leading-none", styling, "countdownDigit");
37
- const digitTextColor = resolveToken(styling, "counterDigitColor", "#FFFFFF") || "#FFFFFF";
36
+ const digitClass = mergeSlotClasses("text-lg font-bold flex items-center justify-center leading-tight rounded px-1", styling, "countdownDigit");
37
+ const colors = resolveCountdownColors(content);
38
38
  const digitStyle = mergeSlotStyles({
39
- color: digitTextColor,
39
+ color: colors.digitColor,
40
+ backgroundColor: colors.digitBackgroundColor,
40
41
  }, styling, "countdownDigit");
41
42
  const digitAttributes = mergeSlotAttributes(styling, "countdownDigit");
42
43
  const labelClass = mergeSlotClasses("mt-0.5 text-[10px] leading-tight", styling, "countdownLabel");
43
44
  const labelStyle = mergeSlotStyles({
44
- color: digitTextColor,
45
+ color: colors.textColor,
45
46
  }, styling, "countdownLabel");
46
47
  const labelAttributes = mergeSlotAttributes(styling, "countdownLabel");
47
48
  const separatorClass = mergeSlotClasses("text-xl font-semibold -mt-4", styling, "countdownSeparator");
48
49
  const separatorStyle = mergeSlotStyles({
49
- color: digitTextColor,
50
+ color: colors.textColor,
50
51
  }, styling, "countdownSeparator");
51
52
  const separatorAttributes = mergeSlotAttributes(styling, "countdownSeparator");
52
53
  const renderBlock = (value, label) => (React.createElement("div", { className: blockClass, style: blockStyle, ...(blockAttributes ?? {}) },
53
- React.createElement("div", { className: "flex" }, value.split("").map((digit, i) => (React.createElement("span", { key: i, className: digitClass, style: digitStyle, ...(digitAttributes ?? {}) }, digit)))),
54
+ React.createElement("div", { className: "flex gap-1" }, value.split("").map((digit, i) => (React.createElement("span", { key: i, className: digitClass, style: digitStyle, ...(digitAttributes ?? {}) }, digit)))),
54
55
  React.createElement("span", { className: labelClass, style: labelStyle, ...(labelAttributes ?? {}) }, label)));
55
56
  return (React.createElement("div", { className: containerClass, style: containerStyle, ...(containerAttributes ?? {}) },
56
57
  renderBlock(timeLeft.days, "Days"),
@@ -1,7 +1,7 @@
1
1
  import { XMarkIcon } from "@heroicons/react/24/outline";
2
2
  import React, { useEffect, useRef } from "react";
3
3
  import { AnnouncementType, ButtonType } from "../../constants";
4
- import { buildClickUrl, fireImpressionWhenVisible, getThemeClasses, mergeSlotAttributes, mergeSlotClasses, mergeSlotStyles, resolveToken, resolveTokenByCategory, } from "../../utils";
4
+ import { buildClickUrl, fireImpressionWhenVisible, getThemeClasses, mergeSlotAttributes, mergeSlotClasses, mergeSlotStyles, resolveAnnouncementColors, } from "../../utils";
5
5
  import AnnouncementButton from "./AnnouncementButton";
6
6
  import { AnnouncementStyles } from "./AnnouncementStyles";
7
7
  import CountdownTimer from "./CountdownTimer";
@@ -19,15 +19,12 @@ export default function Announcement({ content, type, handleClose, }) {
19
19
  if (!content)
20
20
  return null;
21
21
  const styling = content.styling;
22
- const backgroundColor = resolveTokenByCategory(styling, "colors", "background") ||
23
- resolveToken(styling, "bgColor");
24
- const textColor = resolveTokenByCategory(styling, "colors", "text") ||
25
- resolveToken(styling, "textColor");
22
+ const colors = resolveAnnouncementColors(content);
26
23
  const themeClasses = getThemeClasses(styling);
27
24
  const rootClass = mergeSlotClasses(`relative w-full ${themeClasses}`, styling, "root");
28
25
  const rootStyle = mergeSlotStyles({
29
- backgroundColor,
30
- color: textColor,
26
+ backgroundColor: colors.background,
27
+ color: colors.text,
31
28
  }, styling, "root");
32
29
  const rootAttributes = mergeSlotAttributes(styling, "root");
33
30
  const innerClass = mergeSlotClasses("relative mx-auto flex max-w-screen-xl flex-col md:flex-row items-center justify-center gap-4 px-10 md:px-4 py-2 md:py-0 text-center md:text-left min-h-[50px]", styling, "inner", "wrapper");
@@ -48,13 +45,11 @@ export default function Announcement({ content, type, handleClose, }) {
48
45
  const contentRowClass = mergeSlotClasses("flex flex-col md:flex-row items-center justify-center gap-2 md:gap-4 w-full", styling, "contentRow");
49
46
  const contentRowStyle = mergeSlotStyles(undefined, styling, "contentRow");
50
47
  const contentRowAttributes = mergeSlotAttributes(styling, "contentRow");
51
- const announcementTextClass = mergeSlotClasses("max-w-none text-base font-semibold", styling, "announcementText");
48
+ const announcementTextClass = mergeSlotClasses("max-w-none text-based", styling, "announcementText");
52
49
  const announcementTextStyle = mergeSlotStyles(undefined, styling, "announcementText");
53
50
  const announcementTextAttributes = mergeSlotAttributes(styling, "announcementText");
54
51
  const closeButtonClass = mergeSlotClasses("absolute right-4 top-1/2 -translate-y-1/2 cursor-pointer", styling, "closeButton");
55
- const closeButtonColor = resolveTokenByCategory(styling, "colors", "closeButton") ||
56
- (resolveToken(styling, "closeButtonColor", textColor ?? "#000") ?? "#000");
57
- const closeButtonStyle = mergeSlotStyles({ color: closeButtonColor }, styling, "closeButton");
52
+ const closeButtonStyle = mergeSlotStyles({ color: colors.closeButton }, styling, "closeButton");
58
53
  const closeButtonAttributes = mergeSlotAttributes(styling, "closeButton");
59
54
  return (React.createElement("div", { ref: ref, className: rootClass, style: rootStyle, ...(rootAttributes ?? {}) },
60
55
  React.createElement(AnnouncementStyles, null),
@@ -21,8 +21,11 @@ export interface IAnnouncement {
21
21
  name: string;
22
22
  status: AnnouncementStatus;
23
23
  content: IAnnouncementContent | null;
24
+ active_duration_seconds: number | null;
24
25
  active_start_date: string | null;
25
26
  active_end_date: string | null;
27
+ last_activated_at: string | null;
28
+ last_deactivated_at: string | null;
26
29
  created_at: string | null;
27
30
  updated_at: string | null;
28
31
  views_count: number;
@@ -25,7 +25,10 @@ export interface IHero {
25
25
  page: ShopPage["handle"] | null;
26
26
  status: HeroStatus;
27
27
  content: IHeroContent | null;
28
+ active_duration_seconds: number | null;
28
29
  active_start_date: string | null;
30
+ last_activated_at: string | null;
31
+ last_deactivated_at: string | null;
29
32
  active_end_date: string | null;
30
33
  created_at: string | null;
31
34
  updated_at: string | null;
@@ -0,0 +1,15 @@
1
+ import { IAnnouncementContent } from "../types";
2
+ export interface AnnouncementResolvedColors {
3
+ background: string;
4
+ text: string;
5
+ button: string;
6
+ buttonText: string;
7
+ closeButton: string;
8
+ }
9
+ export interface CountdownResolvedColors {
10
+ digitColor: string;
11
+ digitBackgroundColor: string;
12
+ textColor: string;
13
+ }
14
+ export declare function resolveAnnouncementColors(content: IAnnouncementContent): AnnouncementResolvedColors;
15
+ export declare function resolveCountdownColors(content: IAnnouncementContent): CountdownResolvedColors;
@@ -0,0 +1,45 @@
1
+ import { resolveToken, resolveTokenByCategory } from "./styling";
2
+ const DEFAULT_ANNOUNCEMENT_COLORS = {
3
+ background: "#000000",
4
+ text: "#ffffff",
5
+ button: "#ffffff",
6
+ buttonText: "#000000",
7
+ closeButton: "#ffffff",
8
+ };
9
+ const DEFAULT_COUNTDOWN_COLORS = {
10
+ digitColor: "#ffffff",
11
+ digitBackgroundColor: "#000000",
12
+ textColor: "#ffffff",
13
+ };
14
+ const fallbackColor = (value, fallback) => typeof value === "string" && value.trim().length > 0 ? value : fallback;
15
+ export function resolveAnnouncementColors(content) {
16
+ const styling = content.styling;
17
+ const background = resolveTokenByCategory(styling, "colors", "background") ||
18
+ resolveToken(styling, "bgColor");
19
+ const text = resolveTokenByCategory(styling, "colors", "text") ||
20
+ resolveToken(styling, "textColor");
21
+ const button = resolveTokenByCategory(styling, "colors", "button") ||
22
+ resolveToken(styling, "buttonColor");
23
+ const buttonText = resolveTokenByCategory(styling, "colors", "buttonText") ||
24
+ resolveToken(styling, "buttonTextColor");
25
+ const closeButton = resolveTokenByCategory(styling, "colors", "closeButton") ||
26
+ resolveToken(styling, "closeButtonColor");
27
+ return {
28
+ background: fallbackColor(background, DEFAULT_ANNOUNCEMENT_COLORS.background),
29
+ text: fallbackColor(text, DEFAULT_ANNOUNCEMENT_COLORS.text),
30
+ button: fallbackColor(button, DEFAULT_ANNOUNCEMENT_COLORS.button),
31
+ buttonText: fallbackColor(buttonText, DEFAULT_ANNOUNCEMENT_COLORS.buttonText),
32
+ closeButton: fallbackColor(closeButton, fallbackColor(text, DEFAULT_ANNOUNCEMENT_COLORS.closeButton)),
33
+ };
34
+ }
35
+ export function resolveCountdownColors(content) {
36
+ const styling = content.styling;
37
+ const digitColor = resolveToken(styling, "counterDigitColor");
38
+ const digitBackgroundColor = resolveToken(styling, "counterDigitBackgroundColor");
39
+ const textColor = resolveToken(styling, "counterTextColor", digitColor);
40
+ return {
41
+ digitColor: fallbackColor(digitColor, DEFAULT_COUNTDOWN_COLORS.digitColor),
42
+ digitBackgroundColor: fallbackColor(digitBackgroundColor, DEFAULT_COUNTDOWN_COLORS.digitBackgroundColor),
43
+ textColor: fallbackColor(textColor, DEFAULT_COUNTDOWN_COLORS.textColor),
44
+ };
45
+ }
@@ -39,7 +39,7 @@ export function resolveHeroColors(content) {
39
39
  return {
40
40
  title: fallbackColor(tokens.title, DEFAULT_COLORS.title),
41
41
  text: fallbackColor(tokens.text, DEFAULT_COLORS.text),
42
- buttonBackground: fallbackColor(tokens.button ?? tokens.buttonBackground, DEFAULT_COLORS.buttonBackground),
42
+ buttonBackground: fallbackColor(tokens.buttonBackground, DEFAULT_COLORS.buttonBackground),
43
43
  buttonText: fallbackColor(tokens.buttonText, DEFAULT_COLORS.buttonText),
44
44
  background: fallbackColor(tokens.background, DEFAULT_COLORS.background),
45
45
  };
@@ -1,3 +1,4 @@
1
+ export * from "./announcement-resolvers";
1
2
  export * from "./cache";
2
3
  export * from "./fetch-resource";
3
4
  export * from "./hero-resolvers";
@@ -1,3 +1,4 @@
1
+ export * from "./announcement-resolvers";
1
2
  export * from "./cache";
2
3
  export * from "./fetch-resource";
3
4
  export * from "./hero-resolvers";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fragment-headless-sdk",
3
- "version": "2.1.7",
3
+ "version": "2.1.9",
4
4
  "license": "MIT",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/readme.md CHANGED
@@ -4,7 +4,7 @@ The official SDK for integrating with Fragment-Shopify CMS. Provides React compo
4
4
 
5
5
  ## ✨ What's New
6
6
 
7
- **v2.1.4** - Countdown timer enhancements and improved announcement layouts
7
+ **v2.1.8** - Enhanced countdown timer styling with customizable color tokens
8
8
 
9
9
  > See [CHANGELOG.md](./docs/CHANGELOG.md) for full release history
10
10
 
@@ -433,6 +433,44 @@ interface IAnnouncementContent {
433
433
  - `button` - Action button
434
434
  - `closeButton` - Close button
435
435
  - `countdown` - Countdown container (countdown type)
436
+ - `countdownContainer` - Countdown timer container
437
+ - `countdownBlock` - Individual time block (days, hours, etc.)
438
+ - `countdownDigit` - Countdown digit styling
439
+ - `countdownLabel` - Time unit labels (Days, Hours, Mins, Secs)
440
+ - `countdownSeparator` - Separator between time blocks (`:`)
441
+
442
+ **Countdown Timer Color Tokens:**
443
+
444
+ For countdown-type announcements, you can customize the timer appearance using these color tokens in `styling.tokens.colors`:
445
+
446
+ - `counterDigitColor` - Color of the countdown digits (default: `#FFFFFF`)
447
+ - `counterDigitBackgroundColor` - Background color of the countdown digits (default: `#000000`)
448
+ - `counterTextColor` - Color of labels and separators (default: uses `counterDigitColor`)
449
+
450
+ **Example:**
451
+
452
+ ```tsx
453
+ const announcementContent = {
454
+ buttonType: ButtonType.Default,
455
+ buttonText: "Shop now",
456
+ buttonLink: "/",
457
+ counterEndDate: "2026-01-01T17:00:00.000Z",
458
+ announcementHtml: "🎉 Check out the latest products!",
459
+ styling: {
460
+ tokens: {
461
+ colors: {
462
+ text: "#1e293b",
463
+ background: "#e0e7ff",
464
+ button: "#4f46e5",
465
+ buttonText: "#ffffff",
466
+ counterDigitColor: "#ffffff",
467
+ counterDigitBackgroundColor: "#4f46e5",
468
+ counterTextColor: "#000000",
469
+ },
470
+ },
471
+ },
472
+ };
473
+ ```
436
474
 
437
475
  ## 🔑 API Key Setup
438
476