Skip to content

Commit 2dc3e5b

Browse files
authored
Merge pull request #55 from lambda-curry/codegen-bot/add-custom-input-to-textfield
2 parents 1ddf1d2 + fd0254c commit 2dc3e5b

4 files changed

Lines changed: 829 additions & 794 deletions

File tree

packages/components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@lambdacurry/forms",
3-
"version": "0.15.0",
3+
"version": "0.15.1",
44
"type": "module",
55
"main": "./dist/index.js",
66
"types": "./dist/index.d.ts",

packages/components/src/remix-hook-form/text-field.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ export type TextFieldProps = Omit<BaseTextFieldProps, 'control'>;
88
export function TextField(props: TextFieldProps) {
99
const { control } = useRemixFormContext();
1010

11+
// Merge the provided components with the default form components
12+
const defaultComponents = {
13+
FormControl,
14+
FormLabel,
15+
FormDescription,
16+
FormMessage,
17+
};
18+
1119
const components = {
12-
FormControl: FormControl,
13-
FormLabel: FormLabel,
14-
FormDescription: FormDescription,
15-
FormMessage: FormMessage,
20+
...defaultComponents,
21+
...props.components,
1622
};
1723

1824
return <BaseTextField control={control} components={components} {...props} />;

packages/components/src/ui/text-field.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ export interface TextInputProps extends Omit<InputProps, 'prefix' | 'suffix'> {
5656
name: FieldPath<FieldValues>;
5757
label?: string;
5858
description?: string;
59-
components?: Partial<FieldComponents>;
59+
components?: Partial<FieldComponents> & {
60+
Input?: React.ComponentType<InputProps>;
61+
};
6062
prefix?: React.ReactNode;
6163
suffix?: React.ReactNode;
6264
className?: string;
@@ -73,6 +75,9 @@ export const TextField = ({
7375
suffix,
7476
...props
7577
}: TextInputProps) => {
78+
// Use the custom Input component if provided, otherwise use the default TextInput
79+
const InputComponent = components?.Input || TextInput;
80+
7681
return (
7782
<FormField
7883
control={control}
@@ -90,7 +95,7 @@ export const TextField = ({
9095
>
9196
{prefix && <FieldPrefix>{prefix}</FieldPrefix>}
9297
<FormControl Component={components?.FormControl}>
93-
<TextInput
98+
<InputComponent
9499
{...field}
95100
{...props}
96101
className={cn('focus-visible:ring-0 focus-visible:ring-offset-0 border-input', {

0 commit comments

Comments
 (0)