mirror of
https://git.rdcenter.ru/RDCenter/skb-kit.git
synced 2026-12-05 03:29:45 +00:00
перенес структуру Севы со своими правками
This commit is contained in:
1 parent
3a1cac0dfe
commit
808d97eb4b
331 files changed
+12260
-19950
No files matched your search
@@ -0,0 +1,36 @@
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
// Тип для параметров IntersectionObserver
|
||||
interface IntersectionObserverOptions {
|
||||
root?: Element | null;
|
||||
rootMargin?: string;
|
||||
threshold?: number | number[];
|
||||
}
|
||||
|
||||
const useElementOnScreen = (options: IntersectionObserverOptions) => {
|
||||
const [ref, setRef] = useState<HTMLElement | null>(null);
|
||||
const [isVisible, setIsVisible] = useState<boolean>(false);
|
||||
|
||||
const observerCallback = (entries: IntersectionObserverEntry[]) => {
|
||||
const [entry] = entries;
|
||||
setIsVisible(entry.isIntersecting);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const observer = new IntersectionObserver(observerCallback, options);
|
||||
|
||||
if (ref) {
|
||||
observer.observe(ref);
|
||||
}
|
||||
|
||||
return () => {
|
||||
if (ref) {
|
||||
observer.unobserve(ref);
|
||||
}
|
||||
};
|
||||
}, [ref, options]);
|
||||
|
||||
return [setRef, isVisible] as const;
|
||||
};
|
||||
|
||||
export default useElementOnScreen;
|
||||
@@ -0,0 +1,34 @@
|
||||
type Mods = Record<string, boolean | string>;
|
||||
|
||||
export function classNames(
|
||||
cls: string,
|
||||
mods?: Mods,
|
||||
additional?: string[] | undefined[],
|
||||
): string {
|
||||
if (additional && mods) {
|
||||
return [
|
||||
cls,
|
||||
...additional.filter(Boolean),
|
||||
Object.entries(mods)
|
||||
.filter(([cls, value]) => Boolean(value))
|
||||
.map(([className, value]) => className)
|
||||
.join(' '),
|
||||
].join(' ');
|
||||
}
|
||||
if (additional && !mods) {
|
||||
return [cls, ...additional.filter(Boolean)].join(' ');
|
||||
}
|
||||
if (!additional && mods) {
|
||||
return [
|
||||
cls,
|
||||
Object.entries(mods)
|
||||
.filter(([cls, value]) => Boolean(value))
|
||||
.map(([className, value]) => className),
|
||||
].join(' ');
|
||||
}
|
||||
return [cls].join(' ');
|
||||
}
|
||||
|
||||
classNames('remove-btn', { hovered: true, selectable: true, red: false }, [
|
||||
'pdg',
|
||||
]);
|
||||
Reference in new issue
Block a user