Skip to content
Merged
5 changes: 3 additions & 2 deletions docs/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ frontend/src/
│ ├── ui/ # Shared UI components (shadcn/ui and Base UI)
│ ├── filter-builder/ # QueryKit filter component
│ ├── app-sidebar.tsx # Main navigation
│ ├── theme-provider.tsx # Theme context
│ ├── theme-context.ts # Theme context and useTheme
│ ├── theme-provider.tsx # Theme provider
│ └── theme-toggle.tsx # Light, dark, and system toggle
├── routes/ # TanStack Router file routes
├── hooks/ # Shared React hooks
Expand Down Expand Up @@ -76,7 +77,7 @@ export const Route = createFileRoute('/users')({

## Theme

`useTheme()` from `@/components/theme-provider` returns `theme` and `setTheme`. The values are `'light'`, `'dark'`, and `'system'`. The theme persists in localStorage.
`useTheme()` from `@/components/theme-context` returns `theme` and `setTheme`. The values are `'light'`, `'dark'`, and `'system'`. The theme persists in localStorage.

## Filter builder

Expand Down
4 changes: 0 additions & 4 deletions frontend/src/components/filter-builder/filter-builder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { FilterPropertyMenu } from './filter-property-menu'
import type { Filter, FilterBuilderProps } from './types'
import { isFilter } from './types'
import { canCreateGroup } from './utils/depth'
import { toQueryKitString } from './utils/querykit-converter'
import { LogicalOperators } from './utils/operators'
import { useFilterBuilderReducer } from './use-filter-builder-reducer'

Expand Down Expand Up @@ -277,6 +276,3 @@ export function FilterBuilder({
</div>
)
}

// Export utility function to convert state to QueryKit string
export { toQueryKitString }
44 changes: 0 additions & 44 deletions frontend/src/components/filter-builder/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,76 +1,8 @@
import toast, { Toaster, type ToastOptions } from 'react-hot-toast'
import toast, { type ToastOptions } from 'react-hot-toast'
import { cn } from '@/lib/utils'
import { Cancel01Icon, CheckmarkCircle02Icon, AlertCircleIcon, InformationCircleIcon, Alert02Icon } from '@hugeicons/core-free-icons'
import { Cancel01Icon } from '@hugeicons/core-free-icons'
import { HugeiconsIcon } from '@hugeicons/react'

/**
* Toast notification component styled with the app's theme.
* Place this component once at the root of your app (e.g., in main.tsx).
*
* Usage:
* Notification.success('Operation completed!')
* Notification.error('Something went wrong')
* Notification.info('Here is some information')
* Notification.warning('Please be careful')
*/
export function Notifications() {
return (
<Toaster
position="top-center"
gutter={8}
containerClassName=""
toastOptions={{
duration: 4000,
className: cn(
'bg-card text-card-foreground border border-border',
'shadow-lg rounded-lg px-4 py-3',
'flex items-start gap-3 min-w-[300px] max-w-[500px]'
),
}}
/>
)
}

// Icons for each toast type
const icons = {
success: CheckmarkCircle02Icon,
error: AlertCircleIcon,
info: InformationCircleIcon,
warning: Alert02Icon,
} as const

// Colors for each toast type using theme variables
const iconColors = {
success: 'text-chart-2', // green from chart colors
error: 'text-destructive',
info: 'text-primary',
warning: 'text-chart-3', // orange from chart colors
} as const

type ToastType = keyof typeof icons

interface ToastContentProps {
message: string
type: ToastType
description?: string
}

function ToastContent({ message, type, description }: ToastContentProps) {
const icon = icons[type]
const iconColor = iconColors[type]

return (
<div className="flex items-start gap-3 flex-1">
<HugeiconsIcon icon={icon} className={cn('size-5 shrink-0 mt-0.5', iconColor)} />
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-foreground">{message}</p>
{description && (
<p className="text-sm text-muted-foreground mt-1">{description}</p>
)}
</div>
</div>
)
}
import { ToastContent, type ToastType } from '@/components/toaster'

type NotificationOptions = ToastOptions & {
description?: string
Expand Down
24 changes: 24 additions & 0 deletions frontend/src/components/theme-context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { createContext, useContext } from "react"

export type Theme = "dark" | "light" | "system"

type ThemeProviderState = {
theme: Theme
setTheme: (theme: Theme) => void
}

const initialState: ThemeProviderState = {
theme: "system",
setTheme: () => null,
}

export const ThemeProviderContext = createContext<ThemeProviderState>(initialState)

export const useTheme = () => {
const context = useContext(ThemeProviderContext)

if (context === undefined)
throw new Error("useTheme must be used within a ThemeProvider")

return context
}
26 changes: 2 additions & 24 deletions frontend/src/components/theme-provider.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
import { createContext, useContext, useEffect, useState } from "react"

type Theme = "dark" | "light" | "system"
import { useEffect, useState } from "react"
import { ThemeProviderContext, type Theme } from "@/components/theme-context"

type ThemeProviderProps = {
children: React.ReactNode
defaultTheme?: Theme
storageKey?: string
}

type ThemeProviderState = {
theme: Theme
setTheme: (theme: Theme) => void
}

const initialState: ThemeProviderState = {
theme: "system",
setTheme: () => null,
}

const ThemeProviderContext = createContext<ThemeProviderState>(initialState)

export function ThemeProvider({
children,
defaultTheme = "system",
Expand Down Expand Up @@ -78,12 +65,3 @@ export function ThemeProvider({
</ThemeProviderContext.Provider>
)
}

export const useTheme = () => {
const context = useContext(ThemeProviderContext)

if (context === undefined)
throw new Error("useTheme must be used within a ThemeProvider")

return context
}
10 changes: 5 additions & 5 deletions frontend/src/components/theme-toggle.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Sun03Icon, Moon02Icon, ComputerIcon } from "@hugeicons/core-free-icons"
import { HugeiconsIcon } from "@hugeicons/react"
import { useTheme } from "@/components/theme-provider"
import { useTheme } from "@/components/theme-context"
import { cn } from "@/lib/utils"

export function ThemeToggle() {
const { theme, setTheme } = useTheme()

return (
<div className="inline-flex items-center rounded-lg border bg-muted p-0.5">
<div className="inline-flex items-center rounded-lg border bg-muted p-0.5 group-data-[collapsible=icon]:flex-col">
<button
onClick={() => setTheme("light")}
className={cn(
"inline-flex items-center justify-center rounded-md px-2 py-1 text-sm transition-colors",
"inline-flex items-center justify-center rounded-md px-2 py-1 text-sm group-data-[collapsible=icon]:px-1 transition-colors",
theme === "light"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
Expand All @@ -23,7 +23,7 @@ export function ThemeToggle() {
<button
onClick={() => setTheme("dark")}
className={cn(
"inline-flex items-center justify-center rounded-md px-2 py-1 text-sm transition-colors",
"inline-flex items-center justify-center rounded-md px-2 py-1 text-sm group-data-[collapsible=icon]:px-1 transition-colors",
theme === "dark"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
Expand All @@ -35,7 +35,7 @@ export function ThemeToggle() {
<button
onClick={() => setTheme("system")}
className={cn(
"inline-flex items-center justify-center rounded-md px-2 py-1 text-sm transition-colors",
"inline-flex items-center justify-center rounded-md px-2 py-1 text-sm group-data-[collapsible=icon]:px-1 transition-colors",
theme === "system"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
Expand Down
73 changes: 73 additions & 0 deletions frontend/src/components/toaster.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { Toaster as HotToaster } from 'react-hot-toast'
import { cn } from '@/lib/utils'
import { CheckmarkCircle02Icon, AlertCircleIcon, InformationCircleIcon, Alert02Icon } from '@hugeicons/core-free-icons'
import { HugeiconsIcon } from '@hugeicons/react'

/**
* The container that shows the toast notifications, styled with the theme of the app.
* main.tsx renders it once, at the root of the app.
*
* To show a toast, call `Notification` from '@/components/notification':
* Notification.success('Operation completed!')
* Notification.error('Something went wrong')
* Notification.info('Here is some information')
* Notification.warning('Please be careful')
*/
export function Toaster() {
return (
<HotToaster
position="top-center"
gutter={8}
containerClassName=""
toastOptions={{
duration: 4000,
className: cn(
'bg-card text-card-foreground border border-border',
'shadow-lg rounded-lg px-4 py-3',
'flex items-start gap-3 min-w-[300px] max-w-[500px]'
),
}}
/>
)
}

// Icons for each toast type
const icons = {
success: CheckmarkCircle02Icon,
error: AlertCircleIcon,
info: InformationCircleIcon,
warning: Alert02Icon,
} as const

// Colors for each toast type using theme variables
const iconColors = {
success: 'text-chart-2', // green from chart colors
error: 'text-destructive',
info: 'text-primary',
warning: 'text-chart-3', // orange from chart colors
} as const

export type ToastType = keyof typeof icons

interface ToastContentProps {
message: string
type: ToastType
description?: string
}

export function ToastContent({ message, type, description }: ToastContentProps) {
const icon = icons[type]
const iconColor = iconColors[type]

return (
<div className="flex items-start gap-3 flex-1">
<HugeiconsIcon icon={icon} className={cn('size-5 shrink-0 mt-0.5', iconColor)} />
<div className="flex-1 min-w-0">
<p className="text-sm font-medium text-foreground">{message}</p>
{description && (
<p className="text-sm text-muted-foreground mt-1">{description}</p>
)}
</div>
</div>
)
}
4 changes: 0 additions & 4 deletions frontend/src/components/ui/autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,6 @@ function AutocompleteClearButton({
)
}

// Hook for filtering - re-export from Base UI
const useAutocompleteFilter = AutocompletePrimitive.useFilter

// Convenience component that combines common parts
function AutocompleteContent({
className,
Expand Down Expand Up @@ -236,5 +233,4 @@ export {
AutocompleteStatus,
AutocompleteClearButton,
AutocompleteContent,
useAutocompleteFilter,
}
22 changes: 22 additions & 0 deletions frontend/src/components/ui/badge-variants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { cva } from "class-variance-authority"

const badgeVariants = cva(
"h-5 gap-1 rounded-4xl border border-transparent px-2 py-0.5 text-xs font-medium transition-all has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&>svg]:size-3! inline-flex items-center justify-center w-fit whitespace-nowrap shrink-0 [&>svg]:pointer-events-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive transition-colors overflow-hidden group/badge",
{
variants: {
variant: {
default: "bg-primary text-primary-foreground [a]:hover:bg-primary/80",
secondary: "bg-secondary text-secondary-foreground [a]:hover:bg-secondary/80",
destructive: "bg-destructive/10 [a]:hover:bg-destructive/20 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 text-destructive dark:bg-destructive/20",
outline: "border-border text-foreground [a]:hover:bg-muted [a]:hover:text-muted-foreground",
ghost: "hover:bg-muted hover:text-muted-foreground dark:hover:bg-muted/50",
link: "text-primary underline-offset-4 hover:underline",
},
},
defaultVariants: {
variant: "default",
},
}
)

export { badgeVariants }
Loading