Skip to content

Commit 994c55c

Browse files
authored
Make collapseAnimationTime local (#164)
1 parent 56d386f commit 994c55c

File tree

4 files changed

+10
-23
lines changed

4 files changed

+10
-23
lines changed

src/CollectionNode.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,8 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
6363

6464
const startCollapsed = collapseFilter(incomingNodeData)
6565

66-
const { contentRef, isAnimating, maxHeight, collapsed, animateCollapse } = useCollapseTransition(
67-
data,
68-
collapseAnimationTime,
69-
startCollapsed,
70-
mainContainerRef
71-
)
66+
const { contentRef, isAnimating, maxHeight, collapsed, animateCollapse, cssTransitionValue } =
67+
useCollapseTransition(data, collapseAnimationTime, startCollapsed, mainContainerRef)
7268

7369
const {
7470
pathString,
@@ -462,7 +458,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
462458
<div className="jer-collection-name">
463459
<div
464460
className={`jer-collapse-icon jer-accordion-icon${collapsed ? ' jer-rotate-90' : ''}`}
465-
style={{ zIndex: 11 + nodeData.level * 2 }}
461+
style={{ zIndex: 11 + nodeData.level * 2, transition: cssTransitionValue }}
466462
onClick={(e) => handleCollapse(e)}
467463
>
468464
<Icon name="chevron" rotate={collapsed} nodeData={nodeData} />
@@ -480,7 +476,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
480476
{!isEditing && showCount && (
481477
<div
482478
className={`jer-collection-item-count${showCount ? ' jer-visible' : ' jer-hidden'}`}
483-
style={getStyles('itemCount', nodeData)}
479+
style={{ ...getStyles('itemCount', nodeData), transition: cssTransitionValue }}
484480
>
485481
{size === 1
486482
? translate('ITEM_SINGLE', { ...nodeData, size: 1 }, 1)
@@ -489,7 +485,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
489485
)}
490486
<div
491487
className={`jer-brackets${isCollapsed ? ' jer-visible' : ' jer-hidden'}`}
492-
style={getStyles('bracket', nodeData)}
488+
style={{ ...getStyles('bracket', nodeData), transition: cssTransitionValue }}
493489
>
494490
{brackets.close}
495491
</div>
@@ -510,6 +506,7 @@ export const CollectionNode: React.FC<CollectionNodeProps> = (props) => {
510506
// Prevent collapse if this node or any children are being edited
511507
maxHeight: childrenEditing ? undefined : maxHeight,
512508
...getStyles('collectionInner', nodeData),
509+
transition: cssTransitionValue,
513510
}}
514511
ref={contentRef}
515512
>

src/JsonEditor.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,15 +376,8 @@ export const JsonEditor: React.FC<JsonEditorProps> = (props) => {
376376
setDocRoot(root)
377377
}, [])
378378

379-
const { collapseAnimationTime = 300 } = props
380-
381379
if (!docRoot) return null
382380

383-
const transitionTime = getComputedStyle(docRoot).getPropertyValue('--jer-expand-transition-time')
384-
if (parseFloat(transitionTime) * 1000 !== collapseAnimationTime) {
385-
docRoot.style.setProperty('--jer-expand-transition-time', `${collapseAnimationTime / 1000}s`)
386-
}
387-
388381
return (
389382
<ThemeProvider theme={props.theme ?? defaultTheme} icons={props.icons} docRoot={docRoot}>
390383
<TreeStateProvider>

src/hooks/useCollapseTransition.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ export const useCollapseTransition = (
6262
const prevHeight = useRef<string | number>(0)
6363
const timerId = useRef<number>()
6464

65+
const cssTransitionValue = `${collapseAnimationTime / 1000}s`
66+
6567
// Method to change the collapse state and manage the animated transition
6668
const animateCollapse = (collapse: boolean) => {
6769
if (collapsed === collapse) return
@@ -98,6 +100,7 @@ export const useCollapseTransition = (
98100
animateCollapse,
99101
maxHeight,
100102
collapsed,
103+
cssTransitionValue,
101104
}
102105
}
103106

src/style.css

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,15 @@
44
--jer-select-arrow: #777;
55
--jer-form-border: 1px solid #ededf0;
66
--jer-form-border-focus: 1px solid #e2e2e2;
7-
--jer-expand-transition-time: 0.3s;
87
--jer-highlight-color: #b3d8ff;
98
}
109

1110
.jer-visible {
1211
opacity: 1;
13-
transition: var(--jer-expand-transition-time);
1412
}
1513

1614
.jer-hidden {
1715
opacity: 0;
18-
transition: var(--jer-expand-transition-time);
1916
}
2017

2118
/* Select styled as per:
@@ -157,7 +154,6 @@ select:focus + .focus {
157154

158155
.jer-collection-inner {
159156
position: relative;
160-
transition: var(--jer-expand-transition-time);
161157
}
162158

163159
.jer-collection-text-edit {
@@ -339,7 +335,7 @@ select:focus + .focus {
339335

340336
.jer-copy-pulse {
341337
position: relative;
342-
transition: transform var(--jer-expand-transition-time);
338+
transition: 0.3s;
343339
}
344340

345341
.jer-copy-pulse:hover {
@@ -378,12 +374,10 @@ select:focus + .focus {
378374

379375
.jer-rotate-90 {
380376
transform: rotate(-90deg);
381-
transition: transform var(--jer-expand-transition-time);
382377
}
383378

384379
.jer-accordion-icon {
385380
/* font-size: '2em'; */
386-
transition: transform var(--jer-expand-transition-time);
387381
}
388382

389383
.jer-icon:hover {

0 commit comments

Comments
 (0)