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

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 (94) 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/product/components/DynamicCheckout/DynamicCheckout.js +2 -5
  30. package/dist/cjs/product/components/DynamicCheckout.js +2 -5
  31. package/dist/cjs/product/components/FileUpload/components/common/index.js +1 -1
  32. package/dist/cjs/product/components/ProductButton.js +2 -3
  33. package/dist/cjs/product/components/ProductButton.liquid.js +3 -3
  34. package/dist/cjs/product/components/ProductDescription/index.liquid.js +1 -2
  35. package/dist/cjs/product/components/ProductViewMore.js +2 -5
  36. package/dist/cjs/product/components/ProductViewMore.liquid.js +2 -2
  37. package/dist/cjs/setting.js +2 -2
  38. package/dist/cjs/text/components/common/getClasses.js +1 -1
  39. package/dist/cjs/third-party/components/PushOwl.js +0 -5
  40. package/dist/esm/article/components/ArticleReadMore.js +1 -3
  41. package/dist/esm/banner/components/HeroBannerItem.liquid.js +4 -4
  42. package/dist/esm/builder.js +1 -5
  43. package/dist/esm/button/components/Button.js +113 -186
  44. package/dist/esm/button/components/Button.liquid.js +109 -172
  45. package/dist/esm/button/components/ButtonIcon.js +13 -0
  46. package/dist/esm/button/components/ButtonIcon.liquid.js +12 -0
  47. package/dist/esm/button/components/ButtonLabel.js +14 -0
  48. package/dist/esm/button/components/ButtonLabel.liquid.js +11 -0
  49. package/dist/esm/button/components/ButtonLoadingIndicator.liquid.js +8 -0
  50. package/dist/esm/button/components/common/attributes.js +13 -0
  51. package/dist/esm/button/components/common/classes.js +49 -0
  52. package/dist/esm/button/components/common/constants.js +24 -0
  53. package/dist/esm/button/components/common/data.js +74 -0
  54. package/dist/esm/button/components/common/helpers.js +118 -0
  55. package/dist/esm/button/components/common/styles.js +148 -0
  56. package/dist/esm/button/next.js +2 -6
  57. package/dist/esm/button/setting/configs/settings.js +5 -1
  58. package/dist/esm/cart/components/CheckoutNow.js +0 -2
  59. package/dist/esm/coupon/components/Coupon.js +1 -3
  60. package/dist/esm/dialog/setting/Dialog.js +7 -580
  61. package/dist/esm/dialog/setting/configs/settings.js +323 -0
  62. package/dist/esm/dialog/setting/configs/uiV1.js +286 -0
  63. package/dist/esm/dialog/setting/configs/uiV2.js +256 -0
  64. package/dist/esm/estimate-delivery/components/EstimateDate.liquid.js +3 -3
  65. package/dist/esm/form/components/submit-button/SubmitButton.js +0 -4
  66. package/dist/esm/index.js +1 -2
  67. package/dist/esm/index.liquid.js +1 -2
  68. package/dist/esm/product/components/DynamicCheckout/DynamicCheckout.js +1 -4
  69. package/dist/esm/product/components/DynamicCheckout.js +1 -4
  70. package/dist/esm/product/components/FileUpload/components/common/index.js +1 -1
  71. package/dist/esm/product/components/ProductButton.js +1 -2
  72. package/dist/esm/product/components/ProductButton.liquid.js +1 -1
  73. package/dist/esm/product/components/ProductDescription/index.liquid.js +3 -4
  74. package/dist/esm/product/components/ProductViewMore.js +1 -4
  75. package/dist/esm/product/components/ProductViewMore.liquid.js +1 -1
  76. package/dist/esm/setting.js +2 -2
  77. package/dist/esm/text/components/common/getClasses.js +1 -1
  78. package/dist/esm/third-party/components/PushOwl.js +0 -5
  79. package/dist/types/index.d.ts +174 -266
  80. package/package.json +2 -2
  81. package/dist/cjs/button/components/v2/ButtonIcon.js +0 -18
  82. package/dist/cjs/button/components/v2/ButtonLabel.js +0 -25
  83. package/dist/cjs/button/components/v2/ButtonV2.js +0 -140
  84. package/dist/cjs/button/components/v2/ButtonV2.liquid.js +0 -181
  85. package/dist/cjs/button/hooks/useButtonCustomCss.js +0 -88
  86. package/dist/cjs/button/hooks/useButtonStyles.js +0 -93
  87. package/dist/esm/button/components/v2/ButtonIcon.js +0 -14
  88. package/dist/esm/button/components/v2/ButtonLabel.js +0 -21
  89. package/dist/esm/button/components/v2/ButtonV2.js +0 -136
  90. package/dist/esm/button/components/v2/ButtonV2.liquid.js +0 -177
  91. package/dist/esm/button/hooks/useButtonCustomCss.js +0 -84
  92. package/dist/esm/button/hooks/useButtonStyles.js +0 -91
  93. /package/dist/cjs/button/components/{v2/ButtonLoadingIndicator.js → ButtonLoadingIndicator.js} +0 -0
  94. /package/dist/esm/button/components/{v2/ButtonLoadingIndicator.js → ButtonLoadingIndicator.js} +0 -0
@@ -1,192 +1,119 @@
1
1
  'use client';
2
- import { jsxs, jsx } from 'react/jsx-runtime';
3
- import { convertHTML, makeStyleResponsive, useEditorMode, makeGlobalSize, composeTypographyClassName, composeTypographyStyle, composeBorderCss, composeCornerCss, getSingleColorVariable, globalEvent, cls, getGlobalColorStateClass, getGlobalColorStateStyle, composeRadius, getStyleShadowState, getGradientBgrStyleForButton, makeStyle } from '@gem-sdk/core';
4
- import Link from 'next/link';
5
- import { useMemo } from 'react';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+ import { useEditorMode, globalEvent } from '@gem-sdk/core';
4
+ import { createStyle, createClass, createAttr, If } from '@gem-sdk/system';
5
+ import { getButtonAttributes } from './common/attributes.js';
6
+ import { getButtonStyles, getButtonIconStyles, getButtonWrapperStyles } from './common/styles.js';
7
+ import { getButtonClasses, getButtonIconClasses, getButtonLabelClasses, getButtonWrapperClasses, getButtonContentWrapperClasses } from './common/classes.js';
8
+ import ButtonIcon from './ButtonIcon.js';
9
+ import ButtonLabel from './ButtonLabel.js';
10
+ import ButtonLoadingIndicator from './ButtonLoadingIndicator.js';
11
+ import { getData } from './common/data.js';
12
+ import { getInsertLinkData, getButtonWrapper } from './common/helpers.js';
6
13
 
7
- const Button = ({ className, onClick, builderProps, builderAttrs, setting = {}, styles, style, children, nodePrice })=>{
8
- const { align, size, backgroundColor, textColor, roundedBtn, iconSpacing, globalSize } = styles ?? {};
9
- const { iconSvg, btnLink, htmlType, disabled, loading, iconAlign, iconVisible, options, shouldClearSpace } = setting;
10
- const label = convertHTML(setting?.label);
11
- const Wrap = btnLink?.link !== undefined && btnLink.link !== '' ? Link : 'button';
12
- const props = btnLink?.link !== undefined && btnLink.link !== '' ? {
13
- href: btnLink?.link,
14
- target: btnLink?.target,
15
- noFollow: btnLink?.noFollow
16
- } : {
17
- type: htmlType
18
- };
19
- const iconSpacingStyle = useMemo(()=>{
20
- const spacing = iconSpacing || {
21
- desktop: '8px'
22
- };
23
- return iconAlign === 'left' ? makeStyleResponsive('mr', spacing) : makeStyleResponsive('ml', spacing);
24
- }, [
25
- iconAlign,
26
- iconSpacing
27
- ]);
28
- // fix disabled still display hover color
29
- if (disabled) {
30
- delete backgroundColor?.hover;
31
- delete backgroundColor?.focus;
32
- }
14
+ const Button = (props)=>{
15
+ const { children, advanced, className, nodePrice, customAttrs, styles = {}, setting = {}, builderProps, builderAttrs, wrapClassName = '', onClick } = props;
16
+ const { iconSvg, btnLink, htmlType, loading, disabled, shouldClearSpace } = setting;
33
17
  const mode = useEditorMode();
34
- const composeGlobalSize = makeGlobalSize(globalSize);
35
- const textOverFlow = styles?.textOverFlow || false;
36
- const appendTypoClass = composeTypographyClassName(styles?.typo, styles?.typography);
37
- const appendTypoStyle = composeTypographyStyle(styles?.typo, styles?.typography);
38
- delete appendTypoStyle['--c'];
39
- const innerBorderCss = `
40
- .${builderProps?.uid}.gp-button-base::before {
41
- content: "";
42
- height: 100%;
43
- width: 100%;
44
- position: absolute;
45
- pointer-events: none;
46
- ${composeBorderCss(styles?.borderBtn?.normal)}
47
- ${composeCornerCss(styles?.roundedBtn?.normal)}
48
- }
49
-
50
- .${builderProps?.uid}:hover::before {
51
- ${composeBorderCss(styles?.borderBtn?.hover)}
52
- ${composeCornerCss(styles?.roundedBtn?.hover)}
53
- }
54
-
55
- .${builderProps?.uid}:hover .gp-button-icon {
56
- color: ${getSingleColorVariable(styles?.textColor?.hover)};
57
- }
58
-
59
- .${builderProps?.uid} .gp-button-icon {
60
- color: ${getSingleColorVariable(styles?.textColor?.normal)};
61
- }
62
-
63
- .${builderProps?.uid}:hover .gp-button-price {
64
- color: ${getSingleColorVariable(styles?.textColor?.hover)};
65
- }
66
-
67
- .${builderProps?.uid} .gp-button-price {
68
- color: ${getSingleColorVariable(styles?.textColor?.normal)};
69
- }
70
-
71
- .${builderProps?.uid} .gp-product-dot-price {
72
- color: ${getSingleColorVariable(styles?.textColor?.normal)};
73
- }
74
-
75
- .${builderProps?.uid}:hover .gp-product-dot-price {
76
- color: ${getSingleColorVariable(styles?.textColor?.hover)};
77
- }
78
- `;
79
- return /*#__PURE__*/ jsxs("div", {
80
- ...builderAttrs,
81
- style: {
82
- ...style,
83
- ...makeStyleResponsive('ta', align)
84
- },
85
- children: [
86
- /*#__PURE__*/ jsx("style", {
87
- dangerouslySetInnerHTML: {
88
- __html: innerBorderCss
89
- }
90
- }),
91
- /*#__PURE__*/ jsxs(Wrap, {
92
- ...props,
93
- "data-id": builderProps?.uid,
94
- "aria-label": setting?.label,
95
- onClick: (e)=>{
96
- onClick?.(e);
97
- if (btnLink?.link?.startsWith('#') && mode !== 'edit') {
98
- globalEvent.dispatch('onOpenDialog', {
99
- popupUId: btnLink.link
100
- });
101
- }
102
- },
103
- "data-state": loading ? 'loading' : 'idle',
104
- className: cls(builderProps?.uid, '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', getGlobalColorStateClass('bg', backgroundColor), {
105
- 'gp-animate-bounce': styles?.animation?.normal === 'bounce',
106
- 'hover:gp-animate-bounce': styles?.animation?.hover === 'bounce',
107
- 'gp-scale-[1.1]': styles?.animation?.normal === 'grow',
108
- 'hover:gp-scale-[1.1]': styles?.animation?.hover === 'grow',
109
- 'gp-max-w-full': textOverFlow,
110
- 'gp-text-center': !!btnLink?.link
111
- }, className, getGlobalColorStateClass('text', textColor), !nodePrice ? appendTypoClass : {}),
112
- style: {
113
- ...getGlobalColorStateStyle('bg', backgroundColor),
114
- ...composeRadius(roundedBtn),
115
- ...getStyleShadowState(styles?.boxShadowBtn, 'box-shadow', {
116
- normal: styles?.boxShadowBtn?.normal?.type !== 'none',
117
- hover: styles?.boxShadowBtn?.hover?.type !== 'none'
118
- }),
119
- ...composeGlobalSize.width,
120
- ...composeGlobalSize.height,
121
- ...composeGlobalSize.padding,
122
- ...getGradientBgrStyleForButton(backgroundColor),
123
- ...getGlobalColorStateStyle('c', textColor),
124
- '--size': appendTypoStyle['--size'],
125
- '--size-tablet': appendTypoStyle['--size-tablet'],
126
- '--size-mobile': appendTypoStyle['--size-mobile'],
127
- ...!nodePrice && appendTypoStyle
128
- },
129
- disabled: disabled,
130
- children: [
131
- loading ? /*#__PURE__*/ jsxs("svg", {
132
- className: "gp-invisible gp-h-5 gp-w-5 gp-animate-spin group-data-[state=loading]:gp-visible gp-absolute",
133
- xmlns: "http://www.w3.org/2000/svg",
134
- fill: "none",
135
- viewBox: "0 0 24 24",
136
- children: [
137
- /*#__PURE__*/ jsx("circle", {
138
- className: "gp-opacity-25",
139
- cx: "12",
140
- cy: "12",
141
- r: "10",
142
- stroke: "currentColor",
143
- strokeWidth: "4"
144
- }),
145
- /*#__PURE__*/ jsx("path", {
146
- className: "gp-opacity-75",
147
- fill: "currentColor",
148
- 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"
149
- })
150
- ]
151
- }) : '',
152
- /*#__PURE__*/ jsxs("div", {
153
- className: cls({
154
- 'gp-flex-row-reverse': iconAlign === 'right'
155
- }, 'gp-inline-flex'),
156
- children: [
157
- !!iconSvg && iconVisible && /*#__PURE__*/ jsx("span", {
158
- className: `
159
- 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)] ${shouldClearSpace && !label ? '!gp-m-0' : ''}`,
160
- style: {
161
- ...iconSpacingStyle,
162
- '--height-desktop': `${size?.desktop}`,
163
- '--height-tablet': `${size?.desktop || size?.tablet}`,
164
- '--height-mobile': `${size?.mobile || size?.tablet || size?.desktop}`
165
- },
166
- dangerouslySetInnerHTML: {
167
- __html: iconSvg
168
- }
169
- }),
170
- (!!label || !shouldClearSpace) && /*#__PURE__*/ jsx("div", {
171
- "data-gp-text": true,
172
- className: cls(`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`, styles?.typo?.attrs?.italic ? '[&:not(:has(p))]:gp-pr-[0.2em] [&_p]:[&:has(p)]:gp-pr-[0.2em]' : '', mode === 'edit' && !options?.isCannotEditing ? 'gp-text button-text' : '', nodePrice ? appendTypoClass : {}),
173
- style: {
174
- ...makeStyle({
175
- tt: styles?.transform
176
- }),
177
- ...nodePrice && appendTypoStyle
178
- },
179
- dangerouslySetInnerHTML: {
180
- __html: styles?.typo?.attrs?.transform === 'capitalize' ? label?.toString().toLocaleLowerCase() : label
181
- }
182
- })
183
- ]
184
- }),
185
- nodePrice && nodePrice
186
- ]
187
- }),
188
- children
189
- ]
18
+ const { customCss, wrapStyle, restStyle, dataState, dataIdAttr, isShowIcon, isScrollToElement, getArialLabel, getLabelToDisplay, checkIsShowLabel, checkIsEditableLabel } = getData(props);
19
+ const { HTMLTag, urlData, shouldRenderLink } = getInsertLinkData({
20
+ htmlType,
21
+ setting: btnLink,
22
+ defaultTag: 'button'
23
+ });
24
+ const ButtonWrapper = getButtonWrapper(HTMLTag, isScrollToElement);
25
+ const buttonStyles = createStyle({
26
+ ...getButtonStyles(styles, nodePrice)
27
+ });
28
+ const buttonIconStyles = createStyle({
29
+ ...getButtonIconStyles(styles, setting)
30
+ });
31
+ const buttonWrapperStyles = createStyle({
32
+ ...getButtonWrapperStyles(restStyle, styles)
33
+ });
34
+ const buttonClasses = createClass({
35
+ ...getButtonClasses({
36
+ styles,
37
+ className,
38
+ shouldRenderLink,
39
+ uid: builderProps?.uid
40
+ })
41
+ });
42
+ const buttonIconClasses = createClass({
43
+ ...getButtonIconClasses(getLabelToDisplay(), shouldClearSpace)
44
+ });
45
+ const buttonLabelClasses = createClass({
46
+ ...getButtonLabelClasses(styles, checkIsEditableLabel({
47
+ mode
48
+ }))
49
+ });
50
+ const buttonWrapperClasses = createClass({
51
+ ...getButtonWrapperClasses(wrapClassName, className, advanced?.cssClass)
52
+ });
53
+ const buttonContentWrapperClasses = createClass({
54
+ ...getButtonContentWrapperClasses(setting)
55
+ });
56
+ const buttonWrapperAttrs = createAttr({
57
+ ...getButtonAttributes({
58
+ urlData,
59
+ disabled,
60
+ dataState,
61
+ dataId: dataIdAttr,
62
+ arialLabel: getArialLabel()
63
+ })
64
+ });
65
+ const handleClick = (e)=>{
66
+ onClick?.(e);
67
+ if (btnLink?.link?.startsWith('#') && mode !== 'edit') {
68
+ globalEvent.dispatch('onOpenDialog', {
69
+ popupUId: btnLink.link
70
+ });
71
+ }
72
+ };
73
+ return /*#__PURE__*/ jsx("div", {
74
+ style: wrapStyle,
75
+ children: /*#__PURE__*/ jsxs("div", {
76
+ ...builderAttrs,
77
+ style: buttonWrapperStyles,
78
+ className: buttonWrapperClasses,
79
+ children: [
80
+ /*#__PURE__*/ jsx("style", {
81
+ children: customCss
82
+ }),
83
+ If(isScrollToElement, // eslint-disable-next-line jsx-a11y/anchor-has-content
84
+ /*#__PURE__*/ jsx("a", {
85
+ className: "gp-trigger-button-link gp-hidden",
86
+ href: urlData.href,
87
+ target: urlData.target
88
+ })),
89
+ /*#__PURE__*/ jsxs(ButtonWrapper, {
90
+ ...buttonWrapperAttrs,
91
+ ...customAttrs,
92
+ style: buttonStyles,
93
+ className: buttonClasses,
94
+ onClick: handleClick,
95
+ children: [
96
+ If(loading, /*#__PURE__*/ jsx(ButtonLoadingIndicator, {}), ''),
97
+ /*#__PURE__*/ jsxs("div", {
98
+ className: buttonContentWrapperClasses,
99
+ children: [
100
+ If(isShowIcon, /*#__PURE__*/ jsx(ButtonIcon, {
101
+ iconSvg: iconSvg ?? '',
102
+ styles: buttonIconStyles,
103
+ classes: buttonIconClasses
104
+ })),
105
+ If(checkIsShowLabel(), /*#__PURE__*/ jsx(ButtonLabel, {
106
+ label: getLabelToDisplay(),
107
+ classes: buttonLabelClasses
108
+ }))
109
+ ]
110
+ }),
111
+ If(!!nodePrice, nodePrice?.toString() ?? '', '')
112
+ ]
113
+ }),
114
+ children
115
+ ]
116
+ })
190
117
  });
191
118
  };
192
119
 
@@ -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 };