@gem-sdk/components 2.0.0-dev.275 → 2.0.0-dev.278

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 (112) hide show
  1. package/dist/cjs/article/components/ArticleReadMore.js +2 -4
  2. package/dist/cjs/banner/components/HeroBannerItem.liquid.js +4 -4
  3. package/dist/cjs/builder.js +4 -8
  4. package/dist/cjs/button/components/Button.js +111 -184
  5. package/dist/cjs/button/components/Button.liquid.js +108 -171
  6. package/dist/cjs/button/components/ButtonIcon.js +17 -0
  7. package/dist/cjs/button/components/ButtonIcon.liquid.js +16 -0
  8. package/dist/cjs/button/components/ButtonLabel.js +18 -0
  9. package/dist/cjs/button/components/ButtonLabel.liquid.js +15 -0
  10. package/dist/cjs/button/components/ButtonLoadingIndicator.liquid.js +12 -0
  11. package/dist/cjs/button/components/common/attributes.js +15 -0
  12. package/dist/cjs/button/components/common/classes.js +55 -0
  13. package/dist/cjs/button/components/common/constants.js +26 -0
  14. package/dist/cjs/button/components/common/data.js +76 -0
  15. package/dist/cjs/button/components/common/helpers.js +131 -0
  16. package/dist/cjs/button/components/common/styles.js +157 -0
  17. package/dist/cjs/button/next.js +2 -6
  18. package/dist/cjs/button/setting/configs/settings.js +5 -1
  19. package/dist/cjs/cart/components/CheckoutNow.js +0 -2
  20. package/dist/cjs/coupon/components/Coupon.js +1 -3
  21. package/dist/cjs/dialog/setting/Dialog.js +7 -580
  22. package/dist/cjs/dialog/setting/configs/settings.js +325 -0
  23. package/dist/cjs/dialog/setting/configs/uiV1.js +288 -0
  24. package/dist/cjs/dialog/setting/configs/uiV2.js +258 -0
  25. package/dist/cjs/estimate-delivery/components/EstimateDate.liquid.js +3 -3
  26. package/dist/cjs/form/components/submit-button/SubmitButton.js +0 -4
  27. package/dist/cjs/index.js +2 -4
  28. package/dist/cjs/index.liquid.js +1 -3
  29. package/dist/cjs/post-purchase/callout-banner/components/CalloutText.js +1 -2
  30. package/dist/cjs/post-purchase/callout-banner/components/common/getClasses.js +2 -5
  31. package/dist/cjs/post-purchase/callout-banner/components/common/getStyles.js +4 -2
  32. package/dist/cjs/post-purchase/callout-banner/setting/config/callout-text/setting.js +11 -1
  33. package/dist/cjs/post-purchase/product/hooks/product-image/useListCarousel.js +1 -1
  34. package/dist/cjs/post-purchase/product/hooks/product-image/useProductImagePostPurchase.js +4 -1
  35. package/dist/cjs/post-purchase/product/settings/product-image/setting-v2.js +15 -2
  36. package/dist/cjs/post-purchase/product/settings/product-image/uiV2.js +3 -1
  37. package/dist/cjs/post-purchase/utils/constants.js +1 -1
  38. package/dist/cjs/product/components/DynamicCheckout/DynamicCheckout.js +2 -5
  39. package/dist/cjs/product/components/DynamicCheckout.js +2 -5
  40. package/dist/cjs/product/components/FileUpload/components/common/index.js +1 -1
  41. package/dist/cjs/product/components/ProductButton.js +2 -3
  42. package/dist/cjs/product/components/ProductButton.liquid.js +3 -3
  43. package/dist/cjs/product/components/ProductDescription/index.liquid.js +1 -2
  44. package/dist/cjs/product/components/ProductViewMore.js +2 -5
  45. package/dist/cjs/product/components/ProductViewMore.liquid.js +2 -2
  46. package/dist/cjs/setting.js +2 -2
  47. package/dist/cjs/text/components/common/getClasses.js +1 -1
  48. package/dist/cjs/third-party/components/PushOwl.js +0 -5
  49. package/dist/esm/article/components/ArticleReadMore.js +1 -3
  50. package/dist/esm/banner/components/HeroBannerItem.liquid.js +4 -4
  51. package/dist/esm/builder.js +1 -5
  52. package/dist/esm/button/components/Button.js +113 -186
  53. package/dist/esm/button/components/Button.liquid.js +109 -172
  54. package/dist/esm/button/components/ButtonIcon.js +13 -0
  55. package/dist/esm/button/components/ButtonIcon.liquid.js +12 -0
  56. package/dist/esm/button/components/ButtonLabel.js +14 -0
  57. package/dist/esm/button/components/ButtonLabel.liquid.js +11 -0
  58. package/dist/esm/button/components/ButtonLoadingIndicator.liquid.js +8 -0
  59. package/dist/esm/button/components/common/attributes.js +13 -0
  60. package/dist/esm/button/components/common/classes.js +49 -0
  61. package/dist/esm/button/components/common/constants.js +24 -0
  62. package/dist/esm/button/components/common/data.js +74 -0
  63. package/dist/esm/button/components/common/helpers.js +118 -0
  64. package/dist/esm/button/components/common/styles.js +148 -0
  65. package/dist/esm/button/next.js +2 -6
  66. package/dist/esm/button/setting/configs/settings.js +5 -1
  67. package/dist/esm/cart/components/CheckoutNow.js +0 -2
  68. package/dist/esm/coupon/components/Coupon.js +1 -3
  69. package/dist/esm/dialog/setting/Dialog.js +7 -580
  70. package/dist/esm/dialog/setting/configs/settings.js +323 -0
  71. package/dist/esm/dialog/setting/configs/uiV1.js +286 -0
  72. package/dist/esm/dialog/setting/configs/uiV2.js +256 -0
  73. package/dist/esm/estimate-delivery/components/EstimateDate.liquid.js +3 -3
  74. package/dist/esm/form/components/submit-button/SubmitButton.js +0 -4
  75. package/dist/esm/index.js +1 -2
  76. package/dist/esm/index.liquid.js +1 -2
  77. package/dist/esm/post-purchase/callout-banner/components/CalloutText.js +1 -2
  78. package/dist/esm/post-purchase/callout-banner/components/common/getClasses.js +2 -5
  79. package/dist/esm/post-purchase/callout-banner/components/common/getStyles.js +4 -2
  80. package/dist/esm/post-purchase/callout-banner/setting/config/callout-text/setting.js +11 -1
  81. package/dist/esm/post-purchase/product/hooks/product-image/useListCarousel.js +1 -1
  82. package/dist/esm/post-purchase/product/hooks/product-image/useProductImagePostPurchase.js +4 -1
  83. package/dist/esm/post-purchase/product/settings/product-image/setting-v2.js +15 -2
  84. package/dist/esm/post-purchase/product/settings/product-image/uiV2.js +3 -1
  85. package/dist/esm/post-purchase/utils/constants.js +1 -1
  86. package/dist/esm/product/components/DynamicCheckout/DynamicCheckout.js +1 -4
  87. package/dist/esm/product/components/DynamicCheckout.js +1 -4
  88. package/dist/esm/product/components/FileUpload/components/common/index.js +1 -1
  89. package/dist/esm/product/components/ProductButton.js +1 -2
  90. package/dist/esm/product/components/ProductButton.liquid.js +1 -1
  91. package/dist/esm/product/components/ProductDescription/index.liquid.js +3 -4
  92. package/dist/esm/product/components/ProductViewMore.js +1 -4
  93. package/dist/esm/product/components/ProductViewMore.liquid.js +1 -1
  94. package/dist/esm/setting.js +2 -2
  95. package/dist/esm/text/components/common/getClasses.js +1 -1
  96. package/dist/esm/third-party/components/PushOwl.js +0 -5
  97. package/dist/types/index.d.ts +175 -267
  98. package/package.json +2 -2
  99. package/dist/cjs/button/components/v2/ButtonIcon.js +0 -18
  100. package/dist/cjs/button/components/v2/ButtonLabel.js +0 -25
  101. package/dist/cjs/button/components/v2/ButtonV2.js +0 -140
  102. package/dist/cjs/button/components/v2/ButtonV2.liquid.js +0 -181
  103. package/dist/cjs/button/hooks/useButtonCustomCss.js +0 -88
  104. package/dist/cjs/button/hooks/useButtonStyles.js +0 -93
  105. package/dist/esm/button/components/v2/ButtonIcon.js +0 -14
  106. package/dist/esm/button/components/v2/ButtonLabel.js +0 -21
  107. package/dist/esm/button/components/v2/ButtonV2.js +0 -136
  108. package/dist/esm/button/components/v2/ButtonV2.liquid.js +0 -177
  109. package/dist/esm/button/hooks/useButtonCustomCss.js +0 -84
  110. package/dist/esm/button/hooks/useButtonStyles.js +0 -91
  111. /package/dist/cjs/button/components/{v2/ButtonLoadingIndicator.js → ButtonLoadingIndicator.js} +0 -0
  112. /package/dist/esm/button/components/{v2/ButtonLoadingIndicator.js → ButtonLoadingIndicator.js} +0 -0
@@ -1,182 +1,119 @@
1
- import { splitStyle, makeStyleResponsive, makeGlobalSize, composeTypographyClassName, composeTypographyStyle, composeBorderCss, composeCornerCss, getSingleColorVariable, template, cls, getGlobalColorStateClass, getGlobalColorStateStyle, composeRadius, getStyleShadowState, composeSize, getGradientBgrStyleForButton, RenderIf } from '@gem-sdk/core';
2
- import { getInsertLinkData, getDynamicSourceLocales } from '../../helpers.js';
1
+ import { template, dataStringify, isLocalEnv, baseAssetURL } from '@gem-sdk/core';
2
+ import { createStyle, createClass, createAttr, createStateOrContext, Liquid, If } from '@gem-sdk/system';
3
+ import { getButtonAttributes } from './common/attributes.js';
4
+ import { getButtonStyles, getButtonIconStyles, getButtonWrapperStyles } from './common/styles.js';
5
+ import { getButtonClasses, getButtonIconClasses, getButtonLabelClasses, getButtonWrapperClasses, getButtonContentWrapperClasses } from './common/classes.js';
6
+ import { getSettingPreloadData } from '../../helpers.js';
7
+ import ButtonIcon from './ButtonIcon.liquid.js';
8
+ import ButtonLabel from './ButtonLabel.liquid.js';
9
+ import ButtonLoadingIndicator from './ButtonLoadingIndicator.liquid.js';
10
+ import { getData } from './common/data.js';
11
+ import { getInsertLinkData, getButtonWrapper } from './common/helpers.js';
3
12
 
4
- const Button = ({ className, builderProps, customAttrs, pageContext, setting = {}, styles = {}, style, wrapClassName = '', advanced, nodePrice, dataId, isForceValue = false })=>{
5
- const { align, size, backgroundColor, textColor, roundedBtn, iconSpacing, globalSize } = styles;
6
- const { label, iconSvg, btnLink, htmlType, disabled, loading, iconAlign, iconVisible, translate, disabledLoading = true } = setting;
7
- const [wrapStyle, restStyle] = splitStyle([
8
- 'pos',
9
- 'top',
10
- 'left',
11
- 'bottom',
12
- 'right',
13
- 'z'
14
- ], style);
15
- const { Wrap, urlData, shouldRenderLink } = getInsertLinkData('button', btnLink, htmlType);
16
- const spacingDefault = {
17
- desktop: '8px'
18
- };
19
- const iconSpacingStyle = iconAlign === 'left' ? makeStyleResponsive('mr', iconSpacing || spacingDefault) : makeStyleResponsive('ml', iconSpacing || spacingDefault);
20
- // fix disabled still display hover color
21
- if (disabled) {
22
- delete backgroundColor?.hover;
23
- delete backgroundColor?.focus;
24
- }
25
- const composeGlobalSize = makeGlobalSize(globalSize);
26
- const appendTypoClass = composeTypographyClassName(styles?.typo, styles?.typography);
27
- const appendTypoStyle = composeTypographyStyle(styles?.typo, styles?.typography);
28
- delete appendTypoStyle['--c'];
29
- const innerBorderCss = `
30
- .${builderProps?.uid}.gp-button-base::before {
31
- content: "";
32
- height: 100%;
33
- width: 100%;
34
- position: absolute;
35
- pointer-events: none;
36
- ${composeBorderCss(styles?.borderBtn?.normal)}
37
- ${composeCornerCss(styles?.roundedBtn?.normal)}
38
- }
39
-
40
- .${builderProps?.uid}:hover::before {
41
- ${composeBorderCss(styles?.borderBtn?.hover)}
42
- ${composeCornerCss(styles?.roundedBtn?.hover)}
43
- }
44
-
45
- .${builderProps?.uid}:hover .gp-button-icon {
46
- color: ${getSingleColorVariable(styles?.textColor?.hover)};
47
- }
48
-
49
- .${builderProps?.uid} .gp-button-icon {
50
- color: ${getSingleColorVariable(styles?.textColor?.normal)};
51
- }
52
-
53
- .${builderProps?.uid}:hover .gp-button-price {
54
- color: ${getSingleColorVariable(styles?.textColor?.hover)};
55
- }
56
-
57
- .${builderProps?.uid} .gp-button-price {
58
- color: ${getSingleColorVariable(styles?.textColor?.normal)};
59
- }
60
-
61
- .${builderProps?.uid} .gp-product-dot-price {
62
- color: ${getSingleColorVariable(styles?.textColor?.normal)};
63
- }
64
-
65
- .${builderProps?.uid}:hover .gp-product-dot-price {
66
- color: ${getSingleColorVariable(styles?.textColor?.hover)};
67
- }
68
- `;
69
- const labelValDisplay = isForceValue ? label : getDynamicSourceLocales({
70
- val: label,
71
- uid: builderProps?.uidTranslate ?? builderProps?.uid,
72
- settingId: translate ?? 'label',
73
- pageContext,
74
- isCapitalize: styles?.typo?.attrs?.transform === 'capitalize',
75
- translate
13
+ const Button = (props)=>{
14
+ const { advanced, className, nodePrice, customAttrs, styles = {}, setting = {}, builderProps, wrapClassName = '' } = props;
15
+ const { iconSvg, loading, btnLink, htmlType, disabled, shouldClearSpace } = setting;
16
+ const { customCss, wrapStyle, restStyle, dataState, dataIdAttr, isShowIcon, isScrollToElement, getArialLabel, getLabelToDisplay, checkIsShowLabel, checkIsEditableLabel } = getData(props);
17
+ const { HTMLTag, urlData, shouldRenderLink } = getInsertLinkData({
18
+ htmlType,
19
+ setting: btnLink,
20
+ defaultTag: 'button',
21
+ isLiquid: true
22
+ });
23
+ const ButtonWrapper = getButtonWrapper(HTMLTag, isScrollToElement);
24
+ const buttonStyles = createStyle({
25
+ ...getButtonStyles(styles, nodePrice)
26
+ });
27
+ const buttonIconStyles = createStyle({
28
+ ...getButtonIconStyles(styles, setting)
29
+ });
30
+ const buttonWrapperStyles = createStyle({
31
+ ...getButtonWrapperStyles(restStyle, styles)
32
+ });
33
+ const buttonClasses = createClass({
34
+ ...getButtonClasses({
35
+ styles,
36
+ className,
37
+ shouldRenderLink,
38
+ uid: builderProps?.uid
39
+ })
40
+ });
41
+ const buttonIconClasses = createClass({
42
+ ...getButtonIconClasses(getLabelToDisplay({
43
+ isLiquid: true
44
+ }), shouldClearSpace)
76
45
  });
77
- return template`
78
- <gp-button style="${{
79
- ...wrapStyle
80
- }}">
81
- <div
82
- style="${{
83
- ...restStyle,
84
- ...makeStyleResponsive('ta', align)
85
- }}"
86
- class="${cls(wrapClassName, className?.includes('gp-button-atc') ? '' : advanced?.cssClass)}"
87
- >
88
- <style>${innerBorderCss}</style>
89
- <${Wrap}
90
- ${{
91
- ...urlData,
92
- 'data-id': builderProps?.uidInteraction ?? (dataId || builderProps?.uid),
93
- 'aria-label': setting?.label?.toString().replaceAll("'", '&#039;').replaceAll('"', "'"),
94
- ...disabled && typeof disabled === 'boolean' || disabled ? {
95
- disabled: 'disabled'
96
- } : {}
46
+ const buttonLabelClasses = createClass({
47
+ ...getButtonLabelClasses(styles, checkIsEditableLabel({
48
+ isLiquid: true
49
+ }))
50
+ });
51
+ const buttonWrapperClasses = createClass({
52
+ ...getButtonWrapperClasses(wrapClassName, className, advanced?.cssClass)
53
+ });
54
+ const buttonContentWrapperClasses = createClass({
55
+ ...getButtonContentWrapperClasses(setting)
56
+ });
57
+ const buttonWrapperAttrs = createAttr({
58
+ ...getButtonAttributes({
59
+ urlData,
60
+ disabled,
61
+ dataState,
62
+ dataId: dataIdAttr,
63
+ arialLabel: getArialLabel({
64
+ isLiquid: true
65
+ })
66
+ })
67
+ });
68
+ const buttonState = createStateOrContext({
69
+ btnLink: setting?.btnLink
70
+ });
71
+ return Liquid(template`
72
+ <gp-button
73
+ gp-data='${dataStringify(buttonState)}'
74
+ style="${{
75
+ wrapStyle
76
+ }}"
77
+ >
78
+ <div style="${buttonWrapperStyles}" class="${buttonWrapperClasses}">
79
+ <style>${customCss}</style>
80
+ ${If(isScrollToElement, `<a
81
+ class="gp-trigger-button-link gp-hidden"
82
+ href=${urlData.href}
83
+ target=${urlData.target}
84
+ ></a>`)}
85
+ <${ButtonWrapper}
86
+ ${{
87
+ ...buttonWrapperAttrs
97
88
  }}
98
- ${{
89
+ ${{
99
90
  ...customAttrs
100
91
  }}
101
- data-state="${loading ? 'loading' : 'idle'}"
102
- class="${cls(builderProps?.uid, 'gp-button-base gp-rounded-none gp-max-w-full gp-relative gp-group gp-inline-flex gp-items-center gp-justify-center gp-no-underline gp-transition-colors gp-duration-300 disabled:gp-btn-disabled disabled:gp-opacity-30 disabled:gp-pointer-events-none', getGlobalColorStateClass('bg', backgroundColor), getGlobalColorStateClass('text', textColor), {
103
- 'gp-animate-bounce': styles?.animation?.normal === 'bounce',
104
- 'hover:gp-animate-bounce': styles?.animation?.hover === 'bounce',
105
- 'gp-scale-[1.1]': styles?.animation?.normal === 'grow',
106
- 'hover:gp-scale-[1.1]': styles?.animation?.hover === 'grow',
107
- 'gp-text-center': shouldRenderLink
108
- }, className, className?.includes('gp-button-atc') && advanced ? advanced?.cssClass : '', !nodePrice ? appendTypoClass : {})}"
109
- style="${{
110
- ...getGlobalColorStateStyle('bg', backgroundColor),
111
- ...composeRadius(roundedBtn),
112
- ...getStyleShadowState(styles?.boxShadowBtn, 'box-shadow', {
113
- normal: styles?.boxShadowBtn?.normal?.type !== 'none',
114
- hover: styles?.boxShadowBtn?.hover?.type !== 'none'
115
- }),
116
- ...!styles?.btnSpacing?.type ? composeSize(styles?.btnSpacing?.custom) : {},
117
- ...composeGlobalSize.width,
118
- ...composeGlobalSize.height,
119
- ...composeGlobalSize.padding,
120
- ...getGradientBgrStyleForButton(backgroundColor),
121
- ...getGlobalColorStateStyle('c', textColor),
122
- '--size': appendTypoStyle['--size'],
123
- '--size-tablet': appendTypoStyle['--size-tablet'],
124
- '--size-mobile': appendTypoStyle['--size-mobile'],
125
- ...!nodePrice ? appendTypoStyle : {}
126
- }}"
127
- >
128
- ${!disabledLoading ? ` <svg
129
- class="gp-invisible gp-absolute gp-h-5 gp-w-5 group-data-[state=loading]:gp-animate-spin group-data-[state=loading]:gp-visible"
130
- xmlns="http://www.w3.org/2000/svg"
131
- fill="none"
132
- viewBox="0 0 24 24"
92
+ style="${buttonStyles}"
93
+ class="${buttonClasses}"
133
94
  >
134
- <circle
135
- class="gp-opacity-25"
136
- cx="12"
137
- cy="12"
138
- r="10"
139
- stroke="currentColor"
140
- stroke-width="4"
141
- ></circle>
142
- <path
143
- class="gp-opacity-75"
144
- fill="currentColor"
145
- d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
146
- ></path>
147
- </svg>` : ''}
148
- <div
149
- class="${cls('gp-inline-flex', {
150
- 'gp-flex-row-reverse': iconAlign === 'right'
151
- })}">
152
- ${RenderIf(!!iconSvg && iconVisible, template`<span
153
- class="${`gp-inline-flex gp-button-icon gp-transition-colors gp-duration-300 gp-shrink-0 gp-items-center gp-justify-center group-data-[state=loading]:gp-invisible gp-z-1 [&>svg]:!gp-h-[var(--height-desktop)] [&>svg]:!gp-w-auto tablet:[&>svg]:!gp-h-[var(--height-tablet)] mobile:[&>svg]:!gp-h-[var(--height-mobile)]`}"
154
- style="${{
155
- ...label ? iconSpacingStyle : {},
156
- '--height-desktop': `${size?.desktop}`,
157
- '--height-tablet': `${size?.desktop ?? size?.tablet}`,
158
- '--height-mobile': `${size?.mobile ?? size?.tablet ?? size?.desktop}`
159
- }}"
160
- >${iconSvg}</span>`)}
161
- <span
162
- data-gp-text
163
- class="${`gp-content-product-button gp-button-text-only gp-break-words group-data-[state=loading]:gp-invisible [&_p]:gp-whitespace-pre-line gp-z-1 gp-h-full gp-flex gp-items-center gp-overflow-hidden ${nodePrice ? appendTypoClass : ''}
164
- ${styles?.typo?.attrs?.italic ? '[&:not(:has(p))]:gp-pr-[0.2em] [&_p]:[&:has(p)]:gp-pr-[0.2em]' : ''}`}"
165
- style="${{
166
- ...nodePrice && appendTypoStyle,
167
- '--size': appendTypoStyle['--size'],
168
- '--size-tablet': appendTypoStyle['--size-tablet'],
169
- '--size-mobile': appendTypoStyle['--size-mobile']
170
- }}"
171
- >
172
- ${labelValDisplay}
173
- </span>
95
+ ${If(loading, ButtonLoadingIndicator, '')}
96
+ <div class="${buttonContentWrapperClasses}">
97
+ ${If(isShowIcon, ButtonIcon({
98
+ iconSvg: iconSvg ?? '',
99
+ styles: buttonIconStyles,
100
+ classes: buttonIconClasses
101
+ }))}
102
+ ${If(checkIsShowLabel({
103
+ isLiquid: true
104
+ }), ButtonLabel({
105
+ label: getLabelToDisplay({
106
+ isLiquid: true
107
+ }),
108
+ classes: buttonLabelClasses
109
+ }))}
110
+ </div>
111
+ ${If(!!nodePrice, nodePrice?.toString() ?? '', '')}
112
+ </${ButtonWrapper}>
174
113
  </div>
175
- ${nodePrice ? nodePrice : ''}
176
- </${Wrap}>
177
- </div>
178
- </gp-button>
179
- `;
114
+ ${If(isLocalEnv, `<script ${getSettingPreloadData('class="gps-link" delay', 'src')}="{{ 'gp-button.js' | asset_url }}" defer="defer"></script>`, `<script ${getSettingPreloadData('class="gps-link" delay', 'src')}="${baseAssetURL}/assets-v2/gp-button.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}" defer="defer"></script>`)}
115
+ </gp-button>
116
+ `);
180
117
  };
181
118
 
182
119
  export { Button as default };
@@ -0,0 +1,13 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+
3
+ const ButtonIcon = ({ iconSvg, classes, styles })=>{
4
+ return /*#__PURE__*/ jsx("span", {
5
+ className: classes,
6
+ style: styles,
7
+ dangerouslySetInnerHTML: {
8
+ __html: iconSvg
9
+ }
10
+ });
11
+ };
12
+
13
+ export { ButtonIcon as default };
@@ -0,0 +1,12 @@
1
+ const ButtonIcon = ({ iconSvg, classes, styles })=>{
2
+ return `
3
+ <span
4
+ style="${styles}"
5
+ class="${classes}"
6
+ >
7
+ ${iconSvg}
8
+ </span>
9
+ `;
10
+ };
11
+
12
+ export { ButtonIcon as default };
@@ -0,0 +1,14 @@
1
+ import { jsx } from 'react/jsx-runtime';
2
+ import 'react';
3
+
4
+ const ButtonLabel = ({ label, classes })=>{
5
+ return /*#__PURE__*/ jsx("div", {
6
+ "data-gp-text": true,
7
+ className: classes,
8
+ dangerouslySetInnerHTML: {
9
+ __html: label
10
+ }
11
+ });
12
+ };
13
+
14
+ export { ButtonLabel as default };
@@ -0,0 +1,11 @@
1
+ const ButtonLabel = ({ label, classes })=>{
2
+ return `
3
+ <span
4
+ data-gp-text
5
+ class="${classes}"
6
+ >
7
+ ${label}
8
+ </span>`;
9
+ };
10
+
11
+ export { ButtonLabel as default };
@@ -0,0 +1,8 @@
1
+ import { template } from '@gem-sdk/core';
2
+ import { LOADING_INDICATOR } from './common/constants.js';
3
+
4
+ const ButtonLoadingIndicator = ()=>{
5
+ return template`${LOADING_INDICATOR}`;
6
+ };
7
+
8
+ export { ButtonLoadingIndicator as default };
@@ -0,0 +1,13 @@
1
+ const getButtonAttributes = ({ dataId, disabled, urlData, dataState, arialLabel })=>{
2
+ return {
3
+ ...urlData,
4
+ ...disabled !== undefined && {
5
+ disabled: disabled
6
+ },
7
+ 'data-id': dataId,
8
+ 'data-state': dataState,
9
+ 'aria-label': arialLabel
10
+ };
11
+ };
12
+
13
+ export { getButtonAttributes };
@@ -0,0 +1,49 @@
1
+ import { getGlobalColorStateClass } from '@gem-sdk/core';
2
+
3
+ const getButtonClasses = ({ uid, styles, className, shouldRenderLink })=>{
4
+ return {
5
+ ...className && {
6
+ [className]: true
7
+ },
8
+ ...uid && {
9
+ [uid]: true
10
+ },
11
+ 'gp-text-center': shouldRenderLink,
12
+ 'gp-max-w-full': styles?.textOverFlow || false,
13
+ 'gp-scale-[1.1]': styles?.animation?.normal === 'grow',
14
+ 'gp-animate-bounce': styles?.animation?.normal === 'bounce',
15
+ 'hover:gp-scale-[1.1]': styles?.animation?.hover === 'grow',
16
+ 'hover:gp-animate-bounce': styles?.animation?.hover === 'bounce',
17
+ 'gp-button-base gp-group gp-relative gp-inline-flex gp-max-w-full gp-items-center gp-justify-center gp-no-underline gp-transition-colors gp-duration-300 disabled:gp-btn-disabled disabled:gp-opacity-30': true,
18
+ [getGlobalColorStateClass('text', styles?.textColor)]: true
19
+ };
20
+ };
21
+ const getButtonWrapperClasses = (wrapClassName, className, advancedCssClass)=>{
22
+ return {
23
+ [wrapClassName]: true,
24
+ ...className?.includes('gp-button-atc') && advancedCssClass && {
25
+ [advancedCssClass]: true
26
+ }
27
+ };
28
+ };
29
+ const getButtonContentWrapperClasses = (setting)=>{
30
+ return {
31
+ 'gp-inline-flex': true,
32
+ 'gp-flex-row-reverse': setting?.iconAlign === 'right'
33
+ };
34
+ };
35
+ const getButtonLabelClasses = (styles, isEditable)=>{
36
+ return {
37
+ 'gp-relative gp-flex gp-h-full gp-items-center gp-overflow-hidden gp-break-words group-data-[state=loading]:gp-invisible [&_p]:gp-whitespace-pre-line': true,
38
+ '[&:not(:has(p))]:gp-pr-[0.2em] [&_p]:[&:has(p)]:gp-pr-[0.2em]': styles?.typo?.attrs?.italic,
39
+ 'gp-text button-text': isEditable
40
+ };
41
+ };
42
+ const getButtonIconClasses = (label, shouldClearSpace)=>{
43
+ return {
44
+ '!gp-m-0': shouldClearSpace && !label,
45
+ 'gp-button-icon gp-transition-colors gp-duration-300 gp-z-1 gp-inline-flex gp-shrink-0 gp-items-center gp-justify-center group-data-[state=loading]:gp-invisible [&>svg]:!gp-h-[var(--height-desktop)] [&>svg]:!gp-w-auto tablet:[&>svg]:!gp-h-[var(--height-tablet)] mobile:[&>svg]:!gp-h-[var(--height-mobile)]': true
46
+ };
47
+ };
48
+
49
+ export { getButtonClasses, getButtonContentWrapperClasses, getButtonIconClasses, getButtonLabelClasses, getButtonWrapperClasses };
@@ -0,0 +1,24 @@
1
+ const LOADING_INDICATOR = `
2
+ <svg
3
+ class="gp-invisible gp-absolute gp-h-5 gp-w-5 group-data-[state=loading]:gp-animate-spin group-data-[state=loading]:gp-visible"
4
+ xmlns="http://www.w3.org/2000/svg"
5
+ fill="none"
6
+ viewBox="0 0 24 24"
7
+ >
8
+ <circle
9
+ class="gp-opacity-25"
10
+ cx="12"
11
+ cy="12"
12
+ r="10"
13
+ stroke="currentColor"
14
+ stroke-width="4"
15
+ ></circle>
16
+ <path
17
+ class="gp-opacity-75"
18
+ fill="currentColor"
19
+ d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
20
+ ></path>
21
+ </svg>
22
+ `;
23
+
24
+ export { LOADING_INDICATOR };
@@ -0,0 +1,74 @@
1
+ import { getSplitStyles, getCleanedStyles, checkIsScrollToElement, getDataState, getDataId, handleGetArialLabel, handleGetLabelToDisplay, handleCheckIsShowLabel, handleCheckIsEditableLabel, checkIsShowIcon } from './helpers.js';
2
+ import { getCustomCssStyles } from './styles.js';
3
+
4
+ const getData = (props)=>{
5
+ const { style, dataId, pageContext, styles = {}, setting = {}, builderProps, isForceValue = false } = props;
6
+ const { label, iconSvg, btnLink, loading, options, disabled, translate, iconVisible, shouldClearSpace } = setting;
7
+ const [wrapStyle, restStyle] = getSplitStyles(style);
8
+ const cleanedStyles = getCleanedStyles(styles, disabled);
9
+ const customCss = getCustomCssStyles({
10
+ styles,
11
+ uid: builderProps?.uid
12
+ });
13
+ const dataState = getDataState(loading);
14
+ const dataIdAttr = getDataId(builderProps?.uidInteraction, dataId, builderProps?.uid);
15
+ const getArialLabel = (props)=>{
16
+ const { isLiquid } = props ?? {};
17
+ return handleGetArialLabel({
18
+ label,
19
+ isLiquid
20
+ });
21
+ };
22
+ const getLabelToDisplay = (props)=>{
23
+ const { isLiquid } = props ?? {};
24
+ return handleGetLabelToDisplay({
25
+ label,
26
+ builderProps,
27
+ styles: cleanedStyles,
28
+ isLiquid,
29
+ ...isLiquid && {
30
+ translate
31
+ },
32
+ ...isLiquid && {
33
+ pageContext
34
+ },
35
+ ...isLiquid && {
36
+ isForceValue
37
+ }
38
+ });
39
+ };
40
+ const checkIsShowLabel = (props)=>{
41
+ const { isLiquid } = props ?? {};
42
+ const labelToDisplay = getLabelToDisplay({
43
+ isLiquid
44
+ });
45
+ return handleCheckIsShowLabel(labelToDisplay, shouldClearSpace);
46
+ };
47
+ const checkIsEditableLabel = (props)=>{
48
+ const { isLiquid, mode } = props ?? {};
49
+ return handleCheckIsEditableLabel({
50
+ options,
51
+ isLiquid,
52
+ ...!isLiquid && mode && {
53
+ mode
54
+ }
55
+ });
56
+ };
57
+ const isShowIcon = checkIsShowIcon(iconSvg, iconVisible);
58
+ const isScrollToElement = checkIsScrollToElement(btnLink);
59
+ return {
60
+ customCss,
61
+ wrapStyle,
62
+ restStyle,
63
+ dataState,
64
+ dataIdAttr,
65
+ isShowIcon,
66
+ isScrollToElement,
67
+ getArialLabel,
68
+ getLabelToDisplay,
69
+ checkIsShowLabel,
70
+ checkIsEditableLabel
71
+ };
72
+ };
73
+
74
+ export { getData };
@@ -0,0 +1,118 @@
1
+ import { splitStyle, convertHTML } from '@gem-sdk/core';
2
+ import { getDynamicSourceLocales } from '../../../helpers.js';
3
+ import Link from '../../../link/components/Link.js';
4
+
5
+ const getCleanedStyles = (styles, disabled)=>{
6
+ if (!disabled) return styles;
7
+ const cleanedStyles = {
8
+ ...styles
9
+ };
10
+ const states = [
11
+ 'hover',
12
+ 'focus'
13
+ ];
14
+ const devices = [
15
+ 'tablet',
16
+ 'mobile',
17
+ 'desktop'
18
+ ];
19
+ devices.forEach((device)=>{
20
+ states.forEach((state)=>{
21
+ delete cleanedStyles?.backgroundColorV2?.[device]?.[state];
22
+ });
23
+ });
24
+ return cleanedStyles;
25
+ };
26
+ const handleGetLabelToDisplay = ({ label, styles, translate, pageContext, isForceValue, builderProps, isLiquid = false })=>{
27
+ const liquidLabel = isForceValue ? label : getDynamicSourceLocales({
28
+ translate,
29
+ val: label,
30
+ pageContext,
31
+ settingId: translate ?? 'label',
32
+ uid: builderProps?.uidTranslate ?? builderProps?.uid,
33
+ isCapitalize: styles?.typo?.attrs?.transform === 'capitalize'
34
+ });
35
+ return isLiquid ? liquidLabel?.toString() ?? '' : convertHTML(label);
36
+ };
37
+ const checkIsShowIcon = (iconSvg, iconVisible)=>{
38
+ return !!iconSvg && iconVisible;
39
+ };
40
+ const handleCheckIsShowLabel = (labelToDisplay, shouldClearSpace)=>{
41
+ return !!labelToDisplay || !shouldClearSpace;
42
+ };
43
+ const handleCheckIsEditableLabel = ({ mode, options, isLiquid = false })=>{
44
+ return isLiquid ? !options?.isCannotEditing : mode === 'edit' && !options?.isCannotEditing;
45
+ };
46
+ const checkIsScrollToElement = (btnLink)=>{
47
+ return btnLink?.link?.startsWith('#') && btnLink?.target === '_self';
48
+ };
49
+ const getButtonWrapper = (Wrap, isScrollToElement)=>{
50
+ return isScrollToElement ? 'button' : Wrap;
51
+ };
52
+ const getSplitStyles = (style)=>{
53
+ return splitStyle([
54
+ 'pos',
55
+ 'top',
56
+ 'left',
57
+ 'bottom',
58
+ 'right',
59
+ 'z'
60
+ ], style);
61
+ };
62
+ const getDataState = (isLoading)=>{
63
+ return isLoading ? 'loading' : 'idle';
64
+ };
65
+ const getDataId = (uidInteraction, dataId, uid)=>{
66
+ return uidInteraction ?? (dataId || uid) ?? '';
67
+ };
68
+ const handleGetArialLabel = ({ label, isLiquid = false })=>{
69
+ return isLiquid ? label?.toString().replaceAll("'", '&#039;').replaceAll('"', "'") ?? '' : label?.toString() ?? '';
70
+ };
71
+ const getInsertLinkData = ({ setting, htmlType, defaultTag, isLiquid = false })=>{
72
+ const URL_INCLUDES = [
73
+ 'product.url'
74
+ ];
75
+ const URL_START_WITH = [
76
+ '#',
77
+ 'mailto:',
78
+ 'tel:'
79
+ ];
80
+ const urlHref = setting?.link ?? '';
81
+ const isHomePageHref = urlHref === '/';
82
+ const isHyperlink = setting?.link !== undefined && setting.link !== '';
83
+ const regexHttp = new RegExp(/^https?:\/\//i);
84
+ const isDomain = isHyperlink && regexHttp.test(urlHref);
85
+ const regexPageType = new RegExp(/^\/?(?:collections|pages|products|blogs|checkout|cart)\/?/i);
86
+ const isShopifyDomain = isHyperlink && !regexHttp.test(urlHref) && regexPageType.test(urlHref);
87
+ const isLink = ()=>{
88
+ if (URL_INCLUDES.find((el)=>urlHref.includes(el))) return true;
89
+ if (URL_START_WITH.find((el)=>urlHref.startsWith(el))) return true;
90
+ return false;
91
+ };
92
+ const shouldRenderLink = isDomain || isShopifyDomain || isLink() || isHomePageHref;
93
+ let transformedUrl = urlHref;
94
+ if (isLiquid && (isShopifyDomain || isHomePageHref)) {
95
+ transformedUrl = setting?.isTranslate ? '$locationOrigin' + urlHref : "{{ request.origin }}{{ routes.root_url | split: '/' | join: '/' }}" + urlHref;
96
+ }
97
+ const HTMLTag = shouldRenderLink ? isLiquid ? 'a' : Link : defaultTag;
98
+ const baseUrlData = {
99
+ href: transformedUrl,
100
+ target: setting?.target,
101
+ ...setting?.noFollow && {
102
+ rel: 'nofollow'
103
+ }
104
+ };
105
+ const urlData = shouldRenderLink ? baseUrlData : isHyperlink ? {
106
+ ...baseUrlData,
107
+ type: htmlType
108
+ } : {
109
+ type: htmlType
110
+ };
111
+ return {
112
+ HTMLTag,
113
+ urlData,
114
+ shouldRenderLink
115
+ };
116
+ };
117
+
118
+ export { checkIsScrollToElement, checkIsShowIcon, getButtonWrapper, getCleanedStyles, getDataId, getDataState, getInsertLinkData, getSplitStyles, handleCheckIsEditableLabel, handleCheckIsShowLabel, handleGetArialLabel, handleGetLabelToDisplay };