@srcroot/ui 0.0.61 → 0.0.63

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.
@@ -1,12 +1,14 @@
1
- import * as React from "react"
2
- import { cn } from "@/lib/utils"
3
- import { buttonVariants } from "./button"
1
+ "use client";
4
2
 
5
- interface PaginationProps extends React.HTMLAttributes<HTMLElement> { }
3
+ import * as React from "react";
4
+ import { cn } from "@/lib/utils";
5
+ import { buttonVariants } from "./button";
6
+
7
+ interface PaginationProps extends React.HTMLAttributes<HTMLElement> {}
6
8
 
7
9
  /**
8
10
  * Pagination component
9
- *
11
+ *
10
12
  * @example
11
13
  * <Pagination>
12
14
  * <PaginationContent>
@@ -26,124 +28,136 @@ interface PaginationProps extends React.HTMLAttributes<HTMLElement> { }
26
28
  * </Pagination>
27
29
  */
28
30
  const Pagination = ({ className, ...props }: PaginationProps) => (
29
- <nav
30
- role="navigation"
31
- aria-label="pagination"
32
- className={cn("mx-auto flex w-full justify-center", className)}
33
- {...props}
34
- />
35
- )
36
- Pagination.displayName = "Pagination"
31
+ <nav
32
+ role="navigation"
33
+ aria-label="pagination"
34
+ className={cn("mx-auto flex w-full justify-center", className)}
35
+ {...props}
36
+ />
37
+ );
38
+ Pagination.displayName = "Pagination";
37
39
 
38
40
  const PaginationContent = React.forwardRef<
39
- HTMLUListElement,
40
- React.HTMLAttributes<HTMLUListElement>
41
+ HTMLUListElement,
42
+ React.HTMLAttributes<HTMLUListElement>
41
43
  >(({ className, ...props }, ref) => (
42
- <ul
43
- ref={ref}
44
- className={cn("flex flex-row items-center gap-1", className)}
45
- {...props}
46
- />
47
- ))
48
- PaginationContent.displayName = "PaginationContent"
44
+ <ul
45
+ ref={ref}
46
+ className={cn("flex flex-row items-center gap-1", className)}
47
+ {...props}
48
+ />
49
+ ));
50
+ PaginationContent.displayName = "PaginationContent";
49
51
 
50
52
  const PaginationItem = React.forwardRef<
51
- HTMLLIElement,
52
- React.LiHTMLAttributes<HTMLLIElement>
53
+ HTMLLIElement,
54
+ React.LiHTMLAttributes<HTMLLIElement>
53
55
  >(({ className, ...props }, ref) => (
54
- <li ref={ref} className={cn("", className)} {...props} />
55
- ))
56
- PaginationItem.displayName = "PaginationItem"
56
+ <li ref={ref} className={cn("", className)} {...props} />
57
+ ));
58
+ PaginationItem.displayName = "PaginationItem";
57
59
 
58
60
  interface PaginationLinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
59
- isActive?: boolean
60
- size?: "default" | "sm" | "lg" | "icon"
61
- children?: React.ReactNode
62
- className?: string
63
- href?: string
61
+ isActive?: boolean;
62
+ size?: "default" | "sm" | "lg" | "icon";
63
+ children?: React.ReactNode;
64
+ className?: string;
65
+ href?: string;
64
66
  }
65
67
 
66
68
  const PaginationLink = ({
67
- className,
68
- isActive,
69
- size = "icon",
70
- ...props
69
+ className,
70
+ isActive,
71
+ size = "icon",
72
+ ...props
71
73
  }: PaginationLinkProps) => (
72
- <a
73
- aria-current={isActive ? "page" : undefined}
74
- className={cn(
75
- buttonVariants({
76
- variant: isActive ? "outline" : "ghost",
77
- size,
78
- }),
79
- className
80
- )}
81
- {...props}
82
- />
83
- )
84
- PaginationLink.displayName = "PaginationLink"
74
+ <a
75
+ aria-current={isActive ? "page" : undefined}
76
+ className={cn(
77
+ buttonVariants({
78
+ variant: isActive ? "outline" : "ghost",
79
+ size,
80
+ }),
81
+ className,
82
+ )}
83
+ {...props}
84
+ />
85
+ );
86
+ PaginationLink.displayName = "PaginationLink";
85
87
 
86
88
  const PaginationPrevious = ({
87
- className,
88
- ...props
89
+ className,
90
+ ...props
89
91
  }: React.ComponentProps<typeof PaginationLink>) => (
90
- <PaginationLink
91
- aria-label="Go to previous page"
92
- size="default"
93
- className={cn("gap-1 pl-2.5", className)}
94
- {...props}
92
+ <PaginationLink
93
+ aria-label="Go to previous page"
94
+ size="default"
95
+ className={cn("gap-1 pl-2.5", className)}
96
+ {...props}
97
+ >
98
+ <svg
99
+ className="h-4 w-4"
100
+ fill="none"
101
+ viewBox="0 0 24 24"
102
+ stroke="currentColor"
103
+ strokeWidth={2}
95
104
  >
96
- <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
97
- <path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7" />
98
- </svg>
99
- <span>Previous</span>
100
- </PaginationLink>
101
- )
102
- PaginationPrevious.displayName = "PaginationPrevious"
105
+ <path strokeLinecap="round" strokeLinejoin="round" d="M15 19l-7-7 7-7" />
106
+ </svg>
107
+ <span>Previous</span>
108
+ </PaginationLink>
109
+ );
110
+ PaginationPrevious.displayName = "PaginationPrevious";
103
111
 
104
112
  const PaginationNext = ({
105
- className,
106
- ...props
113
+ className,
114
+ ...props
107
115
  }: React.ComponentProps<typeof PaginationLink>) => (
108
- <PaginationLink
109
- aria-label="Go to next page"
110
- size="default"
111
- className={cn("gap-1 pr-2.5", className)}
112
- {...props}
116
+ <PaginationLink
117
+ aria-label="Go to next page"
118
+ size="default"
119
+ className={cn("gap-1 pr-2.5", className)}
120
+ {...props}
121
+ >
122
+ <span>Next</span>
123
+ <svg
124
+ className="h-4 w-4"
125
+ fill="none"
126
+ viewBox="0 0 24 24"
127
+ stroke="currentColor"
128
+ strokeWidth={2}
113
129
  >
114
- <span>Next</span>
115
- <svg className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2}>
116
- <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
117
- </svg>
118
- </PaginationLink>
119
- )
120
- PaginationNext.displayName = "PaginationNext"
130
+ <path strokeLinecap="round" strokeLinejoin="round" d="M9 5l7 7-7 7" />
131
+ </svg>
132
+ </PaginationLink>
133
+ );
134
+ PaginationNext.displayName = "PaginationNext";
121
135
 
122
136
  const PaginationEllipsis = ({
123
- className,
124
- ...props
137
+ className,
138
+ ...props
125
139
  }: React.HTMLAttributes<HTMLSpanElement>) => (
126
- <span
127
- aria-hidden
128
- className={cn("flex h-9 w-9 items-center justify-center", className)}
129
- {...props}
130
- >
131
- <svg className="h-4 w-4" fill="currentColor" viewBox="0 0 24 24">
132
- <circle cx="12" cy="12" r="1" />
133
- <circle cx="19" cy="12" r="1" />
134
- <circle cx="5" cy="12" r="1" />
135
- </svg>
136
- <span className="sr-only">More pages</span>
137
- </span>
138
- )
139
- PaginationEllipsis.displayName = "PaginationEllipsis"
140
+ <span
141
+ aria-hidden
142
+ className={cn("flex h-9 w-9 items-center justify-center", className)}
143
+ {...props}
144
+ >
145
+ <svg className="h-4 w-4" fill="currentColor" viewBox="0 0 24 24">
146
+ <circle cx="12" cy="12" r="1" />
147
+ <circle cx="19" cy="12" r="1" />
148
+ <circle cx="5" cy="12" r="1" />
149
+ </svg>
150
+ <span className="sr-only">More pages</span>
151
+ </span>
152
+ );
153
+ PaginationEllipsis.displayName = "PaginationEllipsis";
140
154
 
141
155
  export {
142
- Pagination,
143
- PaginationContent,
144
- PaginationLink,
145
- PaginationItem,
146
- PaginationPrevious,
147
- PaginationNext,
148
- PaginationEllipsis,
149
- }
156
+ Pagination,
157
+ PaginationContent,
158
+ PaginationLink,
159
+ PaginationItem,
160
+ PaginationPrevious,
161
+ PaginationNext,
162
+ PaginationEllipsis,
163
+ };
@@ -1,24 +1,30 @@
1
- import * as React from "react"
2
- import { cn } from "@/lib/utils"
1
+ "use client";
2
+ import * as React from "react";
3
+ import { cn } from "@/lib/utils";
3
4
 
4
5
  interface RadioGroupContextValue {
5
- value: string
6
- onValueChange: (value: string) => void
7
- name: string
6
+ value: string;
7
+ onValueChange: (value: string) => void;
8
+ name: string;
8
9
  }
9
10
 
10
- const RadioGroupContext = React.createContext<RadioGroupContextValue | null>(null)
11
+ const RadioGroupContext = React.createContext<RadioGroupContextValue | null>(
12
+ null,
13
+ );
11
14
 
12
- interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "onChange"> {
13
- value?: string
14
- onValueChange?: (value: string) => void
15
- defaultValue?: string
16
- name?: string
15
+ interface RadioGroupProps extends Omit<
16
+ React.HTMLAttributes<HTMLDivElement>,
17
+ "onChange"
18
+ > {
19
+ value?: string;
20
+ onValueChange?: (value: string) => void;
21
+ defaultValue?: string;
22
+ name?: string;
17
23
  }
18
24
 
19
25
  /**
20
26
  * RadioGroup component
21
- *
27
+ *
22
28
  * @example
23
29
  * <RadioGroup value={value} onValueChange={setValue}>
24
30
  * <div className="flex items-center space-x-2">
@@ -32,68 +38,92 @@ interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "on
32
38
  * </RadioGroup>
33
39
  */
34
40
  const RadioGroup = React.forwardRef<HTMLDivElement, RadioGroupProps>(
35
- ({ className, value: controlledValue, onValueChange, defaultValue = "", name = "radio-group", children, ...props }, ref) => {
36
- const [uncontrolledValue, setUncontrolledValue] = React.useState(defaultValue)
41
+ (
42
+ {
43
+ className,
44
+ value: controlledValue,
45
+ onValueChange,
46
+ defaultValue = "",
47
+ name = "radio-group",
48
+ children,
49
+ ...props
50
+ },
51
+ ref,
52
+ ) => {
53
+ const [uncontrolledValue, setUncontrolledValue] =
54
+ React.useState(defaultValue);
37
55
 
38
- const value = controlledValue !== undefined ? controlledValue : uncontrolledValue
39
- const setValue = onValueChange || setUncontrolledValue
56
+ const value =
57
+ controlledValue !== undefined ? controlledValue : uncontrolledValue;
58
+ const setValue = onValueChange || setUncontrolledValue;
40
59
 
41
- return (
42
- <RadioGroupContext.Provider value={{ value, onValueChange: setValue, name }}>
43
- <div ref={ref} role="radiogroup" className={cn("grid gap-2", className)} {...props}>
44
- {children}
45
- </div>
46
- </RadioGroupContext.Provider>
47
- )
48
- }
49
- )
50
- RadioGroup.displayName = "RadioGroup"
60
+ return (
61
+ <RadioGroupContext.Provider
62
+ value={{ value, onValueChange: setValue, name }}
63
+ >
64
+ <div
65
+ ref={ref}
66
+ role="radiogroup"
67
+ className={cn("grid gap-2", className)}
68
+ {...props}
69
+ >
70
+ {children}
71
+ </div>
72
+ </RadioGroupContext.Provider>
73
+ );
74
+ },
75
+ );
76
+ RadioGroup.displayName = "RadioGroup";
51
77
 
52
- interface RadioGroupItemProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onChange"> {
53
- value: string
78
+ interface RadioGroupItemProps extends Omit<
79
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
80
+ "onChange"
81
+ > {
82
+ value: string;
54
83
  }
55
84
 
56
85
  const RadioGroupItem = React.forwardRef<HTMLButtonElement, RadioGroupItemProps>(
57
- ({ className, value, ...props }, ref) => {
58
- const context = React.useContext(RadioGroupContext)
59
- if (!context) throw new Error("RadioGroupItem must be used within RadioGroup")
86
+ ({ className, value, ...props }, ref) => {
87
+ const context = React.useContext(RadioGroupContext);
88
+ if (!context)
89
+ throw new Error("RadioGroupItem must be used within RadioGroup");
60
90
 
61
- const isSelected = context.value === value
91
+ const isSelected = context.value === value;
62
92
 
63
- const handleClick = () => {
64
- context.onValueChange(value)
65
- }
93
+ const handleClick = () => {
94
+ context.onValueChange(value);
95
+ };
66
96
 
67
- const handleKeyDown = (e: React.KeyboardEvent) => {
68
- if (e.key === " " || e.key === "Enter") {
69
- e.preventDefault()
70
- handleClick()
71
- }
72
- }
97
+ const handleKeyDown = (e: React.KeyboardEvent) => {
98
+ if (e.key === " " || e.key === "Enter") {
99
+ e.preventDefault();
100
+ handleClick();
101
+ }
102
+ };
73
103
 
74
- return (
75
- <button
76
- ref={ref}
77
- type="button"
78
- role="radio"
79
- aria-checked={isSelected}
80
- className={cn(
81
- "aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
82
- className
83
- )}
84
- onClick={handleClick}
85
- onKeyDown={handleKeyDown}
86
- {...props}
87
- >
88
- {isSelected && (
89
- <span className="flex items-center justify-center">
90
- <span className="h-2 w-2 rounded-full bg-primary" />
91
- </span>
92
- )}
93
- </button>
94
- )
95
- }
96
- )
97
- RadioGroupItem.displayName = "RadioGroupItem"
104
+ return (
105
+ <button
106
+ ref={ref}
107
+ type="button"
108
+ role="radio"
109
+ aria-checked={isSelected}
110
+ className={cn(
111
+ "aspect-square h-4 w-4 rounded-full border border-primary text-primary shadow focus:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
112
+ className,
113
+ )}
114
+ onClick={handleClick}
115
+ onKeyDown={handleKeyDown}
116
+ {...props}
117
+ >
118
+ {isSelected && (
119
+ <span className="flex items-center justify-center">
120
+ <span className="h-2 w-2 rounded-full bg-primary" />
121
+ </span>
122
+ )}
123
+ </button>
124
+ );
125
+ },
126
+ );
127
+ RadioGroupItem.displayName = "RadioGroupItem";
98
128
 
99
- export { RadioGroup, RadioGroupItem }
129
+ export { RadioGroup, RadioGroupItem };
@@ -1,26 +1,27 @@
1
- import * as React from "react"
2
- import { cn } from "@/lib/utils"
1
+ "use client";
2
+ import * as React from "react";
3
+ import { cn } from "@/lib/utils";
3
4
 
4
5
  /**
5
6
  * Skeleton loading placeholder
6
- *
7
+ *
7
8
  * @example
8
9
  * <Skeleton className="h-4 w-[200px]" />
9
- *
10
+ *
10
11
  * @example
11
12
  * // Circle skeleton for avatars
12
13
  * <Skeleton className="h-12 w-12 rounded-full" />
13
14
  */
14
15
  const Skeleton = React.forwardRef<
15
- HTMLDivElement,
16
- React.HTMLAttributes<HTMLDivElement>
16
+ HTMLDivElement,
17
+ React.HTMLAttributes<HTMLDivElement>
17
18
  >(({ className, ...props }, ref) => (
18
- <div
19
- ref={ref}
20
- className={cn("animate-pulse rounded-md bg-primary/10", className)}
21
- {...props}
22
- />
23
- ))
24
- Skeleton.displayName = "Skeleton"
19
+ <div
20
+ ref={ref}
21
+ className={cn("animate-pulse rounded-md bg-primary/10", className)}
22
+ {...props}
23
+ />
24
+ ));
25
+ Skeleton.displayName = "Skeleton";
25
26
 
26
- export { Skeleton }
27
+ export { Skeleton };
@@ -1,69 +1,70 @@
1
- import * as React from "react"
2
- import { cn } from "@/lib/utils"
1
+ "use client";
2
+ import * as React from "react";
3
+ import { cn } from "@/lib/utils";
3
4
 
4
5
  export interface SlotProps extends React.HTMLAttributes<HTMLElement> {
5
- children?: React.ReactNode
6
+ children?: React.ReactNode;
6
7
  }
7
8
 
8
9
  const Slot = React.forwardRef<HTMLElement, SlotProps>(
9
- ({ children, className, ...props }, ref) => {
10
- if (React.isValidElement(children)) {
11
- const child = children as React.ReactElement<any>
10
+ ({ children, className, ...props }, ref) => {
11
+ if (React.isValidElement(children)) {
12
+ const child = children as React.ReactElement<any>;
12
13
 
13
- const mergedProps: Record<string, any> = { ...props }
14
- if (className) {
15
- mergedProps.className = className
16
- }
14
+ const mergedProps: Record<string, any> = { ...props };
15
+ if (className) {
16
+ mergedProps.className = className;
17
+ }
17
18
 
18
- for (const propName in child.props) {
19
- const slotPropValue = mergedProps[propName]
20
- const childPropValue = child.props[propName]
19
+ for (const propName in child.props) {
20
+ const slotPropValue = mergedProps[propName];
21
+ const childPropValue = child.props[propName];
21
22
 
22
- if (
23
- /^on[A-Z]/.test(propName) &&
24
- typeof slotPropValue === "function" &&
25
- typeof childPropValue === "function"
26
- ) {
27
- mergedProps[propName] = (...args: any[]) => {
28
- childPropValue(...args)
29
- if (!args[0]?.defaultPrevented) {
30
- slotPropValue(...args)
31
- }
32
- }
33
- } else if (propName === "style") {
34
- mergedProps[propName] = { ...slotPropValue, ...childPropValue }
35
- } else if (propName === "className") {
36
- mergedProps[propName] = cn(slotPropValue, childPropValue)
37
- } else {
38
- mergedProps[propName] = childPropValue
39
- }
23
+ if (
24
+ /^on[A-Z]/.test(propName) &&
25
+ typeof slotPropValue === "function" &&
26
+ typeof childPropValue === "function"
27
+ ) {
28
+ mergedProps[propName] = (...args: any[]) => {
29
+ childPropValue(...args);
30
+ if (!args[0]?.defaultPrevented) {
31
+ slotPropValue(...args);
40
32
  }
41
-
42
- return React.cloneElement(child, {
43
- ...mergedProps,
44
- ref: (node: HTMLElement | null) => {
45
- // Handle both function and object refs for the forwarded ref
46
- if (typeof ref === "function") {
47
- ref(node)
48
- } else if (ref && "current" in ref) {
49
- (ref as any).current = node
50
- }
51
-
52
- // Handle the child's existing ref
53
- const childRef = (child as any).ref
54
- if (typeof childRef === "function") {
55
- childRef(node)
56
- } else if (childRef && "current" in childRef) {
57
- (childRef as any).current = node
58
- }
59
- },
60
- })
33
+ };
34
+ } else if (propName === "style") {
35
+ mergedProps[propName] = { ...slotPropValue, ...childPropValue };
36
+ } else if (propName === "className") {
37
+ mergedProps[propName] = cn(slotPropValue, childPropValue);
38
+ } else {
39
+ mergedProps[propName] = childPropValue;
61
40
  }
41
+ }
62
42
 
63
- return null
43
+ return React.cloneElement(child, {
44
+ ...mergedProps,
45
+ ref: (node: HTMLElement | null) => {
46
+ // Handle both function and object refs for the forwarded ref
47
+ if (typeof ref === "function") {
48
+ ref(node);
49
+ } else if (ref && "current" in ref) {
50
+ (ref as any).current = node;
51
+ }
52
+
53
+ // Handle the child's existing ref
54
+ const childRef = (child as any).ref;
55
+ if (typeof childRef === "function") {
56
+ childRef(node);
57
+ } else if (childRef && "current" in childRef) {
58
+ (childRef as any).current = node;
59
+ }
60
+ },
61
+ });
64
62
  }
65
- )
66
63
 
67
- Slot.displayName = "Slot"
64
+ return null;
65
+ },
66
+ );
67
+
68
+ Slot.displayName = "Slot";
68
69
 
69
- export { Slot }
70
+ export { Slot };