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: form component

Brad Barbinc1128a8bdf84
diff --git a/apps/carbon/app/components/Form/Abilities.tsx b/apps/carbon/app/components/Form/Abilities.tsx
index 72dc9dd5b4..5463f307cf 100644
--- a/apps/carbon/app/components/Form/Abilities.tsx
+++ b/apps/carbon/app/components/Form/Abilities.tsx
@@ -1,11 +1,12 @@
import type { MultiValue } from "@carbon/react";
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Ability.tsx b/apps/carbon/app/components/Form/Ability.tsx
index 5c0f55fc1b..b775c8ba79 100644
--- a/apps/carbon/app/components/Form/Ability.tsx
+++ b/apps/carbon/app/components/Form/Ability.tsx
@@ -1,11 +1,13 @@
import type { SingleValue } from "@carbon/react";
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
+
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Account.tsx b/apps/carbon/app/components/Form/Account.tsx
index 9658c05e6f..07bdc84087 100644
--- a/apps/carbon/app/components/Form/Account.tsx
+++ b/apps/carbon/app/components/Form/Account.tsx
@@ -1,10 +1,11 @@
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/AccountCategory.tsx b/apps/carbon/app/components/Form/AccountCategory.tsx
index 48acd6285b..2171f6030b 100644
--- a/apps/carbon/app/components/Form/AccountCategory.tsx
+++ b/apps/carbon/app/components/Form/AccountCategory.tsx
@@ -1,10 +1,11 @@
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/AccountSubcategory.tsx b/apps/carbon/app/components/Form/AccountSubcategory.tsx
index 692fa0536b..02c54059fa 100644
--- a/apps/carbon/app/components/Form/AccountSubcategory.tsx
+++ b/apps/carbon/app/components/Form/AccountSubcategory.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Array.tsx b/apps/carbon/app/components/Form/Array.tsx
index eeb4a2944d..2158371dce 100644
--- a/apps/carbon/app/components/Form/Array.tsx
+++ b/apps/carbon/app/components/Form/Array.tsx
@@ -1,11 +1,14 @@
-import { Button, HStack, IconButton, VStack } from "@carbon/react";
-import type { InputProps } from "@chakra-ui/react";
+import type { InputProps } from "@carbon/react";
import {
- Input as ChakraInput,
+ Button,
FormControl,
FormErrorMessage,
FormLabel,
-} from "@chakra-ui/react";
+ HStack,
+ IconButton,
+ Input as InputBase,
+ VStack,
+} from "@carbon/react";
import { forwardRef } from "react";
import { IoMdAdd, IoMdClose } from "react-icons/io";
import { useField, useFieldArray } from "remix-validated-form";
@@ -62,7 +65,7 @@ const ArrayInput = forwardRef<HTMLInputElement, ArrayInputProps>(
return (
<FormControl isInvalid={!!error} isRequired>
<HStack className="w-full content-between">
- <ChakraInput
+ <InputBase
ref={ref}
{...getInputProps({
id: name,
diff --git a/apps/carbon/app/components/Form/Boolean.tsx b/apps/carbon/app/components/Form/Boolean.tsx
index af7bc3836a..4502040b51 100644
--- a/apps/carbon/app/components/Form/Boolean.tsx
+++ b/apps/carbon/app/components/Form/Boolean.tsx
@@ -1,10 +1,12 @@
-import { HStack } from "@carbon/react";
-import type { SwitchProps, SystemStyleObject } from "@chakra-ui/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
+ HStack,
+} from "@carbon/react";
+import type { SwitchProps, SystemStyleObject } from "@chakra-ui/react";
+import {
VisuallyHidden,
chakra,
omitThemingProps,
@@ -62,7 +64,7 @@ const Boolean = forwardRef<HTMLInputElement, FormBooleanProps>(
);
return (
- <FormControl isInvalid={!!error} pt={2}>
+ <FormControl isInvalid={!!error} className="pt-2">
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
<HStack className="w-full">
<chakra.label
diff --git a/apps/carbon/app/components/Form/Color.tsx b/apps/carbon/app/components/Form/Color.tsx
index fe9156697d..e9c58a14da 100644
--- a/apps/carbon/app/components/Form/Color.tsx
+++ b/apps/carbon/app/components/Form/Color.tsx
@@ -1,12 +1,11 @@
-import { HStack } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormLabel,
+ HStack,
useDisclosure,
useOutsideClick,
-} from "@chakra-ui/react";
-
+} from "@carbon/react";
import { useRef } from "react";
import { HexColorInput, HexColorPicker } from "react-colorful";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/CreatableMultiSelect.tsx b/apps/carbon/app/components/Form/CreatableMultiSelect.tsx
index 99c61e950d..46d28d45e1 100644
--- a/apps/carbon/app/components/Form/CreatableMultiSelect.tsx
+++ b/apps/carbon/app/components/Form/CreatableMultiSelect.tsx
@@ -1,10 +1,10 @@
-import { CreatableSelect } from "@carbon/react";
import {
+ CreatableSelect,
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+} from "@carbon/react";
import { useControlField, useField } from "remix-validated-form";
import type { SelectProps } from "./Select";
diff --git a/apps/carbon/app/components/Form/CreatableSelect.tsx b/apps/carbon/app/components/Form/CreatableSelect.tsx
index f19111aaf3..2fb2144e8a 100644
--- a/apps/carbon/app/components/Form/CreatableSelect.tsx
+++ b/apps/carbon/app/components/Form/CreatableSelect.tsx
@@ -1,10 +1,10 @@
-import { CreatableSelect } from "@carbon/react";
import {
+ CreatableSelect,
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+} from "@carbon/react";
import { useControlField, useField } from "remix-validated-form";
import type { SelectProps } from "./Select";
diff --git a/apps/carbon/app/components/Form/Currency.tsx b/apps/carbon/app/components/Form/Currency.tsx
index b0723008fa..419e85eb5a 100644
--- a/apps/carbon/app/components/Form/Currency.tsx
+++ b/apps/carbon/app/components/Form/Currency.tsx
@@ -1,10 +1,11 @@
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Customer.tsx b/apps/carbon/app/components/Form/Customer.tsx
index c721e81aa4..536593f283 100644
--- a/apps/carbon/app/components/Form/Customer.tsx
+++ b/apps/carbon/app/components/Form/Customer.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
import { useCustomers } from "~/stores";
diff --git a/apps/carbon/app/components/Form/CustomerContact.tsx b/apps/carbon/app/components/Form/CustomerContact.tsx
index 561faacfa8..27d2200c49 100644
--- a/apps/carbon/app/components/Form/CustomerContact.tsx
+++ b/apps/carbon/app/components/Form/CustomerContact.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo, useRef } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/CustomerLocation.tsx b/apps/carbon/app/components/Form/CustomerLocation.tsx
index 83808cd170..a2ae2db549 100644
--- a/apps/carbon/app/components/Form/CustomerLocation.tsx
+++ b/apps/carbon/app/components/Form/CustomerLocation.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo, useRef } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/DatePicker.tsx b/apps/carbon/app/components/Form/DatePicker.tsx
index 8f352f365c..7921425787 100644
--- a/apps/carbon/app/components/Form/DatePicker.tsx
+++ b/apps/carbon/app/components/Form/DatePicker.tsx
@@ -1,5 +1,9 @@
-import { DatePicker as DatePickerBase } from "@carbon/react";
-import { FormControl, FormErrorMessage, FormLabel } from "@chakra-ui/react";
+import {
+ DatePicker as DatePickerBase,
+ FormControl,
+ FormErrorMessage,
+ FormLabel,
+} from "@carbon/react";
import type { CalendarDate } from "@internationalized/date";
import { parseDate } from "@internationalized/date";
import { useState } from "react";
diff --git a/apps/carbon/app/components/Form/Department.tsx b/apps/carbon/app/components/Form/Department.tsx
index 31692b86ec..a5495df8d8 100644
--- a/apps/carbon/app/components/Form/Department.tsx
+++ b/apps/carbon/app/components/Form/Department.tsx
@@ -1,10 +1,11 @@
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Employees.tsx b/apps/carbon/app/components/Form/Employees.tsx
index 6237ff30ef..510571b023 100644
--- a/apps/carbon/app/components/Form/Employees.tsx
+++ b/apps/carbon/app/components/Form/Employees.tsx
@@ -3,7 +3,7 @@ import {
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+} from "@carbon/react";
import { useState } from "react";
import { useField } from "remix-validated-form";
import { UserSelect } from "../Selectors";
diff --git a/apps/carbon/app/components/Form/Hidden.tsx b/apps/carbon/app/components/Form/Hidden.tsx
index a8fca7469b..9aa032d8ac 100644
--- a/apps/carbon/app/components/Form/Hidden.tsx
+++ b/apps/carbon/app/components/Form/Hidden.tsx
@@ -1,9 +1,9 @@
-import type { InputProps } from "@chakra-ui/react";
+import type { InputProps } from "@carbon/react";
import {
- Input as ChakraInput,
FormControl,
FormErrorMessage,
-} from "@chakra-ui/react";
+ Input as InputBase,
+} from "@carbon/react";
import { forwardRef } from "react";
import { useField } from "remix-validated-form";
@@ -18,7 +18,7 @@ const Hidden = forwardRef<HTMLInputElement, HiddenProps>(
return (
<FormControl isInvalid={!!error}>
- <ChakraInput
+ <InputBase
ref={ref}
{...getInputProps({
id: name,
diff --git a/apps/carbon/app/components/Form/Input.tsx b/apps/carbon/app/components/Form/Input.tsx
index 327b89d615..f249cca140 100644
--- a/apps/carbon/app/components/Form/Input.tsx
+++ b/apps/carbon/app/components/Form/Input.tsx
@@ -1,16 +1,14 @@
import type { InputProps } from "@carbon/react";
import {
+ FormControl,
+ FormErrorMessage,
+ FormHelperText,
+ FormLabel,
Input as InputBase,
InputGroup,
InputLeftAddon,
InputRightAddon,
} from "@carbon/react";
-import {
- FormControl,
- FormErrorMessage,
- FormHelperText,
- FormLabel,
-} from "@chakra-ui/react";
import { forwardRef } from "react";
import { useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/InputControlled.tsx b/apps/carbon/app/components/Form/InputControlled.tsx
index f7d12c426a..8192a63eae 100644
--- a/apps/carbon/app/components/Form/InputControlled.tsx
+++ b/apps/carbon/app/components/Form/InputControlled.tsx
@@ -1,16 +1,14 @@
import type { InputProps } from "@carbon/react";
import {
+ FormControl,
+ FormErrorMessage,
+ FormHelperText,
+ FormLabel,
Input as InputBase,
InputGroup,
InputLeftAddon,
InputRightAddon,
} from "@carbon/react";
-import {
- FormControl,
- FormErrorMessage,
- FormHelperText,
- FormLabel,
-} from "@chakra-ui/react";
import type { ChangeEvent } from "react";
import { forwardRef, useEffect } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Location.tsx b/apps/carbon/app/components/Form/Location.tsx
index 16c9cc55b6..b44d61c122 100644
--- a/apps/carbon/app/components/Form/Location.tsx
+++ b/apps/carbon/app/components/Form/Location.tsx
@@ -1,10 +1,11 @@
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Number.tsx b/apps/carbon/app/components/Form/Number.tsx
index 4ab9174d3e..b92d38fc4a 100644
--- a/apps/carbon/app/components/Form/Number.tsx
+++ b/apps/carbon/app/components/Form/Number.tsx
@@ -1,9 +1,11 @@
-import type { NumberInputProps } from "@chakra-ui/react";
-import { FormHelperText } from "@chakra-ui/react";
import {
FormControl,
FormErrorMessage,
+ FormHelperText,
FormLabel,
+} from "@carbon/react";
+import type { NumberInputProps } from "@chakra-ui/react";
+import {
NumberDecrementStepper,
NumberIncrementStepper,
NumberInput,
diff --git a/apps/carbon/app/components/Form/Part.tsx b/apps/carbon/app/components/Form/Part.tsx
index 97f06914a8..f6d41bb22d 100644
--- a/apps/carbon/app/components/Form/Part.tsx
+++ b/apps/carbon/app/components/Form/Part.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
import type { PartReplenishmentSystem } from "~/modules/parts";
diff --git a/apps/carbon/app/components/Form/Password.tsx b/apps/carbon/app/components/Form/Password.tsx
index 7b72ab1154..44aaabf56d 100644
--- a/apps/carbon/app/components/Form/Password.tsx
+++ b/apps/carbon/app/components/Form/Password.tsx
@@ -1,11 +1,13 @@
import type { InputProps } from "@carbon/react";
import {
+ FormControl,
+ FormErrorMessage,
+ FormLabel,
IconButton,
Input,
InputGroup,
InputRightElement,
} from "@carbon/react";
-import { FormControl, FormErrorMessage, FormLabel } from "@chakra-ui/react";
import { forwardRef, useState } from "react";
import { BiHide, BiShowAlt } from "react-icons/bi";
import { useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Phone.tsx b/apps/carbon/app/components/Form/Phone.tsx
index 6aa5386df1..39435bb1f4 100644
--- a/apps/carbon/app/components/Form/Phone.tsx
+++ b/apps/carbon/app/components/Form/Phone.tsx
@@ -1,10 +1,10 @@
-import type { InputProps } from "@chakra-ui/react";
+import type { InputProps } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormLabel,
- Input as ChakraInput,
-} from "@chakra-ui/react";
+ Input as InputBase,
+} from "@carbon/react";
import { forwardRef } from "react";
import { useField } from "remix-validated-form";
@@ -21,7 +21,7 @@ const Phone = forwardRef<HTMLInputElement, FormPhoneProps>(
return (
<FormControl isInvalid={!!error} isRequired={isRequired}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
- <ChakraInput
+ <InputBase
ref={ref}
{...getInputProps({
id: name,
diff --git a/apps/carbon/app/components/Form/Radios.tsx b/apps/carbon/app/components/Form/Radios.tsx
index dcf335671f..a7423b7daf 100644
--- a/apps/carbon/app/components/Form/Radios.tsx
+++ b/apps/carbon/app/components/Form/Radios.tsx
@@ -1,19 +1,18 @@
-import type { StackDirection } from "@chakra-ui/react";
import {
FormControl,
FormErrorMessage,
FormLabel,
- Radio,
- RadioGroup,
- Stack,
-} from "@chakra-ui/react";
+ HStack,
+ VStack,
+} from "@carbon/react";
+import { Radio, RadioGroup } from "@chakra-ui/react";
import { useField } from "remix-validated-form";
type RadiosProps = {
name: string;
label?: string;
options: { label: string; value: string }[];
- direction?: StackDirection;
+ direction?: "column" | "row";
};
const Radios = ({
@@ -23,6 +22,7 @@ const Radios = ({
direction = "column",
}: RadiosProps) => {
const { getInputProps, error } = useField(name);
+ const Stack = direction === "column" ? VStack : HStack;
return (
<FormControl isInvalid={!!error}>
@@ -34,7 +34,7 @@ const Radios = ({
})}
name={name}
>
- <Stack alignItems="start" direction={direction}>
+ <Stack className="items-start">
{options.map(({ label, value }) => (
<Radio key={value} value={value}>
{label}
diff --git a/apps/carbon/app/components/Form/RichText.tsx b/apps/carbon/app/components/Form/RichText.tsx
index 9efe5aa8e0..f5422c22dd 100644
--- a/apps/carbon/app/components/Form/RichText.tsx
+++ b/apps/carbon/app/components/Form/RichText.tsx
@@ -1,6 +1,10 @@
-import { Editor, useEditor } from "@carbon/react";
+import {
+ Editor,
+ FormControl,
+ FormErrorMessage,
+ useEditor,
+} from "@carbon/react";
import type { BoxProps } from "@chakra-ui/react";
-import { FormControl, FormErrorMessage } from "@chakra-ui/react";
import { useEffect } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Select.tsx b/apps/carbon/app/components/Form/Select.tsx
index 582e200e2b..03296578f3 100644
--- a/apps/carbon/app/components/Form/Select.tsx
+++ b/apps/carbon/app/components/Form/Select.tsx
@@ -1,10 +1,10 @@
-import { Select as CarbonSelect } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select as SelectBase,
+} from "@carbon/react";
import { useMemo } from "react";
import { useField } from "remix-validated-form";
@@ -40,7 +40,7 @@ const Select = ({
<FormControl isInvalid={!!error}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
{options?.length > 0 ? (
- <CarbonSelect
+ <SelectBase
{...getInputProps({
// @ts-ignore
id: name,
@@ -51,18 +51,12 @@ const Select = ({
isLoading={isLoading}
options={options}
placeholder={placeholder}
- // @ts-ignore
w="full"
// @ts-ignore
onChange={onChange ?? undefined}
/>
) : (
- <CarbonSelect
- isLoading={isLoading}
- options={[]}
- // @ts-ignore
- w="full"
- />
+ <SelectBase isLoading={isLoading} options={[]} w="full" />
)}
{error ? (
diff --git a/apps/carbon/app/components/Form/SelectControlled.tsx b/apps/carbon/app/components/Form/SelectControlled.tsx
index eacba275c9..56151c0c4a 100644
--- a/apps/carbon/app/components/Form/SelectControlled.tsx
+++ b/apps/carbon/app/components/Form/SelectControlled.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useEffect } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Sequence.tsx b/apps/carbon/app/components/Form/Sequence.tsx
index 90cb6aad4e..88012128c7 100644
--- a/apps/carbon/app/components/Form/Sequence.tsx
+++ b/apps/carbon/app/components/Form/Sequence.tsx
@@ -1,10 +1,11 @@
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Service.tsx b/apps/carbon/app/components/Form/Service.tsx
index f31f641a9f..04845a38d6 100644
--- a/apps/carbon/app/components/Form/Service.tsx
+++ b/apps/carbon/app/components/Form/Service.tsx
@@ -1,10 +1,11 @@
-import { Select, useMount } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Slider.tsx b/apps/carbon/app/components/Form/Slider.tsx
index b93c0fc440..ae0e8ea772 100644
--- a/apps/carbon/app/components/Form/Slider.tsx
+++ b/apps/carbon/app/components/Form/Slider.tsx
@@ -1,21 +1,21 @@
-import type { SliderProps as ChakraSliderProps } from "@chakra-ui/react";
+import {
+ FormControl,
+ FormErrorMessage,
+ FormHelperText,
+ FormLabel,
+} from "@carbon/react";
+import type { SliderProps as SliderBaseProps } from "@chakra-ui/react";
import {
Box,
+ Slider as SliderBase,
SliderFilledTrack,
SliderThumb,
SliderTrack,
} from "@chakra-ui/react";
-import { FormHelperText } from "@chakra-ui/react";
-import {
- FormControl,
- FormErrorMessage,
- FormLabel,
- Slider as ChakraSlider,
-} from "@chakra-ui/react";
import { forwardRef } from "react";
import { useField } from "remix-validated-form";
-type SliderProps = ChakraSliderProps & {
+type SliderProps = SliderBaseProps & {
name: string;
label?: string;
isRequired?: boolean;
@@ -30,7 +30,7 @@ const Slider = forwardRef<HTMLInputElement, SliderProps>(
<FormControl isInvalid={!!error} isRequired={isRequired}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
- <ChakraSlider
+ <SliderBase
{...getInputProps({
id: name,
...rest,
@@ -41,7 +41,7 @@ const Slider = forwardRef<HTMLInputElement, SliderProps>(
<SliderFilledTrack bg="green.500" />
</SliderTrack>
<SliderThumb boxSize={6} />
- </ChakraSlider>
+ </SliderBase>
{helperText && <FormHelperText>{helperText}</FormHelperText>}
{error && <FormErrorMessage>{error}</FormErrorMessage>}
</FormControl>
diff --git a/apps/carbon/app/components/Form/Supplier.tsx b/apps/carbon/app/components/Form/Supplier.tsx
index 817b89a9ae..ec5174448f 100644
--- a/apps/carbon/app/components/Form/Supplier.tsx
+++ b/apps/carbon/app/components/Form/Supplier.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useMemo } from "react";
import { useControlField, useField } from "remix-validated-form";
import { useSuppliers } from "~/stores";
diff --git a/apps/carbon/app/components/Form/SupplierContact.tsx b/apps/carbon/app/components/Form/SupplierContact.tsx
index 136f356da4..fb6537423c 100644
--- a/apps/carbon/app/components/Form/SupplierContact.tsx
+++ b/apps/carbon/app/components/Form/SupplierContact.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo, useRef } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/SupplierLocation.tsx b/apps/carbon/app/components/Form/SupplierLocation.tsx
index af555c8fe5..03f6ea9b38 100644
--- a/apps/carbon/app/components/Form/SupplierLocation.tsx
+++ b/apps/carbon/app/components/Form/SupplierLocation.tsx
@@ -1,10 +1,10 @@
-import { Select } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo, useRef } from "react";
import { useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/components/Form/Textarea.tsx b/apps/carbon/app/components/Form/Textarea.tsx
index ece9553265..d1efbb1ed0 100644
--- a/apps/carbon/app/components/Form/Textarea.tsx
+++ b/apps/carbon/app/components/Form/Textarea.tsx
@@ -1,11 +1,6 @@
-import { useColor } from "@carbon/react";
+import { FormControl, FormErrorMessage, FormLabel } from "@carbon/react";
import type { TextareaProps } from "@chakra-ui/react";
-import {
- Textarea as ChakraTextArea,
- FormControl,
- FormErrorMessage,
- FormLabel,
-} from "@chakra-ui/react";
+import { Textarea as TextAreaBase } from "@chakra-ui/react";
import type { ChangeEvent } from "react";
import { forwardRef, useState } from "react";
import { useField } from "remix-validated-form";
@@ -31,13 +26,13 @@ const TextArea = forwardRef<HTMLTextAreaElement, FormTextArea>(
return (
<FormControl isInvalid={!!error} isRequired={isRequired}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
- <ChakraTextArea
+ <TextAreaBase
ref={ref}
{...getInputProps({
id: name,
...rest,
})}
- bg={useColor("white")}
+ className="bg-transparent"
maxLength={characterLimit}
onChange={onChange}
/>
diff --git a/apps/carbon/app/components/Form/TimePicker.tsx b/apps/carbon/app/components/Form/TimePicker.tsx
index f9aade3599..9d69c3c0a2 100644
--- a/apps/carbon/app/components/Form/TimePicker.tsx
+++ b/apps/carbon/app/components/Form/TimePicker.tsx
@@ -1,5 +1,9 @@
-import { TimePicker as CarbonTimePicker } from "@carbon/react";
-import { FormControl, FormErrorMessage, FormLabel } from "@chakra-ui/react";
+import {
+ FormControl,
+ FormErrorMessage,
+ FormLabel,
+ TimePicker as TimePickerBase,
+} from "@carbon/react";
import type {
CalendarDateTime,
Time,
@@ -34,7 +38,7 @@ const TimePicker = ({ name, label, onChange }: TimePickerProps) => {
<FormControl isInvalid={!!error}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
<input type="hidden" name={name} value={date?.toString()} />
- <CarbonTimePicker
+ <TimePickerBase
value={date ?? undefined}
//@ts-ignore
onChange={handleChange}
diff --git a/apps/carbon/app/components/Form/Timezone.tsx b/apps/carbon/app/components/Form/Timezone.tsx
index 932e5c8ca8..5aaa007b76 100644
--- a/apps/carbon/app/components/Form/Timezone.tsx
+++ b/apps/carbon/app/components/Form/Timezone.tsx
@@ -1,10 +1,11 @@
-import { createFilter, Select as CarbonSelect } from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+ Select as SelectBase,
+ createFilter,
+} from "@carbon/react";
import { useMemo } from "react";
import { useField } from "remix-validated-form";
import { timezonesGroupedByCountry } from "~/config/timezones";
@@ -43,7 +44,7 @@ const Timezone = ({
return (
<FormControl isInvalid={!!error}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
- <CarbonSelect
+ <SelectBase
{...getInputProps({
// @ts-ignore
id: name,
diff --git a/apps/carbon/app/components/Form/User.tsx b/apps/carbon/app/components/Form/User.tsx
index 31a082cefc..47bde38df0 100644
--- a/apps/carbon/app/components/Form/User.tsx
+++ b/apps/carbon/app/components/Form/User.tsx
@@ -3,7 +3,7 @@ import {
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+} from "@carbon/react";
import { useState } from "react";
import { useField } from "remix-validated-form";
import { UserSelect } from "../Selectors";
diff --git a/apps/carbon/app/components/Form/Users.tsx b/apps/carbon/app/components/Form/Users.tsx
index 0116e7bd86..763ac37331 100644
--- a/apps/carbon/app/components/Form/Users.tsx
+++ b/apps/carbon/app/components/Form/Users.tsx
@@ -3,7 +3,7 @@ import {
FormErrorMessage,
FormHelperText,
FormLabel,
-} from "@chakra-ui/react";
+} from "@carbon/react";
import { useState } from "react";
import { useField } from "remix-validated-form";
import { UserSelect } from "../Selectors";
diff --git a/apps/carbon/app/components/Selectors/UserSelect/UserSelect.tsx b/apps/carbon/app/components/Selectors/UserSelect/UserSelect.tsx
index 34395285a6..fc164f0a5b 100644
--- a/apps/carbon/app/components/Selectors/UserSelect/UserSelect.tsx
+++ b/apps/carbon/app/components/Selectors/UserSelect/UserSelect.tsx
@@ -10,8 +10,7 @@
* @see WAI-ARIA Tree View https://www.w3.org/WAI/ARIA/apg/patterns/treeview/
*/
-import { Select } from "@carbon/react";
-import { FormLabel } from "@chakra-ui/react";
+import { FormLabel, Select } from "@carbon/react";
import { usePermissions } from "~/hooks";
import Combobox from "./components/Combobox";
import Container from "./components/Container";
diff --git a/apps/carbon/app/components/Selectors/UserSelect/useUserSelect.ts b/apps/carbon/app/components/Selectors/UserSelect/useUserSelect.ts
index a70130295f..0b06bbb98e 100644
--- a/apps/carbon/app/components/Selectors/UserSelect/useUserSelect.ts
+++ b/apps/carbon/app/components/Selectors/UserSelect/useUserSelect.ts
@@ -1,10 +1,17 @@
-import { useDisclosure, useId, useOutsideClick } from "@chakra-ui/react";
+import { useDisclosure, useOutsideClick } from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import type { PostgrestError } from "@supabase/supabase-js";
import debounce from "lodash/debounce";
import words from "lodash/words";
import type { AriaAttributes, ChangeEvent, KeyboardEvent } from "react";
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import {
+ useCallback,
+ useEffect,
+ useId,
+ useMemo,
+ useRef,
+ useState,
+} from "react";
import type { Group } from "~/modules/users";
import { path } from "~/utils/path";
diff --git a/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountSubcategoryForm/AccountSubcategoryForm.tsx b/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountSubcategoryForm/AccountSubcategoryForm.tsx
index aba122c144..b9dd268af3 100644
--- a/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountSubcategoryForm/AccountSubcategoryForm.tsx
+++ b/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountSubcategoryForm/AccountSubcategoryForm.tsx
@@ -6,11 +6,13 @@ import {
DrawerFooter,
DrawerHeader,
DrawerTitle,
+ FormControl,
+ FormLabel,
HStack,
Input as InputBase,
VStack,
} from "@carbon/react";
-import { FormControl, FormLabel } from "@chakra-ui/react";
+import {} from "@chakra-ui/react";
import { useParams } from "@remix-run/react";
import { ValidatedForm } from "remix-validated-form";
import { Hidden, Input, Submit } from "~/components/Form";
diff --git a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx
index 2b032d1656..fd11f7099c 100644
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx
@@ -6,13 +6,13 @@ import {
DrawerFooter,
DrawerHeader,
DrawerTitle,
+ FormControl,
+ FormLabel,
HStack,
Input,
VStack,
} from "@carbon/react";
import {
- FormControl,
- FormLabel,
NumberDecrementStepper,
NumberIncrementStepper,
NumberInput,
diff --git a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx
index dcfccc74cf..e765f396de 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx
@@ -6,13 +6,13 @@ import {
DrawerFooter,
DrawerHeader,
DrawerTitle,
+ FormControl,
+ FormLabel,
HStack,
Input,
VStack,
} from "@carbon/react";
import {
- FormControl,
- FormLabel,
NumberDecrementStepper,
NumberIncrementStepper,
NumberInput,
diff --git a/apps/carbon/app/modules/resources/ui/Equipment/EquipmentForm/EquipmentForm.tsx b/apps/carbon/app/modules/resources/ui/Equipment/EquipmentForm/EquipmentForm.tsx
index 3e8e116b30..6786cda16b 100644
--- a/apps/carbon/app/modules/resources/ui/Equipment/EquipmentForm/EquipmentForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Equipment/EquipmentForm/EquipmentForm.tsx
@@ -6,10 +6,12 @@ import {
DrawerFooter,
DrawerHeader,
DrawerTitle,
+ FormControl,
+ FormErrorMessage,
+ FormLabel,
HStack,
VStack,
} from "@carbon/react";
-import { FormControl, FormErrorMessage, FormLabel } from "@chakra-ui/react";
import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo, useState } from "react";
import { ValidatedForm, useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/modules/resources/ui/Partners/PartnerForm/PartnerForm.tsx b/apps/carbon/app/modules/resources/ui/Partners/PartnerForm/PartnerForm.tsx
index e80a5a247d..331235b6e3 100644
--- a/apps/carbon/app/modules/resources/ui/Partners/PartnerForm/PartnerForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Partners/PartnerForm/PartnerForm.tsx
@@ -6,12 +6,14 @@ import {
DrawerFooter,
DrawerHeader,
DrawerTitle,
+ FormControl,
+ FormErrorMessage,
+ FormLabel,
HStack,
Select,
VStack,
useMount,
} from "@carbon/react";
-import { FormControl, FormErrorMessage, FormLabel } from "@chakra-ui/react";
import { useFetcher, useNavigate } from "@remix-run/react";
import { useEffect, useMemo } from "react";
import { ValidatedForm, useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/modules/resources/ui/Person/PersonJob/PersonJob.tsx b/apps/carbon/app/modules/resources/ui/Person/PersonJob/PersonJob.tsx
index 0ac0664adc..c2ce1688c8 100644
--- a/apps/carbon/app/modules/resources/ui/Person/PersonJob/PersonJob.tsx
+++ b/apps/carbon/app/modules/resources/ui/Person/PersonJob/PersonJob.tsx
@@ -1,5 +1,11 @@
-import { Select, VStack, useMount } from "@carbon/react";
-import { FormControl, FormErrorMessage, FormLabel } from "@chakra-ui/react";
+import {
+ FormControl,
+ FormErrorMessage,
+ FormLabel,
+ Select,
+ VStack,
+ useMount,
+} from "@carbon/react";
import { useFetcher } from "@remix-run/react";
import { useEffect, useMemo } from "react";
import { ValidatedForm, useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/modules/resources/ui/Shifts/ShiftForm/ShiftForm.tsx b/apps/carbon/app/modules/resources/ui/Shifts/ShiftForm/ShiftForm.tsx
index 58096b7e83..1b352763b0 100644
--- a/apps/carbon/app/modules/resources/ui/Shifts/ShiftForm/ShiftForm.tsx
+++ b/apps/carbon/app/modules/resources/ui/Shifts/ShiftForm/ShiftForm.tsx
@@ -6,10 +6,11 @@ import {
DrawerFooter,
DrawerHeader,
DrawerTitle,
+ FormControl,
+ FormLabel,
HStack,
VStack,
} from "@carbon/react";
-import { FormControl, FormLabel } from "@chakra-ui/react";
import { useNavigate } from "@remix-run/react";
import { ValidatedForm } from "remix-validated-form";
import {
diff --git a/apps/carbon/app/modules/users/ui/Customers/CreateCustomerModal/CreateCustomerModal.tsx b/apps/carbon/app/modules/users/ui/Customers/CreateCustomerModal/CreateCustomerModal.tsx
index 62ba2cc7d6..f3d12e2515 100644
--- a/apps/carbon/app/modules/users/ui/Customers/CreateCustomerModal/CreateCustomerModal.tsx
+++ b/apps/carbon/app/modules/users/ui/Customers/CreateCustomerModal/CreateCustomerModal.tsx
@@ -1,4 +1,7 @@
import {
+ FormControl,
+ FormErrorMessage,
+ FormLabel,
HStack,
Input,
Modal,
@@ -11,12 +14,7 @@ import {
Select,
VStack,
} from "@carbon/react";
-import {
- FormControl,
- FormErrorMessage,
- FormLabel,
- Grid,
-} from "@chakra-ui/react";
+import { Grid } from "@chakra-ui/react";
import { useFetcher, useNavigate } from "@remix-run/react";
import { useEffect, useMemo, useRef, useState } from "react";
import { ValidatedForm, useControlField, useField } from "remix-validated-form";
diff --git a/apps/carbon/app/modules/users/ui/Employees/BulkEditPermissionsForm/BulkEditPermissionsForm.tsx b/apps/carbon/app/modules/users/ui/Employees/BulkEditPermissionsForm/BulkEditPermissionsForm.tsx
index 05c38a13f2..feb00e518d 100644
--- a/apps/carbon/app/modules/users/ui/Employees/BulkEditPermissionsForm/BulkEditPermissionsForm.tsx
+++ b/apps/carbon/app/modules/users/ui/Employees/BulkEditPermissionsForm/BulkEditPermissionsForm.tsx
@@ -10,7 +10,6 @@ import {
VStack,
useMount,
} from "@carbon/react";
-import { FormLabel } from "@chakra-ui/react";
import { useFetcher } from "@remix-run/react";
import { useEffect, useState } from "react";
import { ValidatedForm } from "remix-validated-form";
@@ -112,7 +111,9 @@ const BulkEditPermissions = ({
label="Users to Update"
/>
- <FormLabel>Permissions</FormLabel>
+ <label className="block text-sm font-medium leading-none">
+ Permissions
+ </label>
{Object.entries(permissions)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([module, data], index) => (
diff --git a/apps/carbon/app/modules/users/ui/Employees/EmployeePermissionsForm/EmployeePermissionsForm.tsx b/apps/carbon/app/modules/users/ui/Employees/EmployeePermissionsForm/EmployeePermissionsForm.tsx
index dfd6bb11ba..650e10c694 100644
--- a/apps/carbon/app/modules/users/ui/Employees/EmployeePermissionsForm/EmployeePermissionsForm.tsx
+++ b/apps/carbon/app/modules/users/ui/Employees/EmployeePermissionsForm/EmployeePermissionsForm.tsx
@@ -9,7 +9,6 @@ import {
HStack,
VStack,
} from "@carbon/react";
-import { FormLabel } from "@chakra-ui/react";
import { useNavigate } from "@remix-run/react";
import { useState } from "react";
import { ValidatedForm } from "remix-validated-form";
@@ -77,7 +76,9 @@ const EmployeePermissionsForm = ({
options={employeeTypeOptions}
placeholder="Select Employee Type"
/>
- <FormLabel>Permissions</FormLabel>
+ <label className="block text-sm font-medium leading-none">
+ Permissions
+ </label>
{Object.entries(permissions)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(([module, data], index) => (
diff --git a/apps/carbon/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx b/apps/carbon/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx
index 663f468ed4..dfd82af481 100644
--- a/apps/carbon/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx
+++ b/apps/carbon/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx
@@ -1,4 +1,7 @@
import {
+ FormControl,
+ FormErrorMessage,
+ FormLabel,
HStack,
Input,
Modal,
@@ -10,12 +13,7 @@ import {
Select,
VStack,
} from "@carbon/react";
-import {
- FormControl,
- FormErrorMessage,
- FormLabel,
- Grid,
-} from "@chakra-ui/react";
+import { Grid } from "@chakra-ui/react";
import { useFetcher, useNavigate } from "@remix-run/react";
import { useEffect, useMemo, useRef, useState } from "react";
import { ValidatedForm, useControlField, useField } from "remix-validated-form";
diff --git a/packages/react/src/Form/FormControl.tsx b/packages/react/src/Form/FormControl.tsx
new file mode 100644
index 0000000000..27748a2e1a
--- /dev/null
+++ b/packages/react/src/Form/FormControl.tsx
@@ -0,0 +1,270 @@
+import type { ComponentProps, ForwardedRef } from "react";
+import {
+ createContext,
+ forwardRef,
+ useCallback,
+ useContext,
+ useId,
+ useState,
+} from "react";
+import { cn } from "~/utils/cn";
+import { dataAttr } from "~/utils/dom";
+import { mergeRefs } from "~/utils/react";
+
+export interface FormControlOptions {
+ /**
+ * If `true`, the form control will be required. This has 2 side effects:
+ * - The `FormLabel` will show a required indicator
+ * - The form element (e.g, Input) will have `aria-required` set to `true`
+ *
+ * @default false
+ */
+ isRequired?: boolean;
+ /**
+ * If `true`, the form control will be disabled. This has 2 side effects:
+ * - The `FormLabel` will have `data-disabled` attribute
+ * - The form element (e.g, Input) will be disabled
+ *
+ * @default false
+ */
+ isDisabled?: boolean;
+ /**
+ * If `true`, the form control will be invalid. This has 2 side effects:
+ * - The `FormLabel` and `FormErrorIcon` will have `data-invalid` set to `true`
+ * - The form element (e.g, Input) will have `aria-invalid` set to `true`
+ *
+ * @default false
+ */
+ isInvalid?: boolean;
+ /**
+ * If `true`, the form control will be readonly
+ *
+ * @default false
+ */
+ isReadOnly?: boolean;
+}
+
+interface FormControlContextType extends FormControlOptions {
+ /**
+ * The label text used to inform users as to what information is
+ * requested for a text field.
+ */
+ label?: string;
+ /**
+ * The custom `id` to use for the form control. This is passed directly to the form element (e.g, Input).
+ * - The form element (e.g. Input) gets the `id`
+ * - The form label id: `form-label-${id}`
+ * - The form error text id: `form-error-text-${id}`
+ * - The form helper text id: `form-helper-text-${id}`
+ */
+ id?: string;
+}
+
+type FormControlProviderContext = Omit<
+ ReturnType<typeof useFormControlProvider>,
+ "getRootProps" | "htmlProps"
+>;
+
+const FormControlContext = createContext<FormControlProviderContext | null>(
+ null
+);
+
+export const useFormControlContext = () => {
+ const ctx = useContext(FormControlContext);
+
+ if (!ctx) {
+ throw Error("useFormControlContext() must be used inside of a FormControl");
+ }
+
+ return ctx;
+};
+
+function useFormControlProvider(props: FormControlContextType) {
+ const {
+ id: idProp,
+ isRequired,
+ isInvalid,
+ isDisabled,
+ isReadOnly,
+ ...htmlProps
+ } = props;
+
+ // Generate all the required ids
+ const uuid = useId();
+ const id = idProp || `field-${uuid}`;
+
+ const labelId = `${id}-label`;
+ const feedbackId = `${id}-feedback`;
+ const helpTextId = `${id}-helptext`;
+
+ /**
+ * Track whether the `FormErrorMessage` has been rendered.
+ * We use this to append its id the `aria-describedby` of the `input`.
+ */
+ const [hasFeedbackText, setHasFeedbackText] = useState(false);
+
+ /**
+ * Track whether the `FormHelperText` has been rendered.
+ * We use this to append its id the `aria-describedby` of the `input`.
+ */
+ const [hasHelpText, setHasHelpText] = useState(false);
+
+ // Track whether the form element (e.g, `input`) has focus.
+ const [isFocused, setFocus] = useState(false);
+
+ const getHelpTextProps = useCallback(
+ (
+ props: ComponentProps<"div"> & FormControlOptions = {},
+ forwardedRef: ForwardedRef<HTMLDivElement> | null = null
+ ) => ({
+ id: helpTextId,
+ ...props,
+ /**
+ * Notify the field context when the help text is rendered on screen,
+ * so we can apply the correct `aria-describedby` to the field (e.g. input, textarea).
+ */
+ ref: mergeRefs(forwardedRef, (node) => {
+ if (!node) return;
+ setHasHelpText(true);
+ }),
+ }),
+ [helpTextId]
+ );
+
+ const getLabelProps = useCallback(
+ (
+ props: ComponentProps<"label"> & FormControlOptions = {},
+ forwardedRef: ForwardedRef<HTMLLabelElement> | null = null
+ ) => ({
+ ...props,
+ ref: forwardedRef,
+ "data-focus": dataAttr(isFocused),
+ "data-disabled": dataAttr(isDisabled),
+ "data-invalid": dataAttr(isInvalid),
+ "data-readonly": dataAttr(isReadOnly),
+ id: props.id !== undefined ? props.id : labelId,
+ htmlFor: id,
+ }),
+ [id, isDisabled, isFocused, isInvalid, isReadOnly, labelId]
+ );
+
+ const getErrorMessageProps = useCallback(
+ (
+ props: ComponentProps<"div"> & FormControlOptions = {},
+ forwardedRef: ForwardedRef<HTMLDivElement> | null = null
+ ) => ({
+ id: feedbackId,
+ ...props,
+ /**
+ * Notify the field context when the error message is rendered on screen,
+ * so we can apply the correct `aria-describedby` to the field (e.g. input, textarea).
+ */
+ ref: mergeRefs(forwardedRef, (node) => {
+ if (!node) return;
+ setHasFeedbackText(true);
+ }),
+ "aria-live": "polite" as const,
+ }),
+ [feedbackId]
+ );
+
+ const getRootProps = useCallback(
+ (
+ props: FormControlOptions = {},
+ forwardedRef: ForwardedRef<HTMLDivElement> | null = null
+ ) => ({
+ ...props,
+ ...htmlProps,
+ ref: forwardedRef,
+ role: "group",
+ "data-focus": dataAttr(isFocused),
+ "data-disabled": dataAttr(isDisabled),
+ "data-invalid": dataAttr(isInvalid),
+ "data-readonly": dataAttr(isReadOnly),
+ }),
+ [htmlProps, isDisabled, isFocused, isInvalid, isReadOnly]
+ );
+
+ return {
+ isRequired: !!isRequired,
+ isInvalid: !!isInvalid,
+ isReadOnly: !!isReadOnly,
+ isDisabled: !!isDisabled,
+ isFocused: !!isFocused,
+ onFocus: () => setFocus(true),
+ onBlur: () => setFocus(false),
+ hasFeedbackText,
+ setHasFeedbackText,
+ hasHelpText,
+ setHasHelpText,
+ id,
+ labelId,
+ feedbackId,
+ helpTextId,
+ htmlProps,
+ getHelpTextProps,
+ getErrorMessageProps,
+ getRootProps,
+ getLabelProps,
+ };
+}
+
+export interface FormControlProps
+ extends ComponentProps<"div">,
+ FormControlContextType {}
+
+/**
+ * FormControl provides context such as
+ * `isInvalid`, `isDisabled`, and `isRequired` to form elements.
+ *
+ * This is commonly used in form elements such as `input`,
+ * `select`, `textarea`, etc.
+ *
+ */
+export const FormControl = forwardRef<HTMLDivElement, FormControlProps>(
+ function FormControl(props, ref) {
+ const {
+ getRootProps,
+ htmlProps: _,
+ ...context
+ } = useFormControlProvider(props);
+
+ return (
+ <FormControlContext.Provider value={context}>
+ <div
+ {...getRootProps({}, ref)}
+ className={cn("flex flex-col w-full space-y-2", props.className)}
+ />
+ </FormControlContext.Provider>
+ );
+ }
+);
+
+FormControl.displayName = "FormControl";
+
+export interface FormHelperTextProps extends ComponentProps<"div"> {}
+
+/**
+ * FormHelperText
+ *
+ * Assistive component that conveys additional guidance
+ * about the field, such as how it will be used and what
+ * types in values should be provided.
+ */
+export const FormHelperText = forwardRef<HTMLDivElement, FormHelperTextProps>(
+ function FormHelperText(props, ref) {
+ const field = useFormControlContext();
+
+ return (
+ <div
+ {...field?.getHelpTextProps(props, ref)}
+ className={cn(
+ "font-normal text-sm text-muted-foreground",
+ props.className
+ )}
+ />
+ );
+ }
+);
+
+FormHelperText.displayName = "FormHelperText";
diff --git a/packages/react/src/Form/FormError.tsx b/packages/react/src/Form/FormError.tsx
new file mode 100644
index 0000000000..0068141a8a
--- /dev/null
+++ b/packages/react/src/Form/FormError.tsx
@@ -0,0 +1,34 @@
+import type { ComponentProps } from "react";
+import { forwardRef } from "react";
+import { cn } from "~/utils/cn";
+import type { FormControlOptions } from "./FormControl";
+import { useFormControlContext } from "./FormControl";
+
+export interface FormErrorMessageProps
+ extends ComponentProps<"div">,
+ FormControlOptions {}
+
+/**
+ * Used to provide feedback about an invalid input,
+ * and suggest clear instructions on how to fix it.
+ */
+export const FormErrorMessage = forwardRef<
+ HTMLDivElement,
+ FormErrorMessageProps
+>((props, ref) => {
+ const field = useFormControlContext();
+
+ if (!field?.isInvalid) return null;
+
+ return (
+ <div
+ {...field?.getErrorMessageProps(props, ref)}
+ className={cn(
+ "text-destructive text-sm font-medium leading-none",
+ props.className
+ )}
+ />
+ );
+});
+
+FormErrorMessage.displayName = "FormErrorMessage";
diff --git a/packages/react/src/Form/FormLabel.tsx b/packages/react/src/Form/FormLabel.tsx
new file mode 100644
index 0000000000..8d77ee023e
--- /dev/null
+++ b/packages/react/src/Form/FormLabel.tsx
@@ -0,0 +1,42 @@
+import type { ComponentPropsWithoutRef, ElementRef } from "react";
+import { forwardRef } from "react";
+import { cn } from "~/utils/cn";
+import type { FormControlOptions } from "./FormControl";
+import { useFormControlContext } from "./FormControl";
+
+import * as LabelPrimitive from "@radix-ui/react-label";
+import type { VariantProps } from "class-variance-authority";
+import { cva } from "class-variance-authority";
+
+const labelVariants = cva(
+ "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70"
+);
+
+export interface FormLabelProps
+ extends ComponentPropsWithoutRef<typeof LabelPrimitive.Root>,
+ VariantProps<typeof labelVariants>,
+ FormControlOptions {}
+
+export const FormLabel = forwardRef<
+ ElementRef<typeof LabelPrimitive.Root>,
+ FormLabelProps
+>((props, ref) => {
+ const { className, children, ...rest } = props;
+
+ const field = useFormControlContext();
+ const labelProps = field?.getLabelProps(rest, ref) ?? { ref, ...rest };
+
+ return (
+ <LabelPrimitive.Root
+ {...labelProps}
+ ref={ref}
+ className={cn(labelVariants(), className)}
+ {...props}
+ >
+ {children}
+ {field?.isRequired && <span className="text-destructive"> *</span>}
+ </LabelPrimitive.Root>
+ );
+});
+
+FormLabel.displayName = "FormLabel";
diff --git a/packages/react/src/Form/index.ts b/packages/react/src/Form/index.ts
new file mode 100644
index 0000000000..4ffdc790a4
--- /dev/null
+++ b/packages/react/src/Form/index.ts
@@ -0,0 +1,5 @@
+import { FormControl, FormHelperText } from "./FormControl";
+import { FormErrorMessage } from "./FormError";
+import { FormLabel } from "./FormLabel";
+
+export { FormControl, FormErrorMessage, FormHelperText, FormLabel };
diff --git a/packages/react/src/Form/useFormControl.tsx b/packages/react/src/Form/useFormControl.tsx
new file mode 100644
index 0000000000..f0bcc7dbd5
--- /dev/null
+++ b/packages/react/src/Form/useFormControl.tsx
@@ -0,0 +1,89 @@
+import { ariaAttr } from "~/utils/dom";
+import { callAllHandlers } from "~/utils/function";
+import type { FormControlOptions } from "./FormControl";
+import { useFormControlContext } from "./FormControl";
+
+export interface UseFormControlProps<T extends HTMLElement>
+ extends FormControlOptions {
+ id?: string;
+ onFocus?: React.FocusEventHandler<T>;
+ onBlur?: React.FocusEventHandler<T>;
+ disabled?: boolean;
+ readOnly?: boolean;
+ required?: boolean;
+ "aria-describedby"?: string;
+}
+
+/**
+ * React hook that provides the props that should be spread on to
+ * input fields (`input`, `select`, `textarea`, etc.).
+ *
+ * It provides a convenient way to control a form fields, validation
+ * and helper text.
+ *
+ * @internal
+ */
+export function useFormControl<T extends HTMLElement>(
+ props: UseFormControlProps<T>
+) {
+ const { isDisabled, isInvalid, isReadOnly, isRequired, ...rest } =
+ useFormControlProps(props);
+
+ return {
+ ...rest,
+ disabled: isDisabled,
+ readOnly: isReadOnly,
+ required: isRequired,
+ "aria-invalid": ariaAttr(isInvalid),
+ "aria-required": ariaAttr(isRequired),
+ "aria-readonly": ariaAttr(isReadOnly),
+ };
+}
+
+/**
+ * @internal
+ */
+export function useFormControlProps<T extends HTMLElement>(
+ props: UseFormControlProps<T>
+) {
+ const field = useFormControlContext();
+
+ const {
+ id,
+ disabled,
+ readOnly,
+ required,
+ isRequired,
+ isInvalid,
+ isReadOnly,
+ isDisabled,
+ onFocus,
+ onBlur,
+ ...rest
+ } = props;
+
+ const labelIds: string[] = props["aria-describedby"]
+ ? [props["aria-describedby"]]
+ : [];
+
+ // Error message must be described first in all scenarios.
+ if (field?.hasFeedbackText && field?.isInvalid) {
+ labelIds.push(field.feedbackId);
+ }
+
+ if (field?.hasHelpText) {
+ labelIds.push(field.helpTextId);
+ }
+
+ return {
+ ...rest,
+ "aria-describedby": labelIds.join(" ") || undefined,
+ id: id ?? field?.id,
+ isDisabled: disabled ?? isDisabled ?? field?.isDisabled,
+ isReadOnly: readOnly ?? isReadOnly ?? field?.isReadOnly,
+ isRequired: required ?? isRequired ?? field?.isRequired,
+ isInvalid: isInvalid ?? field?.isInvalid,
+ onFocus: callAllHandlers(field?.onFocus, onFocus),
+ onBlur: callAllHandlers(field?.onBlur, onBlur),
+ };
+}
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index 3ac4b4d6c5..6ea0524d1f 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -34,6 +34,12 @@ import {
} from "./Drawer";
import { Editor, useEditor } from "./Editor";
import { File } from "./File";
+import {
+ FormControl,
+ FormErrorMessage,
+ FormHelperText,
+ FormLabel,
+} from "./Form";
import { HStack } from "./HStack";
import { HTML } from "./HTML";
import { Heading } from "./Heading";
@@ -127,6 +133,10 @@ export {
DrawerTrigger,
Editor,
File,
+ FormControl,
+ FormErrorMessage,
+ FormHelperText,
+ FormLabel,
HStack,
HTML,
Heading,
diff --git a/packages/react/src/utils/dom.ts b/packages/react/src/utils/dom.ts
new file mode 100644
index 0000000000..9ba3fa2133
--- /dev/null
+++ b/packages/react/src/utils/dom.ts
@@ -0,0 +1,7 @@
+export type Booleanish = boolean | "true" | "false";
+
+export const dataAttr = (condition: boolean | undefined) =>
+ (condition ? "" : undefined) as Booleanish;
+
+export const ariaAttr = (condition: boolean | undefined) =>
+ condition ? true : undefined;
diff --git a/packages/react/src/utils/function.ts b/packages/react/src/utils/function.ts
new file mode 100644
index 0000000000..d98ee56e6c
--- /dev/null
+++ b/packages/react/src/utils/function.ts
@@ -0,0 +1,16 @@
+export type FunctionArguments<T extends Function> = T extends (
+ ...args: infer R
+) => any
+ ? R
+ : never;
+
+export function callAllHandlers<T extends (event: any) => void>(
+ ...fns: (T | undefined)[]
+) {
+ return function func(event: FunctionArguments<T>[0]) {
+ fns.some((fn) => {
+ fn?.(event);
+ return event?.defaultPrevented;
+ });
+ };
+}
diff --git a/packages/react/src/utils/react.ts b/packages/react/src/utils/react.ts
index a7104d7ea7..3df138ec0f 100644
--- a/packages/react/src/utils/react.ts
+++ b/packages/react/src/utils/react.ts
@@ -11,3 +11,37 @@ export function getValidChildren(children: React.ReactNode) {
isValidElement(child)
) as React.ReactElement[];
}
+
+export type Merge<T, P> = P & Omit<T, keyof P>;
+
+export type MaybeRenderProp<P> =
+ | React.ReactNode
+ | ((props: P) => React.ReactNode);
+
+export type ReactRef<T> = React.RefCallback<T> | React.MutableRefObject<T>;
+
+export function assignRef<T = any>(
+ ref: ReactRef<T> | null | undefined,
+ value: T
+) {
+ if (ref == null) return;
+
+ if (typeof ref === "function") {
+ ref(value);
+ return;
+ }
+
+ try {
+ ref.current = value;
+ } catch (error) {
+ throw new Error(`Cannot assign value '${value}' to ref '${ref}'`);
+ }
+}
+
+export function mergeRefs<T>(...refs: (ReactRef<T> | null | undefined)[]) {
+ return (node: T | null) => {
+ refs.forEach((ref) => {
+ assignRef(ref, node);
+ });
+ };
+}