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

Brad Barbin77a3e6e48cca
diff --git a/apps/carbon/app/components/Editable/EditableText.tsx b/apps/carbon/app/components/Editable/EditableText.tsx
index 9d57bec4a9..089d078017 100644
--- a/apps/carbon/app/components/Editable/EditableText.tsx
+++ b/apps/carbon/app/components/Editable/EditableText.tsx
@@ -1,5 +1,5 @@
/* eslint-disable react/display-name */
-import { Input } from "@chakra-ui/react";
+import { Input } from "@carbon/react";
import type { PostgrestSingleResponse } from "@supabase/supabase-js";
import type { FocusEvent, KeyboardEvent } from "react";
import type { EditableTableCellComponentProps } from "~/components/Editable";
@@ -58,9 +58,8 @@ const EditableText =
<Input
autoFocus
defaultValue={value as string}
- borderRadius="none"
+ className="border-0 rounded-none w-full"
size="sm"
- w="full"
onBlur={onBlur}
onKeyDown={onKeyDown}
/>
diff --git a/apps/carbon/app/components/Form/DatePicker.tsx b/apps/carbon/app/components/Form/DatePicker.tsx
index 548b221bfb..8f352f365c 100644
--- a/apps/carbon/app/components/Form/DatePicker.tsx
+++ b/apps/carbon/app/components/Form/DatePicker.tsx
@@ -1,4 +1,4 @@
-import { DatePicker as CarbonDatePicker } from "@carbon/react";
+import { DatePicker as DatePickerBase } from "@carbon/react";
import { FormControl, FormErrorMessage, FormLabel } from "@chakra-ui/react";
import type { CalendarDate } from "@internationalized/date";
import { parseDate } from "@internationalized/date";
@@ -22,7 +22,7 @@ const DatePicker = ({ name, label, isDisabled = false }: DatePickerProps) => {
<FormControl isInvalid={!!error}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
<input type="hidden" name={name} value={date?.toString()} />
- <CarbonDatePicker
+ <DatePickerBase
value={date}
//@ts-ignore
onChange={onChange}
diff --git a/apps/carbon/app/components/Form/Input.tsx b/apps/carbon/app/components/Form/Input.tsx
index 7db4d53a86..327b89d615 100644
--- a/apps/carbon/app/components/Form/Input.tsx
+++ b/apps/carbon/app/components/Form/Input.tsx
@@ -1,13 +1,15 @@
-import type { InputProps } from "@chakra-ui/react";
-import { InputLeftAddon } from "@chakra-ui/react";
+import type { InputProps } from "@carbon/react";
+import {
+ Input as InputBase,
+ InputGroup,
+ InputLeftAddon,
+ InputRightAddon,
+} from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
- Input as ChakraInput,
- InputGroup,
- InputRightAddon,
} from "@chakra-ui/react";
import { forwardRef } from "react";
import { useField } from "remix-validated-form";
@@ -28,17 +30,28 @@ const Input = forwardRef<HTMLInputElement, FormInputProps>(
return (
<FormControl isInvalid={!!error} isRequired={isRequired}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
- <InputGroup>
- {prefix && <InputLeftAddon children={prefix} />}
- <ChakraInput
+ {prefix || suffix ? (
+ <InputGroup>
+ {prefix && <InputLeftAddon children={prefix} />}
+ <InputBase
+ ref={ref}
+ {...getInputProps({
+ id: name,
+ ...rest,
+ })}
+ />
+ {suffix && <InputRightAddon children={suffix} />}
+ </InputGroup>
+ ) : (
+ <InputBase
ref={ref}
{...getInputProps({
id: name,
...rest,
})}
/>
- {suffix && <InputRightAddon children={suffix} />}
- </InputGroup>
+ )}
+
{helperText && <FormHelperText>{helperText}</FormHelperText>}
{error && <FormErrorMessage>{error}</FormErrorMessage>}
</FormControl>
diff --git a/apps/carbon/app/components/Form/InputControlled.tsx b/apps/carbon/app/components/Form/InputControlled.tsx
index bb3b3ba5a3..f7d12c426a 100644
--- a/apps/carbon/app/components/Form/InputControlled.tsx
+++ b/apps/carbon/app/components/Form/InputControlled.tsx
@@ -1,13 +1,15 @@
-import type { InputProps } from "@chakra-ui/react";
+import type { InputProps } from "@carbon/react";
+import {
+ Input as InputBase,
+ InputGroup,
+ InputLeftAddon,
+ InputRightAddon,
+} from "@carbon/react";
import {
FormControl,
FormErrorMessage,
FormHelperText,
FormLabel,
- Input as ChakraInput,
- InputGroup,
- InputLeftAddon,
- InputRightAddon,
} from "@chakra-ui/react";
import type { ChangeEvent } from "react";
import { forwardRef, useEffect } from "react";
@@ -58,7 +60,7 @@ const InputControlled = forwardRef<HTMLInputElement, FormInputControlledProps>(
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
<InputGroup>
{prefix && <InputLeftAddon children={prefix} />}
- <ChakraInput
+ <InputBase
ref={ref}
{...getInputProps({
id: name,
diff --git a/apps/carbon/app/components/Form/Password.tsx b/apps/carbon/app/components/Form/Password.tsx
index 10a67e0253..7b72ab1154 100644
--- a/apps/carbon/app/components/Form/Password.tsx
+++ b/apps/carbon/app/components/Form/Password.tsx
@@ -1,13 +1,11 @@
-import { IconButton } from "@carbon/react";
-import type { InputProps } from "@chakra-ui/react";
+import type { InputProps } from "@carbon/react";
import {
- FormControl,
- FormErrorMessage,
- FormLabel,
+ IconButton,
Input,
InputGroup,
InputRightElement,
-} from "@chakra-ui/react";
+} 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";
@@ -26,7 +24,7 @@ const Password = forwardRef<HTMLInputElement, FormPasswordProps>(
return (
<FormControl isInvalid={!!error} isRequired={isRequired}>
{label && <FormLabel htmlFor={name}>{label}</FormLabel>}
- <InputGroup size="md">
+ <InputGroup>
<Input
{...getInputProps({
id: name,
@@ -35,7 +33,7 @@ const Password = forwardRef<HTMLInputElement, FormPasswordProps>(
ref={ref}
type={passwordVisible ? "text" : "password"}
/>
- <InputRightElement width="2.75rem">
+ <InputRightElement className="w-[2.75rem]">
<IconButton
aria-label={passwordVisible ? "Show password" : "Hide password"}
icon={passwordVisible ? <BiShowAlt /> : <BiHide />}
diff --git a/apps/carbon/app/components/Form/RichText.tsx b/apps/carbon/app/components/Form/RichText.tsx
index c27b0f8871..9efe5aa8e0 100644
--- a/apps/carbon/app/components/Form/RichText.tsx
+++ b/apps/carbon/app/components/Form/RichText.tsx
@@ -1,6 +1,6 @@
import { Editor, useEditor } from "@carbon/react";
import type { BoxProps } from "@chakra-ui/react";
-import { FormControl, FormErrorMessage, Input } from "@chakra-ui/react";
+import { FormControl, FormErrorMessage } from "@chakra-ui/react";
import { useEffect } from "react";
import { useControlField, useField } from "remix-validated-form";
@@ -50,7 +50,7 @@ const RichText = ({ name, output = "html", ...props }: RichTextProps) => {
return (
<FormControl isInvalid={!!error}>
<Editor editor={editor} {...props} />
- <Input
+ <input
{...getInputProps({
// @ts-ignore
id: name,
diff --git a/apps/carbon/app/components/Form/Submit.tsx b/apps/carbon/app/components/Form/Submit.tsx
index b1ff21d7bf..2bc5ed63ff 100644
--- a/apps/carbon/app/components/Form/Submit.tsx
+++ b/apps/carbon/app/components/Form/Submit.tsx
@@ -13,7 +13,6 @@ export const Submit = ({
<Button
form={formId}
type="submit"
- size="md"
isLoading={isSubmitting}
isDisabled={isSubmitting}
{...props}
diff --git a/apps/carbon/app/components/Search/DebouncedInput/DebouncedInput.tsx b/apps/carbon/app/components/Search/DebouncedInput/DebouncedInput.tsx
index 233f7bb42d..47b9ef6962 100644
--- a/apps/carbon/app/components/Search/DebouncedInput/DebouncedInput.tsx
+++ b/apps/carbon/app/components/Search/DebouncedInput/DebouncedInput.tsx
@@ -1,6 +1,5 @@
-import { useDebounce } from "@carbon/react";
-import type { InputProps } from "@chakra-ui/react";
-import { Input } from "@chakra-ui/react";
+import type { InputProps } from "@carbon/react";
+import { Input, useDebounce } from "@carbon/react";
import { useEffect, useRef, useState } from "react";
import { useUrlParams } from "~/hooks";
diff --git a/apps/carbon/app/components/Search/Search/Search.tsx b/apps/carbon/app/components/Search/Search/Search.tsx
index 111bbcbf6d..5b22a654d9 100644
--- a/apps/carbon/app/components/Search/Search/Search.tsx
+++ b/apps/carbon/app/components/Search/Search/Search.tsx
@@ -1,6 +1,9 @@
import {
Button,
HStack,
+ Input,
+ InputGroup,
+ InputLeftElement,
Modal,
ModalBody,
ModalContent,
@@ -10,14 +13,7 @@ import {
useKeyboardShortcuts,
} from "@carbon/react";
import { clip } from "@carbon/utils";
-import {
- Icon,
- Input,
- InputGroup,
- InputLeftElement,
- Kbd,
- List,
-} from "@chakra-ui/react";
+import { Icon, Kbd, List } from "@chakra-ui/react";
import { Link, useNavigate } from "@remix-run/react";
import clsx from "clsx";
import { useCallback, useEffect, useRef, useState } from "react";
@@ -197,23 +193,18 @@ const SearchModal = ({
>
<ModalContent className="rounded-lg top-[10vh] translate-y-0 p-0">
<ModalBody className="max-h-[66vh]">
- <InputGroup size="lg">
- <InputLeftElement pointerEvents="none">
+ <InputGroup
+ size="lg"
+ className="ring-0 focus-within:ring-0 shadow-none"
+ >
+ <InputLeftElement className="pointer-events-none">
<FaSearch className="text-muted-foreground" />
</InputLeftElement>
<Input
placeholder="Search..."
value={query}
- variant="flushed"
onChange={(e) => setQuery(e.target.value)}
onKeyDown={onKeyDown}
- borderTopLeftRadius="lg"
- borderTopRightRadius="lg"
- _focus={{
- borderBottomColor: "transparent",
- boxShadow: "none",
- outline: "none",
- }}
/>
</InputGroup>
diff --git a/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx b/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx
index d1b03dff4f..6006b5431a 100644
--- a/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx
+++ b/apps/carbon/app/components/Selectors/UserSelect/components/Input.tsx
@@ -1,17 +1,16 @@
-import { HStack, IconButton } from "@carbon/react";
import {
- Avatar,
- AvatarGroup,
- Input,
+ HStack,
+ IconButton,
+ Input as InputBase,
InputGroup,
InputLeftElement,
InputRightElement,
- Spinner,
-} from "@chakra-ui/react";
+} from "@carbon/react";
+import { Avatar, AvatarGroup, Spinner } from "@chakra-ui/react";
import { MdOutlineClear } from "react-icons/md";
import useUserSelectContext from "../provider";
-const SelectInput = () => {
+const Input = () => {
const {
aria: { inputProps },
innerProps: { disabled, isMulti, placeholder, readOnly, testID },
@@ -28,7 +27,7 @@ const SelectInput = () => {
return (
<InputGroup>
{isMulti ? (
- <InputLeftElement left={2}>
+ <InputLeftElement>
<AvatarGroup size="xs" max={2}>
<Avatar />
<Avatar />
@@ -40,7 +39,7 @@ const SelectInput = () => {
</InputLeftElement>
)}
- <Input
+ <InputBase
{...inputProps}
id={`${instanceId}:UserSelectionInput:searchInput:${testID}`}
data-testid={`UserSelectionInput:searchInput:${testID}`}
@@ -54,11 +53,12 @@ const SelectInput = () => {
ref={inputRef}
type="text"
value={inputValue}
- pl={isMulti ? "3.175rem" : undefined}
- pr="2.5rem"
+
+ // pl={isMulti ? "3.175rem" : undefined}
+ // pr="2.5rem"
/>
- <InputRightElement w="auto">
+ <InputRightElement>
<HStack spacing={1} className="mr-2">
{loading && <Spinner size="sm" />}
{!loading && !disabled && inputValue.length > 0 && (
@@ -75,4 +75,4 @@ const SelectInput = () => {
);
};
-export default SelectInput;
+export default Input;
diff --git a/apps/carbon/app/components/Table/components/Filter/FilterRow.tsx b/apps/carbon/app/components/Table/components/Filter/FilterRow.tsx
index 38a42f0bb1..13fdc640c6 100644
--- a/apps/carbon/app/components/Table/components/Filter/FilterRow.tsx
+++ b/apps/carbon/app/components/Table/components/Filter/FilterRow.tsx
@@ -1,5 +1,5 @@
-import { IconButton, useDebounce } from "@carbon/react";
-import { Grid, Input, Select } from "@chakra-ui/react";
+import { IconButton, Input, useDebounce } from "@carbon/react";
+import { Grid, Select } from "@chakra-ui/react";
import { useEffect, useState } from "react";
import { IoMdClose } from "react-icons/io";
import { filterOperatorLabels } from "~/utils/query";
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 8d360e461e..aba122c144 100644
--- a/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountSubcategoryForm/AccountSubcategoryForm.tsx
+++ b/apps/carbon/app/modules/accounting/ui/AccountCategories/AccountSubcategoryForm/AccountSubcategoryForm.tsx
@@ -7,9 +7,10 @@ import {
DrawerHeader,
DrawerTitle,
HStack,
+ Input as InputBase,
VStack,
} from "@carbon/react";
-import { FormControl, FormLabel, Input as InputBase } from "@chakra-ui/react";
+import { FormControl, FormLabel } 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 34532b20f6..2b032d1656 100644
--- a/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx
+++ b/apps/carbon/app/modules/invoicing/ui/PurchaseInvoice/PurchaseInvoiceLineForm/PurchaseInvoiceLineForm.tsx
@@ -7,12 +7,12 @@ import {
DrawerHeader,
DrawerTitle,
HStack,
+ Input,
VStack,
} from "@carbon/react";
import {
FormControl,
FormLabel,
- Input,
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 0438c24ea3..dcfccc74cf 100644
--- a/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx
+++ b/apps/carbon/app/modules/purchasing/ui/PurchaseOrder/PurchaseOrderLineForm/PurchaseOrderLineForm.tsx
@@ -7,12 +7,12 @@ import {
DrawerHeader,
DrawerTitle,
HStack,
+ Input,
VStack,
} from "@carbon/react";
import {
FormControl,
FormLabel,
- Input,
NumberDecrementStepper,
NumberIncrementStepper,
NumberInput,
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 61b01446b3..62ba2cc7d6 100644
--- a/apps/carbon/app/modules/users/ui/Customers/CreateCustomerModal/CreateCustomerModal.tsx
+++ b/apps/carbon/app/modules/users/ui/Customers/CreateCustomerModal/CreateCustomerModal.tsx
@@ -1,5 +1,6 @@
import {
HStack,
+ Input,
Modal,
ModalBody,
ModalContent,
@@ -15,7 +16,6 @@ import {
FormErrorMessage,
FormLabel,
Grid,
- Input,
} from "@chakra-ui/react";
import { useFetcher, useNavigate } from "@remix-run/react";
import { useEffect, useMemo, useRef, useState } from "react";
@@ -87,28 +87,16 @@ const CreateCustomerModal = () => {
<>
<FormControl>
<FormLabel>Email</FormLabel>
- <Input
- isReadOnly
- value={contact?.email ?? ""}
- variant="filled"
- />
+ <Input isReadOnly value={contact?.email ?? ""} />
</FormControl>
<Grid templateColumns="1fr 1fr" gap={4}>
<FormControl>
<FormLabel>First Name</FormLabel>
- <Input
- isReadOnly
- value={contact?.firstName ?? ""}
- variant="filled"
- />
+ <Input isReadOnly value={contact?.firstName ?? ""} />
</FormControl>
<FormControl>
<FormLabel>Last Name</FormLabel>
- <Input
- isReadOnly
- value={contact?.lastName ?? ""}
- variant="filled"
- />
+ <Input isReadOnly value={contact?.lastName ?? ""} />
</FormControl>
</Grid>
</>
diff --git a/apps/carbon/app/modules/users/ui/Employees/CreateEmployeeModal/CreateEmployeeModal.tsx b/apps/carbon/app/modules/users/ui/Employees/CreateEmployeeModal/CreateEmployeeModal.tsx
index 3699fc7351..ffa706e1b4 100644
--- a/apps/carbon/app/modules/users/ui/Employees/CreateEmployeeModal/CreateEmployeeModal.tsx
+++ b/apps/carbon/app/modules/users/ui/Employees/CreateEmployeeModal/CreateEmployeeModal.tsx
@@ -12,20 +12,18 @@ import {
} from "@carbon/react";
import { Grid } from "@chakra-ui/react";
import { useFetcher, useNavigate } from "@remix-run/react";
-import type { PostgrestResponse } from "@supabase/supabase-js";
-import { useRef } from "react";
import { ValidatedForm } from "remix-validated-form";
import { Input, Select, Submit } from "~/components/Form";
-import type { EmployeeType } from "~/modules/users";
+import type { getEmployeeTypes } from "~/modules/users";
import { createEmployeeValidator } from "~/modules/users";
import type { Result } from "~/types";
import { path } from "~/utils/path";
const CreateEmployeeModal = () => {
- const initialFocusRef = useRef<HTMLInputElement>(null);
const navigate = useNavigate();
const formFetcher = useFetcher<Result>();
- const employeeTypeFetcher = useFetcher<PostgrestResponse<EmployeeType>>();
+ const employeeTypeFetcher =
+ useFetcher<Awaited<ReturnType<typeof getEmployeeTypes>>>();
useMount(() => {
employeeTypeFetcher.load(path.to.api.employeeTypes);
@@ -60,7 +58,7 @@ const CreateEmployeeModal = () => {
<ModalBody>
<VStack spacing={4}>
- <Input ref={initialFocusRef} name="email" label="Email" />
+ <Input name="email" label="Email" />
<Grid templateColumns="1fr 1fr" gap={4}>
<Input name="firstName" label="First Name" />
<Input name="lastName" label="Last Name" />
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 1926b49689..663f468ed4 100644
--- a/apps/carbon/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx
+++ b/apps/carbon/app/modules/users/ui/Suppliers/CreateSupplierModal/CreateSupplierModal.tsx
@@ -1,5 +1,6 @@
import {
HStack,
+ Input,
Modal,
ModalBody,
ModalContent,
@@ -14,7 +15,6 @@ import {
FormErrorMessage,
FormLabel,
Grid,
- Input,
} from "@chakra-ui/react";
import { useFetcher, useNavigate } from "@remix-run/react";
import { useEffect, useMemo, useRef, useState } from "react";
@@ -84,28 +84,16 @@ const CreateSupplierModal = () => {
<>
<FormControl>
<FormLabel>Email</FormLabel>
- <Input
- isReadOnly
- value={contact?.email ?? ""}
- variant="filled"
- />
+ <Input isReadOnly value={contact?.email ?? ""} />
</FormControl>
<Grid templateColumns="1fr 1fr" gap={4}>
<FormControl>
<FormLabel>First Name</FormLabel>
- <Input
- isReadOnly
- value={contact?.firstName ?? ""}
- variant="filled"
- />
+ <Input isReadOnly value={contact?.firstName ?? ""} />
</FormControl>
<FormControl>
<FormLabel>Last Name</FormLabel>
- <Input
- isReadOnly
- value={contact?.lastName ?? ""}
- variant="filled"
- />
+ <Input isReadOnly value={contact?.lastName ?? ""} />
</FormControl>
</Grid>
</>
diff --git a/apps/carbon/app/routes/_public+/forgot-password.tsx b/apps/carbon/app/routes/_public+/forgot-password.tsx
index f28265262d..9bf349f1e0 100644
--- a/apps/carbon/app/routes/_public+/forgot-password.tsx
+++ b/apps/carbon/app/routes/_public+/forgot-password.tsx
@@ -114,7 +114,9 @@ export default function ForgotPasswordRoute() {
</Alert>
)}
<Input name="email" label="Email" />
- <Submit className="w-full">Search</Submit>
+ <Submit size="lg" className="w-full">
+ Search
+ </Submit>
</VStack>
</ValidatedForm>
</div>
diff --git a/apps/carbon/app/routes/_public+/login.tsx b/apps/carbon/app/routes/_public+/login.tsx
index 7ef12ccfe8..0cf2f1c3ee 100644
--- a/apps/carbon/app/routes/_public+/login.tsx
+++ b/apps/carbon/app/routes/_public+/login.tsx
@@ -1,11 +1,4 @@
-import { VStack, useColor } from "@carbon/react";
-import {
- Alert,
- AlertIcon,
- AlertTitle,
- Image,
- useColorModeValue,
-} from "@chakra-ui/react";
+import { Alert, AlertIcon, AlertTitle, VStack } from "@chakra-ui/react";
import type {
ActionFunctionArgs,
LoaderFunctionArgs,
@@ -15,7 +8,7 @@ import { json, redirect } from "@remix-run/node";
import { Link, useActionData, useSearchParams } from "@remix-run/react";
import { ValidatedForm, validationError } from "remix-validated-form";
-import { Input, Password, Submit } from "~/components/Form";
+import { Hidden, Input, Password, Submit } from "~/components/Form";
import {
loginValidator,
signInWithEmail,
@@ -74,17 +67,18 @@ export default function LoginRoute() {
return (
<>
- <Image
- src={useColorModeValue(
- "/carbon-logo-dark.png",
- "/carbon-logo-light.png"
- )}
+ <img
+ src="/carbon-logo-dark.png"
+ alt="Carbon Logo"
+ className="block dark:hidden max-w-[100px] mb-3"
+ />
+ <img
+ src="/carbon-logo-light.png"
alt="Carbon Logo"
- maxW={100}
- marginBottom={3}
+ className="hidden dark:block max-w-[100px] mb-3"
/>
- <div className="rounded-lg bg-background shadow-lg p-8 w-[380px]">
+ <div className="rounded-lg bg-card shadow-lg p-8 w-[380px]">
<ValidatedForm
validator={loginValidator}
defaultValues={{ redirectTo }}
@@ -97,11 +91,14 @@ export default function LoginRoute() {
<AlertTitle>{result?.message}</AlertTitle>
</Alert>
)}
+
<Input name="email" label="Email" />
<Password name="password" label="Password" type="password" />
- <Input name="redirectTo" value={redirectTo} type="hidden" />
- <Submit className="w-full">Sign in</Submit>
- <Link to={path.to.forgotPassword} color={useColor("black")}>
+ <Hidden name="redirectTo" value={redirectTo} type="hidden" />
+ <Submit size="lg" className="w-full">
+ Sign in
+ </Submit>
+ <Link to={path.to.forgotPassword} className="text-foreground">
Forgot password?
</Link>
</VStack>
diff --git a/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx b/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx
index 112af65784..e081d329f1 100644
--- a/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx
+++ b/apps/carbon/app/routes/x+/resources+/ability.$abilityId.tsx
@@ -27,9 +27,15 @@ import {
} from "~/modules/resources";
import { requirePermissions } from "~/services/auth";
import { flash } from "~/services/session";
+import type { Handle } from "~/utils/handle";
import { path } from "~/utils/path";
import { error, success } from "~/utils/result";
+export const handle: Handle = {
+ breadcrumb: "Abilities",
+ to: path.to.abilities,
+};
+
export async function loader({ request, params }: LoaderFunctionArgs) {
const { client } = await requirePermissions(request, {
view: "resources",
@@ -175,9 +181,7 @@ export default function AbilitiesRoute() {
<Input
autoFocus
name="name"
- variant="unstyled"
- fontWeight="bold"
- fontSize="xl"
+ className="text-xl font-bold border-none shadow-none"
/>
<Submit>Save</Submit>
<IconButton
diff --git a/packages/react/src/Date/DatePicker.tsx b/packages/react/src/Date/DatePicker.tsx
index d87aa8d24c..50e8c02ec4 100644
--- a/packages/react/src/Date/DatePicker.tsx
+++ b/packages/react/src/Date/DatePicker.tsx
@@ -1,22 +1,16 @@
-import {
- Box,
- Icon,
- InputGroup,
- InputRightElement,
- useOutsideClick,
-} from "@chakra-ui/react";
import type { CalendarDate } from "@internationalized/date";
import { useDatePicker } from "@react-aria/datepicker";
import { useDatePickerState } from "@react-stately/datepicker";
import type { DatePickerProps } from "@react-types/datepicker";
import { useRef } from "react";
import { MdOutlineCalendarToday, MdOutlineDoNotDisturb } from "react-icons/md";
+import { InputGroup, InputRightElement } from "~/Input";
+import { useOutsideClick } from "~/hooks";
import { FieldButton } from "./components/Button";
import { Calendar } from "./components/Calendar";
import DateField from "./components/DateField";
import { Popover } from "./components/Popover";
-import { StyledField } from "./components/StyledField";
const DatePicker = (props: DatePickerProps<CalendarDate>) => {
const state = useDatePickerState({
@@ -33,33 +27,17 @@ const DatePicker = (props: DatePickerProps<CalendarDate>) => {
});
return (
- <Box
- position="relative"
- display="inline-flex"
- flexDirection="column"
- w="full"
- >
- <InputGroup
- {...groupProps}
- ref={ref}
- width="auto"
- display="inline-flex"
- w="full"
- >
- <StyledField pr="4.5rem">
+ <div className="relative inline-flex flex-col w-full">
+ <InputGroup {...groupProps} ref={ref} className="w-full inline-flex">
+ <div className="flex w-full px-4 py-2">
<DateField {...fieldProps} />
- {state.validationState === "invalid" && (
- <Icon
- as={MdOutlineDoNotDisturb}
- color="red.600"
- position="absolute"
- right="12"
- />
+ {state.isInvalid && (
+ <MdOutlineDoNotDisturb className="text-destructive-foreground aboslute right-[12px]" />
)}
- </StyledField>
+ </div>
<InputRightElement>
<FieldButton {...buttonProps} isPressed={state.isOpen}>
- <Icon as={MdOutlineCalendarToday} />
+ <MdOutlineCalendarToday />
</FieldButton>
</InputRightElement>
</InputGroup>
@@ -68,7 +46,7 @@ const DatePicker = (props: DatePickerProps<CalendarDate>) => {
<Calendar {...calendarProps} />
</Popover>
)}
- </Box>
+ </div>
);
};
diff --git a/packages/react/src/Date/DateRangePicker.tsx b/packages/react/src/Date/DateRangePicker.tsx
index 0c09950ae1..3104ec5c0f 100644
--- a/packages/react/src/Date/DateRangePicker.tsx
+++ b/packages/react/src/Date/DateRangePicker.tsx
@@ -1,15 +1,14 @@
-import { useRef } from "react";
-import { useDateRangePickerState } from "@react-stately/datepicker";
+import { InputGroup, InputRightElement } from "@carbon/react";
import { useDateRangePicker } from "@react-aria/datepicker";
-import { InputGroup, Box, Icon, InputRightElement } from "@chakra-ui/react";
+import { useDateRangePickerState } from "@react-stately/datepicker";
import type { DateRangePickerProps, DateValue } from "@react-types/datepicker";
-import { MdDoNotDisturbAlt, MdCalendarToday } from "react-icons/md";
+import { useRef } from "react";
+import { MdCalendarToday, MdOutlineDoNotDisturb } from "react-icons/md";
+import TimeField from "./TimePicker";
import { FieldButton } from "./components/Button";
-import { RangeCalendar } from "./components/RangeCalendar";
-import { Popover } from "./components/Popover";
-import { StyledField } from "./components/StyledField";
import DateField from "./components/DateField";
-import TimeField from "./TimePicker";
+import { Popover } from "./components/Popover";
+import { RangeCalendar } from "./components/RangeCalendar";
const DateRangePicker = (props: DateRangePickerProps<DateValue>) => {
const state = useDateRangePickerState({
@@ -27,26 +26,21 @@ const DateRangePicker = (props: DateRangePickerProps<DateValue>) => {
} = useDateRangePicker(props, state, ref);
return (
- <Box position="relative" display="inline-flex" flexDirection="column">
- <InputGroup {...groupProps} ref={ref} width="auto" display="inline-flex">
- <StyledField pr="5.5rem">
+ <div className="relative inline-flex flex-col w-full">
+ <InputGroup {...groupProps} ref={ref} className="w-full inline-flex">
+ <div className="flex w-auto px-4 py-2">
<DateField {...startFieldProps} />
- <Box as="span" aria-hidden="true" paddingX="2">
+ <span aria-hidden="true" className="px-2">
–
- </Box>
+ </span>
<DateField {...endFieldProps} />
- {state.validationState === "invalid" && (
- <Icon
- as={MdDoNotDisturbAlt}
- color="red.600"
- position="absolute"
- right="12"
- />
+ {state.isInvalid && (
+ <MdOutlineDoNotDisturb className="text-destructive-foreground aboslute right-[12px]" />
)}
- </StyledField>
+ </div>
<InputRightElement>
<FieldButton {...buttonProps} isPressed={state.isOpen}>
- <Icon as={MdCalendarToday} />
+ <MdCalendarToday />
</FieldButton>
</InputRightElement>
</InputGroup>
@@ -57,7 +51,7 @@ const DateRangePicker = (props: DateRangePickerProps<DateValue>) => {
onClose={() => state.setOpen(false)}
>
<RangeCalendar {...calendarProps} />
- <Box display="flex" gap="2">
+ <div className="flex gap-2">
<TimeField
label="Start time"
value={state.timeRange?.start || null}
@@ -68,10 +62,10 @@ const DateRangePicker = (props: DateRangePickerProps<DateValue>) => {
value={state.timeRange?.end || null}
onChange={(v) => state.setTime("end", v)}
/>
- </Box>
+ </div>
</Popover>
)}
- </Box>
+ </div>
);
};
diff --git a/packages/react/src/Date/DateTimePicker.tsx b/packages/react/src/Date/DateTimePicker.tsx
index c9b4b462ce..9f8ea30f5e 100644
--- a/packages/react/src/Date/DateTimePicker.tsx
+++ b/packages/react/src/Date/DateTimePicker.tsx
@@ -1,17 +1,16 @@
-import { useRef } from "react";
-import { useDatePickerState } from "@react-stately/datepicker";
+import { InputGroup, InputRightElement } from "@carbon/react";
+import type { DateValue } from "@internationalized/date";
import { useDatePicker } from "@react-aria/datepicker";
-import { MdOutlineCalendarToday, MdOutlineDoNotDisturb } from "react-icons/md";
-import { Box, Icon, InputGroup, InputRightElement } from "@chakra-ui/react";
+import { useDatePickerState } from "@react-stately/datepicker";
import type { DatePickerProps } from "@react-types/datepicker";
-import type { DateValue } from "@internationalized/date";
+import { useRef } from "react";
+import { MdOutlineCalendarToday, MdOutlineDoNotDisturb } from "react-icons/md";
+import TimeField from "./TimePicker";
import { FieldButton } from "./components/Button";
import { Calendar } from "./components/Calendar";
-import { Popover } from "./components/Popover";
-import { StyledField } from "./components/StyledField";
import DateField from "./components/DateField";
-import TimeField from "./TimePicker";
+import { Popover } from "./components/Popover";
const DateTimePicker = (props: DatePickerProps<DateValue>) => {
const state = useDatePickerState({
@@ -23,22 +22,22 @@ const DateTimePicker = (props: DatePickerProps<DateValue>) => {
useDatePicker(props, state, ref);
return (
- <Box position="relative" display="inline-flex" flexDirection="column">
- <InputGroup {...groupProps} ref={ref} width="auto" display="inline-flex">
- <StyledField pr="4.5rem">
+ <div className="relative inline-flex flex-col w-full">
+ <InputGroup
+ {...groupProps}
+ ref={ref}
+ width="auto"
+ className="w-full inline-flex"
+ >
+ <div className="flex w-full px-4 py-2">
<DateField {...fieldProps} />
- {state.validationState === "invalid" && (
- <Icon
- as={MdOutlineDoNotDisturb}
- color="red.600"
- position="absolute"
- right="12"
- />
+ {state.isInvalid && (
+ <MdOutlineDoNotDisturb className="text-destructive-foreground aboslute right-[12px]" />
)}
- </StyledField>
+ </div>
<InputRightElement>
<FieldButton {...buttonProps} isPressed={state.isOpen}>
- <Icon as={MdOutlineCalendarToday} />
+ <MdOutlineCalendarToday />
</FieldButton>
</InputRightElement>
</InputGroup>
@@ -56,7 +55,7 @@ const DateTimePicker = (props: DatePickerProps<DateValue>) => {
/>
</Popover>
)}
- </Box>
+ </div>
);
};
diff --git a/packages/react/src/Date/TimePicker.tsx b/packages/react/src/Date/TimePicker.tsx
index 5069d0f2bd..c9f2e027c9 100644
--- a/packages/react/src/Date/TimePicker.tsx
+++ b/packages/react/src/Date/TimePicker.tsx
@@ -1,11 +1,10 @@
-import { useRef } from "react";
+import { useTimeField } from "@react-aria/datepicker";
import { useLocale } from "@react-aria/i18n";
-import { useTimeFieldState } from "@react-stately/datepicker";
import type { TimeFieldStateOptions } from "@react-stately/datepicker";
-import { useTimeField } from "@react-aria/datepicker";
-import { Box } from "@chakra-ui/react";
+import { useTimeFieldState } from "@react-stately/datepicker";
+import { useRef } from "react";
+import { InputGroup } from "~/Input";
import { DateSegment } from "./components/DateSegment";
-import { StyledField } from "./components/StyledField";
const TimePicker = (
props: Omit<TimeFieldStateOptions, "locale" | "createCalendar">
@@ -20,13 +19,11 @@ const TimePicker = (
const { fieldProps } = useTimeField(props, state, ref);
return (
- <Box mt={2}>
- <StyledField {...fieldProps} ref={ref} pr={2}>
- {state.segments.map((segment, i) => (
- <DateSegment key={i} segment={segment} state={state} />
- ))}
- </StyledField>
- </Box>
+ <InputGroup {...fieldProps} ref={ref} className="px-4 py-2">
+ {state.segments.map((segment, i) => (
+ <DateSegment key={i} segment={segment} state={state} />
+ ))}
+ </InputGroup>
);
};
diff --git a/packages/react/src/Date/components/Button.tsx b/packages/react/src/Date/components/Button.tsx
index 2c1275aa94..9ae773db3c 100644
--- a/packages/react/src/Date/components/Button.tsx
+++ b/packages/react/src/Date/components/Button.tsx
@@ -1,8 +1,9 @@
-import type { IconButtonProps } from "@chakra-ui/react";
-import { Button, IconButton } from "@chakra-ui/react";
import { useButton } from "@react-aria/button";
import type { AriaButtonProps } from "@react-types/button";
import { useRef } from "react";
+import { Button } from "~/Button";
+import type { IconButtonProps } from "~/IconButton";
+import { IconButton } from "~/IconButton";
export const CalendarButton = (props: AriaButtonProps & IconButtonProps) => {
const ref = useRef<HTMLButtonElement>(null);
@@ -11,9 +12,8 @@ export const CalendarButton = (props: AriaButtonProps & IconButtonProps) => {
<IconButton
{...buttonProps}
ref={ref}
- size="sm"
- rounded="full"
variant="solid"
+ className="rounded-full"
{...props}
/>
);
@@ -27,14 +27,7 @@ export const FieldButton = (props: FieldButtonProps) => {
const ref = useRef<HTMLButtonElement>(null);
const { buttonProps } = useButton(props, ref);
return (
- <Button
- {...buttonProps}
- ref={ref}
- size="sm"
- h="1.75rem"
- mr="2"
- variant="solid"
- >
+ <Button {...buttonProps} ref={ref} isIcon variant="solid">
{props.children}
</Button>
);
diff --git a/packages/react/src/Date/components/CalendarCell.tsx b/packages/react/src/Date/components/CalendarCell.tsx
index 191cfe8288..4321e25575 100644
--- a/packages/react/src/Date/components/CalendarCell.tsx
+++ b/packages/react/src/Date/components/CalendarCell.tsx
@@ -1,4 +1,4 @@
-import { Button, Td } from "@chakra-ui/react";
+import { Td } from "@chakra-ui/react";
import type { CalendarDate } from "@internationalized/date";
import { isSameMonth } from "@internationalized/date";
import { useCalendarCell } from "@react-aria/calendar";
@@ -6,7 +6,9 @@ import type {
CalendarState,
RangeCalendarState,
} from "@react-stately/calendar";
+import clsx from "clsx";
import { useRef } from "react";
+import { Button } from "~/Button";
export const CalendarCell = ({
state,
@@ -36,22 +38,22 @@ export const CalendarCell = ({
<Button
{...buttonProps}
ref={ref}
- size="sm"
- colorScheme={isInvalid ? "red" : "brand"}
- variant={isSelected || isFocused ? "solid" : "ghost"}
- w={8}
- h={8}
- p={0}
- rounded="full"
- opacity={
- isOutsideMonth
+ className={clsx("w-8 h-8 rounded-full hover:bg-muted", {
+ "opacity-50 disabled:cursor-not-allowed": isDisabled,
+ "bg-destructive text-destructive-foreground": isInvalid,
+ "bg-muted": isFocused,
+ "bg-primary text-primary-foreground hover:bg-primary": isSelected,
+ "opacity-50 hover:bg-white focus:bg-white":
+ isInvalid || isDisabled || isUnavailable,
+ hidden: isOutsideMonth,
+ })}
+ variant={isSelected ? "primary" : "ghost"}
+ style={{
+ opacity: isOutsideMonth
? 0.25
: isInvalid || isDisabled || isUnavailable
? 0.5
- : 1
- }
- _hover={{
- bg: isSelected || isFocused ? undefined : "gray.200",
+ : 1,
}}
>
{formattedDate}
diff --git a/packages/react/src/Date/components/DateField.tsx b/packages/react/src/Date/components/DateField.tsx
index 7c64bcd256..dca9e34dc4 100644
--- a/packages/react/src/Date/components/DateField.tsx
+++ b/packages/react/src/Date/components/DateField.tsx
@@ -1,4 +1,3 @@
-import { Box } from "@chakra-ui/react";
import type { DateValue } from "@internationalized/date";
import { createCalendar } from "@internationalized/date";
import type { AriaDateFieldProps } from "@react-aria/datepicker";
@@ -20,11 +19,11 @@ const DateField = (props: AriaDateFieldProps<DateValue>) => {
const { fieldProps } = useDateField(props, state, ref);
return (
- <Box {...fieldProps} ref={ref} display="flex">
+ <div className="flex" {...fieldProps} ref={ref}>
{state.segments.map((segment, i) => (
<DateSegment key={i} segment={segment} state={state} />
))}
- </Box>
+ </div>
);
};
diff --git a/packages/react/src/Date/components/StyledField.tsx b/packages/react/src/Date/components/StyledField.tsx
deleted file mode 100644
index c049410b3b..0000000000
--- a/packages/react/src/Date/components/StyledField.tsx
+++ /dev/null
@@ -1,44 +0,0 @@
-import { Box, useColorModeValue } from "@chakra-ui/react";
-import { forwardRef, useId } from "react";
-import type { HTMLAttributes } from "react";
-
-export type StyledFieldProps = HTMLAttributes<HTMLElement> & {
- pr: number | string;
-};
-
-export const StyledField = forwardRef<HTMLDivElement, StyledFieldProps>(
- function Field({ children, ...otherProps }, ref) {
- const instanceId = useId();
- if ("id" in otherProps && otherProps.id) {
- otherProps.id = instanceId;
- }
- if ("aria-describedby" in otherProps && otherProps["aria-describedby"]) {
- otherProps["aria-describedby"] = instanceId;
- }
- return (
- <Box
- position="relative"
- border="1px solid"
- borderColor={useColorModeValue("gray.300", "gray.600")}
- rounded="md"
- transition="all 200ms"
- display="flex"
- alignItems="center"
- px="1"
- py=".4rem"
- w="full"
- _hover={{
- borderColor: "gray.400",
- }}
- _focusWithin={{
- borderColor: "gray.500",
- boxShadow: "0 0 0 2px var(--chakra-ui-focus-ring-color)",
- }}
- {...otherProps}
- ref={ref}
- >
- {children}
- </Box>
- );
- }
-);
diff --git a/packages/react/src/File.tsx b/packages/react/src/File.tsx
index edbd913811..9ff8ca7dfd 100644
--- a/packages/react/src/File.tsx
+++ b/packages/react/src/File.tsx
@@ -1,4 +1,3 @@
-import { Input, InputGroup } from "@chakra-ui/react";
import type { ChangeEvent, ComponentPropsWithoutRef } from "react";
import { useRef } from "react";
import { Button } from "~/Button";
@@ -12,8 +11,8 @@ const File = ({ accept, className, children, onChange }: FileProps) => {
const fileInputRef = useRef<HTMLInputElement>(null);
return (
- <InputGroup w="auto">
- <Input
+ <div className="flex w-auto">
+ <input
ref={fileInputRef}
type="file"
hidden
@@ -28,7 +27,7 @@ const File = ({ accept, className, children, onChange }: FileProps) => {
>
{children}
</Button>
- </InputGroup>
+ </div>
);
};
diff --git a/packages/react/src/Input.tsx b/packages/react/src/Input.tsx
new file mode 100644
index 0000000000..06c310a714
--- /dev/null
+++ b/packages/react/src/Input.tsx
@@ -0,0 +1,384 @@
+import type { VariantProps } from "class-variance-authority";
+import { cva } from "class-variance-authority";
+import type { HTMLAttributes, InputHTMLAttributes } from "react";
+import { cloneElement, createContext, forwardRef, useContext } from "react";
+
+import { cn } from "~/utils/cn";
+import { getValidChildren } from "~/utils/react";
+
+const InputGroupContext = createContext<boolean>(false);
+
+const inputGroupVariants = cva(
+ "flex relative w-full shadow-sm focus-within:outline-none ring-1 ring-border focus-within:ring-1 focus-within:ring-ring",
+ {
+ variants: {
+ size: {
+ lg: "h-12 rounded-lg",
+ md: "h-10 rounded-md",
+ sm: "h-8 rounded",
+ xs: "h-6 rounded",
+ },
+ isDisabled: {
+ true: "opacity-50 disabled:cursor-not-allowed",
+ false: "",
+ },
+ isInvalid: {
+ true: "ring-destructive focus-within:ring-offset-1 focus-within:ring-2 focus-within:ring-destructive",
+ false: "",
+ },
+ },
+ defaultVariants: {
+ size: "md",
+ isDisabled: false,
+ isInvalid: false,
+ },
+ }
+);
+
+export interface InputGroupProps
+ extends Omit<InputHTMLAttributes<HTMLInputElement>, "size">,
+ VariantProps<typeof inputVariants> {
+ isDisabled?: boolean;
+ isInvalid?: boolean;
+}
+
+const InputGroup = forwardRef<HTMLDivElement, InputGroupProps>(
+ (
+ {
+ className,
+ isInvalid = false,
+ isDisabled = false,
+ size,
+ children,
+ ...props
+ },
+ ref
+ ) => {
+ const validChildren = getValidChildren(children);
+
+ const _children = validChildren.map((child, index) =>
+ cloneElement(child, {
+ isFirstChild: index === 0,
+ isLastChild: index === validChildren.length - 1,
+ className: child.props.className,
+ childtype: child.type,
+ size,
+ isInvalid,
+ isDisabled,
+ key: index,
+ })
+ );
+
+ return (
+ <InputGroupContext.Provider value={true}>
+ <div
+ className={cn(
+ inputGroupVariants({
+ size,
+ isDisabled,
+ isInvalid,
+ className,
+ })
+ )}
+ {...props}
+ ref={ref}
+ >
+ {_children}
+ </div>
+ </InputGroupContext.Provider>
+ );
+ }
+);
+InputGroup.displayName = "InputGroup";
+
+const inputVariants = cva(
+ "flex h-9 w-full px-3 py-1 text-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground disabled:opacity-50 rounded-md ",
+ {
+ variants: {
+ size: {
+ lg: "h-12 rounded-lg px-4 text-lg",
+ md: "h-10 rounded-md px-4 text-base",
+ sm: "h-8 rounded px-3 text-sm",
+ xs: "h-6 rounded px-2 text-xs",
+ },
+ isInputGroup: {
+ true: "focus-visible:outline-none focus-visible:ring-0",
+ false:
+ "border border-input focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed shadow-sm",
+ },
+ isFirstChild: {
+ true: "",
+ false: "",
+ },
+ isLastChild: {
+ true: "",
+ false: "",
+ },
+ isInvalid: {
+ true: "",
+ false: "",
+ },
+ isReadOnly: {
+ true: "bg-muted text-muted-foreground",
+ false: "",
+ },
+ isDisabled: {
+ true: "bg-muted text-muted-foreground",
+ false: "",
+ },
+ },
+ compoundVariants: [
+ {
+ isFirstChild: false,
+ isInputGroup: true,
+ class: "rounded-l-none border-l-0",
+ },
+ {
+ isLastChild: false,
+ isInputGroup: true,
+ class: "rounded-r-none border-r-0",
+ },
+ {
+ isInvalid: true,
+ isInputGroup: false,
+ class: "border-2 border-destructive focus-visible:ring-destructive",
+ },
+ ],
+ defaultVariants: {
+ size: "md",
+ isInputGroup: false,
+ isFirstChild: false,
+ isLastChild: false,
+ isInvalid: false,
+ },
+ }
+);
+
+export interface InputProps
+ extends Omit<InputHTMLAttributes<HTMLInputElement>, "size">,
+ VariantProps<typeof inputVariants> {
+ isFirstChild?: boolean;
+ isLastChild?: boolean;
+ isInvalid?: boolean;
+ isDisabled?: boolean;
+ isReadOnly?: boolean;
+}
+
+const Input = forwardRef<HTMLInputElement, InputProps>(
+ (
+ {
+ className,
+ size,
+ isFirstChild = true,
+ isLastChild = true,
+ isInvalid = false,
+ isDisabled = false,
+ isReadOnly = false,
+ type,
+ ...props
+ },
+ ref
+ ) => {
+ const isInputGroup = useContext(InputGroupContext) ?? false;
+
+ return (
+ <input
+ className={cn(
+ inputVariants({
+ size,
+ className,
+ isInputGroup,
+ isFirstChild,
+ isLastChild,
+ isInvalid,
+ isReadOnly,
+ isDisabled,
+ })
+ )}
+ {...props}
+ disabled={isDisabled}
+ readOnly={isReadOnly}
+ ref={ref}
+ type={type}
+ />
+ );
+ }
+);
+Input.displayName = "Input";
+
+const inputAddonVariants = cva(
+ "flex items-center justify-center bg-muted text-muted-foreground border border-input",
+ {
+ variants: {
+ placement: {
+ left: "",
+ right: "",
+ },
+ size: {
+ lg: "h-12 px-3",
+ md: "h-10 px-3",
+ sm: "h-8 px-2",
+ xs: "h-6 px-1",
+ },
+ },
+ compoundVariants: [
+ {
+ placement: "left",
+ size: "lg",
+ class: "rounded-l-lg",
+ },
+ {
+ placement: "left",
+ size: "md",
+ class: "rounded-l-md",
+ },
+ {
+ placement: "left",
+ size: "sm",
+ class: "rounded-l",
+ },
+ {
+ placement: "left",
+ size: "xs",
+ class: "rounded-l",
+ },
+ {
+ placement: "right",
+ size: "lg",
+ class: "rounded-r-lg",
+ },
+ {
+ placement: "right",
+ size: "md",
+ class: "rounded-r-md",
+ },
+ {
+ placement: "right",
+ size: "sm",
+ class: "rounded-r",
+ },
+ {
+ placement: "right",
+ size: "xs",
+ class: "rounded-r",
+ },
+ ],
+ defaultVariants: {
+ size: "md",
+ },
+ }
+);
+
+export interface InputAddonProps
+ extends HTMLAttributes<HTMLDivElement>,
+ VariantProps<typeof inputAddonVariants> {}
+
+const InputLeftAddon = forwardRef<HTMLDivElement, InputAddonProps>(
+ ({ className, size, ...props }, ref) => {
+ return (
+ <div
+ className={cn(
+ inputAddonVariants({
+ placement: "left",
+ size,
+ className,
+ })
+ )}
+ {...props}
+ ref={ref}
+ />
+ );
+ }
+);
+InputLeftAddon.displayName = "InputLeftAddon";
+
+const InputRightAddon = forwardRef<HTMLDivElement, InputAddonProps>(
+ ({ className, size, ...props }, ref) => {
+ return (
+ <div
+ className={cn(
+ inputAddonVariants({
+ placement: "right",
+ size,
+ className,
+ })
+ )}
+ {...props}
+ ref={ref}
+ />
+ );
+ }
+);
+InputRightAddon.displayName = "InputRightAddon";
+
+const inputElementVariants = cva(
+ "flex w-auto h-full space-x-2 whitespace-nowrap items-center justify-center",
+ {
+ variants: {
+ size: {
+ lg: "h-12",
+ md: "h-10",
+ sm: "h-8",
+ xs: "h-6",
+ },
+ placement: {
+ left: "pl-2",
+ right: "pr-2",
+ },
+ },
+ }
+);
+
+export interface InputElementProps
+ extends HTMLAttributes<HTMLDivElement>,
+ VariantProps<typeof inputElementVariants> {
+ isFirstChild?: boolean;
+ isLastChild?: boolean;
+}
+
+const InputLeftElement = forwardRef<HTMLDivElement, InputElementProps>(
+ ({ className, size, isFirstChild, isLastChild, ...props }, ref) => {
+ return (
+ <div
+ className={cn(
+ inputElementVariants({
+ size,
+ placement: "left",
+ className,
+ })
+ )}
+ {...props}
+ ref={ref}
+ />
+ );
+ }
+);
+InputLeftElement.displayName = "InputLeftElement";
+
+const InputRightElement = forwardRef<HTMLDivElement, InputElementProps>(
+ ({ className, size, isFirstChild, isLastChild, ...props }, ref) => {
+ return (
+ <div
+ className={cn(
+ inputElementVariants({
+ size,
+ placement: "right",
+ className,
+ })
+ )}
+ {...props}
+ ref={ref}
+ />
+ );
+ }
+);
+InputRightElement.displayName = "InputRightElement";
+
+export {
+ Input,
+ InputGroup,
+ InputLeftAddon,
+ InputLeftElement,
+ InputRightAddon,
+ InputRightElement,
+};
diff --git a/packages/react/src/index.tsx b/packages/react/src/index.tsx
index b7f5afc550..3ac4b4d6c5 100644
--- a/packages/react/src/index.tsx
+++ b/packages/react/src/index.tsx
@@ -39,6 +39,15 @@ import { HTML } from "./HTML";
import { Heading } from "./Heading";
import { HoverCard, HoverCardContent, HoverCardTrigger } from "./HoverCard";
import { IconButton } from "./IconButton";
+import type { InputProps } from "./Input";
+import {
+ Input,
+ InputGroup,
+ InputLeftAddon,
+ InputLeftElement,
+ InputRightAddon,
+ InputRightElement,
+} from "./Input";
import { Loading } from "./Loading";
import { Menubar, MenubarItem, MenubarTrigger } from "./Menubar";
import {
@@ -125,6 +134,12 @@ export {
HoverCardContent,
HoverCardTrigger,
IconButton,
+ Input,
+ InputGroup,
+ InputLeftAddon,
+ InputLeftElement,
+ InputRightAddon,
+ InputRightElement,
Loading,
Menubar,
MenubarItem,
@@ -171,6 +186,7 @@ export {
export type {
ButtonProps,
GroupBase,
+ InputProps,
MultiValue,
OptionBase,
OptionProps,
diff --git a/packages/react/src/utils/react.ts b/packages/react/src/utils/react.ts
new file mode 100644
index 0000000000..a7104d7ea7
--- /dev/null
+++ b/packages/react/src/utils/react.ts
@@ -0,0 +1,13 @@
+import { Children, isValidElement } from "react";
+
+/**
+ * Gets only the valid children of a component,
+ * and ignores any nullish or falsy child.
+ *
+ * @param children the children
+ */
+export function getValidChildren(children: React.ReactNode) {
+ return Children.toArray(children).filter((child) =>
+ isValidElement(child)
+ ) as React.ReactElement[];
+}