@gem-sdk/components 2.1.15 → 2.1.16
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.
- package/dist/cjs/product/components/ProductDescription/common.js +28 -0
- package/dist/cjs/product/components/ProductDescription/const.js +5 -0
- package/dist/cjs/product/components/ProductDescription.js +38 -10
- package/dist/cjs/product/components/ProductDescription.liquid.js +3 -1
- package/dist/esm/product/components/ProductDescription/common.js +26 -0
- package/dist/esm/product/components/ProductDescription/const.js +3 -0
- package/dist/esm/product/components/ProductDescription.js +38 -10
- package/dist/esm/product/components/ProductDescription.liquid.js +3 -1
- package/package.json +1 -1
|
@@ -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;
|
|
@@ -5,6 +5,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
6
6
|
var core = require('@gem-sdk/core');
|
|
7
7
|
var React = require('react');
|
|
8
|
+
var common = require('./ProductDescription/common.js');
|
|
9
|
+
var _const = require('./ProductDescription/const.js');
|
|
8
10
|
|
|
9
11
|
const ProductDescription = ({ setting, builderProps })=>{
|
|
10
12
|
const [open, setOpen] = React.useState(false);
|
|
@@ -18,14 +20,18 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
18
20
|
React.useEffect(()=>{
|
|
19
21
|
const dom = ref.current;
|
|
20
22
|
setOpen(false);
|
|
21
|
-
if (dom
|
|
23
|
+
if (!dom) return;
|
|
24
|
+
const enableShowMore = hasLineClamp && product?.descriptionHtml;
|
|
25
|
+
if (!enableShowMore) dom.style.maxHeight = 'none';
|
|
26
|
+
else {
|
|
22
27
|
const value = lineClamp;
|
|
23
28
|
setTimeout(()=>{
|
|
24
29
|
const scrollHeight = dom?.scrollHeight ?? 0;
|
|
25
30
|
const clientHeight = dom?.clientHeight ?? 0;
|
|
26
|
-
const lineHeight =
|
|
27
|
-
const lineText = Math.round((scrollHeight ?? 0) /
|
|
28
|
-
|
|
31
|
+
const lineHeight = getLineHeightFromDom();
|
|
32
|
+
const lineText = Math.round((scrollHeight ?? 0) / lineHeight);
|
|
33
|
+
dom.style.maxHeight = getMaxHeight(lineHeight);
|
|
34
|
+
const conditionCheckLine = value && value < lineText || clientHeight < scrollHeight;
|
|
29
35
|
if (value && conditionCheckLine) {
|
|
30
36
|
allowShowViewMore(()=>true);
|
|
31
37
|
} else {
|
|
@@ -36,8 +42,19 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
36
42
|
}, [
|
|
37
43
|
hasLineClamp,
|
|
38
44
|
lineClamp,
|
|
39
|
-
product?.description
|
|
45
|
+
product?.description,
|
|
46
|
+
core.isSafari
|
|
40
47
|
]);
|
|
48
|
+
const getLineHeightFromDom = ()=>{
|
|
49
|
+
if (!ref.current) return _const.DESCRIPTION_LINE_HEIGHT_DEFAULT;
|
|
50
|
+
const lineHeight = window.getComputedStyle(ref.current).getPropertyValue('line-height');
|
|
51
|
+
return parseInt(lineHeight);
|
|
52
|
+
};
|
|
53
|
+
const getMaxHeight = (lineHeight)=>{
|
|
54
|
+
if (!hasLineClamp || !lineClamp) return 'auto';
|
|
55
|
+
if (lineHeight) return `${lineClamp * lineHeight}px`;
|
|
56
|
+
return 'auto';
|
|
57
|
+
};
|
|
41
58
|
const Tag = htmlTag === 'html' ? 'div' : 'p';
|
|
42
59
|
const appendTypoClass = core.composeTypographyClassName(setting?.typo, setting?.typography);
|
|
43
60
|
const appendTypoStyle = core.composeTypographyStyle(setting?.typo, setting?.typography);
|
|
@@ -54,7 +71,17 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
54
71
|
}
|
|
55
72
|
`;
|
|
56
73
|
const DescriptionNotFoundString = 'This product does not have a description';
|
|
57
|
-
const
|
|
74
|
+
const noDescriptionHtml = !product?.descriptionHtml;
|
|
75
|
+
const handleToggleShowMore = ()=>{
|
|
76
|
+
if (!ref.current) return;
|
|
77
|
+
const lineHeight = getLineHeightFromDom();
|
|
78
|
+
if (open) {
|
|
79
|
+
ref.current.style.maxHeight = getMaxHeight(lineHeight);
|
|
80
|
+
} else {
|
|
81
|
+
ref.current.style.maxHeight = 'none';
|
|
82
|
+
}
|
|
83
|
+
setOpen((prev)=>!prev);
|
|
84
|
+
};
|
|
58
85
|
return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
59
86
|
children: !product ? null : /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
60
87
|
"data-id": builderProps?.uid,
|
|
@@ -65,7 +92,7 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
65
92
|
/*#__PURE__*/ jsxRuntime.jsx(Tag, {
|
|
66
93
|
ref: ref,
|
|
67
94
|
"data-gp-text": true,
|
|
68
|
-
className: core.cls('gp-p-description-text gp-break-words safari:[&_p]:gp-inline safari:[&_p]:after:gp-whitespace-pre', appendTypoClass,
|
|
95
|
+
className: core.cls('gp-p-description-text gp-break-words safari:[&_p]:gp-inline safari:[&_p]:after:gp-whitespace-pre', appendTypoClass, noDescriptionHtml ? '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)),
|
|
69
96
|
style: {
|
|
70
97
|
...core.getStyleShadow({
|
|
71
98
|
value: setting?.textShadow,
|
|
@@ -77,10 +104,11 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
77
104
|
...core.makeStyle({
|
|
78
105
|
tt: setting?.transform
|
|
79
106
|
}),
|
|
80
|
-
...appendTypoStyle
|
|
107
|
+
...appendTypoStyle,
|
|
108
|
+
...common.getMaxHeightStyleDefault(setting)
|
|
81
109
|
},
|
|
82
110
|
dangerouslySetInnerHTML: {
|
|
83
|
-
__html: product?.descriptionHtml
|
|
111
|
+
__html: product?.descriptionHtml || `${DescriptionNotFoundString}`
|
|
84
112
|
}
|
|
85
113
|
}),
|
|
86
114
|
hasLineClamp && isShowViewMore && /*#__PURE__*/ jsxRuntime.jsxs("button", {
|
|
@@ -93,7 +121,7 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
93
121
|
...appendTypoStyle,
|
|
94
122
|
...core.getGlobalColorStyle(setting?.showMoreColor)
|
|
95
123
|
},
|
|
96
|
-
onClick:
|
|
124
|
+
onClick: handleToggleShowMore,
|
|
97
125
|
children: [
|
|
98
126
|
!open ? setting?.viewMoreText : setting?.viewLessText,
|
|
99
127
|
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 };
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useProduct, useCurrentDevice, getResponsiveValueByScreen, isSafari, composeTypographyClassName, composeTypographyStyle, cls, getGlobalColorClass, getStyleShadow, makeStyleResponsive, makeStyle, getGlobalColorStyle } from '@gem-sdk/core';
|
|
3
3
|
import { useState, useRef, useEffect } from 'react';
|
|
4
|
+
import { getMaxHeightStyleDefault } from './ProductDescription/common.js';
|
|
5
|
+
import { DESCRIPTION_LINE_HEIGHT_DEFAULT } from './ProductDescription/const.js';
|
|
4
6
|
|
|
5
7
|
const ProductDescription = ({ setting, builderProps })=>{
|
|
6
8
|
const [open, setOpen] = useState(false);
|
|
@@ -14,14 +16,18 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
14
16
|
useEffect(()=>{
|
|
15
17
|
const dom = ref.current;
|
|
16
18
|
setOpen(false);
|
|
17
|
-
if (dom
|
|
19
|
+
if (!dom) return;
|
|
20
|
+
const enableShowMore = hasLineClamp && product?.descriptionHtml;
|
|
21
|
+
if (!enableShowMore) dom.style.maxHeight = 'none';
|
|
22
|
+
else {
|
|
18
23
|
const value = lineClamp;
|
|
19
24
|
setTimeout(()=>{
|
|
20
25
|
const scrollHeight = dom?.scrollHeight ?? 0;
|
|
21
26
|
const clientHeight = dom?.clientHeight ?? 0;
|
|
22
|
-
const lineHeight =
|
|
23
|
-
const lineText = Math.round((scrollHeight ?? 0) /
|
|
24
|
-
|
|
27
|
+
const lineHeight = getLineHeightFromDom();
|
|
28
|
+
const lineText = Math.round((scrollHeight ?? 0) / lineHeight);
|
|
29
|
+
dom.style.maxHeight = getMaxHeight(lineHeight);
|
|
30
|
+
const conditionCheckLine = value && value < lineText || clientHeight < scrollHeight;
|
|
25
31
|
if (value && conditionCheckLine) {
|
|
26
32
|
allowShowViewMore(()=>true);
|
|
27
33
|
} else {
|
|
@@ -32,8 +38,19 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
32
38
|
}, [
|
|
33
39
|
hasLineClamp,
|
|
34
40
|
lineClamp,
|
|
35
|
-
product?.description
|
|
41
|
+
product?.description,
|
|
42
|
+
isSafari
|
|
36
43
|
]);
|
|
44
|
+
const getLineHeightFromDom = ()=>{
|
|
45
|
+
if (!ref.current) return DESCRIPTION_LINE_HEIGHT_DEFAULT;
|
|
46
|
+
const lineHeight = window.getComputedStyle(ref.current).getPropertyValue('line-height');
|
|
47
|
+
return parseInt(lineHeight);
|
|
48
|
+
};
|
|
49
|
+
const getMaxHeight = (lineHeight)=>{
|
|
50
|
+
if (!hasLineClamp || !lineClamp) return 'auto';
|
|
51
|
+
if (lineHeight) return `${lineClamp * lineHeight}px`;
|
|
52
|
+
return 'auto';
|
|
53
|
+
};
|
|
37
54
|
const Tag = htmlTag === 'html' ? 'div' : 'p';
|
|
38
55
|
const appendTypoClass = composeTypographyClassName(setting?.typo, setting?.typography);
|
|
39
56
|
const appendTypoStyle = composeTypographyStyle(setting?.typo, setting?.typography);
|
|
@@ -50,7 +67,17 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
50
67
|
}
|
|
51
68
|
`;
|
|
52
69
|
const DescriptionNotFoundString = 'This product does not have a description';
|
|
53
|
-
const
|
|
70
|
+
const noDescriptionHtml = !product?.descriptionHtml;
|
|
71
|
+
const handleToggleShowMore = ()=>{
|
|
72
|
+
if (!ref.current) return;
|
|
73
|
+
const lineHeight = getLineHeightFromDom();
|
|
74
|
+
if (open) {
|
|
75
|
+
ref.current.style.maxHeight = getMaxHeight(lineHeight);
|
|
76
|
+
} else {
|
|
77
|
+
ref.current.style.maxHeight = 'none';
|
|
78
|
+
}
|
|
79
|
+
setOpen((prev)=>!prev);
|
|
80
|
+
};
|
|
54
81
|
return /*#__PURE__*/ jsx(Fragment, {
|
|
55
82
|
children: !product ? null : /*#__PURE__*/ jsxs("div", {
|
|
56
83
|
"data-id": builderProps?.uid,
|
|
@@ -61,7 +88,7 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
61
88
|
/*#__PURE__*/ jsx(Tag, {
|
|
62
89
|
ref: ref,
|
|
63
90
|
"data-gp-text": true,
|
|
64
|
-
className: cls('gp-p-description-text gp-break-words safari:[&_p]:gp-inline safari:[&_p]:after:gp-whitespace-pre', appendTypoClass,
|
|
91
|
+
className: cls('gp-p-description-text gp-break-words safari:[&_p]:gp-inline safari:[&_p]:after:gp-whitespace-pre', appendTypoClass, noDescriptionHtml ? '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)),
|
|
65
92
|
style: {
|
|
66
93
|
...getStyleShadow({
|
|
67
94
|
value: setting?.textShadow,
|
|
@@ -73,10 +100,11 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
73
100
|
...makeStyle({
|
|
74
101
|
tt: setting?.transform
|
|
75
102
|
}),
|
|
76
|
-
...appendTypoStyle
|
|
103
|
+
...appendTypoStyle,
|
|
104
|
+
...getMaxHeightStyleDefault(setting)
|
|
77
105
|
},
|
|
78
106
|
dangerouslySetInnerHTML: {
|
|
79
|
-
__html: product?.descriptionHtml
|
|
107
|
+
__html: product?.descriptionHtml || `${DescriptionNotFoundString}`
|
|
80
108
|
}
|
|
81
109
|
}),
|
|
82
110
|
hasLineClamp && isShowViewMore && /*#__PURE__*/ jsxs("button", {
|
|
@@ -89,7 +117,7 @@ const ProductDescription = ({ setting, builderProps })=>{
|
|
|
89
117
|
...appendTypoStyle,
|
|
90
118
|
...getGlobalColorStyle(setting?.showMoreColor)
|
|
91
119
|
},
|
|
92
|
-
onClick:
|
|
120
|
+
onClick: handleToggleShowMore,
|
|
93
121
|
children: [
|
|
94
122
|
!open ? setting?.viewMoreText : setting?.viewLessText,
|
|
95
123
|
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,
|