@kadoui/react 1.4.10 → 1.5.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -8
- package/dist/components/AccessNavigation/AccessNavigation.jsx +0 -26
- package/dist/components/Accordion/AccordionBody.jsx +0 -14
- package/dist/components/Accordion/AccordionRoot.jsx +0 -9
- package/dist/components/Accordion/AccordionToggle.jsx +0 -11
- package/dist/components/Affix/Affix.jsx +0 -35
- package/dist/components/Breadcrumbs/BreadcrumbsItem.jsx +0 -10
- package/dist/components/Breadcrumbs/BreadcrumbsRoot.jsx +0 -7
- package/dist/components/Carousel/CarouselContainer.jsx +0 -9
- package/dist/components/Carousel/CarouselLeftFade.jsx +0 -10
- package/dist/components/Carousel/CarouselRightFade.jsx +0 -10
- package/dist/components/Carousel/CarouselRoot.jsx +0 -40
- package/dist/components/ClientOnly/ClientOnly.jsx +0 -6
- package/dist/components/Clipboard/Clipboard.jsx +0 -12
- package/dist/components/ContextMenu/ContextMenuContent.jsx +0 -29
- package/dist/components/ContextMenu/ContextMenuRoot.jsx +0 -56
- package/dist/components/Drawer/DrawerBody.jsx +0 -38
- package/dist/components/Drawer/DrawerPortal.jsx +0 -19
- package/dist/components/Drawer/DrawerRoot.jsx +0 -35
- package/dist/components/Drawer/DrawerToggle.jsx +0 -10
- package/dist/components/Dropdown/Dropdown.d.ts +0 -8
- package/dist/components/Dropdown/Dropdown.d.ts.map +0 -1
- package/dist/components/Dropdown/Dropdown.js +0 -7
- package/dist/components/Dropdown/DropdownContext.d.ts +0 -9
- package/dist/components/Dropdown/DropdownContext.d.ts.map +0 -1
- package/dist/components/Dropdown/DropdownContext.js +0 -2
- package/dist/components/Dropdown/DropdownMenu.d.ts +0 -6
- package/dist/components/Dropdown/DropdownMenu.d.ts.map +0 -1
- package/dist/components/Dropdown/DropdownMenu.jsx +0 -12
- package/dist/components/Dropdown/DropdownRoot.d.ts +0 -6
- package/dist/components/Dropdown/DropdownRoot.d.ts.map +0 -1
- package/dist/components/Dropdown/DropdownRoot.jsx +0 -63
- package/dist/components/Dropdown/DropdownToggle.d.ts +0 -4
- package/dist/components/Dropdown/DropdownToggle.d.ts.map +0 -1
- package/dist/components/Dropdown/DropdownToggle.jsx +0 -11
- package/dist/components/LoaderLink/LoaderLink.jsx +0 -6
- package/dist/components/Modal/ModalBody.jsx +0 -21
- package/dist/components/Modal/ModalContent.jsx +0 -3
- package/dist/components/Modal/ModalHeader.jsx +0 -3
- package/dist/components/Modal/ModalPortal.jsx +0 -19
- package/dist/components/Modal/ModalRoot.jsx +0 -35
- package/dist/components/Modal/ModalTrigger.jsx +0 -10
- package/dist/components/Otp/OtpHiddenInput.jsx +0 -7
- package/dist/components/Otp/OtpInputs.jsx +0 -54
- package/dist/components/Otp/OtpRoot.jsx +0 -15
- package/dist/components/Pagination/PaginationContext.jsx +0 -2
- package/dist/components/Pagination/PaginationCounts.jsx +0 -9
- package/dist/components/Pagination/PaginationNextBtn.jsx +0 -10
- package/dist/components/Pagination/PaginationPrevBtn.jsx +0 -10
- package/dist/components/Pagination/PaginationSearchParamsRoot.jsx +0 -30
- package/dist/components/Pagination/PaginationStateRoot.jsx +0 -11
- package/dist/components/PasswordInput/PasswordInputContext.jsx +0 -2
- package/dist/components/PasswordInput/PasswordInputField.jsx +0 -7
- package/dist/components/PasswordInput/PasswordInputRoot.jsx +0 -9
- package/dist/components/PasswordInput/PasswordInputToggle.jsx +0 -12
- package/dist/components/Popover/PopoverBody.jsx +0 -12
- package/dist/components/Popover/PopoverMenu.d.ts +0 -6
- package/dist/components/Popover/PopoverMenu.d.ts.map +0 -1
- package/dist/components/Popover/PopoverMenu.jsx +0 -12
- package/dist/components/Popover/PopoverRoot.jsx +0 -75
- package/dist/components/Popover/PopoverToggle.jsx +0 -13
- package/dist/components/Portal/Portal.jsx +0 -7
- package/dist/components/Progress/ProgressBar.jsx +0 -11
- package/dist/components/Progress/ProgressRoot.jsx +0 -7
- package/dist/components/QrCode/QrCode.jsx +0 -14
- package/dist/components/Rating/RatingItems.jsx +0 -14
- package/dist/components/Rating/RatingRoot.jsx +0 -9
- package/dist/components/Sheet/SheetBody.jsx +0 -20
- package/dist/components/Sheet/SheetContent.jsx +0 -3
- package/dist/components/Sheet/SheetHeader.jsx +0 -10
- package/dist/components/Sheet/SheetPortal.jsx +0 -16
- package/dist/components/Sheet/SheetRoot.jsx +0 -36
- package/dist/components/Sheet/SheetToggle.jsx +0 -10
- package/dist/components/ShowMore/ShowMoreContent.jsx +0 -20
- package/dist/components/ShowMore/ShowMoreFade.jsx +0 -7
- package/dist/components/ShowMore/ShowMoreRoot.jsx +0 -22
- package/dist/components/ShowMore/ShowMoreTrigger.jsx +0 -13
- package/dist/components/Slide/Slide.d.ts +0 -12
- package/dist/components/Slide/Slide.d.ts.map +0 -1
- package/dist/components/Slide/Slide.js +0 -11
- package/dist/components/Slide/SlideBody.d.ts +0 -4
- package/dist/components/Slide/SlideBody.d.ts.map +0 -1
- package/dist/components/Slide/SlideBody.jsx +0 -3
- package/dist/components/Slide/SlideContext.d.ts +0 -7
- package/dist/components/Slide/SlideContext.d.ts.map +0 -1
- package/dist/components/Slide/SlideContext.js +0 -5
- package/dist/components/Slide/SlideHeader.d.ts +0 -4
- package/dist/components/Slide/SlideHeader.d.ts.map +0 -1
- package/dist/components/Slide/SlideHeader.jsx +0 -3
- package/dist/components/Slide/SlidePortal.d.ts +0 -4
- package/dist/components/Slide/SlidePortal.d.ts.map +0 -1
- package/dist/components/Slide/SlidePortal.jsx +0 -11
- package/dist/components/Slide/SlideRoot.d.ts +0 -6
- package/dist/components/Slide/SlideRoot.d.ts.map +0 -1
- package/dist/components/Slide/SlideRoot.jsx +0 -35
- package/dist/components/Slide/SlideToggle.d.ts +0 -4
- package/dist/components/Slide/SlideToggle.d.ts.map +0 -1
- package/dist/components/Slide/SlideToggle.jsx +0 -10
- package/dist/components/Spoiler/SpoilerBlur.jsx +0 -8
- package/dist/components/Spoiler/SpoilerRoot.jsx +0 -10
- package/dist/components/Steps/StepsContext.jsx +0 -2
- package/dist/components/Steps/StepsControls.d.ts +0 -4
- package/dist/components/Steps/StepsControls.d.ts.map +0 -1
- package/dist/components/Steps/StepsControls.jsx +0 -34
- package/dist/components/Steps/StepsIndexBtn.jsx +0 -10
- package/dist/components/Steps/StepsNextBtn.jsx +0 -10
- package/dist/components/Steps/StepsPrevBtn.jsx +0 -10
- package/dist/components/Steps/StepsRender.jsx +0 -7
- package/dist/components/Steps/StepsSearchParamsRoot.jsx +0 -30
- package/dist/components/Steps/StepsStateRoot.jsx +0 -11
- package/dist/components/Swap/SwapItem.jsx +0 -5
- package/dist/components/Swap/SwapRoot.jsx +0 -16
- package/dist/components/Swap/SwapTrigger.jsx +0 -16
- package/dist/components/Tabs/TabsList.jsx +0 -4
- package/dist/components/Tabs/TabsPanel.jsx +0 -8
- package/dist/components/Tabs/TabsRoot.jsx +0 -7
- package/dist/components/Tabs/TabsTab.jsx +0 -10
- package/dist/components/Toast/Toast.d.ts +0 -4
- package/dist/components/Toast/Toast.d.ts.map +0 -1
- package/dist/components/Toast/Toast.js +0 -3
- package/dist/components/Toast/ToastBox.d.ts +0 -6
- package/dist/components/Toast/ToastBox.d.ts.map +0 -1
- package/dist/components/Toast/ToastBox.jsx +0 -32
- package/dist/components/Toast/ToastRoot.d.ts +0 -15
- package/dist/components/Toast/ToastRoot.d.ts.map +0 -1
- package/dist/components/Toast/ToastRoot.jsx +0 -38
- package/dist/components/Toast/toastStore.d.ts +0 -11
- package/dist/components/Toast/toastStore.d.ts.map +0 -1
- package/dist/components/Toast/toastStore.js +0 -10
- package/dist/components/Toggle/Toggle.d.ts +0 -6
- package/dist/components/Toggle/Toggle.d.ts.map +0 -1
- package/dist/components/Toggle/Toggle.js +0 -5
- package/dist/components/Toggle/ToggleContext.d.ts +0 -8
- package/dist/components/Toggle/ToggleContext.d.ts.map +0 -1
- package/dist/components/Toggle/ToggleContext.js +0 -2
- package/dist/components/Toggle/ToggleRoot.d.ts +0 -8
- package/dist/components/Toggle/ToggleRoot.d.ts.map +0 -1
- package/dist/components/Toggle/ToggleRoot.jsx +0 -13
- package/dist/components/Toggle/ToggleSwitch.d.ts +0 -4
- package/dist/components/Toggle/ToggleSwitch.d.ts.map +0 -1
- package/dist/components/Toggle/ToggleSwitch.jsx +0 -23
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kadoui/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.12",
|
|
4
4
|
"description": "Kadoui primitive components for React",
|
|
5
5
|
"author": "ArrowUp",
|
|
6
6
|
"license": "MIT",
|
|
@@ -9,13 +9,9 @@
|
|
|
9
9
|
"build": "tsc"
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
},
|
|
16
|
-
"./utils": {
|
|
17
|
-
"import": "./dist/utils.js",
|
|
18
|
-
"require": "./dist/utils.js"
|
|
12
|
+
"exports": {
|
|
13
|
+
".": "./dist/index.js",
|
|
14
|
+
"./utils": "./dist/utils.js"
|
|
19
15
|
}
|
|
20
16
|
},
|
|
21
17
|
"keywords": [
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { selectAccessibleChildren } from "../../utils";
|
|
3
|
-
export function AccessNavigation({ direction = "y", dir, onKeyDown, ...p }) {
|
|
4
|
-
const handleKeyDown = (ev) => {
|
|
5
|
-
const focusableChildren = selectAccessibleChildren(ev.currentTarget);
|
|
6
|
-
if (!focusableChildren.length) {
|
|
7
|
-
return;
|
|
8
|
-
}
|
|
9
|
-
const currentDir = (dir || document.documentElement.getAttribute("dir") || "ltr");
|
|
10
|
-
const currentIndex = focusableChildren.findIndex((item) => item === document.activeElement);
|
|
11
|
-
if (ev.key === (direction === "y" ? "ArrowDown" : (currentDir === "ltr" ? "ArrowRight" : "ArrowLeft"))) {
|
|
12
|
-
ev.preventDefault();
|
|
13
|
-
const nextIndex = currentIndex === -1 || currentIndex === focusableChildren.length - 1 ? 0 : currentIndex + 1;
|
|
14
|
-
focusableChildren[nextIndex]?.focus();
|
|
15
|
-
}
|
|
16
|
-
if (ev.key === (direction === "y" ? "ArrowUp" : (currentDir === "ltr" ? "ArrowLeft" : "ArrowRight"))) {
|
|
17
|
-
ev.preventDefault();
|
|
18
|
-
const prevIndex = currentIndex <= 0 ? focusableChildren.length - 1 : currentIndex - 1;
|
|
19
|
-
focusableChildren[prevIndex]?.focus();
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
return (<div dir={dir} onKeyDown={ev => {
|
|
23
|
-
onKeyDown?.(ev);
|
|
24
|
-
handleKeyDown(ev);
|
|
25
|
-
}} {...p}/>);
|
|
26
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { AnimatePresence, motion } from "framer-motion";
|
|
4
|
-
import { AccordionContext } from "./AccordionContext";
|
|
5
|
-
export function AccordionBody({ children, ...props }) {
|
|
6
|
-
const { isOpen } = use(AccordionContext);
|
|
7
|
-
return (<AnimatePresence>
|
|
8
|
-
{isOpen ?
|
|
9
|
-
<motion.div initial={{ height: 0, opacity: 0 }} animate={{ height: "auto", opacity: 1 }} exit={{ height: 0, opacity: 0 }} {...props}>
|
|
10
|
-
{children}
|
|
11
|
-
</motion.div>
|
|
12
|
-
: null}
|
|
13
|
-
</AnimatePresence>);
|
|
14
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { AccordionContext } from "./AccordionContext";
|
|
4
|
-
export function AccordionRoot({ children }) {
|
|
5
|
-
const [isOpen, setOpen] = useState(false);
|
|
6
|
-
return (<AccordionContext value={{ isOpen, setOpen }}>
|
|
7
|
-
{children}
|
|
8
|
-
</AccordionContext>);
|
|
9
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { cn } from "../../utils";
|
|
4
|
-
import { AccordionContext } from "./AccordionContext";
|
|
5
|
-
export function AccordionToggle({ className, onClick, ...props }) {
|
|
6
|
-
const { isOpen, setOpen } = use(AccordionContext);
|
|
7
|
-
return (<button onClick={ev => {
|
|
8
|
-
onClick?.(ev);
|
|
9
|
-
setOpen(prev => !prev);
|
|
10
|
-
}} className={cn(isOpen ? "accordion-active" : null, className)} {...props}/>);
|
|
11
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useState, useEffect } from "react";
|
|
3
|
-
import { cn } from "../../utils";
|
|
4
|
-
export const Affix = ({ className, onClick, ...p }) => {
|
|
5
|
-
const [isVisible, setIsVisible] = useState(false);
|
|
6
|
-
const [lastScrollY, setLastScrollY] = useState(0);
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const handleScroll = () => {
|
|
9
|
-
const currentScrollY = window.scrollY;
|
|
10
|
-
const viewportHeight = window.innerHeight;
|
|
11
|
-
const scrollThreshold = viewportHeight * 0.5;
|
|
12
|
-
if (currentScrollY > scrollThreshold && currentScrollY > lastScrollY) {
|
|
13
|
-
setIsVisible(true);
|
|
14
|
-
}
|
|
15
|
-
else if (currentScrollY < lastScrollY && currentScrollY < scrollThreshold) {
|
|
16
|
-
setIsVisible(false);
|
|
17
|
-
}
|
|
18
|
-
setLastScrollY(currentScrollY);
|
|
19
|
-
};
|
|
20
|
-
window.addEventListener("scroll", handleScroll, {
|
|
21
|
-
passive: true
|
|
22
|
-
});
|
|
23
|
-
return () => window.removeEventListener("scroll", handleScroll);
|
|
24
|
-
}, [lastScrollY]);
|
|
25
|
-
const scrollToTop = () => {
|
|
26
|
-
window.scrollTo({
|
|
27
|
-
top: 0,
|
|
28
|
-
behavior: "smooth"
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
return (<button onClick={ev => {
|
|
32
|
-
onClick?.(ev);
|
|
33
|
-
scrollToTop();
|
|
34
|
-
}} className={cn(isVisible ? "affix-active" : null, className)} {...p}/>);
|
|
35
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { BreadcrumbsContext } from "./BreadcrumbsContext";
|
|
4
|
-
export function BreadcrumbsItem({ isLast = false, children, ...p }) {
|
|
5
|
-
const { separator } = use(BreadcrumbsContext);
|
|
6
|
-
return (<div {...p}>
|
|
7
|
-
{children}
|
|
8
|
-
{!isLast && separator}
|
|
9
|
-
</div>);
|
|
10
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { CarouselContext } from "./CarouselContext";
|
|
4
|
-
export function CarouselContainer({ children, ...p }) {
|
|
5
|
-
const { scrollRef } = use(CarouselContext);
|
|
6
|
-
return (<div ref={scrollRef} {...p}>
|
|
7
|
-
{children}
|
|
8
|
-
</div>);
|
|
9
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { CarouselContext } from "./CarouselContext";
|
|
4
|
-
export function CarouselLeftFade({ style, ...p }) {
|
|
5
|
-
const { leftOpacity } = use(CarouselContext);
|
|
6
|
-
return (<div style={{
|
|
7
|
-
opacity: leftOpacity,
|
|
8
|
-
...style
|
|
9
|
-
}} {...p}/>);
|
|
10
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { CarouselContext } from "./CarouselContext";
|
|
4
|
-
export function CarouselRightFade({ style, ...p }) {
|
|
5
|
-
const { rightOpacity } = use(CarouselContext);
|
|
6
|
-
return (<div style={{
|
|
7
|
-
opacity: rightOpacity,
|
|
8
|
-
...style
|
|
9
|
-
}} {...p}/>);
|
|
10
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { CarouselContext } from "./CarouselContext";
|
|
4
|
-
export function CarouselRoot(p) {
|
|
5
|
-
const scrollRef = useRef(null);
|
|
6
|
-
const [leftOpacity, setLeftOpacity] = useState(0);
|
|
7
|
-
const [rightOpacity, setRightOpacity] = useState(1);
|
|
8
|
-
const updateFade = () => {
|
|
9
|
-
const el = scrollRef.current;
|
|
10
|
-
if (!el)
|
|
11
|
-
return;
|
|
12
|
-
const { scrollLeft, scrollWidth, clientWidth } = el;
|
|
13
|
-
const maxScroll = scrollWidth - clientWidth;
|
|
14
|
-
if (maxScroll <= 0) {
|
|
15
|
-
setLeftOpacity(0);
|
|
16
|
-
setRightOpacity(0);
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
const scrollRatio = Math.abs(+(scrollLeft / maxScroll));
|
|
20
|
-
const left = Math.min(1, scrollRatio * 2);
|
|
21
|
-
const right = Math.min(1, (1 - scrollRatio) * 2);
|
|
22
|
-
setLeftOpacity(+left.toFixed(1));
|
|
23
|
-
setRightOpacity(+right.toFixed(1));
|
|
24
|
-
};
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
const el = scrollRef.current;
|
|
27
|
-
if (!el)
|
|
28
|
-
return;
|
|
29
|
-
updateFade();
|
|
30
|
-
el.addEventListener("scroll", updateFade);
|
|
31
|
-
window.addEventListener("resize", updateFade);
|
|
32
|
-
return () => {
|
|
33
|
-
el.removeEventListener("scroll", updateFade);
|
|
34
|
-
window.removeEventListener("resize", updateFade);
|
|
35
|
-
};
|
|
36
|
-
}, []);
|
|
37
|
-
return (<CarouselContext value={{ scrollRef, leftOpacity, rightOpacity }}>
|
|
38
|
-
<div {...p}/>
|
|
39
|
-
</CarouselContext>);
|
|
40
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useClipboard } from "@mantine/hooks";
|
|
3
|
-
export function Clipboard({ copiedChildren, onClick, children, text, timeout = 3_000, ...props }) {
|
|
4
|
-
const { copy, copied } = useClipboard({ timeout });
|
|
5
|
-
const handleClick = (ev) => {
|
|
6
|
-
onClick?.(ev);
|
|
7
|
-
copy(text.trim());
|
|
8
|
-
};
|
|
9
|
-
return (<button aria-label={text} onClick={handleClick} {...props}>
|
|
10
|
-
{copiedChildren && copied ? copiedChildren : children}
|
|
11
|
-
</button>);
|
|
12
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use, useEffect } from "react";
|
|
3
|
-
import { cn } from "../../utils";
|
|
4
|
-
import { selectAccessibleChildren } from "../../utils";
|
|
5
|
-
import { ContextMenuContext } from "./ContextMenuContext";
|
|
6
|
-
export function ContextMenuContent({ onContextMenu, className, ...p }) {
|
|
7
|
-
const { contentRef, position, isOpen } = use(ContextMenuContext);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (!contentRef.current) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
if (isOpen) {
|
|
13
|
-
const children = selectAccessibleChildren(contentRef.current);
|
|
14
|
-
const firstChild = children[0];
|
|
15
|
-
if (!firstChild) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
firstChild.focus();
|
|
19
|
-
}
|
|
20
|
-
}, [isOpen, position, contentRef]);
|
|
21
|
-
return (<div ref={contentRef} onContextMenu={ev => {
|
|
22
|
-
ev.stopPropagation();
|
|
23
|
-
ev.preventDefault();
|
|
24
|
-
onContextMenu?.(ev);
|
|
25
|
-
}} className={cn(isOpen ? "context-menu-active" : null, className)} style={{
|
|
26
|
-
top: position?.y,
|
|
27
|
-
left: position?.x,
|
|
28
|
-
}} {...p}/>);
|
|
29
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
-
import { getBrowserScrollbarWith } from "../../utils";
|
|
4
|
-
import { ContextMenuContext } from "./ContextMenuContext";
|
|
5
|
-
export function ContextMenuRoot({ onContextMenu, ...p }) {
|
|
6
|
-
const [position, setPosition] = useState(undefined);
|
|
7
|
-
const [isOpen, setOpen] = useState(false);
|
|
8
|
-
const contentRef = useRef(null);
|
|
9
|
-
const handleClickOutside = useCallback((ev) => {
|
|
10
|
-
if (!contentRef.current?.contains(ev.target)) {
|
|
11
|
-
setOpen(false);
|
|
12
|
-
setPosition(undefined);
|
|
13
|
-
}
|
|
14
|
-
}, []);
|
|
15
|
-
useEffect(() => {
|
|
16
|
-
document.addEventListener("click", handleClickOutside);
|
|
17
|
-
return () => document.removeEventListener("click", handleClickOutside);
|
|
18
|
-
}, [handleClickOutside]);
|
|
19
|
-
useEffect(() => {
|
|
20
|
-
const scrollbarWidth = getBrowserScrollbarWith();
|
|
21
|
-
if (isOpen) {
|
|
22
|
-
document.body.style.overflow = "hidden";
|
|
23
|
-
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
document.body.style.overflow = "unset";
|
|
27
|
-
document.body.style.paddingRight = "0px";
|
|
28
|
-
}
|
|
29
|
-
;
|
|
30
|
-
}, [isOpen]);
|
|
31
|
-
const handleContextMenu = (ev) => {
|
|
32
|
-
if (!contentRef.current)
|
|
33
|
-
return;
|
|
34
|
-
ev.preventDefault();
|
|
35
|
-
const viewportWidth = window.innerWidth;
|
|
36
|
-
const viewportHeight = window.innerHeight;
|
|
37
|
-
const menuWidth = contentRef.current.scrollWidth;
|
|
38
|
-
const menuHeight = contentRef.current.scrollHeight;
|
|
39
|
-
let x = ev.clientX;
|
|
40
|
-
let y = ev.clientY;
|
|
41
|
-
if (x + menuWidth > viewportWidth) {
|
|
42
|
-
x = viewportWidth - menuWidth - 10;
|
|
43
|
-
}
|
|
44
|
-
if (y + menuHeight > viewportHeight) {
|
|
45
|
-
y = viewportHeight - menuHeight - 10;
|
|
46
|
-
}
|
|
47
|
-
setPosition({ x, y });
|
|
48
|
-
setOpen(true);
|
|
49
|
-
};
|
|
50
|
-
return (<ContextMenuContext value={{ contentRef, isOpen, position }}>
|
|
51
|
-
<div onContextMenu={ev => {
|
|
52
|
-
onContextMenu?.(ev);
|
|
53
|
-
handleContextMenu(ev);
|
|
54
|
-
}} {...p}/>
|
|
55
|
-
</ContextMenuContext>);
|
|
56
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { motion } from "framer-motion";
|
|
3
|
-
import { use, useEffect, useRef } from "react";
|
|
4
|
-
import { DrawerContext } from "./DrawerContext";
|
|
5
|
-
export function DrawerBody({ position, dir, children, ...p }) {
|
|
6
|
-
const { isOpen } = use(DrawerContext);
|
|
7
|
-
const bodyRef = useRef(null);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (isOpen) {
|
|
10
|
-
const indexElement = bodyRef.current?.querySelector("[data-drawer='index']");
|
|
11
|
-
indexElement?.focus();
|
|
12
|
-
}
|
|
13
|
-
;
|
|
14
|
-
}, [isOpen]);
|
|
15
|
-
const currentDir = (dir || document.documentElement.getAttribute("dir") || "ltr");
|
|
16
|
-
const currentPosition = position || (currentDir === "ltr" ? "left" : "right");
|
|
17
|
-
const direction = ["right", "left"].includes(currentPosition) ? "y" : "x";
|
|
18
|
-
const width = direction === "y" ? "clamp(300px,30%,30%)" : undefined;
|
|
19
|
-
const height = direction === "y" ? undefined : "50%";
|
|
20
|
-
return (<motion.div ref={bodyRef} onClick={ev => ev.stopPropagation()} initial={direction === "y"
|
|
21
|
-
? { x: currentPosition === "left" ? "-100%" : "100%" }
|
|
22
|
-
: { y: currentPosition === "top" ? "-100%" : "100%" }} animate={{ y: 0, x: 0 }} exit={direction === "y"
|
|
23
|
-
? { x: currentPosition === "left" ? "-100%" : "100%" }
|
|
24
|
-
: { y: currentPosition === "top" ? "-100%" : "100%" }} style={{
|
|
25
|
-
width,
|
|
26
|
-
height,
|
|
27
|
-
...(currentPosition === "top"
|
|
28
|
-
? { top: 0, left: 0, right: 0 }
|
|
29
|
-
: currentPosition === "right"
|
|
30
|
-
? { top: 0, bottom: 0, right: 0 }
|
|
31
|
-
: currentPosition === "bottom"
|
|
32
|
-
? { bottom: 0, left: 0, right: 0 }
|
|
33
|
-
: { top: 0, bottom: 0, left: 0 })
|
|
34
|
-
}} transition={{ ease: "easeInOut" }} {...p}>
|
|
35
|
-
{children}
|
|
36
|
-
</motion.div>);
|
|
37
|
-
}
|
|
38
|
-
;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { motion, AnimatePresence } from "framer-motion";
|
|
4
|
-
import { Portal } from "../Portal/Portal";
|
|
5
|
-
import { DrawerContext } from "./DrawerContext";
|
|
6
|
-
import { ClientOnly } from "../ClientOnly/ClientOnly";
|
|
7
|
-
export function DrawerPortal({ onClick, ...p }) {
|
|
8
|
-
const { isOpen, setOpen } = use(DrawerContext);
|
|
9
|
-
return (<ClientOnly>
|
|
10
|
-
<Portal>
|
|
11
|
-
<AnimatePresence>
|
|
12
|
-
{isOpen ? (<motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} exit={{ opacity: 0 }} onClick={ev => {
|
|
13
|
-
onClick?.(ev);
|
|
14
|
-
setOpen(false);
|
|
15
|
-
}} {...p}/>) : null}
|
|
16
|
-
</AnimatePresence>
|
|
17
|
-
</Portal>
|
|
18
|
-
</ClientOnly>);
|
|
19
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { getBrowserScrollbarWith } from "../../utils";
|
|
3
|
-
import { useState, useEffect } from "react";
|
|
4
|
-
import { DrawerContext } from "./DrawerContext";
|
|
5
|
-
export function DrawerRoot({ children }) {
|
|
6
|
-
const [isOpen, setOpen] = useState(false);
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
const handleEscape = (ev) => {
|
|
9
|
-
if (ev.key === "Escape") {
|
|
10
|
-
setOpen(false);
|
|
11
|
-
}
|
|
12
|
-
;
|
|
13
|
-
};
|
|
14
|
-
document.addEventListener("keydown", handleEscape);
|
|
15
|
-
return () => {
|
|
16
|
-
document.removeEventListener("keydown", handleEscape);
|
|
17
|
-
document.body.style.overflow = "unset";
|
|
18
|
-
};
|
|
19
|
-
}, []);
|
|
20
|
-
useEffect(() => {
|
|
21
|
-
const scrollbarWidth = getBrowserScrollbarWith();
|
|
22
|
-
if (isOpen) {
|
|
23
|
-
document.body.style.overflow = "hidden";
|
|
24
|
-
document.body.style.paddingRight = `${scrollbarWidth}px`;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
document.body.style.overflow = "unset";
|
|
28
|
-
document.body.style.paddingRight = "0px";
|
|
29
|
-
}
|
|
30
|
-
;
|
|
31
|
-
}, [isOpen]);
|
|
32
|
-
return (<DrawerContext value={{ isOpen, setOpen }}>
|
|
33
|
-
{children}
|
|
34
|
-
</DrawerContext>);
|
|
35
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { DrawerContext } from "./DrawerContext";
|
|
4
|
-
export function DrawerToggle({ onClick, ...props }) {
|
|
5
|
-
const { setOpen } = use(DrawerContext);
|
|
6
|
-
return (<button onClick={(ev) => {
|
|
7
|
-
onClick?.(ev);
|
|
8
|
-
setOpen(prev => !prev);
|
|
9
|
-
}} {...props}/>);
|
|
10
|
-
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { DropdownMenu } from "./DropdownMenu";
|
|
2
|
-
import { DropdownRoot } from "./DropdownRoot";
|
|
3
|
-
import { DropdownToggle } from "./DropdownToggle";
|
|
4
|
-
export declare const Dropdown: typeof DropdownRoot & {
|
|
5
|
-
Toggle: typeof DropdownToggle;
|
|
6
|
-
Menu: typeof DropdownMenu;
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=Dropdown.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Dropdown.d.ts","sourceRoot":"","sources":["../../../src/components/Dropdown/Dropdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,eAAO,MAAM,QAAQ;;;CAGnB,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Dispatch, RefObject, SetStateAction } from "react";
|
|
2
|
-
export type DropdownContextT = {
|
|
3
|
-
isOpen: boolean;
|
|
4
|
-
setOpen: Dispatch<SetStateAction<boolean>>;
|
|
5
|
-
toggleRef: RefObject<HTMLButtonElement | null>;
|
|
6
|
-
menuRef: RefObject<HTMLDivElement | null>;
|
|
7
|
-
};
|
|
8
|
-
export declare const DropdownContext: import("react").Context<DropdownContextT>;
|
|
9
|
-
//# sourceMappingURL=DropdownContext.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownContext.d.ts","sourceRoot":"","sources":["../../../src/components/Dropdown/DropdownContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiB,QAAQ,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE3E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3C,SAAS,EAAE,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,CAAC;IAC/C,OAAO,EAAE,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;CAC3C,CAAA;AAED,eAAO,MAAM,eAAe,2CAA0D,CAAC"}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { HTMLAttributes } from "react";
|
|
2
|
-
export type DropdownMenuPropsT = HTMLAttributes<HTMLDivElement> & {
|
|
3
|
-
preventClose?: boolean;
|
|
4
|
-
};
|
|
5
|
-
export declare function DropdownMenu({ preventClose, onClick, ...p }: DropdownMenuPropsT): import("react").JSX.Element | null;
|
|
6
|
-
//# sourceMappingURL=DropdownMenu.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownMenu.d.ts","sourceRoot":"","sources":["../../../src/components/Dropdown/DropdownMenu.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAO,MAAM,OAAO,CAAC;AAI5C,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG;IAChE,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAA;AAED,wBAAgB,YAAY,CAAC,EAAE,YAAY,EAAE,OAAO,EAAE,GAAG,CAAC,EAAE,EAAE,kBAAkB,sCAkB/E"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { DropdownContext } from "./DropdownContext";
|
|
4
|
-
export function DropdownMenu({ preventClose, onClick, ...p }) {
|
|
5
|
-
const { menuRef, isOpen } = use(DropdownContext);
|
|
6
|
-
return (isOpen ? (<div ref={menuRef} onClick={ev => {
|
|
7
|
-
if (preventClose) {
|
|
8
|
-
ev.stopPropagation();
|
|
9
|
-
}
|
|
10
|
-
onClick?.(ev);
|
|
11
|
-
}} {...p}/>) : null);
|
|
12
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { HTMLAttributes } from "react";
|
|
2
|
-
export type DropdownRootPropsT = HTMLAttributes<HTMLDivElement> & {
|
|
3
|
-
accessHorizontalArrows?: "ArrowRight" | "ArrowLeft";
|
|
4
|
-
};
|
|
5
|
-
export declare function DropdownRoot({ accessHorizontalArrows, onKeyDown, ...p }: DropdownRootPropsT): import("react").JSX.Element;
|
|
6
|
-
//# sourceMappingURL=DropdownRoot.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownRoot.d.ts","sourceRoot":"","sources":["../../../src/components/Dropdown/DropdownRoot.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAA8C,MAAM,OAAO,CAAC;AAOnF,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC,cAAc,CAAC,GAAG;IAChE,sBAAsB,CAAC,EAAE,YAAY,GAAG,WAAW,CAAC;CACrD,CAAA;AAED,wBAAgB,YAAY,CAAC,EAAE,sBAAsB,EAAE,SAAS,EAAE,GAAG,CAAC,EAAE,EAAE,kBAAkB,+BA0E3F"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { useEffect, useRef, useState } from "react";
|
|
3
|
-
import { selectAccessibleChildren } from "../../utils";
|
|
4
|
-
import { DropdownContext } from "./DropdownContext";
|
|
5
|
-
export function DropdownRoot({ accessHorizontalArrows, onKeyDown, ...p }) {
|
|
6
|
-
const [isOpen, setOpen] = useState(false);
|
|
7
|
-
const toggleRef = useRef(null);
|
|
8
|
-
const menuRef = useRef(null);
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
const closeHandler = () => {
|
|
11
|
-
setOpen(false);
|
|
12
|
-
};
|
|
13
|
-
window.addEventListener("click", closeHandler);
|
|
14
|
-
return () => window.removeEventListener("click", closeHandler);
|
|
15
|
-
}, []);
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (isOpen) {
|
|
18
|
-
selectFirstMenuChild();
|
|
19
|
-
}
|
|
20
|
-
}, [isOpen]);
|
|
21
|
-
const selectFirstMenuChild = () => {
|
|
22
|
-
if (!menuRef.current) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const children = selectAccessibleChildren(menuRef.current);
|
|
26
|
-
const firstChild = children[0];
|
|
27
|
-
if (!firstChild) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
firstChild.focus();
|
|
31
|
-
};
|
|
32
|
-
const handleKeyDown = (ev) => {
|
|
33
|
-
if (!accessHorizontalArrows) {
|
|
34
|
-
return null;
|
|
35
|
-
}
|
|
36
|
-
if (ev.key === "ArrowRight") {
|
|
37
|
-
if (accessHorizontalArrows === "ArrowRight") {
|
|
38
|
-
setOpen(true);
|
|
39
|
-
selectFirstMenuChild();
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
setOpen(false);
|
|
43
|
-
toggleRef.current?.focus();
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
if (ev.key === "ArrowLeft") {
|
|
47
|
-
if (accessHorizontalArrows === "ArrowLeft") {
|
|
48
|
-
setOpen(true);
|
|
49
|
-
selectFirstMenuChild();
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
52
|
-
setOpen(false);
|
|
53
|
-
toggleRef.current?.focus();
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
return (<DropdownContext value={{ isOpen, setOpen, toggleRef, menuRef }}>
|
|
58
|
-
<div onKeyDown={ev => {
|
|
59
|
-
onKeyDown?.(ev);
|
|
60
|
-
handleKeyDown(ev);
|
|
61
|
-
}} {...p}/>
|
|
62
|
-
</DropdownContext>);
|
|
63
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { HTMLAttributes } from "react";
|
|
2
|
-
export type DropdownTogglePropsT = HTMLAttributes<HTMLButtonElement>;
|
|
3
|
-
export declare function DropdownToggle({ onClick, ...props }: DropdownTogglePropsT): import("react").JSX.Element;
|
|
4
|
-
//# sourceMappingURL=DropdownToggle.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"DropdownToggle.d.ts","sourceRoot":"","sources":["../../../src/components/Dropdown/DropdownToggle.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAO,MAAM,OAAO,CAAC;AAI5C,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,iBAAiB,CAAC,CAAC;AAErE,wBAAgB,cAAc,CAAC,EAAE,OAAO,EAAE,GAAG,KAAK,EAAE,EAAE,oBAAoB,+BAczE"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use } from "react";
|
|
3
|
-
import { DropdownContext } from "./DropdownContext";
|
|
4
|
-
export function DropdownToggle({ onClick, ...props }) {
|
|
5
|
-
const { toggleRef, setOpen } = use(DropdownContext);
|
|
6
|
-
return (<button ref={toggleRef} onClick={ev => {
|
|
7
|
-
ev.stopPropagation();
|
|
8
|
-
onClick?.(ev);
|
|
9
|
-
setOpen(prev => !prev);
|
|
10
|
-
}} {...props}/>);
|
|
11
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { use, useEffect, useRef } from "react";
|
|
3
|
-
import { AnimatePresence, motion } from "framer-motion";
|
|
4
|
-
import { ModalContext } from "./ModalContext";
|
|
5
|
-
export function ModalBody({ onClick, ...props }) {
|
|
6
|
-
const { isOpen } = use(ModalContext);
|
|
7
|
-
const contentRef = useRef(null);
|
|
8
|
-
useEffect(() => {
|
|
9
|
-
if (isOpen) {
|
|
10
|
-
const indexElement = contentRef.current?.querySelector("[data-modal='index']");
|
|
11
|
-
indexElement?.focus();
|
|
12
|
-
}
|
|
13
|
-
;
|
|
14
|
-
}, [isOpen]);
|
|
15
|
-
return (<AnimatePresence>
|
|
16
|
-
{isOpen ? (<motion.div ref={contentRef} initial={{ opacity: 0, scale: 0.9 }} animate={{ opacity: 1, scale: 1 }} exit={{ opacity: 0, scale: 0.9 }} transition={{ ease: "easeInOut" }} onClick={ev => {
|
|
17
|
-
onClick?.(ev);
|
|
18
|
-
ev.stopPropagation();
|
|
19
|
-
}} {...props}/>) : null}
|
|
20
|
-
</AnimatePresence>);
|
|
21
|
-
}
|