@gem-sdk/components 2.0.0-dev.351 → 2.0.0-dev.353
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/article/setting/configs/ArticleAuthor/uiV2.js +9 -2
- package/dist/cjs/article/setting/configs/ArticleDate/uiV2.js +13 -6
- package/dist/cjs/article/setting/configs/ArticleExcerpt/settings.js +1 -1
- package/dist/cjs/article/setting/configs/ArticleExcerpt/uiV2.js +11 -1
- package/dist/cjs/article/setting/configs/ArticleImage/presets.js +3 -3
- package/dist/cjs/article/setting/configs/ArticleReadMore/presets.js +9 -9
- package/dist/cjs/article/setting/configs/ArticleReadMore/settings.js +4 -4
- package/dist/cjs/article/setting/configs/ArticleReadMore/uiV2.js +16 -12
- package/dist/cjs/stock-counter/components/StockCounter.js +104 -112
- package/dist/cjs/stock-counter/components/StockCounter.liquid.js +116 -141
- package/dist/cjs/stock-counter/components/common/getAttrs.js +44 -0
- package/dist/cjs/stock-counter/components/common/getClasses.js +68 -0
- package/dist/cjs/stock-counter/components/common/getContent.js +71 -0
- package/dist/cjs/stock-counter/components/common/getInlineCss.js +39 -0
- package/dist/cjs/stock-counter/components/common/getStyles.js +73 -0
- package/dist/cjs/stock-counter/components/hook/useStockCounter.js +37 -0
- package/dist/cjs/stock-counter/const.js +0 -6
- package/dist/cjs/stock-counter/helpers.js +0 -14
- package/dist/cjs/stock-counter/index.js +3 -1
- package/dist/cjs/stock-counter/setting/StockCounter.js +2 -2
- package/dist/cjs/stock-counter/setting/configs/presets.js +3 -0
- package/dist/cjs/stock-counter/setting/configs/{settings.js → settingsV2.js} +211 -42
- package/dist/cjs/stock-counter/setting/configs/uiV2.js +228 -41
- package/dist/esm/article/setting/configs/ArticleAuthor/uiV2.js +9 -2
- package/dist/esm/article/setting/configs/ArticleDate/uiV2.js +13 -6
- package/dist/esm/article/setting/configs/ArticleExcerpt/settings.js +1 -1
- package/dist/esm/article/setting/configs/ArticleExcerpt/uiV2.js +11 -1
- package/dist/esm/article/setting/configs/ArticleImage/presets.js +3 -3
- package/dist/esm/article/setting/configs/ArticleReadMore/presets.js +9 -9
- package/dist/esm/article/setting/configs/ArticleReadMore/settings.js +4 -4
- package/dist/esm/article/setting/configs/ArticleReadMore/uiV2.js +16 -12
- package/dist/esm/stock-counter/components/StockCounter.js +106 -114
- package/dist/esm/stock-counter/components/StockCounter.liquid.js +116 -141
- package/dist/esm/stock-counter/components/common/getAttrs.js +39 -0
- package/dist/esm/stock-counter/components/common/getClasses.js +60 -0
- package/dist/esm/stock-counter/components/common/getContent.js +68 -0
- package/dist/esm/stock-counter/components/common/getInlineCss.js +37 -0
- package/dist/esm/stock-counter/components/common/getStyles.js +67 -0
- package/dist/esm/stock-counter/components/hook/useStockCounter.js +35 -0
- package/dist/esm/stock-counter/const.js +1 -4
- package/dist/esm/stock-counter/helpers.js +1 -14
- package/dist/esm/stock-counter/index.js +3 -1
- package/dist/esm/stock-counter/setting/StockCounter.js +2 -2
- package/dist/esm/stock-counter/setting/configs/presets.js +3 -0
- package/dist/esm/stock-counter/setting/configs/settingsV2.js +438 -0
- package/dist/esm/stock-counter/setting/configs/uiV2.js +228 -41
- package/dist/types/index.d.ts +13 -5
- package/package.json +1 -1
- package/dist/esm/stock-counter/setting/configs/settings.js +0 -269
|
@@ -1,135 +1,127 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useRef, useMemo, useEffect } from 'react';
|
|
5
|
-
import { NO_PRODUCT_LEFT, CONTINUE_SELLING_WHEN_OUT_OF_STOCK } from '../const.js';
|
|
6
|
-
import { convertSizeToWidth, transformHighlighTag, transformNumberTag } from '../helpers.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useRef, useEffect } from 'react';
|
|
7
4
|
import { useStockCounterInteraction } from '../hooks/useStockCounterInteraction.js';
|
|
5
|
+
import { getInlineCss } from './common/getInlineCss.js';
|
|
6
|
+
import { getProgressBarClasses, getContainerClasses, getWrapperIconClasses, getIconClasses, getWrapperClasses, getTextClasses } from './common/getClasses.js';
|
|
7
|
+
import { getProgressBarStyles, getContainerStyles, getWrapperStyles, getIconStyles, getTextStyles } from './common/getStyles.js';
|
|
8
|
+
import 'next/link';
|
|
9
|
+
import '@gem-sdk/core';
|
|
10
|
+
import { getWrapperAttrs } from './common/getAttrs.js';
|
|
11
|
+
import { createClass, createStyle, createAttr } from '@gem-sdk/system';
|
|
12
|
+
import { useStockCounter } from './hook/useStockCounter.js';
|
|
8
13
|
|
|
9
14
|
const StockCounter = ({ setting, styles, builderProps })=>{
|
|
10
|
-
const {
|
|
11
|
-
const {
|
|
12
|
-
const
|
|
15
|
+
const { displayProgressBar, borderRadius } = styles ?? {};
|
|
16
|
+
const { showIcon, icon, layout = 'full', oosIcon } = setting ?? {};
|
|
17
|
+
const { getMessage, isOutOfStock, inventoryQuantity } = useStockCounter(setting, styles);
|
|
13
18
|
const elementRef = useRef(null);
|
|
14
|
-
const inventoryQuantity = useMemo(()=>{
|
|
15
|
-
return Number(variant ? variant.inventoryQuantity : 0);
|
|
16
|
-
}, [
|
|
17
|
-
variant
|
|
18
|
-
]);
|
|
19
|
-
const manageInventory = variant ? variant.manageInventory : true;
|
|
20
|
-
const inventoryPolicy = variant ? variant.inventoryPolicy : 'deny';
|
|
21
|
-
const mainColor = textColor || 'brand';
|
|
22
19
|
const { dispatchStockCounterInteraction } = useStockCounterInteraction({
|
|
23
20
|
element: elementRef,
|
|
24
21
|
uid: builderProps?.uid
|
|
25
22
|
});
|
|
26
|
-
const
|
|
27
|
-
return `var(--g-${variableName})`;
|
|
28
|
-
};
|
|
29
|
-
const isOutOfStock = manageInventory && inventoryQuantity <= NO_PRODUCT_LEFT && inventoryPolicy !== CONTINUE_SELLING_WHEN_OUT_OF_STOCK;
|
|
30
|
-
const isContinueShopping = inventoryPolicy === CONTINUE_SELLING_WHEN_OUT_OF_STOCK && inventoryQuantity <= NO_PRODUCT_LEFT;
|
|
31
|
-
const isUnlimitedQuantity = !manageInventory && unlimitedQuantityMessage;
|
|
23
|
+
const inlineCss = getInlineCss(builderProps?.uid, borderRadius);
|
|
32
24
|
const showProgressBar = displayProgressBar !== false && !isOutOfStock;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
25
|
+
const showText = layout !== 'progress-bar';
|
|
26
|
+
const progressBarClasses = createClass({
|
|
27
|
+
...getProgressBarClasses(styles)
|
|
28
|
+
});
|
|
29
|
+
const progressBarStyles = createStyle({
|
|
30
|
+
...getProgressBarStyles(styles, setting)
|
|
31
|
+
});
|
|
32
|
+
const containerStyles = createStyle({
|
|
33
|
+
...getContainerStyles(styles)
|
|
34
|
+
});
|
|
35
|
+
const containerClasses = createClass({
|
|
36
|
+
...getContainerClasses(setting)
|
|
37
|
+
});
|
|
38
|
+
const wrapperStyles = createStyle({
|
|
39
|
+
...getWrapperStyles(styles)
|
|
40
|
+
});
|
|
41
|
+
const wrapperIconClasses = createClass({
|
|
42
|
+
...getWrapperIconClasses(setting)
|
|
43
|
+
});
|
|
44
|
+
const iconClasses = createClass({
|
|
45
|
+
...getIconClasses()
|
|
46
|
+
});
|
|
47
|
+
const iconStyles = (isOutOfStock)=>{
|
|
48
|
+
return createStyle({
|
|
49
|
+
...getIconStyles(styles, setting, isOutOfStock)
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const textClasses = (isOutOfStock)=>{
|
|
53
|
+
return createClass({
|
|
54
|
+
...getTextClasses(styles, isOutOfStock)
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
const textStyles = (isOutOfStock)=>{
|
|
58
|
+
return createStyle({
|
|
59
|
+
...getTextStyles(styles, isOutOfStock)
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
const wrapperClasses = createClass({
|
|
63
|
+
...getWrapperClasses(setting, isOutOfStock)
|
|
64
|
+
});
|
|
65
|
+
const wrapperAttrs = createAttr({
|
|
66
|
+
...getWrapperAttrs(builderProps)
|
|
67
|
+
});
|
|
59
68
|
useEffect(()=>{
|
|
60
69
|
dispatchStockCounterInteraction(inventoryQuantity);
|
|
61
70
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
71
|
}, [
|
|
63
72
|
inventoryQuantity
|
|
64
73
|
]);
|
|
65
|
-
return /*#__PURE__*/
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
74
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
75
|
+
...wrapperAttrs,
|
|
76
|
+
style: wrapperStyles,
|
|
69
77
|
ref: elementRef,
|
|
70
|
-
className:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
]
|
|
114
|
-
}),
|
|
115
|
-
showProgressBar && /*#__PURE__*/ jsx("div", {
|
|
116
|
-
style: {
|
|
117
|
-
...makeStyleResponsive('h', progressBarHeight),
|
|
118
|
-
...makeStyle({
|
|
119
|
-
bg: 'linear-gradient(90deg, #eee 50%, transparent 50%)',
|
|
120
|
-
bgc: getSingleColorVariable(color),
|
|
121
|
-
bgp: `${remainingPercentage}% center`
|
|
122
|
-
})
|
|
123
|
-
},
|
|
124
|
-
className: cls('gp-relative gp-mt-2 gp-w-full -gp-scale-100 !gp-bg-[length:200%]', {
|
|
125
|
-
'gp-rounded-md': roundedBorder,
|
|
126
|
-
"before:gp-absolute before:gp-eft-0 before:gp-h-full before:gp-w-full before:gp-animate-shift before:gp-content-['']": effect,
|
|
127
|
-
'before:gp-bg-stock-counter-animate before:gp-bg-[length:60px_100%] before:gp-shadow-stock-counter': effect,
|
|
128
|
-
'before:gp-rounded-md': effect && roundedBorder
|
|
78
|
+
className: wrapperClasses,
|
|
79
|
+
children: [
|
|
80
|
+
/*#__PURE__*/ jsx("style", {
|
|
81
|
+
children: inlineCss
|
|
82
|
+
}),
|
|
83
|
+
/*#__PURE__*/ jsxs("div", {
|
|
84
|
+
className: containerClasses,
|
|
85
|
+
style: containerStyles,
|
|
86
|
+
children: [
|
|
87
|
+
/*#__PURE__*/ jsxs("div", {
|
|
88
|
+
className: wrapperIconClasses,
|
|
89
|
+
children: [
|
|
90
|
+
showIcon && (isOutOfStock ? /*#__PURE__*/ jsx("div", {
|
|
91
|
+
dangerouslySetInnerHTML: {
|
|
92
|
+
__html: oosIcon || ''
|
|
93
|
+
},
|
|
94
|
+
className: iconClasses,
|
|
95
|
+
style: iconStyles(true)
|
|
96
|
+
}) : /*#__PURE__*/ jsx("div", {
|
|
97
|
+
dangerouslySetInnerHTML: {
|
|
98
|
+
__html: icon || ''
|
|
99
|
+
},
|
|
100
|
+
className: iconClasses,
|
|
101
|
+
style: iconStyles(false)
|
|
102
|
+
})),
|
|
103
|
+
showText && (isOutOfStock ? /*#__PURE__*/ jsx("p", {
|
|
104
|
+
dangerouslySetInnerHTML: {
|
|
105
|
+
__html: getMessage()
|
|
106
|
+
},
|
|
107
|
+
className: textClasses(true),
|
|
108
|
+
style: textStyles(true)
|
|
109
|
+
}) : /*#__PURE__*/ jsx("p", {
|
|
110
|
+
dangerouslySetInnerHTML: {
|
|
111
|
+
__html: getMessage()
|
|
112
|
+
},
|
|
113
|
+
className: textClasses(false),
|
|
114
|
+
style: textStyles(false)
|
|
115
|
+
}))
|
|
116
|
+
]
|
|
117
|
+
}),
|
|
118
|
+
showProgressBar && /*#__PURE__*/ jsx("div", {
|
|
119
|
+
style: progressBarStyles,
|
|
120
|
+
className: progressBarClasses
|
|
129
121
|
})
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
122
|
+
]
|
|
123
|
+
})
|
|
124
|
+
]
|
|
133
125
|
});
|
|
134
126
|
};
|
|
135
127
|
|
|
@@ -1,157 +1,132 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { composeClasses, template, RenderIf, isLocalEnv, baseAssetURL } from '@gem-sdk/core';
|
|
2
|
+
import { getSettingPreloadData } from '../../helpers.js';
|
|
3
|
+
import { getInlineCss } from './common/getInlineCss.js';
|
|
4
|
+
import { getProgressBarClasses, getContainerClasses, getLiquidTagClasses, getWrapperIconClasses, getIconClasses, getTextClasses } from './common/getClasses.js';
|
|
5
|
+
import { getProgressBarStyles, getContainerStyles, getWrapperStyles, getIconStyles, getTextStyles } from './common/getStyles.js';
|
|
6
|
+
import { getLiquidTextContent, getLiquidInitData } from './common/getContent.js';
|
|
7
|
+
import { getLiquidTagAttrs, getLiquidProgressBarAttrs, getLiquidTextAttrs } from './common/getAttrs.js';
|
|
8
|
+
import { createAttr, createClass, createStyle } from '@gem-sdk/system';
|
|
5
9
|
|
|
6
10
|
const StockCounter = ({ setting, styles, style, advanced, builderProps })=>{
|
|
7
|
-
const {
|
|
8
|
-
const {
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const { borderRadius } = styles ?? {};
|
|
12
|
+
const { showIcon, icon, oosIcon, layout = 'full' } = setting ?? {};
|
|
13
|
+
const inlineCss = getInlineCss(builderProps?.uid, borderRadius);
|
|
14
|
+
const showText = layout !== 'progress-bar';
|
|
15
|
+
const liquidTagAttrs = createAttr({
|
|
16
|
+
...getLiquidTagAttrs(builderProps, setting, styles)
|
|
17
|
+
});
|
|
18
|
+
const progressBarClasses = createClass({
|
|
19
|
+
...composeClasses('gp-stock-counter-progress gp-mt-2 data-[visible=true]:gp-block data-[visible=false]:gp-hidden'),
|
|
20
|
+
...getProgressBarClasses(styles)
|
|
21
|
+
});
|
|
22
|
+
const progressBarStyles = createStyle({
|
|
23
|
+
...getProgressBarStyles(styles, setting)
|
|
24
|
+
});
|
|
25
|
+
const containerStyles = createStyle({
|
|
26
|
+
...getContainerStyles(styles)
|
|
27
|
+
});
|
|
28
|
+
const containerClasses = createClass({
|
|
29
|
+
...getContainerClasses(setting)
|
|
30
|
+
});
|
|
31
|
+
const liquidTagClasses = createClass({
|
|
32
|
+
...getLiquidTagClasses(advanced)
|
|
33
|
+
});
|
|
34
|
+
const liquidTagStyles = createStyle({
|
|
35
|
+
...style,
|
|
36
|
+
...getWrapperStyles(styles)
|
|
37
|
+
});
|
|
38
|
+
const liquidInitData = getLiquidInitData(setting, styles);
|
|
39
|
+
const liquidTextContent = getLiquidTextContent(setting, styles);
|
|
40
|
+
const wrapperIconClasses = createClass({
|
|
41
|
+
...getWrapperIconClasses(setting)
|
|
42
|
+
});
|
|
43
|
+
const iconClasses = createClass({
|
|
44
|
+
...composeClasses('gp-stock-counter-icon'),
|
|
45
|
+
...getIconClasses()
|
|
46
|
+
});
|
|
47
|
+
const iconStyles = (isOutOfStock)=>{
|
|
48
|
+
return createStyle({
|
|
49
|
+
...getIconStyles(styles, setting, isOutOfStock)
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
const progressBarAttrs = createAttr({
|
|
53
|
+
...getLiquidProgressBarAttrs()
|
|
54
|
+
});
|
|
55
|
+
const textClasses = (isOutOfStock)=>{
|
|
56
|
+
return createClass({
|
|
57
|
+
...getTextClasses(styles, isOutOfStock),
|
|
58
|
+
...composeClasses('gp-stock-counter-mark')
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
const textStyles = (isOutOfStock)=>{
|
|
62
|
+
return createStyle({
|
|
63
|
+
...getTextStyles(styles, isOutOfStock)
|
|
64
|
+
});
|
|
13
65
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return typo && typo.custom ? convertSizeToWidth(composeTypographyV2(typo.custom)) : {};
|
|
18
|
-
}
|
|
19
|
-
return typography && typography.custom ? convertSizeToWidth(composeTypography(typography.custom)) : {};
|
|
20
|
-
}, [
|
|
21
|
-
typo,
|
|
22
|
-
typography
|
|
23
|
-
]);
|
|
24
|
-
const typoWidth = composeMemo(()=>{
|
|
25
|
-
if (typo) {
|
|
26
|
-
return typo && !typo.custom ? genVariable(getShortName(`typography-${typo.type}-fontSize`)) : undefined;
|
|
27
|
-
}
|
|
28
|
-
return typography && !typography.custom ? genVariable(getShortName(`typography-${typography.type}-fontSize`)) : undefined;
|
|
29
|
-
}, [
|
|
30
|
-
typo,
|
|
31
|
-
typography
|
|
32
|
-
]);
|
|
33
|
-
const appendTypoClass = composeTypographyClassName(styles?.typo, styles?.typography);
|
|
34
|
-
const appendTypoStyle = composeTypographyStyle(styles?.typo, styles?.typography);
|
|
66
|
+
const textAttrs = createAttr({
|
|
67
|
+
...getLiquidTextAttrs()
|
|
68
|
+
});
|
|
35
69
|
return template /* liquid */ `
|
|
36
|
-
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
assign scarcityThreshold = ${isScarcityThreshold}
|
|
43
|
-
assign check_display = ${checkDisplay()}
|
|
44
|
-
|
|
45
|
-
if check_display == true
|
|
46
|
-
assign should_display = true
|
|
47
|
-
elsif ${isScarcityThreshold} and inventory_quantity >= 0 and inventory_quantity < ${scarcityThreshold}
|
|
48
|
-
assign should_display = true
|
|
49
|
-
else
|
|
50
|
-
assign should_display = false
|
|
51
|
-
endif
|
|
52
|
-
|
|
53
|
-
if ${hiddenCounterWhenOutOfStock === true} and available == false
|
|
54
|
-
assign should_display = false
|
|
55
|
-
endif
|
|
56
|
-
|
|
57
|
-
if ${displayProgressBar === true} and available
|
|
58
|
-
assign show_progress_bar = true
|
|
59
|
-
else
|
|
60
|
-
assign show_progress_bar = false
|
|
61
|
-
endif
|
|
62
|
-
-%}
|
|
63
|
-
{% capture variant_policy_list %}
|
|
64
|
-
{
|
|
65
|
-
{% for variant in product.variants %}
|
|
66
|
-
"{{ variant.id }}":"{{ variant.inventory_policy }}",
|
|
67
|
-
"{{ variant.id }}_management":"{{ variant.inventory_management }}"{% if forloop.last == false %},{% endif %}
|
|
68
|
-
{% endfor %}
|
|
69
|
-
}
|
|
70
|
-
{% endcapture %}
|
|
71
|
-
<gp-product-stock-counter
|
|
72
|
-
data-id="${builderProps?.uid}"
|
|
73
|
-
data-visible="{{ should_display }}"
|
|
74
|
-
data-policy='{{ variant_policy_list }}'
|
|
75
|
-
gp-setting='${JSON.stringify({
|
|
76
|
-
displayByDefault,
|
|
77
|
-
displayProgressBar,
|
|
78
|
-
scarcityThreshold,
|
|
79
|
-
template: templateString,
|
|
80
|
-
outOfStockMessage,
|
|
81
|
-
continueSelling,
|
|
82
|
-
unlimitedQuantityMessage,
|
|
83
|
-
color: mainColor,
|
|
84
|
-
hiddenCounterWhenOutOfStock
|
|
85
|
-
}).replaceAll("'", ''')}'
|
|
86
|
-
class="gp-product-stock-counter data-[visible=true]:gp-block data-[visible=false]:gp-hidden ${advanced?.cssClass}"
|
|
87
|
-
style="${{
|
|
88
|
-
...style,
|
|
89
|
-
...makeStyleResponsive('ta', alignment)
|
|
90
|
-
}}">
|
|
70
|
+
${liquidInitData}
|
|
71
|
+
<gp-product-stock-counter ${{
|
|
72
|
+
...liquidTagAttrs
|
|
73
|
+
}} class="${liquidTagClasses}"
|
|
74
|
+
style="${liquidTagStyles}">
|
|
75
|
+
<style>${inlineCss}</style>
|
|
91
76
|
<div
|
|
92
|
-
class="
|
|
93
|
-
style="${
|
|
94
|
-
...makeStyleResponsive('w', makeWidth(width)),
|
|
95
|
-
...makeStyle({
|
|
96
|
-
c: getSingleColorVariable(textColor)
|
|
97
|
-
})
|
|
98
|
-
}}"
|
|
77
|
+
class="${containerClasses}"
|
|
78
|
+
style="${containerStyles}"
|
|
99
79
|
>
|
|
100
|
-
<div class="
|
|
80
|
+
<div class="${wrapperIconClasses}">
|
|
101
81
|
${RenderIf(showIcon, template /* liquid */ `
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
82
|
+
{% if is_out_of_stock %}
|
|
83
|
+
<div
|
|
84
|
+
class="${iconClasses}"
|
|
85
|
+
style="${iconStyles(true)}"
|
|
86
|
+
>
|
|
87
|
+
${oosIcon}
|
|
88
|
+
</div>
|
|
89
|
+
{% else %}
|
|
90
|
+
<div
|
|
91
|
+
class="${iconClasses}"
|
|
92
|
+
style="${iconStyles(false)}"
|
|
93
|
+
>
|
|
94
|
+
${icon}
|
|
95
|
+
</div>
|
|
96
|
+
{% endif %}
|
|
113
97
|
`)}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
...
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
>
|
|
126
|
-
{% if inventory_management == null or inventory_management != "shopify" and inventory_quantity <= 0 %}
|
|
127
|
-
${transformHighlighTag(unlimitedQuantityMessage ?? getStaticLocale('StockCounter', 'let_buy_now'), mainColor)}
|
|
128
|
-
{% elsif available == false %}
|
|
129
|
-
${transformHighlighTag(outOfStockMessage ?? '', mainColor)}
|
|
130
|
-
{% elsif available and inventory_policy == '${CONTINUE_SELLING_WHEN_OUT_OF_STOCK.toLowerCase()}' and inventory_quantity <= 0 %}
|
|
131
|
-
${transformHighlighTag(continueSelling ?? '', mainColor)}
|
|
98
|
+
${RenderIf(showText, template`
|
|
99
|
+
{% if is_out_of_stock %}
|
|
100
|
+
<p
|
|
101
|
+
${{
|
|
102
|
+
...textAttrs
|
|
103
|
+
}}
|
|
104
|
+
class="${textClasses(true)}"
|
|
105
|
+
style="${textStyles(true)}"
|
|
106
|
+
>
|
|
107
|
+
${liquidTextContent}
|
|
108
|
+
</p>
|
|
132
109
|
{% else %}
|
|
133
|
-
|
|
110
|
+
<p
|
|
111
|
+
${{
|
|
112
|
+
...textAttrs
|
|
113
|
+
}}
|
|
114
|
+
class="${textClasses(false)}"
|
|
115
|
+
style="${textStyles(false)}"
|
|
116
|
+
>
|
|
117
|
+
${liquidTextContent}
|
|
118
|
+
</p>
|
|
134
119
|
{% endif %}
|
|
135
|
-
|
|
120
|
+
`)}
|
|
121
|
+
|
|
136
122
|
</div>
|
|
137
123
|
|
|
138
124
|
<div
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
bg: 'linear-gradient(90deg, #eee 50%, transparent 50%)',
|
|
145
|
-
bgc: getSingleColorVariable(color),
|
|
146
|
-
bgp: `${remainingPercentage}% center`
|
|
147
|
-
})
|
|
148
|
-
}}"
|
|
149
|
-
class="${cls('gp-stock-counter-progress gp-relative gp-mt-2 gp-w-full -gp-scale-100 data-[visible=true]:gp-block data-[visible=false]:gp-hidden !gp-bg-[length:200%]', {
|
|
150
|
-
'gp-rounded-md ': roundedBorder,
|
|
151
|
-
"before:gp-absolute before:gp-left-0 before:gp-h-full before:gp-w-full before:gp-animate-shift before:gp-content-['']": effect,
|
|
152
|
-
'before:gp-bg-stock-counter-animate before:gp-bg-[length:60px_100%] before:gp-shadow-stock-counter': effect,
|
|
153
|
-
'before:gp-rounded-md': effect && roundedBorder
|
|
154
|
-
})}"
|
|
125
|
+
${{
|
|
126
|
+
...progressBarAttrs
|
|
127
|
+
}}
|
|
128
|
+
style="${progressBarStyles}"
|
|
129
|
+
class="${progressBarClasses}"
|
|
155
130
|
></div>
|
|
156
131
|
</div>
|
|
157
132
|
</gp-product-stock-counter>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const getLiquidTagAttrs = (builderProps, setting, styles)=>{
|
|
2
|
+
const { displayByDefault, scarcityThreshold = 0, template: templateString, outOfStockMessage, continueSelling, unlimitedQuantityMessage, hiddenCounterWhenOutOfStock } = setting ?? {};
|
|
3
|
+
const { displayProgressBar, textColor } = styles ?? {};
|
|
4
|
+
const mainColor = textColor || 'brand';
|
|
5
|
+
return {
|
|
6
|
+
'data-id': builderProps?.uid ?? '',
|
|
7
|
+
'data-visible': '{{ should_display }}',
|
|
8
|
+
'data-policy': '{{ variant_policy_list | escape }}',
|
|
9
|
+
'gp-setting': JSON.stringify({
|
|
10
|
+
displayByDefault,
|
|
11
|
+
displayProgressBar,
|
|
12
|
+
scarcityThreshold,
|
|
13
|
+
template: templateString,
|
|
14
|
+
outOfStockMessage,
|
|
15
|
+
continueSelling,
|
|
16
|
+
unlimitedQuantityMessage,
|
|
17
|
+
color: mainColor,
|
|
18
|
+
hiddenCounterWhenOutOfStock
|
|
19
|
+
}).replaceAll(`"`, '"')
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const getLiquidProgressBarAttrs = ()=>{
|
|
23
|
+
return {
|
|
24
|
+
'data-slot-type': 'progress-bar',
|
|
25
|
+
'data-visible': '{{ show_progress_bar }}'
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const getLiquidTextAttrs = ()=>{
|
|
29
|
+
return {
|
|
30
|
+
'data-slot-type': 'message'
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const getWrapperAttrs = (builderProps)=>{
|
|
34
|
+
return {
|
|
35
|
+
'data-id': builderProps?.uid ?? ''
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { getLiquidProgressBarAttrs, getLiquidTagAttrs, getLiquidTextAttrs, getWrapperAttrs };
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { composeClasses, composeTypographyClassName } from '@gem-sdk/core';
|
|
2
|
+
|
|
3
|
+
const getProgressBarClasses = (styles)=>{
|
|
4
|
+
const { effect } = styles ?? {};
|
|
5
|
+
const effectClasses = effect ? composeClasses("before:gp-absolute before:gp-left-0 before:gp-h-full before:gp-w-full before:gp-animate-shift before:gp-content-[''] before:gp-bg-stock-counter-animate before:gp-bg-[length:60px_100%] before:gp-shadow-stock-counter") : {};
|
|
6
|
+
return {
|
|
7
|
+
...composeClasses('gp-sc-progress-bar gp-relative gp-w-full -gp-scale-100 !gp-bg-[length:200%]'),
|
|
8
|
+
...effectClasses
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
const getContainerClasses = (setting)=>{
|
|
12
|
+
const { progressBarPosition = 'bottom' } = setting ?? {};
|
|
13
|
+
const isProgressBarBottom = progressBarPosition === 'bottom';
|
|
14
|
+
return {
|
|
15
|
+
...composeClasses('gp-inline-block gp-flex gp-flex-col gp-gap-y-1.5'),
|
|
16
|
+
'gp-flex-col': isProgressBarBottom,
|
|
17
|
+
'gp-flex-col-reverse': !isProgressBarBottom
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const getLiquidTagClasses = (advanced)=>{
|
|
21
|
+
return {
|
|
22
|
+
...composeClasses('gp-product-stock-counter data-[visible=true]:gp-block data-[visible=false]:gp-hidden'),
|
|
23
|
+
...composeClasses(advanced?.cssClass)
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const getWrapperIconClasses = (setting)=>{
|
|
27
|
+
const { iconPosition = 'left' } = setting ?? {};
|
|
28
|
+
return {
|
|
29
|
+
...composeClasses('gp-flex gp-items-baseline gp-gap-x-1'),
|
|
30
|
+
'gp-flex-row': iconPosition === 'left',
|
|
31
|
+
'gp-flex-row-reverse gp-justify-end': iconPosition === 'right'
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const getIconClasses = ()=>{
|
|
35
|
+
return {
|
|
36
|
+
...composeClasses('gp-shrink-0 gp-bg-[length:60px_100%]')
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const getTextClasses = (styles, isOutOfStock)=>{
|
|
40
|
+
const { typo, oosTextColor } = styles ?? {};
|
|
41
|
+
const displayTypo = {
|
|
42
|
+
...typo,
|
|
43
|
+
attrs: {
|
|
44
|
+
...typo?.attrs,
|
|
45
|
+
color: isOutOfStock ? oosTextColor : typo?.attrs?.color
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const appendTypoClass = composeTypographyClassName(displayTypo, styles?.typography);
|
|
49
|
+
return {
|
|
50
|
+
...composeClasses(appendTypoClass)
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const getWrapperClasses = (setting, isOutOfStock)=>{
|
|
54
|
+
const { hiddenCounterWhenOutOfStock } = setting ?? {};
|
|
55
|
+
return {
|
|
56
|
+
'gp-opacity-50': isOutOfStock && hiddenCounterWhenOutOfStock
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export { getContainerClasses, getIconClasses, getLiquidTagClasses, getProgressBarClasses, getTextClasses, getWrapperClasses, getWrapperIconClasses };
|