@gem-sdk/components 2.0.0-dev.392 → 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 (43) 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-badge/configs/settings.js +6 -0
  13. package/dist/cjs/product/setting/product-badge/configs/uiV2.js +14 -19
  14. package/dist/cjs/product/setting/product-discount-tag/configs/settings.js +191 -0
  15. package/dist/cjs/product/setting/product-discount-tag/configs/uiV2.js +190 -0
  16. package/dist/cjs/product/setting/product-vendor/configs/settings.js +12 -0
  17. package/dist/cjs/product/setting/product-vendor/configs/uiV2.js +1 -1
  18. package/dist/cjs/sticky/components/Sticky.js +4 -4
  19. package/dist/cjs/sticky/components/hooks/useSticky.js +19 -9
  20. package/dist/esm/builder.js +1 -1
  21. package/dist/esm/index.js +1 -1
  22. package/dist/esm/index.liquid.js +1 -1
  23. package/dist/esm/product/components/ProductDiscountTag/common/getClasses.js +33 -0
  24. package/dist/esm/product/components/ProductDiscountTag/common/getStyle.js +38 -0
  25. package/dist/esm/product/components/ProductDiscountTag/hooks/useGpDiscountTag.js +106 -0
  26. package/dist/esm/product/components/ProductDiscountTag/index.js +106 -0
  27. package/dist/esm/product/components/ProductDiscountTag/index.liquid.js +87 -0
  28. package/dist/esm/product/next.js +1 -1
  29. package/dist/esm/product/setting/ProductTag.js +7 -299
  30. package/dist/esm/product/setting/product-badge/configs/settings.js +6 -0
  31. package/dist/esm/product/setting/product-badge/configs/uiV2.js +14 -19
  32. package/dist/esm/product/setting/product-discount-tag/configs/settings.js +189 -0
  33. package/dist/esm/product/setting/product-discount-tag/configs/uiV2.js +188 -0
  34. package/dist/esm/product/setting/product-vendor/configs/settings.js +12 -0
  35. package/dist/esm/product/setting/product-vendor/configs/uiV2.js +1 -1
  36. package/dist/esm/sticky/components/Sticky.js +4 -4
  37. package/dist/esm/sticky/components/hooks/useSticky.js +20 -10
  38. package/dist/types/index.d.ts +1 -0
  39. package/package.json +2 -2
  40. package/dist/cjs/product/components/ProductTag/ProductTag.js +0 -200
  41. package/dist/cjs/product/components/ProductTag/ProductTag.liquid.js +0 -107
  42. package/dist/esm/product/components/ProductTag/ProductTag.js +0 -196
  43. package/dist/esm/product/components/ProductTag/ProductTag.liquid.js +0 -103
@@ -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 };