@open-elements/ui 0.3.0 → 0.4.0
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/README.md +1 -0
- package/dist/components/markdown-editor.d.ts +3 -0
- package/dist/components/markdown-editor.d.ts.map +1 -0
- package/dist/components/markdown-editor.js +77 -0
- package/dist/components/markdown-editor.js.map +1 -0
- package/dist/components/markdown-view.d.ts +3 -0
- package/dist/components/markdown-view.d.ts.map +1 -0
- package/dist/components/markdown-view.js +46 -0
- package/dist/components/markdown-view.js.map +1 -0
- package/dist/components/user-avatar.d.ts +3 -0
- package/dist/components/user-avatar.d.ts.map +1 -0
- package/dist/components/user-avatar.js +38 -0
- package/dist/components/user-avatar.js.map +1 -0
- package/dist/components/user-multi-select.d.ts +3 -0
- package/dist/components/user-multi-select.d.ts.map +1 -0
- package/dist/components/user-multi-select.js +46 -0
- package/dist/components/user-multi-select.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +30 -0
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +15 -3
- package/src/components/__tests__/markdown-editor.test.tsx +35 -0
- package/src/components/__tests__/markdown-view.test.tsx +32 -0
- package/src/components/__tests__/user-avatar.test.tsx +68 -0
- package/src/components/__tests__/user-multi-select.test.tsx +97 -0
- package/src/components/markdown-editor.tsx +143 -0
- package/src/components/markdown-view.tsx +49 -0
- package/src/components/user-avatar.tsx +60 -0
- package/src/components/user-multi-select.tsx +134 -0
- package/src/index.ts +16 -0
- package/src/types/index.ts +36 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Check, ChevronsUpDown, X } from "lucide-react";
|
|
5
|
+
import { Button } from "./button.tsx";
|
|
6
|
+
import { Popover, PopoverContent, PopoverTrigger } from "./popover.tsx";
|
|
7
|
+
import { cn } from "../lib/utils.ts";
|
|
8
|
+
import { UserAvatar } from "./user-avatar.tsx";
|
|
9
|
+
import type { UserMultiSelectProps } from "../types/index.ts";
|
|
10
|
+
|
|
11
|
+
export function UserMultiSelect({
|
|
12
|
+
users,
|
|
13
|
+
selectedIds,
|
|
14
|
+
onChange,
|
|
15
|
+
disabledIds = [],
|
|
16
|
+
translations,
|
|
17
|
+
}: UserMultiSelectProps) {
|
|
18
|
+
const [open, setOpen] = useState(false);
|
|
19
|
+
const [search, setSearch] = useState("");
|
|
20
|
+
|
|
21
|
+
const toggle = (id: string) => {
|
|
22
|
+
if (disabledIds.includes(id)) return;
|
|
23
|
+
if (selectedIds.includes(id)) {
|
|
24
|
+
onChange(selectedIds.filter((s) => s !== id));
|
|
25
|
+
} else {
|
|
26
|
+
onChange([...selectedIds, id]);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const selectedUsers = users.filter((u) => selectedIds.includes(u.id));
|
|
31
|
+
const filteredUsers = search
|
|
32
|
+
? users.filter(
|
|
33
|
+
(u) =>
|
|
34
|
+
u.name.toLowerCase().includes(search.toLowerCase()) ||
|
|
35
|
+
u.email.toLowerCase().includes(search.toLowerCase()),
|
|
36
|
+
)
|
|
37
|
+
: users;
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
41
|
+
<PopoverTrigger asChild>
|
|
42
|
+
<Button
|
|
43
|
+
variant="outline"
|
|
44
|
+
role="combobox"
|
|
45
|
+
aria-expanded={open}
|
|
46
|
+
className="h-auto min-h-[40px] w-full justify-between"
|
|
47
|
+
type="button"
|
|
48
|
+
>
|
|
49
|
+
<div className="flex flex-wrap gap-1.5 overflow-hidden">
|
|
50
|
+
{selectedUsers.length > 0 ? (
|
|
51
|
+
selectedUsers.map((user) => {
|
|
52
|
+
const isDisabled = disabledIds.includes(user.id);
|
|
53
|
+
return (
|
|
54
|
+
<span
|
|
55
|
+
key={user.id}
|
|
56
|
+
className="bg-muted inline-flex items-center gap-1.5 rounded-full py-0.5 pr-2 pl-1 text-xs font-medium"
|
|
57
|
+
>
|
|
58
|
+
<UserAvatar user={user} size="sm" />
|
|
59
|
+
<span className="max-w-[120px] truncate">{user.name}</span>
|
|
60
|
+
{!isDisabled && (
|
|
61
|
+
<span
|
|
62
|
+
role="button"
|
|
63
|
+
tabIndex={0}
|
|
64
|
+
onClick={(e) => {
|
|
65
|
+
e.stopPropagation();
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
toggle(user.id);
|
|
68
|
+
}}
|
|
69
|
+
onKeyDown={(e) => {
|
|
70
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
71
|
+
e.stopPropagation();
|
|
72
|
+
e.preventDefault();
|
|
73
|
+
toggle(user.id);
|
|
74
|
+
}
|
|
75
|
+
}}
|
|
76
|
+
className="text-muted-foreground hover:text-foreground ml-0.5 cursor-pointer"
|
|
77
|
+
>
|
|
78
|
+
<X className="h-3 w-3" />
|
|
79
|
+
</span>
|
|
80
|
+
)}
|
|
81
|
+
</span>
|
|
82
|
+
);
|
|
83
|
+
})
|
|
84
|
+
) : (
|
|
85
|
+
<span className="text-muted-foreground">{translations.placeholder}</span>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
<ChevronsUpDown className="ml-2 h-4 w-4 shrink-0 opacity-50" />
|
|
89
|
+
</Button>
|
|
90
|
+
</PopoverTrigger>
|
|
91
|
+
<PopoverContent className="w-[320px] p-0" align="start">
|
|
92
|
+
<div className="border-b p-2">
|
|
93
|
+
<input
|
|
94
|
+
type="text"
|
|
95
|
+
placeholder={translations.searchPlaceholder}
|
|
96
|
+
value={search}
|
|
97
|
+
onChange={(e) => setSearch(e.target.value)}
|
|
98
|
+
className="placeholder:text-muted-foreground w-full rounded-md border-0 bg-transparent px-2 py-1.5 text-sm outline-none"
|
|
99
|
+
/>
|
|
100
|
+
</div>
|
|
101
|
+
<div className="max-h-[300px] overflow-y-auto p-1">
|
|
102
|
+
{filteredUsers.map((user) => {
|
|
103
|
+
const isSelected = selectedIds.includes(user.id);
|
|
104
|
+
const isDisabled = disabledIds.includes(user.id);
|
|
105
|
+
return (
|
|
106
|
+
<button
|
|
107
|
+
key={user.id}
|
|
108
|
+
type="button"
|
|
109
|
+
onClick={() => toggle(user.id)}
|
|
110
|
+
disabled={isDisabled}
|
|
111
|
+
className={cn(
|
|
112
|
+
"hover:bg-accent flex w-full items-center gap-3 rounded-md px-2 py-2 text-sm",
|
|
113
|
+
isDisabled && "cursor-not-allowed opacity-60",
|
|
114
|
+
)}
|
|
115
|
+
>
|
|
116
|
+
<Check
|
|
117
|
+
className={cn("h-4 w-4 shrink-0", isSelected ? "opacity-100" : "opacity-0")}
|
|
118
|
+
/>
|
|
119
|
+
<UserAvatar user={user} size="md" />
|
|
120
|
+
<div className="flex flex-col items-start overflow-hidden">
|
|
121
|
+
<span className="truncate font-medium">{user.name}</span>
|
|
122
|
+
<span className="text-muted-foreground truncate text-xs">{user.email}</span>
|
|
123
|
+
</div>
|
|
124
|
+
</button>
|
|
125
|
+
);
|
|
126
|
+
})}
|
|
127
|
+
{filteredUsers.length === 0 && (
|
|
128
|
+
<p className="text-muted-foreground py-4 text-center text-sm">{translations.empty}</p>
|
|
129
|
+
)}
|
|
130
|
+
</div>
|
|
131
|
+
</PopoverContent>
|
|
132
|
+
</Popover>
|
|
133
|
+
);
|
|
134
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -147,8 +147,24 @@ export type {
|
|
|
147
147
|
UserSectionTranslations,
|
|
148
148
|
} from "./components/sidebar.tsx";
|
|
149
149
|
|
|
150
|
+
// Markdown components
|
|
151
|
+
export { MarkdownEditor } from "./components/markdown-editor.tsx";
|
|
152
|
+
export { MarkdownView } from "./components/markdown-view.tsx";
|
|
153
|
+
|
|
154
|
+
// User components
|
|
155
|
+
export { UserAvatar } from "./components/user-avatar.tsx";
|
|
156
|
+
export { UserMultiSelect } from "./components/user-multi-select.tsx";
|
|
157
|
+
|
|
150
158
|
// Types
|
|
151
159
|
export type { TagDto } from "./types/index.ts";
|
|
160
|
+
export type {
|
|
161
|
+
UserOption,
|
|
162
|
+
UserAvatarProps,
|
|
163
|
+
UserMultiSelectProps,
|
|
164
|
+
UserMultiSelectTranslations,
|
|
165
|
+
MarkdownEditorProps,
|
|
166
|
+
MarkdownViewProps,
|
|
167
|
+
} from "./types/index.ts";
|
|
152
168
|
|
|
153
169
|
// Utilities
|
|
154
170
|
export { cn } from "./lib/utils.ts";
|
package/src/types/index.ts
CHANGED
|
@@ -27,3 +27,39 @@ export interface TagMultiSelectProps {
|
|
|
27
27
|
readonly loadTags: () => Promise<TagOption[]>;
|
|
28
28
|
readonly translations: TagMultiSelectTranslations;
|
|
29
29
|
}
|
|
30
|
+
|
|
31
|
+
export interface UserOption {
|
|
32
|
+
readonly id: string;
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly email: string;
|
|
35
|
+
readonly avatarUrl?: string | null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface UserAvatarProps {
|
|
39
|
+
readonly user: UserOption;
|
|
40
|
+
readonly size?: "sm" | "md";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface UserMultiSelectTranslations {
|
|
44
|
+
readonly placeholder: string;
|
|
45
|
+
readonly searchPlaceholder: string;
|
|
46
|
+
readonly empty: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface UserMultiSelectProps {
|
|
50
|
+
readonly users: readonly UserOption[];
|
|
51
|
+
readonly selectedIds: readonly string[];
|
|
52
|
+
readonly onChange: (ids: string[]) => void;
|
|
53
|
+
readonly disabledIds?: readonly string[];
|
|
54
|
+
readonly translations: UserMultiSelectTranslations;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface MarkdownEditorProps {
|
|
58
|
+
readonly value: string;
|
|
59
|
+
readonly onChange: (value: string) => void;
|
|
60
|
+
readonly placeholder?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface MarkdownViewProps {
|
|
64
|
+
readonly content: string;
|
|
65
|
+
}
|