@kadoui/react 1.0.0 → 1.0.1

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.
Files changed (179) hide show
  1. package/README.md +1 -0
  2. package/dist/components/AccessNavigation/AccessNavigation.d.ts.map +1 -1
  3. package/dist/components/AccessNavigation/AccessNavigation.jsx +1 -1
  4. package/dist/components/Accordion/AccordionBody.jsx +1 -1
  5. package/dist/components/Affix/Affix.jsx +1 -1
  6. package/dist/components/Breadcrumbs/BreadcrumbsItem.jsx +1 -1
  7. package/dist/components/Breadcrumbs/BreadcrumbsRoot.jsx +1 -1
  8. package/dist/components/Carousel/CarouselContainer.jsx +1 -1
  9. package/dist/components/Carousel/CarouselRoot.jsx +1 -1
  10. package/dist/components/ContextMenu/ContextMenuContent.d.ts.map +1 -1
  11. package/dist/components/ContextMenu/ContextMenuContent.jsx +2 -1
  12. package/dist/components/ContextMenu/ContextMenuRoot.d.ts.map +1 -1
  13. package/dist/components/ContextMenu/ContextMenuRoot.jsx +1 -1
  14. package/dist/components/Drawer/DrawerBody.jsx +1 -1
  15. package/dist/components/Drawer/DrawerPortal.jsx +1 -1
  16. package/dist/components/Drawer/DrawerRoot.jsx +1 -1
  17. package/dist/components/Dropdown/DropdownMenu.d.ts.map +1 -1
  18. package/dist/components/Dropdown/DropdownMenu.jsx +1 -1
  19. package/dist/components/Dropdown/DropdownRoot.d.ts.map +1 -1
  20. package/dist/components/Dropdown/DropdownRoot.jsx +2 -1
  21. package/dist/components/LinkLoader/LinkLoader.jsx +1 -1
  22. package/dist/components/Modal/ModalBody.jsx +1 -1
  23. package/dist/components/Modal/ModalContent.jsx +1 -1
  24. package/dist/components/Modal/ModalHeader.jsx +1 -1
  25. package/dist/components/Modal/ModalPortal.jsx +1 -1
  26. package/dist/components/Modal/ModalRoot.d.ts.map +1 -1
  27. package/dist/components/Modal/ModalRoot.jsx +1 -1
  28. package/dist/components/Otp/OtpInputs.jsx +1 -1
  29. package/dist/components/Otp/OtpRoot.jsx +1 -1
  30. package/dist/components/Progress/ProgressBar.jsx +1 -1
  31. package/dist/components/Progress/ProgressRoot.jsx +1 -1
  32. package/dist/components/Rating/RatingItems.jsx +1 -1
  33. package/dist/components/Rating/RatingRoot.jsx +1 -1
  34. package/dist/components/Sheet/SheetBody.jsx +1 -1
  35. package/dist/components/Sheet/SheetContent.jsx +1 -1
  36. package/dist/components/Sheet/SheetHeader.jsx +1 -1
  37. package/dist/components/Sheet/SheetPortal.jsx +1 -1
  38. package/dist/components/ShowMore/ShowMoreContent.jsx +1 -1
  39. package/dist/components/ShowMore/ShowMoreFade.jsx +1 -1
  40. package/dist/components/ShowMore/ShowMoreRoot.jsx +1 -1
  41. package/dist/components/ShowMore/ShowMoreTrigger.jsx +1 -1
  42. package/dist/components/Slide/SlideContent.jsx +1 -1
  43. package/dist/components/Slide/SlideHeader.jsx +1 -1
  44. package/dist/components/Slide/SlidePortal.jsx +1 -1
  45. package/dist/components/Spoiler/Spoiler.jsx +1 -1
  46. package/dist/components/Steps/StepsControls.jsx +1 -1
  47. package/dist/components/Tabs/TabsList.jsx +1 -1
  48. package/dist/components/Tabs/TabsPanel.jsx +1 -1
  49. package/dist/components/Toast/ToastBox.jsx +1 -1
  50. package/dist/index.d.ts +3 -0
  51. package/dist/index.d.ts.map +1 -1
  52. package/dist/index.js +5 -0
  53. package/dist/utils/browser.d.ts +3 -0
  54. package/dist/utils/browser.d.ts.map +1 -0
  55. package/dist/utils/browser.js +21 -0
  56. package/dist/utils/cn.d.ts +3 -0
  57. package/dist/utils/cn.d.ts.map +1 -0
  58. package/dist/utils/cn.js +3 -0
  59. package/dist/utils/form.d.ts +2 -0
  60. package/dist/utils/form.d.ts.map +1 -0
  61. package/dist/utils/form.js +8 -0
  62. package/package.json +4 -3
  63. package/src/components/AccessNavigation/AccessNavigation.tsx +0 -46
  64. package/src/components/Accordion/Accordion.ts +0 -8
  65. package/src/components/Accordion/AccordionBody.tsx +0 -31
  66. package/src/components/Accordion/AccordionContext.ts +0 -8
  67. package/src/components/Accordion/AccordionRoot.tsx +0 -17
  68. package/src/components/Accordion/AccordionToggle.tsx +0 -29
  69. package/src/components/Affix/Affix.tsx +0 -59
  70. package/src/components/Breadcrumbs/Breadcrumbs.ts +0 -6
  71. package/src/components/Breadcrumbs/BreadcrumbsContext.ts +0 -7
  72. package/src/components/Breadcrumbs/BreadcrumbsItem.tsx +0 -24
  73. package/src/components/Breadcrumbs/BreadcrumbsRoot.tsx +0 -21
  74. package/src/components/Carousel/Carousel.ts +0 -6
  75. package/src/components/Carousel/CarouselContainer.tsx +0 -18
  76. package/src/components/Carousel/CarouselContext.ts +0 -7
  77. package/src/components/Carousel/CarouselRoot.tsx +0 -75
  78. package/src/components/ClientOnly/ClientOnly.tsx +0 -12
  79. package/src/components/Clipboard/Clipboard.tsx +0 -36
  80. package/src/components/ContextMenu/ContextMenu.ts +0 -6
  81. package/src/components/ContextMenu/ContextMenuContent.tsx +0 -51
  82. package/src/components/ContextMenu/ContextMenuContext.ts +0 -9
  83. package/src/components/ContextMenu/ContextMenuRoot.tsx +0 -79
  84. package/src/components/Drawer/Drawer.ts +0 -10
  85. package/src/components/Drawer/DrawerBody.tsx +0 -67
  86. package/src/components/Drawer/DrawerContext.ts +0 -8
  87. package/src/components/Drawer/DrawerPortal.tsx +0 -40
  88. package/src/components/Drawer/DrawerRoot.tsx +0 -45
  89. package/src/components/Drawer/DrawerToggle.tsx +0 -21
  90. package/src/components/Dropdown/Dropdown.ts +0 -8
  91. package/src/components/Dropdown/DropdownContext.ts +0 -10
  92. package/src/components/Dropdown/DropdownMenu.tsx +0 -34
  93. package/src/components/Dropdown/DropdownRoot.tsx +0 -90
  94. package/src/components/Dropdown/DropdownToggle.tsx +0 -23
  95. package/src/components/LinkLoader/LinkLoader.tsx +0 -16
  96. package/src/components/Modal/Modal.ts +0 -14
  97. package/src/components/Modal/ModalBody.tsx +0 -12
  98. package/src/components/Modal/ModalContent.tsx +0 -44
  99. package/src/components/Modal/ModalContext.ts +0 -8
  100. package/src/components/Modal/ModalHeader.tsx +0 -10
  101. package/src/components/Modal/ModalPortal.tsx +0 -40
  102. package/src/components/Modal/ModalRoot.tsx +0 -47
  103. package/src/components/Modal/ModalTrigger.tsx +0 -21
  104. package/src/components/Otp/Otp.ts +0 -8
  105. package/src/components/Otp/OtpContext.ts +0 -10
  106. package/src/components/Otp/OtpHiddenInput.tsx +0 -15
  107. package/src/components/Otp/OtpInputs.tsx +0 -86
  108. package/src/components/Otp/OtpRoot.tsx +0 -26
  109. package/src/components/Pagination/Pagination.ts +0 -15
  110. package/src/components/Pagination/PaginationContext.tsx +0 -10
  111. package/src/components/Pagination/PaginationCounts.tsx +0 -17
  112. package/src/components/Pagination/PaginationNextBtn.tsx +0 -27
  113. package/src/components/Pagination/PaginationPrevBtn.tsx +0 -27
  114. package/src/components/Pagination/PaginationSearchParamsRoot.tsx +0 -45
  115. package/src/components/Pagination/PaginationStateRoot.tsx +0 -23
  116. package/src/components/PasswordInput/PasswordInput.ts +0 -8
  117. package/src/components/PasswordInput/PasswordInputContext.tsx +0 -8
  118. package/src/components/PasswordInput/PasswordInputField.tsx +0 -15
  119. package/src/components/PasswordInput/PasswordInputRoot.tsx +0 -17
  120. package/src/components/PasswordInput/PasswordInputToggle.tsx +0 -52
  121. package/src/components/Portal/Portal.tsx +0 -17
  122. package/src/components/Progress/Progress.ts +0 -6
  123. package/src/components/Progress/ProgressBar.tsx +0 -29
  124. package/src/components/Progress/ProgressContext.ts +0 -8
  125. package/src/components/Progress/ProgressRoot.tsx +0 -22
  126. package/src/components/QrCode/QrCode.tsx +0 -22
  127. package/src/components/Rating/Rating.ts +0 -6
  128. package/src/components/Rating/RatingContext.ts +0 -8
  129. package/src/components/Rating/RatingItems.tsx +0 -50
  130. package/src/components/Rating/RatingRoot.tsx +0 -22
  131. package/src/components/Sheet/Sheet.tsx +0 -14
  132. package/src/components/Sheet/SheetBody.tsx +0 -49
  133. package/src/components/Sheet/SheetContent.tsx +0 -8
  134. package/src/components/Sheet/SheetContext.ts +0 -14
  135. package/src/components/Sheet/SheetHeader.tsx +0 -24
  136. package/src/components/Sheet/SheetPortal.tsx +0 -35
  137. package/src/components/Sheet/SheetRoot.tsx +0 -56
  138. package/src/components/Sheet/SheetToggle.tsx +0 -21
  139. package/src/components/ShowMore/ShowMore.ts +0 -10
  140. package/src/components/ShowMore/ShowMoreContent.tsx +0 -31
  141. package/src/components/ShowMore/ShowMoreContext.ts +0 -11
  142. package/src/components/ShowMore/ShowMoreFade.tsx +0 -18
  143. package/src/components/ShowMore/ShowMoreRoot.tsx +0 -37
  144. package/src/components/ShowMore/ShowMoreTrigger.tsx +0 -23
  145. package/src/components/Slide/Slide.ts +0 -12
  146. package/src/components/Slide/SlideContent.tsx +0 -8
  147. package/src/components/Slide/SlideContext.ts +0 -11
  148. package/src/components/Slide/SlideHeader.tsx +0 -10
  149. package/src/components/Slide/SlidePortal.tsx +0 -26
  150. package/src/components/Slide/SlideRoot.tsx +0 -39
  151. package/src/components/Slide/SlideToggle.tsx +0 -21
  152. package/src/components/Spoiler/Spoiler.tsx +0 -28
  153. package/src/components/Steps/Steps.ts +0 -15
  154. package/src/components/Steps/StepsContext.tsx +0 -16
  155. package/src/components/Steps/StepsControls.tsx +0 -56
  156. package/src/components/Steps/StepsNextBtn.tsx +0 -27
  157. package/src/components/Steps/StepsPrevBtn.tsx +0 -27
  158. package/src/components/Steps/StepsSearchParamsRoot.tsx +0 -45
  159. package/src/components/Steps/StepsStateRoot.tsx +0 -23
  160. package/src/components/Swap/Swap.ts +0 -8
  161. package/src/components/Swap/SwapContext.ts +0 -9
  162. package/src/components/Swap/SwapItem.tsx +0 -16
  163. package/src/components/Swap/SwapRoot.tsx +0 -29
  164. package/src/components/Swap/SwapTrigger.tsx +0 -31
  165. package/src/components/Tabs/Tabs.ts +0 -10
  166. package/src/components/Tabs/TabsContext.ts +0 -11
  167. package/src/components/Tabs/TabsList.tsx +0 -12
  168. package/src/components/Tabs/TabsPanel.tsx +0 -23
  169. package/src/components/Tabs/TabsRoot.tsx +0 -18
  170. package/src/components/Tabs/TabsTab.tsx +0 -23
  171. package/src/components/Toast/Toast.ts +0 -3
  172. package/src/components/Toast/ToastBox.tsx +0 -50
  173. package/src/components/Toast/ToastRoot.tsx +0 -71
  174. package/src/components/Toast/toastStore.ts +0 -22
  175. package/src/components/Toggle/Toggle.ts +0 -6
  176. package/src/components/Toggle/ToggleContext.ts +0 -9
  177. package/src/components/Toggle/ToggleRoot.tsx +0 -26
  178. package/src/components/Toggle/ToggleSwitch.tsx +0 -41
  179. package/src/index.ts +0 -28
@@ -1,45 +0,0 @@
1
- "use client";
2
-
3
- import { useRouter, useSearchParams } from "next/navigation";
4
- import { PropsWithChildren, useEffect, useState } from "react";
5
-
6
- import { PaginationContext } from "./PaginationContext";
7
-
8
- export type PaginationSearchParamsRootPropsT = PropsWithChildren & {
9
- pageKey?: string;
10
- pageLength: number;
11
- }
12
-
13
- export function PaginationSearchParamsRoot({ pageKey, pageLength, children }: PaginationSearchParamsRootPropsT) {
14
- const router = useRouter();
15
- const searchParams = useSearchParams();
16
- const [currentPage, setCurrentPage] = useState(1);
17
-
18
- useEffect(() => {
19
- setCurrentPage(+(searchParams.get(pageKey || "page") || "1"));
20
- }, [pageKey, searchParams]);
21
-
22
- const pushRouter = (page: number) => {
23
- const params = new URLSearchParams(searchParams.toString());
24
- params.set(pageKey || "page", page.toString());
25
- router.push("?" + params.toString())
26
- }
27
-
28
- const nextPage = () => {
29
- if (currentPage < pageLength) {
30
- pushRouter(currentPage + 1)
31
- }
32
- }
33
-
34
- const prevPage = () => {
35
- if (currentPage > 1) {
36
- pushRouter(currentPage - 1)
37
- }
38
- }
39
-
40
- return (
41
- <PaginationContext.Provider value={{ page: currentPage, pageLength, nextPage, prevPage }}>
42
- {children}
43
- </PaginationContext.Provider>
44
- )
45
- }
@@ -1,23 +0,0 @@
1
- "use client";
2
-
3
- import { PropsWithChildren, useState } from "react";
4
-
5
- import { PaginationContext } from "./PaginationContext";
6
-
7
- export type PaginationStateRootPropsT = PropsWithChildren & {
8
- pageLength: number;
9
- }
10
-
11
- export function PaginationStateRoot({ pageLength, children }: PaginationStateRootPropsT) {
12
- const [page, setPage] = useState(1);
13
-
14
- const nextPage = () => setPage(prev => prev < pageLength ? prev + 1 : prev);
15
-
16
- const prevPage = () => setPage(prev => prev > 1 ? prev - 1 : prev);
17
-
18
- return (
19
- <PaginationContext.Provider value={{ page, pageLength, nextPage, prevPage }}>
20
- {children}
21
- </PaginationContext.Provider>
22
- );
23
- }
@@ -1,8 +0,0 @@
1
- import { PasswordInputRoot } from "./PasswordInputRoot";
2
- import { PasswordInputField } from "./PasswordInputField";
3
- import { PasswordInputToggle } from "./PasswordInputToggle";
4
-
5
- export const PasswordInput = Object.assign(PasswordInputRoot, {
6
- Field: PasswordInputField,
7
- Toggle: PasswordInputToggle
8
- });
@@ -1,8 +0,0 @@
1
- import { createContext, Dispatch, SetStateAction } from "react";
2
-
3
- export type PasswordInputContextT = {
4
- isVisible: boolean;
5
- setIsVisible: Dispatch<SetStateAction<boolean>>;
6
- }
7
-
8
- export const PasswordInputContext = createContext<PasswordInputContextT>({} as PasswordInputContextT);
@@ -1,15 +0,0 @@
1
- "use client";
2
-
3
- import { InputHTMLAttributes, use } from "react";
4
-
5
- import { PasswordInputContext } from "./PasswordInputContext";
6
-
7
- export type PasswordInputFieldPropsT = InputHTMLAttributes<HTMLInputElement>;
8
-
9
- export function PasswordInputField(props: PasswordInputFieldPropsT) {
10
- const { isVisible } = use(PasswordInputContext);
11
-
12
- return (
13
- <input type={isVisible ? "text" : "password"} {...props} />
14
- );
15
- }
@@ -1,17 +0,0 @@
1
- "use client";
2
-
3
- import { LabelHTMLAttributes, useState } from "react";
4
-
5
- import { PasswordInputContext } from "./PasswordInputContext";
6
-
7
- export type PasswordInputRootPropsT = LabelHTMLAttributes<HTMLLabelElement>;
8
-
9
- export function PasswordInputRoot(props: PasswordInputRootPropsT) {
10
- const [isVisible, setIsVisible] = useState(false);
11
-
12
- return (
13
- <PasswordInputContext value={{ isVisible, setIsVisible }}>
14
- <label {...props} />
15
- </PasswordInputContext>
16
- )
17
- }
@@ -1,52 +0,0 @@
1
- "use client";
2
-
3
- import { ButtonHTMLAttributes, use } from "react";
4
- import { EyeClosedIcon, EyeIcon } from "lucide-react";
5
- import { AnimatePresence, motion } from "framer-motion";
6
-
7
- import { PasswordInputContext } from "./PasswordInputContext";
8
-
9
- export type PasswordInputTogglePropsT = ButtonHTMLAttributes<HTMLButtonElement>;
10
-
11
- export function PasswordInputToggle({ onClick, children, ...props }: PasswordInputTogglePropsT) {
12
- const { isVisible, setIsVisible } = use(PasswordInputContext);
13
-
14
- return (
15
- <button
16
- type="button"
17
- onClick={ev => {
18
- setIsVisible(prev => !prev);
19
- onClick?.(ev);
20
- }}
21
- {...props}
22
- >
23
- {children || (
24
- <AnimatePresence initial={false} mode="wait">
25
- {isVisible ? (
26
- <motion.div
27
- key="visible"
28
- className="compatible-icon"
29
- initial={{ opacity: 0, y: "-25%" }}
30
- animate={{ opacity: 1, y: 0 }}
31
- exit={{ opacity: 0, y: "25%" }}
32
- transition={{ duration: 0.1 }}
33
- >
34
- <EyeIcon className="size-full" />
35
- </motion.div>
36
- ) : (
37
- <motion.div
38
- key="hidden"
39
- className="compatible-icon"
40
- initial={{ opacity: 0, y: "-25%" }}
41
- animate={{ opacity: 1, y: 0 }}
42
- exit={{ opacity: 0, y: "25%" }}
43
- transition={{ duration: 0.1 }}
44
- >
45
- <EyeClosedIcon className="size-full" />
46
- </motion.div>
47
- )}
48
- </AnimatePresence>
49
- )}
50
- </button>
51
- );
52
- }
@@ -1,17 +0,0 @@
1
- "use client";
2
-
3
- import { createPortal } from "react-dom";
4
- import { PropsWithChildren } from "react";
5
-
6
- export type PortalPropsT = PropsWithChildren & {
7
- container?: Element;
8
- }
9
-
10
- export function Portal({ children, container }: PortalPropsT) {
11
- return createPortal(
12
- <>
13
- {children}
14
- </>,
15
- container || document.body
16
- );
17
- }
@@ -1,6 +0,0 @@
1
- import { ProgressBar } from "./ProgressBar";
2
- import { ProgressRoot } from "./ProgressRoot";
3
-
4
- export const Progress = Object.assign(ProgressRoot, {
5
- Bar: ProgressBar
6
- });
@@ -1,29 +0,0 @@
1
- "use client"
2
-
3
- import { use } from "react";
4
- import { cn } from "@kadoui/utils";
5
- import { HTMLMotionProps, motion } from "framer-motion";
6
-
7
- import { ProgressContext } from "./ProgressContext";
8
-
9
- export type ProgressBarPropsT = HTMLMotionProps<"div"> & {
10
- duration?: number;
11
- }
12
-
13
- export function ProgressBar({ className, duration, children, ...p }: ProgressBarPropsT) {
14
- const { value, maxValue } = use(ProgressContext);
15
-
16
- const percentage = Math.min(100, Math.max(0, (value / maxValue) * 100));
17
-
18
- return (
19
- <motion.div
20
- className={cn("f-center h-full bg-palette text-brush max-w-full", className)}
21
- initial={{ width: 0 }}
22
- whileInView={{ width: `${percentage}%` }}
23
- transition={{ duration: duration || 3 }}
24
- {...p}
25
- >
26
- {children || <span className="text-xs">{percentage}%</span>}
27
- </motion.div>
28
- )
29
- }
@@ -1,8 +0,0 @@
1
- import { createContext } from "react";
2
-
3
- export type ProgressContextT = {
4
- value: number;
5
- maxValue: number;
6
- }
7
-
8
- export const ProgressContext = createContext<ProgressContextT>({} as ProgressContextT);
@@ -1,22 +0,0 @@
1
- "use client"
2
-
3
- import { cn } from "@kadoui/utils";
4
- import type { HTMLAttributes } from "react";
5
-
6
- import { ProgressContext } from "./ProgressContext";
7
-
8
- export type ProgressRootPropsT = HTMLAttributes<HTMLDivElement> & {
9
- value: number;
10
- maxValue?: number;
11
- }
12
-
13
- export function ProgressRoot({ value, maxValue = 100, className, ...p }: ProgressRootPropsT) {
14
- return (
15
- <ProgressContext value={{ value, maxValue }}>
16
- <div
17
- className={cn("w-full rounded-kado overflow-hidden h-6 bg-palette/10", className)}
18
- {...p}
19
- />
20
- </ProgressContext>
21
- )
22
- }
@@ -1,22 +0,0 @@
1
- "use client";
2
-
3
- import QRCode, { QRCodeRenderersOptions } from "qrcode";
4
- import React, { HTMLAttributes, useEffect, useRef } from "react";
5
-
6
- export type QrCodePropsT = HTMLAttributes<HTMLCanvasElement> & {
7
- value: string
8
- options: QRCodeRenderersOptions;
9
- }
10
-
11
- export function QrCode({ value, options, ...props }: QrCodePropsT) {
12
- const canvasRef = useRef(null);
13
-
14
- useEffect(() => {
15
- console.log(value)
16
- QRCode.toCanvas(canvasRef.current, value, options, function (error) {
17
- if (error) console.error(error);
18
- });
19
- }, [value, options]);
20
-
21
- return <canvas ref={canvasRef} {...props} />;
22
- }
@@ -1,6 +0,0 @@
1
- import { RatingRoot } from "./RatingRoot";
2
- import { RatingItems } from "./RatingItems";
3
-
4
- export const Rating = Object.assign(RatingRoot, {
5
- Items: RatingItems
6
- });
@@ -1,8 +0,0 @@
1
- import { createContext, Dispatch, SetStateAction } from "react";
2
-
3
- export type RatingContextT = {
4
- hoverValue: number | null;
5
- setHoverValue: Dispatch<SetStateAction<number | null>>;
6
- }
7
-
8
- export const RatingContext = createContext<RatingContextT>({} as RatingContextT);
@@ -1,50 +0,0 @@
1
- "use client";
2
-
3
- import { cn } from "@kadoui/utils";
4
- import { StarIcon } from "lucide-react";
5
- import { ButtonHTMLAttributes, ReactNode, use } from "react";
6
-
7
- import { RatingContext } from "./RatingContext";
8
-
9
- export type RatingItemsPropsT = ButtonHTMLAttributes<HTMLButtonElement> & {
10
- count: number;
11
- value: number;
12
- onValueChange: (newValue: number) => void;
13
- element?: ReactNode;
14
- activeElement?: ReactNode;
15
- }
16
-
17
- export function RatingItems({ count, value, onValueChange, element, activeElement, className, ...p }: RatingItemsPropsT) {
18
- const { hoverValue, setHoverValue } = use(RatingContext);
19
-
20
- const defaultElement = element || <StarIcon className="icon-size-3 text-palette" />;
21
- const defaultActiveElement = activeElement || <StarIcon className="icon-size-3 text-palette fill-palette" />;
22
-
23
- const displayValue = hoverValue !== null ? hoverValue : value;
24
-
25
- return (
26
- Array.from({ length: count }).map((_, index) => {
27
- const itemValue = index + 1;
28
- const isActive = itemValue <= displayValue;
29
-
30
- return (
31
- <button
32
- key={index}
33
- role="radio"
34
- type="button"
35
- className={cn(
36
- "transition-all px-0.5 not-active:hover:-translate-y-0.5",
37
- className
38
- )}
39
- aria-checked={itemValue === value}
40
- onClick={() => onValueChange(itemValue)}
41
- onMouseEnter={() => setHoverValue(itemValue)}
42
- aria-label={`${itemValue} out of ${count} stars`}
43
- {...p}
44
- >
45
- {isActive ? defaultActiveElement : defaultElement}
46
- </button>
47
- )
48
- })
49
- )
50
- }
@@ -1,22 +0,0 @@
1
- "use client"
2
-
3
- import { cn } from "@kadoui/utils";
4
- import { HTMLAttributes, useState } from "react";
5
-
6
- import { RatingContext, RatingContextT } from "./RatingContext";
7
-
8
- export type RatingRootPropsT = HTMLAttributes<HTMLDivElement>
9
-
10
- export const RatingRoot = ({ className, ...p }: RatingRootPropsT) => {
11
- const [hoverValue, setHoverValue] = useState<RatingContextT["hoverValue"]>(null);
12
-
13
- return (
14
- <RatingContext value={{ hoverValue, setHoverValue }}>
15
- <div
16
- className={cn("f-align w-fit max-w-full", className)}
17
- onMouseLeave={() => setHoverValue(null)}
18
- {...p}
19
- />
20
- </RatingContext>
21
- )
22
- }
@@ -1,14 +0,0 @@
1
- import { SheetBody } from "./SheetBody";
2
- import { SheetRoot } from "./SheetRoot";
3
- import { SheetHeader } from "./SheetHeader";
4
- import { SheetPortal } from "./SheetPortal";
5
- import { SheetToggle } from "./SheetToggle";
6
- import { SheetContent } from "./SheetContent";
7
-
8
- export const Sheet = Object.assign(SheetRoot, {
9
- Portal: SheetPortal,
10
- Body: SheetBody,
11
- Header: SheetHeader,
12
- Content: SheetContent,
13
- Toggle: SheetToggle
14
- });
@@ -1,49 +0,0 @@
1
- "use client";
2
-
3
- import { use } from "react";
4
- import { cn } from "@kadoui/utils";
5
- import { HTMLMotionProps, motion } from "framer-motion";
6
-
7
- import { SheetContext } from "./SheetContext";
8
-
9
- export type SheetBodyPropsT = HTMLMotionProps<"div">;
10
-
11
- export function SheetBody({ className, ...props }: SheetBodyPropsT) {
12
- const { drawerRef, controls, y, closeHandler: handleClose } = use(SheetContext);
13
-
14
- return (
15
- <motion.div
16
- id="drawer"
17
- ref={drawerRef}
18
- onClick={(ev) => ev.stopPropagation()}
19
- initial={{ y: "100%" }}
20
- animate={{ y: "0%" }}
21
- exit={{ y: "100%" }}
22
- style={{ y }}
23
- drag="y"
24
- dragControls={controls}
25
- dragListener={false}
26
- transition={{
27
- ease: "easeInOut",
28
- }}
29
- className={cn(
30
- "absolute bottom-0 h-[75%] w-full overflow-hidden bg-background",
31
- className
32
- )}
33
- onDragEnd={() => {
34
- if ((y?.get() || 0) >= 100) {
35
- handleClose();
36
- }
37
- }}
38
- dragConstraints={{
39
- top: 0,
40
- bottom: 0,
41
- }}
42
- dragElastic={{
43
- top: 0,
44
- bottom: 0.5,
45
- }}
46
- {...props}
47
- />
48
- );
49
- }
@@ -1,8 +0,0 @@
1
- import { cn } from "@kadoui/utils";
2
- import { HTMLAttributes } from "react";
3
-
4
- export type SheetContentPropsT = HTMLAttributes<HTMLDivElement>;
5
-
6
- export function SheetContent({ className, ...props }: SheetContentPropsT) {
7
- return <div className={cn("overflow-y-auto h-[calc(100%-1.75rem)] px-3 pb-3", className)} {...props} />;
8
- }
@@ -1,14 +0,0 @@
1
- import { AnimationScope, DragControls, MotionValue } from "framer-motion";
2
- import { createContext, Dispatch, RefObject, SetStateAction } from "react";
3
-
4
- export type SheetContextT = {
5
- isOpen: boolean;
6
- setOpen: Dispatch<SetStateAction<boolean>>;
7
- closeHandler: () => void;
8
- drawerRef?: RefObject<HTMLDivElement>;
9
- scope?: AnimationScope<any>;
10
- controls?: DragControls;
11
- y?: MotionValue<number>;
12
- }
13
-
14
- export const SheetContext = createContext<SheetContextT>({} as SheetContextT);
@@ -1,24 +0,0 @@
1
- "use client";
2
-
3
- import { cn } from "@kadoui/utils";
4
- import { HTMLAttributes, use } from "react";
5
-
6
- import { SheetContext } from "./SheetContext";
7
-
8
- export type SheetHeaderPropsT = HTMLAttributes<HTMLDivElement>;
9
-
10
- export function SheetHeader({ className, children, ...props }: SheetHeaderPropsT) {
11
- const { controls } = use(SheetContext);
12
-
13
- return (
14
- <div
15
- className={cn("h-7 f-center", className)}
16
- onPointerDown={(ev) => controls?.start(ev)}
17
- {...props}
18
- >
19
- {children || (
20
- <span className="h-1 w-1/3 rounded-full bg-foreground/10" />
21
- )}
22
- </div>
23
- );
24
- }
@@ -1,35 +0,0 @@
1
- "use client";
2
-
3
- import { use } from "react";
4
- import { cn } from "@kadoui/utils";
5
- import { AnimatePresence, HTMLMotionProps, motion } from "framer-motion";
6
-
7
- import { Portal } from "../Portal/Portal";
8
- import { SheetContext } from "./SheetContext";
9
- import { ClientOnly } from "../ClientOnly/ClientOnly";
10
-
11
- export type SheetPortalPropsT = HTMLMotionProps<"div">;
12
-
13
- export function SheetPortal({ className, ...props }: SheetPortalPropsT) {
14
- const { isOpen, closeHandler: handleClose, scope } = use(SheetContext);
15
-
16
- return (
17
- <ClientOnly>
18
- <Portal>
19
- <AnimatePresence>
20
- {isOpen ? (
21
- <motion.div
22
- ref={scope}
23
- onClick={handleClose}
24
- initial={{ opacity: 0 }}
25
- animate={{ opacity: 1 }}
26
- exit={{ opacity: 0 }}
27
- className={cn("fixed inset-0 z-50 bg-foreground/10", className)}
28
- {...props}
29
- />
30
- ) : null}
31
- </AnimatePresence>
32
- </Portal>
33
- </ClientOnly>
34
- )
35
- }
@@ -1,56 +0,0 @@
1
- "use client";
2
-
3
- import { useElementSize } from "@mantine/hooks";
4
- import { PropsWithChildren, useEffect, useState } from "react";
5
- import {
6
- useDragControls,
7
- useMotionValue,
8
- useAnimate,
9
- } from "framer-motion";
10
-
11
- import { SheetContext } from "./SheetContext";
12
-
13
- export type SheetRootPropsT = PropsWithChildren;
14
-
15
- export function SheetRoot({ children }: SheetRootPropsT) {
16
- const { ref: drawerRef, height } = useElementSize();
17
-
18
- const y = useMotionValue(0);
19
- const controls = useDragControls();
20
- const [scope, animate] = useAnimate();
21
-
22
- const [isOpen, setOpen] = useState(false);
23
-
24
- useEffect(() => {
25
- const removeOverflow = () => {
26
- document.body.classList.remove("overflow-hidden");
27
- };
28
-
29
- if (isOpen) {
30
- document.body.classList.add("overflow-hidden");
31
- } else {
32
- removeOverflow();
33
- }
34
-
35
- return () => removeOverflow();
36
- }, [isOpen]);
37
-
38
- const closeHandler = async () => {
39
- animate(scope.current, {
40
- opacity: [1, 0],
41
- });
42
-
43
- const yStart = typeof y.get() === "number" ? y.get() : 0;
44
- await animate("#drawer", {
45
- y: [yStart, height],
46
- });
47
-
48
- setOpen(false);
49
- };
50
-
51
- return (
52
- <SheetContext value={{ isOpen, setOpen, closeHandler, drawerRef, scope, controls, y }}>
53
- {children}
54
- </SheetContext>
55
- );
56
- }
@@ -1,21 +0,0 @@
1
- "use client";
2
-
3
- import { HTMLAttributes, use } from "react";
4
-
5
- import { SheetContext } from "./SheetContext";
6
-
7
- export type SheetTogglePropsT = HTMLAttributes<HTMLButtonElement>;
8
-
9
- export function SheetToggle({ onClick, ...props }: SheetTogglePropsT) {
10
- const { setOpen } = use(SheetContext);
11
-
12
- return (
13
- <button
14
- onClick={ev => {
15
- onClick?.(ev)
16
- setOpen(prev => !prev)
17
- }}
18
- {...props}
19
- />
20
- )
21
- }
@@ -1,10 +0,0 @@
1
- import { ShowMoreRoot } from "./ShowMoreRoot";
2
- import { ShowMoreFade } from "./ShowMoreFade";
3
- import { ShowMoreContent } from "./ShowMoreContent";
4
- import { ShowMoreTrigger } from "./ShowMoreTrigger";
5
-
6
- export const ShowMore = Object.assign(ShowMoreRoot, {
7
- Content: ShowMoreContent,
8
- Trigger: ShowMoreTrigger,
9
- Fade: ShowMoreFade
10
- });
@@ -1,31 +0,0 @@
1
- "use client"
2
-
3
- import { cn } from "@kadoui/utils";
4
- import { HTMLAttributes, use } from "react";
5
-
6
- import { ShowMoreContext } from "./ShowMoreContext";
7
-
8
- export type ShowMoreContentPropsT = HTMLAttributes<HTMLDivElement>;
9
-
10
- export function ShowMoreContent({ children, className, ...props }: ShowMoreContentPropsT) {
11
- const { contentRef, shouldShowMore, isShowMore, maxHeight } = use(ShowMoreContext);
12
-
13
- return (
14
- <div
15
- ref={contentRef}
16
- className={cn("overflow-hidden transition-all", className)}
17
- style={{
18
- height: shouldShowMore
19
- ? isShowMore
20
- ? contentRef.current?.scrollHeight
21
- ? `${contentRef.current.scrollHeight}px`
22
- : "auto"
23
- : maxHeight
24
- : "auto"
25
- }}
26
- {...props}
27
- >
28
- {children}
29
- </div>
30
- )
31
- }
@@ -1,11 +0,0 @@
1
- import { createContext, Dispatch, RefObject, SetStateAction } from "react";
2
-
3
- export type ShowMoreContextT = {
4
- contentRef: RefObject<HTMLDivElement | null>;
5
- shouldShowMore: boolean;
6
- isShowMore: boolean;
7
- setIsShowMore: Dispatch<SetStateAction<boolean>>;
8
- maxHeight: number;
9
- }
10
-
11
- export const ShowMoreContext = createContext<ShowMoreContextT>({} as ShowMoreContextT);