mirror of
https://github.com/hzrd149/nostrudel.git
synced 2025-03-28 18:53:47 +01:00
maybe fix overflow container
This commit is contained in:
parent
44def1d64e
commit
e2d0fa423f
@ -1,5 +1,6 @@
|
|||||||
import styled from "@emotion/styled";
|
import styled from "@emotion/styled";
|
||||||
import { useEffect, useRef } from "react";
|
import { useEffect, useRef } from "react";
|
||||||
|
import { debounce } from "../../helpers/function";
|
||||||
|
|
||||||
const StyledOverflowContainer = styled.div`
|
const StyledOverflowContainer = styled.div`
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -30,7 +31,7 @@ export default function ShowMoreContainer({ children, ...props }: React.HTMLAttr
|
|||||||
const ref = useRef<HTMLDivElement | null>(null);
|
const ref = useRef<HTMLDivElement | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const update = () => {
|
const update = debounce(() => {
|
||||||
if (!ref.current) return;
|
if (!ref.current) return;
|
||||||
|
|
||||||
const innerHeight = Array.from(ref.current.children).reduce(
|
const innerHeight = Array.from(ref.current.children).reduce(
|
||||||
@ -42,7 +43,7 @@ export default function ShowMoreContainer({ children, ...props }: React.HTMLAttr
|
|||||||
// add or remove the "overflow" class
|
// add or remove the "overflow" class
|
||||||
if (innerHeight > height && !ref.current.classList.contains("overflow")) ref.current.classList.add("overflow");
|
if (innerHeight > height && !ref.current.classList.contains("overflow")) ref.current.classList.add("overflow");
|
||||||
else if (ref.current.classList.contains("overflow")) ref.current.classList.remove("overflow");
|
else if (ref.current.classList.contains("overflow")) ref.current.classList.remove("overflow");
|
||||||
};
|
}, 1000 / 60);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
// copied from https://dev.to/bwca/create-a-debounce-function-from-scratch-in-typescript-560m
|
// copied from https://dev.to/bwca/create-a-debounce-function-from-scratch-in-typescript-560m
|
||||||
export function debounce<A = unknown, R = void>(fn: (args: A) => R, ms: number): (args: A) => Promise<R> {
|
export function debounce<A extends unknown[], R = void>(fn: (...args: A) => R, ms: number): (...args: A) => Promise<R> {
|
||||||
let timer: number;
|
let timer: number;
|
||||||
|
|
||||||
const debouncedFunc = (args: A): Promise<R> =>
|
const debouncedFunc = (...args: A): Promise<R> =>
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
if (timer) {
|
if (timer) {
|
||||||
window.clearTimeout(timer);
|
window.clearTimeout(timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
timer = window.setTimeout(() => {
|
timer = window.setTimeout(() => {
|
||||||
resolve(fn(args));
|
resolve(fn(...args));
|
||||||
}, ms);
|
}, ms);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user