@gem-sdk/components 2.0.0-dev.542 → 2.0.0-dev.543
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/collection/components/collection-description/common/classes.js +12 -0
- package/dist/cjs/collection/components/collection-description/common/styles.js +9 -2
- package/dist/cjs/collection/components/collection-description/components/CollectionDescription.js +11 -13
- package/dist/cjs/collection/components/collection-description/components/CollectionDescription.liquid.js +10 -10
- package/dist/cjs/collection/components/collection-description/hook/useDescription.js +8 -43
- package/dist/esm/collection/components/collection-description/common/classes.js +10 -1
- package/dist/esm/collection/components/collection-description/common/styles.js +9 -2
- package/dist/esm/collection/components/collection-description/components/CollectionDescription.js +12 -14
- package/dist/esm/collection/components/collection-description/components/CollectionDescription.liquid.js +11 -11
- package/dist/esm/collection/components/collection-description/hook/useDescription.js +10 -45
- package/package.json +1 -1
|
@@ -10,6 +10,15 @@ const getClassButtonViewMore = ({ setting })=>{
|
|
|
10
10
|
const appendTypoClass = core.composeTypographyClassName(setting?.typo, setting?.typography);
|
|
11
11
|
return composeClasses(core.cls('p-description-show-more', 'gp-mt-4 hover:gp-opacity-80 gp-transition-all gp-w-full', appendTypoClass, core.getGlobalColorClass('text', setting?.showMoreColor)));
|
|
12
12
|
};
|
|
13
|
+
const getDescriptionClasses = ({ advanced })=>{
|
|
14
|
+
return composeClasses(core.cls('gp-collection-description', advanced?.cssClass));
|
|
15
|
+
};
|
|
16
|
+
const getShowMoreIconClasses = ()=>{
|
|
17
|
+
return composeClasses(core.cls('gp-show-more-icon gp-ml-1'));
|
|
18
|
+
};
|
|
19
|
+
const getShowMoreTextClasses = ()=>{
|
|
20
|
+
return composeClasses(core.cls('gp-show-more-text'));
|
|
21
|
+
};
|
|
13
22
|
const composeClasses = (classes)=>{
|
|
14
23
|
return classes.trim().split(/\s+/).reduce((acc, className)=>{
|
|
15
24
|
acc[className] = true;
|
|
@@ -19,3 +28,6 @@ const composeClasses = (classes)=>{
|
|
|
19
28
|
|
|
20
29
|
exports.getClassButtonViewMore = getClassButtonViewMore;
|
|
21
30
|
exports.getClassContainerCollectionDes = getClassContainerCollectionDes;
|
|
31
|
+
exports.getDescriptionClasses = getDescriptionClasses;
|
|
32
|
+
exports.getShowMoreIconClasses = getShowMoreIconClasses;
|
|
33
|
+
exports.getShowMoreTextClasses = getShowMoreTextClasses;
|
|
@@ -43,13 +43,20 @@ const getDefaultStyleCollectionDes = ({ setting, renderMaxHeight })=>{
|
|
|
43
43
|
};
|
|
44
44
|
const getStyleDefaultViewMore = (setting)=>{
|
|
45
45
|
const appendTypoStyle = core.composeTypographyStyle(setting?.typo, setting?.typography);
|
|
46
|
+
const getDisplayCollapse = ()=>{
|
|
47
|
+
return helpers.getDisplayStyle((device)=>{
|
|
48
|
+
const hasClamp = setting?.hasLineClamp?.[device];
|
|
49
|
+
return !!setting?.hasLineClamp && hasClamp !== undefined && !hasClamp;
|
|
50
|
+
}, 'inline-flex');
|
|
51
|
+
};
|
|
46
52
|
return {
|
|
47
53
|
...core.makeStyle({
|
|
48
54
|
tt: setting?.transform
|
|
49
55
|
}),
|
|
50
|
-
...core.makeStyleResponsive('
|
|
56
|
+
...core.makeStyleResponsive('jc', setting?.textAlign),
|
|
51
57
|
...appendTypoStyle,
|
|
52
|
-
...core.getGlobalColorStyle(setting?.showMoreColor)
|
|
58
|
+
...core.getGlobalColorStyle(setting?.showMoreColor),
|
|
59
|
+
...getDisplayCollapse()
|
|
53
60
|
};
|
|
54
61
|
};
|
|
55
62
|
const getDisplayCollapse = (setting)=>{
|
package/dist/cjs/collection/components/collection-description/components/CollectionDescription.js
CHANGED
|
@@ -22,17 +22,12 @@ const CollectionDescription = ({ setting, builderProps, pageContext, advanced })
|
|
|
22
22
|
const classButtonViewMore = system.createClass(classes.getClassButtonViewMore({
|
|
23
23
|
setting
|
|
24
24
|
}));
|
|
25
|
-
const gpDescriptionClasses = system.createClass({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
...open ? {
|
|
32
|
-
'gp-rotate-180': true
|
|
33
|
-
} : {}
|
|
34
|
-
});
|
|
35
|
-
const collapseStyle = system.createStyle({
|
|
25
|
+
const gpDescriptionClasses = system.createClass(classes.getDescriptionClasses({
|
|
26
|
+
advanced
|
|
27
|
+
}));
|
|
28
|
+
const showMoreIconClasses = system.createClass(classes.getShowMoreIconClasses());
|
|
29
|
+
const showMoreTextClasses = system.createClass(classes.getShowMoreTextClasses());
|
|
30
|
+
const textStyle = system.createStyle({
|
|
36
31
|
...styles.getDefaultStyleCollectionDes({
|
|
37
32
|
setting
|
|
38
33
|
}),
|
|
@@ -74,7 +69,7 @@ const CollectionDescription = ({ setting, builderProps, pageContext, advanced })
|
|
|
74
69
|
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
75
70
|
ref: ref,
|
|
76
71
|
className: classContainerCollectionDes,
|
|
77
|
-
style:
|
|
72
|
+
style: textStyle,
|
|
78
73
|
dangerouslySetInnerHTML: {
|
|
79
74
|
__html: collection?.descriptionHtml ?? ''
|
|
80
75
|
},
|
|
@@ -86,7 +81,10 @@ const CollectionDescription = ({ setting, builderProps, pageContext, advanced })
|
|
|
86
81
|
style: styleViewMore,
|
|
87
82
|
onClick: handleToggleShowMore,
|
|
88
83
|
children: [
|
|
89
|
-
|
|
84
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
85
|
+
className: showMoreTextClasses,
|
|
86
|
+
children: system.If(open, viewLessText?.toString() ?? '', viewMoreText?.toString() ?? '')
|
|
87
|
+
}),
|
|
90
88
|
system.If(setting?.enableViewMoreIcon, /*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
91
89
|
className: showMoreIconClasses,
|
|
92
90
|
dangerouslySetInnerHTML: {
|
|
@@ -18,14 +18,12 @@ const CollectionDescription = ({ setting, advanced, builderProps, pageContext })
|
|
|
18
18
|
const classButtonViewMore = system.createClass(classes.getClassButtonViewMore({
|
|
19
19
|
setting
|
|
20
20
|
}));
|
|
21
|
-
const gpDescriptionClasses = system.createClass({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
});
|
|
28
|
-
const collapseStyle = system.createStyle({
|
|
21
|
+
const gpDescriptionClasses = system.createClass(classes.getDescriptionClasses({
|
|
22
|
+
advanced
|
|
23
|
+
}));
|
|
24
|
+
const showMoreIconClasses = system.createClass(classes.getShowMoreIconClasses());
|
|
25
|
+
const showMoreTextClasses = system.createClass(classes.getShowMoreTextClasses());
|
|
26
|
+
const textStyle = system.createStyle({
|
|
29
27
|
...styles.getDefaultStyleCollectionDes({
|
|
30
28
|
setting,
|
|
31
29
|
renderMaxHeight: true
|
|
@@ -67,7 +65,7 @@ const CollectionDescription = ({ setting, advanced, builderProps, pageContext })
|
|
|
67
65
|
viewLessText: viewLessText,
|
|
68
66
|
enableViewMoreIcon: setting?.enableViewMoreIcon
|
|
69
67
|
},
|
|
70
|
-
|
|
68
|
+
textStyle
|
|
71
69
|
});
|
|
72
70
|
const renderScript = ()=>{
|
|
73
71
|
const jsURL = core.isLocalEnv ? `{{ 'gp-collection-description.js' | asset_url }}` : `${core.baseAssetURL}/assets-v2/gp-collection-description.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}`;
|
|
@@ -81,11 +79,13 @@ const CollectionDescription = ({ setting, advanced, builderProps, pageContext })
|
|
|
81
79
|
>
|
|
82
80
|
<style>${textDescriptionCss}</style>
|
|
83
81
|
${system.If(!core.isSafari(), `<style>${gpDescriptionCss}</style>`, ' ')}
|
|
84
|
-
${system.LiquidUnless('collection', `<p>Collection not found</p>`, core.template`<div ${textAttr} class="${classContainerCollectionDes}" style="${
|
|
82
|
+
${system.LiquidUnless('collection', `<p>Collection not found</p>`, core.template`<div ${textAttr} class="${classContainerCollectionDes}" style="${textStyle}">
|
|
85
83
|
{{collection.description}}
|
|
86
84
|
</div>
|
|
87
85
|
${system.LiquidIf(hasDescriptionHtml, core.template`<button type="button" class="${classButtonViewMore}" style="${styleViewMore}">
|
|
86
|
+
<span class="${showMoreTextClasses}">
|
|
88
87
|
${system.If(pageContext?.isPreviewing, viewMoreText?.toString() || '', `{{${viewMoreText}}}`)}
|
|
88
|
+
</span>
|
|
89
89
|
${system.If(setting?.enableViewMoreIcon, core.template`<span class="${showMoreIconClasses}">${constant.ICON_SVG}</span>`, ' ')}
|
|
90
90
|
</button>`)}`)}
|
|
91
91
|
</gp-collection-description>
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var React = require('react');
|
|
4
|
-
var constant = require('../common/constant.js');
|
|
5
4
|
var core = require('@gem-sdk/core');
|
|
6
5
|
|
|
7
6
|
const useGpDescription = (setting)=>{
|
|
@@ -13,52 +12,23 @@ const useGpDescription = (setting)=>{
|
|
|
13
12
|
const hasLineClamp = core.getResponsiveValueByScreen(setting?.hasLineClamp, currentDevice);
|
|
14
13
|
const lineClamp = core.getResponsiveValueByScreen(setting?.lineClamp, currentDevice);
|
|
15
14
|
const mode = core.useEditorMode();
|
|
16
|
-
const getLineHeightFromDom = React.useCallback(()=>{
|
|
17
|
-
if (!ref.current) return constant.DESCRIPTION_LINE_HEIGHT_DEFAULT;
|
|
18
|
-
const lineHeight = window.getComputedStyle(ref.current).getPropertyValue('line-height');
|
|
19
|
-
return Math.ceil(parseFloat(lineHeight));
|
|
20
|
-
}, []);
|
|
21
|
-
const getMaxHeight = React.useCallback((lineHeight)=>{
|
|
22
|
-
if (!hasLineClamp || !lineClamp) return 'auto';
|
|
23
|
-
if (lineHeight) return `${lineClamp * lineHeight}px`;
|
|
24
|
-
return 'auto';
|
|
25
|
-
}, [
|
|
26
|
-
hasLineClamp,
|
|
27
|
-
lineClamp
|
|
28
|
-
]);
|
|
29
15
|
const handleToggleShowMore = ()=>{
|
|
30
|
-
if (!ref.current) return;
|
|
31
|
-
const lineHeight = getLineHeightFromDom();
|
|
32
|
-
if (open) {
|
|
33
|
-
ref.current.style.maxHeight = getMaxHeight(lineHeight);
|
|
34
|
-
} else {
|
|
35
|
-
ref.current.style.maxHeight = 'none';
|
|
36
|
-
}
|
|
37
16
|
setOpen((prev)=>!prev);
|
|
38
17
|
};
|
|
39
|
-
React.useEffect(()=>{
|
|
40
|
-
const lineHeight = getLineHeightFromDom();
|
|
41
|
-
getMaxHeight(lineHeight);
|
|
42
|
-
}, [
|
|
43
|
-
setting?.typo?.custom,
|
|
44
|
-
getMaxHeight,
|
|
45
|
-
getLineHeightFromDom
|
|
46
|
-
]);
|
|
47
18
|
React.useEffect(()=>{
|
|
48
19
|
const dom = ref.current;
|
|
49
20
|
setOpen(false);
|
|
50
|
-
if (
|
|
51
|
-
const enableShowMore = hasLineClamp && collection?.descriptionHtml;
|
|
52
|
-
if (!enableShowMore) dom.style.maxHeight = 'none';
|
|
53
|
-
else {
|
|
21
|
+
if (dom && hasLineClamp && collection?.description) {
|
|
54
22
|
const value = lineClamp;
|
|
55
23
|
setTimeout(()=>{
|
|
56
24
|
const scrollHeight = dom?.scrollHeight ?? 0;
|
|
57
25
|
const clientHeight = dom?.clientHeight ?? 0;
|
|
58
|
-
const lineHeight =
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
26
|
+
const lineHeight = window.getComputedStyle(dom).getPropertyValue('line-height');
|
|
27
|
+
const parsedLineHeight = parseInt(lineHeight, 10) || 1;
|
|
28
|
+
const lineText = Math.round((scrollHeight ?? 0) / parsedLineHeight);
|
|
29
|
+
const isValueExceeded = value !== undefined && value < lineText;
|
|
30
|
+
const isOverflow = clientHeight < scrollHeight;
|
|
31
|
+
const conditionCheckLine = core.isSafari() ? isValueExceeded : isOverflow;
|
|
62
32
|
if (value && conditionCheckLine) {
|
|
63
33
|
setIsShowViewMore(()=>true);
|
|
64
34
|
} else {
|
|
@@ -69,12 +39,7 @@ const useGpDescription = (setting)=>{
|
|
|
69
39
|
}, [
|
|
70
40
|
hasLineClamp,
|
|
71
41
|
lineClamp,
|
|
72
|
-
collection?.description
|
|
73
|
-
collection?.descriptionHtml,
|
|
74
|
-
getLineHeightFromDom,
|
|
75
|
-
getMaxHeight,
|
|
76
|
-
setOpen,
|
|
77
|
-
setIsShowViewMore
|
|
42
|
+
collection?.description
|
|
78
43
|
]);
|
|
79
44
|
return {
|
|
80
45
|
ref,
|
|
@@ -8,6 +8,15 @@ const getClassButtonViewMore = ({ setting })=>{
|
|
|
8
8
|
const appendTypoClass = composeTypographyClassName(setting?.typo, setting?.typography);
|
|
9
9
|
return composeClasses(cls('p-description-show-more', 'gp-mt-4 hover:gp-opacity-80 gp-transition-all gp-w-full', appendTypoClass, getGlobalColorClass('text', setting?.showMoreColor)));
|
|
10
10
|
};
|
|
11
|
+
const getDescriptionClasses = ({ advanced })=>{
|
|
12
|
+
return composeClasses(cls('gp-collection-description', advanced?.cssClass));
|
|
13
|
+
};
|
|
14
|
+
const getShowMoreIconClasses = ()=>{
|
|
15
|
+
return composeClasses(cls('gp-show-more-icon gp-ml-1'));
|
|
16
|
+
};
|
|
17
|
+
const getShowMoreTextClasses = ()=>{
|
|
18
|
+
return composeClasses(cls('gp-show-more-text'));
|
|
19
|
+
};
|
|
11
20
|
const composeClasses = (classes)=>{
|
|
12
21
|
return classes.trim().split(/\s+/).reduce((acc, className)=>{
|
|
13
22
|
acc[className] = true;
|
|
@@ -15,4 +24,4 @@ const composeClasses = (classes)=>{
|
|
|
15
24
|
}, {});
|
|
16
25
|
};
|
|
17
26
|
|
|
18
|
-
export { getClassButtonViewMore, getClassContainerCollectionDes };
|
|
27
|
+
export { getClassButtonViewMore, getClassContainerCollectionDes, getDescriptionClasses, getShowMoreIconClasses, getShowMoreTextClasses };
|
|
@@ -41,13 +41,20 @@ const getDefaultStyleCollectionDes = ({ setting, renderMaxHeight })=>{
|
|
|
41
41
|
};
|
|
42
42
|
const getStyleDefaultViewMore = (setting)=>{
|
|
43
43
|
const appendTypoStyle = composeTypographyStyle(setting?.typo, setting?.typography);
|
|
44
|
+
const getDisplayCollapse = ()=>{
|
|
45
|
+
return getDisplayStyle((device)=>{
|
|
46
|
+
const hasClamp = setting?.hasLineClamp?.[device];
|
|
47
|
+
return !!setting?.hasLineClamp && hasClamp !== undefined && !hasClamp;
|
|
48
|
+
}, 'inline-flex');
|
|
49
|
+
};
|
|
44
50
|
return {
|
|
45
51
|
...makeStyle({
|
|
46
52
|
tt: setting?.transform
|
|
47
53
|
}),
|
|
48
|
-
...makeStyleResponsive('
|
|
54
|
+
...makeStyleResponsive('jc', setting?.textAlign),
|
|
49
55
|
...appendTypoStyle,
|
|
50
|
-
...getGlobalColorStyle(setting?.showMoreColor)
|
|
56
|
+
...getGlobalColorStyle(setting?.showMoreColor),
|
|
57
|
+
...getDisplayCollapse()
|
|
51
58
|
};
|
|
52
59
|
};
|
|
53
60
|
const getDisplayCollapse = (setting)=>{
|
package/dist/esm/collection/components/collection-description/components/CollectionDescription.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { useCollection, makeStyleResponsive, makeLineClamp, isSafari } from '@gem-sdk/core';
|
|
4
4
|
import { getDefaultStyleCollectionDes, getStyleDefaultViewMore, getStaticCss } from '../common/styles.js';
|
|
5
|
-
import { getClassContainerCollectionDes, getClassButtonViewMore } from '../common/classes.js';
|
|
5
|
+
import { getClassContainerCollectionDes, getClassButtonViewMore, getDescriptionClasses, getShowMoreIconClasses, getShowMoreTextClasses } from '../common/classes.js';
|
|
6
6
|
import { createClass, createStyle, createAttr, If } from '@gem-sdk/system';
|
|
7
7
|
import { getViewLessText, getViewMoreText } from '../common/index.js';
|
|
8
8
|
import { useGpDescription } from '../hook/useDescription.js';
|
|
@@ -18,17 +18,12 @@ const CollectionDescription = ({ setting, builderProps, pageContext, advanced })
|
|
|
18
18
|
const classButtonViewMore = createClass(getClassButtonViewMore({
|
|
19
19
|
setting
|
|
20
20
|
}));
|
|
21
|
-
const gpDescriptionClasses = createClass({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
...open ? {
|
|
28
|
-
'gp-rotate-180': true
|
|
29
|
-
} : {}
|
|
30
|
-
});
|
|
31
|
-
const collapseStyle = createStyle({
|
|
21
|
+
const gpDescriptionClasses = createClass(getDescriptionClasses({
|
|
22
|
+
advanced
|
|
23
|
+
}));
|
|
24
|
+
const showMoreIconClasses = createClass(getShowMoreIconClasses());
|
|
25
|
+
const showMoreTextClasses = createClass(getShowMoreTextClasses());
|
|
26
|
+
const textStyle = createStyle({
|
|
32
27
|
...getDefaultStyleCollectionDes({
|
|
33
28
|
setting
|
|
34
29
|
}),
|
|
@@ -70,7 +65,7 @@ const CollectionDescription = ({ setting, builderProps, pageContext, advanced })
|
|
|
70
65
|
/*#__PURE__*/ jsx("div", {
|
|
71
66
|
ref: ref,
|
|
72
67
|
className: classContainerCollectionDes,
|
|
73
|
-
style:
|
|
68
|
+
style: textStyle,
|
|
74
69
|
dangerouslySetInnerHTML: {
|
|
75
70
|
__html: collection?.descriptionHtml ?? ''
|
|
76
71
|
},
|
|
@@ -82,7 +77,10 @@ const CollectionDescription = ({ setting, builderProps, pageContext, advanced })
|
|
|
82
77
|
style: styleViewMore,
|
|
83
78
|
onClick: handleToggleShowMore,
|
|
84
79
|
children: [
|
|
85
|
-
|
|
80
|
+
/*#__PURE__*/ jsx("span", {
|
|
81
|
+
className: showMoreTextClasses,
|
|
82
|
+
children: If(open, viewLessText?.toString() ?? '', viewMoreText?.toString() ?? '')
|
|
83
|
+
}),
|
|
86
84
|
If(setting?.enableViewMoreIcon, /*#__PURE__*/ jsx("span", {
|
|
87
85
|
className: showMoreIconClasses,
|
|
88
86
|
dangerouslySetInnerHTML: {
|
|
@@ -2,7 +2,7 @@ import { makeStyleResponsive, makeLineClamp, template, isSafari, isLocalEnv, bas
|
|
|
2
2
|
import { getSettingPreloadData } from '../../../../helpers.js';
|
|
3
3
|
import { getDefaultStyleCollectionDes, getStyleDefaultViewMore, getDisplayCollapse, getStaticCss } from '../common/styles.js';
|
|
4
4
|
import { createClass, createStyle, createAttr, createStateOrContext, If, Liquid, LiquidUnless, LiquidIf } from '@gem-sdk/system';
|
|
5
|
-
import { getClassContainerCollectionDes, getClassButtonViewMore } from '../common/classes.js';
|
|
5
|
+
import { getClassContainerCollectionDes, getClassButtonViewMore, getDescriptionClasses, getShowMoreIconClasses, getShowMoreTextClasses } from '../common/classes.js';
|
|
6
6
|
import { getViewLessText, getViewMoreText } from '../common/index.js';
|
|
7
7
|
import { ICON_SVG } from '../common/constant.js';
|
|
8
8
|
|
|
@@ -14,14 +14,12 @@ const CollectionDescription = ({ setting, advanced, builderProps, pageContext })
|
|
|
14
14
|
const classButtonViewMore = createClass(getClassButtonViewMore({
|
|
15
15
|
setting
|
|
16
16
|
}));
|
|
17
|
-
const gpDescriptionClasses = createClass({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
});
|
|
24
|
-
const collapseStyle = createStyle({
|
|
17
|
+
const gpDescriptionClasses = createClass(getDescriptionClasses({
|
|
18
|
+
advanced
|
|
19
|
+
}));
|
|
20
|
+
const showMoreIconClasses = createClass(getShowMoreIconClasses());
|
|
21
|
+
const showMoreTextClasses = createClass(getShowMoreTextClasses());
|
|
22
|
+
const textStyle = createStyle({
|
|
25
23
|
...getDefaultStyleCollectionDes({
|
|
26
24
|
setting,
|
|
27
25
|
renderMaxHeight: true
|
|
@@ -63,7 +61,7 @@ const CollectionDescription = ({ setting, advanced, builderProps, pageContext })
|
|
|
63
61
|
viewLessText: viewLessText,
|
|
64
62
|
enableViewMoreIcon: setting?.enableViewMoreIcon
|
|
65
63
|
},
|
|
66
|
-
|
|
64
|
+
textStyle
|
|
67
65
|
});
|
|
68
66
|
const renderScript = ()=>{
|
|
69
67
|
const jsURL = isLocalEnv ? `{{ 'gp-collection-description.js' | asset_url }}` : `${baseAssetURL}/assets-v2/gp-collection-description.js?v={{ shop.metafields.GEMPAGES.ASSETS_VERSION }}`;
|
|
@@ -77,11 +75,13 @@ const CollectionDescription = ({ setting, advanced, builderProps, pageContext })
|
|
|
77
75
|
>
|
|
78
76
|
<style>${textDescriptionCss}</style>
|
|
79
77
|
${If(!isSafari(), `<style>${gpDescriptionCss}</style>`, ' ')}
|
|
80
|
-
${LiquidUnless('collection', `<p>Collection not found</p>`, template`<div ${textAttr} class="${classContainerCollectionDes}" style="${
|
|
78
|
+
${LiquidUnless('collection', `<p>Collection not found</p>`, template`<div ${textAttr} class="${classContainerCollectionDes}" style="${textStyle}">
|
|
81
79
|
{{collection.description}}
|
|
82
80
|
</div>
|
|
83
81
|
${LiquidIf(hasDescriptionHtml, template`<button type="button" class="${classButtonViewMore}" style="${styleViewMore}">
|
|
82
|
+
<span class="${showMoreTextClasses}">
|
|
84
83
|
${If(pageContext?.isPreviewing, viewMoreText?.toString() || '', `{{${viewMoreText}}}`)}
|
|
84
|
+
</span>
|
|
85
85
|
${If(setting?.enableViewMoreIcon, template`<span class="${showMoreIconClasses}">${ICON_SVG}</span>`, ' ')}
|
|
86
86
|
</button>`)}`)}
|
|
87
87
|
</gp-collection-description>
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { useRef, useState,
|
|
2
|
-
import {
|
|
3
|
-
import { useCollection, useCurrentDevice, getResponsiveValueByScreen, useEditorMode } from '@gem-sdk/core';
|
|
1
|
+
import { useRef, useState, useEffect } from 'react';
|
|
2
|
+
import { useCollection, useCurrentDevice, getResponsiveValueByScreen, useEditorMode, isSafari } from '@gem-sdk/core';
|
|
4
3
|
|
|
5
4
|
const useGpDescription = (setting)=>{
|
|
6
5
|
const ref = useRef(null);
|
|
@@ -11,52 +10,23 @@ const useGpDescription = (setting)=>{
|
|
|
11
10
|
const hasLineClamp = getResponsiveValueByScreen(setting?.hasLineClamp, currentDevice);
|
|
12
11
|
const lineClamp = getResponsiveValueByScreen(setting?.lineClamp, currentDevice);
|
|
13
12
|
const mode = useEditorMode();
|
|
14
|
-
const getLineHeightFromDom = useCallback(()=>{
|
|
15
|
-
if (!ref.current) return DESCRIPTION_LINE_HEIGHT_DEFAULT;
|
|
16
|
-
const lineHeight = window.getComputedStyle(ref.current).getPropertyValue('line-height');
|
|
17
|
-
return Math.ceil(parseFloat(lineHeight));
|
|
18
|
-
}, []);
|
|
19
|
-
const getMaxHeight = useCallback((lineHeight)=>{
|
|
20
|
-
if (!hasLineClamp || !lineClamp) return 'auto';
|
|
21
|
-
if (lineHeight) return `${lineClamp * lineHeight}px`;
|
|
22
|
-
return 'auto';
|
|
23
|
-
}, [
|
|
24
|
-
hasLineClamp,
|
|
25
|
-
lineClamp
|
|
26
|
-
]);
|
|
27
13
|
const handleToggleShowMore = ()=>{
|
|
28
|
-
if (!ref.current) return;
|
|
29
|
-
const lineHeight = getLineHeightFromDom();
|
|
30
|
-
if (open) {
|
|
31
|
-
ref.current.style.maxHeight = getMaxHeight(lineHeight);
|
|
32
|
-
} else {
|
|
33
|
-
ref.current.style.maxHeight = 'none';
|
|
34
|
-
}
|
|
35
14
|
setOpen((prev)=>!prev);
|
|
36
15
|
};
|
|
37
|
-
useEffect(()=>{
|
|
38
|
-
const lineHeight = getLineHeightFromDom();
|
|
39
|
-
getMaxHeight(lineHeight);
|
|
40
|
-
}, [
|
|
41
|
-
setting?.typo?.custom,
|
|
42
|
-
getMaxHeight,
|
|
43
|
-
getLineHeightFromDom
|
|
44
|
-
]);
|
|
45
16
|
useEffect(()=>{
|
|
46
17
|
const dom = ref.current;
|
|
47
18
|
setOpen(false);
|
|
48
|
-
if (
|
|
49
|
-
const enableShowMore = hasLineClamp && collection?.descriptionHtml;
|
|
50
|
-
if (!enableShowMore) dom.style.maxHeight = 'none';
|
|
51
|
-
else {
|
|
19
|
+
if (dom && hasLineClamp && collection?.description) {
|
|
52
20
|
const value = lineClamp;
|
|
53
21
|
setTimeout(()=>{
|
|
54
22
|
const scrollHeight = dom?.scrollHeight ?? 0;
|
|
55
23
|
const clientHeight = dom?.clientHeight ?? 0;
|
|
56
|
-
const lineHeight =
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
const
|
|
24
|
+
const lineHeight = window.getComputedStyle(dom).getPropertyValue('line-height');
|
|
25
|
+
const parsedLineHeight = parseInt(lineHeight, 10) || 1;
|
|
26
|
+
const lineText = Math.round((scrollHeight ?? 0) / parsedLineHeight);
|
|
27
|
+
const isValueExceeded = value !== undefined && value < lineText;
|
|
28
|
+
const isOverflow = clientHeight < scrollHeight;
|
|
29
|
+
const conditionCheckLine = isSafari() ? isValueExceeded : isOverflow;
|
|
60
30
|
if (value && conditionCheckLine) {
|
|
61
31
|
setIsShowViewMore(()=>true);
|
|
62
32
|
} else {
|
|
@@ -67,12 +37,7 @@ const useGpDescription = (setting)=>{
|
|
|
67
37
|
}, [
|
|
68
38
|
hasLineClamp,
|
|
69
39
|
lineClamp,
|
|
70
|
-
collection?.description
|
|
71
|
-
collection?.descriptionHtml,
|
|
72
|
-
getLineHeightFromDom,
|
|
73
|
-
getMaxHeight,
|
|
74
|
-
setOpen,
|
|
75
|
-
setIsShowViewMore
|
|
40
|
+
collection?.description
|
|
76
41
|
]);
|
|
77
42
|
return {
|
|
78
43
|
ref,
|