feat: use opacity for overflowed tags animation
This commit is contained in:
@@ -28,8 +28,6 @@ const NoteTags = observer(({ application, appState }: Props) => {
|
|||||||
|
|
||||||
const [containerHeight, setContainerHeight] =
|
const [containerHeight, setContainerHeight] =
|
||||||
useState(TAGS_ROW_HEIGHT);
|
useState(TAGS_ROW_HEIGHT);
|
||||||
const [tagsContainerHeight, setTagsContainerHeight] =
|
|
||||||
useState(TAGS_ROW_HEIGHT);
|
|
||||||
const [overflowCountPosition, setOverflowCountPosition] = useState(0);
|
const [overflowCountPosition, setOverflowCountPosition] = useState(0);
|
||||||
|
|
||||||
const containerRef = useRef<HTMLDivElement>();
|
const containerRef = useRef<HTMLDivElement>();
|
||||||
@@ -90,13 +88,6 @@ const NoteTags = observer(({ application, appState }: Props) => {
|
|||||||
? tagsContainerRef.current.scrollHeight
|
? tagsContainerRef.current.scrollHeight
|
||||||
: TAGS_ROW_HEIGHT;
|
: TAGS_ROW_HEIGHT;
|
||||||
setContainerHeight(containerHeight);
|
setContainerHeight(containerHeight);
|
||||||
|
|
||||||
const firstTagTop = tagsRef.current[0].getBoundingClientRect().top;
|
|
||||||
const lastTagBottom = tagsRef.current[tagsRef.current.length - 1].getBoundingClientRect().bottom;
|
|
||||||
const tagsContainerHeight = tagsContainerExpanded
|
|
||||||
? lastTagBottom - firstTagTop
|
|
||||||
: TAGS_ROW_HEIGHT;
|
|
||||||
setTagsContainerHeight(tagsContainerHeight);
|
|
||||||
}, [tagsContainerExpanded]);
|
}, [tagsContainerExpanded]);
|
||||||
|
|
||||||
const reloadOverflowCount = useCallback(() => {
|
const reloadOverflowCount = useCallback(() => {
|
||||||
@@ -134,17 +125,21 @@ const NoteTags = observer(({ application, appState }: Props) => {
|
|||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
ref={tagsContainerRef}
|
ref={tagsContainerRef}
|
||||||
className={`absolute flex flex-wrap pl-1 -ml-1 transition-height duration-150 ${
|
className={`absolute flex flex-wrap pl-1 -ml-1 ${
|
||||||
tagsContainerExpanded ? '' : 'overflow-hidden'
|
tagsContainerExpanded ? '' : 'overflow-hidden'
|
||||||
}`}
|
}`}
|
||||||
style={{
|
style={{
|
||||||
maxWidth: tagsContainerMaxWidth,
|
maxWidth: tagsContainerMaxWidth,
|
||||||
height: tagsContainerHeight,
|
height: TAGS_ROW_HEIGHT,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{tags.map((tag: SNTag, index: number) => (
|
{tags.map((tag: SNTag, index: number) => (
|
||||||
<button
|
<button
|
||||||
className={`${tagClass} pl-1 mr-2`}
|
className={`${tagClass} pl-1 mr-2 transition-opacity duration-150 ${
|
||||||
|
isTagOverflowed(tagsRef.current[index])
|
||||||
|
? 'opacity-0'
|
||||||
|
: 'opacity-1'
|
||||||
|
}`}
|
||||||
style={{ maxWidth: tagsContainerMaxWidth }}
|
style={{ maxWidth: tagsContainerMaxWidth }}
|
||||||
ref={(element) => {
|
ref={(element) => {
|
||||||
if (element) {
|
if (element) {
|
||||||
|
|||||||
@@ -244,6 +244,18 @@
|
|||||||
transition-property: height;
|
transition-property: height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.transition-opacity {
|
||||||
|
transition-property: opacity;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opacity-0 {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.opacity-1 {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
|
||||||
.w-80 {
|
.w-80 {
|
||||||
width: 20rem;
|
width: 20rem;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user