@datlv-trustshop/shopify-inapp-components 0.2.6 → 0.2.7
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,12 +1,18 @@
|
|
|
1
|
-
import { jsx as _jsx, jsxs as _jsxs
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useEffect, useContext } from "react";
|
|
3
3
|
import { Banner, Button, Text, BlockStack, InlineStack, } from "@shopify/polaris";
|
|
4
4
|
import { ExternalIcon } from "@shopify/polaris-icons";
|
|
5
5
|
import { useTopBanner } from "../hooks/useBanner";
|
|
6
6
|
import { DashboardContext } from "../provider/DashboardProvider";
|
|
7
7
|
const BANNER_MIN_HEIGHT = 100;
|
|
8
|
-
const TopBannerSkeleton = ({ className }) => {
|
|
9
|
-
return (_jsxs("div", { className: className, style: {
|
|
8
|
+
const TopBannerSkeleton = ({ className, visible }) => {
|
|
9
|
+
return (_jsxs("div", { className: className, style: {
|
|
10
|
+
width: "100%",
|
|
11
|
+
opacity: visible ? 1 : 0,
|
|
12
|
+
visibility: visible ? "visible" : "hidden",
|
|
13
|
+
transition: "opacity 0.2s ease, visibility 0.2s ease",
|
|
14
|
+
pointerEvents: visible ? "auto" : "none",
|
|
15
|
+
}, children: [_jsxs("div", { style: {
|
|
10
16
|
minHeight: `${BANNER_MIN_HEIGHT}px`,
|
|
11
17
|
padding: "16px",
|
|
12
18
|
borderRadius: "8px",
|
|
@@ -49,7 +55,7 @@ const TopBannerSkeleton = ({ className }) => {
|
|
|
49
55
|
}
|
|
50
56
|
` })] }));
|
|
51
57
|
};
|
|
52
|
-
export const TopBanner = ({ className = "", onClose, onAction, closable = true, renderBanner, }) => {
|
|
58
|
+
export const TopBanner = ({ className = "", open = true, onClose, onAction, closable = true, renderBanner, }) => {
|
|
53
59
|
const context = useContext(DashboardContext);
|
|
54
60
|
const isInitialized = context?.isInitialized ?? false;
|
|
55
61
|
const isLoading = context?.state?.loading ?? true;
|
|
@@ -94,27 +100,39 @@ export const TopBanner = ({ className = "", onClose, onAction, closable = true,
|
|
|
94
100
|
onAction?.(banner);
|
|
95
101
|
}
|
|
96
102
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
if (!isInitialized || isLoading) {
|
|
105
|
-
return _jsx(TopBannerSkeleton, { className: className });
|
|
103
|
+
const shouldShow = open && !isDismissed;
|
|
104
|
+
const showSkeleton = shouldShow && (!dismissChecked || !isInitialized || isLoading);
|
|
105
|
+
const showBanner = shouldShow && dismissChecked && isInitialized && !isLoading && banner;
|
|
106
|
+
if (!dismissChecked || !isInitialized || isLoading) {
|
|
107
|
+
return _jsx(TopBannerSkeleton, { className: className, visible: showSkeleton });
|
|
106
108
|
}
|
|
107
109
|
if (!banner) {
|
|
108
|
-
return
|
|
110
|
+
return (_jsx("div", { className: className, style: {
|
|
111
|
+
width: "100%",
|
|
112
|
+
height: 0,
|
|
113
|
+
overflow: "hidden",
|
|
114
|
+
opacity: 0,
|
|
115
|
+
visibility: "hidden",
|
|
116
|
+
}, "aria-hidden": "true" }));
|
|
109
117
|
}
|
|
110
118
|
if (renderBanner) {
|
|
111
|
-
return (_jsx(
|
|
119
|
+
return (_jsx("div", { style: {
|
|
120
|
+
opacity: showBanner ? 1 : 0,
|
|
121
|
+
visibility: showBanner ? "visible" : "hidden",
|
|
122
|
+
transition: "opacity 0.3s ease, visibility 0.3s ease",
|
|
123
|
+
pointerEvents: showBanner ? "auto" : "none",
|
|
124
|
+
}, children: renderBanner(banner, {
|
|
112
125
|
onClose: handleClose,
|
|
113
126
|
onAction: handleAction,
|
|
114
127
|
}) }));
|
|
115
128
|
}
|
|
116
129
|
return (_jsx("div", { className: className, style: {
|
|
117
130
|
width: "100%",
|
|
118
|
-
minHeight: `${BANNER_MIN_HEIGHT}px
|
|
131
|
+
minHeight: showBanner ? `${BANNER_MIN_HEIGHT}px` : 0,
|
|
132
|
+
opacity: showBanner ? 1 : 0,
|
|
133
|
+
visibility: showBanner ? "visible" : "hidden",
|
|
134
|
+
transition: "opacity 0.3s ease, visibility 0.3s ease, min-height 0.3s ease",
|
|
135
|
+
pointerEvents: showBanner ? "auto" : "none",
|
|
136
|
+
overflow: "hidden",
|
|
119
137
|
}, children: _jsx(Banner, { hideIcon: true, onDismiss: closable ? handleClose : undefined, children: _jsxs(InlineStack, { gap: "400", blockAlign: "center", wrap: false, children: [banner.icon && (_jsx("div", { style: { flexShrink: 0 }, children: _jsx("img", { src: banner.icon, alt: "", width: 72, height: 72, style: { borderRadius: "8px" }, loading: "eager" }) })), _jsx("div", { style: { flex: 1, minWidth: 0 }, children: _jsxs(BlockStack, { gap: "100", align: "space-between", children: [_jsxs(BlockStack, { gap: "100", children: [_jsx(Text, { variant: "headingSm", as: "h3", children: banner.title }), banner.description && (_jsx(Text, { variant: "bodyMd", tone: "subdued", as: "p", children: banner.description }))] }), banner.link && (_jsx("div", { style: { flexShrink: 0 }, children: _jsx(Button, { icon: ExternalIcon, onClick: handleAction, children: banner.linkText || "Learn More" }) }))] }) })] }) }) }));
|
|
120
138
|
};
|