fixed button color, some select components
This commit is contained in:
@@ -243,6 +243,9 @@ interface DataTableProps<TData> {
|
||||
totalPages?: number
|
||||
totalCount?: number
|
||||
onPageChange?: (page: number) => void
|
||||
|
||||
// Optional content rendered above the table (e.g. month selector)
|
||||
headerContent?: React.ReactNode
|
||||
}
|
||||
|
||||
export function DataTable<TData>({
|
||||
@@ -260,6 +263,7 @@ export function DataTable<TData>({
|
||||
totalPages = 1,
|
||||
totalCount,
|
||||
onPageChange,
|
||||
headerContent,
|
||||
}: DataTableProps<TData>) {
|
||||
const [sorting, setSorting] = useState<SortingState>([])
|
||||
const [rowSelection, setRowSelection] = useState<RowSelectionState>({})
|
||||
@@ -394,6 +398,11 @@ export function DataTable<TData>({
|
||||
|
||||
return (
|
||||
<div className="space-y-0">
|
||||
{/* Header content (e.g. month selector) */}
|
||||
{headerContent && (
|
||||
<div className="mb-3">{headerContent}</div>
|
||||
)}
|
||||
|
||||
{/* Selection banner */}
|
||||
{showBanner && (
|
||||
<div className="flex items-center justify-between px-3 py-2 bg-primary/5 border border-primary/20 rounded-t-lg text-sm border-b-0">
|
||||
|
||||
@@ -6,6 +6,18 @@ import { useOutsideClick } from '@/lib/hooks/useOutsideClick'
|
||||
import { cn } from '@/lib/utils'
|
||||
import { TableSearchInput } from '@/components/tableSearch'
|
||||
import { TableActionButton } from '@/components/tableButton'
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from '@/components/ui/popover'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
|
||||
// ─── Types ────────────────────────────────────────────────────────────────────
|
||||
|
||||
@@ -50,6 +62,8 @@ interface DataTableToolbarProps {
|
||||
|
||||
hideSearch?: boolean
|
||||
hideAction?: boolean
|
||||
|
||||
extraActions?: React.ReactNode
|
||||
}
|
||||
|
||||
// ─── Toggle Columns Dropdown ──────────────────────────────────────────────────
|
||||
@@ -84,7 +98,6 @@ function ToggleColumnsDropdown({
|
||||
onColumnVisibilityChange({ ...columnVisibility, [id]: !isVisible(id) })
|
||||
}
|
||||
|
||||
// columnOrder'a göre sırala; columnOrder'da olmayan kolonları sona at
|
||||
const orderedColumns = [...columns].sort((a, b) => {
|
||||
const ai = columnOrder.indexOf(a.id)
|
||||
const bi = columnOrder.indexOf(b.id)
|
||||
@@ -94,9 +107,7 @@ function ToggleColumnsDropdown({
|
||||
return ai - bi
|
||||
})
|
||||
|
||||
const handleDragStart = (id: string) => {
|
||||
dragIdRef.current = id
|
||||
}
|
||||
const handleDragStart = (id: string) => { dragIdRef.current = id }
|
||||
|
||||
const handleDragOver = (e: React.DragEvent, id: string) => {
|
||||
e.preventDefault()
|
||||
@@ -106,19 +117,14 @@ function ToggleColumnsDropdown({
|
||||
const handleDrop = (targetId: string) => {
|
||||
const sourceId = dragIdRef.current
|
||||
if (!sourceId || sourceId === targetId) return
|
||||
|
||||
const next = [...columnOrder]
|
||||
const from = next.indexOf(sourceId)
|
||||
const to = next.indexOf(targetId)
|
||||
|
||||
// columnOrder'da yoksa ekle
|
||||
const safeFrom = from === -1 ? next.length : from
|
||||
const safeTo = to === -1 ? next.length : to
|
||||
|
||||
next.splice(safeFrom, 1)
|
||||
next.splice(safeTo, 0, sourceId)
|
||||
onColumnOrderChange(next)
|
||||
|
||||
dragIdRef.current = null
|
||||
setDragOverId(null)
|
||||
}
|
||||
@@ -226,8 +232,6 @@ function FilterDropdown({
|
||||
}: FilterDropdownProps) {
|
||||
const { t } = useTranslation()
|
||||
const [open, setOpen] = useState(false)
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
useOutsideClick(ref, () => setOpen(false))
|
||||
|
||||
const activeCount = activeFilters.filter((f) => f.value !== '').length
|
||||
const hasActive = activeCount > 0
|
||||
@@ -236,95 +240,138 @@ function FilterDropdown({
|
||||
activeFilters.find((f) => f.fieldId === fieldId)?.value ?? ''
|
||||
|
||||
return (
|
||||
<div ref={ref} className="relative">
|
||||
<button
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
className={cn(
|
||||
'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',
|
||||
// emerald yerine primary token
|
||||
hasActive && 'border-primary text-primary'
|
||||
)}
|
||||
>
|
||||
<Filter size={14} />
|
||||
{hasActive && (
|
||||
<span className="text-xs font-semibold bg-primary text-primary-foreground rounded-full w-4 h-4 flex items-center justify-center leading-none">
|
||||
{activeCount}
|
||||
</span>
|
||||
)}
|
||||
<ChevronDown size={12} />
|
||||
</button>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
className={cn(
|
||||
'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',
|
||||
hasActive && 'border-primary text-primary'
|
||||
)}
|
||||
>
|
||||
<Filter size={14} />
|
||||
{hasActive && (
|
||||
<span className="text-xs font-semibold bg-primary text-primary-foreground rounded-full w-4 h-4 flex items-center justify-center leading-none">
|
||||
{activeCount}
|
||||
</span>
|
||||
)}
|
||||
<ChevronDown size={12} />
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
|
||||
{open && (
|
||||
<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')}
|
||||
</p>
|
||||
{hasActive && (
|
||||
<button
|
||||
onClick={onFilterReset}
|
||||
className="flex items-center gap-1 text-xs text-destructive hover:text-destructive/80 transition-colors"
|
||||
>
|
||||
<X size={11} />
|
||||
{t('table.reset', 'Reset')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<PopoverContent align="end" sideOffset={4} className="w-64 p-0">
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between px-3 py-2 border-b border-border">
|
||||
<p className="text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{t('table.filters', 'Filters')}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="px-3 space-y-3">
|
||||
{filterFields.map((field) => (
|
||||
<div key={field.id}>
|
||||
<label className="block text-[11px] font-semibold text-muted-foreground uppercase tracking-wider mb-1">
|
||||
{/* Fields */}
|
||||
<div className="px-3 py-3 space-y-3">
|
||||
{filterFields.map((field) => {
|
||||
const current = getActiveValue(field.id)
|
||||
const isFieldActive = current !== ''
|
||||
|
||||
return (
|
||||
<div key={field.id} className="space-y-1">
|
||||
<label className="block text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{field.label}
|
||||
</label>
|
||||
<select
|
||||
value={getActiveValue(field.id)}
|
||||
onChange={(e) => onFilterChange(field.id, e.target.value)}
|
||||
className={cn(
|
||||
'w-full h-8 px-2 rounded-md border border-border bg-background',
|
||||
'text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring',
|
||||
'transition-colors appearance-none cursor-pointer'
|
||||
)}
|
||||
>
|
||||
<option value="">—</option>
|
||||
{field.options.map((opt) => (
|
||||
<option key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
))}
|
||||
|
||||
{onPerPageChange && (
|
||||
<div>
|
||||
<label className="block text-[11px] font-semibold text-muted-foreground uppercase tracking-wider mb-1">
|
||||
{t('table.perPage', 'Sahypa başyna')}
|
||||
</label>
|
||||
<select
|
||||
value={perPage}
|
||||
onChange={(e) => onPerPageChange(Number(e.target.value))}
|
||||
className={cn(
|
||||
'w-full h-8 px-2 rounded-md border border-border bg-background',
|
||||
'text-sm text-foreground focus:outline-none focus:ring-2 focus:ring-ring',
|
||||
'transition-colors appearance-none cursor-pointer'
|
||||
{/* MonthSelect ile aynı pattern: manuel span + sentinel */}
|
||||
<div className="flex items-center gap-1">
|
||||
<Select
|
||||
value={current || '__all__'}
|
||||
onValueChange={(val) =>
|
||||
onFilterChange(field.id, val === '__all__' ? '' : val)
|
||||
}
|
||||
>
|
||||
<SelectTrigger
|
||||
className={cn(
|
||||
'h-8 flex-1 text-sm gap-1.5 transition-colors',
|
||||
isFieldActive
|
||||
? 'border-primary text-primary [&>svg:last-child]:text-primary'
|
||||
: 'text-muted-foreground'
|
||||
)}
|
||||
>
|
||||
{/* SelectValue kullanmıyoruz — MonthSelect gibi manuel */}
|
||||
<span className="flex-1 text-left truncate">
|
||||
{isFieldActive
|
||||
? field.options.find((o) => o.value === current)?.label
|
||||
: '—'}
|
||||
</span>
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" sideOffset={4} className='p-1'>
|
||||
<SelectItem value="__all__">
|
||||
<span className="text-muted-foreground">— Ählisi</span>
|
||||
</SelectItem>
|
||||
{field.options.map((opt) => (
|
||||
<SelectItem key={opt.value} value={opt.value}>
|
||||
{opt.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{/* Field bazlı temizle — MonthSelect'teki X butonu ile aynı */}
|
||||
{isFieldActive && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onFilterChange(field.id, '')}
|
||||
className="h-6 w-6 rounded flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors shrink-0"
|
||||
>
|
||||
<X size={11} />
|
||||
</button>
|
||||
)}
|
||||
>
|
||||
{perPageOptions.map((n) => (
|
||||
<option key={n} value={n}>
|
||||
{n}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
|
||||
{onPerPageChange && (
|
||||
<div className="space-y-1">
|
||||
<label className="block text-[11px] font-semibold text-muted-foreground uppercase tracking-wider">
|
||||
{t('table.perPage', 'Sahypa başyna')}
|
||||
</label>
|
||||
<Select
|
||||
value={String(perPage)}
|
||||
onValueChange={(val) => onPerPageChange(Number(val))}
|
||||
>
|
||||
<SelectTrigger className="h-8 w-full text-sm">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" sideOffset={4} className='p-1'>
|
||||
{perPageOptions.map((n) => (
|
||||
<SelectItem key={n} value={String(n)}>
|
||||
{n}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Reset — tüm filtreler, sadece aktif filter varsa göster */}
|
||||
{hasActive && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={onFilterReset}
|
||||
className={cn(
|
||||
'w-full cursor-pointer flex items-center justify-center gap-1.5 h-8 rounded-md text-xs font-medium transition-colors',
|
||||
'bg-destructive/10 text-destructive border border-destructive/20',
|
||||
'hover:bg-destructive/30 hover:text-destructive-foreground'
|
||||
)}
|
||||
>
|
||||
<X size={11} />
|
||||
{t('table.reset', 'Reset')} ({activeCount})
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -350,9 +397,10 @@ export function DataTableToolbar({
|
||||
onAction,
|
||||
hideSearch = false,
|
||||
hideAction = false,
|
||||
extraActions,
|
||||
}: DataTableToolbarProps) {
|
||||
return (
|
||||
<div className={cn("flex items-center gap-3 mb-3", hideSearch ? "justify-end" : "justify-between")}>
|
||||
<div className={cn('flex items-center gap-3 mb-3', hideSearch ? 'justify-end' : 'justify-between')}>
|
||||
{!hideSearch && (
|
||||
<TableSearchInput
|
||||
value={searchValue}
|
||||
@@ -384,6 +432,8 @@ export function DataTableToolbar({
|
||||
/>
|
||||
)}
|
||||
|
||||
{extraActions}
|
||||
|
||||
{!hideAction && actionLabel && onAction && (
|
||||
<TableActionButton label={actionLabel} onClick={onAction} />
|
||||
)}
|
||||
|
||||
78
src/components/monthSelect.tsx
Normal file
78
src/components/monthSelect.tsx
Normal file
@@ -0,0 +1,78 @@
|
||||
import { Calendar, X } from 'lucide-react'
|
||||
import { cn } from '@/lib/utils'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
} from '@/components/ui/select'
|
||||
|
||||
// ─── Month data ───────────────────────────────────────────────────────────────
|
||||
|
||||
export const MONTHS = [
|
||||
{ value: '01', label: 'Ýanwar' },
|
||||
{ value: '02', label: 'Fewral' },
|
||||
{ value: '03', label: 'Mart' },
|
||||
{ value: '04', label: 'Aprel' },
|
||||
{ value: '05', label: 'Maý' },
|
||||
{ value: '06', label: 'Iýun' },
|
||||
{ value: '07', label: 'Iýul' },
|
||||
{ value: '08', label: 'Awgust' },
|
||||
{ value: '09', label: 'Sentýabr' },
|
||||
{ value: '10', label: 'Oktýabr' },
|
||||
{ value: '11', label: 'Noýabr' },
|
||||
{ value: '12', label: 'Dekabr' },
|
||||
]
|
||||
|
||||
// ─── MonthSelect ──────────────────────────────────────────────────────────────
|
||||
|
||||
interface MonthSelectProps {
|
||||
value: string
|
||||
onChange: (value: string) => void
|
||||
placeholder?: string
|
||||
}
|
||||
|
||||
export function MonthSelect({
|
||||
value,
|
||||
onChange,
|
||||
}: MonthSelectProps) {
|
||||
const isActive = Boolean(value)
|
||||
|
||||
return (
|
||||
<div className="flex items-center gap-1">
|
||||
<Select value={value || undefined} onValueChange={onChange}>
|
||||
<SelectTrigger
|
||||
className={cn(
|
||||
'h-9 w-[135px] gap-1.5 text-sm cursor-pointer transition-colors',
|
||||
isActive
|
||||
? 'border-primary text-primary font-medium [&>svg:last-child]:text-primary'
|
||||
: 'text-muted-foreground hover:text-foreground',
|
||||
)}
|
||||
>
|
||||
<Calendar size={14} className="shrink-0 opacity-80" />
|
||||
<span className="flex-1 text-left truncate">
|
||||
{isActive ? MONTHS.find(m => m.value === value)?.label : "—"}
|
||||
</span>
|
||||
</SelectTrigger>
|
||||
<SelectContent position="popper" sideOffset={4} className='p-1'>
|
||||
{MONTHS.map((m) => (
|
||||
<SelectItem key={m.value} value={m.value}>
|
||||
{m.label}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
{isActive && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onChange('')}
|
||||
className="h-6 w-6 rounded flex items-center justify-center text-muted-foreground hover:text-foreground hover:bg-muted/60 transition-colors"
|
||||
aria-label="Aý filtri aýyr"
|
||||
>
|
||||
<X size={11} />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
import { cva } from "class-variance-authority"
|
||||
|
||||
export const buttonVariants = cva(
|
||||
"group/button inline-flex shrink-0 cursor-pointer 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-3 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-lg 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-lg 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-lg [&_svg:not([class*='size-'])]:size-3",
|
||||
"icon-sm":
|
||||
"size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
|
||||
"icon-lg": "size-9",
|
||||
},
|
||||
},
|
||||
defaultVariants: {
|
||||
variant: "default",
|
||||
size: "default",
|
||||
},
|
||||
}
|
||||
)
|
||||
@@ -9,7 +9,7 @@ const buttonVariants = cva(
|
||||
{
|
||||
variants: {
|
||||
variant: {
|
||||
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
|
||||
default: "bg-[#005f78] dark: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:
|
||||
|
||||
Reference in New Issue
Block a user