Skip to content
8 changes: 3 additions & 5 deletions apps/docs/src/medusa-forms/ControlledCheckbox.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
import React from 'react';
import { FormProvider, useForm } from 'react-hook-form';

// Regex patterns defined at top level for performance
const EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i;

const meta = {
title: 'Medusa Forms/Controlled Checkbox',
component: ControlledCheckbox,
parameters: {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {},
} satisfies Meta<typeof ControlledCheckbox>;

export default meta;
Expand Down Expand Up @@ -94,7 +92,7 @@ const RequiredValidationForm = () => {
});

const onSubmit = (data: any) => {
// Form data processed successfully
alert(`Form submitted with data: ${JSON.stringify(data, null, 2)}`);
};

return (
Expand Down Expand Up @@ -298,7 +296,7 @@ const CompleteFormExampleComponent = () => {
{...form.register('email', {
required: 'Email is required',
pattern: {
value: EMAIL_REGEX,
value: /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}$/i,
message: 'Invalid email address',
},
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const RequiredFieldValidationComponent = () => {
});

const onSubmit = (data: unknown) => {
// Form data processed successfully
alert(`Form submitted with data: ${JSON.stringify(data, null, 2)}`);
};

return (
Expand Down
29 changes: 9 additions & 20 deletions apps/docs/src/medusa-forms/ControlledTextArea.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const meta = {
layout: 'centered',
},
tags: ['autodocs'],
argTypes: {},
} satisfies Meta<typeof ControlledTextArea>;

export default meta;
Expand Down Expand Up @@ -128,7 +129,7 @@ const RequiredFieldForm = () => {
});

const onSubmit = (data: unknown) => {
// Form data processed successfully
alert(`Form submitted with data: ${JSON.stringify(data, null, 2)}`);
};

return (
Expand Down Expand Up @@ -242,7 +243,7 @@ const ValidationErrorForm = () => {
});

const onSubmit = (data: unknown) => {
// Form data processed successfully
alert(`Form submitted with data: ${JSON.stringify(data, null, 2)}`);
};

const hasError = !!form.formState.errors.message;
Expand Down Expand Up @@ -331,7 +332,7 @@ const ComprehensiveForm = () => {
});

const onSubmit = (data: unknown) => {
// Form data processed successfully
alert(`Comprehensive form submitted: ${JSON.stringify(data, null, 2)}`);
};

return (
Expand Down Expand Up @@ -380,33 +381,21 @@ const ComprehensiveForm = () => {
</Button>
</div>

<div className="mt-4 p-2 bg-gray-100 rounded">
<strong>Form Values:</strong>
<pre className="text-xs mt-2">{JSON.stringify(form.watch(), null, 2)}</pre>
<div className="text-sm text-gray-600">
<p>Form Status: {form.formState.isValid ? 'βœ… Valid' : '❌ Invalid'}</p>
<p>Errors: {Object.keys(form.formState.errors).length}</p>
</div>

{form.formState.isSubmitted && form.formState.isValid && (
<div className="p-4 bg-green-100 border border-green-400 text-green-700 rounded">
Form submitted successfully! Check the console for the data.
</div>
)}
</form>
</FormProvider>
);
};

export const ComprehensiveExample: Story = {
args: {
name: 'title',
label: 'Title',
placeholder: 'Enter a title...',
},
export const ComprehensiveFormExample: Story = {
render: () => <ComprehensiveForm />,
parameters: {
docs: {
description: {
story:
'A comprehensive form example showing multiple ControlledTextArea components with different validation rules and states.',
story: 'Complete form example with multiple text areas, validation, and form state management.',
},
},
},
Expand Down
37 changes: 36 additions & 1 deletion biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,40 @@
"useImportExtensions": "off"
}
}
}
},
"overrides": [
{
"include": ["apps/docs/**/*.stories.tsx", "apps/docs/**/*.stories.ts"],
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off",
"noUnusedImports": "off",
"noUnusedFunctionParameters": "off"
},
"performance": {
"useTopLevelRegex": "off"
}
}
}
},
{
"include": ["**/*.d.ts"],
"linter": {
"rules": {
"correctness": {
"noUnusedVariables": "off",
"noUnusedImports": "off"
},
"style": {
"noNamespace": "off",
"useImportType": "off"
},
"suspicious": {
"noEmptyInterface": "off"
}
}
}
}
]
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"clean": "find . -name '.turbo' -type d -prune -exec rm -rf {} + && find . -name 'node_modules' -type d -prune -exec rm -rf {} + && find . -name 'yarn.lock' -type f -delete",
"format-and-lint": "biome check .",
"format-and-lint:fix": "biome check . --write",
"biome:fix": "biome check . --write --unsafe",
"prerelease": "turbo run build",
"release": "changeset publish",
"build-storybook": "turbo run build-storybook"
Expand Down
4 changes: 3 additions & 1 deletion packages/medusa-forms/src/ui/FieldCheckbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ export const FieldCheckbox: React.FC<FieldCheckboxProps> = ({
{...fieldProps}
ref={ref}
checked={props.checked}
onChange={(e) => {}}
onChange={(_e) => {
// Handled by onCheckedChange
}}
Comment on lines +39 to +41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codegen-sh does this still work with onChange completely removed?

onCheckedChange={(checked) => {
onChange?.(checked);
}}
Expand Down
23 changes: 3 additions & 20 deletions packages/medusa-forms/src/ui/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,35 +61,18 @@ type DatePickerValueProps = {
className?: string;
modal?: boolean;
};

interface DatePickerProps
extends Omit<BaseDatePickerProps<CalendarDateTime | CalendarDate>, keyof DatePickerValueProps>,
DatePickerValueProps {}

// export type DatePickerProps = (
// | {
// mode?: 'single';
// presets?: DatePreset[];
// defaultValue?: Date;
// value?: Date;
// onChange?: (date: Date | null) => void;
// }
// | {
// mode: 'range';
// presets?: DateRangePreset[];
// defaultValue?: DateRange;
// value?: DateRange;
// onChange?: (dateRange: DateRange | null) => void;
// }
// ) &
// PickerProps;

export type SearchableSelectProps = Props<Option, IsMulti, Group> &
RefAttributes<SelectInstance<Option, IsMulti, Group>>;

export type CreatableSelectProps = CreatableProps<Option, IsMulti, Group> &
RefAttributes<SelectInstance<Option, IsMulti, Group>>;

interface SelectProps extends React.ComponentPropsWithRef {
interface SelectProps extends React.ComponentPropsWithRef<'select'> {
size?: 'base' | 'small';
children?: React.ReactNode;
value?: string;
Expand All @@ -98,7 +81,7 @@ interface SelectProps extends React.ComponentPropsWithRef {
open?: boolean;
defaultOpen?: boolean;
onOpenChange?(open: boolean): void;
dir?: Direction;
dir?: 'ltr' | 'rtl';
name?: string;
autoComplete?: string;
disabled?: boolean;
Expand Down
Loading