@gem-sdk/components 2.0.0-staging.151 → 2.0.0-staging.154

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.
@@ -0,0 +1,28 @@
1
+ 'use strict';
2
+
3
+ var core = require('@gem-sdk/core');
4
+ var _const = require('./const.js');
5
+
6
+ const getMaxHeightStyleDefault = (setting)=>{
7
+ let result = {
8
+ desktop: 'none'
9
+ };
10
+ const devices = [
11
+ 'desktop',
12
+ 'mobile',
13
+ 'tablet'
14
+ ];
15
+ devices.forEach((device)=>{
16
+ const lineClamp = core.getResponsiveValueByScreen(setting?.lineClamp, device);
17
+ const hasLineClamp = core.getResponsiveValueByScreen(setting?.hasLineClamp, device);
18
+ const maxHeight = hasLineClamp && lineClamp ? `${lineClamp * _const.DESCRIPTION_LINE_HEIGHT_DEFAULT}px` : 'none';
19
+ result = {
20
+ ...result,
21
+ [device]: maxHeight
22
+ };
23
+ });
24
+ const style = core.makeStyleResponsive('maxh', result);
25
+ return style;
26
+ };
27
+
28
+ exports.getMaxHeightStyleDefault = getMaxHeightStyleDefault;
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ const DESCRIPTION_LINE_HEIGHT_DEFAULT = 21;
4
+
5
+ exports.DESCRIPTION_LINE_HEIGHT_DEFAULT = DESCRIPTION_LINE_HEIGHT_DEFAULT;
@@ -7,6 +7,8 @@ var jsxRuntime = require('react/jsx-runtime');
7
7
  var core = require('@gem-sdk/core');
8
8
  var React = require('react');
9
9
  var NoDataState = require('../../common/components/NoDataState.js');
10
+ var common = require('./ProductDescription/common.js');
11
+ var _const = require('./ProductDescription/const.js');
10
12
 
11
13
  const ProductDescription = ({ setting, builderProps })=>{
12
14
  const [open, setOpen] = React.useState(false);
@@ -23,13 +25,17 @@ const ProductDescription = ({ setting, builderProps })=>{
23
25
  React.useEffect(()=>{
24
26
  const dom = ref.current;
25
27
  setOpen(false);
26
- if (dom && hasLineClamp && product?.description) {
28
+ if (!dom) return;
29
+ const enableShowMore = hasLineClamp && product?.descriptionHtml;
30
+ if (!enableShowMore) dom.style.maxHeight = 'none';
31
+ else {
27
32
  const value = lineClamp;
28
33
  setTimeout(()=>{
29
34
  const scrollHeight = dom?.scrollHeight ?? 0;
30
35
  const clientHeight = dom?.clientHeight ?? 0;
31
- const lineHeight = window.getComputedStyle(dom).getPropertyValue('line-height');
32
- const lineText = Math.round((scrollHeight ?? 0) / parseInt(lineHeight));
36
+ const lineHeight = getLineHeightFromDom();
37
+ const lineText = Math.round((scrollHeight ?? 0) / lineHeight);
38
+ dom.style.maxHeight = getMaxHeight(lineHeight);
33
39
  const conditionCheckLine = isSafari ? value && value < lineText : clientHeight < scrollHeight;
34
40
  if (value && conditionCheckLine) {
35
41
  allowShowViewMore(()=>true);
@@ -44,6 +50,16 @@ const ProductDescription = ({ setting, builderProps })=>{
44
50
  product?.description,
45
51
  isSafari
46
52
  ]);
53
+ const getLineHeightFromDom = ()=>{
54
+ if (!ref.current) return _const.DESCRIPTION_LINE_HEIGHT_DEFAULT;
55
+ const lineHeight = window.getComputedStyle(ref.current).getPropertyValue('line-height');
56
+ return parseInt(lineHeight);
57
+ };
58
+ const getMaxHeight = (lineHeight)=>{
59
+ if (!hasLineClamp || !lineClamp) return 'auto';
60
+ if (lineHeight) return `${lineClamp * lineHeight}px`;
61
+ return 'auto';
62
+ };
47
63
  const Tag = htmlTag === 'html' ? 'div' : 'p';
48
64
  const appendTypoClass = core.composeTypographyClassName(setting?.typo, setting?.typography);
49
65
  const appendTypoStyle = core.composeTypographyStyle(setting?.typo, setting?.typography);
@@ -59,8 +75,8 @@ const ProductDescription = ({ setting, builderProps })=>{
59
75
  box-shadow: none;
60
76
  }
61
77
  `;
62
- const hasDescription = product?.description && product.description?.trim() != '';
63
- if ((!product?.descriptionHtml || !hasDescription) && mode === 'edit') {
78
+ const noDescriptionHtml = !product?.descriptionHtml;
79
+ if (noDescriptionHtml && mode === 'edit') {
64
80
  return /*#__PURE__*/ jsxRuntime.jsx(NoDataState.default, {
65
81
  elementType: "secondary",
66
82
  description: "Highlight key benefits with product description.",
@@ -76,8 +92,18 @@ const ProductDescription = ({ setting, builderProps })=>{
76
92
  ]
77
93
  });
78
94
  }
95
+ const handleToggleShowMore = ()=>{
96
+ if (!ref.current) return;
97
+ const lineHeight = getLineHeightFromDom();
98
+ if (open) {
99
+ ref.current.style.maxHeight = getMaxHeight(lineHeight);
100
+ } else {
101
+ ref.current.style.maxHeight = 'none';
102
+ }
103
+ setOpen((prev)=>!prev);
104
+ };
79
105
  return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
80
- children: !product?.descriptionHtml || !hasDescription ? null : /*#__PURE__*/ jsxRuntime.jsxs("div", {
106
+ children: noDescriptionHtml ? null : /*#__PURE__*/ jsxRuntime.jsxs("div", {
81
107
  "data-id": builderProps?.uid,
82
108
  children: [
83
109
  !isSafari && /*#__PURE__*/ jsxRuntime.jsx("style", {
@@ -89,7 +115,7 @@ const ProductDescription = ({ setting, builderProps })=>{
89
115
  /*#__PURE__*/ jsxRuntime.jsx(Tag, {
90
116
  ref: ref,
91
117
  "data-gp-text": true,
92
- className: core.cls('gp-p-description-text gp-break-words safari:[&_p]:gp-inline safari:[&_p]:after:gp-whitespace-pre', appendTypoClass, !hasDescription ? 'gp-p-2 gp-text-center gp-text-sm gp-font-semibold gp-text-gray-500 gp-py-2 !gp-text-center' : '', core.getGlobalColorClass('text', setting?.color)),
118
+ className: core.cls('gp-p-description-text gp-break-words safari:[&_p]:gp-inline safari:[&_p]:after:gp-whitespace-pre', appendTypoClass, core.getGlobalColorClass('text', setting?.color)),
93
119
  style: {
94
120
  ...core.getStyleShadow({
95
121
  value: setting?.textShadow,
@@ -101,10 +127,11 @@ const ProductDescription = ({ setting, builderProps })=>{
101
127
  ...core.makeStyle({
102
128
  tt: setting?.transform
103
129
  }),
104
- ...appendTypoStyle
130
+ ...appendTypoStyle,
131
+ ...common.getMaxHeightStyleDefault(setting)
105
132
  },
106
133
  dangerouslySetInnerHTML: {
107
- __html: product?.descriptionHtml
134
+ __html: product?.descriptionHtml || ''
108
135
  }
109
136
  }),
110
137
  hasLineClamp && isShowViewMore && /*#__PURE__*/ jsxRuntime.jsxs("button", {
@@ -117,7 +144,7 @@ const ProductDescription = ({ setting, builderProps })=>{
117
144
  ...appendTypoStyle,
118
145
  ...core.getGlobalColorStyle(setting?.showMoreColor)
119
146
  },
120
- onClick: ()=>setOpen((prev)=>!prev),
147
+ onClick: handleToggleShowMore,
121
148
  children: [
122
149
  !open ? setting?.viewMoreText : setting?.viewLessText,
123
150
  setting?.enableViewMoreIcon && /*#__PURE__*/ jsxRuntime.jsx("svg", {
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var core = require('@gem-sdk/core');
6
6
  var helpers = require('../../helpers.js');
7
+ var common = require('./ProductDescription/common.js');
7
8
 
8
9
  const devices = [
9
10
  'desktop',
@@ -35,7 +36,8 @@ const ProductDescription = ({ setting, advanced, builderProps })=>{
35
36
  ...core.makeStyle({
36
37
  tt: setting?.transform
37
38
  }),
38
- ...appendTypoStyle
39
+ ...appendTypoStyle,
40
+ ...common.getMaxHeightStyleDefault(setting)
39
41
  };
40
42
  const collapseStyle = {
41
43
  ...defaultStyle,
@@ -0,0 +1,26 @@
1
+ import { getResponsiveValueByScreen, makeStyleResponsive } from '@gem-sdk/core';
2
+ import { DESCRIPTION_LINE_HEIGHT_DEFAULT } from './const.js';
3
+
4
+ const getMaxHeightStyleDefault = (setting)=>{
5
+ let result = {
6
+ desktop: 'none'
7
+ };
8
+ const devices = [
9
+ 'desktop',
10
+ 'mobile',
11
+ 'tablet'
12
+ ];
13
+ devices.forEach((device)=>{
14
+ const lineClamp = getResponsiveValueByScreen(setting?.lineClamp, device);
15
+ const hasLineClamp = getResponsiveValueByScreen(setting?.hasLineClamp, device);
16
+ const maxHeight = hasLineClamp && lineClamp ? `${lineClamp * DESCRIPTION_LINE_HEIGHT_DEFAULT}px` : 'none';
17
+ result = {
18
+ ...result,
19
+ [device]: maxHeight
20
+ };
21
+ });
22
+ const style = makeStyleResponsive('maxh', result);
23
+ return style;
24
+ };
25
+
26
+ export { getMaxHeightStyleDefault };
@@ -0,0 +1,3 @@
1
+ const DESCRIPTION_LINE_HEIGHT_DEFAULT = 21;
2
+
3
+ export { DESCRIPTION_LINE_HEIGHT_DEFAULT };
@@ -3,6 +3,8 @@ import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
3
3
  import { useProduct, useCurrentDevice, getResponsiveValueByScreen, useProductShopifyEditLink, useEditorMode, isBrowser, composeTypographyClassName, composeTypographyStyle, cls, getGlobalColorClass, getStyleShadow, makeStyleResponsive, makeStyle, getGlobalColorStyle } from '@gem-sdk/core';
4
4
  import { useState, useRef, useEffect } from 'react';
5
5
  import NoDataState from '../../common/components/NoDataState.js';
6
+ import { getMaxHeightStyleDefault } from './ProductDescription/common.js';
7
+ import { DESCRIPTION_LINE_HEIGHT_DEFAULT } from './ProductDescription/const.js';
6
8
 
7
9
  const ProductDescription = ({ setting, builderProps })=>{
8
10
  const [open, setOpen] = useState(false);
@@ -19,13 +21,17 @@ const ProductDescription = ({ setting, builderProps })=>{
19
21
  useEffect(()=>{
20
22
  const dom = ref.current;
21
23
  setOpen(false);
22
- if (dom && hasLineClamp && product?.description) {
24
+ if (!dom) return;
25
+ const enableShowMore = hasLineClamp && product?.descriptionHtml;
26
+ if (!enableShowMore) dom.style.maxHeight = 'none';
27
+ else {
23
28
  const value = lineClamp;
24
29
  setTimeout(()=>{
25
30
  const scrollHeight = dom?.scrollHeight ?? 0;
26
31
  const clientHeight = dom?.clientHeight ?? 0;
27
- const lineHeight = window.getComputedStyle(dom).getPropertyValue('line-height');
28
- const lineText = Math.round((scrollHeight ?? 0) / parseInt(lineHeight));
32
+ const lineHeight = getLineHeightFromDom();
33
+ const lineText = Math.round((scrollHeight ?? 0) / lineHeight);
34
+ dom.style.maxHeight = getMaxHeight(lineHeight);
29
35
  const conditionCheckLine = isSafari ? value && value < lineText : clientHeight < scrollHeight;
30
36
  if (value && conditionCheckLine) {
31
37
  allowShowViewMore(()=>true);
@@ -40,6 +46,16 @@ const ProductDescription = ({ setting, builderProps })=>{
40
46
  product?.description,
41
47
  isSafari
42
48
  ]);
49
+ const getLineHeightFromDom = ()=>{
50
+ if (!ref.current) return DESCRIPTION_LINE_HEIGHT_DEFAULT;
51
+ const lineHeight = window.getComputedStyle(ref.current).getPropertyValue('line-height');
52
+ return parseInt(lineHeight);
53
+ };
54
+ const getMaxHeight = (lineHeight)=>{
55
+ if (!hasLineClamp || !lineClamp) return 'auto';
56
+ if (lineHeight) return `${lineClamp * lineHeight}px`;
57
+ return 'auto';
58
+ };
43
59
  const Tag = htmlTag === 'html' ? 'div' : 'p';
44
60
  const appendTypoClass = composeTypographyClassName(setting?.typo, setting?.typography);
45
61
  const appendTypoStyle = composeTypographyStyle(setting?.typo, setting?.typography);
@@ -55,8 +71,8 @@ const ProductDescription = ({ setting, builderProps })=>{
55
71
  box-shadow: none;
56
72
  }
57
73
  `;
58
- const hasDescription = product?.description && product.description?.trim() != '';
59
- if ((!product?.descriptionHtml || !hasDescription) && mode === 'edit') {
74
+ const noDescriptionHtml = !product?.descriptionHtml;
75
+ if (noDescriptionHtml && mode === 'edit') {
60
76
  return /*#__PURE__*/ jsx(NoDataState, {
61
77
  elementType: "secondary",
62
78
  description: "Highlight key benefits with product description.",
@@ -72,8 +88,18 @@ const ProductDescription = ({ setting, builderProps })=>{
72
88
  ]
73
89
  });
74
90
  }
91
+ const handleToggleShowMore = ()=>{
92
+ if (!ref.current) return;
93
+ const lineHeight = getLineHeightFromDom();
94
+ if (open) {
95
+ ref.current.style.maxHeight = getMaxHeight(lineHeight);
96
+ } else {
97
+ ref.current.style.maxHeight = 'none';
98
+ }
99
+ setOpen((prev)=>!prev);
100
+ };
75
101
  return /*#__PURE__*/ jsx(Fragment, {
76
- children: !product?.descriptionHtml || !hasDescription ? null : /*#__PURE__*/ jsxs("div", {
102
+ children: noDescriptionHtml ? null : /*#__PURE__*/ jsxs("div", {
77
103
  "data-id": builderProps?.uid,
78
104
  children: [
79
105
  !isSafari && /*#__PURE__*/ jsx("style", {
@@ -85,7 +111,7 @@ const ProductDescription = ({ setting, builderProps })=>{
85
111
  /*#__PURE__*/ jsx(Tag, {
86
112
  ref: ref,
87
113
  "data-gp-text": true,
88
- className: cls('gp-p-description-text gp-break-words safari:[&_p]:gp-inline safari:[&_p]:after:gp-whitespace-pre', appendTypoClass, !hasDescription ? 'gp-p-2 gp-text-center gp-text-sm gp-font-semibold gp-text-gray-500 gp-py-2 !gp-text-center' : '', getGlobalColorClass('text', setting?.color)),
114
+ className: cls('gp-p-description-text gp-break-words safari:[&_p]:gp-inline safari:[&_p]:after:gp-whitespace-pre', appendTypoClass, getGlobalColorClass('text', setting?.color)),
89
115
  style: {
90
116
  ...getStyleShadow({
91
117
  value: setting?.textShadow,
@@ -97,10 +123,11 @@ const ProductDescription = ({ setting, builderProps })=>{
97
123
  ...makeStyle({
98
124
  tt: setting?.transform
99
125
  }),
100
- ...appendTypoStyle
126
+ ...appendTypoStyle,
127
+ ...getMaxHeightStyleDefault(setting)
101
128
  },
102
129
  dangerouslySetInnerHTML: {
103
- __html: product?.descriptionHtml
130
+ __html: product?.descriptionHtml || ''
104
131
  }
105
132
  }),
106
133
  hasLineClamp && isShowViewMore && /*#__PURE__*/ jsxs("button", {
@@ -113,7 +140,7 @@ const ProductDescription = ({ setting, builderProps })=>{
113
140
  ...appendTypoStyle,
114
141
  ...getGlobalColorStyle(setting?.showMoreColor)
115
142
  },
116
- onClick: ()=>setOpen((prev)=>!prev),
143
+ onClick: handleToggleShowMore,
117
144
  children: [
118
145
  !open ? setting?.viewMoreText : setting?.viewLessText,
119
146
  setting?.enableViewMoreIcon && /*#__PURE__*/ jsx("svg", {
@@ -1,5 +1,6 @@
1
1
  import { composeTypographyClassName, composeTypographyStyle, getStyleShadow, makeStyleResponsive, getGlobalColorStyle, makeStyle, makeLineClamp, template, cls, getGlobalColorClass, RenderIf, isLocalEnv, baseAssetURL } from '@gem-sdk/core';
2
2
  import { getSettingPreloadData } from '../../helpers.js';
3
+ import { getMaxHeightStyleDefault } from './ProductDescription/common.js';
3
4
 
4
5
  const devices = [
5
6
  'desktop',
@@ -31,7 +32,8 @@ const ProductDescription = ({ setting, advanced, builderProps })=>{
31
32
  ...makeStyle({
32
33
  tt: setting?.transform
33
34
  }),
34
- ...appendTypoStyle
35
+ ...appendTypoStyle,
36
+ ...getMaxHeightStyleDefault(setting)
35
37
  };
36
38
  const collapseStyle = {
37
39
  ...defaultStyle,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/components",
3
- "version": "2.0.0-staging.151",
3
+ "version": "2.0.0-staging.154",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -22,8 +22,8 @@
22
22
  "relationship": "rollup -c ./scripts/rollup.config.settings.mjs && node ./scripts/get-control-relationship.js && node ./scripts/get-element-relationship.js"
23
23
  },
24
24
  "devDependencies": {
25
- "@gem-sdk/core": "2.0.0-staging.136",
26
- "@gem-sdk/styles": "2.0.0-staging.127",
25
+ "@gem-sdk/core": "2.0.0-staging.153",
26
+ "@gem-sdk/styles": "2.0.0-staging.153",
27
27
  "@types/react-transition-group": "^4.4.5"
28
28
  },
29
29
  "dependencies": {