@chayns-components/core 5.0.0-beta.552 → 5.0.0-beta.554
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/lib/components/truncation/Truncation.js +23 -6
- package/lib/components/truncation/Truncation.js.map +1 -1
- package/lib/components/truncation/Truncation.styles.js +1 -0
- package/lib/components/truncation/Truncation.styles.js.map +1 -1
- package/lib/utils/debounce.d.ts +1 -0
- package/lib/utils/debounce.js +17 -0
- package/lib/utils/debounce.js.map +1 -0
- package/package.json +2 -2
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
2
2
|
import { ClampPosition } from '../../types/truncation';
|
|
3
|
+
import { debounce } from '../../utils/debounce';
|
|
3
4
|
import { truncateElement } from '../../utils/truncation';
|
|
4
5
|
import { StyledMotionTruncationContent, StyledTruncation, StyledTruncationClamp, StyledTruncationClampWrapper, StyledTruncationPseudoContent } from './Truncation.styles';
|
|
5
6
|
const Truncation = _ref => {
|
|
@@ -29,6 +30,8 @@ const Truncation = _ref => {
|
|
|
29
30
|
const originalChildrenRef = useRef(null);
|
|
30
31
|
const hasCollapsed = useRef(false);
|
|
31
32
|
const isAnimating = useRef(false);
|
|
33
|
+
const hasSizeRecentlyChanged = useRef(false);
|
|
34
|
+
const canResetSizeChanged = useRef(true);
|
|
32
35
|
useEffect(() => {
|
|
33
36
|
if (typeof isOpen === 'boolean') {
|
|
34
37
|
setInternalIsOpen(isOpen);
|
|
@@ -46,9 +49,15 @@ const Truncation = _ref => {
|
|
|
46
49
|
});
|
|
47
50
|
}, [onChange]);
|
|
48
51
|
const handleAnimationEnd = useCallback(() => {
|
|
49
|
-
setHasSizeChanged(false);
|
|
50
52
|
hasCollapsed.current = true;
|
|
51
53
|
isAnimating.current = false;
|
|
54
|
+
if (canResetSizeChanged.current) {
|
|
55
|
+
setHasSizeChanged(false);
|
|
56
|
+
canResetSizeChanged.current = false;
|
|
57
|
+
}
|
|
58
|
+
window.setTimeout(() => {
|
|
59
|
+
hasSizeRecentlyChanged.current = false;
|
|
60
|
+
}, 10);
|
|
52
61
|
setShouldShowCollapsedElement(!internalIsOpen);
|
|
53
62
|
window.setTimeout(() => {
|
|
54
63
|
hasCollapsed.current = false;
|
|
@@ -80,14 +89,18 @@ const Truncation = _ref => {
|
|
|
80
89
|
childrenRef.current.children[0].style.visibility = 'visible';
|
|
81
90
|
}
|
|
82
91
|
}, [children, internalIsOpen, shouldShowCollapsedElement]);
|
|
83
|
-
|
|
92
|
+
useLayoutEffect(() => {
|
|
84
93
|
if (originalChildrenRef.current) {
|
|
85
94
|
const resizeObserver = new ResizeObserver(entries => {
|
|
86
95
|
if (entries && entries[0]) {
|
|
87
96
|
const observedHeight = entries[0].contentRect.height;
|
|
88
97
|
setOriginalHeight(observedHeight < originalBigHeight ? originalBigHeight : observedHeight);
|
|
89
|
-
if (!hasCollapsed.current && !isAnimating.current) {
|
|
98
|
+
if (!hasCollapsed.current && !isAnimating.current && !hasSizeRecentlyChanged.current) {
|
|
99
|
+
void debounce(() => {
|
|
100
|
+
canResetSizeChanged.current = true;
|
|
101
|
+
}, 250)();
|
|
90
102
|
setHasSizeChanged(true);
|
|
103
|
+
hasSizeRecentlyChanged.current = true;
|
|
91
104
|
}
|
|
92
105
|
}
|
|
93
106
|
});
|
|
@@ -98,14 +111,18 @@ const Truncation = _ref => {
|
|
|
98
111
|
}
|
|
99
112
|
return () => {};
|
|
100
113
|
}, [originalBigHeight]);
|
|
101
|
-
|
|
114
|
+
useLayoutEffect(() => {
|
|
102
115
|
if (pseudoChildrenRef.current) {
|
|
103
116
|
const resizeObserver = new ResizeObserver(entries => {
|
|
104
117
|
if (entries && entries[0]) {
|
|
105
118
|
const observedHeight = entries[0].contentRect.height;
|
|
106
119
|
setNewCollapsedHeight(observedHeight < originalSmallHeight ? originalSmallHeight : observedHeight);
|
|
107
|
-
if (!hasCollapsed.current && !isAnimating.current) {
|
|
120
|
+
if (!hasCollapsed.current && !isAnimating.current && !hasSizeRecentlyChanged.current) {
|
|
121
|
+
void debounce(() => {
|
|
122
|
+
canResetSizeChanged.current = true;
|
|
123
|
+
}, 250)();
|
|
108
124
|
setHasSizeChanged(true);
|
|
125
|
+
hasSizeRecentlyChanged.current = true;
|
|
109
126
|
}
|
|
110
127
|
}
|
|
111
128
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Truncation.js","names":["React","useCallback","useEffect","useMemo","useRef","useState","ClampPosition","truncateElement","StyledMotionTruncationContent","StyledTruncation","StyledTruncationClamp","StyledTruncationClampWrapper","StyledTruncationPseudoContent","Truncation","_ref","collapsedHeight","clampPosition","Right","isOpen","moreLabel","lessLabel","onChange","children","internalIsOpen","setInternalIsOpen","showClamp","setShowClamp","newCollapsedHeight","setNewCollapsedHeight","originalHeight","setOriginalHeight","shouldShowCollapsedElement","setShouldShowCollapsedElement","hasSizeChanged","setHasSizeChanged","initialRender","setInitialRender","originalSmallHeight","setOriginalSmallHeight","originalBigHeight","setOriginalBigHeight","pseudoChildrenRef","childrenRef","originalChildrenRef","hasCollapsed","isAnimating","handleClampClick","event","current","handleAnimationEnd","window","setTimeout","offsetHeight","firstChild","removeChild","appendChild","style","visibility","resizeObserver","ResizeObserver","entries","observedHeight","contentRect","height","observe","disconnect","createElement","className","ref","animate","initial","transition","type","duration","onAnimationComplete","onAnimationStart","$position","onClick"],"sources":["../../../src/components/truncation/Truncation.tsx"],"sourcesContent":["import React, {\n FC,\n MouseEvent,\n MouseEventHandler,\n ReactElement,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { ClampPosition } from '../../types/truncation';\nimport { truncateElement } from '../../utils/truncation';\nimport {\n StyledMotionTruncationContent,\n StyledTruncation,\n StyledTruncationClamp,\n StyledTruncationClampWrapper,\n StyledTruncationPseudoContent,\n} from './Truncation.styles';\n\nexport type TruncationProps = {\n /**\n * The elements that should be expanding or collapsing.\n */\n children: ReactElement;\n /**\n * The position of the clamp.\n */\n clampPosition?: ClampPosition;\n /**\n * The height of the children Element in it`s collapsed state.\n */\n collapsedHeight?: number;\n /**\n * If set to true, the content is exposed.\n */\n isOpen?: boolean;\n /**\n * A text that should be displayed if the content is expanded.\n */\n lessLabel?: string;\n /**\n * A text that should be displayed if the content is collapsed.\n */\n moreLabel?: string;\n /**\n * Function to be executed when the component is expanding or collapsing.\n */\n onChange?: (event: MouseEvent<HTMLAnchorElement>, isOpen: boolean) => void;\n};\n\nconst Truncation: FC<TruncationProps> = ({\n collapsedHeight = 150,\n clampPosition = ClampPosition.Right,\n isOpen,\n moreLabel = 'Mehr',\n lessLabel = 'Weniger',\n onChange,\n children,\n}) => {\n const [internalIsOpen, setInternalIsOpen] = useState(false);\n const [showClamp, setShowClamp] = useState(true);\n const [newCollapsedHeight, setNewCollapsedHeight] = useState(collapsedHeight);\n const [originalHeight, setOriginalHeight] = useState(0);\n const [shouldShowCollapsedElement, setShouldShowCollapsedElement] = useState(true);\n const [hasSizeChanged, setHasSizeChanged] = useState(false);\n const [initialRender, setInitialRender] = useState(true);\n\n const [originalSmallHeight, setOriginalSmallHeight] = useState(0);\n const [originalBigHeight, setOriginalBigHeight] = useState(0);\n\n useEffect(() => {\n setInitialRender(false);\n }, []);\n\n const pseudoChildrenRef = useRef<HTMLDivElement>(null);\n const childrenRef = useRef<HTMLDivElement>(null);\n const originalChildrenRef = useRef<HTMLDivElement>(null);\n const hasCollapsed = useRef(false);\n const isAnimating = useRef(false);\n\n useEffect(() => {\n if (typeof isOpen === 'boolean') {\n setInternalIsOpen(isOpen);\n setShowClamp(!isOpen);\n }\n }, [isOpen]);\n\n // Changes the state of the truncation\n const handleClampClick = useCallback<MouseEventHandler<HTMLAnchorElement>>(\n (event) => {\n setInternalIsOpen((current) => {\n if (typeof onChange === 'function') {\n onChange(event, !current);\n }\n\n return !current;\n });\n },\n [onChange],\n );\n\n const handleAnimationEnd = useCallback(() => {\n setHasSizeChanged(false);\n hasCollapsed.current = true;\n isAnimating.current = false;\n setShouldShowCollapsedElement(!internalIsOpen);\n\n window.setTimeout(() => {\n hasCollapsed.current = false;\n }, 30);\n }, [internalIsOpen]);\n\n useEffect(() => {\n if (!pseudoChildrenRef.current) {\n return;\n }\n\n setOriginalHeight(pseudoChildrenRef.current.offsetHeight);\n setOriginalBigHeight(pseudoChildrenRef.current.offsetHeight);\n\n truncateElement(pseudoChildrenRef.current, collapsedHeight);\n\n setNewCollapsedHeight(pseudoChildrenRef.current.offsetHeight);\n setOriginalSmallHeight(pseudoChildrenRef.current.offsetHeight);\n }, [collapsedHeight, pseudoChildrenRef]);\n\n // Checks if the clamp should be shown\n useEffect(() => {\n if (pseudoChildrenRef.current && !hasSizeChanged && !initialRender) {\n setShowClamp(originalHeight > newCollapsedHeight);\n }\n }, [collapsedHeight, hasSizeChanged, initialRender, newCollapsedHeight, originalHeight]);\n\n useEffect(() => {\n if (childrenRef.current && pseudoChildrenRef.current && originalChildrenRef.current) {\n while (childrenRef.current.firstChild) {\n childrenRef.current.removeChild(childrenRef.current.firstChild);\n }\n\n childrenRef.current.appendChild(\n shouldShowCollapsedElement && !internalIsOpen\n ? pseudoChildrenRef.current\n : originalChildrenRef.current,\n );\n\n (childrenRef.current.children[0] as HTMLDivElement).style.visibility = 'visible';\n }\n }, [children, internalIsOpen, shouldShowCollapsedElement]);\n\n useEffect(() => {\n if (originalChildrenRef.current) {\n const resizeObserver = new ResizeObserver((entries) => {\n if (entries && entries[0]) {\n const observedHeight = entries[0].contentRect.height;\n\n setOriginalHeight(\n observedHeight < originalBigHeight ? originalBigHeight : observedHeight,\n );\n\n if (!hasCollapsed.current && !isAnimating.current) {\n setHasSizeChanged(true);\n }\n }\n });\n\n resizeObserver.observe(originalChildrenRef.current);\n\n return () => {\n resizeObserver.disconnect();\n };\n }\n\n return () => {};\n }, [originalBigHeight]);\n\n useEffect(() => {\n if (pseudoChildrenRef.current) {\n const resizeObserver = new ResizeObserver((entries) => {\n if (entries && entries[0]) {\n const observedHeight = entries[0].contentRect.height;\n\n setNewCollapsedHeight(\n observedHeight < originalSmallHeight ? originalSmallHeight : observedHeight,\n );\n\n if (!hasCollapsed.current && !isAnimating.current) {\n setHasSizeChanged(true);\n }\n }\n });\n\n resizeObserver.observe(pseudoChildrenRef.current);\n\n return () => {\n resizeObserver.disconnect();\n };\n }\n\n return () => {};\n }, [originalSmallHeight]);\n\n return useMemo(\n () => (\n <StyledTruncation className=\"beta-chayns-truncation\">\n <StyledTruncationPseudoContent ref={pseudoChildrenRef}>\n {children}\n </StyledTruncationPseudoContent>\n <StyledTruncationPseudoContent ref={originalChildrenRef}>\n {children}\n </StyledTruncationPseudoContent>\n <StyledMotionTruncationContent\n animate={{ height: internalIsOpen ? originalHeight : newCollapsedHeight }}\n initial={false}\n transition={{ type: 'tween', duration: hasSizeChanged ? 0 : 0.2 }}\n onAnimationComplete={handleAnimationEnd}\n onAnimationStart={() => {\n isAnimating.current = true;\n }}\n ref={childrenRef}\n />\n {showClamp && (\n <StyledTruncationClampWrapper $position={clampPosition}>\n <StyledTruncationClamp onClick={handleClampClick}>\n {internalIsOpen ? lessLabel : moreLabel}\n </StyledTruncationClamp>\n </StyledTruncationClampWrapper>\n )}\n </StyledTruncation>\n ),\n [\n children,\n clampPosition,\n handleAnimationEnd,\n handleClampClick,\n hasSizeChanged,\n internalIsOpen,\n lessLabel,\n moreLabel,\n newCollapsedHeight,\n originalHeight,\n showClamp,\n ],\n );\n};\n\nexport default Truncation;\n"],"mappings":"AAAA,OAAOA,KAAK,IAKRC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,eAAe,QAAQ,wBAAwB;AACxD,SACIC,6BAA6B,EAC7BC,gBAAgB,EAChBC,qBAAqB,EACrBC,4BAA4B,EAC5BC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BAAgB;IAAC0D,SAAS,EAAC;EAAwB,gBAChDnE,KAAA,CAAAkE,aAAA,CAACtD,6BAA6B;IAACwD,GAAG,EAAE3B;EAAkB,GACjDnB,QAC0B,CAAC,eAChCtB,KAAA,CAAAkE,aAAA,CAACtD,6BAA6B;IAACwD,GAAG,EAAEzB;EAAoB,GACnDrB,QAC0B,CAAC,eAChCtB,KAAA,CAAAkE,aAAA,CAAC1D,6BAA6B;IAC1B6D,OAAO,EAAE;MAAEN,MAAM,EAAExC,cAAc,GAAGM,cAAc,GAAGF;IAAmB,CAAE;IAC1E2C,OAAO,EAAE,KAAM;IACfC,UAAU,EAAE;MAAEC,IAAI,EAAE,OAAO;MAAEC,QAAQ,EAAExC,cAAc,GAAG,CAAC,GAAG;IAAI,CAAE;IAClEyC,mBAAmB,EAAEzB,kBAAmB;IACxC0B,gBAAgB,EAAEA,CAAA,KAAM;MACpB9B,WAAW,CAACG,OAAO,GAAG,IAAI;IAC9B,CAAE;IACFoB,GAAG,EAAE1B;EAAY,CACpB,CAAC,EACDjB,SAAS,iBACNzB,KAAA,CAAAkE,aAAA,CAACvD,4BAA4B;IAACiE,SAAS,EAAE5D;EAAc,gBACnDhB,KAAA,CAAAkE,aAAA,CAACxD,qBAAqB;IAACmE,OAAO,EAAE/B;EAAiB,GAC5CvB,cAAc,GAAGH,SAAS,GAAGD,SACX,CACG,CAEpB,CACrB,EACD,CACIG,QAAQ,EACRN,aAAa,EACbiC,kBAAkB,EAClBH,gBAAgB,EAChBb,cAAc,EACdV,cAAc,EACdH,SAAS,EACTD,SAAS,EACTQ,kBAAkB,EAClBE,cAAc,EACdJ,SAAS,CAEjB,CAAC;AACL,CAAC;AAED,eAAeZ,UAAU"}
|
|
1
|
+
{"version":3,"file":"Truncation.js","names":["React","useCallback","useEffect","useLayoutEffect","useMemo","useRef","useState","ClampPosition","debounce","truncateElement","StyledMotionTruncationContent","StyledTruncation","StyledTruncationClamp","StyledTruncationClampWrapper","StyledTruncationPseudoContent","Truncation","_ref","collapsedHeight","clampPosition","Right","isOpen","moreLabel","lessLabel","onChange","children","internalIsOpen","setInternalIsOpen","showClamp","setShowClamp","newCollapsedHeight","setNewCollapsedHeight","originalHeight","setOriginalHeight","shouldShowCollapsedElement","setShouldShowCollapsedElement","hasSizeChanged","setHasSizeChanged","initialRender","setInitialRender","originalSmallHeight","setOriginalSmallHeight","originalBigHeight","setOriginalBigHeight","pseudoChildrenRef","childrenRef","originalChildrenRef","hasCollapsed","isAnimating","hasSizeRecentlyChanged","canResetSizeChanged","handleClampClick","event","current","handleAnimationEnd","window","setTimeout","offsetHeight","firstChild","removeChild","appendChild","style","visibility","resizeObserver","ResizeObserver","entries","observedHeight","contentRect","height","observe","disconnect","createElement","className","ref","animate","initial","transition","type","duration","onAnimationComplete","onAnimationStart","$position","onClick"],"sources":["../../../src/components/truncation/Truncation.tsx"],"sourcesContent":["import React, {\n FC,\n MouseEvent,\n MouseEventHandler,\n ReactElement,\n useCallback,\n useEffect,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { ClampPosition } from '../../types/truncation';\nimport { debounce } from '../../utils/debounce';\nimport { truncateElement } from '../../utils/truncation';\nimport {\n StyledMotionTruncationContent,\n StyledTruncation,\n StyledTruncationClamp,\n StyledTruncationClampWrapper,\n StyledTruncationPseudoContent,\n} from './Truncation.styles';\n\nexport type TruncationProps = {\n /**\n * The elements that should be expanding or collapsing.\n */\n children: ReactElement;\n /**\n * The position of the clamp.\n */\n clampPosition?: ClampPosition;\n /**\n * The height of the children Element in it`s collapsed state.\n */\n collapsedHeight?: number;\n /**\n * If set to true, the content is exposed.\n */\n isOpen?: boolean;\n /**\n * A text that should be displayed if the content is expanded.\n */\n lessLabel?: string;\n /**\n * A text that should be displayed if the content is collapsed.\n */\n moreLabel?: string;\n /**\n * Function to be executed when the component is expanding or collapsing.\n */\n onChange?: (event: MouseEvent<HTMLAnchorElement>, isOpen: boolean) => void;\n};\n\nconst Truncation: FC<TruncationProps> = ({\n collapsedHeight = 150,\n clampPosition = ClampPosition.Right,\n isOpen,\n moreLabel = 'Mehr',\n lessLabel = 'Weniger',\n onChange,\n children,\n}) => {\n const [internalIsOpen, setInternalIsOpen] = useState(false);\n const [showClamp, setShowClamp] = useState(true);\n const [newCollapsedHeight, setNewCollapsedHeight] = useState(collapsedHeight);\n const [originalHeight, setOriginalHeight] = useState(0);\n const [shouldShowCollapsedElement, setShouldShowCollapsedElement] = useState(true);\n const [hasSizeChanged, setHasSizeChanged] = useState(false);\n const [initialRender, setInitialRender] = useState(true);\n\n const [originalSmallHeight, setOriginalSmallHeight] = useState(0);\n const [originalBigHeight, setOriginalBigHeight] = useState(0);\n\n useEffect(() => {\n setInitialRender(false);\n }, []);\n\n const pseudoChildrenRef = useRef<HTMLDivElement>(null);\n const childrenRef = useRef<HTMLDivElement>(null);\n const originalChildrenRef = useRef<HTMLDivElement>(null);\n const hasCollapsed = useRef(false);\n const isAnimating = useRef(false);\n const hasSizeRecentlyChanged = useRef(false);\n const canResetSizeChanged = useRef(true);\n\n useEffect(() => {\n if (typeof isOpen === 'boolean') {\n setInternalIsOpen(isOpen);\n setShowClamp(!isOpen);\n }\n }, [isOpen]);\n\n // Changes the state of the truncation\n const handleClampClick = useCallback<MouseEventHandler<HTMLAnchorElement>>(\n (event) => {\n setInternalIsOpen((current) => {\n if (typeof onChange === 'function') {\n onChange(event, !current);\n }\n\n return !current;\n });\n },\n [onChange],\n );\n\n const handleAnimationEnd = useCallback(() => {\n hasCollapsed.current = true;\n isAnimating.current = false;\n\n if (canResetSizeChanged.current) {\n setHasSizeChanged(false);\n canResetSizeChanged.current = false;\n }\n\n window.setTimeout(() => {\n hasSizeRecentlyChanged.current = false;\n }, 10);\n\n setShouldShowCollapsedElement(!internalIsOpen);\n\n window.setTimeout(() => {\n hasCollapsed.current = false;\n }, 30);\n }, [internalIsOpen]);\n\n useEffect(() => {\n if (!pseudoChildrenRef.current) {\n return;\n }\n\n setOriginalHeight(pseudoChildrenRef.current.offsetHeight);\n setOriginalBigHeight(pseudoChildrenRef.current.offsetHeight);\n\n truncateElement(pseudoChildrenRef.current, collapsedHeight);\n\n setNewCollapsedHeight(pseudoChildrenRef.current.offsetHeight);\n setOriginalSmallHeight(pseudoChildrenRef.current.offsetHeight);\n }, [collapsedHeight, pseudoChildrenRef]);\n\n // Checks if the clamp should be shown\n useEffect(() => {\n if (pseudoChildrenRef.current && !hasSizeChanged && !initialRender) {\n setShowClamp(originalHeight > newCollapsedHeight);\n }\n }, [collapsedHeight, hasSizeChanged, initialRender, newCollapsedHeight, originalHeight]);\n\n useEffect(() => {\n if (childrenRef.current && pseudoChildrenRef.current && originalChildrenRef.current) {\n while (childrenRef.current.firstChild) {\n childrenRef.current.removeChild(childrenRef.current.firstChild);\n }\n\n childrenRef.current.appendChild(\n shouldShowCollapsedElement && !internalIsOpen\n ? pseudoChildrenRef.current\n : originalChildrenRef.current,\n );\n\n (childrenRef.current.children[0] as HTMLDivElement).style.visibility = 'visible';\n }\n }, [children, internalIsOpen, shouldShowCollapsedElement]);\n\n useLayoutEffect(() => {\n if (originalChildrenRef.current) {\n const resizeObserver = new ResizeObserver((entries) => {\n if (entries && entries[0]) {\n const observedHeight = entries[0].contentRect.height;\n\n setOriginalHeight(\n observedHeight < originalBigHeight ? originalBigHeight : observedHeight,\n );\n\n if (\n !hasCollapsed.current &&\n !isAnimating.current &&\n !hasSizeRecentlyChanged.current\n ) {\n void debounce(() => {\n canResetSizeChanged.current = true;\n }, 250)();\n\n setHasSizeChanged(true);\n hasSizeRecentlyChanged.current = true;\n }\n }\n });\n\n resizeObserver.observe(originalChildrenRef.current);\n\n return () => {\n resizeObserver.disconnect();\n };\n }\n\n return () => {};\n }, [originalBigHeight]);\n\n useLayoutEffect(() => {\n if (pseudoChildrenRef.current) {\n const resizeObserver = new ResizeObserver((entries) => {\n if (entries && entries[0]) {\n const observedHeight = entries[0].contentRect.height;\n\n setNewCollapsedHeight(\n observedHeight < originalSmallHeight ? originalSmallHeight : observedHeight,\n );\n\n if (\n !hasCollapsed.current &&\n !isAnimating.current &&\n !hasSizeRecentlyChanged.current\n ) {\n void debounce(() => {\n canResetSizeChanged.current = true;\n }, 250)();\n\n setHasSizeChanged(true);\n hasSizeRecentlyChanged.current = true;\n }\n }\n });\n\n resizeObserver.observe(pseudoChildrenRef.current);\n\n return () => {\n resizeObserver.disconnect();\n };\n }\n\n return () => {};\n }, [originalSmallHeight]);\n\n return useMemo(\n () => (\n <StyledTruncation className=\"beta-chayns-truncation\">\n <StyledTruncationPseudoContent ref={pseudoChildrenRef}>\n {children}\n </StyledTruncationPseudoContent>\n <StyledTruncationPseudoContent ref={originalChildrenRef}>\n {children}\n </StyledTruncationPseudoContent>\n <StyledMotionTruncationContent\n animate={{ height: internalIsOpen ? originalHeight : newCollapsedHeight }}\n initial={false}\n transition={{ type: 'tween', duration: hasSizeChanged ? 0 : 0.2 }}\n onAnimationComplete={handleAnimationEnd}\n onAnimationStart={() => {\n isAnimating.current = true;\n }}\n ref={childrenRef}\n />\n {showClamp && (\n <StyledTruncationClampWrapper $position={clampPosition}>\n <StyledTruncationClamp onClick={handleClampClick}>\n {internalIsOpen ? lessLabel : moreLabel}\n </StyledTruncationClamp>\n </StyledTruncationClampWrapper>\n )}\n </StyledTruncation>\n ),\n [\n children,\n clampPosition,\n handleAnimationEnd,\n handleClampClick,\n hasSizeChanged,\n internalIsOpen,\n lessLabel,\n moreLabel,\n newCollapsedHeight,\n originalHeight,\n showClamp,\n ],\n );\n};\n\nexport default Truncation;\n"],"mappings":"AAAA,OAAOA,KAAK,IAKRC,WAAW,EACXC,SAAS,EACTC,eAAe,EACfC,OAAO,EACPC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAASC,aAAa,QAAQ,wBAAwB;AACtD,SAASC,QAAQ,QAAQ,sBAAsB;AAC/C,SAASC,eAAe,QAAQ,wBAAwB;AACxD,SACIC,6BAA6B,EAC7BC,gBAAgB,EAChBC,qBAAqB,EACrBC,4BAA4B,E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AAA,KAAM;MACpBhC,WAAW,CAACK,OAAO,GAAG,IAAI;IAC9B,CAAE;IACFoB,GAAG,EAAE5B;EAAY,CACpB,CAAC,EACDjB,SAAS,iBACN3B,KAAA,CAAAsE,aAAA,CAACzD,4BAA4B;IAACmE,SAAS,EAAE9D;EAAc,gBACnDlB,KAAA,CAAAsE,aAAA,CAAC1D,qBAAqB;IAACqE,OAAO,EAAE/B;EAAiB,GAC5CzB,cAAc,GAAGH,SAAS,GAAGD,SACX,CACG,CAEpB,CACrB,EACD,CACIG,QAAQ,EACRN,aAAa,EACbmC,kBAAkB,EAClBH,gBAAgB,EAChBf,cAAc,EACdV,cAAc,EACdH,SAAS,EACTD,SAAS,EACTQ,kBAAkB,EAClBE,cAAc,EACdJ,SAAS,CAEjB,CAAC;AACL,CAAC;AAED,eAAeZ,UAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Truncation.styles.js","names":["motion","styled","css","ClampPosition","StyledTruncation","div","StyledMotionTruncationContent","StyledTruncationPseudoContent","StyledTruncationClampWrapper","_ref","$position","Left","Middle","StyledTruncationClamp","a"],"sources":["../../../src/components/truncation/Truncation.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport { ClampPosition } from '../../types/truncation';\nimport type { FramerMotionBugFix, WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport const StyledTruncation = styled.div`\n position: relative;\n`;\n\n// Fix framer-motion bug\nexport const StyledMotionTruncationContent = styled(motion.div)<FramerMotionBugFix>`\n overflow: hidden;\n`;\n\nexport const StyledTruncationPseudoContent = styled.div`\n visibility: hidden;\n position: absolute;\n width: fit-content;\n`;\n\ntype StyledTruncationClampWrapperProps = WithTheme<{ $position: ClampPosition }>;\n\nexport const StyledTruncationClampWrapper = styled.div<StyledTruncationClampWrapperProps>`\n display: flex;\n\n ${({ $position }) => {\n switch ($position) {\n case ClampPosition.Left:\n return css`\n justify-content: left;\n `;\n case ClampPosition.Middle:\n return css`\n justify-content: center;\n `;\n default:\n return css`\n justify-content: right;\n `;\n }\n }}\n`;\n\nexport const StyledTruncationClamp = styled.a`\n cursor: pointer;\n z-index: 2;\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAC/C,SAASC,aAAa,QAAQ,wBAAwB;AAGtD,OAAO,MAAMC,gBAAgB,GAAGH,MAAM,CAACI,GAAI;AAC3C;AACA,CAAC;;AAED;AACA,OAAO,MAAMC,6BAA6B,GAAGL,MAAM,CAACD,MAAM,CAACK,GAAG,CAAsB;AACpF;AACA,CAAC;AAED,OAAO,MAAME,6BAA6B,GAAGN,MAAM,CAACI,GAAI;AACxD;AACA;AACA;AACA,CAAC;AAID,OAAO,MAAMG,4BAA4B,GAAGP,MAAM,CAACI,GAAuC;AAC1F;AACA;AACA,MAAMI,IAAA,IAAmB;EAAA,IAAlB;IAAEC;EAAU,CAAC,GAAAD,IAAA;EACZ,QAAQC,SAAS;IACb,KAAKP,aAAa,CAACQ,IAAI;MACnB,OAAOT,GAAI;AAC3B;AACA,iBAAiB;IACL,KAAKC,aAAa,CAACS,MAAM;MACrB,OAAOV,GAAI;AAC3B;AACA,iBAAiB;IACL;MACI,OAAOA,GAAI;AAC3B;AACA,iBAAiB;EACT;AACJ,CAAE;AACN,CAAC;AAED,OAAO,MAAMW,qBAAqB,GAAGZ,MAAM,CAACa,CAAE;AAC9C;AACA;AACA,CAAC"}
|
|
1
|
+
{"version":3,"file":"Truncation.styles.js","names":["motion","styled","css","ClampPosition","StyledTruncation","div","StyledMotionTruncationContent","StyledTruncationPseudoContent","StyledTruncationClampWrapper","_ref","$position","Left","Middle","StyledTruncationClamp","a"],"sources":["../../../src/components/truncation/Truncation.styles.ts"],"sourcesContent":["import { motion } from 'framer-motion';\nimport styled, { css } from 'styled-components';\nimport { ClampPosition } from '../../types/truncation';\nimport type { FramerMotionBugFix, WithTheme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport const StyledTruncation = styled.div`\n position: relative;\n overflow: hidden;\n`;\n\n// Fix framer-motion bug\nexport const StyledMotionTruncationContent = styled(motion.div)<FramerMotionBugFix>`\n overflow: hidden;\n`;\n\nexport const StyledTruncationPseudoContent = styled.div`\n visibility: hidden;\n position: absolute;\n width: fit-content;\n`;\n\ntype StyledTruncationClampWrapperProps = WithTheme<{ $position: ClampPosition }>;\n\nexport const StyledTruncationClampWrapper = styled.div<StyledTruncationClampWrapperProps>`\n display: flex;\n\n ${({ $position }) => {\n switch ($position) {\n case ClampPosition.Left:\n return css`\n justify-content: left;\n `;\n case ClampPosition.Middle:\n return css`\n justify-content: center;\n `;\n default:\n return css`\n justify-content: right;\n `;\n }\n }}\n`;\n\nexport const StyledTruncationClamp = styled.a`\n cursor: pointer;\n z-index: 2;\n`;\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,IAAIC,GAAG,QAAQ,mBAAmB;AAC/C,SAASC,aAAa,QAAQ,wBAAwB;AAGtD,OAAO,MAAMC,gBAAgB,GAAGH,MAAM,CAACI,GAAI;AAC3C;AACA;AACA,CAAC;;AAED;AACA,OAAO,MAAMC,6BAA6B,GAAGL,MAAM,CAACD,MAAM,CAACK,GAAG,CAAsB;AACpF;AACA,CAAC;AAED,OAAO,MAAME,6BAA6B,GAAGN,MAAM,CAACI,GAAI;AACxD;AACA;AACA;AACA,CAAC;AAID,OAAO,MAAMG,4BAA4B,GAAGP,MAAM,CAACI,GAAuC;AAC1F;AACA;AACA,MAAMI,IAAA,IAAmB;EAAA,IAAlB;IAAEC;EAAU,CAAC,GAAAD,IAAA;EACZ,QAAQC,SAAS;IACb,KAAKP,aAAa,CAACQ,IAAI;MACnB,OAAOT,GAAI;AAC3B;AACA,iBAAiB;IACL,KAAKC,aAAa,CAACS,MAAM;MACrB,OAAOV,GAAI;AAC3B;AACA,iBAAiB;IACL;MACI,OAAOA,GAAI;AAC3B;AACA,iBAAiB;EACT;AACJ,CAAE;AACN,CAAC;AAED,OAAO,MAAMW,qBAAqB,GAAGZ,MAAM,CAACa,CAAE;AAC9C;AACA;AACA,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const debounce: <F extends (...args: any[]) => any>(func: F, waitFor: number) => (...args: Parameters<F>) => Promise<ReturnType<F>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export const debounce = (func, waitFor) => {
|
|
2
|
+
let timeout;
|
|
3
|
+
return function () {
|
|
4
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
5
|
+
args[_key] = arguments[_key];
|
|
6
|
+
}
|
|
7
|
+
return new Promise(resolve => {
|
|
8
|
+
if (timeout) {
|
|
9
|
+
clearTimeout(timeout);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
13
|
+
timeout = setTimeout(() => resolve(func(...args)), waitFor);
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=debounce.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debounce.js","names":["debounce","func","waitFor","timeout","_len","arguments","length","args","Array","_key","Promise","resolve","clearTimeout","setTimeout"],"sources":["../../src/utils/debounce.ts"],"sourcesContent":["export const debounce = <F extends (...args: any[]) => any>(func: F, waitFor: number) => {\n let timeout: string | number | NodeJS.Timeout | undefined;\n\n return (...args: Parameters<F>): Promise<ReturnType<F>> =>\n new Promise((resolve) => {\n if (timeout) {\n clearTimeout(timeout);\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n timeout = setTimeout(() => resolve(func(...args)), waitFor);\n });\n};\n"],"mappings":"AAAA,OAAO,MAAMA,QAAQ,GAAGA,CAAoCC,IAAO,EAAEC,OAAe,KAAK;EACrF,IAAIC,OAAqD;EAEzD,OAAO;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAIC,IAAI,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAAJF,IAAI,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IAAA,OACX,IAAIC,OAAO,CAAEC,OAAO,IAAK;MACrB,IAAIR,OAAO,EAAE;QACTS,YAAY,CAACT,OAAO,CAAC;MACzB;;MAEA;MACAA,OAAO,GAAGU,UAAU,CAAC,MAAMF,OAAO,CAACV,IAAI,CAAC,GAAGM,IAAI,CAAC,CAAC,EAAEL,OAAO,CAAC;IAC/D,CAAC,CAAC;EAAA;AACV,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chayns-components/core",
|
|
3
|
-
"version": "5.0.0-beta.
|
|
3
|
+
"version": "5.0.0-beta.554",
|
|
4
4
|
"description": "A set of beautiful React components for developing your own applications with chayns.",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"browserslist": [
|
|
@@ -73,5 +73,5 @@
|
|
|
73
73
|
"publishConfig": {
|
|
74
74
|
"access": "public"
|
|
75
75
|
},
|
|
76
|
-
"gitHead": "
|
|
76
|
+
"gitHead": "c4b48186ce2303f0ed5e2eb63bd07483bfbc914a"
|
|
77
77
|
}
|