Skip to content

Commit 706a6ef

Browse files
committed
refactor: Update controlled components to use consistent prop types
- Renamed internal prop types to Controlled*Props for ControlledCheckbox, ControlledCurrencyInput, ControlledDatePicker, ControlledInput, ControlledSelect, and ControlledTextArea for clarity and consistency. - Updated import statements for UI components to align with new prop type names. - Enhanced type definitions to improve type safety and maintainability across controlled components.
1 parent d003476 commit 706a6ef

15 files changed

Lines changed: 75 additions & 38 deletions

packages/medusa-forms/src/controlled/ControlledCheckbox.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ import {
88
} from 'react-hook-form';
99
import { FieldCheckbox, type FieldCheckboxProps } from '../ui/FieldCheckbox';
1010

11-
type Props<T extends FieldValues> = Omit<FieldCheckboxProps, 'name'> &
11+
export type ControlledCheckboxProps<T extends FieldValues> = Omit<FieldCheckboxProps, 'name'> &
1212
Omit<ControllerProps, 'render'> & {
1313
name: Path<T>;
1414
rules?: Omit<RegisterOptions<T, Path<T>>, 'disabled' | 'valueAsNumber' | 'valueAsDate' | 'setValueAs'>;
1515
};
1616

17-
export const ControlledCheckbox = <T extends FieldValues>({ name, rules, onChange, ...props }: Props<T>) => {
17+
export const ControlledCheckbox = <T extends FieldValues>({
18+
name,
19+
rules,
20+
onChange,
21+
...props
22+
}: ControlledCheckboxProps<T>) => {
1823
const {
1924
control,
2025
formState: { errors },

packages/medusa-forms/src/controlled/ControlledCurrencyInput.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ import {
77
type RegisterOptions,
88
useFormContext,
99
} from 'react-hook-form';
10-
import { CurrencyInput, type Props as CurrencyInputProps } from '../ui/CurrencyInput';
10+
import { CurrencyInput, type CurrencyInputProps } from '../ui/CurrencyInput';
1111

12-
type Props<T extends FieldValues> = CurrencyInputProps &
12+
export type ControlledCurrencyInputProps<T extends FieldValues> = CurrencyInputProps &
1313
Omit<ControllerProps, 'render' | 'control'> & {
1414
name: Path<T>;
1515
};
1616

17-
export const ControlledCurrencyInput = <T extends FieldValues>({ name, rules, ...props }: Props<T>) => {
17+
export const ControlledCurrencyInput = <T extends FieldValues>({
18+
name,
19+
rules,
20+
...props
21+
}: ControlledCurrencyInputProps<T>) => {
1822
const { control } = useFormContext<T>();
1923

2024
return (

packages/medusa-forms/src/controlled/ControlledDatePicker.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ import {
66
type RegisterOptions,
77
useFormContext,
88
} from 'react-hook-form';
9-
import { DatePickerInput, type Props as DatePickerProps } from '../ui/DatePicker';
9+
import { DatePickerInput, type DatePickerProps } from '../ui/DatePicker';
1010

11-
type Props<T extends FieldValues> = DatePickerProps &
11+
export type ControlledDatePickerProps<T extends FieldValues> = DatePickerProps &
1212
Omit<ControllerProps, 'render' | 'control'> & {
1313
name: Path<T>;
1414
};
1515

16-
export const ControlledDatePicker = <T extends FieldValues>({ name, rules, ...props }: Props<T>) => {
16+
export const ControlledDatePicker = <T extends FieldValues>({
17+
name,
18+
rules,
19+
...props
20+
}: ControlledDatePickerProps<T>) => {
1721
const { control } = useFormContext<T>();
1822
return (
1923
<Controller<T>

packages/medusa-forms/src/controlled/ControlledInput.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ import {
77
type RegisterOptions,
88
useFormContext,
99
} from 'react-hook-form';
10-
import { Input, type Props as InputProps } from '../ui/Input';
10+
import { Input, type InputProps } from '../ui/Input';
1111

12-
type Props<T extends FieldValues> = InputProps &
12+
export type ControlledInputProps<T extends FieldValues> = InputProps &
1313
Omit<ControllerProps, 'render'> & {
1414
name: Path<T>;
1515
rules?: Omit<RegisterOptions<T, Path<T>>, 'disabled' | 'valueAsNumber' | 'valueAsDate' | 'setValueAs'>;
1616
} & ComponentProps<typeof Input> &
1717
Omit<ControllerProps<T>, 'render'>;
1818

19-
export const ControlledInput = <T extends FieldValues>({ name, rules, onChange, ...props }: Props<T>) => {
19+
export const ControlledInput = <T extends FieldValues>({
20+
name,
21+
rules,
22+
onChange,
23+
...props
24+
}: ControlledInputProps<T>) => {
2025
const {
2126
control,
2227
formState: { errors },

packages/medusa-forms/src/controlled/ControlledSelect.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import {
88
type RegisterOptions,
99
useFormContext,
1010
} from 'react-hook-form';
11-
import { Select, type Props as SelectProps } from '../ui/Select';
11+
import { Select, type SelectProps } from '../ui/Select';
1212

13-
type Props<T extends FieldValues> = SelectProps &
13+
export type ControlledSelectProps<T extends FieldValues> = SelectProps &
1414
Omit<ControllerProps, 'render'> & {
1515
name: Path<T>;
1616
onBlur?: () => void;
@@ -34,7 +34,7 @@ export const ControlledSelect = <T extends FieldValues>({
3434
onChange,
3535
onBlur,
3636
...props
37-
}: Props<T>) => {
37+
}: ControlledSelectProps<T>) => {
3838
const { control } = useFormContext<T>();
3939
return (
4040
<Controller<T>

packages/medusa-forms/src/controlled/ControlledTextArea.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import {
77
type RegisterOptions,
88
useFormContext,
99
} from 'react-hook-form';
10-
import { TextArea, type Props as TextAreaProps } from '../ui/TextArea';
10+
import { TextArea, type TextAreaProps } from '../ui/TextArea';
1111

12-
type Props<T extends FieldValues> = TextAreaProps &
12+
export type ControlledTextAreaProps<T extends FieldValues> = TextAreaProps &
1313
Omit<ControllerProps, 'render'> & {
1414
name: Path<T>;
1515
rules?: RegisterOptions<T, Path<T>>;
1616
} & React.ComponentProps<typeof TextArea> &
1717
Omit<ControllerProps<T>, 'render'>;
1818

19-
export const ControlledTextArea = <T extends FieldValues>({ name, rules, ...props }: Props<T>) => {
19+
export const ControlledTextArea = <T extends FieldValues>({ name, rules, ...props }: ControlledTextAreaProps<T>) => {
2020
const { control } = useFormContext<T>();
2121
return (
2222
<Controller<T>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export * from './ControlledCheckbox';
2+
export * from './ControlledCurrencyInput';
3+
export * from './ControlledDatePicker';
4+
export * from './ControlledInput';
5+
export * from './ControlledSelect';
6+
export * from './ControlledTextArea';

packages/medusa-forms/src/ui/ColorInput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type * as React from 'react';
22
import { Input } from './Input';
33

4-
interface ColorInputProps {
4+
export interface ColorInputProps {
55
onChange: (color: string) => void;
66
selectedColor: string;
77
onKeyDown?: (e: React.KeyboardEvent) => void;

packages/medusa-forms/src/ui/CurrencyInput.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import type { FC } from 'react';
44
import { FieldWrapper } from './FieldWrapper';
55
import type { BasicFieldProps, MedusaCurrencyInputProps } from './types';
66

7-
export type Props = MedusaCurrencyInputProps &
7+
export type CurrencyInputProps = MedusaCurrencyInputProps &
88
BasicFieldProps & {
99
ref?: React.Ref<HTMLInputElement>;
1010
};
1111

12-
const Wrapper = FieldWrapper<Props>;
12+
const Wrapper = FieldWrapper<CurrencyInputProps>;
1313

14-
export const CurrencyInput: FC<Props> = ({ ref, ...props }) => (
14+
export const CurrencyInput: FC<CurrencyInputProps> = ({ ref, ...props }) => (
1515
<Wrapper {...props}>{(inputProps) => <MedusaCurrencyInput {...inputProps} ref={ref} />}</Wrapper>
1616
);

packages/medusa-forms/src/ui/DatePicker.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { DatePicker } from '@medusajs/ui';
22
import type * as React from 'react';
33
import type { FC } from 'react';
44
import { FieldWrapper } from './FieldWrapper';
5-
import type { BasicFieldProps, DatePickerProps } from './types';
5+
import type { BasicFieldProps, DatePickerProps as MedusaDatePickerProps } from './types';
66

7-
export type Props = DatePickerProps &
7+
export type DatePickerProps = MedusaDatePickerProps &
88
BasicFieldProps & {
99
ref?: React.Ref<HTMLInputElement>;
1010
};
1111

12-
const Wrapper = FieldWrapper<Props>;
12+
const Wrapper = FieldWrapper<DatePickerProps>;
1313

14-
export const DatePickerInput: FC<Props> = ({ ref, ...props }) => {
14+
export const DatePickerInput: FC<DatePickerProps> = ({ ref, ...props }) => {
1515
return <Wrapper {...props}>{(inputProps) => <DatePicker {...{ ...inputProps, ref }} />}</Wrapper>;
1616
};

0 commit comments

Comments
 (0)