Skip to content

Commit bf5c98b

Browse files
committed
feat: Refactor form components in FormIntegrationExamples to use Button from @medusajs/ui
- Replaced native button elements with the Button component for improved styling and functionality. - Updated button properties to utilize isLoading and variant attributes for better user experience. - Ensured consistent usage of the Button component across different forms, enhancing code maintainability.
1 parent 0d48c37 commit bf5c98b

File tree

2 files changed

+27
-30
lines changed

2 files changed

+27
-30
lines changed

apps/docs/src/medusa-forms/FormIntegrationExamples.stories.tsx

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { ControlledDatePicker } from '@lambdacurry/medusa-forms/controlled/Contr
44
import { ControlledInput } from '@lambdacurry/medusa-forms/controlled/ControlledInput';
55
import { ControlledSelect } from '@lambdacurry/medusa-forms/controlled/ControlledSelect';
66
import { ControlledTextArea } from '@lambdacurry/medusa-forms/controlled/ControlledTextArea';
7+
import { Button } from '@medusajs/ui';
78
import type { Meta, StoryObj } from '@storybook/react-vite';
89
import { useState } from 'react';
910
import { FormProvider, useForm } from 'react-hook-form';
@@ -216,17 +217,15 @@ const CompleteRegistrationForm = () => {
216217

217218
{/* Submit Section */}
218219
<div className="pt-4 border-t">
219-
<button
220+
<Button
220221
type="submit"
221222
disabled={!isValid || isSubmitting}
222-
className={`w-full py-3 px-4 rounded-md font-medium transition-colors ${
223-
isValid && !isSubmitting
224-
? 'bg-blue-600 hover:bg-blue-700 text-white'
225-
: 'bg-gray-300 text-gray-500 cursor-not-allowed'
226-
}`}
223+
isLoading={isSubmitting}
224+
className="w-full"
225+
variant="primary"
227226
>
228227
{isSubmitting ? 'Creating Account...' : 'Create Account'}
229-
</button>
228+
</Button>
230229

231230
{submitResult && (
232231
<div className="mt-4 p-3 bg-green-100 border border-green-400 text-green-700 rounded">{submitResult}</div>
@@ -442,25 +441,19 @@ const ProductCreationForm = () => {
442441
{/* Submit Section */}
443442
<div className="pt-4 border-t">
444443
<div className="flex gap-4">
445-
<button
446-
type="button"
447-
className="flex-1 py-3 px-4 border border-gray-300 rounded-md font-medium text-gray-700 hover:bg-gray-50 transition-colors"
448-
onClick={() => form.reset()}
449-
>
444+
<Button type="button" variant="secondary" className="flex-1" onClick={() => form.reset()}>
450445
Reset Form
451-
</button>
446+
</Button>
452447

453-
<button
448+
<Button
454449
type="submit"
455450
disabled={!isValid || isSubmitting}
456-
className={`flex-1 py-3 px-4 rounded-md font-medium transition-colors ${
457-
isValid && !isSubmitting
458-
? 'bg-green-600 hover:bg-green-700 text-white'
459-
: 'bg-gray-300 text-gray-500 cursor-not-allowed'
460-
}`}
451+
isLoading={isSubmitting}
452+
variant="primary"
453+
className="flex-1"
461454
>
462455
{isSubmitting ? 'Creating Product...' : 'Create Product'}
463-
</button>
456+
</Button>
464457
</div>
465458

466459
{submitResult && (
@@ -651,17 +644,9 @@ export const FormValidationShowcase: Story = {
651644
/>
652645

653646
<div className="pt-4 border-t">
654-
<button
655-
type="button"
656-
disabled={!form.formState.isValid}
657-
className={`w-full py-2 px-4 rounded-md font-medium transition-colors ${
658-
form.formState.isValid
659-
? 'bg-blue-600 hover:bg-blue-700 text-white'
660-
: 'bg-gray-300 text-gray-500 cursor-not-allowed'
661-
}`}
662-
>
647+
<Button type="button" disabled={!form.formState.isValid} variant="primary" className="w-full">
663648
Submit (Validation Demo)
664-
</button>
649+
</Button>
665650
</div>
666651
</div>
667652
</FormProvider>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { Button as MedusaButton } from '@medusajs/ui';
2+
import type { ComponentPropsWithoutRef } from 'react';
3+
4+
export { MedusaButton as Button };
5+
6+
// Define ButtonProps based on Medusa UI Button component
7+
export interface ButtonProps extends ComponentPropsWithoutRef<'button'> {
8+
variant?: 'primary' | 'transparent' | 'secondary' | 'danger';
9+
size?: 'small' | 'base' | 'large' | 'xlarge';
10+
isLoading?: boolean;
11+
asChild?: boolean;
12+
}

0 commit comments

Comments
 (0)