Skip to content

Commit 53df0e8

Browse files
committed
Enhance form configuration with optional default styles
- Updated the `initForm` function to conditionally inject default styles based on the new `useDefaultStyles` configuration option. - Added documentation for the `useDefaultStyles` property in the `FormConfig` interface, allowing users to customize styling behavior. These changes provide greater flexibility for users to manage form styling according to their needs.
1 parent 151bd91 commit 53df0e8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

packages/formspree-ajax/src/form.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ const injectDefaultStyles = (): void => {
422422
export const initForm = <T extends FieldValues = FieldValues>(
423423
config: FormConfig<T>
424424
): FormHandle => {
425-
injectDefaultStyles();
425+
if (config.useDefaultStyles !== false) {
426+
injectDefaultStyles();
427+
}
426428

427429
if (!config.formElement) {
428430
throw new Error('You must provide a `formElement` in the config');

packages/formspree-ajax/src/types.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,13 @@ export interface FormConfig<T extends FieldValues = FieldValues> {
144144
*/
145145
debug?: boolean;
146146

147+
/**
148+
* When true, injects default CSS styles for error messages, success banners,
149+
* invalid field borders, and the loading spinner. Set to `false` to provide
150+
* your own styles. Defaults to `true`.
151+
*/
152+
useDefaultStyles?: boolean;
153+
147154
/**
148155
* Callback invoked when the form is initialized.
149156
* @param context - The form context containing form element and configuration.

0 commit comments

Comments
 (0)