@gem-sdk/components 2.0.0-dev.367 → 2.0.0-dev.368
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/cjs/sticky/components/Sticky.js +18 -113
- package/dist/cjs/sticky/components/Sticky.liquid.js +18 -51
- package/dist/cjs/sticky/components/common/styles.js +42 -0
- package/dist/cjs/sticky/components/hooks/useSticky.js +119 -0
- package/dist/cjs/sticky/index.js +1 -0
- package/dist/esm/sticky/components/Sticky.js +19 -114
- package/dist/esm/sticky/components/Sticky.liquid.js +19 -52
- package/dist/esm/sticky/components/common/styles.js +40 -0
- package/dist/esm/sticky/components/hooks/useSticky.js +114 -0
- package/dist/esm/sticky/index.js +1 -0
- package/package.json +1 -1
|
@@ -7,69 +7,28 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
7
7
|
var core = require('@gem-sdk/core');
|
|
8
8
|
var Head = require('next/head');
|
|
9
9
|
var ChildrenDroppable = require('../../grid/components/ChildrenDroppable.js');
|
|
10
|
-
|
|
10
|
+
require('react');
|
|
11
11
|
var _const = require('../../common/const.js');
|
|
12
|
-
var
|
|
12
|
+
var useSticky = require('./hooks/useSticky.js');
|
|
13
|
+
var system = require('@gem-sdk/system');
|
|
13
14
|
|
|
14
15
|
const Sticky = ({ children, builderAttrs, setting, style, builderProps })=>{
|
|
15
|
-
const {
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const { minimize, background, preloadBgImage } = setting ?? {};
|
|
17
|
+
const { w, displayStyle, positionStyle, getCSSAlign } = useSticky.default(setting);
|
|
18
|
+
const computedContainerStyles = system.createStyle({
|
|
19
|
+
margin: '0 auto',
|
|
20
|
+
...style,
|
|
21
|
+
...w,
|
|
22
|
+
...core.getStyleBackgroundByDevice(background),
|
|
23
|
+
...displayStyle(),
|
|
24
|
+
...positionStyle(),
|
|
25
|
+
...getCSSAlign(),
|
|
26
|
+
zIndex: _const.ELEMENT_Z_INDEX.STICKY
|
|
20
27
|
});
|
|
21
|
-
const
|
|
22
|
-
const sidebarMode = core.usePageStore((s)=>s.sidebarMode === 'interaction');
|
|
23
|
-
const currentDevice = core.useCurrentDevice();
|
|
24
|
-
const getCSSPosition = (position)=>{
|
|
25
|
-
return position == 'top' ? 'sticky' : 'fixed';
|
|
26
|
-
};
|
|
27
|
-
const getCSSAlignByDevice = (position, device)=>{
|
|
28
|
-
return {
|
|
29
|
-
[`--left${device}`]: position == 'top' ? '0' : '50%',
|
|
30
|
-
[`--t${device}`]: position == 'top' ? 'unset' : 'translateX(-50%)'
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
const getCSSAlign = ()=>{
|
|
34
|
-
return {
|
|
35
|
-
...getCSSAlignByDevice(position?.desktop, ''),
|
|
36
|
-
...getCSSAlignByDevice(position?.tablet ?? position?.desktop, '-tablet'),
|
|
37
|
-
...getCSSAlignByDevice(position?.mobile ?? position?.desktop, '-mobile')
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const gap = React.useMemo(()=>{
|
|
41
|
-
if (sidebarMode && position?.[currentDevice] === 'top') {
|
|
42
|
-
return '40px';
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
45
|
-
}, [
|
|
46
|
-
currentDevice,
|
|
47
|
-
sidebarMode,
|
|
48
|
-
position
|
|
49
|
-
]);
|
|
50
|
-
const displayStyle = React.useCallback(()=>{
|
|
51
|
-
return {
|
|
52
|
-
[`--top`]: gap ?? 'auto',
|
|
53
|
-
[`--top-tablet`]: gap ?? 'auto',
|
|
54
|
-
[`--top-mobile`]: gap ?? 'auto',
|
|
55
|
-
[`--${position?.desktop}`]: gap ?? 0,
|
|
56
|
-
[`--${position?.tablet ?? position?.desktop}-tablet`]: gap ?? 0,
|
|
57
|
-
[`--${position?.mobile ?? position?.desktop}-mobile`]: gap ?? 0
|
|
58
|
-
};
|
|
59
|
-
}, [
|
|
60
|
-
gap,
|
|
61
|
-
position
|
|
62
|
-
]);
|
|
63
|
-
const positionStyle = ()=>{
|
|
64
|
-
return {
|
|
65
|
-
[`--pos`]: getCSSPosition(position?.desktop),
|
|
66
|
-
[`--pos-tablet`]: getCSSPosition(position?.tablet ?? position?.desktop),
|
|
67
|
-
[`--pos-mobile`]: getCSSPosition(position?.mobile ?? position?.desktop)
|
|
68
|
-
};
|
|
69
|
-
};
|
|
28
|
+
const computedMinimizeClasses = system.createClass(core.composeClasses('sticky-minimize gp-fixed gp-flex gp-h-[32px] gp-w-[76px] gp-cursor-pointer gp-items-center gp-gap-[4px] gp-border gp-border-[#D8E1FF] gp-bg-white hover:gp-bg-[#D8E1FF]'));
|
|
70
29
|
if (minimize) {
|
|
71
30
|
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
72
|
-
className:
|
|
31
|
+
className: computedMinimizeClasses,
|
|
73
32
|
"data-uid": builderProps?.uid,
|
|
74
33
|
"data-id": builderProps?.uid,
|
|
75
34
|
...builderAttrs,
|
|
@@ -78,52 +37,7 @@ const Sticky = ({ children, builderAttrs, setting, style, builderProps })=>{
|
|
|
78
37
|
zIndex: _const.ELEMENT_Z_INDEX.STICKY
|
|
79
38
|
},
|
|
80
39
|
children: [
|
|
81
|
-
|
|
82
|
-
className: "gp-ml-[7px]",
|
|
83
|
-
width: "16",
|
|
84
|
-
height: "16",
|
|
85
|
-
viewBox: "0 0 16 16",
|
|
86
|
-
fill: "none",
|
|
87
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
88
|
-
children: [
|
|
89
|
-
/*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
90
|
-
fillRule: "evenodd",
|
|
91
|
-
clipRule: "evenodd",
|
|
92
|
-
d: "M5.75 1.25C4.64543 1.25 3.75 2.14543 3.75 3.25C3.75 4.35457 4.64543 5.25 5.75 5.25C6.85457 5.25 7.75 4.35457 7.75 3.25C7.75 2.14543 6.85457 1.25 5.75 1.25ZM4.75 3.25C4.75 2.69772 5.19772 2.25 5.75 2.25C6.30228 2.25 6.75 2.69772 6.75 3.25C6.75 3.80228 6.30228 4.25 5.75 4.25C5.19772 4.25 4.75 3.80228 4.75 3.25Z",
|
|
93
|
-
fill: "#3C67FF"
|
|
94
|
-
}),
|
|
95
|
-
/*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
96
|
-
fillRule: "evenodd",
|
|
97
|
-
clipRule: "evenodd",
|
|
98
|
-
d: "M5.75 6C4.64543 6 3.75 6.89543 3.75 8C3.75 9.10457 4.64543 10 5.75 10C6.85457 10 7.75 9.10457 7.75 8C7.75 6.89543 6.85457 6 5.75 6ZM4.75 8C4.75 7.44772 5.19772 7 5.75 7C6.30228 7 6.75 7.44772 6.75 8C6.75 8.55228 6.30228 9 5.75 9C5.19772 9 4.75 8.55228 4.75 8Z",
|
|
99
|
-
fill: "#3C67FF"
|
|
100
|
-
}),
|
|
101
|
-
/*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
102
|
-
fillRule: "evenodd",
|
|
103
|
-
clipRule: "evenodd",
|
|
104
|
-
d: "M3.75 12.75C3.75 11.6454 4.64543 10.75 5.75 10.75C6.85457 10.75 7.75 11.6454 7.75 12.75C7.75 13.8546 6.85457 14.75 5.75 14.75C4.64543 14.75 3.75 13.8546 3.75 12.75ZM5.75 11.75C5.19772 11.75 4.75 12.1977 4.75 12.75C4.75 13.3023 5.19772 13.75 5.75 13.75C6.30228 13.75 6.75 13.3023 6.75 12.75C6.75 12.1977 6.30228 11.75 5.75 11.75Z",
|
|
105
|
-
fill: "#3C67FF"
|
|
106
|
-
}),
|
|
107
|
-
/*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
108
|
-
fillRule: "evenodd",
|
|
109
|
-
clipRule: "evenodd",
|
|
110
|
-
d: "M10.25 1.25C9.14543 1.25 8.25 2.14543 8.25 3.25C8.25 4.35457 9.14543 5.25 10.25 5.25C11.3546 5.25 12.25 4.35457 12.25 3.25C12.25 2.14543 11.3546 1.25 10.25 1.25ZM9.25 3.25C9.25 2.69772 9.69772 2.25 10.25 2.25C10.8023 2.25 11.25 2.69772 11.25 3.25C11.25 3.80228 10.8023 4.25 10.25 4.25C9.69772 4.25 9.25 3.80228 9.25 3.25Z",
|
|
111
|
-
fill: "#3C67FF"
|
|
112
|
-
}),
|
|
113
|
-
/*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
114
|
-
fillRule: "evenodd",
|
|
115
|
-
clipRule: "evenodd",
|
|
116
|
-
d: "M8.25 8C8.25 6.89543 9.14543 6 10.25 6C11.3546 6 12.25 6.89543 12.25 8C12.25 9.10457 11.3546 10 10.25 10C9.14543 10 8.25 9.10457 8.25 8ZM10.25 7C9.69772 7 9.25 7.44772 9.25 8C9.25 8.55228 9.69772 9 10.25 9C10.8023 9 11.25 8.55228 11.25 8C11.25 7.44772 10.8023 7 10.25 7Z",
|
|
117
|
-
fill: "#3C67FF"
|
|
118
|
-
}),
|
|
119
|
-
/*#__PURE__*/ jsxRuntime.jsx("path", {
|
|
120
|
-
fillRule: "evenodd",
|
|
121
|
-
clipRule: "evenodd",
|
|
122
|
-
d: "M10.25 10.75C9.14543 10.75 8.25 11.6454 8.25 12.75C8.25 13.8546 9.14543 14.75 10.25 14.75C11.3546 14.75 12.25 13.8546 12.25 12.75C12.25 11.6454 11.3546 10.75 10.25 10.75ZM9.25 12.75C9.25 12.1977 9.69772 11.75 10.25 11.75C10.8023 11.75 11.25 12.1977 11.25 12.75C11.25 13.3023 10.8023 13.75 10.25 13.75C9.69772 13.75 9.25 13.3023 9.25 12.75Z",
|
|
123
|
-
fill: "#3C67FF"
|
|
124
|
-
})
|
|
125
|
-
]
|
|
126
|
-
}),
|
|
40
|
+
useSticky.minimizeSvg,
|
|
127
41
|
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
128
42
|
className: "gp-text-[12px] gp-font-medium gp-text-[#3C67FF]",
|
|
129
43
|
children: "Sticky"
|
|
@@ -155,16 +69,7 @@ const Sticky = ({ children, builderAttrs, setting, style, builderProps })=>{
|
|
|
155
69
|
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
156
70
|
className: core.cls('sticky-wrapper', builderProps?.uid),
|
|
157
71
|
id: builderProps?.uid,
|
|
158
|
-
style:
|
|
159
|
-
margin: '0 auto',
|
|
160
|
-
...style,
|
|
161
|
-
...w,
|
|
162
|
-
...core.getStyleBackgroundByDevice(background),
|
|
163
|
-
...displayStyle(),
|
|
164
|
-
...positionStyle(),
|
|
165
|
-
...getCSSAlign(),
|
|
166
|
-
zIndex: _const.ELEMENT_Z_INDEX.STICKY
|
|
167
|
-
},
|
|
72
|
+
style: computedContainerStyles,
|
|
168
73
|
children: /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
169
74
|
...builderAttrs,
|
|
170
75
|
"data-id": builderProps?.uid,
|
|
@@ -4,51 +4,22 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var core = require('@gem-sdk/core');
|
|
6
6
|
var helpers = require('../../helpers.js');
|
|
7
|
-
require('
|
|
8
|
-
require('
|
|
9
|
-
var _const = require('../../common/const.js');
|
|
7
|
+
var system = require('@gem-sdk/system');
|
|
8
|
+
var styles = require('./common/styles.js');
|
|
10
9
|
|
|
11
10
|
const Sticky = ({ children, builderAttrs, setting, style, builderProps, advanced })=>{
|
|
12
11
|
const { width, fullWidth, position, background, display, preloadBgImage, isScrollToTop } = setting ?? {};
|
|
13
12
|
const advancedDisplay = advanced?.d;
|
|
14
13
|
const w = core.makeWidth(width, fullWidth);
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const getCSSAlign = ()=>{
|
|
25
|
-
return {
|
|
26
|
-
...getCSSAlignByDevice(position?.desktop, ''),
|
|
27
|
-
...getCSSAlignByDevice(position?.tablet ?? position?.desktop, '-tablet'),
|
|
28
|
-
...getCSSAlignByDevice(position?.mobile ?? position?.desktop, '-mobile')
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
const getDisplayStyle = (device, display, position)=>{
|
|
32
|
-
const style = {
|
|
33
|
-
[`--top${device}`]: 'auto',
|
|
34
|
-
[`--${position + device}`]: '0',
|
|
35
|
-
[`--pos${device}`]: getCSSPosition(position)
|
|
36
|
-
};
|
|
37
|
-
if (display === 'after-first-cart-button') style[`--d${device}`] = 'none';
|
|
38
|
-
return style;
|
|
39
|
-
};
|
|
40
|
-
const displayStyle = ()=>{
|
|
41
|
-
return {
|
|
42
|
-
...getDisplayStyle('', display?.desktop, position?.desktop),
|
|
43
|
-
...getDisplayStyle('-tablet', display?.tablet ?? display?.desktop, position?.tablet ?? position?.desktop),
|
|
44
|
-
...getDisplayStyle('-mobile', display?.mobile ?? display?.desktop, position?.mobile ?? position?.desktop)
|
|
45
|
-
};
|
|
46
|
-
};
|
|
47
|
-
return core.template`
|
|
48
|
-
${core.RenderIf(!!preloadBgImage, `${core.RenderIf(!!background?.desktop?.image?.src, `<link rel="preload" href="${background?.desktop?.image?.src}" as="image" />`)}${core.RenderIf(!!background?.tablet?.image?.src, `<link rel="preload" href="${background?.tablet?.image?.src}" as="image" />`)}${core.RenderIf(!!background?.mobile?.image?.src, `<link rel="preload" href="${background?.mobile?.image?.src}" as="image" />`)}`)}
|
|
49
|
-
<gp-sticky
|
|
50
|
-
data-id="${builderProps?.uid}"
|
|
51
|
-
gp-data='${JSON.stringify({
|
|
14
|
+
const computedContainerStyles = system.createStyle(styles.getContainerStyles({
|
|
15
|
+
w,
|
|
16
|
+
background,
|
|
17
|
+
position,
|
|
18
|
+
style,
|
|
19
|
+
display
|
|
20
|
+
}));
|
|
21
|
+
const computedContainerClasses = system.createClass(core.composeClasses(`${builderProps?.uid} ${helpers.getSettingPreloadData('gps-lazy')} ${advanced?.cssClass} ${isScrollToTop ? '!gp-pointer-events-none [&_gp-button_a]:!gp-pointer-events-auto' : ''}`));
|
|
22
|
+
const createDataState = system.createStateOrContext({
|
|
52
23
|
uid: builderProps?.uid,
|
|
53
24
|
setting: {
|
|
54
25
|
display
|
|
@@ -56,19 +27,15 @@ const Sticky = ({ children, builderAttrs, setting, style, builderProps, advanced
|
|
|
56
27
|
advanced: {
|
|
57
28
|
d: advancedDisplay
|
|
58
29
|
}
|
|
59
|
-
})
|
|
30
|
+
});
|
|
31
|
+
return core.template`
|
|
32
|
+
${core.RenderIf(!!preloadBgImage, `${core.RenderIf(!!background?.desktop?.image?.src, `<link rel="preload" href="${background?.desktop?.image?.src}" as="image" />`)}${core.RenderIf(!!background?.tablet?.image?.src, `<link rel="preload" href="${background?.tablet?.image?.src}" as="image" />`)}${core.RenderIf(!!background?.mobile?.image?.src, `<link rel="preload" href="${background?.mobile?.image?.src}" as="image" />`)}`)}
|
|
33
|
+
<gp-sticky
|
|
34
|
+
gp-data='${JSON.stringify(createDataState)}'
|
|
60
35
|
id="${builderProps?.uid}"
|
|
61
36
|
data-id="${builderProps?.uid}"
|
|
62
|
-
class="${
|
|
63
|
-
style="${
|
|
64
|
-
margin: '0 auto',
|
|
65
|
-
...style,
|
|
66
|
-
...core.makeStyleResponsive('w', w),
|
|
67
|
-
...core.getStyleBackgroundByDevice(background),
|
|
68
|
-
...displayStyle(),
|
|
69
|
-
...getCSSAlign(),
|
|
70
|
-
'z-index': _const.ELEMENT_Z_INDEX.STICKY
|
|
71
|
-
}}"
|
|
37
|
+
class="${computedContainerClasses}"
|
|
38
|
+
style="${computedContainerStyles}"
|
|
72
39
|
>
|
|
73
40
|
<div ${{
|
|
74
41
|
...builderAttrs
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@gem-sdk/core');
|
|
4
|
+
var helpers = require('../../../helpers.js');
|
|
5
|
+
require('react/jsx-runtime');
|
|
6
|
+
require('react');
|
|
7
|
+
var _const = require('../../../common/const.js');
|
|
8
|
+
|
|
9
|
+
const getCSSAlignByDevice = (position, device)=>{
|
|
10
|
+
return {
|
|
11
|
+
[`--left${device}`]: position == 'top' ? '0' : '50%',
|
|
12
|
+
[`--t${device}`]: position == 'top' ? 'unset' : 'translateX(-50%)'
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
const getCSSAlign = (position)=>{
|
|
16
|
+
return {
|
|
17
|
+
...getCSSAlignByDevice(position?.desktop, ''),
|
|
18
|
+
...getCSSAlignByDevice(position?.tablet ?? position?.desktop, '-tablet'),
|
|
19
|
+
...getCSSAlignByDevice(position?.mobile ?? position?.desktop, '-mobile')
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const displayStyle = (display, position)=>{
|
|
23
|
+
return {
|
|
24
|
+
...helpers.getDisplayStyle('', display?.desktop),
|
|
25
|
+
...helpers.getDisplayStyle('-tablet', display?.tablet ?? display?.desktop),
|
|
26
|
+
...helpers.getDisplayStyle('-mobile', display?.mobile ?? display?.desktop)
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const getContainerStyles = (args)=>{
|
|
30
|
+
const { style, w, background, position, display } = args;
|
|
31
|
+
return {
|
|
32
|
+
margin: '0 auto',
|
|
33
|
+
...style,
|
|
34
|
+
...core.makeStyleResponsive('w', w),
|
|
35
|
+
...core.getStyleBackgroundByDevice(background),
|
|
36
|
+
...displayStyle(display),
|
|
37
|
+
...getCSSAlign(position),
|
|
38
|
+
'z-index': _const.ELEMENT_Z_INDEX.STICKY
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
exports.getContainerStyles = getContainerStyles;
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@gem-sdk/core');
|
|
6
|
+
var helpers = require('../../../grid/row/commons/helpers.js');
|
|
7
|
+
var React = require('react');
|
|
8
|
+
|
|
9
|
+
const minimizeSvg = ` <svg
|
|
10
|
+
className="gp-ml-[7px]"
|
|
11
|
+
width="16"
|
|
12
|
+
height="16"
|
|
13
|
+
viewBox="0 0 16 16"
|
|
14
|
+
fill="none"
|
|
15
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
16
|
+
>
|
|
17
|
+
<path
|
|
18
|
+
fillRule="evenodd"
|
|
19
|
+
clipRule="evenodd"
|
|
20
|
+
d="M5.75 1.25C4.64543 1.25 3.75 2.14543 3.75 3.25C3.75 4.35457 4.64543 5.25 5.75 5.25C6.85457 5.25 7.75 4.35457 7.75 3.25C7.75 2.14543 6.85457 1.25 5.75 1.25ZM4.75 3.25C4.75 2.69772 5.19772 2.25 5.75 2.25C6.30228 2.25 6.75 2.69772 6.75 3.25C6.75 3.80228 6.30228 4.25 5.75 4.25C5.19772 4.25 4.75 3.80228 4.75 3.25Z"
|
|
21
|
+
fill="#3C67FF"
|
|
22
|
+
/>
|
|
23
|
+
<path
|
|
24
|
+
fillRule="evenodd"
|
|
25
|
+
clipRule="evenodd"
|
|
26
|
+
d="M5.75 6C4.64543 6 3.75 6.89543 3.75 8C3.75 9.10457 4.64543 10 5.75 10C6.85457 10 7.75 9.10457 7.75 8C7.75 6.89543 6.85457 6 5.75 6ZM4.75 8C4.75 7.44772 5.19772 7 5.75 7C6.30228 7 6.75 7.44772 6.75 8C6.75 8.55228 6.30228 9 5.75 9C5.19772 9 4.75 8.55228 4.75 8Z"
|
|
27
|
+
fill="#3C67FF"
|
|
28
|
+
/>
|
|
29
|
+
<path
|
|
30
|
+
fillRule="evenodd"
|
|
31
|
+
clipRule="evenodd"
|
|
32
|
+
d="M3.75 12.75C3.75 11.6454 4.64543 10.75 5.75 10.75C6.85457 10.75 7.75 11.6454 7.75 12.75C7.75 13.8546 6.85457 14.75 5.75 14.75C4.64543 14.75 3.75 13.8546 3.75 12.75ZM5.75 11.75C5.19772 11.75 4.75 12.1977 4.75 12.75C4.75 13.3023 5.19772 13.75 5.75 13.75C6.30228 13.75 6.75 13.3023 6.75 12.75C6.75 12.1977 6.30228 11.75 5.75 11.75Z"
|
|
33
|
+
fill="#3C67FF"
|
|
34
|
+
/>
|
|
35
|
+
<path
|
|
36
|
+
fillRule="evenodd"
|
|
37
|
+
clipRule="evenodd"
|
|
38
|
+
d="M10.25 1.25C9.14543 1.25 8.25 2.14543 8.25 3.25C8.25 4.35457 9.14543 5.25 10.25 5.25C11.3546 5.25 12.25 4.35457 12.25 3.25C12.25 2.14543 11.3546 1.25 10.25 1.25ZM9.25 3.25C9.25 2.69772 9.69772 2.25 10.25 2.25C10.8023 2.25 11.25 2.69772 11.25 3.25C11.25 3.80228 10.8023 4.25 10.25 4.25C9.69772 4.25 9.25 3.80228 9.25 3.25Z"
|
|
39
|
+
fill="#3C67FF"
|
|
40
|
+
/>
|
|
41
|
+
<path
|
|
42
|
+
fillRule="evenodd"
|
|
43
|
+
clipRule="evenodd"
|
|
44
|
+
d="M8.25 8C8.25 6.89543 9.14543 6 10.25 6C11.3546 6 12.25 6.89543 12.25 8C12.25 9.10457 11.3546 10 10.25 10C9.14543 10 8.25 9.10457 8.25 8ZM10.25 7C9.69772 7 9.25 7.44772 9.25 8C9.25 8.55228 9.69772 9 10.25 9C10.8023 9 11.25 8.55228 11.25 8C11.25 7.44772 10.8023 7 10.25 7Z"
|
|
45
|
+
fill="#3C67FF"
|
|
46
|
+
/>
|
|
47
|
+
<path
|
|
48
|
+
fillRule="evenodd"
|
|
49
|
+
clipRule="evenodd"
|
|
50
|
+
d="M10.25 10.75C9.14543 10.75 8.25 11.6454 8.25 12.75C8.25 13.8546 9.14543 14.75 10.25 14.75C11.3546 14.75 12.25 13.8546 12.25 12.75C12.25 11.6454 11.3546 10.75 10.25 10.75ZM9.25 12.75C9.25 12.1977 9.69772 11.75 10.25 11.75C10.8023 11.75 11.25 12.1977 11.25 12.75C11.25 13.3023 10.8023 13.75 10.25 13.75C9.69772 13.75 9.25 13.3023 9.25 12.75Z"
|
|
51
|
+
fill="#3C67FF"
|
|
52
|
+
/>
|
|
53
|
+
</svg>`;
|
|
54
|
+
const useSticky = (setting)=>{
|
|
55
|
+
const { width, fullWidth, position } = setting ?? {};
|
|
56
|
+
const styleObject = helpers.createStyleObject(width, fullWidth ?? {
|
|
57
|
+
desktop: false,
|
|
58
|
+
tablet: false,
|
|
59
|
+
mobile: false
|
|
60
|
+
});
|
|
61
|
+
const w = core.makeStyleResponsive('w', styleObject.content);
|
|
62
|
+
const sidebarMode = core.usePageStore((s)=>s.sidebarMode === 'interaction');
|
|
63
|
+
const currentDevice = core.useCurrentDevice();
|
|
64
|
+
const getCSSPosition = (position)=>{
|
|
65
|
+
return position == 'top' ? 'sticky' : 'fixed';
|
|
66
|
+
};
|
|
67
|
+
const getCSSAlignByDevice = (position, device)=>{
|
|
68
|
+
return {
|
|
69
|
+
[`--left${device}`]: position == 'top' ? '0' : '50%',
|
|
70
|
+
[`--t${device}`]: position == 'top' ? 'unset' : 'translateX(-50%)'
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
const getCSSAlign = ()=>{
|
|
74
|
+
return {
|
|
75
|
+
...getCSSAlignByDevice(position?.desktop, ''),
|
|
76
|
+
...getCSSAlignByDevice(position?.tablet ?? position?.desktop, '-tablet'),
|
|
77
|
+
...getCSSAlignByDevice(position?.mobile ?? position?.desktop, '-mobile')
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
const gap = React.useMemo(()=>{
|
|
81
|
+
if (sidebarMode && position?.[currentDevice] === 'top') {
|
|
82
|
+
return '40px';
|
|
83
|
+
}
|
|
84
|
+
return undefined;
|
|
85
|
+
}, [
|
|
86
|
+
currentDevice,
|
|
87
|
+
sidebarMode,
|
|
88
|
+
position
|
|
89
|
+
]);
|
|
90
|
+
const displayStyle = React.useCallback(()=>{
|
|
91
|
+
return {
|
|
92
|
+
[`--top`]: gap ?? 'auto',
|
|
93
|
+
[`--top-tablet`]: gap ?? 'auto',
|
|
94
|
+
[`--top-mobile`]: gap ?? 'auto',
|
|
95
|
+
[`--${position?.desktop}`]: gap ?? 0,
|
|
96
|
+
[`--${position?.tablet ?? position?.desktop}-tablet`]: gap ?? 0,
|
|
97
|
+
[`--${position?.mobile ?? position?.desktop}-mobile`]: gap ?? 0
|
|
98
|
+
};
|
|
99
|
+
}, [
|
|
100
|
+
gap,
|
|
101
|
+
position
|
|
102
|
+
]);
|
|
103
|
+
const positionStyle = ()=>{
|
|
104
|
+
return {
|
|
105
|
+
[`--pos`]: getCSSPosition(position?.desktop),
|
|
106
|
+
[`--pos-tablet`]: getCSSPosition(position?.tablet ?? position?.desktop),
|
|
107
|
+
[`--pos-mobile`]: getCSSPosition(position?.mobile ?? position?.desktop)
|
|
108
|
+
};
|
|
109
|
+
};
|
|
110
|
+
return {
|
|
111
|
+
w,
|
|
112
|
+
displayStyle,
|
|
113
|
+
positionStyle,
|
|
114
|
+
getCSSAlign
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
exports.default = useSticky;
|
|
119
|
+
exports.minimizeSvg = minimizeSvg;
|
package/dist/cjs/sticky/index.js
CHANGED
|
@@ -1,71 +1,30 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
3
|
-
import {
|
|
3
|
+
import { getStyleBackgroundByDevice, composeClasses, cls, isEmptyChildren } from '@gem-sdk/core';
|
|
4
4
|
import Head from 'next/head';
|
|
5
5
|
import ChildrenDroppable from '../../grid/components/ChildrenDroppable.js';
|
|
6
|
-
import
|
|
6
|
+
import 'react';
|
|
7
7
|
import { ELEMENT_Z_INDEX } from '../../common/const.js';
|
|
8
|
-
import {
|
|
8
|
+
import useSticky, { minimizeSvg } from './hooks/useSticky.js';
|
|
9
|
+
import { createStyle, createClass } from '@gem-sdk/system';
|
|
9
10
|
|
|
10
11
|
const Sticky = ({ children, builderAttrs, setting, style, builderProps })=>{
|
|
11
|
-
const {
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const { minimize, background, preloadBgImage } = setting ?? {};
|
|
13
|
+
const { w, displayStyle, positionStyle, getCSSAlign } = useSticky(setting);
|
|
14
|
+
const computedContainerStyles = createStyle({
|
|
15
|
+
margin: '0 auto',
|
|
16
|
+
...style,
|
|
17
|
+
...w,
|
|
18
|
+
...getStyleBackgroundByDevice(background),
|
|
19
|
+
...displayStyle(),
|
|
20
|
+
...positionStyle(),
|
|
21
|
+
...getCSSAlign(),
|
|
22
|
+
zIndex: ELEMENT_Z_INDEX.STICKY
|
|
16
23
|
});
|
|
17
|
-
const
|
|
18
|
-
const sidebarMode = usePageStore((s)=>s.sidebarMode === 'interaction');
|
|
19
|
-
const currentDevice = useCurrentDevice();
|
|
20
|
-
const getCSSPosition = (position)=>{
|
|
21
|
-
return position == 'top' ? 'sticky' : 'fixed';
|
|
22
|
-
};
|
|
23
|
-
const getCSSAlignByDevice = (position, device)=>{
|
|
24
|
-
return {
|
|
25
|
-
[`--left${device}`]: position == 'top' ? '0' : '50%',
|
|
26
|
-
[`--t${device}`]: position == 'top' ? 'unset' : 'translateX(-50%)'
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
const getCSSAlign = ()=>{
|
|
30
|
-
return {
|
|
31
|
-
...getCSSAlignByDevice(position?.desktop, ''),
|
|
32
|
-
...getCSSAlignByDevice(position?.tablet ?? position?.desktop, '-tablet'),
|
|
33
|
-
...getCSSAlignByDevice(position?.mobile ?? position?.desktop, '-mobile')
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
const gap = useMemo(()=>{
|
|
37
|
-
if (sidebarMode && position?.[currentDevice] === 'top') {
|
|
38
|
-
return '40px';
|
|
39
|
-
}
|
|
40
|
-
return undefined;
|
|
41
|
-
}, [
|
|
42
|
-
currentDevice,
|
|
43
|
-
sidebarMode,
|
|
44
|
-
position
|
|
45
|
-
]);
|
|
46
|
-
const displayStyle = useCallback(()=>{
|
|
47
|
-
return {
|
|
48
|
-
[`--top`]: gap ?? 'auto',
|
|
49
|
-
[`--top-tablet`]: gap ?? 'auto',
|
|
50
|
-
[`--top-mobile`]: gap ?? 'auto',
|
|
51
|
-
[`--${position?.desktop}`]: gap ?? 0,
|
|
52
|
-
[`--${position?.tablet ?? position?.desktop}-tablet`]: gap ?? 0,
|
|
53
|
-
[`--${position?.mobile ?? position?.desktop}-mobile`]: gap ?? 0
|
|
54
|
-
};
|
|
55
|
-
}, [
|
|
56
|
-
gap,
|
|
57
|
-
position
|
|
58
|
-
]);
|
|
59
|
-
const positionStyle = ()=>{
|
|
60
|
-
return {
|
|
61
|
-
[`--pos`]: getCSSPosition(position?.desktop),
|
|
62
|
-
[`--pos-tablet`]: getCSSPosition(position?.tablet ?? position?.desktop),
|
|
63
|
-
[`--pos-mobile`]: getCSSPosition(position?.mobile ?? position?.desktop)
|
|
64
|
-
};
|
|
65
|
-
};
|
|
24
|
+
const computedMinimizeClasses = createClass(composeClasses('sticky-minimize gp-fixed gp-flex gp-h-[32px] gp-w-[76px] gp-cursor-pointer gp-items-center gp-gap-[4px] gp-border gp-border-[#D8E1FF] gp-bg-white hover:gp-bg-[#D8E1FF]'));
|
|
66
25
|
if (minimize) {
|
|
67
26
|
return /*#__PURE__*/ jsxs("div", {
|
|
68
|
-
className:
|
|
27
|
+
className: computedMinimizeClasses,
|
|
69
28
|
"data-uid": builderProps?.uid,
|
|
70
29
|
"data-id": builderProps?.uid,
|
|
71
30
|
...builderAttrs,
|
|
@@ -74,52 +33,7 @@ const Sticky = ({ children, builderAttrs, setting, style, builderProps })=>{
|
|
|
74
33
|
zIndex: ELEMENT_Z_INDEX.STICKY
|
|
75
34
|
},
|
|
76
35
|
children: [
|
|
77
|
-
|
|
78
|
-
className: "gp-ml-[7px]",
|
|
79
|
-
width: "16",
|
|
80
|
-
height: "16",
|
|
81
|
-
viewBox: "0 0 16 16",
|
|
82
|
-
fill: "none",
|
|
83
|
-
xmlns: "http://www.w3.org/2000/svg",
|
|
84
|
-
children: [
|
|
85
|
-
/*#__PURE__*/ jsx("path", {
|
|
86
|
-
fillRule: "evenodd",
|
|
87
|
-
clipRule: "evenodd",
|
|
88
|
-
d: "M5.75 1.25C4.64543 1.25 3.75 2.14543 3.75 3.25C3.75 4.35457 4.64543 5.25 5.75 5.25C6.85457 5.25 7.75 4.35457 7.75 3.25C7.75 2.14543 6.85457 1.25 5.75 1.25ZM4.75 3.25C4.75 2.69772 5.19772 2.25 5.75 2.25C6.30228 2.25 6.75 2.69772 6.75 3.25C6.75 3.80228 6.30228 4.25 5.75 4.25C5.19772 4.25 4.75 3.80228 4.75 3.25Z",
|
|
89
|
-
fill: "#3C67FF"
|
|
90
|
-
}),
|
|
91
|
-
/*#__PURE__*/ jsx("path", {
|
|
92
|
-
fillRule: "evenodd",
|
|
93
|
-
clipRule: "evenodd",
|
|
94
|
-
d: "M5.75 6C4.64543 6 3.75 6.89543 3.75 8C3.75 9.10457 4.64543 10 5.75 10C6.85457 10 7.75 9.10457 7.75 8C7.75 6.89543 6.85457 6 5.75 6ZM4.75 8C4.75 7.44772 5.19772 7 5.75 7C6.30228 7 6.75 7.44772 6.75 8C6.75 8.55228 6.30228 9 5.75 9C5.19772 9 4.75 8.55228 4.75 8Z",
|
|
95
|
-
fill: "#3C67FF"
|
|
96
|
-
}),
|
|
97
|
-
/*#__PURE__*/ jsx("path", {
|
|
98
|
-
fillRule: "evenodd",
|
|
99
|
-
clipRule: "evenodd",
|
|
100
|
-
d: "M3.75 12.75C3.75 11.6454 4.64543 10.75 5.75 10.75C6.85457 10.75 7.75 11.6454 7.75 12.75C7.75 13.8546 6.85457 14.75 5.75 14.75C4.64543 14.75 3.75 13.8546 3.75 12.75ZM5.75 11.75C5.19772 11.75 4.75 12.1977 4.75 12.75C4.75 13.3023 5.19772 13.75 5.75 13.75C6.30228 13.75 6.75 13.3023 6.75 12.75C6.75 12.1977 6.30228 11.75 5.75 11.75Z",
|
|
101
|
-
fill: "#3C67FF"
|
|
102
|
-
}),
|
|
103
|
-
/*#__PURE__*/ jsx("path", {
|
|
104
|
-
fillRule: "evenodd",
|
|
105
|
-
clipRule: "evenodd",
|
|
106
|
-
d: "M10.25 1.25C9.14543 1.25 8.25 2.14543 8.25 3.25C8.25 4.35457 9.14543 5.25 10.25 5.25C11.3546 5.25 12.25 4.35457 12.25 3.25C12.25 2.14543 11.3546 1.25 10.25 1.25ZM9.25 3.25C9.25 2.69772 9.69772 2.25 10.25 2.25C10.8023 2.25 11.25 2.69772 11.25 3.25C11.25 3.80228 10.8023 4.25 10.25 4.25C9.69772 4.25 9.25 3.80228 9.25 3.25Z",
|
|
107
|
-
fill: "#3C67FF"
|
|
108
|
-
}),
|
|
109
|
-
/*#__PURE__*/ jsx("path", {
|
|
110
|
-
fillRule: "evenodd",
|
|
111
|
-
clipRule: "evenodd",
|
|
112
|
-
d: "M8.25 8C8.25 6.89543 9.14543 6 10.25 6C11.3546 6 12.25 6.89543 12.25 8C12.25 9.10457 11.3546 10 10.25 10C9.14543 10 8.25 9.10457 8.25 8ZM10.25 7C9.69772 7 9.25 7.44772 9.25 8C9.25 8.55228 9.69772 9 10.25 9C10.8023 9 11.25 8.55228 11.25 8C11.25 7.44772 10.8023 7 10.25 7Z",
|
|
113
|
-
fill: "#3C67FF"
|
|
114
|
-
}),
|
|
115
|
-
/*#__PURE__*/ jsx("path", {
|
|
116
|
-
fillRule: "evenodd",
|
|
117
|
-
clipRule: "evenodd",
|
|
118
|
-
d: "M10.25 10.75C9.14543 10.75 8.25 11.6454 8.25 12.75C8.25 13.8546 9.14543 14.75 10.25 14.75C11.3546 14.75 12.25 13.8546 12.25 12.75C12.25 11.6454 11.3546 10.75 10.25 10.75ZM9.25 12.75C9.25 12.1977 9.69772 11.75 10.25 11.75C10.8023 11.75 11.25 12.1977 11.25 12.75C11.25 13.3023 10.8023 13.75 10.25 13.75C9.69772 13.75 9.25 13.3023 9.25 12.75Z",
|
|
119
|
-
fill: "#3C67FF"
|
|
120
|
-
})
|
|
121
|
-
]
|
|
122
|
-
}),
|
|
36
|
+
minimizeSvg,
|
|
123
37
|
/*#__PURE__*/ jsx("span", {
|
|
124
38
|
className: "gp-text-[12px] gp-font-medium gp-text-[#3C67FF]",
|
|
125
39
|
children: "Sticky"
|
|
@@ -151,16 +65,7 @@ const Sticky = ({ children, builderAttrs, setting, style, builderProps })=>{
|
|
|
151
65
|
/*#__PURE__*/ jsx("div", {
|
|
152
66
|
className: cls('sticky-wrapper', builderProps?.uid),
|
|
153
67
|
id: builderProps?.uid,
|
|
154
|
-
style:
|
|
155
|
-
margin: '0 auto',
|
|
156
|
-
...style,
|
|
157
|
-
...w,
|
|
158
|
-
...getStyleBackgroundByDevice(background),
|
|
159
|
-
...displayStyle(),
|
|
160
|
-
...positionStyle(),
|
|
161
|
-
...getCSSAlign(),
|
|
162
|
-
zIndex: ELEMENT_Z_INDEX.STICKY
|
|
163
|
-
},
|
|
68
|
+
style: computedContainerStyles,
|
|
164
69
|
children: /*#__PURE__*/ jsx("div", {
|
|
165
70
|
...builderAttrs,
|
|
166
71
|
"data-id": builderProps?.uid,
|
|
@@ -1,50 +1,21 @@
|
|
|
1
|
-
import { makeWidth, template, RenderIf,
|
|
1
|
+
import { makeWidth, composeClasses, template, RenderIf, isLocalEnv, baseAssetURL } from '@gem-sdk/core';
|
|
2
2
|
import { getSettingPreloadData } from '../../helpers.js';
|
|
3
|
-
import '
|
|
4
|
-
import '
|
|
5
|
-
import { ELEMENT_Z_INDEX } from '../../common/const.js';
|
|
3
|
+
import { createStyle, createClass, createStateOrContext } from '@gem-sdk/system';
|
|
4
|
+
import { getContainerStyles } from './common/styles.js';
|
|
6
5
|
|
|
7
6
|
const Sticky = ({ children, builderAttrs, setting, style, builderProps, advanced })=>{
|
|
8
7
|
const { width, fullWidth, position, background, display, preloadBgImage, isScrollToTop } = setting ?? {};
|
|
9
8
|
const advancedDisplay = advanced?.d;
|
|
10
9
|
const w = makeWidth(width, fullWidth);
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const getCSSAlign = ()=>{
|
|
21
|
-
return {
|
|
22
|
-
...getCSSAlignByDevice(position?.desktop, ''),
|
|
23
|
-
...getCSSAlignByDevice(position?.tablet ?? position?.desktop, '-tablet'),
|
|
24
|
-
...getCSSAlignByDevice(position?.mobile ?? position?.desktop, '-mobile')
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const getDisplayStyle = (device, display, position)=>{
|
|
28
|
-
const style = {
|
|
29
|
-
[`--top${device}`]: 'auto',
|
|
30
|
-
[`--${position + device}`]: '0',
|
|
31
|
-
[`--pos${device}`]: getCSSPosition(position)
|
|
32
|
-
};
|
|
33
|
-
if (display === 'after-first-cart-button') style[`--d${device}`] = 'none';
|
|
34
|
-
return style;
|
|
35
|
-
};
|
|
36
|
-
const displayStyle = ()=>{
|
|
37
|
-
return {
|
|
38
|
-
...getDisplayStyle('', display?.desktop, position?.desktop),
|
|
39
|
-
...getDisplayStyle('-tablet', display?.tablet ?? display?.desktop, position?.tablet ?? position?.desktop),
|
|
40
|
-
...getDisplayStyle('-mobile', display?.mobile ?? display?.desktop, position?.mobile ?? position?.desktop)
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
return template`
|
|
44
|
-
${RenderIf(!!preloadBgImage, `${RenderIf(!!background?.desktop?.image?.src, `<link rel="preload" href="${background?.desktop?.image?.src}" as="image" />`)}${RenderIf(!!background?.tablet?.image?.src, `<link rel="preload" href="${background?.tablet?.image?.src}" as="image" />`)}${RenderIf(!!background?.mobile?.image?.src, `<link rel="preload" href="${background?.mobile?.image?.src}" as="image" />`)}`)}
|
|
45
|
-
<gp-sticky
|
|
46
|
-
data-id="${builderProps?.uid}"
|
|
47
|
-
gp-data='${JSON.stringify({
|
|
10
|
+
const computedContainerStyles = createStyle(getContainerStyles({
|
|
11
|
+
w,
|
|
12
|
+
background,
|
|
13
|
+
position,
|
|
14
|
+
style,
|
|
15
|
+
display
|
|
16
|
+
}));
|
|
17
|
+
const computedContainerClasses = createClass(composeClasses(`${builderProps?.uid} ${getSettingPreloadData('gps-lazy')} ${advanced?.cssClass} ${isScrollToTop ? '!gp-pointer-events-none [&_gp-button_a]:!gp-pointer-events-auto' : ''}`));
|
|
18
|
+
const createDataState = createStateOrContext({
|
|
48
19
|
uid: builderProps?.uid,
|
|
49
20
|
setting: {
|
|
50
21
|
display
|
|
@@ -52,19 +23,15 @@ const Sticky = ({ children, builderAttrs, setting, style, builderProps, advanced
|
|
|
52
23
|
advanced: {
|
|
53
24
|
d: advancedDisplay
|
|
54
25
|
}
|
|
55
|
-
})
|
|
26
|
+
});
|
|
27
|
+
return template`
|
|
28
|
+
${RenderIf(!!preloadBgImage, `${RenderIf(!!background?.desktop?.image?.src, `<link rel="preload" href="${background?.desktop?.image?.src}" as="image" />`)}${RenderIf(!!background?.tablet?.image?.src, `<link rel="preload" href="${background?.tablet?.image?.src}" as="image" />`)}${RenderIf(!!background?.mobile?.image?.src, `<link rel="preload" href="${background?.mobile?.image?.src}" as="image" />`)}`)}
|
|
29
|
+
<gp-sticky
|
|
30
|
+
gp-data='${JSON.stringify(createDataState)}'
|
|
56
31
|
id="${builderProps?.uid}"
|
|
57
32
|
data-id="${builderProps?.uid}"
|
|
58
|
-
class="${
|
|
59
|
-
style="${
|
|
60
|
-
margin: '0 auto',
|
|
61
|
-
...style,
|
|
62
|
-
...makeStyleResponsive('w', w),
|
|
63
|
-
...getStyleBackgroundByDevice(background),
|
|
64
|
-
...displayStyle(),
|
|
65
|
-
...getCSSAlign(),
|
|
66
|
-
'z-index': ELEMENT_Z_INDEX.STICKY
|
|
67
|
-
}}"
|
|
33
|
+
class="${computedContainerClasses}"
|
|
34
|
+
style="${computedContainerStyles}"
|
|
68
35
|
>
|
|
69
36
|
<div ${{
|
|
70
37
|
...builderAttrs
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { makeStyleResponsive, getStyleBackgroundByDevice } from '@gem-sdk/core';
|
|
2
|
+
import { getDisplayStyle } from '../../../helpers.js';
|
|
3
|
+
import 'react/jsx-runtime';
|
|
4
|
+
import 'react';
|
|
5
|
+
import { ELEMENT_Z_INDEX } from '../../../common/const.js';
|
|
6
|
+
|
|
7
|
+
const getCSSAlignByDevice = (position, device)=>{
|
|
8
|
+
return {
|
|
9
|
+
[`--left${device}`]: position == 'top' ? '0' : '50%',
|
|
10
|
+
[`--t${device}`]: position == 'top' ? 'unset' : 'translateX(-50%)'
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const getCSSAlign = (position)=>{
|
|
14
|
+
return {
|
|
15
|
+
...getCSSAlignByDevice(position?.desktop, ''),
|
|
16
|
+
...getCSSAlignByDevice(position?.tablet ?? position?.desktop, '-tablet'),
|
|
17
|
+
...getCSSAlignByDevice(position?.mobile ?? position?.desktop, '-mobile')
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const displayStyle = (display, position)=>{
|
|
21
|
+
return {
|
|
22
|
+
...getDisplayStyle('', display?.desktop),
|
|
23
|
+
...getDisplayStyle('-tablet', display?.tablet ?? display?.desktop),
|
|
24
|
+
...getDisplayStyle('-mobile', display?.mobile ?? display?.desktop)
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const getContainerStyles = (args)=>{
|
|
28
|
+
const { style, w, background, position, display } = args;
|
|
29
|
+
return {
|
|
30
|
+
margin: '0 auto',
|
|
31
|
+
...style,
|
|
32
|
+
...makeStyleResponsive('w', w),
|
|
33
|
+
...getStyleBackgroundByDevice(background),
|
|
34
|
+
...displayStyle(display),
|
|
35
|
+
...getCSSAlign(position),
|
|
36
|
+
'z-index': ELEMENT_Z_INDEX.STICKY
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export { getContainerStyles };
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { makeStyleResponsive, usePageStore, useCurrentDevice } from '@gem-sdk/core';
|
|
2
|
+
import { createStyleObject } from '../../../grid/row/commons/helpers.js';
|
|
3
|
+
import { useMemo, useCallback } from 'react';
|
|
4
|
+
|
|
5
|
+
const minimizeSvg = ` <svg
|
|
6
|
+
className="gp-ml-[7px]"
|
|
7
|
+
width="16"
|
|
8
|
+
height="16"
|
|
9
|
+
viewBox="0 0 16 16"
|
|
10
|
+
fill="none"
|
|
11
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
12
|
+
>
|
|
13
|
+
<path
|
|
14
|
+
fillRule="evenodd"
|
|
15
|
+
clipRule="evenodd"
|
|
16
|
+
d="M5.75 1.25C4.64543 1.25 3.75 2.14543 3.75 3.25C3.75 4.35457 4.64543 5.25 5.75 5.25C6.85457 5.25 7.75 4.35457 7.75 3.25C7.75 2.14543 6.85457 1.25 5.75 1.25ZM4.75 3.25C4.75 2.69772 5.19772 2.25 5.75 2.25C6.30228 2.25 6.75 2.69772 6.75 3.25C6.75 3.80228 6.30228 4.25 5.75 4.25C5.19772 4.25 4.75 3.80228 4.75 3.25Z"
|
|
17
|
+
fill="#3C67FF"
|
|
18
|
+
/>
|
|
19
|
+
<path
|
|
20
|
+
fillRule="evenodd"
|
|
21
|
+
clipRule="evenodd"
|
|
22
|
+
d="M5.75 6C4.64543 6 3.75 6.89543 3.75 8C3.75 9.10457 4.64543 10 5.75 10C6.85457 10 7.75 9.10457 7.75 8C7.75 6.89543 6.85457 6 5.75 6ZM4.75 8C4.75 7.44772 5.19772 7 5.75 7C6.30228 7 6.75 7.44772 6.75 8C6.75 8.55228 6.30228 9 5.75 9C5.19772 9 4.75 8.55228 4.75 8Z"
|
|
23
|
+
fill="#3C67FF"
|
|
24
|
+
/>
|
|
25
|
+
<path
|
|
26
|
+
fillRule="evenodd"
|
|
27
|
+
clipRule="evenodd"
|
|
28
|
+
d="M3.75 12.75C3.75 11.6454 4.64543 10.75 5.75 10.75C6.85457 10.75 7.75 11.6454 7.75 12.75C7.75 13.8546 6.85457 14.75 5.75 14.75C4.64543 14.75 3.75 13.8546 3.75 12.75ZM5.75 11.75C5.19772 11.75 4.75 12.1977 4.75 12.75C4.75 13.3023 5.19772 13.75 5.75 13.75C6.30228 13.75 6.75 13.3023 6.75 12.75C6.75 12.1977 6.30228 11.75 5.75 11.75Z"
|
|
29
|
+
fill="#3C67FF"
|
|
30
|
+
/>
|
|
31
|
+
<path
|
|
32
|
+
fillRule="evenodd"
|
|
33
|
+
clipRule="evenodd"
|
|
34
|
+
d="M10.25 1.25C9.14543 1.25 8.25 2.14543 8.25 3.25C8.25 4.35457 9.14543 5.25 10.25 5.25C11.3546 5.25 12.25 4.35457 12.25 3.25C12.25 2.14543 11.3546 1.25 10.25 1.25ZM9.25 3.25C9.25 2.69772 9.69772 2.25 10.25 2.25C10.8023 2.25 11.25 2.69772 11.25 3.25C11.25 3.80228 10.8023 4.25 10.25 4.25C9.69772 4.25 9.25 3.80228 9.25 3.25Z"
|
|
35
|
+
fill="#3C67FF"
|
|
36
|
+
/>
|
|
37
|
+
<path
|
|
38
|
+
fillRule="evenodd"
|
|
39
|
+
clipRule="evenodd"
|
|
40
|
+
d="M8.25 8C8.25 6.89543 9.14543 6 10.25 6C11.3546 6 12.25 6.89543 12.25 8C12.25 9.10457 11.3546 10 10.25 10C9.14543 10 8.25 9.10457 8.25 8ZM10.25 7C9.69772 7 9.25 7.44772 9.25 8C9.25 8.55228 9.69772 9 10.25 9C10.8023 9 11.25 8.55228 11.25 8C11.25 7.44772 10.8023 7 10.25 7Z"
|
|
41
|
+
fill="#3C67FF"
|
|
42
|
+
/>
|
|
43
|
+
<path
|
|
44
|
+
fillRule="evenodd"
|
|
45
|
+
clipRule="evenodd"
|
|
46
|
+
d="M10.25 10.75C9.14543 10.75 8.25 11.6454 8.25 12.75C8.25 13.8546 9.14543 14.75 10.25 14.75C11.3546 14.75 12.25 13.8546 12.25 12.75C12.25 11.6454 11.3546 10.75 10.25 10.75ZM9.25 12.75C9.25 12.1977 9.69772 11.75 10.25 11.75C10.8023 11.75 11.25 12.1977 11.25 12.75C11.25 13.3023 10.8023 13.75 10.25 13.75C9.69772 13.75 9.25 13.3023 9.25 12.75Z"
|
|
47
|
+
fill="#3C67FF"
|
|
48
|
+
/>
|
|
49
|
+
</svg>`;
|
|
50
|
+
const useSticky = (setting)=>{
|
|
51
|
+
const { width, fullWidth, position } = setting ?? {};
|
|
52
|
+
const styleObject = createStyleObject(width, fullWidth ?? {
|
|
53
|
+
desktop: false,
|
|
54
|
+
tablet: false,
|
|
55
|
+
mobile: false
|
|
56
|
+
});
|
|
57
|
+
const w = makeStyleResponsive('w', styleObject.content);
|
|
58
|
+
const sidebarMode = usePageStore((s)=>s.sidebarMode === 'interaction');
|
|
59
|
+
const currentDevice = useCurrentDevice();
|
|
60
|
+
const getCSSPosition = (position)=>{
|
|
61
|
+
return position == 'top' ? 'sticky' : 'fixed';
|
|
62
|
+
};
|
|
63
|
+
const getCSSAlignByDevice = (position, device)=>{
|
|
64
|
+
return {
|
|
65
|
+
[`--left${device}`]: position == 'top' ? '0' : '50%',
|
|
66
|
+
[`--t${device}`]: position == 'top' ? 'unset' : 'translateX(-50%)'
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
const getCSSAlign = ()=>{
|
|
70
|
+
return {
|
|
71
|
+
...getCSSAlignByDevice(position?.desktop, ''),
|
|
72
|
+
...getCSSAlignByDevice(position?.tablet ?? position?.desktop, '-tablet'),
|
|
73
|
+
...getCSSAlignByDevice(position?.mobile ?? position?.desktop, '-mobile')
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
const gap = useMemo(()=>{
|
|
77
|
+
if (sidebarMode && position?.[currentDevice] === 'top') {
|
|
78
|
+
return '40px';
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}, [
|
|
82
|
+
currentDevice,
|
|
83
|
+
sidebarMode,
|
|
84
|
+
position
|
|
85
|
+
]);
|
|
86
|
+
const displayStyle = useCallback(()=>{
|
|
87
|
+
return {
|
|
88
|
+
[`--top`]: gap ?? 'auto',
|
|
89
|
+
[`--top-tablet`]: gap ?? 'auto',
|
|
90
|
+
[`--top-mobile`]: gap ?? 'auto',
|
|
91
|
+
[`--${position?.desktop}`]: gap ?? 0,
|
|
92
|
+
[`--${position?.tablet ?? position?.desktop}-tablet`]: gap ?? 0,
|
|
93
|
+
[`--${position?.mobile ?? position?.desktop}-mobile`]: gap ?? 0
|
|
94
|
+
};
|
|
95
|
+
}, [
|
|
96
|
+
gap,
|
|
97
|
+
position
|
|
98
|
+
]);
|
|
99
|
+
const positionStyle = ()=>{
|
|
100
|
+
return {
|
|
101
|
+
[`--pos`]: getCSSPosition(position?.desktop),
|
|
102
|
+
[`--pos-tablet`]: getCSSPosition(position?.tablet ?? position?.desktop),
|
|
103
|
+
[`--pos-mobile`]: getCSSPosition(position?.mobile ?? position?.desktop)
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
return {
|
|
107
|
+
w,
|
|
108
|
+
displayStyle,
|
|
109
|
+
positionStyle,
|
|
110
|
+
getCSSAlign
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export { useSticky as default, minimizeSvg };
|
package/dist/esm/sticky/index.js
CHANGED