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.

refactor: radio component

Brad Barbined3dfb85b045
diff --git a/apps/carbon/app/components/Form/Radios.tsx b/apps/carbon/app/components/Form/Radios.tsx
index a7423b7daf..d48c5a262c 100644
--- a/apps/carbon/app/components/Form/Radios.tsx
+++ b/apps/carbon/app/components/Form/Radios.tsx
@@ -2,27 +2,27 @@ import {
FormControl,
FormErrorMessage,
FormLabel,
- HStack,
- VStack,
+ RadioGroup,
+ RadioGroupItem,
} from "@carbon/react";
-import { Radio, RadioGroup } from "@chakra-ui/react";
+import { useId } from "react";
import { useField } from "remix-validated-form";
type RadiosProps = {
name: string;
label?: string;
options: { label: string; value: string }[];
- direction?: "column" | "row";
+ orientation?: "horizontal" | "vertical";
};
const Radios = ({
name,
label,
options,
- direction = "column",
+ orientation = "vertical",
}: RadiosProps) => {
const { getInputProps, error } = useField(name);
- const Stack = direction === "column" ? VStack : HStack;
+ const id = useId();
return (
<FormControl isInvalid={!!error}>
@@ -33,14 +33,14 @@ const Radios = ({
id: name,
})}
name={name}
+ orientation={orientation}
>
- <Stack className="items-start">
- {options.map(({ label, value }) => (
- <Radio key={value} value={value}>
- {label}
- </Radio>
- ))}
- </Stack>
+ {options.map(({ label, value }) => (
+ <div key={value} className="flex items-center space-x-2">
+ <RadioGroupItem value={value} id={`${id}:${value}`} />
+ <label htmlFor={`${id}:${value}`}>{label}</label>
+ </div>
+ ))}
</RadioGroup>
{error && <FormErrorMessage>{error}</FormErrorMessage>}
</FormControl>
diff --git a/packages/react/src/Radio.tsx b/packages/react/src/Radio.tsx
new file mode 100644
index 0000000000..0070b42e02
--- /dev/null
+++ b/packages/react/src/Radio.tsx
@@ -0,0 +1,45 @@
+"use client";
+
+import * as RadioGroupPrimitive from "@radix-ui/react-radio-group";
+import type { ComponentPropsWithoutRef, ElementRef } from "react";
+import { forwardRef } from "react";
+import { LuCircle } from "react-icons/lu";
+
+import { cn } from "~/utils/cn";
+
+const RadioGroup = forwardRef<
+ ElementRef<typeof RadioGroupPrimitive.Root>,
+ ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Root>
+>(({ className, ...props }, ref) => {
+ return (
+ <RadioGroupPrimitive.Root
+ className={cn("grid gap-2", className)}
+ {...props}
+ ref={ref}
+ />
+ );
+});
+RadioGroup.displayName = RadioGroupPrimitive.Root.displayName;
+
+const RadioGroupItem = forwardRef<
+ ElementRef<typeof RadioGroupPrimitive.Item>,
+ ComponentPropsWithoutRef<typeof RadioGroupPrimitive.Item>
+>(({ className, ...props }, ref) => {
+ return (
+ <RadioGroupPrimitive.Item
+ ref={ref}
+ className={cn(
+ "aspect-square h-4 w-4 rounded-full border border-primary text-primary ring-offset-background focus:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
+ className
+ )}
+ {...props}
+ >
+ <RadioGroupPrimitive.Indicator className="flex items-center justify-center">
+ <LuCircle className="h-2.5 w-2.5 fill-current text-current" />
+ </RadioGroupPrimitive.Indicator>
+ </RadioGroupPrimitive.Item>
+ );
+});
+RadioGroupItem.displayName = RadioGroupPrimitive.Item.displayName;
+
+export { RadioGroup, RadioGroupItem };
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index ab29b4248c..239291fdec 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -155,6 +155,7 @@ import {
PopoverHeader,
PopoverTrigger,
} from "./Popover";
+import { RadioGroup, RadioGroupItem } from "./Radio";
import {
Select,
SelectContent,
@@ -324,6 +325,8 @@ export {
PopoverFooter,
PopoverHeader,
PopoverTrigger,
+ RadioGroup,
+ RadioGroupItem,
Select,
SelectContent,
SelectGroup,