@gem-sdk/components 2.0.0-dev.393 → 2.0.0-dev.394

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.
Files changed (30) hide show
  1. package/dist/cjs/builder.js +4 -4
  2. package/dist/cjs/index.js +30 -30
  3. package/dist/cjs/index.liquid.js +4 -4
  4. package/dist/cjs/product/components/ProductDiscountTag/common/getClasses.js +38 -0
  5. package/dist/cjs/product/components/ProductDiscountTag/common/getStyle.js +42 -0
  6. package/dist/cjs/product/components/ProductDiscountTag/hooks/useGpDiscountTag.js +108 -0
  7. package/dist/cjs/product/components/ProductDiscountTag/index.js +110 -0
  8. package/dist/cjs/product/components/ProductDiscountTag/index.liquid.js +91 -0
  9. package/dist/cjs/product/index.js +4 -4
  10. package/dist/cjs/product/next.js +1 -1
  11. package/dist/cjs/product/setting/ProductTag.js +7 -299
  12. package/dist/cjs/product/setting/product-discount-tag/configs/settings.js +191 -0
  13. package/dist/cjs/product/setting/product-discount-tag/configs/uiV2.js +190 -0
  14. package/dist/esm/builder.js +1 -1
  15. package/dist/esm/index.js +1 -1
  16. package/dist/esm/index.liquid.js +1 -1
  17. package/dist/esm/product/components/ProductDiscountTag/common/getClasses.js +33 -0
  18. package/dist/esm/product/components/ProductDiscountTag/common/getStyle.js +38 -0
  19. package/dist/esm/product/components/ProductDiscountTag/hooks/useGpDiscountTag.js +106 -0
  20. package/dist/esm/product/components/ProductDiscountTag/index.js +106 -0
  21. package/dist/esm/product/components/ProductDiscountTag/index.liquid.js +87 -0
  22. package/dist/esm/product/next.js +1 -1
  23. package/dist/esm/product/setting/ProductTag.js +7 -299
  24. package/dist/esm/product/setting/product-discount-tag/configs/settings.js +189 -0
  25. package/dist/esm/product/setting/product-discount-tag/configs/uiV2.js +188 -0
  26. package/package.json +1 -1
  27. package/dist/cjs/product/components/ProductTag/ProductTag.js +0 -200
  28. package/dist/cjs/product/components/ProductTag/ProductTag.liquid.js +0 -107
  29. package/dist/esm/product/components/ProductTag/ProductTag.js +0 -196
  30. package/dist/esm/product/components/ProductTag/ProductTag.liquid.js +0 -103
@@ -1,200 +0,0 @@
1
- 'use client';
2
- 'use strict';
3
-
4
- Object.defineProperty(exports, '__esModule', { value: true });
5
-
6
- var jsxRuntime = require('react/jsx-runtime');
7
- var core = require('@gem-sdk/core');
8
- var React = require('react');
9
- var NoDataState = require('../../../common/components/NoDataState.js');
10
- var TooltipHover = require('../../../common/components/TooltipHover.js');
11
- var productBundle = require('../../helpers/product-bundle.js');
12
- var Text = require('../../../text/components/Text.js');
13
- var productBundle$1 = require('../constants/product-bundle.js');
14
-
15
- const ProductTag = ({ setting, styles, builderProps, ...passProps })=>{
16
- const { customContent } = setting ?? {};
17
- const bundleItem = passProps['bundle-item'];
18
- const { textAlign, backgroundColor, roundedTag, borderTag, textColor } = styles ?? {};
19
- const { moneyFormat } = core.useMoneyFormat();
20
- const composeGlobalSize = core.makeGlobalSize(styles?.size);
21
- const mode = core.useEditorMode();
22
- const product = core.useProduct();
23
- const currentVariant = core.useCurrentVariant();
24
- const { quantity, hasUpdatePrice } = core.useQuantity();
25
- const quantityProduct = React.useMemo(()=>{
26
- return hasUpdatePrice && customContent?.unit !== 'percentage' ? quantity ?? 1 : 1;
27
- }, [
28
- hasUpdatePrice,
29
- customContent?.unit,
30
- quantity
31
- ]);
32
- const price = currentVariant?.price ?? 0;
33
- const salePrice = currentVariant?.salePrice ?? 0;
34
- const priceSave = (salePrice - price) * quantityProduct;
35
- const moneyFormatted = core.useFormatMoney(priceSave < 0 ? 0 : priceSave, setting?.moneyWithCurrentFormat || false);
36
- const customDisplayWithUnit = React.useMemo(()=>{
37
- if (!salePrice && salePrice !== 0 || !price && price !== 0) return `${customContent?.unit === 'percentage' ? '0%' : moneyFormatted}`;
38
- if (customContent?.unit === 'percentage') {
39
- const salePercent = Math.round(priceSave / (salePrice / 100));
40
- return `${salePercent < 0 ? 0 : salePercent}%`;
41
- }
42
- return `${moneyFormatted}`;
43
- }, [
44
- customContent?.unit,
45
- moneyFormatted,
46
- price,
47
- priceSave,
48
- salePrice
49
- ]);
50
- const { useProductCompareAtPrice } = core.useProductBundleDiscount();
51
- const { discountPercentAmount } = productBundle.applyBundleDiscountAmount({
52
- currentVariant,
53
- bundleItem,
54
- options: {
55
- moneyFormat,
56
- useProductCompareAtPrice
57
- }
58
- });
59
- const bundleDiscountDisplay = React.useMemo(()=>{
60
- if (!bundleItem) return 0;
61
- const { discountPercentAmount, discountAmount } = productBundle.applyBundleDiscountAmount({
62
- currentVariant,
63
- bundleItem,
64
- options: {
65
- moneyFormat,
66
- useProductCompareAtPrice
67
- }
68
- });
69
- const { discountType } = bundleItem;
70
- const { unit } = customContent || {};
71
- if (discountType === productBundle$1.DiscountType.NoDiscount && !useProductCompareAtPrice) {
72
- return unit === 'percentage' ? '0%' : core.formatMoney('0', moneyFormat);
73
- }
74
- if (unit === 'percentage') {
75
- return `${discountPercentAmount}%`;
76
- }
77
- return discountAmount;
78
- }, [
79
- bundleItem,
80
- currentVariant,
81
- moneyFormat,
82
- useProductCompareAtPrice,
83
- customContent
84
- ]);
85
- const unitCustomDisplay = React.useMemo(()=>{
86
- if (!bundleItem) {
87
- return customDisplayWithUnit;
88
- }
89
- return bundleDiscountDisplay;
90
- }, [
91
- bundleDiscountDisplay,
92
- bundleItem,
93
- customDisplayWithUnit
94
- ]);
95
- const borderColorClass = core.getGlobalColorClass('border', borderTag?.color);
96
- const textColorClass = core.getGlobalColorClass('text', textColor);
97
- const backgroundColorClass = core.getGlobalColorClass('bg', backgroundColor);
98
- const currentProductId = product?.baseID?.replace('gid://shopify/Product/', '');
99
- const shouldPlaceholderNoDiscount = React.useMemo(()=>{
100
- const noDiscount = !bundleItem ? priceSave <= 0 : discountPercentAmount <= 0;
101
- return mode === 'edit' && noDiscount;
102
- }, [
103
- bundleItem,
104
- discountPercentAmount,
105
- mode,
106
- priceSave
107
- ]);
108
- if (shouldPlaceholderNoDiscount) {
109
- return /*#__PURE__*/ jsxRuntime.jsx(TooltipHover.default, {
110
- enable: true,
111
- text: 'Not be displayed when published',
112
- position: 'bottom',
113
- width: '205px',
114
- children: /*#__PURE__*/ jsxRuntime.jsx(NoDataState.default, {
115
- builderAttrs: builderProps?.builderData,
116
- elementType: "secondary",
117
- description: "No discount",
118
- rawMode: true
119
- })
120
- });
121
- }
122
- return /*#__PURE__*/ jsxRuntime.jsx("div", {
123
- className: core.cls({
124
- 'gp-opacity-0 ': mode !== 'edit' && (salePrice <= 0 || Math.ceil(priceSave / (salePrice / 100)) <= 0),
125
- 'gp-opacity-20 ': mode === 'edit' && (salePrice <= 0 || Math.ceil(priceSave / (salePrice / 100)) <= 0) && !bundleItem
126
- }),
127
- style: {
128
- ...core.makeStyleResponsive('ta', textAlign)
129
- },
130
- id: `shopify-text-element-${builderProps?.uid}`,
131
- "data-id": builderProps?.uid,
132
- "data-product-id": currentProductId,
133
- "gp-data-hidden": "false",
134
- children: !product ? null : /*#__PURE__*/ jsxRuntime.jsx("div", {
135
- className: core.cls('gp-inline-flex gp-flex-wrap gp-items-end gp-gap-3'),
136
- style: {
137
- ...composeGlobalSize.width,
138
- ...composeGlobalSize.height
139
- },
140
- children: /*#__PURE__*/ jsxRuntime.jsx("div", {
141
- className: core.cls('gp-flex gp-items-center gp-w-full gp-h-full', borderColorClass, textColorClass, backgroundColorClass),
142
- style: {
143
- ...core.makeStyleResponsive('jc', styles?.textContentAlign),
144
- ...composeGlobalSize.padding,
145
- ...core.makeStyle({
146
- bs: borderTag?.border,
147
- bw: borderTag?.width,
148
- bc: borderColorClass === '' ? borderTag?.color : undefined,
149
- c: textColorClass === '' ? textColor : undefined,
150
- bg: backgroundColorClass === '' ? backgroundColor : undefined
151
- }),
152
- ...roundedTag?.radiusType !== 'custom' ? core.getRadiusCSSFromGlobal('normal', roundedTag?.radiusType) : {},
153
- ...core.getCustomRadius('normal', roundedTag)
154
- },
155
- children: /*#__PURE__*/ jsxRuntime.jsxs("div", {
156
- className: "gp-flex gp-break-all",
157
- children: [
158
- /*#__PURE__*/ jsxRuntime.jsx(Text.default, {
159
- styles: styles,
160
- setting: {
161
- ...setting,
162
- text: customContent?.prefix?.replaceAll(' ', '&nbsp;'),
163
- options: {
164
- useState: true,
165
- uniqueId: `${builderProps?.uid}-prefix`
166
- },
167
- excludeFlex: true
168
- }
169
- }),
170
- /*#__PURE__*/ jsxRuntime.jsx(Text.default, {
171
- styles: styles,
172
- setting: {
173
- ...setting,
174
- text: unitCustomDisplay,
175
- options: {
176
- isCannotEditing: true
177
- },
178
- excludeFlex: true
179
- }
180
- }),
181
- /*#__PURE__*/ jsxRuntime.jsx(Text.default, {
182
- styles: styles,
183
- setting: {
184
- ...setting,
185
- text: customContent?.suffix?.replaceAll(' ', '&nbsp;'),
186
- excludeFlex: true,
187
- options: {
188
- useState: true,
189
- uniqueId: `${builderProps?.uid}-suffix`
190
- }
191
- }
192
- })
193
- ]
194
- })
195
- })
196
- })
197
- });
198
- };
199
-
200
- exports.default = ProductTag;
@@ -1,107 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var core = require('@gem-sdk/core');
6
- var helpers = require('../../../helpers.js');
7
- var Text_liquid = require('../../../text/components/Text.liquid.js');
8
-
9
- const ProductTag = ({ setting, styles, builderProps, advanced, pageContext })=>{
10
- const { customContent, translate } = setting ?? {};
11
- const { textAlign, backgroundColor, roundedTag, borderTag, textColor } = styles ?? {};
12
- const borderColorClass = core.getGlobalColorClass('border', borderTag?.color);
13
- const textColorClass = core.getGlobalColorClass('text', textColor);
14
- const backgroundColorClass = core.getGlobalColorClass('bg', backgroundColor);
15
- const composeGlobalSize = core.makeGlobalSize(styles?.size);
16
- const moneyFormat = setting?.moneyWithCurrentFormat ? `money_with_currency` : `money`;
17
- const prefixVal = helpers.getDynamicSourceLocales({
18
- val: customContent?.prefix,
19
- uid: builderProps?.uid,
20
- settingId: 'customContent_prefix',
21
- isLiquid: true,
22
- pageContext,
23
- translate
24
- });
25
- const suffixVal = helpers.getDynamicSourceLocales({
26
- val: customContent?.suffix,
27
- uid: builderProps?.uid,
28
- settingId: 'customContent_suffix',
29
- isLiquid: true,
30
- pageContext,
31
- translate
32
- });
33
- return core.template`
34
- {% liquid
35
- assign price = variant.price | times: 1.0
36
- assign salePrice = variant.compare_at_price | times: 1.0
37
- assign priceSave = salePrice | minus: price
38
- assign prefixVal = ${pageContext?.isPreviewing ? JSON.stringify(prefixVal) : prefixVal}
39
- assign suffixVal = ${pageContext?.isPreviewing ? JSON.stringify(suffixVal) : suffixVal}
40
- if salePrice == null or price == null
41
- assign pricePercentage = prefixVal ${customContent?.unit === 'percentage' ? `| append: ' 0% '` : `| ${moneyFormat} | append: ' '`} | append: suffixVal
42
- else
43
- ${customContent?.unit === 'percentage' ? ` assign salePercent = priceSave | divided_by: salePrice | times: 100 | round
44
- assign pricePercentage = prefixVal | append: ' ' | append: salePercent | append: '% ' | append: suffixVal
45
- ` : `
46
- if priceSave > 0
47
- assign priceSaveMoney = priceSave | ${moneyFormat}
48
- assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal
49
- else
50
- assign priceSaveMoney = 0 | ${moneyFormat}
51
- assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal
52
- endif
53
- `}
54
- endif
55
- %}
56
-
57
- <gp-product-tag
58
- data-id="${builderProps?.uid}"
59
- data-disabled="{%- if priceSave > 0 -%} false {%- else -%} true {%- endif -%}"
60
- gp-data='{"setting":${JSON.stringify(setting).replaceAll("'", '&#039;')}, "id": "${builderProps?.uid}", "locale": "{{shop.locale}}", "currency": "{{shop.currency}}", "moneyFormat": "{{ ${setting?.moneyWithCurrentFormat ? 'shop.money_with_currency_format' : 'shop.money_format'} | replace: '"', '\\"' | escape }}"}'
61
- class="gp-block data-[disabled=true]:gp-hidden ${advanced?.cssClass}"
62
- style="${{
63
- ...core.makeStyleResponsive('ta', textAlign)
64
- }}"
65
- price-save="{{priceSave}}"
66
- data-prefix="${pageContext?.isPreviewing ? prefixVal : `{{${prefixVal}}}`}"
67
- data-suffix="${pageContext?.isPreviewing ? suffixVal : `{{${suffixVal}}}`}"
68
- >
69
- <div class="${core.cls('gp-inline-flex gp-flex-wrap gp-items-end gp-gap-3')}" style="${{
70
- ...composeGlobalSize.width,
71
- ...composeGlobalSize.height
72
- }}">
73
- <div
74
- class="${core.cls('gp-flex gp-items-center gp-w-full gp-h-full', borderColorClass, textColorClass, backgroundColorClass)}"
75
- style="${{
76
- ...core.makeStyleResponsive('jc', styles?.textContentAlign),
77
- ...composeGlobalSize.padding,
78
- ...core.makeStyle({
79
- bs: borderTag?.border,
80
- bw: borderTag?.width,
81
- bc: borderColorClass === '' ? borderTag?.color : undefined,
82
- c: textColorClass === '' ? textColor : undefined,
83
- bg: backgroundColorClass === '' ? backgroundColor : undefined
84
- }),
85
- ...roundedTag?.radiusType !== 'custom' ? core.getRadiusCSSFromGlobal('normal', roundedTag?.radiusType) : {},
86
- ...core.getCustomRadius('normal', roundedTag)
87
- }}"
88
- >
89
- ${Text_liquid.default({
90
- styles,
91
- id: `p-tag-${builderProps?.uid}`,
92
- setting: {
93
- ...setting,
94
- translate: '',
95
- text: '{{pricePercentage}}',
96
- excludeFlex: true
97
- }
98
- })}
99
- </div>
100
- </div>
101
-
102
- </gp-product-tag>
103
- ${core.RenderIf(core.isLocalEnv, `<script ${helpers.getSettingPreloadData('class="gps-link" delay', 'src')}="{{ 'gp-product-tag.js' | asset_url }}" defer="defer"></script>`, `<script ${helpers.getSettingPreloadData('class="gps-link" delay', 'src')}="${core.baseAssetURL}/assets-v2/gp-product-tag.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
104
- `;
105
- };
106
-
107
- exports.default = ProductTag;
@@ -1,196 +0,0 @@
1
- 'use client';
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
- import { useMoneyFormat, makeGlobalSize, useEditorMode, useProduct, useCurrentVariant, useQuantity, useFormatMoney, useProductBundleDiscount, formatMoney, getGlobalColorClass, cls, makeStyleResponsive, makeStyle, getRadiusCSSFromGlobal, getCustomRadius } from '@gem-sdk/core';
4
- import { useMemo } from 'react';
5
- import NoDataState from '../../../common/components/NoDataState.js';
6
- import TooltipHover from '../../../common/components/TooltipHover.js';
7
- import { applyBundleDiscountAmount } from '../../helpers/product-bundle.js';
8
- import Text from '../../../text/components/Text.js';
9
- import { DiscountType } from '../constants/product-bundle.js';
10
-
11
- const ProductTag = ({ setting, styles, builderProps, ...passProps })=>{
12
- const { customContent } = setting ?? {};
13
- const bundleItem = passProps['bundle-item'];
14
- const { textAlign, backgroundColor, roundedTag, borderTag, textColor } = styles ?? {};
15
- const { moneyFormat } = useMoneyFormat();
16
- const composeGlobalSize = makeGlobalSize(styles?.size);
17
- const mode = useEditorMode();
18
- const product = useProduct();
19
- const currentVariant = useCurrentVariant();
20
- const { quantity, hasUpdatePrice } = useQuantity();
21
- const quantityProduct = useMemo(()=>{
22
- return hasUpdatePrice && customContent?.unit !== 'percentage' ? quantity ?? 1 : 1;
23
- }, [
24
- hasUpdatePrice,
25
- customContent?.unit,
26
- quantity
27
- ]);
28
- const price = currentVariant?.price ?? 0;
29
- const salePrice = currentVariant?.salePrice ?? 0;
30
- const priceSave = (salePrice - price) * quantityProduct;
31
- const moneyFormatted = useFormatMoney(priceSave < 0 ? 0 : priceSave, setting?.moneyWithCurrentFormat || false);
32
- const customDisplayWithUnit = useMemo(()=>{
33
- if (!salePrice && salePrice !== 0 || !price && price !== 0) return `${customContent?.unit === 'percentage' ? '0%' : moneyFormatted}`;
34
- if (customContent?.unit === 'percentage') {
35
- const salePercent = Math.round(priceSave / (salePrice / 100));
36
- return `${salePercent < 0 ? 0 : salePercent}%`;
37
- }
38
- return `${moneyFormatted}`;
39
- }, [
40
- customContent?.unit,
41
- moneyFormatted,
42
- price,
43
- priceSave,
44
- salePrice
45
- ]);
46
- const { useProductCompareAtPrice } = useProductBundleDiscount();
47
- const { discountPercentAmount } = applyBundleDiscountAmount({
48
- currentVariant,
49
- bundleItem,
50
- options: {
51
- moneyFormat,
52
- useProductCompareAtPrice
53
- }
54
- });
55
- const bundleDiscountDisplay = useMemo(()=>{
56
- if (!bundleItem) return 0;
57
- const { discountPercentAmount, discountAmount } = applyBundleDiscountAmount({
58
- currentVariant,
59
- bundleItem,
60
- options: {
61
- moneyFormat,
62
- useProductCompareAtPrice
63
- }
64
- });
65
- const { discountType } = bundleItem;
66
- const { unit } = customContent || {};
67
- if (discountType === DiscountType.NoDiscount && !useProductCompareAtPrice) {
68
- return unit === 'percentage' ? '0%' : formatMoney('0', moneyFormat);
69
- }
70
- if (unit === 'percentage') {
71
- return `${discountPercentAmount}%`;
72
- }
73
- return discountAmount;
74
- }, [
75
- bundleItem,
76
- currentVariant,
77
- moneyFormat,
78
- useProductCompareAtPrice,
79
- customContent
80
- ]);
81
- const unitCustomDisplay = useMemo(()=>{
82
- if (!bundleItem) {
83
- return customDisplayWithUnit;
84
- }
85
- return bundleDiscountDisplay;
86
- }, [
87
- bundleDiscountDisplay,
88
- bundleItem,
89
- customDisplayWithUnit
90
- ]);
91
- const borderColorClass = getGlobalColorClass('border', borderTag?.color);
92
- const textColorClass = getGlobalColorClass('text', textColor);
93
- const backgroundColorClass = getGlobalColorClass('bg', backgroundColor);
94
- const currentProductId = product?.baseID?.replace('gid://shopify/Product/', '');
95
- const shouldPlaceholderNoDiscount = useMemo(()=>{
96
- const noDiscount = !bundleItem ? priceSave <= 0 : discountPercentAmount <= 0;
97
- return mode === 'edit' && noDiscount;
98
- }, [
99
- bundleItem,
100
- discountPercentAmount,
101
- mode,
102
- priceSave
103
- ]);
104
- if (shouldPlaceholderNoDiscount) {
105
- return /*#__PURE__*/ jsx(TooltipHover, {
106
- enable: true,
107
- text: 'Not be displayed when published',
108
- position: 'bottom',
109
- width: '205px',
110
- children: /*#__PURE__*/ jsx(NoDataState, {
111
- builderAttrs: builderProps?.builderData,
112
- elementType: "secondary",
113
- description: "No discount",
114
- rawMode: true
115
- })
116
- });
117
- }
118
- return /*#__PURE__*/ jsx("div", {
119
- className: cls({
120
- 'gp-opacity-0 ': mode !== 'edit' && (salePrice <= 0 || Math.ceil(priceSave / (salePrice / 100)) <= 0),
121
- 'gp-opacity-20 ': mode === 'edit' && (salePrice <= 0 || Math.ceil(priceSave / (salePrice / 100)) <= 0) && !bundleItem
122
- }),
123
- style: {
124
- ...makeStyleResponsive('ta', textAlign)
125
- },
126
- id: `shopify-text-element-${builderProps?.uid}`,
127
- "data-id": builderProps?.uid,
128
- "data-product-id": currentProductId,
129
- "gp-data-hidden": "false",
130
- children: !product ? null : /*#__PURE__*/ jsx("div", {
131
- className: cls('gp-inline-flex gp-flex-wrap gp-items-end gp-gap-3'),
132
- style: {
133
- ...composeGlobalSize.width,
134
- ...composeGlobalSize.height
135
- },
136
- children: /*#__PURE__*/ jsx("div", {
137
- className: cls('gp-flex gp-items-center gp-w-full gp-h-full', borderColorClass, textColorClass, backgroundColorClass),
138
- style: {
139
- ...makeStyleResponsive('jc', styles?.textContentAlign),
140
- ...composeGlobalSize.padding,
141
- ...makeStyle({
142
- bs: borderTag?.border,
143
- bw: borderTag?.width,
144
- bc: borderColorClass === '' ? borderTag?.color : undefined,
145
- c: textColorClass === '' ? textColor : undefined,
146
- bg: backgroundColorClass === '' ? backgroundColor : undefined
147
- }),
148
- ...roundedTag?.radiusType !== 'custom' ? getRadiusCSSFromGlobal('normal', roundedTag?.radiusType) : {},
149
- ...getCustomRadius('normal', roundedTag)
150
- },
151
- children: /*#__PURE__*/ jsxs("div", {
152
- className: "gp-flex gp-break-all",
153
- children: [
154
- /*#__PURE__*/ jsx(Text, {
155
- styles: styles,
156
- setting: {
157
- ...setting,
158
- text: customContent?.prefix?.replaceAll(' ', '&nbsp;'),
159
- options: {
160
- useState: true,
161
- uniqueId: `${builderProps?.uid}-prefix`
162
- },
163
- excludeFlex: true
164
- }
165
- }),
166
- /*#__PURE__*/ jsx(Text, {
167
- styles: styles,
168
- setting: {
169
- ...setting,
170
- text: unitCustomDisplay,
171
- options: {
172
- isCannotEditing: true
173
- },
174
- excludeFlex: true
175
- }
176
- }),
177
- /*#__PURE__*/ jsx(Text, {
178
- styles: styles,
179
- setting: {
180
- ...setting,
181
- text: customContent?.suffix?.replaceAll(' ', '&nbsp;'),
182
- excludeFlex: true,
183
- options: {
184
- useState: true,
185
- uniqueId: `${builderProps?.uid}-suffix`
186
- }
187
- }
188
- })
189
- ]
190
- })
191
- })
192
- })
193
- });
194
- };
195
-
196
- export { ProductTag as default };
@@ -1,103 +0,0 @@
1
- import { getGlobalColorClass, makeGlobalSize, template, makeStyleResponsive, cls, makeStyle, getRadiusCSSFromGlobal, getCustomRadius, RenderIf, isLocalEnv, baseAssetURL } from '@gem-sdk/core';
2
- import { getDynamicSourceLocales, getSettingPreloadData } from '../../../helpers.js';
3
- import Text from '../../../text/components/Text.liquid.js';
4
-
5
- const ProductTag = ({ setting, styles, builderProps, advanced, pageContext })=>{
6
- const { customContent, translate } = setting ?? {};
7
- const { textAlign, backgroundColor, roundedTag, borderTag, textColor } = styles ?? {};
8
- const borderColorClass = getGlobalColorClass('border', borderTag?.color);
9
- const textColorClass = getGlobalColorClass('text', textColor);
10
- const backgroundColorClass = getGlobalColorClass('bg', backgroundColor);
11
- const composeGlobalSize = makeGlobalSize(styles?.size);
12
- const moneyFormat = setting?.moneyWithCurrentFormat ? `money_with_currency` : `money`;
13
- const prefixVal = getDynamicSourceLocales({
14
- val: customContent?.prefix,
15
- uid: builderProps?.uid,
16
- settingId: 'customContent_prefix',
17
- isLiquid: true,
18
- pageContext,
19
- translate
20
- });
21
- const suffixVal = getDynamicSourceLocales({
22
- val: customContent?.suffix,
23
- uid: builderProps?.uid,
24
- settingId: 'customContent_suffix',
25
- isLiquid: true,
26
- pageContext,
27
- translate
28
- });
29
- return template`
30
- {% liquid
31
- assign price = variant.price | times: 1.0
32
- assign salePrice = variant.compare_at_price | times: 1.0
33
- assign priceSave = salePrice | minus: price
34
- assign prefixVal = ${pageContext?.isPreviewing ? JSON.stringify(prefixVal) : prefixVal}
35
- assign suffixVal = ${pageContext?.isPreviewing ? JSON.stringify(suffixVal) : suffixVal}
36
- if salePrice == null or price == null
37
- assign pricePercentage = prefixVal ${customContent?.unit === 'percentage' ? `| append: ' 0% '` : `| ${moneyFormat} | append: ' '`} | append: suffixVal
38
- else
39
- ${customContent?.unit === 'percentage' ? ` assign salePercent = priceSave | divided_by: salePrice | times: 100 | round
40
- assign pricePercentage = prefixVal | append: ' ' | append: salePercent | append: '% ' | append: suffixVal
41
- ` : `
42
- if priceSave > 0
43
- assign priceSaveMoney = priceSave | ${moneyFormat}
44
- assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal
45
- else
46
- assign priceSaveMoney = 0 | ${moneyFormat}
47
- assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal
48
- endif
49
- `}
50
- endif
51
- %}
52
-
53
- <gp-product-tag
54
- data-id="${builderProps?.uid}"
55
- data-disabled="{%- if priceSave > 0 -%} false {%- else -%} true {%- endif -%}"
56
- gp-data='{"setting":${JSON.stringify(setting).replaceAll("'", '&#039;')}, "id": "${builderProps?.uid}", "locale": "{{shop.locale}}", "currency": "{{shop.currency}}", "moneyFormat": "{{ ${setting?.moneyWithCurrentFormat ? 'shop.money_with_currency_format' : 'shop.money_format'} | replace: '"', '\\"' | escape }}"}'
57
- class="gp-block data-[disabled=true]:gp-hidden ${advanced?.cssClass}"
58
- style="${{
59
- ...makeStyleResponsive('ta', textAlign)
60
- }}"
61
- price-save="{{priceSave}}"
62
- data-prefix="${pageContext?.isPreviewing ? prefixVal : `{{${prefixVal}}}`}"
63
- data-suffix="${pageContext?.isPreviewing ? suffixVal : `{{${suffixVal}}}`}"
64
- >
65
- <div class="${cls('gp-inline-flex gp-flex-wrap gp-items-end gp-gap-3')}" style="${{
66
- ...composeGlobalSize.width,
67
- ...composeGlobalSize.height
68
- }}">
69
- <div
70
- class="${cls('gp-flex gp-items-center gp-w-full gp-h-full', borderColorClass, textColorClass, backgroundColorClass)}"
71
- style="${{
72
- ...makeStyleResponsive('jc', styles?.textContentAlign),
73
- ...composeGlobalSize.padding,
74
- ...makeStyle({
75
- bs: borderTag?.border,
76
- bw: borderTag?.width,
77
- bc: borderColorClass === '' ? borderTag?.color : undefined,
78
- c: textColorClass === '' ? textColor : undefined,
79
- bg: backgroundColorClass === '' ? backgroundColor : undefined
80
- }),
81
- ...roundedTag?.radiusType !== 'custom' ? getRadiusCSSFromGlobal('normal', roundedTag?.radiusType) : {},
82
- ...getCustomRadius('normal', roundedTag)
83
- }}"
84
- >
85
- ${Text({
86
- styles,
87
- id: `p-tag-${builderProps?.uid}`,
88
- setting: {
89
- ...setting,
90
- translate: '',
91
- text: '{{pricePercentage}}',
92
- excludeFlex: true
93
- }
94
- })}
95
- </div>
96
- </div>
97
-
98
- </gp-product-tag>
99
- ${RenderIf(isLocalEnv, `<script ${getSettingPreloadData('class="gps-link" delay', 'src')}="{{ 'gp-product-tag.js' | asset_url }}" defer="defer"></script>`, `<script ${getSettingPreloadData('class="gps-link" delay', 'src')}="${baseAssetURL}/assets-v2/gp-product-tag.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
100
- `;
101
- };
102
-
103
- export { ProductTag as default };