-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Refactor memoized timeline card elements
- Loading branch information
1 parent
a983df3
commit 0a86716
Showing
13 changed files
with
237 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 4 additions & 2 deletions
6
src/components/timeline-elements/memoized/__tests__/index.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/components/timeline-elements/memoized/details-text-memo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { memo, useCallback, useMemo } from 'react'; | ||
import { hexToRGBA } from '../../../utils'; | ||
import { DetailsTextWrapper } from './../timeline-card-media/timeline-card-media.styles'; | ||
import { DetailsTextMemoModel } from './memoized-model'; | ||
|
||
const DetailsTextMemo = memo<DetailsTextMemoModel>( | ||
({ | ||
theme, | ||
show, | ||
expand, | ||
textOverlay, | ||
text, | ||
height, | ||
onRender, | ||
}: DetailsTextMemoModel) => { | ||
const onTextRef = useCallback((node: HTMLDivElement) => { | ||
if (node) { | ||
onRender?.(node.clientHeight); | ||
} | ||
}, []); | ||
|
||
const Text = text; | ||
|
||
const background = useMemo(() => { | ||
const bg = theme?.cardDetailsBackGround || ''; | ||
if (bg) { | ||
return hexToRGBA(bg, 0.8); | ||
} else { | ||
return bg; | ||
} | ||
}, [theme?.cardDetailsBackGround]); | ||
|
||
return textOverlay ? ( | ||
<DetailsTextWrapper | ||
ref={onTextRef} | ||
// height={expand ? height : 0} | ||
$expandFull={expand} | ||
theme={theme} | ||
$show={show} | ||
background={background} | ||
> | ||
<Text /> | ||
</DetailsTextWrapper> | ||
) : null; | ||
}, | ||
(prev, next) => | ||
prev.height === next.height && | ||
prev.show === next.show && | ||
prev.expand === next.expand && | ||
JSON.stringify(prev.theme) === JSON.stringify(next.theme), | ||
); | ||
|
||
DetailsTextMemo.displayName = 'Details Text'; | ||
|
||
export { DetailsTextMemo }; |
31 changes: 31 additions & 0 deletions
31
src/components/timeline-elements/memoized/expand-button-memo.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { memo, useMemo } from 'react'; | ||
import { MaximizeIcon, MinimizeIcon } from '../../icons'; | ||
import { ExpandButton } from '../timeline-card-media/timeline-card-media-buttons'; | ||
import { ExpandButtonModel } from './memoized-model'; | ||
|
||
const ExpandButtonMemo = memo<ExpandButtonModel>( | ||
({ theme, expanded, onExpand, textOverlay }: ExpandButtonModel) => { | ||
const label = useMemo(() => { | ||
return expanded ? 'Minimize' : 'Maximize'; | ||
}, [expanded]); | ||
|
||
return textOverlay ? ( | ||
<ExpandButton | ||
onPointerDown={onExpand} | ||
onKeyDown={(ev) => ev.key === 'Enter' && onExpand?.(ev)} | ||
theme={theme} | ||
aria-expanded={expanded} | ||
tabIndex={0} | ||
aria-label={label} | ||
title={label} | ||
> | ||
{expanded ? <MinimizeIcon /> : <MaximizeIcon />} | ||
</ExpandButton> | ||
) : null; | ||
}, | ||
(prev, next) => prev.expanded === next.expanded, | ||
); | ||
|
||
ExpandButtonMemo.displayName = 'Expand Button'; | ||
|
||
export { ExpandButtonMemo }; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.