@xyhp915/slack-base-ui 0.0.1 → 0.0.2
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/package.json +1 -1
- package/src/App.css +7 -0
- package/src/App.tsx +18 -0
- package/src/assets/react.svg +1 -0
- package/src/components/AlertDialog.tsx +185 -0
- package/src/components/AutoComplete.tsx +311 -0
- package/src/components/Avatar.tsx +70 -0
- package/src/components/Badge.tsx +48 -0
- package/src/components/Button.tsx +53 -0
- package/src/components/Checkbox.tsx +109 -0
- package/src/components/ContextMenu.tsx +393 -0
- package/src/components/Dialog.tsx +129 -0
- package/src/components/Form.tsx +409 -0
- package/src/components/IconButton.tsx +49 -0
- package/src/components/Input.tsx +56 -0
- package/src/components/Loading.tsx +123 -0
- package/src/components/Menu.tsx +368 -0
- package/src/components/Popover.tsx +200 -0
- package/src/components/Progress.tsx +89 -0
- package/src/components/Radio.tsx +137 -0
- package/src/components/Select.tsx +177 -0
- package/src/components/Switch.tsx +116 -0
- package/src/components/Tabs.tsx +128 -0
- package/src/components/Toast.tsx +149 -0
- package/src/components/Tooltip.tsx +46 -0
- package/src/components/index.ts +165 -0
- package/src/context/ThemeContext.tsx +53 -0
- package/src/context/useTheme.ts +11 -0
- package/src/examples/slack-clone/SlackApp.tsx +94 -0
- package/src/examples/slack-clone/components/ChannelHeader.tsx +34 -0
- package/src/examples/slack-clone/components/Composer.tsx +42 -0
- package/src/examples/slack-clone/components/Message.tsx +97 -0
- package/src/examples/slack-clone/components/UserProfile.tsx +78 -0
- package/src/examples/slack-clone/layout/Layout.tsx +27 -0
- package/src/examples/slack-clone/layout/Sidebar.tsx +67 -0
- package/src/examples/slack-clone/layout/SidebarItem.tsx +57 -0
- package/src/examples/slack-clone/layout/TopBar.tsx +30 -0
- package/src/index.css +240 -0
- package/src/main.tsx +16 -0
- package/src/pages/ComponentShowcase.tsx +1618 -0
- package/src/pages/Dashboard.tsx +87 -0
- package/src/pages/QuickStartDemo.tsx +262 -0
package/package.json
CHANGED
package/src/App.css
ADDED
package/src/App.tsx
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { BrowserRouter as Router, Routes, Route } from 'react-router-dom';
|
|
2
|
+
import { Dashboard } from './pages/Dashboard';
|
|
3
|
+
import { ComponentShowcase } from './pages/ComponentShowcase';
|
|
4
|
+
import SlackApp from './examples/slack-clone/SlackApp';
|
|
5
|
+
|
|
6
|
+
function App() {
|
|
7
|
+
return (
|
|
8
|
+
<Router>
|
|
9
|
+
<Routes>
|
|
10
|
+
<Route path="/" element={<Dashboard />} />
|
|
11
|
+
<Route path="/components" element={<ComponentShowcase />} />
|
|
12
|
+
<Route path="/examples/slack" element={<SlackApp />} />
|
|
13
|
+
</Routes>
|
|
14
|
+
</Router>
|
|
15
|
+
);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default App;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import clsx from 'clsx'
|
|
2
|
+
import { Dialog as BaseDialog } from '@base-ui/react'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
import { AlertTriangle, Info, CheckCircle, XCircle } from 'lucide-react'
|
|
5
|
+
import { Button } from './Button'
|
|
6
|
+
|
|
7
|
+
export type AlertDialogVariant = 'info' | 'success' | 'warning' | 'danger';
|
|
8
|
+
|
|
9
|
+
export interface AlertDialogProps {
|
|
10
|
+
open?: boolean;
|
|
11
|
+
onOpenChange?: (open: boolean) => void;
|
|
12
|
+
title: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
children?: React.ReactNode;
|
|
15
|
+
variant?: AlertDialogVariant;
|
|
16
|
+
confirmText?: string;
|
|
17
|
+
cancelText?: string;
|
|
18
|
+
onConfirm?: () => void | Promise<void>;
|
|
19
|
+
onCancel?: () => void;
|
|
20
|
+
showCancel?: boolean;
|
|
21
|
+
confirmButtonVariant?: 'primary' | 'secondary' | 'danger' | 'ghost';
|
|
22
|
+
className?: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const variantConfig = {
|
|
26
|
+
info: {
|
|
27
|
+
icon: Info,
|
|
28
|
+
iconClassName: 'text-(--slack-blue)',
|
|
29
|
+
bgClassName: 'bg-(--slack-blue)/10',
|
|
30
|
+
},
|
|
31
|
+
success: {
|
|
32
|
+
icon: CheckCircle,
|
|
33
|
+
iconClassName: 'text-(--slack-green)',
|
|
34
|
+
bgClassName: 'bg-(--slack-green)/10',
|
|
35
|
+
},
|
|
36
|
+
warning: {
|
|
37
|
+
icon: AlertTriangle,
|
|
38
|
+
iconClassName: 'text-[#E2A03F]',
|
|
39
|
+
bgClassName: 'bg-[#E2A03F]/10',
|
|
40
|
+
},
|
|
41
|
+
danger: {
|
|
42
|
+
icon: XCircle,
|
|
43
|
+
iconClassName: 'text-(--danger)',
|
|
44
|
+
bgClassName: 'bg-(--danger)/10',
|
|
45
|
+
},
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export const AlertDialog = ({
|
|
49
|
+
open,
|
|
50
|
+
onOpenChange,
|
|
51
|
+
title,
|
|
52
|
+
description,
|
|
53
|
+
children,
|
|
54
|
+
variant = 'info',
|
|
55
|
+
confirmText = 'Confirm',
|
|
56
|
+
cancelText = 'Cancel',
|
|
57
|
+
onConfirm,
|
|
58
|
+
onCancel,
|
|
59
|
+
showCancel = true,
|
|
60
|
+
confirmButtonVariant,
|
|
61
|
+
className,
|
|
62
|
+
}: AlertDialogProps) => {
|
|
63
|
+
const [isLoading, setIsLoading] = React.useState(false)
|
|
64
|
+
const config = variantConfig[variant]
|
|
65
|
+
const Icon = config.icon
|
|
66
|
+
|
|
67
|
+
// Auto-map variant to button variant if not specified
|
|
68
|
+
const buttonVariant = confirmButtonVariant ?? (variant === 'danger' ? 'danger' : 'primary')
|
|
69
|
+
|
|
70
|
+
const handleConfirm = async () => {
|
|
71
|
+
if (onConfirm) {
|
|
72
|
+
setIsLoading(true)
|
|
73
|
+
try {
|
|
74
|
+
await onConfirm()
|
|
75
|
+
onOpenChange?.(false)
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error('AlertDialog confirm error:', error)
|
|
78
|
+
} finally {
|
|
79
|
+
setIsLoading(false)
|
|
80
|
+
}
|
|
81
|
+
} else {
|
|
82
|
+
onOpenChange?.(false)
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const handleCancel = () => {
|
|
87
|
+
onCancel?.()
|
|
88
|
+
onOpenChange?.(false)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (
|
|
92
|
+
<BaseDialog.Root open={open} onOpenChange={onOpenChange}>
|
|
93
|
+
<BaseDialog.Portal>
|
|
94
|
+
{/* Backdrop */}
|
|
95
|
+
<BaseDialog.Backdrop
|
|
96
|
+
className="fixed inset-0 bg-black/50 z-40 transition-opacity duration-200"
|
|
97
|
+
/>
|
|
98
|
+
|
|
99
|
+
{/* Dialog Content */}
|
|
100
|
+
<BaseDialog.Popup
|
|
101
|
+
className={clsx(
|
|
102
|
+
'fixed left-[50%] top-[50%] z-50 translate-x-[-50%] translate-y-[-50%]',
|
|
103
|
+
'w-full max-w-md',
|
|
104
|
+
'bg-(--bg-primary) rounded-lg shadow-2xl border border-(--border-gray)',
|
|
105
|
+
'transition-all duration-200',
|
|
106
|
+
'outline-none focus-visible:outline-none',
|
|
107
|
+
className,
|
|
108
|
+
)}
|
|
109
|
+
>
|
|
110
|
+
{/* Content */}
|
|
111
|
+
<div className="p-6">
|
|
112
|
+
{/* Icon and Title Section */}
|
|
113
|
+
<div className="flex items-start gap-4 mb-4">
|
|
114
|
+
<div className={clsx('p-2 rounded-lg shrink-0', config.bgClassName)}>
|
|
115
|
+
<Icon className={clsx('w-6 h-6', config.iconClassName)}/>
|
|
116
|
+
</div>
|
|
117
|
+
<div className="flex-1">
|
|
118
|
+
<BaseDialog.Title className="text-xl font-black text-(--text-primary) leading-tight">
|
|
119
|
+
{title}
|
|
120
|
+
</BaseDialog.Title>
|
|
121
|
+
{description && (
|
|
122
|
+
<BaseDialog.Description className="text-(--text-secondary) mt-2 text-[15px] leading-relaxed">
|
|
123
|
+
{description}
|
|
124
|
+
</BaseDialog.Description>
|
|
125
|
+
)}
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
{/* Custom Content */}
|
|
130
|
+
{children && (
|
|
131
|
+
<div className="mb-4 pl-14 text-(--text-primary) text-[15px] leading-relaxed">
|
|
132
|
+
{children}
|
|
133
|
+
</div>
|
|
134
|
+
)}
|
|
135
|
+
|
|
136
|
+
{/* Action Buttons */}
|
|
137
|
+
<div className="flex items-center justify-end gap-3 mt-6">
|
|
138
|
+
{showCancel && (
|
|
139
|
+
<Button
|
|
140
|
+
variant="secondary"
|
|
141
|
+
onClick={handleCancel}
|
|
142
|
+
disabled={isLoading}
|
|
143
|
+
>
|
|
144
|
+
{cancelText}
|
|
145
|
+
</Button>
|
|
146
|
+
)}
|
|
147
|
+
<Button
|
|
148
|
+
variant={buttonVariant}
|
|
149
|
+
onClick={handleConfirm}
|
|
150
|
+
disabled={isLoading}
|
|
151
|
+
>
|
|
152
|
+
{isLoading ? 'Processing...' : confirmText}
|
|
153
|
+
</Button>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
</BaseDialog.Popup>
|
|
157
|
+
</BaseDialog.Portal>
|
|
158
|
+
</BaseDialog.Root>
|
|
159
|
+
)
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
AlertDialog.displayName = 'AlertDialog'
|
|
163
|
+
|
|
164
|
+
// Trigger component for opening alert dialogs
|
|
165
|
+
export interface AlertDialogTriggerProps extends React.ComponentPropsWithoutRef<'button'> {
|
|
166
|
+
asChild?: boolean;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
export const AlertDialogTrigger = React.forwardRef<HTMLButtonElement, AlertDialogTriggerProps>(
|
|
170
|
+
({ children, asChild, ...props }, ref) => {
|
|
171
|
+
if (asChild) {
|
|
172
|
+
return <BaseDialog.Trigger ref={ref}>{children}</BaseDialog.Trigger>
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<BaseDialog.Trigger ref={ref} {...props}>
|
|
177
|
+
{children}
|
|
178
|
+
</BaseDialog.Trigger>
|
|
179
|
+
)
|
|
180
|
+
},
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
AlertDialogTrigger.displayName = 'AlertDialogTrigger'
|
|
184
|
+
|
|
185
|
+
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
import { ChevronDown, X, Check } from 'lucide-react'
|
|
4
|
+
|
|
5
|
+
export interface AutoCompleteOption {
|
|
6
|
+
value: string
|
|
7
|
+
label: string
|
|
8
|
+
disabled?: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface AutoCompleteProps {
|
|
12
|
+
options: AutoCompleteOption[]
|
|
13
|
+
value?: string
|
|
14
|
+
defaultValue?: string
|
|
15
|
+
onValueChange?: (value: string) => void
|
|
16
|
+
/** Called when the raw input text changes */
|
|
17
|
+
onInputChange?: (input: string) => void
|
|
18
|
+
placeholder?: string
|
|
19
|
+
disabled?: boolean
|
|
20
|
+
required?: boolean
|
|
21
|
+
/** Label shown above the input */
|
|
22
|
+
label?: string
|
|
23
|
+
/** Error message shown below the input */
|
|
24
|
+
error?: string
|
|
25
|
+
fullWidth?: boolean
|
|
26
|
+
/** Show a clear button when a value is selected */
|
|
27
|
+
clearable?: boolean
|
|
28
|
+
/** Maximum dropdown height (Tailwind class) */
|
|
29
|
+
maxHeight?: string
|
|
30
|
+
/** No-results message */
|
|
31
|
+
emptyMessage?: string
|
|
32
|
+
className?: string
|
|
33
|
+
id?: string
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const AutoComplete = React.forwardRef<HTMLInputElement, AutoCompleteProps>(
|
|
37
|
+
(
|
|
38
|
+
{
|
|
39
|
+
options,
|
|
40
|
+
value: controlledValue,
|
|
41
|
+
defaultValue = '',
|
|
42
|
+
onValueChange,
|
|
43
|
+
onInputChange,
|
|
44
|
+
placeholder = 'Search…',
|
|
45
|
+
disabled,
|
|
46
|
+
required,
|
|
47
|
+
label,
|
|
48
|
+
error,
|
|
49
|
+
fullWidth,
|
|
50
|
+
clearable = true,
|
|
51
|
+
maxHeight = 'max-h-60',
|
|
52
|
+
emptyMessage = 'No results found',
|
|
53
|
+
className,
|
|
54
|
+
id,
|
|
55
|
+
},
|
|
56
|
+
ref,
|
|
57
|
+
) => {
|
|
58
|
+
const generatedId = React.useId()
|
|
59
|
+
const inputId = id ?? generatedId
|
|
60
|
+
const listboxId = `${inputId}-listbox`
|
|
61
|
+
|
|
62
|
+
// ── state ──────────────────────────────────────────────────────────────
|
|
63
|
+
const isControlled = controlledValue !== undefined
|
|
64
|
+
const [internalValue, setInternalValue] = React.useState<string>(defaultValue)
|
|
65
|
+
const selectedValue = isControlled ? controlledValue : internalValue
|
|
66
|
+
|
|
67
|
+
const [inputText, setInputText] = React.useState<string>(() => {
|
|
68
|
+
const found = options.find((o) => o.value === (isControlled ? controlledValue : defaultValue))
|
|
69
|
+
return found ? found.label : (isControlled ? controlledValue ?? '' : defaultValue)
|
|
70
|
+
})
|
|
71
|
+
const [open, setOpen] = React.useState(false)
|
|
72
|
+
const [activeIndex, setActiveIndex] = React.useState<number>(-1)
|
|
73
|
+
|
|
74
|
+
const containerRef = React.useRef<HTMLDivElement>(null)
|
|
75
|
+
const inputRef = React.useRef<HTMLInputElement>(null)
|
|
76
|
+
|
|
77
|
+
// sync external label when controlled value changes
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
if (isControlled) {
|
|
80
|
+
const found = options.find((o) => o.value === controlledValue)
|
|
81
|
+
setInputText(found ? found.label : controlledValue ?? '')
|
|
82
|
+
}
|
|
83
|
+
}, [controlledValue, isControlled, options])
|
|
84
|
+
|
|
85
|
+
// ── filtered list ──────────────────────────────────────────────────────
|
|
86
|
+
const filtered = React.useMemo(() => {
|
|
87
|
+
const q = inputText.toLowerCase()
|
|
88
|
+
return options.filter((o) => o.label.toLowerCase().includes(q))
|
|
89
|
+
}, [options, inputText])
|
|
90
|
+
|
|
91
|
+
// ── helpers ────────────────────────────────────────────────────────────
|
|
92
|
+
const selectOption = (option: AutoCompleteOption) => {
|
|
93
|
+
if (option.disabled) return
|
|
94
|
+
setInputText(option.label)
|
|
95
|
+
if (!isControlled) setInternalValue(option.value)
|
|
96
|
+
onValueChange?.(option.value)
|
|
97
|
+
setOpen(false)
|
|
98
|
+
setActiveIndex(-1)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const clearSelection = (e: React.MouseEvent) => {
|
|
102
|
+
e.stopPropagation()
|
|
103
|
+
setInputText('')
|
|
104
|
+
if (!isControlled) setInternalValue('')
|
|
105
|
+
onValueChange?.('')
|
|
106
|
+
onInputChange?.('')
|
|
107
|
+
setOpen(false)
|
|
108
|
+
inputRef.current?.focus()
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// ── event handlers ─────────────────────────────────────────────────────
|
|
112
|
+
const handleInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
113
|
+
const v = e.target.value
|
|
114
|
+
setInputText(v)
|
|
115
|
+
onInputChange?.(v)
|
|
116
|
+
if (!isControlled) setInternalValue('')
|
|
117
|
+
onValueChange?.('')
|
|
118
|
+
setOpen(true)
|
|
119
|
+
setActiveIndex(-1)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const handleInputFocus = () => {
|
|
123
|
+
setOpen(true)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const handleKeyDown = (e: React.KeyboardEvent<HTMLInputElement>) => {
|
|
127
|
+
const enabledItems = filtered.filter((o) => !o.disabled)
|
|
128
|
+
switch (e.key) {
|
|
129
|
+
case 'ArrowDown':
|
|
130
|
+
e.preventDefault()
|
|
131
|
+
setOpen(true)
|
|
132
|
+
setActiveIndex((i) => Math.min(i + 1, enabledItems.length - 1))
|
|
133
|
+
break
|
|
134
|
+
case 'ArrowUp':
|
|
135
|
+
e.preventDefault()
|
|
136
|
+
setActiveIndex((i) => Math.max(i - 1, 0))
|
|
137
|
+
break
|
|
138
|
+
case 'Enter':
|
|
139
|
+
e.preventDefault()
|
|
140
|
+
if (open && activeIndex >= 0 && enabledItems[activeIndex]) {
|
|
141
|
+
selectOption(enabledItems[activeIndex])
|
|
142
|
+
}
|
|
143
|
+
break
|
|
144
|
+
case 'Escape':
|
|
145
|
+
setOpen(false)
|
|
146
|
+
setActiveIndex(-1)
|
|
147
|
+
break
|
|
148
|
+
case 'Tab':
|
|
149
|
+
setOpen(false)
|
|
150
|
+
break
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// close on outside click
|
|
155
|
+
React.useEffect(() => {
|
|
156
|
+
const onPointerDown = (e: PointerEvent) => {
|
|
157
|
+
if (containerRef.current && !containerRef.current.contains(e.target as Node)) {
|
|
158
|
+
setOpen(false)
|
|
159
|
+
// restore label if user blurs with partial text
|
|
160
|
+
const matched = options.find((o) => o.value === selectedValue)
|
|
161
|
+
if (matched) setInputText(matched.label)
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
document.addEventListener('pointerdown', onPointerDown)
|
|
165
|
+
return () => document.removeEventListener('pointerdown', onPointerDown)
|
|
166
|
+
}, [options, selectedValue])
|
|
167
|
+
|
|
168
|
+
const showClear = clearable && (inputText || selectedValue)
|
|
169
|
+
|
|
170
|
+
return (
|
|
171
|
+
<div
|
|
172
|
+
ref={containerRef}
|
|
173
|
+
className={clsx('relative flex flex-col gap-1.5', fullWidth && 'w-full', className)}
|
|
174
|
+
>
|
|
175
|
+
{/* Label */}
|
|
176
|
+
{label && (
|
|
177
|
+
<label
|
|
178
|
+
htmlFor={inputId}
|
|
179
|
+
className="text-[14px] font-semibold text-(--text-primary)"
|
|
180
|
+
>
|
|
181
|
+
{label}
|
|
182
|
+
{required && <span className="ml-0.5 text-(--danger)">*</span>}
|
|
183
|
+
</label>
|
|
184
|
+
)}
|
|
185
|
+
|
|
186
|
+
{/* Input row */}
|
|
187
|
+
<div className="relative">
|
|
188
|
+
<input
|
|
189
|
+
ref={(node) => {
|
|
190
|
+
// forward ref + internal ref
|
|
191
|
+
;(inputRef as React.MutableRefObject<HTMLInputElement | null>).current = node
|
|
192
|
+
if (typeof ref === 'function') ref(node)
|
|
193
|
+
else if (ref) (ref as React.MutableRefObject<HTMLInputElement | null>).current = node
|
|
194
|
+
}}
|
|
195
|
+
id={inputId}
|
|
196
|
+
role="combobox"
|
|
197
|
+
aria-autocomplete="list"
|
|
198
|
+
aria-expanded={open}
|
|
199
|
+
aria-controls={listboxId}
|
|
200
|
+
aria-activedescendant={
|
|
201
|
+
activeIndex >= 0 ? `${inputId}-option-${activeIndex}` : undefined
|
|
202
|
+
}
|
|
203
|
+
autoComplete="off"
|
|
204
|
+
disabled={disabled}
|
|
205
|
+
required={required}
|
|
206
|
+
placeholder={placeholder}
|
|
207
|
+
value={inputText}
|
|
208
|
+
onChange={handleInputChange}
|
|
209
|
+
onFocus={handleInputFocus}
|
|
210
|
+
onKeyDown={handleKeyDown}
|
|
211
|
+
className={clsx(
|
|
212
|
+
'appearance-none block w-full rounded-md border text-[15px] leading-[1.4] shadow-sm',
|
|
213
|
+
'px-3 py-2 pr-9 bg-(--bg-primary) text-(--text-primary) placeholder-(--text-muted)',
|
|
214
|
+
'transition-[border-color,box-shadow,background-color] focus:outline-none',
|
|
215
|
+
'focus:border-(--accent)/70',
|
|
216
|
+
'disabled:bg-(--bg-primary) disabled:text-(--text-muted) disabled:cursor-not-allowed',
|
|
217
|
+
error
|
|
218
|
+
? 'border-(--danger) focus:border-(--danger) focus:shadow-[0_0_0_2px_var(--danger)]'
|
|
219
|
+
: 'border-(--border-light) hover:border-(--text-primary)/30',
|
|
220
|
+
)}
|
|
221
|
+
/>
|
|
222
|
+
|
|
223
|
+
{/* Trailing icons */}
|
|
224
|
+
<span className="pointer-events-none absolute inset-y-0 right-0 flex items-center pr-2.5 gap-0.5">
|
|
225
|
+
{showClear && (
|
|
226
|
+
<button
|
|
227
|
+
type="button"
|
|
228
|
+
tabIndex={-1}
|
|
229
|
+
aria-label="Clear"
|
|
230
|
+
onClick={clearSelection}
|
|
231
|
+
className={clsx(
|
|
232
|
+
'pointer-events-auto p-0.5 rounded text-(--text-muted) hover:text-(--text-primary)',
|
|
233
|
+
'transition-colors',
|
|
234
|
+
)}
|
|
235
|
+
>
|
|
236
|
+
<X size={14} />
|
|
237
|
+
</button>
|
|
238
|
+
)}
|
|
239
|
+
<ChevronDown
|
|
240
|
+
size={16}
|
|
241
|
+
className={clsx(
|
|
242
|
+
'text-(--text-muted) transition-transform duration-150',
|
|
243
|
+
open && 'rotate-180',
|
|
244
|
+
)}
|
|
245
|
+
/>
|
|
246
|
+
</span>
|
|
247
|
+
</div>
|
|
248
|
+
|
|
249
|
+
{/* Dropdown */}
|
|
250
|
+
{open && (
|
|
251
|
+
<div
|
|
252
|
+
id={listboxId}
|
|
253
|
+
role="listbox"
|
|
254
|
+
className={clsx(
|
|
255
|
+
'absolute left-0 right-0 z-50 mt-1 overflow-y-auto',
|
|
256
|
+
'rounded-md border border-(--border-light) bg-(--bg-primary) shadow-lg',
|
|
257
|
+
'py-1',
|
|
258
|
+
maxHeight,
|
|
259
|
+
label ? 'top-[calc(100%+2px)]' : 'top-[calc(100%+2px)]',
|
|
260
|
+
)}
|
|
261
|
+
style={{ top: label ? 'calc(1.5rem + 0.375rem + 2.25rem + 2px)' : 'calc(2.25rem + 2px)' }}
|
|
262
|
+
>
|
|
263
|
+
{filtered.length === 0 ? (
|
|
264
|
+
<div className="px-3 py-2 text-[13px] text-(--text-muted)">{emptyMessage}</div>
|
|
265
|
+
) : (
|
|
266
|
+
filtered.map((option, index) => {
|
|
267
|
+
const isSelected = option.value === selectedValue
|
|
268
|
+
const isActive = index === activeIndex
|
|
269
|
+
return (
|
|
270
|
+
<div
|
|
271
|
+
key={option.value}
|
|
272
|
+
id={`${inputId}-option-${index}`}
|
|
273
|
+
role="option"
|
|
274
|
+
aria-selected={isSelected}
|
|
275
|
+
aria-disabled={option.disabled}
|
|
276
|
+
onPointerDown={(e) => {
|
|
277
|
+
e.preventDefault()
|
|
278
|
+
selectOption(option)
|
|
279
|
+
}}
|
|
280
|
+
className={clsx(
|
|
281
|
+
'relative flex cursor-default select-none items-center px-3 py-1.5 text-[14px] rounded mx-1',
|
|
282
|
+
'transition-colors',
|
|
283
|
+
isActive && 'bg-(--bg-hover) outline-none',
|
|
284
|
+
isSelected && !isActive && 'bg-(--bg-hover)/60 font-medium',
|
|
285
|
+
option.disabled && 'opacity-50 cursor-not-allowed',
|
|
286
|
+
)}
|
|
287
|
+
>
|
|
288
|
+
<span className="flex-1">{option.label}</span>
|
|
289
|
+
{isSelected && (
|
|
290
|
+
<Check size={14} className="ml-2 text-(--accent) shrink-0" />
|
|
291
|
+
)}
|
|
292
|
+
</div>
|
|
293
|
+
)
|
|
294
|
+
})
|
|
295
|
+
)}
|
|
296
|
+
</div>
|
|
297
|
+
)}
|
|
298
|
+
|
|
299
|
+
{/* Error */}
|
|
300
|
+
{error && (
|
|
301
|
+
<span className="text-[12px] font-medium text-(--danger) flex items-center gap-1 leading-tight">
|
|
302
|
+
⚠️ {error}
|
|
303
|
+
</span>
|
|
304
|
+
)}
|
|
305
|
+
</div>
|
|
306
|
+
)
|
|
307
|
+
},
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
AutoComplete.displayName = 'AutoComplete'
|
|
311
|
+
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import clsx from 'clsx'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
export type AvatarStatus = 'online' | 'away' | 'dnd' | 'offline';
|
|
5
|
+
export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
|
|
6
|
+
|
|
7
|
+
export interface AvatarProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
8
|
+
src?: string;
|
|
9
|
+
alt?: string;
|
|
10
|
+
fallback?: string;
|
|
11
|
+
size?: AvatarSize;
|
|
12
|
+
status?: AvatarStatus;
|
|
13
|
+
rounded?: boolean; // Slack uses rounded squares mostly
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export const Avatar = React.forwardRef<HTMLDivElement, AvatarProps>(
|
|
17
|
+
({ className, src, alt, fallback, size = 'md', status, rounded = true, ...props }, ref) => {
|
|
18
|
+
|
|
19
|
+
const sizeClasses = {
|
|
20
|
+
xs: 'h-5 w-5 text-[10px]',
|
|
21
|
+
sm: 'h-6 w-6 text-xs',
|
|
22
|
+
md: 'h-9 w-9 text-sm',
|
|
23
|
+
lg: 'h-12 w-12 text-base',
|
|
24
|
+
xl: 'h-16 w-16 text-lg',
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const statusColors = {
|
|
28
|
+
online: 'bg-[#2bac76]',
|
|
29
|
+
away: 'bg-[#eca33d]', // Hollow circle usually, but filled for simplicity or specific icon
|
|
30
|
+
dnd: 'bg-[#e01e5a]',
|
|
31
|
+
offline: 'bg-(--text-muted)',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Slack uses rounded-md for avatars usually
|
|
35
|
+
const radiusClass = rounded ? 'rounded-md' : 'rounded-full'
|
|
36
|
+
|
|
37
|
+
return (
|
|
38
|
+
<div
|
|
39
|
+
ref={ref}
|
|
40
|
+
className={clsx('relative inline-block', className)}
|
|
41
|
+
{...props}
|
|
42
|
+
>
|
|
43
|
+
<div
|
|
44
|
+
className={clsx(
|
|
45
|
+
'overflow-hidden bg-(--bg-secondary) flex items-center justify-center font-medium text-(--text-secondary) select-none',
|
|
46
|
+
sizeClasses[size],
|
|
47
|
+
radiusClass,
|
|
48
|
+
)}
|
|
49
|
+
>
|
|
50
|
+
{src ? (
|
|
51
|
+
<img src={src} alt={alt} className="h-full w-full object-cover"/>
|
|
52
|
+
) : (
|
|
53
|
+
<span>{fallback || (alt ? alt.charAt(0).toUpperCase() : '?')}</span>
|
|
54
|
+
)}
|
|
55
|
+
</div>
|
|
56
|
+
|
|
57
|
+
{status && status !== 'offline' && (
|
|
58
|
+
<span
|
|
59
|
+
className={clsx(
|
|
60
|
+
'absolute -bottom-0.5 -right-0.5 block h-2 w-2 rounded-full ring-2 ring-(--bg-primary)',
|
|
61
|
+
statusColors[status],
|
|
62
|
+
)}
|
|
63
|
+
/>
|
|
64
|
+
)}
|
|
65
|
+
</div>
|
|
66
|
+
)
|
|
67
|
+
},
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
Avatar.displayName = 'Avatar'
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import clsx from 'clsx'
|
|
2
|
+
import React from 'react'
|
|
3
|
+
|
|
4
|
+
export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
5
|
+
count?: number;
|
|
6
|
+
dot?: boolean;
|
|
7
|
+
variant?: 'danger' | 'neutral'; // Red for mentions, Gray for unread
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
|
|
11
|
+
({ className, count, dot, variant = 'danger', children, ...props }, ref) => {
|
|
12
|
+
|
|
13
|
+
const variants = {
|
|
14
|
+
danger: 'bg-(--danger) text-(--accent-contrast)',
|
|
15
|
+
neutral: 'bg-(--badge-neutral) text-(--accent-contrast)',
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (dot) {
|
|
19
|
+
return (
|
|
20
|
+
<span
|
|
21
|
+
ref={ref}
|
|
22
|
+
className={clsx(
|
|
23
|
+
'inline-block h-2 w-2 rounded-full',
|
|
24
|
+
variants[variant],
|
|
25
|
+
className,
|
|
26
|
+
)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<span
|
|
34
|
+
ref={ref}
|
|
35
|
+
className={clsx(
|
|
36
|
+
'inline-flex items-center justify-center rounded-full px-2 py-0.5 text-[11px] font-bold min-w-5',
|
|
37
|
+
variants[variant],
|
|
38
|
+
className,
|
|
39
|
+
)}
|
|
40
|
+
{...props}
|
|
41
|
+
>
|
|
42
|
+
{count !== undefined ? count : children}
|
|
43
|
+
</span>
|
|
44
|
+
)
|
|
45
|
+
},
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
Badge.displayName = 'Badge'
|