Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

feat: job details tab

Brad Barbin3e024e1c3859
diff --git a/apps/mes/src/components/Jobs/JobCard.tsx b/apps/mes/src/components/Jobs/JobCard.tsx
index 61b55c5475..ce18af8148 100644
--- a/apps/mes/src/components/Jobs/JobCard.tsx
+++ b/apps/mes/src/components/Jobs/JobCard.tsx
@@ -159,7 +159,7 @@ export function JobCard({
);
}
-function getStatusIcon(status: Job["status"]) {
+export function getStatusIcon(status: Job["status"]) {
switch (status) {
case "READY":
case "TODO":
@@ -178,7 +178,7 @@ function getStatusIcon(status: Job["status"]) {
}
}
-function getStatusText(status: Job["status"], overdue: boolean = false) {
+export function getStatusText(status: Job["status"], overdue: boolean = false) {
switch (status) {
case "READY":
return "Ready";
@@ -197,7 +197,10 @@ function getStatusText(status: Job["status"], overdue: boolean = false) {
}
}
-function getDeadlineIcon(deadlineType: Job["deadlineType"], overdue: boolean) {
+export function getDeadlineIcon(
+ deadlineType: Job["deadlineType"],
+ overdue: boolean
+) {
switch (deadlineType) {
case "ASAP":
return <BsExclamationSquareFill className="text-red-500" />;
@@ -212,7 +215,7 @@ function getDeadlineIcon(deadlineType: Job["deadlineType"], overdue: boolean) {
}
}
-function getDeadlineText(deadlineType: Job["deadlineType"]) {
+export function getDeadlineText(deadlineType: Job["deadlineType"]) {
switch (deadlineType) {
case "ASAP":
return "ASAP";
diff --git a/apps/mes/src/lib/data.tsx b/apps/mes/src/lib/data.tsx
index 0d8dba3d1c..b5dc7df38a 100644
--- a/apps/mes/src/lib/data.tsx
+++ b/apps/mes/src/lib/data.tsx
@@ -295,14 +295,6 @@ export const workInstructions = {
content: [
{
type: "text",
- marks: [
- {
- type: "textStyle",
- attrs: {
- color: "rgb(4, 4, 2)",
- },
- },
- ],
text: "I'm baby letterpress franzen palo santo offal. XOXO lumbersexual farm-to-table mustache neutra selfies chillwave aesthetic green juice blue bottle letterpress fanny pack try-hard gorpcore. Selvage marfa butcher kale chips craft beer fashion axe lumbersexual mlkshk truffaut etsy same salvia activated charcoal kogi woke. Hoodie green juice put a bird on it, echo park swag disrupt ugh air plant vaporware vice hammock.",
},
],
diff --git a/apps/mes/src/routes/job.tsx b/apps/mes/src/routes/job.tsx
index e46305ed33..650632f8c2 100644
--- a/apps/mes/src/routes/job.tsx
+++ b/apps/mes/src/routes/job.tsx
@@ -3,6 +3,7 @@ import {
Avatar,
Button,
Editor,
+ HStack,
Heading,
IconButton,
Modal,
@@ -18,24 +19,35 @@ import {
NumberInput,
NumberInputGroup,
NumberInputStepper,
- Popover,
- PopoverClose,
- PopoverContent,
- PopoverTrigger,
+ Progress,
ResizableHandle,
ResizablePanel,
+ ScrollArea,
Separator,
+ Table,
Tabs,
TabsContent,
TabsList,
TabsTrigger,
+ Tbody,
+ Td,
+ Th,
+ Thead,
+ ToggleGroup,
+ ToggleGroupItem,
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
+ Tr,
cn,
useMount,
} from "@carbon/react";
+import {
+ convertDateStringToIsoString,
+ formatDurationMilliseconds,
+ formatRelativeTime,
+} from "@carbon/utils";
import type { ComponentProps, ReactNode } from "react";
import { useRef, useState } from "react";
import {
@@ -45,14 +57,18 @@ import {
FaPause,
FaPlay,
FaRedoAlt,
+ FaTasks,
FaTrash,
- FaTruckLoading,
} from "react-icons/fa";
import {
LuChevronDown,
LuChevronLeft,
LuChevronUp,
+ LuClipboardCheck,
LuExpand,
+ LuHammer,
+ LuHardHat,
+ LuTimer,
} from "react-icons/lu";
import {
useLoaderData,
@@ -60,6 +76,12 @@ import {
useOutletContext,
useParams,
} from "react-router-dom";
+import {
+ getDeadlineIcon,
+ getDeadlineText,
+ getStatusIcon,
+ getStatusText,
+} from "~/components/Jobs/JobCard";
import { path } from "~/config";
import { useRouteData } from "~/hooks/useRouteData";
import { notes, workInstructions } from "~/lib/data";
@@ -87,6 +109,11 @@ export function Job() {
const [fullScreen, setFullScreen] = useState(false);
const [activeTab, setActiveTab] = useState("details");
+ const isOverdue =
+ job?.deadlineType !== "NO_DEADLINE" && job?.dueDate
+ ? new Date(job?.dueDate) < new Date()
+ : false;
+
const onWorkInstructionChange = (value: JSONContent) => {
console.log(value);
};
@@ -140,52 +167,278 @@ export function Job() {
</div>
</div>
- {!fullScreen && <Separator />}
+ {!fullScreen && (
+ <>
+ <Separator />
+ <div className="flex items-center justify-start px-4 py-2 h-[52px] bg-background gap-4">
+ {job.description && (
+ <HStack className="justify-start space-x-2">
+ <LuClipboardCheck className="text-muted-foreground" />
+ <span className="text-sm truncate">{job.description}</span>
+ </HStack>
+ )}
+ {job.status && (
+ <HStack className="justify-start space-x-2">
+ {getStatusIcon(job.status)}
+ <span className="text-sm truncate">
+ {getStatusText(job.status)}
+ </span>
+ </HStack>
+ )}
+ {job.duration && (
+ <HStack className="justify-start space-x-2">
+ <LuTimer className="text-muted-foreground" />
+ <span className="text-sm truncate">
+ {formatDurationMilliseconds(job.duration)}
+ </span>
+ </HStack>
+ )}
+ </div>
+ <Separator />
+ </>
+ )}
+
+ <TabsContent value="details">
+ <ScrollArea className="h-[calc(100vh-104px)] pb-36">
+ <div className="flex items-start justify-between p-4">
+ <div className="flex flex-col flex-grow">
+ <Heading size="h2">{job.part}</Heading>
+ <p className="text-muted-foreground line-clamp-1">
+ 3/8" x 2" x 1/4" Bracket
+ </p>
+ </div>
+ <div className="flex flex-col flex-shrink items-end">
+ <Heading size="h2">15</Heading>
+ <p className="text-muted-foreground line-clamp-1">Pieces</p>
+ </div>
+ </div>
+ <Separator />
+ <div className="flex items-start p-4">
+ <div className="grid gap-4 md:grid-cols-1 lg:grid-cols-3 w-full">
+ <div className="rounded-xl border bg-card text-card-foreground shadow">
+ <div className="p-6 flex flex-row items-center justify-between space-y-0 pb-2">
+ <h3 className="tracking-tight text-sm font-medium">
+ Scrapped
+ </h3>
+ <FaTrash className="h-3 w-3 text-muted-foreground" />
+ </div>
+ <div className="p-6 pt-0">
+ <Heading size="h2">0</Heading>
+ </div>
+ </div>
+ <div className="rounded-xl border bg-card text-card-foreground shadow">
+ <div className="p-6 flex flex-row items-center justify-between space-y-0 pb-2">
+ <h3 className="tracking-tight text-sm font-medium">
+ Completed
+ </h3>
+ <FaCheck className="h-3 w-3 text-muted-foreground" />
+ </div>
+ <div className="p-6 pt-0">
+ <Heading size="h2">0</Heading>
+ </div>
+ </div>
- <TabsContent value="details"></TabsContent>
+ <div className="rounded-xl border bg-card text-card-foreground shadow">
+ <div className="p-6 flex flex-row items-center justify-between space-y-0 pb-2">
+ <h3 className="tracking-tight text-sm font-medium">
+ Reworked
+ </h3>
+ <FaRedoAlt className="h-3 w-3 text-muted-foreground" />
+ </div>
+ <div className="p-6 pt-0">
+ <Heading size="h2">0</Heading>
+ </div>
+ </div>
+ </div>
+ </div>
+ <Separator />
+ <div className="flex items-start p-4">
+ <div className="flex flex-col w-full space-y-2">
+ <HStack>
+ <LuTimer className="h-4 w-4 mr-1" />
+ <Progress
+ leftLabel={formatDurationMilliseconds(6.5 * 60 * 1000)}
+ rightLabel={formatDurationMilliseconds(5 * 60 * 1000)}
+ value={120}
+ />
+ </HStack>
+ <HStack>
+ <LuHardHat className="h-4 w-4 mr-1" />
+ <Progress
+ leftLabel={
+ job.progress
+ ? formatDurationMilliseconds(job.progress)
+ : ""
+ }
+ rightLabel={
+ job.duration
+ ? formatDurationMilliseconds(job.duration)
+ : ""
+ }
+ value={
+ job.progress && job.duration
+ ? (job.progress / job.duration) * 100
+ : 0
+ }
+ />
+ </HStack>
+ <HStack>
+ <LuHammer className="h-4 w-4 mr-1" />
+ <Progress
+ leftLabel={
+ job.progress
+ ? formatDurationMilliseconds(job.progress)
+ : ""
+ }
+ rightLabel={
+ job.duration
+ ? formatDurationMilliseconds(job.duration)
+ : ""
+ }
+ value={
+ job.progress && job.duration
+ ? (job.progress / job.duration) * 100
+ : 0
+ }
+ />
+ </HStack>
+ <HStack>
+ <FaTasks className="h-4 w-4 mr-1" />
+ <Progress
+ indicatorClassName={
+ job.status === "PAUSED" ? "bg-yellow-500" : ""
+ }
+ leftLabel={"0/15"}
+ rightLabel={"0%"}
+ value={0}
+ />
+ </HStack>
+ </div>
+ </div>
+ <Separator />
+ {job.customerId && (
+ <>
+ <div className="flex items-start justify-between p-4">
+ <div className="flex flex-col flex-grow">
+ <Heading size="h3">Tesla</Heading>
+ <p className="text-muted-foreground line-clamp-1">
+ SO129034
+ </p>
+ </div>
+ <div className="flex flex-col flex-shrink items-end">
+ {job.deadlineType && (
+ <HStack className="justify-start space-x-2">
+ {getDeadlineIcon(job.deadlineType, isOverdue)}
+ <Tooltip>
+ <TooltipTrigger>
+ <span
+ className={cn(
+ "text-sm truncate",
+ isOverdue ? "text-red-500" : ""
+ )}
+ >
+ {["ASAP", "NO_DEADLINE"].includes(
+ job.deadlineType
+ )
+ ? getDeadlineText(job.deadlineType)
+ : job.dueDate
+ ? `Due ${formatRelativeTime(
+ convertDateStringToIsoString(job.dueDate)
+ )}`
+ : "–"}
+ </span>
+ </TooltipTrigger>
+ <TooltipContent side="bottom">
+ {getDeadlineText(job.deadlineType)}
+ </TooltipContent>
+ </Tooltip>
+ </HStack>
+ )}
+ </div>
+ </div>
+ <Separator />
+ </>
+ )}
+ <div className="flex flex-col items-start justify-between">
+ <div className="p-4">
+ <Heading size="h3">Files</Heading>
+ </div>
+ <Table>
+ <Thead>
+ <Tr>
+ <Th>Name</Th>
+ <Th>Size</Th>
+
+ <Th></Th>
+ </Tr>
+ </Thead>
+ <Tbody>
+ <Tr>
+ <Td
+ colSpan={24}
+ className="py-8 text-muted-foreground text-center"
+ >
+ No files
+ </Td>
+ </Tr>
+ </Tbody>
+ </Table>
+ </div>
+ </ScrollArea>
+ </TabsContent>
<TabsContent value="model"></TabsContent>
<TabsContent value="instructions" className="flex flex-grow bg-card">
- <Editor
- initialValue={workInstructions as JSONContent}
- onChange={onWorkInstructionChange}
- />
+ <ScrollArea className="h-[calc(100vh-104px)] pb-36">
+ <Editor
+ initialValue={workInstructions as JSONContent}
+ onChange={onWorkInstructionChange}
+ />
+ </ScrollArea>
</TabsContent>
<TabsContent value="notes">
<Notes job={job} notes={notes} />
</TabsContent>
- <Controls>
- <IconButtonWithTooltip
- disabled
- icon={
- <FaOilCan className="text-accent-foreground group-hover:text-accent-foreground/80" />
- }
- tooltip="Non-Conformance Report"
- />
- <IconButtonWithTooltip
- icon={
- <FaTrash className="text-accent-foreground group-hover:text-accent-foreground/80" />
- }
- tooltip="Scrap"
- />
- <PlayButton
- onStart={(type) => {
- alert(type);
- }}
- />
- <IconButtonWithTooltip
- icon={
- <FaRedoAlt className="text-accent-foreground group-hover:text-accent-foreground/80" />
- }
- tooltip="Rework"
- />
- <IconButtonWithTooltip
- icon={
- <FaCheck className="text-accent-foreground group-hover:text-accent-foreground/80" />
- }
- tooltip="Complete"
- />
- </Controls>
+ {activeTab !== "notes" && (
+ <Controls>
+ <div className="flex flex-col items-center gap-4">
+ <div className="flex items-center gap-4 justify-center">
+ <IconButtonWithTooltip
+ disabled
+ icon={
+ <FaOilCan className="text-accent-foreground group-hover:text-accent-foreground/80" />
+ }
+ tooltip="Non-Conformance Report"
+ />
+
+ <IconButtonWithTooltip
+ icon={
+ <FaTrash className="text-accent-foreground group-hover:text-accent-foreground/80" />
+ }
+ tooltip="Scrap"
+ />
+ <PlayButton
+ onStart={(type) => {
+ alert(type);
+ }}
+ />
+ <IconButtonWithTooltip
+ icon={
+ <FaRedoAlt className="text-accent-foreground group-hover:text-accent-foreground/80" />
+ }
+ tooltip="Rework"
+ />
+ <IconButtonWithTooltip
+ icon={
+ <FaCheck className="text-accent-foreground group-hover:text-accent-foreground/80" />
+ }
+ tooltip="Complete"
+ />
+ </div>
+ <WorkTypeToggle />
+ </div>
+ </Controls>
+ )}
</Tabs>
</OptionallyFullscreen>
</>
@@ -246,7 +499,7 @@ function Notes({ notes }: { job: JobType; notes: Note[] }) {
const { user } = useOutletContext<OutletContext>();
return (
- <div className="flex flex-col flex-auto h-[calc(100vh-130px)] p-6">
+ <div className="flex flex-col flex-auto h-[calc(100vh-108px)] p-6">
<div className="flex flex-col flex-auto flex-shrink-0 rounded-2xl bg-muted h-full p-4">
<div
ref={listRef}
@@ -258,7 +511,7 @@ function Notes({ notes }: { job: JobType; notes: Note[] }) {
<Message
key={note.id}
note={note}
- isFromUser={note.createdBy === user?.id}
+ isFromViewer={note.createdBy === user?.id}
/>
))}
</div>
@@ -306,11 +559,7 @@ function Notes({ notes }: { job: JobType; notes: Note[] }) {
</button> */}
</div>
- <Button
- className="bg-indigo-600 hover:bg-indigo-500 rounded-2xl"
- size="lg"
- rightIcon={<FaPaperPlane />}
- >
+ <Button className="rounded-xl" size="lg" rightIcon={<FaPaperPlane />}>
Send
</Button>
</div>
@@ -321,22 +570,22 @@ function Notes({ notes }: { job: JobType; notes: Note[] }) {
type MessageProps = {
note: Note;
- isFromUser: boolean;
+ isFromViewer: boolean;
};
-function Message({ note, isFromUser }: MessageProps) {
+function Message({ note, isFromViewer }: MessageProps) {
const { content, createdByAvatar, createdByName } = note;
return (
<div
className={cn(
"p-3 rounded-lg",
- isFromUser ? "col-start-6 col-end-13" : "col-start-1 col-end-8"
+ isFromViewer ? "col-start-6 col-end-13" : "col-start-1 col-end-8"
)}
>
<div
className={cn(
"flex items-center justify-start",
- isFromUser && "flex-row-reverse"
+ isFromViewer && "flex-row-reverse"
)}
>
<Avatar
@@ -348,7 +597,7 @@ function Message({ note, isFromUser }: MessageProps) {
<div
className={cn(
"relative text-sm py-2 px-4 shadow rounded-xl",
- isFromUser ? "mr-3 bg-indigo-100" : "ml-3 bg-background"
+ isFromViewer ? "mr-3 bg-indigo-100" : "ml-3 bg-background"
)}
>
<div>{content}</div>
@@ -369,7 +618,7 @@ function Controls({
<TooltipProvider>
<div
className={cn(
- "flex items-center gap-4 absolute p-4 bottom-0 left-1/2 transform -translate-x-1/2",
+ "absolute p-4 bottom-0 left-1/2 transform -translate-x-1/2",
className
)}
>
@@ -410,6 +659,37 @@ function IconButtonWithTooltip({
);
}
+function WorkTypeToggle() {
+ return (
+ <ToggleGroup defaultValue="labor" type="single">
+ <ToggleGroupItem
+ className="w-[110px]"
+ value="setup"
+ aria-label="Toggle setup"
+ >
+ <LuTimer className="h-4 w-4 mr-2" />
+ Setup
+ </ToggleGroupItem>
+ <ToggleGroupItem
+ className="w-[110px]"
+ value="labor"
+ aria-label="Toggle labor"
+ >
+ <LuHardHat className="h-4 w-4 mr-2" />
+ Labor
+ </ToggleGroupItem>
+ <ToggleGroupItem
+ className="w-[110px]"
+ value="machine"
+ aria-label="Toggle machine"
+ >
+ <LuHammer className="h-4 w-4 mr-2" />
+ Machine
+ </ToggleGroupItem>
+ </ToggleGroup>
+ );
+}
+
function PauseButton({ className, ...props }: ComponentProps<"button">) {
return (
<ButtonWithTooltip
@@ -427,44 +707,13 @@ function PlayButton({
onStart,
...props
}: ComponentProps<"button"> & { onStart: (type: "setup" | "run") => void }) {
- const closeButtonRef = useRef<HTMLButtonElement>(null);
-
return (
- <Popover>
- <PopoverTrigger asChild>
- <button
- {...props}
- className="group w-16 h-16 flex flex-row items-center gap-2 justify-center bg-emerald-500 rounded-full shadow-lg hover:cursor-pointer hover:drop-shadow-xl hover:bg-emerald-600 hover:scale-105 transition-all"
- >
- <FaPlay className="text-accent group-hover:scale-125" />
- </button>
- </PopoverTrigger>
- <PopoverContent className="flex space-x-4 w-full justify-center">
- <Button
- leftIcon={<FaTruckLoading />}
- size="lg"
- variant="secondary"
- onClick={() => {
- onStart("setup");
- closeButtonRef.current?.click();
- }}
- >
- Setup
- </Button>
- <Button
- leftIcon={<FaPlay />}
- size="lg"
- variant="primary"
- onClick={() => {
- onStart("run");
- closeButtonRef.current?.click();
- }}
- >
- Run
- </Button>
- <PopoverClose ref={closeButtonRef} className="sr-only" tabIndex={-1} />
- </PopoverContent>
- </Popover>
+ <button
+ {...props}
+ className="group w-16 h-16 flex flex-row items-center gap-2 justify-center bg-emerald-500 rounded-full shadow-lg hover:cursor-pointer hover:drop-shadow-xl hover:bg-emerald-600 hover:scale-105 transition-all"
+ >
+ <FaPlay className="text-accent group-hover:scale-125" />
+ </button>
);
}
diff --git a/package-lock.json b/package-lock.json
index 3c03277562..4167a9f4e9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -5593,6 +5593,60 @@
}
}
},
+ "node_modules/@radix-ui/react-toggle": {
+ "version": "1.0.3",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-toggle/-/react-toggle-1.0.3.tgz",
+ "integrity": "sha512-Pkqg3+Bc98ftZGsl60CLANXQBBQ4W3mTFS9EJvNxKMZ7magklKV69/id1mlAlOFDDfHvlCms0fx8fA4CMKDJHg==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/primitive": "1.0.1",
+ "@radix-ui/react-primitive": "1.0.3",
+ "@radix-ui/react-use-controllable-state": "1.0.1"
+ },
+ "peerDependencies": {
+ "@types/react": "*",
+ "@types/react-dom": "*",
+ "react": "^16.8 || ^17.0 || ^18.0",
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ },
+ "@types/react-dom": {
+ "optional": true
+ }
+ }
+ },
+ "node_modules/@radix-ui/react-toggle-group": {
+ "version": "1.0.4",
+ "resolved": "https://registry.npmjs.org/@radix-ui/react-toggle-group/-/react-toggle-group-1.0.4.tgz",
+ "integrity": "sha512-Uaj/M/cMyiyT9Bx6fOZO0SAG4Cls0GptBWiBmBxofmDbNVnYYoyRWj/2M/6VCi/7qcXFWnHhRUfdfZFvvkuu8A==",
+ "dependencies": {
+ "@babel/runtime": "^7.13.10",
+ "@radix-ui/primitive": "1.0.1",
+ "@radix-ui/react-context": "1.0.1",
+ "@radix-ui/react-direction": "1.0.1",
+ "@radix-ui/react-primitive": "1.0.3",
+ "@radix-ui/react-roving-focus": "1.0.4",
+ "@radix-ui/react-toggle": "1.0.3",
+ "@radix-ui/react-use-controllable-state": "1.0.1"
+ },
+ "peerDependencies": {
+ "@types/react": "*",
+ "@types/react-dom": "*",
+ "react": "^16.8 || ^17.0 || ^18.0",
+ "react-dom": "^16.8 || ^17.0 || ^18.0"
+ },
+ "peerDependenciesMeta": {
+ "@types/react": {
+ "optional": true
+ },
+ "@types/react-dom": {
+ "optional": true
+ }
+ }
+ },
"node_modules/@radix-ui/react-tooltip": {
"version": "1.0.7",
"resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.0.7.tgz",
@@ -34942,6 +34996,8 @@
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.4",
+ "@radix-ui/react-toggle": "^1.0.3",
+ "@radix-ui/react-toggle-group": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.6",
"@react-aria/button": "^3.8.0",
"@react-aria/calendar": "^3.4.0",
diff --git a/packages/react/package.json b/packages/react/package.json
index 39fecd275f..d83d336362 100644
--- a/packages/react/package.json
+++ b/packages/react/package.json
@@ -19,6 +19,8 @@
"@radix-ui/react-switch": "^1.0.3",
"@radix-ui/react-tabs": "^1.0.4",
"@radix-ui/react-toast": "^1.1.4",
+ "@radix-ui/react-toggle": "^1.0.3",
+ "@radix-ui/react-toggle-group": "^1.0.4",
"@radix-ui/react-tooltip": "^1.0.6",
"@react-aria/button": "^3.8.0",
"@react-aria/calendar": "^3.4.0",
diff --git a/packages/react/src/Toggle.tsx b/packages/react/src/Toggle.tsx
new file mode 100644
index 0000000000..c5c36f829d
--- /dev/null
+++ b/packages/react/src/Toggle.tsx
@@ -0,0 +1,46 @@
+"use client";
+
+import * as TogglePrimitive from "@radix-ui/react-toggle";
+import { cva, type VariantProps } from "class-variance-authority";
+
+import type { ComponentPropsWithoutRef, ElementRef } from "react";
+import { forwardRef } from "react";
+import { cn } from "./utils/cn";
+
+const toggleVariants = cva(
+ "inline-flex items-center justify-center rounded-md text-sm font-medium ring-offset-background transition-colors hover:bg-muted hover:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground",
+ {
+ variants: {
+ variant: {
+ default: "bg-transparent",
+ outline:
+ "border border-input bg-transparent hover:bg-accent hover:text-accent-foreground",
+ },
+ size: {
+ default: "h-10 px-3",
+ sm: "h-9 px-2.5",
+ lg: "h-11 px-5",
+ },
+ },
+ defaultVariants: {
+ variant: "default",
+ size: "default",
+ },
+ }
+);
+
+const Toggle = forwardRef<
+ ElementRef<typeof TogglePrimitive.Root>,
+ ComponentPropsWithoutRef<typeof TogglePrimitive.Root> &
+ VariantProps<typeof toggleVariants>
+>(({ className, variant, size, ...props }, ref) => (
+ <TogglePrimitive.Root
+ ref={ref}
+ className={cn(toggleVariants({ variant, size, className }))}
+ {...props}
+ />
+));
+
+Toggle.displayName = TogglePrimitive.Root.displayName;
+
+export { Toggle, toggleVariants };
diff --git a/packages/react/src/ToggleGroup.tsx b/packages/react/src/ToggleGroup.tsx
new file mode 100644
index 0000000000..4abd2d0440
--- /dev/null
+++ b/packages/react/src/ToggleGroup.tsx
@@ -0,0 +1,60 @@
+"use client";
+
+import * as ToggleGroupPrimitive from "@radix-ui/react-toggle-group";
+import type { VariantProps } from "class-variance-authority";
+
+import type { ComponentPropsWithoutRef, ElementRef } from "react";
+import { createContext, forwardRef, useContext } from "react";
+import { toggleVariants } from "./Toggle";
+import { cn } from "./utils/cn";
+
+const ToggleGroupContext = createContext<VariantProps<typeof toggleVariants>>({
+ size: "default",
+ variant: "default",
+});
+
+const ToggleGroup = forwardRef<
+ ElementRef<typeof ToggleGroupPrimitive.Root>,
+ ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Root> &
+ VariantProps<typeof toggleVariants>
+>(({ className, variant, size, children, ...props }, ref) => (
+ <ToggleGroupPrimitive.Root
+ ref={ref}
+ className={cn("flex items-center justify-center gap-1", className)}
+ {...props}
+ >
+ <ToggleGroupContext.Provider value={{ variant, size }}>
+ {children}
+ </ToggleGroupContext.Provider>
+ </ToggleGroupPrimitive.Root>
+));
+
+ToggleGroup.displayName = ToggleGroupPrimitive.Root.displayName;
+
+const ToggleGroupItem = forwardRef<
+ ElementRef<typeof ToggleGroupPrimitive.Item>,
+ ComponentPropsWithoutRef<typeof ToggleGroupPrimitive.Item> &
+ VariantProps<typeof toggleVariants>
+>(({ className, children, variant, size, ...props }, ref) => {
+ const context = useContext(ToggleGroupContext);
+
+ return (
+ <ToggleGroupPrimitive.Item
+ ref={ref}
+ className={cn(
+ toggleVariants({
+ variant: context.variant || variant,
+ size: context.size || size,
+ }),
+ className
+ )}
+ {...props}
+ >
+ {children}
+ </ToggleGroupPrimitive.Item>
+ );
+});
+
+ToggleGroupItem.displayName = ToggleGroupPrimitive.Item.displayName;
+
+export { ToggleGroup, ToggleGroupItem };
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index 3b9aaf9aed..a6d1964bab 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -223,6 +223,8 @@ import { Tabs, TabsContent, TabsList, TabsTrigger } from "./Tabs";
import type { TextareaProps } from "./Textarea";
import { Textarea } from "./Textarea";
import { Toaster, toast } from "./Toast";
+import { Toggle } from "./Toggle";
+import { ToggleGroup, ToggleGroupItem } from "./ToggleGroup";
import {
Tooltip,
TooltipContent,
@@ -432,6 +434,9 @@ export {
Thead,
TimePicker,
Toaster,
+ Toggle,
+ ToggleGroup,
+ ToggleGroupItem,
Tooltip,
TooltipContent,
TooltipProvider,