mirror of
https://github.com/ichsankurnia/hats-app.git
synced 2026-12-05 10:56:28 +00:00
bab7bbe272
This adds a clearer project assignment workflow with existing-project import, work-order sync, and stronger validation for project and work-order details. It also introduces reusable checkbox and input-group UI primitives and a dedicated loading state for the project assignment screen.
165 lines
5.3 KiB
TypeScript
165 lines
5.3 KiB
TypeScript
"use client"
|
|
|
|
import * as React from "react"
|
|
import { cva, type VariantProps } from "class-variance-authority"
|
|
import { cn } from "@/lib/utils"
|
|
|
|
import { Button } from "@/components/ui/button"
|
|
|
|
function InputGroup({ className, ...props }: React.ComponentProps<"div">) {
|
|
return (
|
|
<div
|
|
data-slot="input-group"
|
|
role="group"
|
|
className={cn(
|
|
"group/input-group relative flex w-full rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none bg-transparent dark:bg-zinc-950",
|
|
"h-10 min-w-0 items-center overflow-hidden",
|
|
"has-[textarea]:h-auto has-[textarea]:flex-col has-[textarea]:items-stretch",
|
|
|
|
// Focus state (matches Input.tsx exactly).
|
|
"focus-within:border-ring focus-within:ring-ring/50 focus-within:ring-[3px]",
|
|
"has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-[3px] has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50",
|
|
|
|
// Error state.
|
|
"has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-destructive/20 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",
|
|
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
const inputGroupAddonVariants = cva(
|
|
"flex select-none text-muted-foreground group-data-[disabled=true]/input-group:opacity-50 shrink-0",
|
|
{
|
|
variants: {
|
|
align: {
|
|
"inline-start":
|
|
"order-first h-full px-3.5 bg-muted/40 dark:bg-zinc-900 border-r border-input text-xs font-mono font-medium text-foreground/80 flex items-center justify-center",
|
|
"inline-end":
|
|
"order-last h-full px-3.5 bg-muted/40 dark:bg-zinc-900 border-l border-input text-xs font-mono font-medium text-foreground/80 flex items-center justify-center",
|
|
"block-start":
|
|
"order-first w-full justify-start px-3 py-2 border-b border-input bg-muted/20 dark:bg-zinc-900/40 text-xs",
|
|
"block-end":
|
|
"order-last w-full flex items-center justify-between px-3 py-1.5 border-t border-input bg-muted/20 dark:bg-zinc-900/40 text-xs",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
align: "inline-start",
|
|
},
|
|
}
|
|
)
|
|
|
|
function InputGroupAddon({
|
|
className,
|
|
align = "inline-start",
|
|
...props
|
|
}: React.ComponentProps<"div"> & VariantProps<typeof inputGroupAddonVariants>) {
|
|
return (
|
|
<div
|
|
role="group"
|
|
data-slot="input-group-addon"
|
|
data-align={align}
|
|
className={cn(inputGroupAddonVariants({ align }), className)}
|
|
onClick={(e) => {
|
|
if ((e.target as HTMLElement).closest("button")) {
|
|
return
|
|
}
|
|
e.currentTarget.parentElement?.querySelector<HTMLInputElement | HTMLTextAreaElement>("input, textarea")?.focus()
|
|
}}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
const inputGroupButtonVariants = cva(
|
|
"flex items-center gap-2 text-sm shadow-none",
|
|
{
|
|
variants: {
|
|
size: {
|
|
xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",
|
|
sm: "h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5",
|
|
"icon-xs":
|
|
"size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
|
|
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
|
|
},
|
|
},
|
|
defaultVariants: {
|
|
size: "xs",
|
|
},
|
|
}
|
|
)
|
|
|
|
function InputGroupButton({
|
|
className,
|
|
type = "button",
|
|
variant = "ghost",
|
|
size = "xs",
|
|
...props
|
|
}: Omit<React.ComponentProps<typeof Button>, "size"> &
|
|
VariantProps<typeof inputGroupButtonVariants>) {
|
|
return (
|
|
<Button
|
|
type={type}
|
|
data-size={size}
|
|
variant={variant}
|
|
className={cn(inputGroupButtonVariants({ size }), className)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function InputGroupText({ className, ...props }: React.ComponentProps<"span">) {
|
|
return (
|
|
<span
|
|
className={cn(
|
|
"flex items-center gap-2 text-xs text-muted-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-3.5",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function InputGroupInput({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<"input">) {
|
|
return (
|
|
<input
|
|
data-slot="input-group-control"
|
|
className={cn(
|
|
"flex-1 h-full w-full min-w-0 bg-transparent px-3 py-1 text-base md:text-sm text-foreground placeholder:text-muted-foreground outline-none border-0 shadow-none focus:outline-none focus:ring-0 focus-visible:outline-none focus-visible:ring-0 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 selection:bg-primary selection:text-primary-foreground",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
function InputGroupTextarea({
|
|
className,
|
|
...props
|
|
}: React.ComponentProps<"textarea">) {
|
|
return (
|
|
<textarea
|
|
data-slot="input-group-control"
|
|
className={cn(
|
|
"w-full min-w-0 bg-transparent p-3 text-base md:text-sm text-foreground placeholder:text-muted-foreground outline-none border-0 shadow-none focus:outline-none focus:ring-0 focus-visible:outline-none focus-visible:ring-0 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 selection:bg-primary selection:text-primary-foreground min-h-[96px]",
|
|
className
|
|
)}
|
|
{...props}
|
|
/>
|
|
)
|
|
}
|
|
|
|
export {
|
|
InputGroup,
|
|
InputGroupAddon,
|
|
InputGroupButton,
|
|
InputGroupText,
|
|
InputGroupInput,
|
|
InputGroupTextarea,
|
|
}
|