Skip to content

Commit

Permalink
[FEAT]: Allow custom submit button label
Browse files Browse the repository at this point in the history
  • Loading branch information
camin-mccluskey committed Nov 23, 2023
1 parent ebcc290 commit 320fc4e
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion examples/submitStepper/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion examples/submitStepper/src/form/StepThree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,14 @@ export default function StepThree({ data, onSubmit, reportValidity }: StepThreeP
<button type="button" onClick={() => append({ name: '', type: Animal.DOG })}>
Add a pet
</button>
<SubmitButton handleSubmit={handleSubmit} onSubmit={onSubmit} disabled={!isValid} />
<SubmitButton handleSubmit={handleSubmit} onSubmit={onSubmit} disabled={!isValid}>
<div style={{ display: 'flex', gap: '4px', alignItems: 'center' }}>
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24">
<path d="M20.285 2l-11.285 11.567-5.286-5.011-3.714 3.716 9 8.728 15-15.285z" />
</svg>
<span>Done</span>
</div>
</SubmitButton>
</form>
)
}
Expand Down
7 changes: 6 additions & 1 deletion examples/submitStepper/src/form/StepTwo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ export default function StepTwo({ data, onSubmit, reportValidity }: StepTwoProps
<label>Country Code</label>
<input type="text" {...register('address.countryCode')} />
<p style={{ fontSize: '10px', color: 'red' }}>{errors.address?.countryCode?.message}</p>
<SubmitButton handleSubmit={handleSubmit} onSubmit={onSubmit} disabled={!isValid} />
<SubmitButton
handleSubmit={handleSubmit}
onSubmit={onSubmit}
disabled={!isValid}
label="Next Step"
/>
</form>
)
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "react-hook-form-multistep",
"description": "Extensible multistep forms for React Hook Form.",
"version": "0.0.10",
"version": "0.0.11",
"private": false,
"author": {
"name": "Camin McCluskey",
Expand Down
4 changes: 3 additions & 1 deletion src/components/SubmitButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type { FormStepOnSubmit } from '~/types'
type SubmitButtonProps<StepFormData extends FieldValues> = {
label?: string
className?: string
children?: React.ReactNode
handleSubmit: UseFormHandleSubmit<StepFormData>
onSubmit: FormStepOnSubmit<StepFormData>
disabled: boolean
Expand All @@ -15,6 +16,7 @@ type SubmitButtonProps<StepFormData extends FieldValues> = {
export default function SubmitButton<StepFormData extends FieldValues>({
label = 'Next',
className,
children,
handleSubmit,
onSubmit,
disabled,
Expand All @@ -29,7 +31,7 @@ export default function SubmitButton<StepFormData extends FieldValues>({

return (
<button type="submit" className={className} disabled={disabled} ref={submitButtonRef}>
{label}
{children || label}
</button>
)
}

0 comments on commit 320fc4e

Please sign in to comment.