@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
@@ -0,0 +1,87 @@
1
+ import { template, dataStringify, isLocalEnv, baseAssetURL } from '@gem-sdk/core';
2
+ import { getDynamicSourceLocales, getSettingPreloadData } from '../../../helpers.js';
3
+ import Text from '../../../text/components/Text.liquid.js';
4
+ import { createStyle, createClass, createStateOrContext, LiquidIf, Liquid, If } from '@gem-sdk/system';
5
+ import { getWrapperTextClass, getContainerClass, getProductTagClass } from './common/getClasses.js';
6
+ import { getRootClass, getWrapperTextStyle, getContainerStyle } from './common/getStyle.js';
7
+
8
+ const ProductTag = ({ setting, styles, builderProps, advanced, pageContext })=>{
9
+ const { customContent, translate } = setting ?? {};
10
+ const moneyFormat = setting?.moneyWithCurrentFormat ? `money_with_currency` : `money`;
11
+ const prefixVal = getDynamicSourceLocales({
12
+ val: customContent?.prefix,
13
+ uid: builderProps?.uid,
14
+ settingId: 'customContent_prefix',
15
+ isLiquid: true,
16
+ pageContext,
17
+ translate
18
+ });
19
+ const suffixVal = getDynamicSourceLocales({
20
+ val: customContent?.suffix,
21
+ uid: builderProps?.uid,
22
+ settingId: 'customContent_suffix',
23
+ isLiquid: true,
24
+ pageContext,
25
+ translate
26
+ });
27
+ const rootStyle = createStyle(getRootClass(styles));
28
+ const wrapperTextStyle = createStyle(getWrapperTextStyle(styles));
29
+ const containerStyle = createStyle(getContainerStyle(styles));
30
+ const wrapperTextClass = createClass(getWrapperTextClass(styles));
31
+ const containerClass = createClass(getContainerClass());
32
+ const productTagClass = createClass(getProductTagClass(advanced));
33
+ const renderScript = ()=>{
34
+ const jsURL = isLocalEnv ? `{{ 'gp-product-tag.js' | asset_url }}` : `${baseAssetURL}/assets-v2/gp-product-tag.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}`;
35
+ return `<script ${getSettingPreloadData('class="gps-link" delay', 'src')}="${jsURL}" defer="defer"></script>`;
36
+ };
37
+ const stateData = createStateOrContext({
38
+ setting: JSON.stringify(setting).replaceAll("'", '&#039;'),
39
+ id: builderProps?.uid,
40
+ locale: '{{shop.locale}}',
41
+ currency: '{{shop.currency}}',
42
+ moneyFormat: `{{ ${setting?.moneyWithCurrentFormat ? 'shop.money_with_currency_format' : 'shop.money_format'} | replace: '"', '\\"' | escape }}`
43
+ });
44
+ return template`
45
+ {% liquid
46
+ assign price = variant.price | times: 1.0
47
+ assign salePrice = variant.compare_at_price | times: 1.0
48
+ assign priceSave = salePrice | minus: price
49
+ assign prefixVal = ${pageContext?.isPreviewing ? JSON.stringify(prefixVal) : prefixVal}
50
+ assign suffixVal = ${pageContext?.isPreviewing ? JSON.stringify(suffixVal) : suffixVal}
51
+ %}
52
+ ${LiquidIf('salePrice == null or price == null', Liquid(`{% assign pricePercentage = prefixVal ${If(customContent?.unit === 'percentage', `| append: ' 0% '`, `| ${moneyFormat} | append: ' '`)} | append: suffixVal %}`), `${If(customContent?.unit === 'percentage', `{% assign salePercent = priceSave | divided_by: salePrice | times: 100 | round %}
53
+ {% assign pricePercentage = prefixVal | append: ' ' | append: salePercent | append: '% ' | append: suffixVal %}`, LiquidIf('priceSave > 0', `{% assign priceSaveMoney = priceSave | ${moneyFormat} %}
54
+ {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`, `{% assign priceSaveMoney = 0 | ${moneyFormat} %}
55
+ {% assign pricePercentage = prefixVal | append: ' ' | append: priceSaveMoney | append: ' ' | append: suffixVal %}`))}`)}
56
+
57
+ <gp-product-tag
58
+ data-id="${builderProps?.uid}"
59
+ data-disabled="{%- if priceSave > 0 -%} false {%- else -%} true {%- endif -%}"
60
+ gp-data="${dataStringify(stateData)}"
61
+ price-save="{{priceSave}}"
62
+ data-prefix="${pageContext?.isPreviewing ? prefixVal : `{{${prefixVal}}}`}"
63
+ data-suffix="${pageContext?.isPreviewing ? suffixVal : `{{${suffixVal}}}`}"
64
+ class="${productTagClass}"
65
+ style="${rootStyle}"
66
+ >
67
+ <div class="${containerClass}" style="${containerStyle}">
68
+ <div class="${wrapperTextClass}" style="${wrapperTextStyle}">
69
+ ${Text({
70
+ styles,
71
+ id: `p-tag-${builderProps?.uid}`,
72
+ setting: {
73
+ ...setting,
74
+ translate: '',
75
+ text: '{{ pricePercentage }}',
76
+ excludeFlex: true
77
+ }
78
+ })}
79
+ </div>
80
+ </div>
81
+
82
+ </gp-product-tag>
83
+ ${renderScript()}
84
+ `;
85
+ };
86
+
87
+ export { ProductTag as default };
@@ -37,7 +37,7 @@ const ProductProperties = dynamic(()=>import('./components/ProductProperties/Pro
37
37
  const ProductQuickView = dynamic(()=>import('./components/ProductQuickView/index.js'), {
38
38
  ssr: false
39
39
  });
40
- const ProductTag = dynamic(()=>import('./components/ProductTag/ProductTag.js'), {
40
+ const ProductTag = dynamic(()=>import('./components/ProductDiscountTag/index.js'), {
41
41
  loading: Loading
42
42
  });
43
43
  const ProductList = dynamic(()=>import('./components/ProductList/ProductList.js'), {
@@ -1,306 +1,14 @@
1
+ import { SettingUIV2 } from './product-discount-tag/configs/uiV2.js';
2
+ import { ProductDiscountTagSettings } from './product-discount-tag/configs/settings.js';
3
+ import { SettingUIV1 } from './product/configs/uiV1.js';
4
+
1
5
  const config = {
2
6
  tag: 'ProductTag',
3
7
  label: 'Discount Tag',
4
8
  icon: `<svg fill="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M19.75 2A2.25 2.25 0 0 1 22 4.25v5.462a3.25 3.25 0 0 1-.952 2.298l-8.5 8.503a3.255 3.255 0 0 1-4.597.001L3.489 16.06a3.25 3.25 0 0 1-.003-4.596l8.5-8.51A3.25 3.25 0 0 1 14.284 2h5.465Zm0 1.5h-5.465c-.465 0-.91.185-1.239.513l-8.512 8.523a1.75 1.75 0 0 0 .015 2.462l4.461 4.454a1.755 1.755 0 0 0 2.477 0l8.5-8.503a1.75 1.75 0 0 0 .513-1.237V4.25a.75.75 0 0 0-.75-.75ZM17 5.502a1.5 1.5 0 1 1 0 3 1.5 1.5 0 0 1 0-3Z"/></svg>`,
5
- settings: [
6
- {
7
- id: 'setting',
8
- // note: 'Product Tag won’t display on live page if Compare at price field is empty or lower than Price.',
9
- controls: [
10
- {
11
- id: 'customContent',
12
- label: 'Custom Content',
13
- type: 'custom-content',
14
- default: {
15
- prefix: 'SALE',
16
- suffix: 'OFF',
17
- unit: 'percentage'
18
- }
19
- },
20
- {
21
- id: 'translate',
22
- type: 'input',
23
- default: 'customContent'
24
- }
25
- ]
26
- },
27
- {
28
- id: 'style',
29
- controls: [
30
- {
31
- id: 'size',
32
- type: 'size-setting',
33
- devices: {
34
- desktop: {
35
- default: {
36
- width: 'Auto',
37
- height: 'Auto',
38
- padding: {
39
- type: 'small',
40
- top: '4px',
41
- left: '16px',
42
- bottom: '4px',
43
- right: '16px'
44
- }
45
- }
46
- }
47
- },
48
- settingConfig: {
49
- width: {
50
- displayOptions: [
51
- 'full',
52
- 'auto',
53
- 'default'
54
- ]
55
- },
56
- padding: {
57
- paddingConfig: {
58
- small: {
59
- vertical: '4px',
60
- horizontal: '16px'
61
- },
62
- medium: {
63
- vertical: '8px',
64
- horizontal: '24px'
65
- },
66
- large: {
67
- vertical: '16px',
68
- horizontal: '32px'
69
- },
70
- custom: {
71
- vertical: '0px',
72
- horizontal: '0px'
73
- }
74
- }
75
- }
76
- },
77
- hiddenSettings: [
78
- 'shape',
79
- 'gap'
80
- ]
81
- },
82
- {
83
- id: 'textContentAlign',
84
- label: 'Alignment',
85
- type: 'segment',
86
- options: [
87
- {
88
- label: 'Left',
89
- value: 'left',
90
- type: 'text',
91
- tooltip: 'Align left'
92
- },
93
- {
94
- label: 'Center',
95
- value: 'center',
96
- type: 'text',
97
- tooltip: 'Align center'
98
- },
99
- {
100
- label: 'Right',
101
- value: 'right',
102
- type: 'text',
103
- tooltip: 'Align right'
104
- },
105
- {
106
- label: 'Justify',
107
- value: 'justify',
108
- type: 'text',
109
- tooltip: 'Align justify'
110
- }
111
- ],
112
- devices: {
113
- desktop: {
114
- default: 'center'
115
- }
116
- }
117
- },
118
- {
119
- id: 'backgroundColor',
120
- type: 'colorpicker',
121
- label: 'Background Color',
122
- default: '#3C67FF'
123
- },
124
- {
125
- id: 'borderTag',
126
- type: 'border',
127
- label: 'Border',
128
- default: {
129
- borderType: 'none',
130
- border: 'none',
131
- borderWidth: '1px',
132
- width: '1px 1px 1px 1px',
133
- color: '#000000',
134
- isCustom: false
135
- }
136
- },
137
- {
138
- id: 'roundedTag',
139
- type: 'radius-preset',
140
- label: 'Border Radius',
141
- default: {
142
- radiusType: 'large'
143
- }
144
- },
145
- {
146
- id: 'textAlign',
147
- label: 'Alignment',
148
- type: 'segment',
149
- options: [
150
- {
151
- label: 'Left',
152
- value: 'left',
153
- type: 'align',
154
- tooltip: 'Align left'
155
- },
156
- {
157
- label: 'Center',
158
- value: 'center',
159
- type: 'align',
160
- tooltip: 'Align center'
161
- },
162
- {
163
- label: 'Right',
164
- value: 'right',
165
- type: 'align',
166
- tooltip: 'Align right'
167
- }
168
- ],
169
- devices: {
170
- desktop: {
171
- default: 'left'
172
- }
173
- }
174
- },
175
- {
176
- id: 'typo',
177
- type: 'typography-v2',
178
- default: {
179
- type: 'subheading-2',
180
- attrs: {
181
- color: '#FFFFFF'
182
- }
183
- },
184
- ignoreReRender: true
185
- }
186
- ]
187
- }
188
- ],
189
- ui: [
190
- {
191
- type: 'group',
192
- controls: [
193
- {
194
- type: 'control',
195
- label: {
196
- en: 'Tag'
197
- },
198
- options: {
199
- label: 'large'
200
- },
201
- setting: {
202
- id: 'customContent'
203
- },
204
- layout: 'vertical'
205
- }
206
- ]
207
- },
208
- {
209
- type: 'group',
210
- label: {
211
- en: 'Size'
212
- },
213
- controls: [
214
- {
215
- type: 'control',
216
- setting: {
217
- id: 'size'
218
- },
219
- layout: 'vertical'
220
- }
221
- ]
222
- },
223
- {
224
- type: 'control',
225
- label: {
226
- en: 'Text align'
227
- },
228
- setting: {
229
- id: 'textContentAlign'
230
- }
231
- },
232
- {
233
- type: 'control',
234
- label: {
235
- en: 'Background color'
236
- },
237
- options: {
238
- label: 'large'
239
- },
240
- setting: {
241
- id: 'backgroundColor'
242
- }
243
- },
244
- {
245
- type: 'group',
246
- options: {
247
- labelPosition: 'start'
248
- },
249
- label: {
250
- en: 'Border'
251
- },
252
- controls: [
253
- {
254
- type: 'control',
255
- options: {
256
- labelPosition: 'start'
257
- },
258
- label: {
259
- en: 'Border'
260
- },
261
- setting: {
262
- id: 'borderTag'
263
- }
264
- },
265
- {
266
- type: 'control',
267
- label: {
268
- en: 'Corner'
269
- },
270
- setting: {
271
- id: 'roundedTag'
272
- }
273
- }
274
- ]
275
- },
276
- {
277
- type: 'group',
278
- label: {
279
- en: 'Text'
280
- },
281
- controls: [
282
- {
283
- type: 'control',
284
- setting: {
285
- id: 'typo'
286
- },
287
- layout: 'vertical'
288
- }
289
- ]
290
- },
291
- {
292
- type: 'control',
293
- label: {
294
- en: 'Align'
295
- },
296
- options: {
297
- label: 'large'
298
- },
299
- setting: {
300
- id: 'textAlign'
301
- }
302
- }
303
- ],
9
+ settings: ProductDiscountTagSettings,
10
+ ui: SettingUIV1,
11
+ uiV2: SettingUIV2,
304
12
  presets: [
305
13
  {
306
14
  id: 'product-tag',
@@ -127,6 +127,12 @@ const ProductBadgeSettings = [
127
127
  }
128
128
  ]
129
129
  },
130
+ {
131
+ id: 'contentBanner',
132
+ type: 'banner',
133
+ message: `{inventory_quantity} Only work with product enable “Track inventory”`,
134
+ closable: true
135
+ },
130
136
  {
131
137
  id: 'contentType',
132
138
  label: 'Shape',
@@ -93,6 +93,16 @@ const SettingUIV2 = [
93
93
  setting: {
94
94
  id: 'displayContent'
95
95
  }
96
+ },
97
+ {
98
+ label: {
99
+ en: ''
100
+ },
101
+ layout: 'vertical',
102
+ setting: {
103
+ id: 'contentBanner'
104
+ },
105
+ conditionDisplay: 'displayContent.includes("{inventory_quantity}")'
96
106
  }
97
107
  ]
98
108
  },
@@ -347,26 +357,10 @@ const SettingUIV2 = [
347
357
  },
348
358
  controls: [
349
359
  {
350
- id: 'badge-position',
351
- type: 'combo',
352
- iconName: 'polaris-plus',
353
- isHideClear: true,
354
- fixedValue: 'Edit',
355
- popoverLabel: {
356
- en: 'Position'
357
- },
358
- label: {
359
- en: 'Choose'
360
- },
361
360
  layout: 'vertical',
362
- controls: [
363
- {
364
- layout: 'vertical',
365
- setting: {
366
- id: 'position'
367
- }
368
- }
369
- ]
361
+ setting: {
362
+ id: 'position'
363
+ }
370
364
  }
371
365
  ],
372
366
  conditionDisplay: 'positionWithImage === "inside"'
@@ -389,6 +383,7 @@ const SettingUIV2 = [
389
383
  en: 'Align'
390
384
  },
391
385
  conditionEnable: '!(parseInt(textSizeV2) >= 100 && textSizeV2?.includes("%"))',
386
+ conditionDisplay: 'positionWithImage === "outside"',
392
387
  setting: {
393
388
  id: 'align'
394
389
  },
@@ -0,0 +1,189 @@
1
+ const ProductDiscountTagSettings = [
2
+ {
3
+ id: 'setting',
4
+ // note: 'Product Tag won’t display on live page if Compare at price field is empty or lower than Price.',
5
+ controls: [
6
+ {
7
+ id: 'customContent',
8
+ label: 'Custom Content',
9
+ type: 'custom-content',
10
+ default: {
11
+ prefix: 'SALE',
12
+ suffix: 'OFF',
13
+ unit: 'percentage'
14
+ }
15
+ },
16
+ {
17
+ id: 'translate',
18
+ type: 'input',
19
+ default: 'customContent'
20
+ }
21
+ ]
22
+ },
23
+ {
24
+ id: 'style',
25
+ controls: [
26
+ {
27
+ id: 'size',
28
+ type: 'size-setting',
29
+ devices: {
30
+ desktop: {
31
+ default: {
32
+ width: 'Auto',
33
+ height: 'Auto',
34
+ padding: {
35
+ type: 'small',
36
+ top: '4px',
37
+ left: '16px',
38
+ bottom: '4px',
39
+ right: '16px'
40
+ }
41
+ }
42
+ }
43
+ },
44
+ settingConfig: {
45
+ width: {
46
+ displayOptions: [
47
+ 'full',
48
+ 'auto',
49
+ 'default'
50
+ ]
51
+ },
52
+ padding: {
53
+ paddingConfig: {
54
+ small: {
55
+ vertical: '4px',
56
+ horizontal: '16px'
57
+ },
58
+ medium: {
59
+ vertical: '8px',
60
+ horizontal: '24px'
61
+ },
62
+ large: {
63
+ vertical: '16px',
64
+ horizontal: '32px'
65
+ },
66
+ custom: {
67
+ vertical: '0px',
68
+ horizontal: '0px'
69
+ }
70
+ }
71
+ }
72
+ },
73
+ hiddenSettings: [
74
+ 'shape',
75
+ 'gap'
76
+ ]
77
+ },
78
+ {
79
+ id: 'textContentAlign',
80
+ label: 'Alignment',
81
+ type: 'option:value',
82
+ options: [
83
+ {
84
+ label: 'Left',
85
+ value: 'left',
86
+ type: 'text',
87
+ tooltip: 'Align left'
88
+ },
89
+ {
90
+ label: 'Center',
91
+ value: 'center',
92
+ type: 'text',
93
+ tooltip: 'Align center'
94
+ },
95
+ {
96
+ label: 'Right',
97
+ value: 'right',
98
+ type: 'text',
99
+ tooltip: 'Align right'
100
+ },
101
+ {
102
+ label: 'Justify',
103
+ value: 'justify',
104
+ type: 'text',
105
+ tooltip: 'Align justify'
106
+ }
107
+ ],
108
+ devices: {
109
+ desktop: {
110
+ default: 'center'
111
+ }
112
+ }
113
+ },
114
+ {
115
+ id: 'backgroundColor',
116
+ type: 'color-picker-v2',
117
+ label: 'Background Color',
118
+ default: '#3C67FF'
119
+ },
120
+ {
121
+ id: 'borderTag',
122
+ type: 'border',
123
+ label: 'Border',
124
+ default: {
125
+ borderType: 'none',
126
+ border: 'none',
127
+ borderWidth: '1px',
128
+ width: '1px 1px 1px 1px',
129
+ color: '#000000',
130
+ isCustom: false
131
+ }
132
+ },
133
+ {
134
+ id: 'roundedTag',
135
+ type: 'radius-preset',
136
+ label: 'Border Radius',
137
+ default: {
138
+ radiusType: 'large'
139
+ }
140
+ },
141
+ {
142
+ id: 'textAlign',
143
+ label: 'Alignment',
144
+ type: 'option:value',
145
+ options: [
146
+ {
147
+ label: 'Left',
148
+ value: 'left',
149
+ type: 'align',
150
+ tooltip: 'Align left',
151
+ iconName: 'gp-align-left'
152
+ },
153
+ {
154
+ label: 'Center',
155
+ value: 'center',
156
+ type: 'align',
157
+ tooltip: 'Align center',
158
+ iconName: 'gp-align-center'
159
+ },
160
+ {
161
+ label: 'Right',
162
+ value: 'right',
163
+ type: 'align',
164
+ tooltip: 'Align right',
165
+ iconName: 'gp-align-right'
166
+ }
167
+ ],
168
+ devices: {
169
+ desktop: {
170
+ default: 'left'
171
+ }
172
+ }
173
+ },
174
+ {
175
+ id: 'typo',
176
+ type: 'typography-v2',
177
+ default: {
178
+ type: 'subheading-2',
179
+ attrs: {
180
+ color: '#FFFFFF'
181
+ }
182
+ },
183
+ ignoreReRender: true
184
+ }
185
+ ]
186
+ }
187
+ ];
188
+
189
+ export { ProductDiscountTagSettings };