mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-08 04:50:12 +02:00
Add custom spoiler component
This commit is contained in:
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
Reference in New Issue
Block a user