added new pages
This commit is contained in:
@@ -161,7 +161,7 @@ function SelectAllDropdown({
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute top-10 left-0 z-50 w-52 bg-card border border-border rounded-lg shadow-lg py-1">
|
||||
<div className="absolute top-10 left-0 z-50 w-52 bg-card border border-border rounded-md shadow-lg py-1">
|
||||
<button
|
||||
onClick={() => {
|
||||
onSelectPage(true)
|
||||
@@ -370,7 +370,7 @@ export function DataTable<TData>({
|
||||
<div
|
||||
className={cn(
|
||||
'border border-border overflow-hidden',
|
||||
showBanner ? 'rounded-b-lg rounded-t-none' : 'rounded-lg'
|
||||
showBanner ? 'rounded-b-lg rounded-t-none' : 'rounded-md'
|
||||
)}
|
||||
>
|
||||
<Table>
|
||||
|
||||
@@ -133,7 +133,7 @@ function ToggleColumnsDropdown({
|
||||
<button
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className={cn(
|
||||
'flex items-center gap-1.5 h-9 px-3 rounded-md border border-border',
|
||||
'flex items-center gap-1.5 h-9 px-3 rounded-md border border-border cursor-pointer',
|
||||
'text-sm text-muted-foreground bg-background',
|
||||
'hover:bg-muted/50 hover:text-foreground transition-colors',
|
||||
open && 'bg-muted/50 text-foreground border-ring'
|
||||
@@ -144,7 +144,7 @@ function ToggleColumnsDropdown({
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute right-0 mt-1.5 w-52 bg-card border border-border rounded-lg shadow-lg z-50 py-2">
|
||||
<div className="absolute right-0 mt-1.5 w-52 bg-card border border-border rounded-md shadow-lg z-50 py-2">
|
||||
<p className="px-3 pb-1.5 text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{t('table.toggleColumns', 'Toggle Columns')}
|
||||
</p>
|
||||
@@ -193,7 +193,7 @@ function DateFilterButton() {
|
||||
return (
|
||||
<button
|
||||
className={cn(
|
||||
'flex items-center h-9 px-3 rounded-md border border-border',
|
||||
'flex items-center h-9 px-3 rounded-md border border-border cursor-pointer',
|
||||
'text-muted-foreground bg-background',
|
||||
'hover:bg-muted/50 hover:text-foreground transition-colors'
|
||||
)}
|
||||
@@ -240,7 +240,7 @@ function FilterDropdown({
|
||||
<button
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className={cn(
|
||||
'flex items-center gap-1.5 h-9 px-3 rounded-md border border-border',
|
||||
'flex items-center gap-1.5 h-9 px-3 rounded-md border border-border cursor-pointer',
|
||||
'text-muted-foreground bg-background',
|
||||
'hover:bg-muted/50 hover:text-foreground transition-colors',
|
||||
open && 'bg-muted/50 text-foreground border-ring',
|
||||
@@ -258,7 +258,7 @@ function FilterDropdown({
|
||||
</button>
|
||||
|
||||
{open && (
|
||||
<div className="absolute right-0 mt-1.5 w-64 bg-card border border-border rounded-lg shadow-lg z-50 py-3">
|
||||
<div className="absolute right-0 mt-1.5 w-64 bg-card border border-border rounded-md shadow-lg z-50 py-3">
|
||||
<div className="flex items-center justify-between px-3 pb-2 border-b border-border mb-2">
|
||||
<p className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{t('table.filters', 'Filters')}
|
||||
|
||||
655
src/components/formInput.tsx
Normal file
655
src/components/formInput.tsx
Normal file
@@ -0,0 +1,655 @@
|
||||
import { useState, useRef } from 'react'
|
||||
import * as CollapsiblePrimitive from '@radix-ui/react-collapsible'
|
||||
import { Check, ChevronsUpDown, Search, X, Eye, EyeOff, Upload, Hash } from 'lucide-react'
|
||||
|
||||
import { cn } from '@/lib/utils'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
||||
import { Calendar } from '@/components/ui/calendar'
|
||||
import { format, parse, isValid } from 'date-fns'
|
||||
import { CalendarIcon } from 'lucide-react'
|
||||
|
||||
// ─── Collapsible aliases ──────────────────────────────────────────────────────
|
||||
|
||||
const Collapsible = CollapsiblePrimitive.Root
|
||||
const CollapsibleTrigger = CollapsiblePrimitive.Trigger
|
||||
const CollapsibleContent = CollapsiblePrimitive.Content
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
export type FormInputType =
|
||||
| 'text'
|
||||
| 'number'
|
||||
| 'phone'
|
||||
| 'email'
|
||||
| 'password'
|
||||
| 'date'
|
||||
| 'select'
|
||||
| 'searchable-select'
|
||||
| 'file'
|
||||
| 'textarea'
|
||||
|
||||
export interface SelectOption {
|
||||
value: string
|
||||
label: string
|
||||
}
|
||||
|
||||
export interface FormInputProps {
|
||||
type?: FormInputType
|
||||
label?: string
|
||||
value?: string
|
||||
onChange?: (value: string) => void
|
||||
placeholder?: string
|
||||
error?: string
|
||||
required?: boolean
|
||||
disabled?: boolean
|
||||
options?: SelectOption[]
|
||||
accept?: string
|
||||
onFileChange?: (file: File | null) => void
|
||||
fileValue?: File | null
|
||||
className?: string
|
||||
phonePrefix?: string
|
||||
rows?: number
|
||||
name?: string
|
||||
readOnly?: boolean
|
||||
}
|
||||
|
||||
// ─── FieldLabel ───────────────────────────────────────────────────────────────
|
||||
|
||||
function FieldLabel({ label, required }: { label?: string; required?: boolean }) {
|
||||
if (!label) return null
|
||||
return (
|
||||
<label className="block text-xs font-semibold text-muted-foreground uppercase tracking-wider mb-1.5 select-none">
|
||||
{label}
|
||||
{required && <span className="text-destructive ml-0.5">*</span>}
|
||||
</label>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── ErrorMsg ─────────────────────────────────────────────────────────────────
|
||||
|
||||
function ErrorMsg({ error }: { error?: string }) {
|
||||
if (!error) return null
|
||||
return (
|
||||
<p className="mt-1.5 text-xs text-destructive font-medium flex items-center gap-1.5">
|
||||
<span className="inline-block w-1 h-1 rounded-full bg-destructive shrink-0" />
|
||||
{error}
|
||||
</p>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── error border helper ──────────────────────────────────────────────────────
|
||||
|
||||
const withError = (error?: string) =>
|
||||
error ? 'border-destructive focus-visible:ring-destructive/30' : ''
|
||||
|
||||
// ─── TextInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
function TextInput({
|
||||
type = 'text',
|
||||
value = '',
|
||||
onChange,
|
||||
placeholder,
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
name,
|
||||
readOnly,
|
||||
rows = 3,
|
||||
}: FormInputProps) {
|
||||
const [showPass, setShowPass] = useState(false)
|
||||
|
||||
const isPassword = type === 'password'
|
||||
const isTextarea = type === 'textarea'
|
||||
const isNumber = type === 'number'
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<div className="relative">
|
||||
{isTextarea ? (
|
||||
<Textarea
|
||||
name={name}
|
||||
value={value}
|
||||
onChange={(e) => onChange?.(e.target.value)}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
rows={rows}
|
||||
className={cn('resize-none', withError(error))}
|
||||
/>
|
||||
) : (
|
||||
<Input
|
||||
name={name}
|
||||
type={
|
||||
isPassword ? (showPass ? 'text' : 'password')
|
||||
: isNumber ? 'number'
|
||||
: type === 'email' ? 'email'
|
||||
: 'text'
|
||||
}
|
||||
min={isNumber ? 0 : undefined}
|
||||
value={value}
|
||||
onChange={(e) => {
|
||||
if (isNumber) {
|
||||
const num = e.target.value
|
||||
if (num === '' || Number(num) >= 0) onChange?.(num)
|
||||
} else {
|
||||
onChange?.(e.target.value)
|
||||
}
|
||||
}}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
readOnly={readOnly}
|
||||
className={cn(
|
||||
isPassword && 'pr-10',
|
||||
isNumber && 'pr-10',
|
||||
withError(error),
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
|
||||
{isPassword && (
|
||||
<button
|
||||
type="button"
|
||||
tabIndex={-1}
|
||||
onClick={() => setShowPass((v) => !v)}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
{showPass ? <EyeOff size={15} /> : <Eye size={15} />}
|
||||
</button>
|
||||
)}
|
||||
|
||||
{isNumber && (
|
||||
<Hash
|
||||
size={14}
|
||||
className="absolute right-3 top-1/2 -translate-y-1/2 text-muted-foreground pointer-events-none"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── PhoneInput ───────────────────────────────────────────────────────────────
|
||||
|
||||
function PhoneInput({
|
||||
value = '',
|
||||
onChange,
|
||||
placeholder = '61 097 651',
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
phonePrefix = '+993',
|
||||
}: FormInputProps) {
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<div
|
||||
className={cn(
|
||||
'flex h-8 w-full rounded-md border bg-background overflow-hidden',
|
||||
'ring-offset-background transition-colors duration-150',
|
||||
'focus-within:outline-none focus-within:ring-1 focus-within:ring-ring focus-within:ring-offset-0',
|
||||
error ? 'border-destructive focus-within:ring-destructive/30' : 'border-input',
|
||||
disabled && 'opacity-50 cursor-not-allowed',
|
||||
)}
|
||||
>
|
||||
<div className="flex items-center px-3 bg-muted/50 border-r border-input text-sm font-medium text-muted-foreground shrink-0 select-none">
|
||||
{phonePrefix}
|
||||
</div>
|
||||
<input
|
||||
type="tel"
|
||||
value={value}
|
||||
onChange={(e) => onChange?.(e.target.value.replace(/[^\d\s-]/g, ''))}
|
||||
placeholder={placeholder}
|
||||
disabled={disabled}
|
||||
className="flex-1 h-full px-3 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none disabled:cursor-not-allowed"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── DateInput (shadcn Popover + Calendar) ───────────────────────────────────
|
||||
|
||||
function DateInput({
|
||||
value = '',
|
||||
onChange,
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
placeholder = 'Sene saýlaň',
|
||||
}: FormInputProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
// value is stored as 'yyyy-MM-dd' string
|
||||
const parsed = value ? parse(value, 'yyyy-MM-dd', new Date()) : undefined
|
||||
const selected = parsed && isValid(parsed) ? parsed : undefined
|
||||
|
||||
const handleSelect = (day: Date | undefined) => {
|
||||
onChange?.(day ? format(day, 'yyyy-MM-dd') : '')
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2',
|
||||
'text-sm ring-offset-background transition-colors duration-150',
|
||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
error ? 'border-destructive' : 'border-input',
|
||||
!selected && 'text-muted-foreground/60',
|
||||
)}
|
||||
>
|
||||
<span>{selected ? format(selected, 'dd.MM.yyyy') : placeholder}</span>
|
||||
<CalendarIcon size={15} className="text-muted-foreground shrink-0" />
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
|
||||
<PopoverContent className="w-auto p-0" align="start">
|
||||
<Calendar
|
||||
mode="single"
|
||||
selected={selected}
|
||||
onSelect={handleSelect}
|
||||
initialFocus
|
||||
captionLayout="dropdown"
|
||||
fromYear={1940}
|
||||
toYear={new Date().getFullYear()}
|
||||
/>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── SelectInput ──────────────────────────────────────────────────────────────
|
||||
|
||||
// ─── SelectInput ──────────────────────────────────────────────────────────────
|
||||
// Artık Collapsible tabanlı — SearchableSelect ile aynı mekanizma
|
||||
|
||||
function SelectInput({
|
||||
value = '',
|
||||
onChange,
|
||||
options = [],
|
||||
placeholder = '—',
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
}: FormInputProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
|
||||
const selected = options.find((o) => o.value === value)
|
||||
|
||||
const handleSelect = (val: string) => {
|
||||
onChange?.(val)
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn('relative', className)}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<Collapsible
|
||||
open={open}
|
||||
onOpenChange={(next) => {
|
||||
if (!disabled) setOpen(next)
|
||||
}}
|
||||
>
|
||||
<CollapsibleTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2',
|
||||
'text-sm ring-offset-background transition-colors duration-150',
|
||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
error ? 'border-destructive' : 'border-input',
|
||||
open && !error && 'ring-2 ring-ring ring-offset-0 border-transparent',
|
||||
)}
|
||||
>
|
||||
<span className={cn('truncate text-left', !selected && 'text-muted-foreground/60')}>
|
||||
{selected ? selected.label : placeholder}
|
||||
</span>
|
||||
<ChevronsUpDown
|
||||
size={14}
|
||||
className={cn(
|
||||
'text-muted-foreground transition-transform duration-200 shrink-0',
|
||||
open && 'text-foreground',
|
||||
)}
|
||||
/>
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
<CollapsibleContent className="mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
||||
<div className="max-h-52 overflow-y-auto py-1">
|
||||
{options.map((opt) => {
|
||||
const isSelected = opt.value === value
|
||||
return (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
onMouseDown={(e) => { e.preventDefault(); handleSelect(opt.value) }}
|
||||
className={cn(
|
||||
'flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors',
|
||||
'hover:bg-accent hover:text-accent-foreground',
|
||||
isSelected && 'text-primary font-medium bg-primary/10',
|
||||
)}
|
||||
>
|
||||
<span>{opt.label}</span>
|
||||
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
||||
</button>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── SearchableSelect ─────────────────────────────────────────────────────────
|
||||
// Uses Radix Collapsible — no portal, no z-index issues, natural document flow.
|
||||
// onMouseDown (not onClick) on options prevents the trigger's onBlur from
|
||||
// firing before the selection is registered.
|
||||
|
||||
function SearchableSelect({
|
||||
value = '',
|
||||
onChange,
|
||||
options = [],
|
||||
placeholder = 'Saýlamak üçin basyň',
|
||||
error,
|
||||
disabled,
|
||||
required,
|
||||
label,
|
||||
className,
|
||||
}: FormInputProps) {
|
||||
const [open, setOpen] = useState(false)
|
||||
const [query, setQuery] = useState('')
|
||||
const searchRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const selected = options.find((o) => o.value === value)
|
||||
const filtered = query.trim()
|
||||
? options.filter((o) => o.label.toLowerCase().includes(query.toLowerCase()))
|
||||
: options
|
||||
|
||||
const openDropdown = () => {
|
||||
setOpen(true)
|
||||
// Focus search after Collapsible animation frame
|
||||
requestAnimationFrame(() => searchRef.current?.focus())
|
||||
}
|
||||
|
||||
const closeDropdown = () => {
|
||||
setOpen(false)
|
||||
setQuery('')
|
||||
}
|
||||
|
||||
const handleSelect = (val: string) => {
|
||||
onChange?.(val)
|
||||
closeDropdown()
|
||||
}
|
||||
|
||||
const handleClear = (e: React.MouseEvent) => {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
onChange?.('')
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={cn('relative', className)}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<Collapsible open={open} onOpenChange={(next) => { if (!disabled) { if (next) { openDropdown() } else { closeDropdown() } } }}>
|
||||
{/* Trigger */}
|
||||
<CollapsibleTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
disabled={disabled}
|
||||
className={cn(
|
||||
'flex h-8 w-full items-center justify-between rounded-md border bg-background px-3 py-2',
|
||||
'text-sm ring-offset-background transition-colors duration-150',
|
||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-0',
|
||||
'disabled:cursor-not-allowed disabled:opacity-50',
|
||||
error ? 'border-destructive' : 'border-input',
|
||||
open && !error && 'ring-2 ring-ring ring-offset-0 border-transparent',
|
||||
)}
|
||||
>
|
||||
<span className={cn('truncate text-left', !selected && 'text-muted-foreground/60')}>
|
||||
{selected ? selected.label : placeholder}
|
||||
</span>
|
||||
|
||||
<div className="flex items-center gap-1 shrink-0 ml-2">
|
||||
{selected && !disabled && (
|
||||
<span
|
||||
role="button"
|
||||
tabIndex={-1}
|
||||
onMouseDown={handleClear}
|
||||
className="p-0.5 rounded text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<X size={12} />
|
||||
</span>
|
||||
)}
|
||||
<ChevronsUpDown
|
||||
size={14}
|
||||
className={cn(
|
||||
'text-muted-foreground transition-transform duration-200 shrink-0',
|
||||
open && 'text-foreground',
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</button>
|
||||
</CollapsibleTrigger>
|
||||
|
||||
{/* Panel */}
|
||||
<CollapsibleContent className="mt-1 rounded-md border border-border bg-card shadow-lg overflow-hidden">
|
||||
{/* Search */}
|
||||
<div className="flex items-center gap-2 px-3 py-2 border-b border-border bg-muted/20">
|
||||
<Search size={13} className="text-muted-foreground shrink-0" />
|
||||
<input
|
||||
ref={searchRef}
|
||||
type="text"
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
placeholder="Gözle..."
|
||||
className="flex-1 bg-transparent text-sm text-foreground placeholder:text-muted-foreground/50 focus:outline-none"
|
||||
/>
|
||||
{query && (
|
||||
<button
|
||||
type="button"
|
||||
tabIndex={-1}
|
||||
onMouseDown={() => setQuery('')}
|
||||
className="text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<X size={12} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Options */}
|
||||
<div className="max-h-52 overflow-y-auto py-1">
|
||||
{filtered.length === 0 ? (
|
||||
<p className="px-3 py-4 text-sm text-muted-foreground text-center">
|
||||
Netije tapylmady
|
||||
</p>
|
||||
) : (
|
||||
filtered.map((opt) => {
|
||||
const isSelected = opt.value === value
|
||||
return (
|
||||
<button
|
||||
key={opt.value}
|
||||
type="button"
|
||||
onMouseDown={(e) => { e.preventDefault(); handleSelect(opt.value) }}
|
||||
className={cn(
|
||||
'flex items-center justify-between w-full text-left px-3 py-2 text-sm transition-colors',
|
||||
'hover:bg-accent hover:text-accent-foreground',
|
||||
isSelected && 'text-primary font-medium bg-primary/10',
|
||||
)}
|
||||
>
|
||||
<span>{opt.label}</span>
|
||||
{isSelected && <Check size={13} className="text-primary shrink-0" />}
|
||||
</button>
|
||||
)
|
||||
})
|
||||
)}
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── FileInput ────────────────────────────────────────────────────────────────
|
||||
|
||||
function FileInput({
|
||||
label,
|
||||
required,
|
||||
error,
|
||||
disabled,
|
||||
accept = 'image/*',
|
||||
onFileChange,
|
||||
fileValue,
|
||||
className,
|
||||
placeholder = 'Faýl saýlaň ýa-da salmak üçin basyň',
|
||||
}: FormInputProps) {
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const [dragOver, setDragOver] = useState(false)
|
||||
const [preview, setPreview] = useState<string | null>(null)
|
||||
|
||||
const handleFile = (file: File | null) => {
|
||||
onFileChange?.(file)
|
||||
if (file?.type.startsWith('image/')) {
|
||||
setPreview(URL.createObjectURL(file))
|
||||
} else {
|
||||
setPreview(null)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDrop = (e: React.DragEvent) => {
|
||||
e.preventDefault()
|
||||
setDragOver(false)
|
||||
handleFile(e.dataTransfer.files[0] ?? null)
|
||||
}
|
||||
|
||||
const isImage = fileValue?.type.startsWith('image/')
|
||||
|
||||
return (
|
||||
<div className={className}>
|
||||
<FieldLabel label={label} required={required} />
|
||||
|
||||
<div
|
||||
role="button"
|
||||
tabIndex={disabled ? -1 : 0}
|
||||
onClick={() => !disabled && inputRef.current?.click()}
|
||||
onKeyDown={(e) => e.key === 'Enter' && !disabled && inputRef.current?.click()}
|
||||
onDragOver={(e) => { e.preventDefault(); setDragOver(true) }}
|
||||
onDragLeave={() => setDragOver(false)}
|
||||
onDrop={handleDrop}
|
||||
className={cn(
|
||||
'relative flex flex-col items-center justify-center',
|
||||
'min-h-[88px] rounded-md border-2 border-dashed cursor-pointer select-none',
|
||||
'transition-all duration-200',
|
||||
'focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring focus-visible:ring-offset-2',
|
||||
dragOver && 'border-primary bg-primary/5 scale-[1.01]',
|
||||
error ? 'border-destructive/60' : 'border-border',
|
||||
!dragOver && !error && 'hover:border-primary/50 hover:bg-muted/20',
|
||||
disabled && 'opacity-50 cursor-not-allowed pointer-events-none',
|
||||
fileValue && isImage && '!border-solid !border-border p-0 overflow-hidden',
|
||||
)}
|
||||
>
|
||||
{fileValue && isImage && preview ? (
|
||||
<>
|
||||
<img src={preview} alt="preview" className="w-full h-32 object-cover" />
|
||||
<Button
|
||||
type="button"
|
||||
size="icon"
|
||||
variant="secondary"
|
||||
onClick={(e) => { e.stopPropagation(); handleFile(null) }}
|
||||
className="absolute top-2 right-2 h-6 w-6 rounded-full border border-border shadow-sm"
|
||||
>
|
||||
<X size={11} />
|
||||
</Button>
|
||||
</>
|
||||
) : fileValue ? (
|
||||
<div className="flex flex-col items-center gap-1.5 p-4">
|
||||
<div className="w-8 h-8 rounded-md bg-primary/10 flex items-center justify-center">
|
||||
<Upload size={14} className="text-primary" />
|
||||
</div>
|
||||
<p className="text-xs font-medium text-foreground text-center truncate max-w-[180px]">
|
||||
{fileValue.name}
|
||||
</p>
|
||||
<button
|
||||
type="button"
|
||||
onClick={(e) => { e.stopPropagation(); handleFile(null) }}
|
||||
className="text-xs text-destructive hover:text-destructive/80 transition-colors"
|
||||
>
|
||||
Aýyr
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-col items-center gap-1.5 p-4">
|
||||
<div className="w-8 h-8 rounded-md bg-muted flex items-center justify-center">
|
||||
<Upload size={14} className="text-muted-foreground" />
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground text-center leading-relaxed">
|
||||
{placeholder}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="file"
|
||||
accept={accept}
|
||||
disabled={disabled}
|
||||
onChange={(e) => handleFile(e.target.files?.[0] ?? null)}
|
||||
className="hidden"
|
||||
/>
|
||||
|
||||
<ErrorMsg error={error} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
// ─── FormInput (router) ───────────────────────────────────────────────────────
|
||||
|
||||
export function FormInput(props: FormInputProps) {
|
||||
const { type = 'text' } = props
|
||||
|
||||
if (type === 'phone') return <PhoneInput {...props} />
|
||||
if (type === 'date') return <DateInput {...props} />
|
||||
if (type === 'select') return <SelectInput {...props} />
|
||||
if (type === 'searchable-select') return <SearchableSelect {...props} />
|
||||
if (type === 'file') return <FileInput {...props} />
|
||||
if (type === 'textarea') return <TextInput {...props} type="textarea" />
|
||||
return <TextInput {...props} />
|
||||
}
|
||||
@@ -25,7 +25,7 @@ export function TableActionButton({
|
||||
disabled={disabled}
|
||||
variant={variant === 'destructive' ? 'destructive' : variant === 'secondary' ? 'secondary' : 'default'}
|
||||
className={cn(
|
||||
'font-medium text-sm h-9 px-4 transition-colors shadow-sm',
|
||||
'font-medium text-sm h-9 px-4 transition-colors shadow-sm cursor-pointer',
|
||||
className
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -31,7 +31,7 @@ export function TableSearchInput({
|
||||
className={cn(
|
||||
'h-9 w-64 rounded-md border border-border bg-background pl-9 pr-3',
|
||||
'text-sm text-foreground placeholder:text-muted-foreground',
|
||||
'focus:outline-none focus:ring-2 focus:ring-ring focus:border-transparent',
|
||||
'focus:outline-none focus:ring-1 focus:ring-ring focus:border-transparent',
|
||||
'transition-colors'
|
||||
)}
|
||||
/>
|
||||
|
||||
@@ -40,7 +40,7 @@ function AccordionTrigger({
|
||||
<AccordionPrimitive.Trigger
|
||||
data-slot="accordion-trigger"
|
||||
className={cn(
|
||||
"group/accordion-trigger relative flex flex-1 items-start justify-between rounded-lg border border-transparent py-2.5 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:after:border-ring disabled:pointer-events-none disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-muted-foreground",
|
||||
"group/accordion-trigger relative flex flex-1 items-start justify-between rounded-md border border-transparent py-2.5 text-left text-sm font-medium transition-all outline-none hover:underline focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:after:border-ring disabled:pointer-events-none disabled:opacity-50 **:data-[slot=accordion-trigger-icon]:ml-auto **:data-[slot=accordion-trigger-icon]:size-4 **:data-[slot=accordion-trigger-icon]:text-muted-foreground",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -1,9 +1,45 @@
|
||||
import * as React from "react"
|
||||
import { type VariantProps } from "class-variance-authority"
|
||||
import { cva, type VariantProps } from "class-variance-authority"
|
||||
import { Slot } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { buttonVariants } from "./button-variants"
|
||||
|
||||
const buttonVariants = cva(
|
||||
"group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
||||
outline:
|
||||
"border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
||||
secondary:
|
||||
"bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
||||
ghost:
|
||||
"hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
||||
destructive:
|
||||
"bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
||||
link: "text-primary underline-offset-4 hover:underline",
|
||||
},
|
||||
size: {
|
||||
default:
|
||||
"h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
||||
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
||||
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
||||
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
||||
icon: "size-8",
|
||||
"icon-xs":
|
||||
"size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
||||
"icon-sm":
|
||||
"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-md",
|
||||
"icon-lg": "size-9",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
function Button({
|
||||
className,
|
||||
@@ -28,4 +64,4 @@ function Button({
|
||||
)
|
||||
}
|
||||
|
||||
export { Button }
|
||||
export { Button, buttonVariants }
|
||||
|
||||
220
src/components/ui/calendar.tsx
Normal file
220
src/components/ui/calendar.tsx
Normal file
@@ -0,0 +1,220 @@
|
||||
import * as React from "react"
|
||||
import {
|
||||
DayPicker,
|
||||
getDefaultClassNames,
|
||||
type DayButton,
|
||||
type Locale,
|
||||
} from "react-day-picker"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { Button, buttonVariants } from "@/components/ui/button"
|
||||
import { ChevronLeftIcon, ChevronRightIcon, ChevronDownIcon } from "lucide-react"
|
||||
|
||||
function Calendar({
|
||||
className,
|
||||
classNames,
|
||||
showOutsideDays = true,
|
||||
captionLayout = "label",
|
||||
buttonVariant = "ghost",
|
||||
locale,
|
||||
formatters,
|
||||
components,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DayPicker> & {
|
||||
buttonVariant?: React.ComponentProps<typeof Button>["variant"]
|
||||
}) {
|
||||
const defaultClassNames = getDefaultClassNames()
|
||||
|
||||
return (
|
||||
<DayPicker
|
||||
showOutsideDays={showOutsideDays}
|
||||
className={cn(
|
||||
"group/calendar bg-background p-2 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(7)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent",
|
||||
String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`,
|
||||
String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`,
|
||||
className
|
||||
)}
|
||||
captionLayout={captionLayout}
|
||||
locale={locale}
|
||||
formatters={{
|
||||
formatMonthDropdown: (date) =>
|
||||
date.toLocaleString(locale?.code, { month: "short" }),
|
||||
...formatters,
|
||||
}}
|
||||
classNames={{
|
||||
root: cn("w-fit", defaultClassNames.root),
|
||||
months: cn(
|
||||
"relative flex flex-col gap-4 md:flex-row",
|
||||
defaultClassNames.months
|
||||
),
|
||||
month: cn("flex w-full flex-col gap-4", defaultClassNames.month),
|
||||
nav: cn(
|
||||
"absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1",
|
||||
defaultClassNames.nav
|
||||
),
|
||||
button_previous: cn(
|
||||
buttonVariants({ variant: buttonVariant }),
|
||||
"size-(--cell-size) p-0 select-none aria-disabled:opacity-50",
|
||||
defaultClassNames.button_previous
|
||||
),
|
||||
button_next: cn(
|
||||
buttonVariants({ variant: buttonVariant }),
|
||||
"size-(--cell-size) p-0 select-none aria-disabled:opacity-50",
|
||||
defaultClassNames.button_next
|
||||
),
|
||||
month_caption: cn(
|
||||
"flex h-(--cell-size) w-full items-center justify-center px-(--cell-size)",
|
||||
defaultClassNames.month_caption
|
||||
),
|
||||
dropdowns: cn(
|
||||
"flex h-(--cell-size) w-full items-center justify-center gap-1.5 text-sm font-medium",
|
||||
defaultClassNames.dropdowns
|
||||
),
|
||||
dropdown_root: cn(
|
||||
"relative rounded-(--cell-radius)",
|
||||
defaultClassNames.dropdown_root
|
||||
),
|
||||
dropdown: cn(
|
||||
"absolute inset-0 bg-popover opacity-0",
|
||||
defaultClassNames.dropdown
|
||||
),
|
||||
caption_label: cn(
|
||||
"font-medium select-none",
|
||||
captionLayout === "label"
|
||||
? "text-sm"
|
||||
: "flex items-center gap-1 rounded-(--cell-radius) text-sm [&>svg]:size-3.5 [&>svg]:text-muted-foreground",
|
||||
defaultClassNames.caption_label
|
||||
),
|
||||
table: "w-full border-collapse",
|
||||
weekdays: cn("flex", defaultClassNames.weekdays),
|
||||
weekday: cn(
|
||||
"flex-1 rounded-(--cell-radius) text-[0.8rem] font-normal text-muted-foreground select-none",
|
||||
defaultClassNames.weekday
|
||||
),
|
||||
week: cn("mt-2 flex w-full", defaultClassNames.week),
|
||||
week_number_header: cn(
|
||||
"w-(--cell-size) select-none",
|
||||
defaultClassNames.week_number_header
|
||||
),
|
||||
week_number: cn(
|
||||
"text-[0.8rem] text-muted-foreground select-none",
|
||||
defaultClassNames.week_number
|
||||
),
|
||||
day: cn(
|
||||
"group/day relative aspect-square h-full w-full rounded-(--cell-radius) p-0 text-center select-none [&:last-child[data-selected=true]_button]:rounded-r-(--cell-radius)",
|
||||
props.showWeekNumber
|
||||
? "[&:nth-child(2)[data-selected=true]_button]:rounded-l-(--cell-radius)"
|
||||
: "[&:first-child[data-selected=true]_button]:rounded-l-(--cell-radius)",
|
||||
defaultClassNames.day
|
||||
),
|
||||
range_start: cn(
|
||||
"relative isolate z-0 rounded-l-(--cell-radius) bg-muted after:absolute after:inset-y-0 after:right-0 after:w-4 after:bg-muted",
|
||||
defaultClassNames.range_start
|
||||
),
|
||||
range_middle: cn("rounded-none", defaultClassNames.range_middle),
|
||||
range_end: cn(
|
||||
"relative isolate z-0 rounded-r-(--cell-radius) bg-muted after:absolute after:inset-y-0 after:left-0 after:w-4 after:bg-muted",
|
||||
defaultClassNames.range_end
|
||||
),
|
||||
today: cn(
|
||||
"rounded-(--cell-radius) bg-muted text-foreground data-[selected=true]:rounded-none",
|
||||
defaultClassNames.today
|
||||
),
|
||||
outside: cn(
|
||||
"text-muted-foreground aria-selected:text-muted-foreground",
|
||||
defaultClassNames.outside
|
||||
),
|
||||
disabled: cn(
|
||||
"text-muted-foreground opacity-50",
|
||||
defaultClassNames.disabled
|
||||
),
|
||||
hidden: cn("invisible", defaultClassNames.hidden),
|
||||
...classNames,
|
||||
}}
|
||||
components={{
|
||||
Root: ({ className, rootRef, ...props }) => {
|
||||
return (
|
||||
<div
|
||||
data-slot="calendar"
|
||||
ref={rootRef}
|
||||
className={cn(className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
},
|
||||
Chevron: ({ className, orientation, ...props }) => {
|
||||
if (orientation === "left") {
|
||||
return (
|
||||
<ChevronLeftIcon className={cn("size-4", className)} {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
if (orientation === "right") {
|
||||
return (
|
||||
<ChevronRightIcon className={cn("size-4", className)} {...props} />
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<ChevronDownIcon className={cn("size-4", className)} {...props} />
|
||||
)
|
||||
},
|
||||
DayButton: ({ ...props }) => (
|
||||
<CalendarDayButton locale={locale} {...props} />
|
||||
),
|
||||
WeekNumber: ({ children, ...props }) => {
|
||||
return (
|
||||
<td {...props}>
|
||||
<div className="flex size-(--cell-size) items-center justify-center text-center">
|
||||
{children}
|
||||
</div>
|
||||
</td>
|
||||
)
|
||||
},
|
||||
...components,
|
||||
}}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function CalendarDayButton({
|
||||
className,
|
||||
day,
|
||||
modifiers,
|
||||
locale,
|
||||
...props
|
||||
}: React.ComponentProps<typeof DayButton> & { locale?: Partial<Locale> }) {
|
||||
const defaultClassNames = getDefaultClassNames()
|
||||
|
||||
const ref = React.useRef<HTMLButtonElement>(null)
|
||||
React.useEffect(() => {
|
||||
if (modifiers.focused) ref.current?.focus()
|
||||
}, [modifiers.focused])
|
||||
|
||||
return (
|
||||
<Button
|
||||
ref={ref}
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
data-day={day.date.toLocaleDateString(locale?.code)}
|
||||
data-selected-single={
|
||||
modifiers.selected &&
|
||||
!modifiers.range_start &&
|
||||
!modifiers.range_end &&
|
||||
!modifiers.range_middle
|
||||
}
|
||||
data-range-start={modifiers.range_start}
|
||||
data-range-end={modifiers.range_end}
|
||||
data-range-middle={modifiers.range_middle}
|
||||
className={cn(
|
||||
"relative isolate z-10 flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 border-0 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-(--cell-radius) data-[range-end=true]:rounded-r-(--cell-radius) data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-muted data-[range-middle=true]:text-foreground data-[range-start=true]:rounded-(--cell-radius) data-[range-start=true]:rounded-l-(--cell-radius) data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-foreground [&>span]:text-xs [&>span]:opacity-70",
|
||||
defaultClassNames.day,
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export { Calendar, CalendarDayButton }
|
||||
@@ -12,7 +12,7 @@ function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
||||
data-slot="input-group"
|
||||
role="group"
|
||||
className={cn(
|
||||
"group/input-group relative flex h-8 w-full min-w-0 items-center rounded-lg border border-input transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
|
||||
"group/input-group relative flex h-8 w-full min-w-0 items-center rounded-md border border-input transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -8,7 +8,7 @@ function Input({ className, type, ...props }: React.ComponentProps<"input">) {
|
||||
type={type}
|
||||
data-slot="input"
|
||||
className={cn(
|
||||
"h-8 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||
"h-8 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-1 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
87
src/components/ui/popover.tsx
Normal file
87
src/components/ui/popover.tsx
Normal file
@@ -0,0 +1,87 @@
|
||||
import * as React from "react"
|
||||
import { Popover as PopoverPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
|
||||
function Popover({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Root>) {
|
||||
return <PopoverPrimitive.Root data-slot="popover" {...props} />
|
||||
}
|
||||
|
||||
function PopoverTrigger({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Trigger>) {
|
||||
return <PopoverPrimitive.Trigger data-slot="popover-trigger" {...props} />
|
||||
}
|
||||
|
||||
function PopoverContent({
|
||||
className,
|
||||
align = "center",
|
||||
sideOffset = 4,
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Content>) {
|
||||
return (
|
||||
<PopoverPrimitive.Portal>
|
||||
<PopoverPrimitive.Content
|
||||
data-slot="popover-content"
|
||||
align={align}
|
||||
sideOffset={sideOffset}
|
||||
className={cn(
|
||||
"z-50 flex w-72 origin-(--radix-popover-content-transform-origin) flex-col gap-2.5 rounded-md bg-popover p-2.5 text-sm text-popover-foreground shadow-md ring-1 ring-foreground/10 outline-hidden duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
/>
|
||||
</PopoverPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function PopoverAnchor({
|
||||
...props
|
||||
}: React.ComponentProps<typeof PopoverPrimitive.Anchor>) {
|
||||
return <PopoverPrimitive.Anchor data-slot="popover-anchor" {...props} />
|
||||
}
|
||||
|
||||
function PopoverHeader({ className, ...props }: React.ComponentProps<"div">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="popover-header"
|
||||
className={cn("flex flex-col gap-0.5 text-sm", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PopoverTitle({ className, ...props }: React.ComponentProps<"h2">) {
|
||||
return (
|
||||
<div
|
||||
data-slot="popover-title"
|
||||
className={cn("font-medium", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function PopoverDescription({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<"p">) {
|
||||
return (
|
||||
<p
|
||||
data-slot="popover-description"
|
||||
className={cn("text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Popover,
|
||||
PopoverAnchor,
|
||||
PopoverContent,
|
||||
PopoverDescription,
|
||||
PopoverHeader,
|
||||
PopoverTitle,
|
||||
PopoverTrigger,
|
||||
}
|
||||
190
src/components/ui/select.tsx
Normal file
190
src/components/ui/select.tsx
Normal file
@@ -0,0 +1,190 @@
|
||||
import * as React from "react"
|
||||
import { Select as SelectPrimitive } from "radix-ui"
|
||||
|
||||
import { cn } from "@/lib/utils"
|
||||
import { ChevronDownIcon, CheckIcon, ChevronUpIcon } from "lucide-react"
|
||||
|
||||
function Select({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Root>) {
|
||||
return <SelectPrimitive.Root data-slot="select" {...props} />
|
||||
}
|
||||
|
||||
function SelectGroup({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Group>) {
|
||||
return (
|
||||
<SelectPrimitive.Group
|
||||
data-slot="select-group"
|
||||
className={cn("scroll-my-1 p-1", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectValue({
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Value>) {
|
||||
return <SelectPrimitive.Value data-slot="select-value" {...props} />
|
||||
}
|
||||
|
||||
function SelectTrigger({
|
||||
className,
|
||||
size = "default",
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Trigger> & {
|
||||
size?: "sm" | "default"
|
||||
}) {
|
||||
return (
|
||||
<SelectPrimitive.Trigger
|
||||
data-slot="select-trigger"
|
||||
data-size={size}
|
||||
className={cn(
|
||||
"flex w-fit items-center justify-between gap-1.5 rounded-md border border-input bg-transparent py-2 pr-2 pl-2.5 text-sm whitespace-nowrap transition-colors outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 data-placeholder:text-muted-foreground data-[size=default]:h-8 data-[size=sm]:h-7 data-[size=sm]:rounded-[min(var(--radius-md),10px)] *:data-[slot=select-value]:line-clamp-1 *:data-[slot=select-value]:flex *:data-[slot=select-value]:items-center *:data-[slot=select-value]:gap-1.5 dark:bg-input/30 dark:hover:bg-input/50 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
{children}
|
||||
<SelectPrimitive.Icon asChild>
|
||||
<ChevronDownIcon className="pointer-events-none size-4 text-muted-foreground" />
|
||||
</SelectPrimitive.Icon>
|
||||
</SelectPrimitive.Trigger>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectContent({
|
||||
className,
|
||||
children,
|
||||
position = "item-aligned",
|
||||
align = "center",
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Content>) {
|
||||
return (
|
||||
<SelectPrimitive.Portal>
|
||||
<SelectPrimitive.Content
|
||||
data-slot="select-content"
|
||||
data-align-trigger={position === "item-aligned"}
|
||||
className={cn("relative z-50 max-h-(--radix-select-content-available-height) min-w-36 origin-(--radix-select-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-md bg-popover text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[align-trigger=true]:animate-none data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95", position ==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", className )}
|
||||
position={position}
|
||||
align={align}
|
||||
{...props}
|
||||
>
|
||||
<SelectScrollUpButton />
|
||||
<SelectPrimitive.Viewport
|
||||
data-position={position}
|
||||
className={cn(
|
||||
"data-[position=popper]:h-(--radix-select-trigger-height) data-[position=popper]:w-full data-[position=popper]:min-w-(--radix-select-trigger-width)",
|
||||
position === "popper" && ""
|
||||
)}
|
||||
>
|
||||
{children}
|
||||
</SelectPrimitive.Viewport>
|
||||
<SelectScrollDownButton />
|
||||
</SelectPrimitive.Content>
|
||||
</SelectPrimitive.Portal>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectLabel({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Label>) {
|
||||
return (
|
||||
<SelectPrimitive.Label
|
||||
data-slot="select-label"
|
||||
className={cn("px-1.5 py-1 text-xs text-muted-foreground", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectItem({
|
||||
className,
|
||||
children,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Item>) {
|
||||
return (
|
||||
<SelectPrimitive.Item
|
||||
data-slot="select-item"
|
||||
className={cn(
|
||||
"relative flex w-full cursor-default items-center gap-1.5 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 *:[span]:last:flex *:[span]:last:items-center *:[span]:last:gap-2",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<span className="pointer-events-none absolute right-2 flex size-4 items-center justify-center">
|
||||
<SelectPrimitive.ItemIndicator>
|
||||
<CheckIcon className="pointer-events-none" />
|
||||
</SelectPrimitive.ItemIndicator>
|
||||
</span>
|
||||
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
|
||||
</SelectPrimitive.Item>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectSeparator({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.Separator>) {
|
||||
return (
|
||||
<SelectPrimitive.Separator
|
||||
data-slot="select-separator"
|
||||
className={cn("pointer-events-none -mx-1 my-1 h-px bg-border", className)}
|
||||
{...props}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollUpButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollUpButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollUpButton
|
||||
data-slot="select-scroll-up-button"
|
||||
className={cn(
|
||||
"z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronUpIcon
|
||||
/>
|
||||
</SelectPrimitive.ScrollUpButton>
|
||||
)
|
||||
}
|
||||
|
||||
function SelectScrollDownButton({
|
||||
className,
|
||||
...props
|
||||
}: React.ComponentProps<typeof SelectPrimitive.ScrollDownButton>) {
|
||||
return (
|
||||
<SelectPrimitive.ScrollDownButton
|
||||
data-slot="select-scroll-down-button"
|
||||
className={cn(
|
||||
"z-10 flex cursor-default items-center justify-center bg-popover py-1 [&_svg:not([class*='size-'])]:size-4",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
>
|
||||
<ChevronDownIcon
|
||||
/>
|
||||
</SelectPrimitive.ScrollDownButton>
|
||||
)
|
||||
}
|
||||
|
||||
export {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectLabel,
|
||||
SelectScrollDownButton,
|
||||
SelectScrollUpButton,
|
||||
SelectSeparator,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
}
|
||||
@@ -241,7 +241,7 @@ function Sidebar({
|
||||
<div
|
||||
data-sidebar="sidebar"
|
||||
data-slot="sidebar-inner"
|
||||
className="flex size-full flex-col bg-sidebar group-data-[variant=floating]:rounded-lg group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1 group-data-[variant=floating]:ring-sidebar-border"
|
||||
className="flex size-full flex-col bg-sidebar group-data-[variant=floating]:rounded-md group-data-[variant=floating]:shadow-sm group-data-[variant=floating]:ring-1 group-data-[variant=floating]:ring-sidebar-border"
|
||||
>
|
||||
{children}
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@ function Textarea({ className, ...props }: React.ComponentProps<"textarea">) {
|
||||
<textarea
|
||||
data-slot="textarea"
|
||||
className={cn(
|
||||
"flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||
"flex field-sizing-content min-h-16 w-full rounded-md border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
Reference in New Issue
Block a user