domify-ui 1.0.2 → 1.0.3

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,179 +0,0 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import { Search, ChevronDown } from "lucide-react";
5
- import { cn } from "./utils";
6
-
7
- export interface SearchableSelectOption {
8
- id: number | string;
9
- label: string;
10
- [key: string]: unknown;
11
- }
12
-
13
- export interface SearchableSelectProps {
14
- options: SearchableSelectOption[];
15
- value?: number | string | null;
16
- onChange?: (value: number | string | null) => void;
17
- onBlur?: () => void;
18
- placeholder?: string;
19
- disabled?: boolean;
20
- className?: string;
21
- getOptionLabel?: (option: SearchableSelectOption) => string;
22
- filterFunction?: (option: SearchableSelectOption, searchTerm: string) => boolean;
23
- emptyMessage?: string;
24
- name?: string;
25
- }
26
-
27
- export const SearchableSelect = React.forwardRef<
28
- HTMLInputElement,
29
- SearchableSelectProps
30
- >(
31
- (
32
- {
33
- options,
34
- value,
35
- onChange,
36
- onBlur,
37
- placeholder = "Selecione uma opcao...",
38
- disabled = false,
39
- className,
40
- getOptionLabel = (option) => option.label,
41
- filterFunction,
42
- emptyMessage = "Nenhuma opcao encontrada",
43
- name,
44
- },
45
- ref,
46
- ) => {
47
- const [isOpen, setIsOpen] = React.useState(false);
48
- const [searchTerm, setSearchTerm] = React.useState("");
49
- const containerRef = React.useRef<HTMLDivElement>(null);
50
- const inputRef = React.useRef<HTMLInputElement>(null);
51
- const listRef = React.useRef<HTMLUListElement>(null);
52
-
53
- const selectedOption = React.useMemo(
54
- () => options.find((opt) => opt.id === value) || null,
55
- [options, value],
56
- );
57
-
58
- const filteredOptions = React.useMemo(() => {
59
- if (!searchTerm.trim()) return options;
60
- const term = searchTerm.toLowerCase().trim();
61
- if (filterFunction) return options.filter((option) => filterFunction(option, term));
62
- return options.filter((option) => getOptionLabel(option).toLowerCase().includes(term));
63
- }, [options, searchTerm, getOptionLabel, filterFunction]);
64
-
65
- React.useEffect(() => {
66
- const handleClickOutside = (event: MouseEvent) => {
67
- if (containerRef.current && !containerRef.current.contains(event.target as Node)) {
68
- setIsOpen(false);
69
- setSearchTerm("");
70
- }
71
- };
72
-
73
- if (!isOpen) return;
74
- document.addEventListener("mousedown", handleClickOutside);
75
- return () => document.removeEventListener("mousedown", handleClickOutside);
76
- }, [isOpen]);
77
-
78
- React.useEffect(() => {
79
- if (!isOpen || !listRef.current || !selectedOption) return;
80
- const selectedIndex = filteredOptions.findIndex((opt) => opt.id === selectedOption.id);
81
- if (selectedIndex < 0) return;
82
- const selectedElement = listRef.current.children[selectedIndex] as HTMLElement;
83
- selectedElement?.scrollIntoView({ block: "nearest" });
84
- }, [isOpen, selectedOption, filteredOptions]);
85
-
86
- const handleSelect = (option: SearchableSelectOption) => {
87
- onChange?.(option.id);
88
- setIsOpen(false);
89
- setSearchTerm("");
90
- onBlur?.();
91
- };
92
-
93
- const handleToggle = () => {
94
- if (disabled) return;
95
- setIsOpen((prev) => !prev);
96
- setTimeout(() => inputRef.current?.focus(), 0);
97
- };
98
-
99
- const displayValue = selectedOption ? getOptionLabel(selectedOption) : "";
100
-
101
- return (
102
- <div ref={containerRef} className={cn("relative w-full", className)}>
103
- <div
104
- className={cn(
105
- "flex h-11 w-full rounded-lg border-2 bg-white px-4 py-2.5 text-sm text-gray-900 transition-all cursor-pointer",
106
- "hover:border-gray-400",
107
- "focus-within:outline-none focus-within:ring-2 focus-within:ring-blue-500 focus-within:border-blue-500",
108
- disabled && "cursor-not-allowed opacity-50 bg-gray-50 hover:border-gray-300",
109
- !isOpen && "border-gray-300",
110
- )}
111
- onClick={handleToggle}
112
- >
113
- <div className="flex items-center flex-1 min-w-0">
114
- {!isOpen && !displayValue ? <span className="text-gray-500">{placeholder}</span> : null}
115
- {!isOpen && displayValue ? <span className="truncate">{displayValue}</span> : null}
116
- {isOpen ? (
117
- <input
118
- ref={inputRef}
119
- type="text"
120
- value={searchTerm}
121
- onChange={(e) => {
122
- if (disabled) return;
123
- setSearchTerm(e.target.value);
124
- setIsOpen(true);
125
- }}
126
- placeholder={placeholder}
127
- className="flex-1 outline-none bg-transparent text-gray-900 placeholder:text-gray-500"
128
- onClick={(e) => e.stopPropagation()}
129
- disabled={disabled}
130
- />
131
- ) : null}
132
- </div>
133
-
134
- <div className="flex items-center gap-2 ml-2">
135
- <Search size={18} className={cn("text-gray-500 transition-transform", isOpen && "rotate-90")} />
136
- <ChevronDown
137
- size={18}
138
- className={cn("text-gray-500 transition-transform", isOpen && "rotate-180")}
139
- />
140
- </div>
141
- </div>
142
-
143
- {isOpen ? (
144
- <div className="absolute z-50 w-full mt-1 bg-white border-2 border-gray-300 rounded-lg shadow-lg max-h-60 overflow-hidden">
145
- <ul ref={listRef} className="overflow-y-auto max-h-60 py-1" role="listbox">
146
- {filteredOptions.length === 0 ? (
147
- <li className="px-4 py-3 text-sm text-gray-500 text-center">{emptyMessage}</li>
148
- ) : (
149
- filteredOptions.map((option) => {
150
- const isSelected = option.id === value;
151
- const label = getOptionLabel(option);
152
- return (
153
- <li
154
- key={option.id}
155
- role="option"
156
- aria-selected={isSelected}
157
- className={cn(
158
- "px-4 py-2 cursor-pointer text-sm transition-colors",
159
- "hover:bg-blue-50 hover:text-blue-900",
160
- isSelected && "bg-blue-100 text-blue-900 font-medium",
161
- )}
162
- onClick={() => handleSelect(option)}
163
- >
164
- {label}
165
- </li>
166
- );
167
- })
168
- )}
169
- </ul>
170
- </div>
171
- ) : null}
172
-
173
- {name ? <input ref={ref} type="hidden" name={name} value={value || ""} readOnly /> : null}
174
- </div>
175
- );
176
- },
177
- );
178
-
179
- SearchableSelect.displayName = "SearchableSelect";
package/src/select.tsx DELETED
@@ -1,24 +0,0 @@
1
- import * as React from "react";
2
- import { cn } from "./utils";
3
-
4
- export type SelectProps = React.SelectHTMLAttributes<HTMLSelectElement>;
5
-
6
- export const Select = React.forwardRef<HTMLSelectElement, SelectProps>(
7
- ({ className, ...props }, ref) => {
8
- return (
9
- <select
10
- className={cn(
11
- "flex h-11 w-full rounded-lg border-2 border-gray-300 bg-white px-4 py-2.5 text-sm text-gray-900 transition-all",
12
- "hover:border-gray-400",
13
- "focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500",
14
- "disabled:cursor-not-allowed disabled:opacity-50 disabled:bg-gray-50",
15
- className,
16
- )}
17
- ref={ref}
18
- {...props}
19
- />
20
- );
21
- },
22
- );
23
-
24
- Select.displayName = "Select";
package/src/skeleton.tsx DELETED
@@ -1,191 +0,0 @@
1
- "use client";
2
-
3
- import { cn } from "./utils";
4
-
5
- interface SkeletonProps {
6
- className?: string;
7
- }
8
-
9
- export function Skeleton({ className }: SkeletonProps) {
10
- return <div className={cn("animate-pulse rounded-md bg-gray-200", className)} />;
11
- }
12
-
13
- export function PropertyCardSkeleton() {
14
- return (
15
- <div className="bg-white rounded-lg shadow overflow-hidden">
16
- <Skeleton className="h-48 w-full rounded-none" />
17
- <div className="p-4 space-y-3">
18
- <Skeleton className="h-4 w-1/4" />
19
- <Skeleton className="h-6 w-3/4" />
20
- <Skeleton className="h-4 w-1/2" />
21
- <div className="flex gap-4 pt-2">
22
- <Skeleton className="h-4 w-16" />
23
- <Skeleton className="h-4 w-16" />
24
- <Skeleton className="h-4 w-16" />
25
- </div>
26
- <div className="flex justify-between pt-4">
27
- <Skeleton className="h-6 w-24" />
28
- <Skeleton className="h-8 w-20" />
29
- </div>
30
- </div>
31
- </div>
32
- );
33
- }
34
-
35
- export function TableRowSkeleton({ columns = 5 }: { columns?: number }) {
36
- return (
37
- <tr className="border-b border-gray-100">
38
- {Array.from({ length: columns }).map((_, i) => (
39
- <td key={i} className="px-4 py-3">
40
- <Skeleton className="h-4 w-full" />
41
- </td>
42
- ))}
43
- </tr>
44
- );
45
- }
46
-
47
- export function TableSkeleton({
48
- rows = 5,
49
- columns = 5,
50
- }: {
51
- rows?: number;
52
- columns?: number;
53
- }) {
54
- return (
55
- <div className="bg-white rounded-lg shadow overflow-hidden">
56
- <div className="overflow-x-auto">
57
- <table className="w-full">
58
- <thead className="bg-gray-50">
59
- <tr>
60
- {Array.from({ length: columns }).map((_, i) => (
61
- <th key={i} className="px-4 py-3 text-left">
62
- <Skeleton className="h-4 w-20" />
63
- </th>
64
- ))}
65
- </tr>
66
- </thead>
67
- <tbody>
68
- {Array.from({ length: rows }).map((_, i) => (
69
- <TableRowSkeleton key={i} columns={columns} />
70
- ))}
71
- </tbody>
72
- </table>
73
- </div>
74
- </div>
75
- );
76
- }
77
-
78
- export function ListItemSkeleton() {
79
- return (
80
- <div className="flex items-center gap-4 p-4 bg-white rounded-lg shadow">
81
- <Skeleton className="h-12 w-12 rounded-full" />
82
- <div className="flex-1 space-y-2">
83
- <Skeleton className="h-4 w-1/3" />
84
- <Skeleton className="h-3 w-1/2" />
85
- </div>
86
- <Skeleton className="h-8 w-20" />
87
- </div>
88
- );
89
- }
90
-
91
- export function StatsCardSkeleton() {
92
- return (
93
- <div className="bg-white rounded-lg shadow p-6">
94
- <div className="flex items-center justify-between">
95
- <div className="space-y-2">
96
- <Skeleton className="h-4 w-24" />
97
- <Skeleton className="h-8 w-16" />
98
- </div>
99
- <Skeleton className="h-12 w-12 rounded-full" />
100
- </div>
101
- </div>
102
- );
103
- }
104
-
105
- export function FormSkeleton({ fields = 4 }: { fields?: number }) {
106
- return (
107
- <div className="bg-white rounded-lg shadow p-6 space-y-6">
108
- {Array.from({ length: fields }).map((_, i) => (
109
- <div key={i} className="space-y-2">
110
- <Skeleton className="h-4 w-24" />
111
- <Skeleton className="h-10 w-full" />
112
- </div>
113
- ))}
114
- <div className="flex justify-end gap-4 pt-4">
115
- <Skeleton className="h-10 w-24" />
116
- <Skeleton className="h-10 w-32" />
117
- </div>
118
- </div>
119
- );
120
- }
121
-
122
- export function DetailPageSkeleton() {
123
- return (
124
- <div className="space-y-6">
125
- <div className="flex items-center justify-between">
126
- <div className="space-y-2">
127
- <Skeleton className="h-8 w-48" />
128
- <Skeleton className="h-4 w-32" />
129
- </div>
130
- <div className="flex gap-2">
131
- <Skeleton className="h-10 w-24" />
132
- <Skeleton className="h-10 w-24" />
133
- </div>
134
- </div>
135
- <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
136
- <div className="lg:col-span-2 space-y-6">
137
- <div className="bg-white rounded-lg shadow p-6 space-y-4">
138
- <Skeleton className="h-6 w-32" />
139
- <Skeleton className="h-4 w-full" />
140
- <Skeleton className="h-4 w-full" />
141
- <Skeleton className="h-4 w-3/4" />
142
- </div>
143
- <div className="bg-white rounded-lg shadow p-6 space-y-4">
144
- <Skeleton className="h-6 w-32" />
145
- <div className="grid grid-cols-2 gap-4">
146
- {Array.from({ length: 6 }).map((_, i) => (
147
- <div key={i} className="space-y-1">
148
- <Skeleton className="h-4 w-20" />
149
- <Skeleton className="h-4 w-28" />
150
- </div>
151
- ))}
152
- </div>
153
- </div>
154
- </div>
155
- <div className="space-y-6">
156
- <div className="bg-white rounded-lg shadow p-6 space-y-4">
157
- <Skeleton className="h-6 w-24" />
158
- <Skeleton className="h-8 w-full" />
159
- <Skeleton className="h-4 w-full" />
160
- </div>
161
- </div>
162
- </div>
163
- </div>
164
- );
165
- }
166
-
167
- export function DashboardSkeleton() {
168
- return (
169
- <div className="space-y-6">
170
- <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4">
171
- {Array.from({ length: 4 }).map((_, i) => (
172
- <StatsCardSkeleton key={i} />
173
- ))}
174
- </div>
175
- <div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
176
- <div className="bg-white rounded-lg shadow p-6">
177
- <Skeleton className="h-6 w-32 mb-4" />
178
- <Skeleton className="h-64 w-full" />
179
- </div>
180
- <div className="bg-white rounded-lg shadow p-6">
181
- <Skeleton className="h-6 w-32 mb-4" />
182
- <div className="space-y-4">
183
- {Array.from({ length: 5 }).map((_, i) => (
184
- <ListItemSkeleton key={i} />
185
- ))}
186
- </div>
187
- </div>
188
- </div>
189
- </div>
190
- );
191
- }
package/src/switch.tsx DELETED
@@ -1,53 +0,0 @@
1
- "use client";
2
-
3
- import * as React from "react";
4
- import { cn } from "./utils";
5
-
6
- export interface SwitchProps {
7
- id?: string;
8
- checked?: boolean;
9
- onCheckedChange?: (checked: boolean) => void;
10
- disabled?: boolean;
11
- className?: string;
12
- }
13
-
14
- export const Switch = React.forwardRef<HTMLButtonElement, SwitchProps>(
15
- (
16
- { id, checked = false, onCheckedChange, disabled = false, className },
17
- ref,
18
- ) => {
19
- const handleClick = () => {
20
- if (!disabled && onCheckedChange) {
21
- onCheckedChange(!checked);
22
- }
23
- };
24
-
25
- return (
26
- <button
27
- type="button"
28
- id={id}
29
- role="switch"
30
- aria-checked={checked}
31
- disabled={disabled}
32
- onClick={handleClick}
33
- ref={ref}
34
- className={cn(
35
- "relative inline-flex h-6 w-11 items-center rounded-full transition-colors",
36
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2",
37
- "disabled:cursor-not-allowed disabled:opacity-50",
38
- checked ? "bg-[#0052CC]" : "bg-gray-300",
39
- className,
40
- )}
41
- >
42
- <span
43
- className={cn(
44
- "inline-block h-5 w-5 transform rounded-full bg-white shadow-sm transition-transform",
45
- checked ? "translate-x-6" : "translate-x-0.5",
46
- )}
47
- />
48
- </button>
49
- );
50
- },
51
- );
52
-
53
- Switch.displayName = "Switch";
package/src/tabs.tsx DELETED
@@ -1,121 +0,0 @@
1
- import * as React from "react";
2
- import { cn } from "./utils";
3
-
4
- interface TabsContextValue {
5
- value: string;
6
- onValueChange: (value: string) => void;
7
- }
8
-
9
- const TabsContext = React.createContext<TabsContextValue | undefined>(undefined);
10
-
11
- function useTabsContext() {
12
- const context = React.useContext(TabsContext);
13
- if (!context) {
14
- throw new Error("Tabs components must be used within a Tabs component");
15
- }
16
- return context;
17
- }
18
-
19
- interface TabsProps extends React.HTMLAttributes<HTMLDivElement> {
20
- defaultValue: string;
21
- onValueChange?: (value: string) => void;
22
- }
23
-
24
- export function Tabs({
25
- defaultValue,
26
- onValueChange,
27
- children,
28
- className,
29
- ...props
30
- }: TabsProps) {
31
- const [value, setValue] = React.useState(defaultValue);
32
-
33
- const handleValueChange = React.useCallback(
34
- (newValue: string) => {
35
- setValue(newValue);
36
- onValueChange?.(newValue);
37
- },
38
- [onValueChange],
39
- );
40
-
41
- return (
42
- <TabsContext.Provider value={{ value, onValueChange: handleValueChange }}>
43
- <div className={cn("w-full", className)} {...props}>
44
- {children}
45
- </div>
46
- </TabsContext.Provider>
47
- );
48
- }
49
-
50
- type TabsListProps = React.HTMLAttributes<HTMLDivElement>;
51
-
52
- export function TabsList({ children, className, ...props }: TabsListProps) {
53
- return (
54
- <div
55
- className={cn(
56
- "inline-flex h-10 items-center justify-center rounded-lg bg-gray-100 p-1 text-gray-500",
57
- className,
58
- )}
59
- {...props}
60
- >
61
- {children}
62
- </div>
63
- );
64
- }
65
-
66
- interface TabsTriggerProps
67
- extends React.ButtonHTMLAttributes<HTMLButtonElement> {
68
- value: string;
69
- }
70
-
71
- export function TabsTrigger({
72
- value,
73
- children,
74
- className,
75
- ...props
76
- }: TabsTriggerProps) {
77
- const { value: selectedValue, onValueChange } = useTabsContext();
78
- const isSelected = value === selectedValue;
79
-
80
- return (
81
- <button
82
- type="button"
83
- role="tab"
84
- aria-selected={isSelected}
85
- onClick={() => onValueChange(value)}
86
- className={cn(
87
- "inline-flex items-center justify-center whitespace-nowrap rounded-md px-3 py-1.5 text-sm font-medium transition-all",
88
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-blue-500 focus-visible:ring-offset-2",
89
- "disabled:pointer-events-none disabled:opacity-50",
90
- isSelected
91
- ? "bg-white text-gray-900 shadow-sm"
92
- : "text-gray-600 hover:bg-gray-50 hover:text-gray-900",
93
- className,
94
- )}
95
- {...props}
96
- >
97
- {children}
98
- </button>
99
- );
100
- }
101
-
102
- interface TabsContentProps extends React.HTMLAttributes<HTMLDivElement> {
103
- value: string;
104
- }
105
-
106
- export function TabsContent({
107
- value,
108
- children,
109
- className,
110
- ...props
111
- }: TabsContentProps) {
112
- const { value: selectedValue } = useTabsContext();
113
-
114
- if (value !== selectedValue) return null;
115
-
116
- return (
117
- <div role="tabpanel" className={cn("mt-2", className)} {...props}>
118
- {children}
119
- </div>
120
- );
121
- }
package/src/textarea.tsx DELETED
@@ -1,25 +0,0 @@
1
- import * as React from "react";
2
- import { cn } from "./utils";
3
-
4
- export type TextareaProps = React.TextareaHTMLAttributes<HTMLTextAreaElement>;
5
-
6
- export const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
7
- ({ className, ...props }, ref) => {
8
- return (
9
- <textarea
10
- className={cn(
11
- "flex min-h-[100px] w-full rounded-lg border-2 border-gray-300 bg-white px-4 py-3 text-sm text-gray-900 placeholder:text-gray-500 transition-all",
12
- "hover:border-gray-400",
13
- "focus:outline-none focus:ring-2 focus:ring-[#0052CC] focus:border-[#0052CC]",
14
- "disabled:cursor-not-allowed disabled:opacity-50 disabled:bg-gray-50",
15
- "resize-y",
16
- className,
17
- )}
18
- ref={ref}
19
- {...props}
20
- />
21
- );
22
- },
23
- );
24
-
25
- Textarea.displayName = "Textarea";
package/src/utils.ts DELETED
@@ -1,6 +0,0 @@
1
- import { type ClassValue, clsx } from "clsx";
2
- import { twMerge } from "tailwind-merge";
3
-
4
- export function cn(...inputs: ClassValue[]) {
5
- return twMerge(clsx(inputs));
6
- }
@@ -1,11 +0,0 @@
1
- import type { Config } from "tailwindcss";
2
-
3
- const config: Config = {
4
- content: ["./src/**/*.{ts,tsx}"],
5
- theme: {
6
- extend: {},
7
- },
8
- plugins: [],
9
- };
10
-
11
- export default config;
package/tsconfig.json DELETED
@@ -1,17 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "lib": ["dom", "es2020"],
5
- "module": "ESNext",
6
- "moduleResolution": "bundler",
7
- "jsx": "react-jsx",
8
- "strict": true,
9
- "skipLibCheck": true,
10
- "declaration": true,
11
- "declarationMap": true,
12
- "emitDeclarationOnly": true,
13
- "outDir": "dist",
14
- "baseUrl": "."
15
- },
16
- "include": ["src/**/*"]
17
- }
package/tsup.config.ts DELETED
@@ -1,16 +0,0 @@
1
- import { defineConfig } from 'tsup'
2
-
3
- export default defineConfig({
4
- entry: ['src/index.ts'],
5
- format: ['esm', 'cjs'],
6
- dts: true,
7
- splitting: false,
8
- sourcemap: true,
9
- clean: true,
10
- external: ['react', 'react-dom'],
11
- outExtension({ format }) {
12
- return {
13
- js: format === 'esm' ? '.js' : '.cjs',
14
- }
15
- },
16
- })