first commit

This commit is contained in:
Nermin Karic
2026-11-22 21:49:17 +01:00
commit f5e2fcbf98
693 changed files with 82975 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
"use client"
import { convertToLocale } from "@lib/util/money"
import React from "react"
import { Separator } from "@/components/ui/separator"
import { ShieldCheck } from "lucide-react"
type CartTotalsProps = {
totals: {
total?: number | null
subtotal?: number | null
tax_total?: number | null
currency_code: string
item_subtotal?: number | null
shipping_subtotal?: number | null
discount_subtotal?: number | null
}
}
const CartTotals: React.FC<CartTotalsProps> = ({ totals }) => {
const {
currency_code,
total,
tax_total,
item_subtotal,
shipping_subtotal,
discount_subtotal,
} = totals
// U BiH su maloprodajne cijene sa uračunatim 17% PDV-om
const grossAmount = total ?? item_subtotal ?? 0
const effectiveTax = tax_total && tax_total > 0
? tax_total
: grossAmount > 0
? Math.round((grossAmount * 17) / 117 * 100) / 100
: 0
return (
<div className="flex flex-col gap-3">
<div className="flex flex-col gap-2.5 text-sm text-muted-foreground">
<div className="flex items-center justify-between">
<span>Međuzbir stavki</span>
<span className="text-foreground font-medium" data-testid="cart-subtotal" data-value={item_subtotal || 0}>
{convertToLocale({ amount: item_subtotal ?? 0, currency_code })}
</span>
</div>
<div className="flex items-center justify-between">
<span>Dostava</span>
<span className="text-foreground font-medium" data-testid="cart-shipping" data-value={shipping_subtotal || 0}>
{shipping_subtotal ? convertToLocale({ amount: shipping_subtotal, currency_code }) : "Besplatno / Obračun"}
</span>
</div>
{!!discount_subtotal && (
<div className="flex items-center justify-between text-primary font-medium">
<span>Popust</span>
<span
data-testid="cart-discount"
data-value={discount_subtotal || 0}
>
-{" "}
{convertToLocale({
amount: discount_subtotal ?? 0,
currency_code,
})}
</span>
</div>
)}
<div className="flex justify-between">
<span>Uračunati PDV (17%)</span>
<span className="text-foreground font-medium" data-testid="cart-taxes" data-value={effectiveTax}>
{convertToLocale({ amount: effectiveTax, currency_code })}
</span>
</div>
</div>
<Separator className="my-1" />
<div className="flex items-center justify-between text-foreground">
<span className="font-semibold text-base">Ukupno za uplatu</span>
<span
className="text-xl font-extrabold text-primary"
data-testid="cart-total"
data-value={total || 0}
>
{convertToLocale({ amount: total ?? 0, currency_code })}
</span>
</div>
<div className="mt-1 flex items-center gap-1.5 text-[11px] text-muted-foreground/90 bg-muted/40 p-2.5 rounded-lg border border-border/60">
<ShieldCheck className="w-3.5 h-3.5 text-emerald-600 shrink-0" />
<span>Fiskalni račun i R1 porezna faktura za firme sa JIB/PDV brojem</span>
</div>
</div>
)
}
export default CartTotals

View File

@@ -0,0 +1,42 @@
import { Checkbox, Label } from "@modules/common/components/ui"
import React from "react"
type CheckboxProps = {
checked?: boolean
onChange?: () => void
label: string
name?: string
'data-testid'?: string
}
const CheckboxWithLabel: React.FC<CheckboxProps> = ({
checked = true,
onChange,
label,
name,
'data-testid': dataTestId
}) => {
return (
<div className="flex items-center space-x-2 ">
<Checkbox
className="text-base-regular flex items-center gap-x-2"
id="checkbox"
role="checkbox"
checked={checked}
readOnly
aria-checked={checked}
onClick={onChange}
name={name}
data-testid={dataTestId}
/>
<Label
htmlFor="checkbox"
className="!transform-none !txt-medium"
>
{label}
</Label>
</div>
)
}
export default CheckboxWithLabel

View File

@@ -0,0 +1,49 @@
"use client"
import { useState } from "react"
import { deleteLineItem } from "@lib/data/cart"
import { notifyCartUpdated } from "@lib/util/cart-events"
import { cn } from "@/lib/utils"
import { Trash2, Loader2 } from "lucide-react"
const DeleteButton = ({
id,
children,
className,
}: {
id: string
children?: React.ReactNode
className?: string
}) => {
const [isDeleting, setIsDeleting] = useState(false)
const handleDelete = async (id: string) => {
setIsDeleting(true)
await deleteLineItem(id)
.then(notifyCartUpdated)
.catch((_err) => {
setIsDeleting(false)
})
}
return (
<div className={cn("flex items-center", className)}>
<button
type="button"
className="inline-flex items-center gap-1.5 text-xs text-muted-foreground hover:text-destructive transition-colors disabled:opacity-50"
onClick={() => handleDelete(id)}
disabled={isDeleting}
aria-label="Ukloni artikal"
>
{isDeleting ? (
<Loader2 className="h-3.5 w-3.5 animate-spin" />
) : (
<Trash2 className="h-3.5 w-3.5" />
)}
{children && <span>{children}</span>}
</button>
</div>
)
}
export default DeleteButton

View File

@@ -0,0 +1,9 @@
import { cn } from "@/lib/utils"
const Divider = ({ className }: { className?: string }) => (
<div
className={cn("h-px w-full border-b border-border my-2", className)}
/>
)
export default Divider

View File

@@ -0,0 +1,61 @@
"use client"
import { Label } from "@/components/ui/label"
import { cn } from "@/lib/utils"
type FilterRadioGroupProps = {
title: string
items: {
value: string
label: string
}[]
value: string
handleChange: (value: string) => void
"data-testid"?: string
}
const FilterRadioGroup = ({
title,
items,
value,
handleChange,
"data-testid": dataTestId,
}: FilterRadioGroupProps) => {
return (
<div className="flex flex-col gap-3">
<span className="text-xs font-semibold uppercase tracking-wider text-muted-foreground">
{title}
</span>
<div className="flex flex-col gap-2" data-testid={dataTestId}>
{items?.map((item) => {
const isSelected = item.value === value
return (
<label
key={item.value}
htmlFor={item.value}
className={cn(
"flex items-center gap-2.5 px-3 py-2 rounded-md text-sm font-medium cursor-pointer transition-colors border",
isSelected
? "border-primary bg-primary/5 text-primary"
: "border-transparent text-muted-foreground hover:bg-muted hover:text-foreground"
)}
>
<input
type="radio"
id={item.value}
name={title}
value={item.value}
checked={isSelected}
onChange={() => handleChange(item.value)}
className="h-4 w-4 border-input text-primary focus:ring-ring focus:ring-offset-background"
/>
<span className="flex-1 select-none">{item.label}</span>
</label>
)
})}
</div>
</div>
)
}
export default FilterRadioGroup

View File

@@ -0,0 +1,76 @@
import { Label } from "@modules/common/components/ui"
import React, { useEffect, useImperativeHandle, useState } from "react"
import Eye from "@modules/common/icons/eye"
import EyeOff from "@modules/common/icons/eye-off"
type InputProps = Omit<
Omit<React.InputHTMLAttributes<HTMLInputElement>, "size">,
"placeholder"
> & {
label: string
errors?: Record<string, unknown>
touched?: Record<string, unknown>
name: string
topLabel?: string
}
const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ type, name, label, touched: _touched, required, topLabel, ...props }, ref) => {
const inputRef = React.useRef<HTMLInputElement>(null)
const [showPassword, setShowPassword] = useState(false)
const [inputType, setInputType] = useState(type)
useEffect(() => {
if (type === "password" && showPassword) {
setInputType("text")
}
if (type === "password" && !showPassword) {
setInputType("password")
}
}, [type, showPassword])
useImperativeHandle(ref, () => inputRef.current!)
return (
<div className="flex flex-col w-full">
{topLabel && (
<Label className="mb-2 txt-compact-medium-plus">{topLabel}</Label>
)}
<div className="flex relative z-0 w-full txt-compact-medium">
<input
type={inputType}
name={name}
placeholder=" "
required={required}
className="pt-4 pb-1 block w-full h-11 px-4 mt-0 bg-ui-bg-field border rounded-md appearance-none focus:outline-none focus:ring-0 focus:shadow-borders-interactive-with-active border-ui-border-base hover:bg-ui-bg-field-hover"
{...props}
ref={inputRef}
/>
<label
htmlFor={name}
onClick={() => inputRef.current?.focus()}
className="flex items-center justify-center mx-3 px-1 transition-all absolute duration-300 top-3 -z-1 origin-0 text-ui-fg-subtle"
>
{label}
{required && <span className="text-rose-500">*</span>}
</label>
{type === "password" && (
<button
type="button"
onClick={() => setShowPassword(!showPassword)}
className="text-ui-fg-subtle px-4 focus:outline-none transition-all duration-150 outline-none focus:text-ui-fg-base absolute right-0 top-3"
>
{showPassword ? <Eye /> : <EyeOff />}
</button>
)}
</div>
</div>
)
}
)
Input.displayName = "Input"
export default Input

View File

@@ -0,0 +1,35 @@
import { ArrowRight } from "lucide-react"
import LocalizedClientLink from "../localized-client-link"
import { cn } from "@/lib/utils"
type InteractiveLinkProps = {
href: string
children?: React.ReactNode
onClick?: () => void
className?: string
}
const InteractiveLink = ({
href,
children,
onClick,
className,
...props
}: InteractiveLinkProps) => {
return (
<LocalizedClientLink
className={cn(
"inline-flex items-center gap-1.5 text-sm font-medium text-foreground hover:text-primary transition-colors group",
className
)}
href={href}
onClick={onClick}
{...props}
>
<span>{children}</span>
<ArrowRight className="h-4 w-4 transition-transform group-hover:translate-x-0.5" />
</LocalizedClientLink>
)
}
export default InteractiveLink

View File

@@ -0,0 +1,26 @@
import { HttpTypes } from "@medusajs/types"
import { Text } from "@modules/common/components/ui"
type LineItemOptionsProps = {
variant: HttpTypes.StoreProductVariant | undefined
"data-testid"?: string
"data-value"?: HttpTypes.StoreProductVariant
}
const LineItemOptions = ({
variant,
"data-testid": dataTestid,
"data-value": dataValue,
}: LineItemOptionsProps) => {
return (
<Text
data-testid={dataTestid}
data-value={dataValue}
className="inline-block txt-medium text-ui-fg-subtle w-full overflow-hidden text-ellipsis"
>
Variant: {variant?.title}
</Text>
)
}
export default LineItemOptions

View File

@@ -0,0 +1,64 @@
import { getPercentageDiff } from "@lib/util/get-percentage-diff"
import { convertToLocale } from "@lib/util/money"
import { HttpTypes } from "@medusajs/types"
import { clx } from "@modules/common/components/ui"
type LineItemPriceProps = {
item: HttpTypes.StoreCartLineItem | HttpTypes.StoreOrderLineItem
style?: "default" | "tight"
currencyCode: string
}
const LineItemPrice = ({
item,
style = "default",
currencyCode,
}: LineItemPriceProps) => {
const { total, original_total } = item
const originalPrice = original_total ?? 0
const currentPrice = total ?? 0
const hasReducedPrice = currentPrice < originalPrice
return (
<div className="flex flex-col gap-x-2 text-ui-fg-subtle items-end">
<div className="text-left">
{hasReducedPrice && (
<>
<p>
{style === "default" && (
<span className="text-ui-fg-subtle">Original: </span>
)}
<span
className="line-through text-ui-fg-muted"
data-testid="product-original-price"
>
{convertToLocale({
amount: originalPrice,
currency_code: currencyCode,
})}
</span>
</p>
{style === "default" && (
<span className="text-ui-fg-interactive">
-{getPercentageDiff(originalPrice, currentPrice || 0)}%
</span>
)}
</>
)}
<span
className={clx("text-base-regular", {
"text-ui-fg-interactive": hasReducedPrice,
})}
data-testid="product-price"
>
{convertToLocale({
amount: currentPrice,
currency_code: currencyCode,
})}
</span>
</div>
</div>
)
}
export default LineItemPrice

View File

@@ -0,0 +1,62 @@
import { convertToLocale } from "@lib/util/money"
import { HttpTypes } from "@medusajs/types"
import { clx } from "@modules/common/components/ui"
type LineItemUnitPriceProps = {
item: HttpTypes.StoreCartLineItem | HttpTypes.StoreOrderLineItem
style?: "default" | "tight"
currencyCode: string
}
const LineItemUnitPrice = ({
item,
style = "default",
currencyCode,
}: LineItemUnitPriceProps) => {
const total = item.total ?? 0
const original_total = item.original_total ?? 0
const hasReducedPrice = total < original_total
const percentage_diff = Math.round(
((original_total - total) / original_total) * 100
)
return (
<div className="flex flex-col text-ui-fg-muted justify-center h-full">
{hasReducedPrice && (
<>
<p>
{style === "default" && (
<span className="text-ui-fg-muted">Original: </span>
)}
<span
className="line-through"
data-testid="product-unit-original-price"
>
{convertToLocale({
amount: original_total / item.quantity,
currency_code: currencyCode,
})}
</span>
</p>
{style === "default" && (
<span className="text-ui-fg-interactive">-{percentage_diff}%</span>
)}
</>
)}
<span
className={clx("text-base-regular", {
"text-ui-fg-interactive": hasReducedPrice,
})}
data-testid="product-unit-price"
>
{convertToLocale({
amount: total / item.quantity,
currency_code: currencyCode,
})}
</span>
</div>
)
}
export default LineItemUnitPrice

View File

@@ -0,0 +1,32 @@
"use client"
import Link from "next/link"
import { useParams } from "next/navigation"
import React from "react"
/**
* Use this component to create a Next.js `<Link />` that persists the current country code in the url,
* without having to explicitly pass it as a prop.
*/
const LocalizedClientLink = ({
children,
href,
...props
}: {
children?: React.ReactNode
href: string
className?: string
onClick?: () => void
passHref?: true
[x: string]: unknown
}) => {
const { countryCode } = useParams()
return (
<Link href={`/${countryCode}${href}`} {...props}>
{children}
</Link>
)
}
export default LocalizedClientLink

View File

@@ -0,0 +1,118 @@
import { Dialog, Transition } from "@headlessui/react"
import { clx } from "@modules/common/components/ui"
import React, { Fragment } from "react"
import { ModalProvider, useModal } from "@lib/context/modal-context"
import X from "@modules/common/icons/x"
type ModalProps = {
isOpen: boolean
close: () => void
size?: "small" | "medium" | "large"
search?: boolean
children: React.ReactNode
'data-testid'?: string
}
const Modal = ({
isOpen,
close,
size = "medium",
search = false,
children,
'data-testid': dataTestId
}: ModalProps) => {
return (
<Transition appear show={isOpen} as={Fragment}>
<Dialog as="div" className="relative z-[75]" onClose={close}>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0"
enterTo="opacity-100"
leave="ease-in duration-200"
leaveFrom="opacity-100"
leaveTo="opacity-0"
>
<div className="fixed inset-0 bg-opacity-75 backdrop-blur-md h-screen" />
</Transition.Child>
<div className="fixed inset-0 overflow-y-hidden">
<div
className={clx(
"flex min-h-full h-full justify-center p-4 text-center",
{
"items-center": !search,
"items-start": search,
}
)}
>
<Transition.Child
as={Fragment}
enter="ease-out duration-300"
enterFrom="opacity-0 scale-95"
enterTo="opacity-100 scale-100"
leave="ease-in duration-200"
leaveFrom="opacity-100 scale-100"
leaveTo="opacity-0 scale-95"
>
<Dialog.Panel
data-testid={dataTestId}
className={clx(
"flex flex-col justify-start w-full transform p-5 text-left align-middle transition-all max-h-[75vh] h-fit",
{
"max-w-md": size === "small",
"max-w-xl": size === "medium",
"max-w-3xl": size === "large",
"bg-transparent shadow-none": search,
"bg-white shadow-xl border rounded-rounded": !search,
}
)}
>
<ModalProvider close={close}>{children}</ModalProvider>
</Dialog.Panel>
</Transition.Child>
</div>
</div>
</Dialog>
</Transition>
)
}
const Title: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const { close } = useModal()
return (
<Dialog.Title className="flex items-center justify-between">
<div className="text-large-semi">{children}</div>
<div>
<button onClick={close} data-testid="close-modal-button">
<X size={20} />
</button>
</div>
</Dialog.Title>
)
}
const Description: React.FC<{ children: React.ReactNode }> = ({ children }) => {
return (
<Dialog.Description className="flex text-small-regular text-ui-fg-base items-center justify-center pt-2 pb-4 h-full">
{children}
</Dialog.Description>
)
}
const Body: React.FC<{ children: React.ReactNode }> = ({ children }) => {
return <div className="flex justify-center">{children}</div>
}
const Footer: React.FC<{ children: React.ReactNode }> = ({ children }) => {
return <div className="flex items-center justify-end gap-x-4">{children}</div>
}
Modal.Title = Title
Modal.Description = Description
Modal.Body = Body
Modal.Footer = Footer
export default Modal

View File

@@ -0,0 +1,74 @@
import { ChevronsUpDown } from "lucide-react"
import { cn } from "@/lib/utils"
import {
SelectHTMLAttributes,
forwardRef,
useEffect,
useImperativeHandle,
useRef,
useState,
} from "react"
export type NativeSelectProps = {
placeholder?: string
errors?: Record<string, unknown>
touched?: Record<string, unknown>
} & SelectHTMLAttributes<HTMLSelectElement>
const NativeSelect = forwardRef<HTMLSelectElement, NativeSelectProps>(
(
{ placeholder = "Odaberite...", defaultValue, className, children, ...props },
ref
) => {
const innerRef = useRef<HTMLSelectElement>(null)
const [isPlaceholder, setIsPlaceholder] = useState(false)
useImperativeHandle<HTMLSelectElement | null, HTMLSelectElement | null>(
ref,
() => innerRef.current
)
useEffect(() => {
if (innerRef.current && innerRef.current.value === "") {
setIsPlaceholder(true)
} else {
setIsPlaceholder(false)
}
}, [innerRef.current?.value])
return (
<div>
<div
onFocus={() => innerRef.current?.focus()}
onBlur={() => innerRef.current?.blur()}
className={cn(
"relative flex items-center rounded-md border border-input bg-background text-sm shadow-sm transition-colors focus-within:ring-1 focus-within:ring-ring",
className,
{
"text-muted-foreground": isPlaceholder,
}
)}
>
<select
ref={innerRef}
defaultValue={defaultValue}
{...props}
className="h-10 w-full appearance-none bg-transparent px-3 py-2 text-sm text-foreground outline-none cursor-pointer disabled:cursor-not-allowed disabled:opacity-50"
>
<option disabled value="">
{placeholder}
</option>
{children}
</select>
<span className="absolute right-3 inset-y-0 flex items-center pointer-events-none text-muted-foreground">
<ChevronsUpDown className="h-4 w-4" />
</span>
</div>
</div>
)
}
)
NativeSelect.displayName = "NativeSelect"
export default NativeSelect

View File

@@ -0,0 +1,27 @@
const Radio = ({ checked, 'data-testid': dataTestId }: { checked: boolean, 'data-testid'?: string }) => {
return (
<>
<button
type="button"
role="radio"
aria-checked="true"
data-state={checked ? "checked" : "unchecked"}
className="group relative flex h-5 w-5 items-center justify-center outline-none"
data-testid={dataTestId || 'radio-button'}
>
<div className="shadow-borders-base group-hover:shadow-borders-strong-with-shadow bg-ui-bg-base group-data-[state=checked]:bg-ui-bg-interactive group-data-[state=checked]:shadow-borders-interactive group-focus:!shadow-borders-interactive-with-focus group-disabled:!bg-ui-bg-disabled group-disabled:!shadow-borders-base flex h-[14px] w-[14px] items-center justify-center rounded-full transition-all">
{checked && (
<span
data-state={checked ? "checked" : "unchecked"}
className="group flex items-center justify-center"
>
<div className="bg-ui-bg-base shadow-details-contrast-on-bg-interactive group-disabled:bg-ui-fg-disabled rounded-full group-disabled:shadow-none h-1.5 w-1.5"></div>
</span>
)}
</div>
</button>
</>
)
}
export default Radio

View File

@@ -0,0 +1,443 @@
import * as React from "react"
import { cn } from "@/lib/utils"
export { cn as clx }
// Text Component
type TextProps = React.HTMLAttributes<HTMLParagraphElement> & {
as?: "p" | "span" | "div"
}
export const Text = React.forwardRef<HTMLParagraphElement, TextProps>(
({ className, as: Component = "p", children, ...props }, ref) => {
return (
<Component
ref={ref}
className={cn("text-sm text-foreground leading-relaxed", className)}
{...props}
>
{children}
</Component>
)
}
)
Text.displayName = "Text"
// Heading Component
type HeadingProps = React.HTMLAttributes<HTMLHeadingElement> & {
level?: "h1" | "h2" | "h3"
}
export const Heading = React.forwardRef<HTMLHeadingElement, HeadingProps>(
({ className, level: Component = "h2", children, ...props }, ref) => {
return (
<Component
ref={ref}
className={cn(
"font-semibold tracking-tight text-foreground",
Component === "h1" && "text-3xl font-extrabold sm:text-4xl",
Component === "h2" && "text-2xl font-bold sm:text-3xl",
Component === "h3" && "text-xl font-semibold sm:text-2xl",
className
)}
{...props}
>
{children}
</Component>
)
}
)
Heading.displayName = "Heading"
// Button Component
type ButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement> & {
variant?: "primary" | "secondary" | "transparent" | "outline" | "danger"
size?: "small" | "medium" | "large"
isLoading?: boolean
}
export const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
(
{
className,
variant = "primary",
size = "medium",
isLoading,
disabled,
children,
...props
},
ref
) => {
return (
<button
ref={ref}
disabled={disabled || isLoading}
className={cn(
"inline-flex items-center justify-center whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50",
variant === "primary" &&
"bg-primary text-primary-foreground shadow hover:bg-primary/90",
variant === "secondary" &&
"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
variant === "transparent" &&
"hover:bg-accent hover:text-accent-foreground",
variant === "outline" &&
"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",
variant === "danger" &&
"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",
size === "small" && "h-8 rounded-md px-3 text-xs",
size === "medium" && "h-9 px-4 py-2",
size === "large" && "h-11 rounded-md px-8 text-base",
className
)}
{...props}
>
{isLoading ? (
<span className="flex items-center gap-2">
<span className="h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent" />
<span>Učitavanje...</span>
</span>
) : (
children
)}
</button>
)
}
)
Button.displayName = "Button"
// Container Component
type ContainerProps = React.HTMLAttributes<HTMLDivElement>
export const Container = React.forwardRef<HTMLDivElement, ContainerProps>(
({ className, children, ...props }, ref) => {
return (
<div
ref={ref}
className={cn(
"rounded-xl border border-border bg-card p-6 text-card-foreground shadow-sm",
className
)}
{...props}
>
{children}
</div>
)
}
)
Container.displayName = "Container"
// Badge Component
type BadgeProps = React.HTMLAttributes<HTMLSpanElement> & {
color?: "green" | "red" | "blue" | "orange" | "grey" | "purple"
}
export const Badge = React.forwardRef<HTMLSpanElement, BadgeProps>(
({ className, color = "grey", children, ...props }, ref) => {
return (
<span
ref={ref}
className={cn(
"inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",
color === "grey" &&
"border-border bg-secondary text-secondary-foreground",
color === "green" &&
"border-transparent bg-emerald-50 text-emerald-700 dark:bg-emerald-950/50 dark:text-emerald-400",
color === "red" &&
"border-transparent bg-destructive/10 text-destructive",
color === "blue" &&
"border-transparent bg-primary/10 text-primary",
color === "orange" &&
"border-transparent bg-amber-50 text-amber-700 dark:bg-amber-950/50 dark:text-amber-400",
color === "purple" &&
"border-transparent bg-purple-50 text-purple-700 dark:bg-purple-950/50 dark:text-purple-400",
className
)}
{...props}
>
{children}
</span>
)
}
)
Badge.displayName = "Badge"
// IconBadge Component
type IconBadgeProps = React.HTMLAttributes<HTMLSpanElement>
export const IconBadge = React.forwardRef<HTMLSpanElement, IconBadgeProps>(
({ className, children, ...props }, ref) => {
return (
<span
ref={ref}
className={cn(
"inline-flex items-center justify-center rounded-lg bg-muted p-2 text-muted-foreground",
className
)}
{...props}
>
{children}
</span>
)
}
)
IconBadge.displayName = "IconBadge"
// IconButton Component
type IconButtonProps = React.ButtonHTMLAttributes<HTMLButtonElement>
export const IconButton = React.forwardRef<HTMLButtonElement, IconButtonProps>(
({ className, children, ...props }, ref) => {
return (
<button
ref={ref}
className={cn(
"inline-flex items-center justify-center rounded-md p-2 text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring transition-colors",
className
)}
{...props}
>
{children}
</button>
)
}
)
IconButton.displayName = "IconButton"
// Label Component
type LabelProps = React.LabelHTMLAttributes<HTMLLabelElement>
export const Label = React.forwardRef<HTMLLabelElement, LabelProps>(
({ className, children, ...props }, ref) => {
return (
<label
ref={ref}
className={cn(
"text-sm font-medium leading-none text-foreground peer-disabled:cursor-not-allowed peer-disabled:opacity-70",
className
)}
{...props}
>
{children}
</label>
)
}
)
Label.displayName = "Label"
// Input Component
type InputProps = React.InputHTMLAttributes<HTMLInputElement> & {
label?: string
}
export const Input = React.forwardRef<HTMLInputElement, InputProps>(
({ className, label, ...props }, ref) => {
return (
<div className="flex flex-col gap-1.5">
{label && <Label>{label}</Label>}
<input
ref={ref}
className={cn(
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
/>
</div>
)
}
)
Input.displayName = "Input"
// Table Components
type TableProps = React.HTMLAttributes<HTMLTableElement>
const TableRoot = React.forwardRef<HTMLTableElement, TableProps>(
({ className, children, ...props }, ref) => {
return (
<div className="relative w-full overflow-auto rounded-lg border border-border">
<table
ref={ref}
className={cn("w-full caption-bottom text-sm", className)}
{...props}
>
{children}
</table>
</div>
)
}
)
TableRoot.displayName = "Table"
type TableHeaderProps = React.HTMLAttributes<HTMLTableSectionElement>
const TableHeader = React.forwardRef<HTMLTableSectionElement, TableHeaderProps>(
({ className, children, ...props }, ref) => {
return (
<thead
ref={ref}
className={cn("[&_tr]:border-b border-border bg-muted/40", className)}
{...props}
>
{children}
</thead>
)
}
)
TableHeader.displayName = "TableHeader"
type TableBodyProps = React.HTMLAttributes<HTMLTableSectionElement>
const TableBody = React.forwardRef<HTMLTableSectionElement, TableBodyProps>(
({ className, children, ...props }, ref) => {
return (
<tbody
ref={ref}
className={cn("[&_tr:last-child]:border-0", className)}
{...props}
>
{children}
</tbody>
)
}
)
TableBody.displayName = "TableBody"
type TableRowProps = React.HTMLAttributes<HTMLTableRowElement>
const TableRow = React.forwardRef<HTMLTableRowElement, TableRowProps>(
({ className, children, ...props }, ref) => {
return (
<tr
ref={ref}
className={cn(
"border-b border-border transition-colors hover:bg-muted/50 data-[state=selected]:bg-muted",
className
)}
{...props}
>
{children}
</tr>
)
}
)
TableRow.displayName = "TableRow"
type TableHeadProps = React.ThHTMLAttributes<HTMLTableCellElement>
const TableHead = React.forwardRef<HTMLTableCellElement, TableHeadProps>(
({ className, children, ...props }, ref) => {
return (
<th
ref={ref}
className={cn(
"h-10 px-4 text-left align-middle font-medium text-muted-foreground [&:has([role=checkbox])]:pr-0",
className
)}
{...props}
>
{children}
</th>
)
}
)
TableHead.displayName = "TableHead"
type TableCellProps = React.TdHTMLAttributes<HTMLTableCellElement>
const TableCell = React.forwardRef<HTMLTableCellElement, TableCellProps>(
({ className, children, ...props }, ref) => {
return (
<td
ref={ref}
className={cn("p-4 align-middle [&:has([role=checkbox])]:pr-0 text-foreground", className)}
{...props}
>
{children}
</td>
)
}
)
TableCell.displayName = "TableCell"
export const Table = Object.assign(TableRoot, {
Header: TableHeader,
Body: TableBody,
Row: TableRow,
Head: TableHead,
HeaderCell: TableHead,
Cell: TableCell,
})
// RadioGroup Components
type RadioGroupProps = React.HTMLAttributes<HTMLDivElement>
const RadioGroupRoot = React.forwardRef<HTMLDivElement, RadioGroupProps>(
({ className, children, ...props }, ref) => {
return (
<div
ref={ref}
className={cn("flex flex-col gap-2", className)}
{...props}
>
{children}
</div>
)
}
)
RadioGroupRoot.displayName = "RadioGroup"
type RadioGroupItemProps = React.InputHTMLAttributes<HTMLInputElement> & {
label?: string
}
const RadioGroupItem = React.forwardRef<HTMLInputElement, RadioGroupItemProps>(
({ className, label, id, ...props }, ref) => {
return (
<div className="flex items-center gap-2">
<input
ref={ref}
type="radio"
id={id}
className={cn(
"h-4 w-4 border-input text-primary focus:ring-ring",
className
)}
{...props}
/>
{label && <Label htmlFor={id}>{label}</Label>}
</div>
)
}
)
RadioGroupItem.displayName = "RadioGroupItem"
export const RadioGroup = Object.assign(RadioGroupRoot, {
Item: RadioGroupItem,
})
// Checkbox Component
type CheckboxProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, "type"> & {
label?: string
}
export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
({ className, label, id, ...props }, ref) => {
return (
<div className="flex items-center gap-2">
<input
ref={ref}
type="checkbox"
id={id}
className={cn(
"h-4 w-4 rounded border-input text-primary focus:ring-ring",
className
)}
{...props}
/>
{label && <Label htmlFor={id}>{label}</Label>}
</div>
)
}
)
Checkbox.displayName = "Checkbox"