@gem-sdk/components 4.0.7 → 4.0.9
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var React=require("react"),helpers=require("../common/helpers.js"),core=require("@gem-sdk/core");const useGpDescription=e=>{let t=React.useRef(null),[r,c]=React.useState(!1),[s
|
|
1
|
+
"use strict";var React=require("react"),helpers=require("../common/helpers.js"),core=require("@gem-sdk/core");const useGpDescription=e=>{let t=React.useRef(null),[r,c]=React.useState(!1),[i,s]=React.useState(!1),u=core.useProduct(),o=core.useCurrentDevice(),n=core.getResponsiveValueByScreen(e?.hasLineClamp,o),l=core.getResponsiveValueByScreen(e?.lineClamp,o),{redirectProductShopifyLink:a}=core.useProductShopifyEditLink(),p=core.useEditorMode(),h=React.useCallback(()=>{if(!t.current)return helpers.DESCRIPTION_LINE_HEIGHT_DEFAULT;let e=window.getComputedStyle(t.current).getPropertyValue("line-height");return Math.ceil(parseFloat(e))},[]),d=React.useCallback(e=>n&&l&&e?`${l*e}px`:"auto",[n,l]),g=()=>{if(!t.current)return;let e=h();r?t.current.style.maxHeight=d(e):t.current.style.maxHeight="none",c(e=>!e)};return React.useEffect(()=>{let e=h();d(e)},[e?.typo?.custom,d,h]),React.useEffect(()=>{let e=t.current;if(c(!1),!e)return;let r=n&&u?.descriptionHtml;r?setTimeout(()=>{let t=e?.scrollHeight??0,r=e?.clientHeight??0,c=r<t,i=window.getComputedStyle(e).getPropertyValue("line-height"),u=parseInt(i,10)||1,o=Math.round((t??0)/u),n=void 0!==l&&l<o,a=core.isSafari()?n:c;e.style.maxHeight=d(u),l&&a?s(()=>!0):s(()=>!1)},100):e.style.maxHeight="none"},[n,l,u?.description,u?.descriptionHtml,h,d,c,s]),{ref:t,open:r,isShowViewMore:i,handleToggleShowMore:g,mode:p,redirectProductShopifyLink:a}};exports.useGpDescription=useGpDescription;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useRef as e,useState as t,useCallback as r,useEffect as i}from"react";import{DESCRIPTION_LINE_HEIGHT_DEFAULT as l}from"../common/helpers.js";import{useProduct as n,useCurrentDevice as o,getResponsiveValueByScreen as
|
|
1
|
+
import{useRef as e,useState as t,useCallback as r,useEffect as i}from"react";import{DESCRIPTION_LINE_HEIGHT_DEFAULT as l}from"../common/helpers.js";import{useProduct as n,useCurrentDevice as o,getResponsiveValueByScreen as p,useProductShopifyEditLink as u,useEditorMode as m,isSafari as s}from"@gem-sdk/core";let useGpDescription=c=>{let a=e(null),[h,g]=t(!1),[d,y]=t(!1),H=n(),f=o(),x=p(c?.hasLineClamp,f),w=p(c?.lineClamp,f),{redirectProductShopifyLink:C}=u(),D=m(),G=r(()=>{if(!a.current)return l;let e=window.getComputedStyle(a.current).getPropertyValue("line-height");return Math.ceil(parseFloat(e))},[]),M=r(e=>x&&w&&e?`${w*e}px`:"auto",[x,w]),P=()=>{if(!a.current)return;let e=G();h?a.current.style.maxHeight=M(e):a.current.style.maxHeight="none",g(e=>!e)};return i(()=>{let e=G();M(e)},[c?.typo?.custom,M,G]),i(()=>{let e=a.current;if(g(!1),!e)return;let t=x&&H?.descriptionHtml;t?setTimeout(()=>{let t=e?.scrollHeight??0,r=e?.clientHeight??0,i=r<t,l=window.getComputedStyle(e).getPropertyValue("line-height"),n=parseInt(l,10)||1,o=Math.round((t??0)/n),p=void 0!==w&&w<o,u=s()?p:i;e.style.maxHeight=M(n),w&&u?y(()=>!0):y(()=>!1)},100):e.style.maxHeight="none"},[x,w,H?.description,H?.descriptionHtml,G,M,g,y]),{ref:a,open:h,isShowViewMore:d,handleToggleShowMore:P,mode:D,redirectProductShopifyLink:C}};export{useGpDescription};
|