mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 02:13:33 +00:00
Add custom spoiler component
This commit is contained in:
parent
7c25d12639
commit
095edfd49f
4 changed files with 78 additions and 37 deletions
|
|
@ -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';
|
||||
|
|
|
|||
20
src/renderer/hooks/use-is-overflow.ts
Normal file
20
src/renderer/hooks/use-is-overflow.ts
Normal 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;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue