Add custom spoiler component

This commit is contained in:
jeffvli 2024-02-02 01:38:58 -08:00
parent 7c25d12639
commit 095edfd49f
4 changed files with 78 additions and 37 deletions

View file

@ -5,3 +5,4 @@ export * from './use-container-query';
export * from './use-fast-average-color';
export * from './use-hide-scrollbar';
export * from './use-app-focus';
export * from './use-is-overflow';

View file

@ -0,0 +1,20 @@
import { MutableRefObject, useState, useLayoutEffect } from 'react';
export const useIsOverflow = (ref: MutableRefObject<HTMLDivElement | null>) => {
const [isOverflow, setIsOverflow] = useState<Boolean | undefined>(undefined);
useLayoutEffect(() => {
const { current } = ref;
const trigger = () => {
const hasOverflow = (current?.scrollHeight || 0) > (current?.clientHeight || 0);
setIsOverflow(hasOverflow);
};
if (current) {
trigger();
}
}, [ref]);
return isOverflow;
};