@aereamart/design-system 0.3.0 → 0.3.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.
package/src/Textarea.tsx CHANGED
@@ -1,30 +1,30 @@
1
- import { cn } from './cn';
2
-
3
- export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
4
- label?: string;
5
- error?: string;
6
- }
7
-
8
- export function Textarea({ label, error, className, id, ...props }: TextareaProps) {
9
- return (
10
- <div className="w-full">
11
- {label && (
12
- <label htmlFor={id} className="mb-1 block text-sm font-medium text-slate-700">
13
- {label}
14
- </label>
15
- )}
16
- <textarea
17
- id={id}
18
- className={cn(
19
- 'w-full rounded-lg border bg-white px-4 py-2.5 text-sm text-slate-900 placeholder:text-slate-500 focus:outline-none focus:ring-2',
20
- error
21
- ? 'border-red-600 focus:border-red-600 focus:ring-red-500/30'
22
- : 'border-slate-500 focus:border-lime-600 focus:ring-lime-500/30',
23
- className
24
- )}
25
- {...props}
26
- />
27
- {error && <p className="mt-1 text-xs text-red-600">{error}</p>}
28
- </div>
29
- );
30
- }
1
+ import { cn } from './cn';
2
+
3
+ export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {
4
+ label?: string;
5
+ error?: string;
6
+ }
7
+
8
+ export function Textarea({ label, error, className, id, ...props }: TextareaProps) {
9
+ return (
10
+ <div className="w-full">
11
+ {label && (
12
+ <label htmlFor={id} className="mb-1 block text-sm font-medium text-slate-700">
13
+ {label}
14
+ </label>
15
+ )}
16
+ <textarea
17
+ id={id}
18
+ className={cn(
19
+ 'w-full rounded-lg border bg-white px-4 py-2.5 text-sm text-slate-900 placeholder:text-slate-500 focus:outline-none focus:ring-2',
20
+ error
21
+ ? 'border-red-600 focus:border-red-600 focus:ring-red-500/30'
22
+ : 'border-slate-500 focus:border-lime-600 focus:ring-lime-500/30',
23
+ className
24
+ )}
25
+ {...props}
26
+ />
27
+ {error && <p className="mt-1 text-xs text-red-600">{error}</p>}
28
+ </div>
29
+ );
30
+ }
package/src/Tooltip.tsx CHANGED
@@ -1,25 +1,25 @@
1
- import { cn } from './cn';
2
-
3
- export interface TooltipProps {
4
- content: React.ReactNode;
5
- side?: 'top' | 'bottom';
6
- children: React.ReactNode;
7
- className?: string;
8
- }
9
-
10
- export function Tooltip({ content, side = 'top', children, className }: TooltipProps) {
11
- return (
12
- <span className={cn('group relative inline-flex', className)}>
13
- {children}
14
- <span
15
- role="tooltip"
16
- className={cn(
17
- 'pointer-events-none absolute left-1/2 z-50 w-max max-w-xs -translate-x-1/2 rounded-lg bg-slate-900 px-3 py-1.5 text-xs font-medium text-white opacity-0 shadow-lg transition-opacity duration-200 group-hover:opacity-100 group-focus-within:opacity-100',
18
- side === 'top' ? 'bottom-full mb-2' : 'top-full mt-2'
19
- )}
20
- >
21
- {content}
22
- </span>
23
- </span>
24
- );
1
+ import { cn } from './cn';
2
+
3
+ export interface TooltipProps {
4
+ content: React.ReactNode;
5
+ side?: 'top' | 'bottom';
6
+ children: React.ReactNode;
7
+ className?: string;
8
+ }
9
+
10
+ export function Tooltip({ content, side = 'top', children, className }: TooltipProps) {
11
+ return (
12
+ <span className={cn('group relative inline-flex', className)}>
13
+ {children}
14
+ <span
15
+ role="tooltip"
16
+ className={cn(
17
+ 'pointer-events-none absolute left-1/2 z-50 w-max max-w-xs -translate-x-1/2 rounded-lg bg-slate-900 px-3 py-1.5 text-xs font-medium text-white opacity-0 shadow-lg transition-opacity duration-200 group-hover:opacity-100 group-focus-within:opacity-100',
18
+ side === 'top' ? 'bottom-full mb-2' : 'top-full mt-2'
19
+ )}
20
+ >
21
+ {content}
22
+ </span>
23
+ </span>
24
+ );
25
25
  }
package/src/TreeView.tsx CHANGED
@@ -1,105 +1,105 @@
1
- import { useId, useState } from 'react';
2
- import { ChevronRight } from 'lucide-react';
3
- import { cn } from './cn';
4
-
5
- export interface TreeNode {
6
- id: string;
7
- label: string;
8
- children?: TreeNode[];
9
- }
10
-
11
- export interface TreeViewProps {
12
- nodes: TreeNode[];
13
- defaultExpanded?: string[];
14
- defaultAllExpanded?: boolean;
15
- className?: string;
16
- }
17
-
18
- function Node({
19
- node,
20
- depth,
21
- expanded,
22
- onToggle,
23
- }: {
24
- node: TreeNode;
25
- depth: number;
26
- expanded: Set<string>;
27
- onToggle: (id: string) => void;
28
- }) {
29
- const hasChildren = !!node.children?.length;
30
- const isOpen = expanded.has(node.id);
31
-
32
- return (
33
- <li>
34
- <div className={cn('flex items-center gap-1.5 rounded-lg py-1.5 pr-2')}>
35
- <button
36
- type="button"
37
- aria-expanded={hasChildren ? isOpen : undefined}
38
- onClick={() => hasChildren && onToggle(node.id)}
39
- className={cn(
40
- 'inline-flex w-full items-center gap-1.5 rounded-lg py-1.5 pr-2 text-left text-sm font-medium transition-colors',
41
- 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40',
42
- 'hover:bg-slate-100'
43
- )}
44
- style={{ paddingLeft: `${8 + depth * 24}px` }}
45
- >
46
- {hasChildren ? (
47
- <ChevronRight
48
- className={cn('h-4 w-4 shrink-0 text-slate-400 transition-transform', isOpen && 'rotate-90')}
49
- />
50
- ) : (
51
- <span className="ml-4 h-4 w-4 shrink-0" aria-hidden="true" />
52
- )}
53
- <span className={cn(isOpen && 'font-semibold text-slate-900')}>{node.label}</span>
54
- </button>
55
- </div>
56
- {hasChildren && isOpen && (
57
- <ul role="group">
58
- {node.children!.map(child => (
59
- <Node key={child.id} node={child} depth={depth + 1} expanded={expanded} onToggle={onToggle} />
60
- ))}
61
- </ul>
62
- )}
63
- </li>
64
- );
65
- }
66
-
67
- export function TreeView({ nodes, defaultExpanded = [], defaultAllExpanded = false, className }: TreeViewProps) {
68
- const [expanded, setExpanded] = useState<Set<string>>(() => {
69
- if (defaultAllExpanded) {
70
- const all = new Set<string>();
71
- const walk = (list: TreeNode[]) => list.forEach(n => {
72
- all.add(n.id);
73
- if (n.children) walk(n.children);
74
- });
75
- walk(nodes);
76
- return all;
77
- }
78
- return new Set(defaultExpanded);
79
- });
80
- const labelId = useId();
81
-
82
- const toggle = (id: string) =>
83
- setExpanded(prev => {
84
- const next = new Set(prev);
85
- if (next.has(id)) next.delete(id);
86
- else next.add(id);
87
- return next;
88
- });
89
-
90
- return (
91
- <ul
92
- role="tree"
93
- aria-label="Tree"
94
- aria-labelledby={labelId}
95
- className={cn('space-y-0.5', className)}
96
- >
97
- <span id={labelId} className="sr-only">
98
- Tree view
99
- </span>
100
- {nodes.map(node => (
101
- <Node key={node.id} node={node} depth={0} expanded={expanded} onToggle={toggle} />
102
- ))}
103
- </ul>
104
- );
1
+ import { useId, useState } from 'react';
2
+ import { ChevronRight } from 'lucide-react';
3
+ import { cn } from './cn';
4
+
5
+ export interface TreeNode {
6
+ id: string;
7
+ label: string;
8
+ children?: TreeNode[];
9
+ }
10
+
11
+ export interface TreeViewProps {
12
+ nodes: TreeNode[];
13
+ defaultExpanded?: string[];
14
+ defaultAllExpanded?: boolean;
15
+ className?: string;
16
+ }
17
+
18
+ function Node({
19
+ node,
20
+ depth,
21
+ expanded,
22
+ onToggle,
23
+ }: {
24
+ node: TreeNode;
25
+ depth: number;
26
+ expanded: Set<string>;
27
+ onToggle: (id: string) => void;
28
+ }) {
29
+ const hasChildren = !!node.children?.length;
30
+ const isOpen = expanded.has(node.id);
31
+
32
+ return (
33
+ <li>
34
+ <div className={cn('flex items-center gap-1.5 rounded-lg py-1.5 pr-2')}>
35
+ <button
36
+ type="button"
37
+ aria-expanded={hasChildren ? isOpen : undefined}
38
+ onClick={() => hasChildren && onToggle(node.id)}
39
+ className={cn(
40
+ 'inline-flex w-full items-center gap-1.5 rounded-lg py-1.5 pr-2 text-left text-sm font-medium transition-colors',
41
+ 'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40',
42
+ 'hover:bg-slate-100'
43
+ )}
44
+ style={{ paddingLeft: `${8 + depth * 24}px` }}
45
+ >
46
+ {hasChildren ? (
47
+ <ChevronRight
48
+ className={cn('h-4 w-4 shrink-0 text-slate-400 transition-transform', isOpen && 'rotate-90')}
49
+ />
50
+ ) : (
51
+ <span className="ml-4 h-4 w-4 shrink-0" aria-hidden="true" />
52
+ )}
53
+ <span className={cn(isOpen && 'font-semibold text-slate-900')}>{node.label}</span>
54
+ </button>
55
+ </div>
56
+ {hasChildren && isOpen && (
57
+ <ul role="group">
58
+ {node.children!.map(child => (
59
+ <Node key={child.id} node={child} depth={depth + 1} expanded={expanded} onToggle={onToggle} />
60
+ ))}
61
+ </ul>
62
+ )}
63
+ </li>
64
+ );
65
+ }
66
+
67
+ export function TreeView({ nodes, defaultExpanded = [], defaultAllExpanded = false, className }: TreeViewProps) {
68
+ const [expanded, setExpanded] = useState<Set<string>>(() => {
69
+ if (defaultAllExpanded) {
70
+ const all = new Set<string>();
71
+ const walk = (list: TreeNode[]) => list.forEach(n => {
72
+ all.add(n.id);
73
+ if (n.children) walk(n.children);
74
+ });
75
+ walk(nodes);
76
+ return all;
77
+ }
78
+ return new Set(defaultExpanded);
79
+ });
80
+ const labelId = useId();
81
+
82
+ const toggle = (id: string) =>
83
+ setExpanded(prev => {
84
+ const next = new Set(prev);
85
+ if (next.has(id)) next.delete(id);
86
+ else next.add(id);
87
+ return next;
88
+ });
89
+
90
+ return (
91
+ <ul
92
+ role="tree"
93
+ aria-label="Tree"
94
+ aria-labelledby={labelId}
95
+ className={cn('space-y-0.5', className)}
96
+ >
97
+ <span id={labelId} className="sr-only">
98
+ Tree view
99
+ </span>
100
+ {nodes.map(node => (
101
+ <Node key={node.id} node={node} depth={0} expanded={expanded} onToggle={toggle} />
102
+ ))}
103
+ </ul>
104
+ );
105
105
  }
package/src/cn.ts CHANGED
@@ -1,3 +1,3 @@
1
- export function cn(...parts: Array<string | false | null | undefined>): string {
2
- return parts.filter(Boolean).join(' ');
1
+ export function cn(...parts: Array<string | false | null | undefined>): string {
2
+ return parts.filter(Boolean).join(' ');
3
3
  }