@gem-sdk/components 2.0.0-dev.332 → 2.0.0-dev.334
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/post-purchase/product/settings/product-image/ProductFeatureImage.js +33 -0
- package/dist/cjs/post-purchase/product/settings/product-image/ProductGalleryImage.js +85 -0
- package/dist/cjs/post-purchase/product/settings/product-image/ProductImageLayoutSetting.js +69 -0
- package/dist/cjs/post-purchase/product/settings/product-image/ProductImages.js +3 -1
- package/dist/cjs/post-purchase/product/settings/product-image/uiV1.js +42 -0
- package/dist/cjs/product/components/ProductBadge/common/getAttrs.js +74 -0
- package/dist/cjs/product/components/ProductBadge/common/getClasses.js +79 -0
- package/dist/cjs/product/components/ProductBadge/common/getStyles.js +144 -0
- package/dist/cjs/product/components/ProductBadge/constants.js +1 -9
- package/dist/cjs/product/components/ProductBadge/index.js +125 -117
- package/dist/cjs/product/components/ProductBadge/index.liquid.js +97 -111
- package/dist/cjs/product/components/ProductBadge/utils/common.js +11 -0
- package/dist/cjs/product/components/ProductBadge/utils/getRotateShape.js +10 -5
- package/dist/cjs/product/components/ProductBadge/utils/shape.js +14 -1
- package/dist/cjs/product/index.js +1 -1
- package/dist/cjs/product/setting/product-badge/configs/settings.js +72 -93
- package/dist/cjs/product/setting/product-badge/configs/uiV2.js +93 -15
- package/dist/esm/post-purchase/product/settings/product-image/ProductFeatureImage.js +31 -0
- package/dist/esm/post-purchase/product/settings/product-image/ProductGalleryImage.js +83 -0
- package/dist/esm/post-purchase/product/settings/product-image/ProductImageLayoutSetting.js +67 -0
- package/dist/esm/post-purchase/product/settings/product-image/ProductImages.js +3 -1
- package/dist/esm/post-purchase/product/settings/product-image/uiV1.js +40 -0
- package/dist/esm/product/components/ProductBadge/common/getAttrs.js +67 -0
- package/dist/esm/product/components/ProductBadge/common/getClasses.js +70 -0
- package/dist/esm/product/components/ProductBadge/common/getStyles.js +137 -0
- package/dist/esm/product/components/ProductBadge/constants.js +2 -5
- package/dist/esm/product/components/ProductBadge/index.js +128 -120
- package/dist/esm/product/components/ProductBadge/index.liquid.js +99 -113
- package/dist/esm/product/components/ProductBadge/utils/common.js +12 -2
- package/dist/esm/product/components/ProductBadge/utils/getRotateShape.js +10 -5
- package/dist/esm/product/components/ProductBadge/utils/shape.js +14 -1
- package/dist/esm/product/index.js +1 -1
- package/dist/esm/product/setting/product-badge/configs/settings.js +72 -93
- package/dist/esm/product/setting/product-badge/configs/uiV2.js +93 -15
- package/dist/types/index.d.ts +1 -3
- package/package.json +2 -2
- package/dist/cjs/product/components/ProductBadge/hooks/useProductBadgeStyles.js +0 -83
- package/dist/esm/product/components/ProductBadge/hooks/useProductBadgeStyles.js +0 -81
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { dataStringify } from '@gem-sdk/core';
|
|
2
|
+
|
|
3
|
+
const getImageAttr = ({ setting })=>{
|
|
4
|
+
return {
|
|
5
|
+
src: setting?.image?.src,
|
|
6
|
+
alt: setting?.image?.alt,
|
|
7
|
+
loading: 'lazy'
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
const getContainerAttrs = (props)=>{
|
|
11
|
+
const { builderAttrs, builderProps, setting } = props;
|
|
12
|
+
const isTextBadge = setting?.contentType === 'text';
|
|
13
|
+
return {
|
|
14
|
+
...builderAttrs,
|
|
15
|
+
'data-id': builderProps?.uid || '',
|
|
16
|
+
id: `g-product-badge-${builderProps?.uid}`,
|
|
17
|
+
'gp-data-hidden': 'false',
|
|
18
|
+
'gp-data': `${dataStringify({
|
|
19
|
+
displayContent: setting?.displayContent,
|
|
20
|
+
minPrice: '{{ minPriceValue }}',
|
|
21
|
+
variantIDs: '{{ product.variants | map: "id" | json | escape }}',
|
|
22
|
+
variantInventoryQuantities: '{{ product.variants | map: "inventory_quantity" | json | escape }}',
|
|
23
|
+
amountDiscount: '{{amountDiscountValue}}',
|
|
24
|
+
percentDiscount: '{{percentDiscountValue}}',
|
|
25
|
+
price: '{{price}}',
|
|
26
|
+
displayTrigger: setting?.displayTrigger,
|
|
27
|
+
uid: builderProps?.uid,
|
|
28
|
+
productCreatedAt: '{{product.created_at | date: "%Y-%m-%d" }}',
|
|
29
|
+
productTags: '{{ product.tags | join: "," }}',
|
|
30
|
+
isTextBadge
|
|
31
|
+
})}`
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
const getEditTooltipAttrs = (props)=>{
|
|
35
|
+
const { setting } = props;
|
|
36
|
+
const isDropOutsideProductImage = setting?.positionWithImage === 'outside';
|
|
37
|
+
return {
|
|
38
|
+
enable: true,
|
|
39
|
+
text: 'Not be displayed when published',
|
|
40
|
+
position: isDropOutsideProductImage ? 'bottom' : 'right',
|
|
41
|
+
width: '205px'
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const getNoDataAttrs = (props)=>{
|
|
45
|
+
const { builderAttrs } = props;
|
|
46
|
+
return {
|
|
47
|
+
...builderAttrs,
|
|
48
|
+
elementType: 'secondary',
|
|
49
|
+
description: 'No discount',
|
|
50
|
+
rawMode: true
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
const getSubWrapperAttrs = (props, product)=>{
|
|
54
|
+
const { builderProps } = props;
|
|
55
|
+
const currentProductId = product ? product?.baseID?.replace('gid://shopify/Product/', '') : '';
|
|
56
|
+
return {
|
|
57
|
+
'data-product-id': currentProductId || '',
|
|
58
|
+
id: builderProps?.uid || ''
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const getTextContentAttrs = ()=>{
|
|
62
|
+
return {
|
|
63
|
+
id: 'product-badge-content'
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { getContainerAttrs, getEditTooltipAttrs, getImageAttr, getNoDataAttrs, getSubWrapperAttrs, getTextContentAttrs };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { composeClasses, composeTypographyClassName } from '@gem-sdk/core';
|
|
2
|
+
import { toggleBadge } from '../utils/renderBadgeILP.js';
|
|
3
|
+
import { getAlignShape, getShapePlacementClass } from '../utils/common.js';
|
|
4
|
+
|
|
5
|
+
const getContainerClasses = ({ mode, isInstant, product, currentVariant, props })=>{
|
|
6
|
+
const { setting, builderProps } = props;
|
|
7
|
+
let classList = 'gp-shrink-0 product-badge ';
|
|
8
|
+
const conditionClass = !mode && isInstant ? toggleBadge(setting?.displayTrigger, product, currentVariant) : '{{className}}';
|
|
9
|
+
const advancedClass = builderProps?.builderData?.advanced?.cssClass || '';
|
|
10
|
+
if (conditionClass) classList += `${conditionClass} `;
|
|
11
|
+
if (advancedClass) classList += `${advancedClass} `;
|
|
12
|
+
if (builderProps?.uid) classList += `${builderProps?.uid} `;
|
|
13
|
+
if (setting?.positionWithImage === 'inside') classList += 'inside-image ';
|
|
14
|
+
return {
|
|
15
|
+
...composeClasses(classList)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
const getTextContainerClasses = ()=>{
|
|
19
|
+
const classList = 'gp-w-full gp-h-full gp-overflow-hidden product-badge-item';
|
|
20
|
+
return {
|
|
21
|
+
...composeClasses(classList)
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const getTextWrapperClasses = ()=>{
|
|
25
|
+
const classList = 'gp-w-full gp-h-full gp-flex gp-items-center gp-justify-center gp-overflow-hidden';
|
|
26
|
+
return {
|
|
27
|
+
...composeClasses(classList)
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const getTextContentClasses = (styles)=>{
|
|
31
|
+
let classList = 'gp-break-words gp-text-center ';
|
|
32
|
+
const typoClass = composeTypographyClassName(styles?.typo);
|
|
33
|
+
if (typoClass) classList += `${typoClass} `;
|
|
34
|
+
return {
|
|
35
|
+
...composeClasses(classList)
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const getImageContainerClasses = ()=>{
|
|
39
|
+
const classList = 'product-badge-item gp-w-full gp-h-full';
|
|
40
|
+
return {
|
|
41
|
+
...composeClasses(classList)
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
const getImageClasses = ()=>{
|
|
45
|
+
const classList = 'gp-object-cover gp-w-full gp-h-full gp-pointer-events-none';
|
|
46
|
+
return {
|
|
47
|
+
...composeClasses(classList)
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
const getWrapperClasses = (props)=>{
|
|
51
|
+
const { styles, setting } = props;
|
|
52
|
+
const { align } = styles ?? {};
|
|
53
|
+
const isDropOutsideProductImage = setting?.positionWithImage === 'outside';
|
|
54
|
+
let classList = isDropOutsideProductImage ? 'gp-flex ' : 'gp-h-full';
|
|
55
|
+
const alignClass = getAlignShape(align, false);
|
|
56
|
+
if (isDropOutsideProductImage && alignClass) classList += `${alignClass} `;
|
|
57
|
+
return {
|
|
58
|
+
...composeClasses(classList)
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const getSubWrapperClass = (props, currentDevice)=>{
|
|
62
|
+
const { setting, style } = props;
|
|
63
|
+
const isInsideProductImage = setting?.positionWithImage === 'inside';
|
|
64
|
+
const classList = !isInsideProductImage && currentDevice ? getShapePlacementClass(isInsideProductImage, style, currentDevice) : 'gp-h-full';
|
|
65
|
+
return {
|
|
66
|
+
...composeClasses(classList)
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export { getContainerClasses, getImageClasses, getImageContainerClasses, getSubWrapperClass, getTextContainerClasses, getTextContentClasses, getTextWrapperClasses, getWrapperClasses };
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { makeGlobalSize, composeTypographyStyle, getStyleShadow } from '@gem-sdk/core';
|
|
2
|
+
import { convertToStyle, getSize, getWrapperStyle, getShapeWrapperPadding, checkDiscountContentProductBadge } from '../utils/common.js';
|
|
3
|
+
import { getShapePosition } from '../utils/getShapePosition.js';
|
|
4
|
+
import { composeTextStyleByPosition, composeShapeStyleByPosition } from '../utils/getRotateShape.js';
|
|
5
|
+
import { getStyleAdvanced } from '../utils/getStyleAdvanced.js';
|
|
6
|
+
import { getWhiteSpaceStyle } from '../utils/getWhiteSpace.js';
|
|
7
|
+
import { getStyleBackground, getStyleShadowV2, getStyleBorder, getStyleCornerRadius } from '../utils/stylesV2.js';
|
|
8
|
+
import { getShape } from '../utils/shape.js';
|
|
9
|
+
|
|
10
|
+
const getSizeStyles = (props)=>{
|
|
11
|
+
const { setting, styles } = props;
|
|
12
|
+
const shape = getShape(setting?.shape);
|
|
13
|
+
const isTextBadge = setting?.contentType === 'text';
|
|
14
|
+
const badgeSize = isTextBadge ? styles?.textSizeV2 : styles?.imageSizeV2;
|
|
15
|
+
return isTextBadge ? getSize(shape, badgeSize) : getSize(undefined, badgeSize);
|
|
16
|
+
};
|
|
17
|
+
const getContainerStyle = (props)=>{
|
|
18
|
+
const { setting, styles, style, navigationPosition, imageData, dotData } = props;
|
|
19
|
+
const isDropOutsideProductImage = setting?.positionWithImage === 'outside';
|
|
20
|
+
const wrapperStyles = getWrapperStyle(false);
|
|
21
|
+
const shapePosition = getShapePosition({
|
|
22
|
+
positionType: styles?.position,
|
|
23
|
+
isLiquid: false,
|
|
24
|
+
navigationPosition,
|
|
25
|
+
dataImage: {
|
|
26
|
+
...imageData,
|
|
27
|
+
...dotData
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const sizeStyles = getSizeStyles(props);
|
|
31
|
+
const advancedStyles = getStyleAdvanced(!isDropOutsideProductImage ? {
|
|
32
|
+
...shapePosition,
|
|
33
|
+
...sizeStyles
|
|
34
|
+
} : {}, style);
|
|
35
|
+
return {
|
|
36
|
+
...!isDropOutsideProductImage && {
|
|
37
|
+
'--pos': 'absolute'
|
|
38
|
+
},
|
|
39
|
+
...wrapperStyles,
|
|
40
|
+
...advancedStyles
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const getTextContentStyle = ({ styles, setting })=>{
|
|
44
|
+
const textBadgePadding = makeGlobalSize(styles?.textSizeV2).padding;
|
|
45
|
+
const shape = getShape(setting?.shape);
|
|
46
|
+
const isDropOutsideProductImage = setting?.positionWithImage === 'outside';
|
|
47
|
+
return {
|
|
48
|
+
...getWhiteSpaceStyle(styles?.textSizeV2),
|
|
49
|
+
...convertToStyle(shape?.textStyle),
|
|
50
|
+
...composeTextStyleByPosition(shape, styles?.position, isDropOutsideProductImage),
|
|
51
|
+
...composeTypographyStyle(styles?.typo),
|
|
52
|
+
...getStyleShadow({
|
|
53
|
+
value: styles?.typo?.custom?.textShadow,
|
|
54
|
+
styleAppliedFor: 'text-shadow',
|
|
55
|
+
isEnableShadow: styles?.typo?.custom?.textShadow?.type !== 'none'
|
|
56
|
+
}),
|
|
57
|
+
...getStyleBackground(!!shape?.backgroundColorInText, styles?.badgeColorV2),
|
|
58
|
+
...textBadgePadding
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
const getBorderStyles = ({ styles, setting })=>{
|
|
62
|
+
const shape = getShape(setting?.shape);
|
|
63
|
+
const isTextBadge = setting?.contentType === 'text';
|
|
64
|
+
return shape?.supportBorder ? isTextBadge ? getStyleBorder(styles?.textBadgeBorder) : getStyleBorder(styles?.imageBadgeBorder) : {};
|
|
65
|
+
};
|
|
66
|
+
const getCornerStyles = ({ styles, setting })=>{
|
|
67
|
+
const shape = getShape(setting?.shape);
|
|
68
|
+
const isTextBadge = setting?.contentType === 'text';
|
|
69
|
+
return isTextBadge ? getStyleCornerRadius(styles?.textBadgeCorner, shape?.shapeRadius) : getStyleCornerRadius(styles?.imageBadgeCorner, shape?.shapeRadius);
|
|
70
|
+
};
|
|
71
|
+
const getTextBadgeWrapperStyles = ({ styles, setting })=>{
|
|
72
|
+
const shape = getShape(setting?.shape);
|
|
73
|
+
const borderStyles = getBorderStyles({
|
|
74
|
+
setting,
|
|
75
|
+
styles
|
|
76
|
+
});
|
|
77
|
+
const isDropOutsideProductImage = setting?.positionWithImage === 'outside';
|
|
78
|
+
const cornerStyles = getCornerStyles({
|
|
79
|
+
setting,
|
|
80
|
+
styles
|
|
81
|
+
});
|
|
82
|
+
const paddingShape = getShapeWrapperPadding(shape?.ratio);
|
|
83
|
+
return {
|
|
84
|
+
...borderStyles,
|
|
85
|
+
...cornerStyles,
|
|
86
|
+
...composeShapeStyleByPosition(shape, styles?.position, isDropOutsideProductImage),
|
|
87
|
+
...getStyleBackground(!shape?.backgroundColorInText, styles?.badgeColorV2),
|
|
88
|
+
...paddingShape
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
const getImageContainerStyles = ({ styles, setting })=>{
|
|
92
|
+
const borderStyles = getBorderStyles({
|
|
93
|
+
setting,
|
|
94
|
+
styles
|
|
95
|
+
});
|
|
96
|
+
const cornerStyles = getCornerStyles({
|
|
97
|
+
setting,
|
|
98
|
+
styles
|
|
99
|
+
});
|
|
100
|
+
const imageBadgePadding = makeGlobalSize(styles?.imageSizeV2).padding;
|
|
101
|
+
return {
|
|
102
|
+
...borderStyles,
|
|
103
|
+
...cornerStyles,
|
|
104
|
+
...imageBadgePadding
|
|
105
|
+
};
|
|
106
|
+
};
|
|
107
|
+
const getOpacityProductBadge = (props, currentVariant, mode)=>{
|
|
108
|
+
const { 'bundle-item': bundleItem, setting } = props;
|
|
109
|
+
const isDiscountContent = checkDiscountContentProductBadge(setting?.displayContent);
|
|
110
|
+
const price = currentVariant?.price ?? 0;
|
|
111
|
+
const salePrice = currentVariant?.salePrice ?? 0;
|
|
112
|
+
const priceSave = salePrice - price;
|
|
113
|
+
const isOpacityBadge = isDiscountContent && priceSave <= 0 && setting?.contentType === 'text';
|
|
114
|
+
if (bundleItem) return 1;
|
|
115
|
+
if (!isOpacityBadge) return 1;
|
|
116
|
+
return mode !== 'edit' ? 0 : 0.2;
|
|
117
|
+
};
|
|
118
|
+
const getSubWrapperStyle = (props, currentVariant, mode)=>{
|
|
119
|
+
const { setting } = props;
|
|
120
|
+
const isDropOutsideProductImage = setting?.positionWithImage === 'outside';
|
|
121
|
+
const sizeStyles = getSizeStyles(props);
|
|
122
|
+
const opacityProductBadge = mode && currentVariant ? getOpacityProductBadge(props, currentVariant, mode) : 1;
|
|
123
|
+
return {
|
|
124
|
+
...isDropOutsideProductImage ? {
|
|
125
|
+
...sizeStyles,
|
|
126
|
+
'--mb': 0
|
|
127
|
+
} : {},
|
|
128
|
+
opacity: opacityProductBadge
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
const getContentStyleInternal = (props)=>{
|
|
132
|
+
const { styles, setting } = props;
|
|
133
|
+
const isTextBadge = setting?.contentType === 'text';
|
|
134
|
+
return getStyleShadowV2('.product-badge-item', isTextBadge ? styles?.textBadgeShadow : styles?.imageBadgeShadow);
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
export { getContainerStyle, getContentStyleInternal, getImageContainerStyles, getSubWrapperStyle, getTextBadgeWrapperStyles, getTextContentStyle };
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
const SHAPE_CLASS = 'gp-w-full gp-h-full gp-flex gp-items-center gp-justify-center gp-overflow-hidden';
|
|
2
|
-
const CONTENT_CLASS = 'gp-break-words gp-text-center';
|
|
3
|
-
const WRAPPER_CLASS = 'gp-w-full gp-h-full gp-overflow-hidden';
|
|
4
|
-
const IS_LIQUID = true;
|
|
5
1
|
var SHAPE_ID;
|
|
6
2
|
(function(SHAPE_ID) {
|
|
7
3
|
SHAPE_ID["SQUARE"] = 'square';
|
|
@@ -12,6 +8,7 @@ var SHAPE_ID;
|
|
|
12
8
|
SHAPE_ID["STAR"] = 'star';
|
|
13
9
|
SHAPE_ID["RIBBON_2"] = 'ribbon_2';
|
|
14
10
|
SHAPE_ID["RIBBON_3"] = 'ribbon_3';
|
|
11
|
+
SHAPE_ID["TRIANGLE"] = 'triangle';
|
|
15
12
|
})(SHAPE_ID || (SHAPE_ID = {}));
|
|
16
13
|
|
|
17
|
-
export {
|
|
14
|
+
export { SHAPE_ID };
|
|
@@ -1,149 +1,157 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { jsxs, jsx
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import { getBadgeContent, checkNoDiscountState, getAlignShape, checkDiscountContentProductBadge } from './utils/common.js';
|
|
7
|
-
import { useProductBadgeStyles } from './hooks/useProductBadgeStyles.js';
|
|
8
|
-
import { toggleBadge } from './utils/renderBadgeILP.js';
|
|
2
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
|
+
import { useProduct, useCurrentVariant, useMoneyFormat, useCurrentDevice, useProductBundleDiscount, useEditorMode, usePageType, filterToolbarPreview } from '@gem-sdk/core';
|
|
4
|
+
import { getBadgeContent, getIsNoDiscountState } from './utils/common.js';
|
|
5
|
+
import './constants.js';
|
|
9
6
|
import NoDataState from '../../../common/components/NoDataState.js';
|
|
10
7
|
import TooltipHover from '../../../common/components/TooltipHover.js';
|
|
8
|
+
import { createClass, createStyle, createAttr, If } from '@gem-sdk/system';
|
|
9
|
+
import { getEditTooltipAttrs, getNoDataAttrs, getSubWrapperAttrs, getContainerAttrs, getTextContentAttrs, getImageAttr } from './common/getAttrs.js';
|
|
10
|
+
import { getContainerClasses, getWrapperClasses, getSubWrapperClass, getTextContainerClasses, getTextWrapperClasses, getTextContentClasses, getImageContainerClasses, getImageClasses } from './common/getClasses.js';
|
|
11
|
+
import { getContainerStyle, getSubWrapperStyle, getContentStyleInternal, getTextBadgeWrapperStyles, getTextContentStyle, getImageContainerStyles } from './common/getStyles.js';
|
|
11
12
|
|
|
12
|
-
const ProductBadge = (
|
|
13
|
+
const ProductBadge = (props)=>{
|
|
14
|
+
const { builderAttrs, builderProps, isInsideProductImage, setting, styles, children, style, navigationPosition, imageData, dotData, ...passProps } = props;
|
|
13
15
|
const product = useProduct();
|
|
14
16
|
const currentVariant = useCurrentVariant();
|
|
15
17
|
const { moneyFormat } = useMoneyFormat();
|
|
16
18
|
const currentDevice = useCurrentDevice();
|
|
17
19
|
const { useProductCompareAtPrice } = useProductBundleDiscount();
|
|
18
20
|
const bundleItem = passProps?.['bundle-item'];
|
|
19
|
-
const price = currentVariant?.price ?? 0;
|
|
20
|
-
const salePrice = currentVariant?.salePrice ?? 0;
|
|
21
|
-
const priceSave = salePrice - price;
|
|
22
|
-
const { align } = styles ?? {};
|
|
23
|
-
const isDiscountContent = checkDiscountContentProductBadge(setting?.displayContent);
|
|
24
|
-
const isOpacityBadge = isDiscountContent && priceSave <= 0 && setting?.contentType === 'text';
|
|
25
21
|
const mode = useEditorMode();
|
|
26
22
|
const isInstant = usePageType() === 'STATIC';
|
|
27
|
-
const conditionClass = useMemo(()=>{
|
|
28
|
-
return !mode && isInstant ? toggleBadge(setting?.displayTrigger, product, currentVariant) : '';
|
|
29
|
-
}, [
|
|
30
|
-
currentVariant,
|
|
31
|
-
isInstant,
|
|
32
|
-
mode,
|
|
33
|
-
product,
|
|
34
|
-
setting?.displayTrigger
|
|
35
|
-
]);
|
|
36
|
-
const opacityProductBadge = useMemo(()=>{
|
|
37
|
-
if (bundleItem) return 1;
|
|
38
|
-
if (!isOpacityBadge) return 1;
|
|
39
|
-
return mode !== 'edit' ? 0 : 0.2;
|
|
40
|
-
}, [
|
|
41
|
-
bundleItem,
|
|
42
|
-
isOpacityBadge,
|
|
43
|
-
mode
|
|
44
|
-
]);
|
|
45
|
-
const currentProductId = product?.baseID?.replace('gid://shopify/Product/', '');
|
|
46
23
|
const badgeContent = getBadgeContent({
|
|
47
24
|
detail: product,
|
|
48
25
|
currentVariant,
|
|
49
26
|
bundleItem,
|
|
50
27
|
useProductCompareAtPrice
|
|
51
28
|
}, setting?.displayContent, moneyFormat);
|
|
52
|
-
const isNoDiscountState =
|
|
53
|
-
|
|
29
|
+
const isNoDiscountState = getIsNoDiscountState({
|
|
30
|
+
props,
|
|
31
|
+
product,
|
|
54
32
|
currentVariant,
|
|
55
|
-
|
|
33
|
+
moneyFormat,
|
|
56
34
|
useProductCompareAtPrice
|
|
57
|
-
}
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
};
|
|
35
|
+
});
|
|
36
|
+
const containerClass = createClass({
|
|
37
|
+
...getContainerClasses({
|
|
38
|
+
mode,
|
|
39
|
+
isInstant,
|
|
40
|
+
product,
|
|
41
|
+
currentVariant,
|
|
42
|
+
props
|
|
43
|
+
})
|
|
44
|
+
});
|
|
45
|
+
const containerStyle = createStyle({
|
|
46
|
+
...getContainerStyle(props)
|
|
47
|
+
});
|
|
48
|
+
const editTooltipAttrs = createAttr({
|
|
49
|
+
...getEditTooltipAttrs(props)
|
|
50
|
+
});
|
|
51
|
+
const noDataAttrs = createAttr({
|
|
52
|
+
...getNoDataAttrs(props)
|
|
53
|
+
});
|
|
54
|
+
const wrapperClass = createClass({
|
|
55
|
+
...getWrapperClasses(props)
|
|
56
|
+
});
|
|
57
|
+
const subWrapperClass = createClass({
|
|
58
|
+
...getSubWrapperClass(props, currentDevice)
|
|
59
|
+
});
|
|
60
|
+
const subWrapperStyle = createStyle({
|
|
61
|
+
...getSubWrapperStyle(props, currentVariant, mode)
|
|
62
|
+
});
|
|
63
|
+
const subWrapperAttrs = createAttr({
|
|
64
|
+
...getSubWrapperAttrs(props, product)
|
|
65
|
+
});
|
|
66
|
+
const contentStyleInternal = getContentStyleInternal(props);
|
|
67
|
+
const textContentContainerClasses = createClass({
|
|
68
|
+
...getTextContainerClasses()
|
|
69
|
+
});
|
|
70
|
+
const containerAttrs = createAttr({
|
|
71
|
+
...getContainerAttrs(props)
|
|
72
|
+
});
|
|
73
|
+
const textContentWrapperClasses = createClass({
|
|
74
|
+
...getTextWrapperClasses()
|
|
75
|
+
});
|
|
76
|
+
const textContentWrapperStyle = createStyle({
|
|
77
|
+
...getTextBadgeWrapperStyles({
|
|
78
|
+
setting,
|
|
79
|
+
styles
|
|
80
|
+
})
|
|
81
|
+
});
|
|
82
|
+
const textContentClasses = createClass({
|
|
83
|
+
...getTextContentClasses(styles)
|
|
84
|
+
});
|
|
85
|
+
const textContentStyle = createStyle({
|
|
86
|
+
...getTextContentStyle({
|
|
87
|
+
setting,
|
|
88
|
+
styles
|
|
89
|
+
})
|
|
90
|
+
});
|
|
91
|
+
const textContentAttrs = createAttr({
|
|
92
|
+
...getTextContentAttrs()
|
|
93
|
+
});
|
|
94
|
+
const imageContainerClasses = createClass({
|
|
95
|
+
...getImageContainerClasses()
|
|
96
|
+
});
|
|
97
|
+
const imageContainerStyles = createStyle({
|
|
98
|
+
...getImageContainerStyles({
|
|
99
|
+
setting,
|
|
100
|
+
styles
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
const imageClass = createClass({
|
|
104
|
+
...getImageClasses()
|
|
105
|
+
});
|
|
106
|
+
const imageAttr = createAttr({
|
|
107
|
+
...getImageAttr({
|
|
108
|
+
setting
|
|
109
|
+
})
|
|
110
|
+
});
|
|
98
111
|
if (!product) return null;
|
|
99
112
|
return /*#__PURE__*/ jsxs("div", {
|
|
100
|
-
...
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
style: {
|
|
104
|
-
...!isDropOutsideProductImage && {
|
|
105
|
-
'--pos': 'absolute'
|
|
106
|
-
},
|
|
107
|
-
...wrapperStyles,
|
|
108
|
-
...advancedStyles
|
|
109
|
-
},
|
|
110
|
-
className: cls(conditionClass, builderProps?.builderData?.advanced?.cssClass || '', builderProps?.uid, 'gp-shrink-0', 'product-badge', isInsideProductImage ? 'inside-image' : ''),
|
|
111
|
-
"gp-data-hidden": "false",
|
|
113
|
+
...containerAttrs,
|
|
114
|
+
style: containerStyle,
|
|
115
|
+
className: containerClass,
|
|
112
116
|
children: [
|
|
113
|
-
mode === 'edit' && isNoDiscountState
|
|
114
|
-
|
|
115
|
-
text: 'Not be displayed when published',
|
|
116
|
-
position: isDropOutsideProductImage ? 'bottom' : 'right',
|
|
117
|
-
width: '205px',
|
|
117
|
+
If(mode === 'edit' && isNoDiscountState, /*#__PURE__*/ jsx(TooltipHover, {
|
|
118
|
+
...editTooltipAttrs,
|
|
118
119
|
children: /*#__PURE__*/ jsx(NoDataState, {
|
|
119
|
-
|
|
120
|
-
elementType: "secondary",
|
|
121
|
-
description: "No discount",
|
|
122
|
-
rawMode: true
|
|
123
|
-
})
|
|
124
|
-
}) : isDropOutsideProductImage ? /*#__PURE__*/ jsx("div", {
|
|
125
|
-
className: cls('gp-flex', getAlignShape(align, false)),
|
|
126
|
-
children: /*#__PURE__*/ jsx("div", {
|
|
127
|
-
"data-product-id": currentProductId,
|
|
128
|
-
className: placementClass,
|
|
129
|
-
style: {
|
|
130
|
-
...sizeStyles,
|
|
131
|
-
'--mb': 0,
|
|
132
|
-
opacity: opacityProductBadge
|
|
133
|
-
},
|
|
134
|
-
children: /*#__PURE__*/ jsx(RenderContent, {})
|
|
120
|
+
...noDataAttrs
|
|
135
121
|
})
|
|
136
|
-
})
|
|
137
|
-
className:
|
|
138
|
-
children: /*#__PURE__*/
|
|
139
|
-
|
|
140
|
-
className:
|
|
141
|
-
style:
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
122
|
+
}), /*#__PURE__*/ jsx("div", {
|
|
123
|
+
className: wrapperClass,
|
|
124
|
+
children: /*#__PURE__*/ jsxs("div", {
|
|
125
|
+
...subWrapperAttrs,
|
|
126
|
+
className: subWrapperClass,
|
|
127
|
+
style: subWrapperStyle,
|
|
128
|
+
children: [
|
|
129
|
+
/*#__PURE__*/ jsx("style", {
|
|
130
|
+
children: contentStyleInternal
|
|
131
|
+
}),
|
|
132
|
+
If(setting?.shape !== 'image', /*#__PURE__*/ jsx("div", {
|
|
133
|
+
className: textContentContainerClasses,
|
|
134
|
+
children: /*#__PURE__*/ jsx("div", {
|
|
135
|
+
className: textContentWrapperClasses,
|
|
136
|
+
style: textContentWrapperStyle,
|
|
137
|
+
children: /*#__PURE__*/ jsx("pre", {
|
|
138
|
+
...textContentAttrs,
|
|
139
|
+
className: textContentClasses,
|
|
140
|
+
style: textContentStyle,
|
|
141
|
+
children: badgeContent
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
}), /*#__PURE__*/ jsx("div", {
|
|
145
|
+
className: imageContainerClasses,
|
|
146
|
+
style: imageContainerStyles,
|
|
147
|
+
children: /*#__PURE__*/ jsx("img", {
|
|
148
|
+
...imageAttr,
|
|
149
|
+
className: imageClass
|
|
150
|
+
})
|
|
151
|
+
}))
|
|
152
|
+
]
|
|
145
153
|
})
|
|
146
|
-
}),
|
|
154
|
+
})),
|
|
147
155
|
filterToolbarPreview(children, true)
|
|
148
156
|
]
|
|
149
157
|
});
|