@gem-sdk/components 2.0.0-dev.333 → 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.
Files changed (28) hide show
  1. package/dist/cjs/product/components/ProductBadge/common/getAttrs.js +74 -0
  2. package/dist/cjs/product/components/ProductBadge/common/getClasses.js +79 -0
  3. package/dist/cjs/product/components/ProductBadge/common/getStyles.js +144 -0
  4. package/dist/cjs/product/components/ProductBadge/constants.js +1 -9
  5. package/dist/cjs/product/components/ProductBadge/index.js +125 -117
  6. package/dist/cjs/product/components/ProductBadge/index.liquid.js +97 -111
  7. package/dist/cjs/product/components/ProductBadge/utils/common.js +11 -0
  8. package/dist/cjs/product/components/ProductBadge/utils/getRotateShape.js +10 -5
  9. package/dist/cjs/product/components/ProductBadge/utils/shape.js +14 -1
  10. package/dist/cjs/product/index.js +1 -1
  11. package/dist/cjs/product/setting/product-badge/configs/settings.js +72 -93
  12. package/dist/cjs/product/setting/product-badge/configs/uiV2.js +93 -15
  13. package/dist/esm/product/components/ProductBadge/common/getAttrs.js +67 -0
  14. package/dist/esm/product/components/ProductBadge/common/getClasses.js +70 -0
  15. package/dist/esm/product/components/ProductBadge/common/getStyles.js +137 -0
  16. package/dist/esm/product/components/ProductBadge/constants.js +2 -5
  17. package/dist/esm/product/components/ProductBadge/index.js +128 -120
  18. package/dist/esm/product/components/ProductBadge/index.liquid.js +99 -113
  19. package/dist/esm/product/components/ProductBadge/utils/common.js +12 -2
  20. package/dist/esm/product/components/ProductBadge/utils/getRotateShape.js +10 -5
  21. package/dist/esm/product/components/ProductBadge/utils/shape.js +14 -1
  22. package/dist/esm/product/index.js +1 -1
  23. package/dist/esm/product/setting/product-badge/configs/settings.js +72 -93
  24. package/dist/esm/product/setting/product-badge/configs/uiV2.js +93 -15
  25. package/dist/types/index.d.ts +1 -3
  26. package/package.json +2 -2
  27. package/dist/cjs/product/components/ProductBadge/hooks/useProductBadgeStyles.js +0 -83
  28. package/dist/esm/product/components/ProductBadge/hooks/useProductBadgeStyles.js +0 -81
@@ -3,14 +3,45 @@
3
3
  const SettingUIV2 = [
4
4
  {
5
5
  label: {
6
- en: 'Layout'
6
+ en: 'Style'
7
7
  },
8
8
  controls: [
9
9
  {
10
10
  setting: {
11
- id: 'contentType'
11
+ id: 'shape'
12
12
  },
13
- layout: 'vertical'
13
+ layout: 'vertical',
14
+ controlChangeTrigger: {
15
+ settings: [
16
+ {
17
+ condition: "shape.includes('image')",
18
+ source: [
19
+ 'shape'
20
+ ],
21
+ action: {
22
+ controlId: 'contentType',
23
+ newValue: 'image',
24
+ groupType: 'setting',
25
+ controlType: 'setting'
26
+ }
27
+ },
28
+ {
29
+ condition: "!shape.includes('image')",
30
+ source: [
31
+ 'shape'
32
+ ],
33
+ action: {
34
+ controlId: 'contentType',
35
+ newValue: 'text',
36
+ groupType: 'setting',
37
+ controlType: 'setting'
38
+ }
39
+ }
40
+ ],
41
+ options: {
42
+ noRecordHistory: true
43
+ }
44
+ }
14
45
  }
15
46
  ]
16
47
  },
@@ -39,12 +70,33 @@ const SettingUIV2 = [
39
70
  conditionDisplay: 'contentType === "text"',
40
71
  controls: [
41
72
  {
42
- id: 'displayContent',
73
+ id: 'content-badge',
74
+ type: 'combo',
75
+ iconName: 'polaris-plus',
76
+ isHideClear: true,
77
+ fixedValue: 'Edit',
78
+ popoverLabel: {
79
+ en: 'Content'
80
+ },
81
+ label: {
82
+ en: 'Content'
83
+ },
43
84
  setting: {
44
85
  id: 'displayContent'
45
86
  },
46
87
  layout: 'vertical',
47
- conditionDisplay: 'contentType == "text"'
88
+ conditionDisplay: 'contentType == "text"',
89
+ controls: [
90
+ {
91
+ label: {
92
+ en: 'Content'
93
+ },
94
+ layout: 'vertical',
95
+ setting: {
96
+ id: 'displayContent'
97
+ }
98
+ }
99
+ ]
48
100
  },
49
101
  {
50
102
  id: 'typo',
@@ -89,15 +141,6 @@ const SettingUIV2 = [
89
141
  },
90
142
  conditionDisplay: 'contentType == "text"',
91
143
  controls: [
92
- {
93
- label: {
94
- en: 'Shape'
95
- },
96
- setting: {
97
- id: 'shape'
98
- },
99
- conditionDisplay: 'contentType == "text"'
100
- },
101
144
  {
102
145
  label: {
103
146
  en: 'Color'
@@ -187,7 +230,7 @@ const SettingUIV2 = [
187
230
  {
188
231
  type: 'control',
189
232
  setting: {
190
- id: 'imageSize'
233
+ id: 'imageSizeV2'
191
234
  },
192
235
  layout: 'vertical'
193
236
  },
@@ -236,6 +279,11 @@ const SettingUIV2 = [
236
279
  label: 'Fit content',
237
280
  value: 'Auto',
238
281
  showValue: true
282
+ },
283
+ {
284
+ label: 'Default',
285
+ value: 'default',
286
+ showValue: true
239
287
  }
240
288
  ]
241
289
  },
@@ -285,6 +333,36 @@ const SettingUIV2 = [
285
333
  }
286
334
  ]
287
335
  },
336
+ {
337
+ label: {
338
+ en: 'Position'
339
+ },
340
+ controls: [
341
+ {
342
+ id: 'badge-position',
343
+ type: 'combo',
344
+ iconName: 'polaris-plus',
345
+ isHideClear: true,
346
+ fixedValue: 'Edit',
347
+ popoverLabel: {
348
+ en: 'Position'
349
+ },
350
+ label: {
351
+ en: 'Position'
352
+ },
353
+ layout: 'vertical',
354
+ controls: [
355
+ {
356
+ layout: 'vertical',
357
+ setting: {
358
+ id: 'position'
359
+ }
360
+ }
361
+ ]
362
+ }
363
+ ],
364
+ conditionDisplay: 'positionWithImage === "inside"'
365
+ },
288
366
  {
289
367
  controls: [
290
368
  {
@@ -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 { CONTENT_CLASS, IS_LIQUID, SHAPE_CLASS, SHAPE_ID, WRAPPER_CLASS };
14
+ export { SHAPE_ID };