Skip to content

Commit 0cb684f

Browse files
committed
chore: Update dependencies and refactor form components for improved functionality
- Upgraded @hookform/error-message to version 2.0.1 and react-hook-form to version 7.57.0 for better compatibility. - Updated @medusajs/ui to version 4.0.13 to leverage new features and fixes. - Refactored CurrencyInput, DatePickerInput, Input, SelectComponent, TextArea components to use forwardRef for better ref handling. - Enhanced FieldWrapper component to ensure proper label handling based on prop types.
1 parent 848207a commit 0cb684f

9 files changed

Lines changed: 52 additions & 56 deletions

File tree

packages/medusa-forms/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
"type-check": "tsc --noEmit"
3636
},
3737
"peerDependencies": {
38-
"react": "^18.3.0"
38+
"react": "^18.3.0 || ^19.0.0"
3939
},
4040
"dependencies": {
41-
"@hookform/error-message": "^2.0.0",
42-
"@medusajs/ui": "^4.0.0",
43-
"react-hook-form": "^7.50.0"
41+
"@hookform/error-message": "^2.0.1",
42+
"@medusajs/ui": "^4.0.13",
43+
"react-hook-form": "^7.57.0"
4444
},
4545
"devDependencies": {
4646
"@types/glob": "^8.1.0",
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { CurrencyInput as MedusaCurrencyInput } from '@medusajs/ui';
2-
import type * as React from 'react';
3-
import type { FC } from 'react';
2+
import { forwardRef } from 'react';
43
import { FieldWrapper } from './FieldWrapper';
54
import type { BasicFieldProps, MedusaCurrencyInputProps } from './types';
65

7-
export type CurrencyInputProps = MedusaCurrencyInputProps &
8-
BasicFieldProps & {
9-
ref?: React.Ref<HTMLInputElement>;
10-
};
6+
export type CurrencyInputProps = MedusaCurrencyInputProps & BasicFieldProps;
117

128
const Wrapper = FieldWrapper<CurrencyInputProps>;
139

14-
export const CurrencyInput: FC<CurrencyInputProps> = ({ ref, ...props }) => (
10+
export const CurrencyInput = forwardRef<HTMLInputElement, CurrencyInputProps>((props, ref) => (
1511
<Wrapper {...props}>{(inputProps) => <MedusaCurrencyInput {...inputProps} ref={ref} />}</Wrapper>
16-
);
12+
));
13+
14+
CurrencyInput.displayName = 'CurrencyInput';
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import { DatePicker } from '@medusajs/ui';
2-
import type * as React from 'react';
3-
import type { FC } from 'react';
2+
import { forwardRef } from 'react';
43
import { FieldWrapper } from './FieldWrapper';
54
import type { BasicFieldProps, DatePickerProps as MedusaDatePickerProps } from './types';
65

7-
export type DatePickerProps = MedusaDatePickerProps &
8-
BasicFieldProps & {
9-
ref?: React.Ref<HTMLInputElement>;
10-
};
6+
export type DatePickerProps = MedusaDatePickerProps & BasicFieldProps;
117

128
const Wrapper = FieldWrapper<DatePickerProps>;
139

14-
export const DatePickerInput: FC<DatePickerProps> = ({ ref, ...props }) => {
10+
export const DatePickerInput = forwardRef<HTMLInputElement, DatePickerProps>((props, ref) => {
1511
return <Wrapper {...props}>{(inputProps) => <DatePicker {...{ ...inputProps, ref }} />}</Wrapper>;
16-
};
12+
});
13+
14+
DatePickerInput.displayName = 'DatePickerInput';

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export const FieldWrapper = <T,>({
1717
}: FieldWrapperProps<T>) => (
1818
<div className={wrapperClassName}>
1919
{label && (
20-
<Label htmlFor={name} tooltip={labelTooltip} className={labelClassName}>
20+
<Label
21+
htmlFor={typeof name === 'string' ? name : undefined}
22+
tooltip={typeof labelTooltip === 'string' ? labelTooltip : undefined}
23+
className={labelClassName}
24+
>
2125
{label}
2226
</Label>
2327
)}
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { Input as MedusaInput } from '@medusajs/ui';
2-
import type * as React from 'react';
2+
import { forwardRef } from 'react';
33
import { FieldWrapper } from './FieldWrapper';
44
import type { BasicFieldProps, MedusaInputProps } from './types';
55

6-
export type InputProps = MedusaInputProps &
7-
BasicFieldProps & {
8-
ref?: React.Ref<HTMLInputElement>;
9-
};
6+
export type InputProps = MedusaInputProps & BasicFieldProps;
107

118
const Wrapper = FieldWrapper<InputProps>;
129

13-
export const Input: React.FC<InputProps> = ({ ref, ...props }) => (
10+
export const Input = forwardRef<HTMLInputElement, InputProps>((props, ref) => (
1411
<Wrapper {...props}>{(inputProps) => <MedusaInput {...inputProps} ref={ref} />}</Wrapper>
15-
);
12+
));
13+
14+
Input.displayName = 'Input';

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
import { Select as MedusaSelect } from '@medusajs/ui';
2-
import type * as React from 'react';
2+
import { forwardRef } from 'react';
33
import { FieldWrapper } from './FieldWrapper';
44
import type { BasicFieldProps, SelectProps as MedusaSelectProps } from './types';
55

6-
export type SelectProps = MedusaSelectProps &
7-
BasicFieldProps & {
8-
ref?: React.Ref<unknown>;
9-
};
6+
export type SelectProps = MedusaSelectProps & BasicFieldProps;
107

118
const Wrapper = FieldWrapper<SelectProps>;
129

13-
const SelectComponent: React.FC<SelectProps> = ({ ref, ...props }) => {
10+
const SelectComponent = forwardRef<unknown, SelectProps>((props, ref) => {
1411
return (
1512
<Wrapper {...props}>
1613
{(inputProps) => <MedusaSelect {...{ ...inputProps, ref }}>{props.children}</MedusaSelect>}
1714
</Wrapper>
1815
);
19-
};
16+
});
17+
18+
SelectComponent.displayName = 'Select';
2019

2120
type SelectComponent = typeof SelectComponent & {
2221
Trigger: typeof MedusaSelect.Trigger;
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { Textarea } from '@medusajs/ui';
2-
import type * as React from 'react';
2+
import { forwardRef } from 'react';
33
import { FieldWrapper } from './FieldWrapper';
44
import type { BasicFieldProps, TextAreaProps as MedusaTextAreaProps } from './types';
55

6-
export type TextAreaProps = MedusaTextAreaProps &
7-
BasicFieldProps & {
8-
ref?: React.Ref<HTMLTextAreaElement>;
9-
};
6+
export type TextAreaProps = MedusaTextAreaProps & BasicFieldProps;
107

118
const Wrapper = FieldWrapper<TextAreaProps>;
129

13-
export const TextArea: React.FC<TextAreaProps> = ({ ref, ...props }) => (
10+
export const TextArea = forwardRef<HTMLTextAreaElement, TextAreaProps>((props, ref) => (
1411
<Wrapper {...props}>{(inputProps) => <Textarea {...inputProps} ref={ref} />}</Wrapper>
15-
);
12+
));
13+
14+
TextArea.displayName = 'TextArea';

packages/medusa-forms/src/ui/types.d.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { RefAttributes } from 'react';
1+
import type { ReactNode, RefAttributes } from 'react';
22
import type { Props, SelectInstance } from 'react-select';
33
import type { CreatableProps } from 'react-select/creatable';
44

@@ -22,14 +22,13 @@ export type TextAreaProps = Omit<
2222
> &
2323
React.RefAttributes<HTMLTextAreaElement>;
2424

25-
interface RawCurrencyInputProps
26-
extends Omit<React.ComponentPropsWithoutRef<typeof Primitive>, 'prefix' | 'suffix' | 'size'>,
27-
VariantProps<typeof currencyInputVariants> {
25+
export type MedusaCurrencyInputProps = Omit<React.InputHTMLAttributes<HTMLInputElement>, 'defaultValue' | 'step'> & {
2826
symbol: string;
2927
code: string;
30-
}
31-
32-
export type MedusaCurrencyInputProps = RawCurrencyInputProps & React.RefAttributes<HTMLInputElement>;
28+
size?: 'small' | 'base';
29+
defaultValue?: string | number;
30+
step?: number;
31+
};
3332

3433
export type MedusaInputProps = React.InputHTMLAttributes<HTMLInputElement> & {
3534
size?: 'small' | 'base';

yarn.lock

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,7 +1360,7 @@ __metadata:
13601360
languageName: node
13611361
linkType: hard
13621362

1363-
"@hookform/error-message@npm:^2.0.0":
1363+
"@hookform/error-message@npm:^2.0.0, @hookform/error-message@npm:^2.0.1":
13641364
version: 2.0.1
13651365
resolution: "@hookform/error-message@npm:2.0.1"
13661366
peerDependencies:
@@ -1853,8 +1853,8 @@ __metadata:
18531853
version: 0.0.0-use.local
18541854
resolution: "@lambdacurry/medusa-forms@workspace:packages/medusa-forms"
18551855
dependencies:
1856-
"@hookform/error-message": "npm:^2.0.0"
1857-
"@medusajs/ui": "npm:^4.0.0"
1856+
"@hookform/error-message": "npm:^2.0.1"
1857+
"@medusajs/ui": "npm:^4.0.13"
18581858
"@types/glob": "npm:^8.1.0"
18591859
"@types/react": "npm:^19.0.0"
18601860
"@typescript-eslint/eslint-plugin": "npm:^6.21.0"
@@ -1863,14 +1863,14 @@ __metadata:
18631863
autoprefixer: "npm:^10.4.20"
18641864
glob: "npm:^11.0.0"
18651865
react: "npm:^19.0.0"
1866-
react-hook-form: "npm:^7.50.0"
1866+
react-hook-form: "npm:^7.57.0"
18671867
tailwindcss: "npm:^4.0.0"
18681868
typescript: "npm:^5.7.2"
18691869
vite: "npm:^5.4.11"
18701870
vite-plugin-dts: "npm:^4.4.0"
18711871
vite-tsconfig-paths: "npm:^5.1.4"
18721872
peerDependencies:
1873-
react: ^18.3.0
1873+
react: ^18.3.0 || ^19.0.0
18741874
languageName: unknown
18751875
linkType: soft
18761876

@@ -1921,7 +1921,7 @@ __metadata:
19211921
languageName: node
19221922
linkType: hard
19231923

1924-
"@medusajs/ui@npm:^4.0.0":
1924+
"@medusajs/ui@npm:^4.0.13":
19251925
version: 4.0.13
19261926
resolution: "@medusajs/ui@npm:4.0.13"
19271927
dependencies:
@@ -12333,7 +12333,7 @@ __metadata:
1233312333
languageName: node
1233412334
linkType: hard
1233512335

12336-
"react-hook-form@npm:^7.50.0, react-hook-form@npm:^7.51.0, react-hook-form@npm:^7.53.1":
12336+
"react-hook-form@npm:^7.51.0, react-hook-form@npm:^7.53.1, react-hook-form@npm:^7.57.0":
1233712337
version: 7.57.0
1233812338
resolution: "react-hook-form@npm:7.57.0"
1233912339
peerDependencies:

0 commit comments

Comments
 (0)