@mbao01/common 0.0.19 → 0.0.21

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 (62) hide show
  1. package/dist/types/components/Command/Command.d.ts +5 -5
  2. package/dist/types/components/Drawer/Drawer.d.ts +41 -0
  3. package/dist/types/components/Drawer/constants.d.ts +6 -0
  4. package/dist/types/components/Drawer/index.d.ts +1 -0
  5. package/dist/types/components/Drawer/types.d.ts +3 -0
  6. package/dist/types/components/Menu/ContextMenu/ContextMenu.d.ts +36 -0
  7. package/dist/types/components/Menu/ContextMenu/constants.d.ts +0 -0
  8. package/dist/types/components/Menu/ContextMenu/index.d.ts +1 -0
  9. package/dist/types/components/Menu/ContextMenu/types.d.ts +14 -0
  10. package/dist/types/components/Menu/DropdownMenu/DropdownMenu.d.ts +36 -0
  11. package/dist/types/components/Menu/DropdownMenu/index.d.ts +1 -0
  12. package/dist/types/components/Menu/DropdownMenu/types.d.ts +14 -0
  13. package/dist/types/components/Menu/Menubar/Menubar.d.ts +43 -0
  14. package/dist/types/components/Menu/Menubar/constants.d.ts +25 -0
  15. package/dist/types/components/Menu/Menubar/index.d.ts +1 -0
  16. package/dist/types/components/Menu/Menubar/types.d.ts +15 -0
  17. package/dist/types/components/Menu/NavigationMenu/NavigationMenu.d.ts +17 -0
  18. package/dist/types/components/Menu/NavigationMenu/constants.d.ts +8 -0
  19. package/dist/types/components/Menu/NavigationMenu/index.d.ts +1 -0
  20. package/dist/types/components/Menu/NavigationMenu/types.d.ts +10 -0
  21. package/dist/types/components/Menu/index.d.ts +4 -0
  22. package/dist/types/components/Pagination/Pagination.d.ts +25 -0
  23. package/dist/types/components/Pagination/constants.d.ts +5 -0
  24. package/dist/types/components/Pagination/index.d.ts +1 -0
  25. package/dist/types/components/Pagination/types.d.ts +12 -0
  26. package/dist/types/components/ScrollArea/ScrollArea.d.ts +11 -0
  27. package/dist/types/components/ScrollArea/constants.d.ts +8 -0
  28. package/dist/types/components/ScrollArea/index.d.ts +1 -0
  29. package/dist/types/components/ScrollArea/types.d.ts +8 -0
  30. package/dist/types/components/Skeleton/constants.d.ts +2 -2
  31. package/dist/types/index.d.ts +3 -0
  32. package/package.json +9 -3
  33. package/src/components/Drawer/Drawer.tsx +121 -0
  34. package/src/components/Drawer/constants.ts +19 -0
  35. package/src/components/Drawer/index.ts +1 -0
  36. package/src/components/Drawer/types.ts +3 -0
  37. package/src/components/Menu/ContextMenu/ContextMenu.tsx +180 -0
  38. package/src/components/Menu/ContextMenu/constants.ts +0 -0
  39. package/src/components/Menu/ContextMenu/index.ts +1 -0
  40. package/src/components/Menu/ContextMenu/types.ts +60 -0
  41. package/src/components/Menu/DropdownMenu/DropdownMenu.tsx +183 -0
  42. package/src/components/Menu/DropdownMenu/index.ts +1 -0
  43. package/src/components/Menu/DropdownMenu/types.ts +60 -0
  44. package/src/components/Menu/Menubar/Menubar.tsx +204 -0
  45. package/src/components/Menu/Menubar/constants.ts +107 -0
  46. package/src/components/Menu/Menubar/index.ts +1 -0
  47. package/src/components/Menu/Menubar/types.ts +66 -0
  48. package/src/components/Menu/NavigationMenu/NavigationMenu.tsx +117 -0
  49. package/src/components/Menu/NavigationMenu/constants.ts +47 -0
  50. package/src/components/Menu/NavigationMenu/index.ts +1 -0
  51. package/src/components/Menu/NavigationMenu/types.ts +40 -0
  52. package/src/components/Menu/index.ts +4 -0
  53. package/src/components/Pagination/Pagination.tsx +132 -0
  54. package/src/components/Pagination/constants.ts +15 -0
  55. package/src/components/Pagination/index.ts +1 -0
  56. package/src/components/Pagination/types.ts +19 -0
  57. package/src/components/ScrollArea/ScrollArea.tsx +52 -0
  58. package/src/components/ScrollArea/constants.ts +36 -0
  59. package/src/components/ScrollArea/index.ts +1 -0
  60. package/src/components/ScrollArea/types.ts +14 -0
  61. package/src/index.ts +3 -0
  62. package/vitest-setup.ts +3 -0
@@ -0,0 +1,132 @@
1
+ import { forwardRef } from "react";
2
+ import {
3
+ ChevronLeftIcon,
4
+ ChevronRightIcon,
5
+ DotsHorizontalIcon,
6
+ } from "@radix-ui/react-icons";
7
+ import {
8
+ PaginationContentProps,
9
+ PaginationEllipsisProps,
10
+ PaginationItemProps,
11
+ PaginationLinkProps,
12
+ PaginationNextProps,
13
+ PaginationPreviousProps,
14
+ type PaginationProps,
15
+ } from "./types";
16
+ import { cn } from "../../utilities";
17
+ import {
18
+ getPaginationClasses,
19
+ getPaginationContentClasses,
20
+ getPaginationEllipsisClasses,
21
+ getPaginationNextClasses,
22
+ getPaginationPreviousClasses,
23
+ } from "./constants";
24
+
25
+ import { getButtonClasses } from "../Button/constants";
26
+
27
+ const Pagination = ({ className, ...props }: PaginationProps) => (
28
+ <nav
29
+ role="navigation"
30
+ aria-label="pagination"
31
+ className={cn(getPaginationClasses(), className)}
32
+ {...props}
33
+ />
34
+ );
35
+ Pagination.displayName = "Pagination";
36
+
37
+ const PaginationContent = forwardRef<HTMLUListElement, PaginationContentProps>(
38
+ ({ className, ...props }, ref) => (
39
+ <ul
40
+ ref={ref}
41
+ className={cn(getPaginationContentClasses(), className)}
42
+ {...props}
43
+ />
44
+ )
45
+ );
46
+ PaginationContent.displayName = "PaginationContent";
47
+
48
+ const PaginationItem = forwardRef<HTMLLIElement, PaginationItemProps>(
49
+ (props, ref) => <li ref={ref} {...props} />
50
+ );
51
+ PaginationItem.displayName = "PaginationItem";
52
+
53
+ const PaginationLink = ({
54
+ className,
55
+ size,
56
+ wide,
57
+ outline,
58
+ variant = "ghost",
59
+ isActive,
60
+ ...props
61
+ }: PaginationLinkProps) => (
62
+ <a
63
+ aria-current={isActive ? "page" : undefined}
64
+ className={cn(
65
+ getButtonClasses({
66
+ size,
67
+ wide,
68
+ outline: outline ?? isActive,
69
+ variant,
70
+ }),
71
+ className
72
+ )}
73
+ {...props}
74
+ />
75
+ );
76
+ PaginationLink.displayName = "PaginationLink";
77
+
78
+ const PaginationPrevious = ({
79
+ className,
80
+ children,
81
+ ...props
82
+ }: PaginationPreviousProps) => (
83
+ <PaginationLink
84
+ aria-label="Go to previous page"
85
+ className={cn(getPaginationPreviousClasses(), className)}
86
+ {...props}
87
+ >
88
+ <ChevronLeftIcon className="h-4 w-4" />
89
+ {children && <span>{children}</span>}
90
+ </PaginationLink>
91
+ );
92
+ PaginationPrevious.displayName = "PaginationPrevious";
93
+
94
+ const PaginationNext = ({
95
+ className,
96
+ children,
97
+ ...props
98
+ }: PaginationNextProps) => (
99
+ <PaginationLink
100
+ aria-label="Go to next page"
101
+ className={cn(getPaginationNextClasses(), className)}
102
+ {...props}
103
+ >
104
+ {children && <span>{children}</span>}
105
+ <ChevronRightIcon className="h-4 w-4" />
106
+ </PaginationLink>
107
+ );
108
+ PaginationNext.displayName = "PaginationNext";
109
+
110
+ const PaginationEllipsis = ({
111
+ className,
112
+ ...props
113
+ }: PaginationEllipsisProps) => (
114
+ <span
115
+ aria-hidden
116
+ className={cn(getPaginationEllipsisClasses(), className)}
117
+ {...props}
118
+ >
119
+ <DotsHorizontalIcon className="h-4 w-4" />
120
+ <span className="sr-only">More pages</span>
121
+ </span>
122
+ );
123
+ PaginationEllipsis.displayName = "PaginationEllipsis";
124
+
125
+ Pagination.Content = PaginationContent;
126
+ Pagination.Link = PaginationLink;
127
+ Pagination.Item = PaginationItem;
128
+ Pagination.Previous = PaginationPrevious;
129
+ Pagination.Next = PaginationNext;
130
+ Pagination.Ellipsis = PaginationEllipsis;
131
+
132
+ export { Pagination };
@@ -0,0 +1,15 @@
1
+ import { cva } from "../../libs";
2
+
3
+ export const getPaginationClasses = cva("mx-auto flex w-full justify-center");
4
+
5
+ export const getPaginationContentClasses = cva(
6
+ "flex flex-row items-center gap-1"
7
+ );
8
+
9
+ export const getPaginationEllipsisClasses = cva(
10
+ "flex h-9 w-9 items-center justify-center"
11
+ );
12
+
13
+ export const getPaginationNextClasses = cva("gap-1 px-3");
14
+
15
+ export const getPaginationPreviousClasses = cva("gap-1 px-3");
@@ -0,0 +1 @@
1
+ export { Pagination } from "./Pagination";
@@ -0,0 +1,19 @@
1
+ import { VariantProps } from "../../libs";
2
+ import { getButtonClasses } from "../Button/constants";
3
+
4
+ export type PaginationProps = React.ComponentProps<"nav">;
5
+
6
+ export type PaginationContentProps = React.ComponentProps<"ul">;
7
+
8
+ export type PaginationEllipsisProps = React.ComponentProps<"span">;
9
+
10
+ export type PaginationItemProps = React.ComponentProps<"li">;
11
+
12
+ export type PaginationLinkProps = React.ComponentProps<"a"> &
13
+ VariantProps<typeof getButtonClasses> & {
14
+ isActive?: boolean;
15
+ };
16
+
17
+ export type PaginationPreviousProps = PaginationLinkProps;
18
+
19
+ export type PaginationNextProps = PaginationLinkProps;
@@ -0,0 +1,52 @@
1
+ "use client";
2
+
3
+ import { forwardRef } from "react";
4
+ import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
5
+ import type { ScrollAreaProps, ScrollbarProps } from "./types";
6
+ import { cn } from "../../utilities";
7
+ import {
8
+ getScrollAreaClasses,
9
+ getScrollAreaScrollbarClasses,
10
+ getScrollAreaThumbClasses,
11
+ getScrollAreaViewportClasses,
12
+ } from "./constants";
13
+
14
+ const ScrollArea = ({
15
+ className,
16
+ children,
17
+ scrollbar,
18
+ ...props
19
+ }: ScrollAreaProps) => (
20
+ <ScrollAreaPrimitive.Root
21
+ className={cn(getScrollAreaClasses(), className)}
22
+ {...props}
23
+ >
24
+ <ScrollAreaPrimitive.Viewport
25
+ className={cn(getScrollAreaViewportClasses())}
26
+ >
27
+ {children}
28
+ </ScrollAreaPrimitive.Viewport>
29
+ <Scrollbar {...scrollbar} />
30
+ <ScrollAreaPrimitive.Corner />
31
+ </ScrollAreaPrimitive.Root>
32
+ );
33
+ ScrollArea.displayName = ScrollAreaPrimitive.Root.displayName;
34
+
35
+ const Scrollbar = forwardRef<
36
+ React.ElementRef<typeof ScrollAreaPrimitive.ScrollAreaScrollbar>,
37
+ ScrollbarProps
38
+ >(({ className, variant, orientation = "vertical", ...props }, ref) => (
39
+ <ScrollAreaPrimitive.ScrollAreaScrollbar
40
+ ref={ref}
41
+ orientation={orientation}
42
+ className={cn(getScrollAreaScrollbarClasses({ orientation }), className)}
43
+ {...props}
44
+ >
45
+ <ScrollAreaPrimitive.ScrollAreaThumb
46
+ className={cn(getScrollAreaThumbClasses({ variant }))}
47
+ />
48
+ </ScrollAreaPrimitive.ScrollAreaScrollbar>
49
+ ));
50
+ Scrollbar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
51
+
52
+ export { ScrollArea, Scrollbar };
@@ -0,0 +1,36 @@
1
+ import { cva } from "../../libs";
2
+
3
+ export const getScrollAreaClasses = cva("relative overflow-hidden");
4
+
5
+ export const getScrollAreaScrollbarClasses = cva(
6
+ "flex touch-none select-none transition-colors",
7
+ {
8
+ variants: {
9
+ orientation: {
10
+ horizontal: "h-2.5 flex-col border-t border-t-transparent p-[1px]",
11
+ vertical: "h-full w-2.5 border-l border-l-transparent p-[1px]",
12
+ },
13
+ },
14
+ }
15
+ );
16
+
17
+ export const getScrollAreaThumbClasses = cva("relative flex-1 rounded-full", {
18
+ variants: {
19
+ variant: {
20
+ accent: "bg-accent",
21
+ base: "bg-base-300",
22
+ error: "bg-error",
23
+ ghost: "bg-ghost",
24
+ info: "bg-info",
25
+ neutral: "bg-neutral",
26
+ primary: "bg-primary",
27
+ secondary: "bg-secondary",
28
+ success: "bg-success",
29
+ warning: "bg-warning",
30
+ },
31
+ },
32
+ });
33
+
34
+ export const getScrollAreaViewportClasses = cva(
35
+ "h-full w-full rounded-[inherit]"
36
+ );
@@ -0,0 +1 @@
1
+ export { ScrollArea } from "./ScrollArea";
@@ -0,0 +1,14 @@
1
+ import * as ScrollAreaPrimitive from "@radix-ui/react-scroll-area";
2
+ import { VariantProps } from "../../libs";
3
+ import { getScrollAreaThumbClasses } from "./constants";
4
+
5
+ export type ScrollAreaProps = React.ComponentPropsWithoutRef<
6
+ typeof ScrollAreaPrimitive.Root
7
+ > & {
8
+ scrollbar?: ScrollbarProps;
9
+ };
10
+
11
+ export type ScrollbarProps = React.ComponentPropsWithoutRef<
12
+ typeof ScrollAreaPrimitive.ScrollAreaScrollbar
13
+ > &
14
+ VariantProps<typeof getScrollAreaThumbClasses>;
package/src/index.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  /** actions */
2
2
  export * from "./components/Button";
3
3
  export * from "./components/Breadcrumbs";
4
+ export * from "./components/Menu";
5
+ export * from "./components/Pagination";
4
6
  export * from "./components/Toggle";
5
7
  export * from "./components/ToggleGroup";
6
8
 
@@ -14,6 +16,7 @@ export * from "./components/Calendar";
14
16
  export * from "./components/Collapsible";
15
17
  export * from "./components/Description";
16
18
  export * from "./components/Progress";
19
+ export * from "./components/ScrollArea";
17
20
  export * from "./components/Separator";
18
21
  export * from "./components/Sonner";
19
22
  export * from "./components/Tabs";
package/vitest-setup.ts CHANGED
@@ -12,6 +12,9 @@ const ResizeObserverMock = vi.fn(() => ({
12
12
  // Stub the global ResizeObserver
13
13
  vi.stubGlobal("ResizeObserver", ResizeObserverMock);
14
14
 
15
+ // Mock the scrollTo method
16
+ vi.stubGlobal("scrollTo", vi.fn());
17
+
15
18
  // runs a cleanup after each test case (e.g. clearing jsdom)
16
19
  afterEach(() => {
17
20
  cleanup();