fragment-headless-sdk 2.1.8 → 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.
- package/dist/components/Announcement/AnnouncementButton.js +6 -11
- package/dist/components/Announcement/CountdownTimer.js +8 -11
- package/dist/components/Announcement/index.js +6 -11
- package/dist/types/announcement.d.ts +3 -0
- package/dist/types/hero.d.ts +3 -0
- package/dist/utils/announcement-resolvers.d.ts +15 -0
- package/dist/utils/announcement-resolvers.js +45 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/package.json +1 -1
|
@@ -1,28 +1,23 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { ButtonType } from "../../constants";
|
|
3
|
-
import { fireClickMetric, mergeSlotAttributes, mergeSlotClasses, mergeSlotStyles,
|
|
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 weren
|
|
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
|
|
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:
|
|
16
|
+
color: colors.text,
|
|
22
17
|
}
|
|
23
18
|
: {
|
|
24
|
-
backgroundColor:
|
|
25
|
-
color:
|
|
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,
|
|
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,28 +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-
|
|
37
|
-
const
|
|
38
|
-
const digitBackgroundColor = resolveToken(styling, "counterDigitBackgroundColor", "#000000") ||
|
|
39
|
-
"#000000";
|
|
40
|
-
const counterTextColor = resolveToken(styling, "counterTextColor", digitTextColor);
|
|
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);
|
|
41
38
|
const digitStyle = mergeSlotStyles({
|
|
42
|
-
color:
|
|
43
|
-
backgroundColor: digitBackgroundColor,
|
|
39
|
+
color: colors.digitColor,
|
|
40
|
+
backgroundColor: colors.digitBackgroundColor,
|
|
44
41
|
}, styling, "countdownDigit");
|
|
45
42
|
const digitAttributes = mergeSlotAttributes(styling, "countdownDigit");
|
|
46
43
|
const labelClass = mergeSlotClasses("mt-0.5 text-[10px] leading-tight", styling, "countdownLabel");
|
|
47
44
|
const labelStyle = mergeSlotStyles({
|
|
48
|
-
color:
|
|
45
|
+
color: colors.textColor,
|
|
49
46
|
}, styling, "countdownLabel");
|
|
50
47
|
const labelAttributes = mergeSlotAttributes(styling, "countdownLabel");
|
|
51
48
|
const separatorClass = mergeSlotClasses("text-xl font-semibold -mt-4", styling, "countdownSeparator");
|
|
52
49
|
const separatorStyle = mergeSlotStyles({
|
|
53
|
-
color:
|
|
50
|
+
color: colors.textColor,
|
|
54
51
|
}, styling, "countdownSeparator");
|
|
55
52
|
const separatorAttributes = mergeSlotAttributes(styling, "countdownSeparator");
|
|
56
53
|
const renderBlock = (value, label) => (React.createElement("div", { className: blockClass, style: blockStyle, ...(blockAttributes ?? {}) },
|
|
57
|
-
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)))),
|
|
58
55
|
React.createElement("span", { className: labelClass, style: labelStyle, ...(labelAttributes ?? {}) }, label)));
|
|
59
56
|
return (React.createElement("div", { className: containerClass, style: containerStyle, ...(containerAttributes ?? {}) },
|
|
60
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,
|
|
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
|
|
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:
|
|
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-
|
|
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
|
|
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;
|
package/dist/types/hero.d.ts
CHANGED
|
@@ -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
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED