Skip to content

Commit 8640c60

Browse files
author
LFRW2K\lecmil2
committed
[MISC] Updated types
1 parent 4fc99d1 commit 8640c60

File tree

1 file changed

+81
-102
lines changed

1 file changed

+81
-102
lines changed

packages/utils/src/types.ts

Lines changed: 81 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -223,51 +223,45 @@ export type FormValidation<T = any> = FieldValidation & {
223223
};
224224

225225
/** The properties that are passed to an `ErrorListTemplate` implementation */
226-
export type ErrorListProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
226+
export type ErrorListProps<
227+
T = any,
228+
S extends StrictRJSFSchema = RJSFSchema,
229+
F extends FormContextType = any
230+
> = RJSFBaseProps<T, S, F> & {
227231
/** The errorSchema constructed by `Form` */
228232
errorSchema: ErrorSchema<T>;
229233
/** An array of the errors */
230234
errors: RJSFValidationError[];
231235
/** The `formContext` object that was passed to `Form` */
232236
formContext?: F;
233-
/** The schema that was passed to `Form` */
234-
schema: S;
235-
/** The uiSchema that was passed to `Form` */
236-
uiSchema?: UiSchema<T, S, F>;
237-
/** The `registry` object */
238-
registry: Registry<T, S, F>;
239237
};
240238

241239
/** The properties that are passed to an `FieldErrorTemplate` implementation */
242-
export type FieldErrorProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
240+
export type FieldErrorProps<
241+
T = any,
242+
S extends StrictRJSFSchema = RJSFSchema,
243+
F extends FormContextType = any
244+
> = RJSFBaseProps<T, S, F> & {
243245
/** The errorSchema constructed by `Form` */
244246
errorSchema?: ErrorSchema<T>;
245247
/** An array of the errors */
246248
errors?: Array<string | ReactElement>;
247249
/** The tree of unique ids for every child field */
248250
idSchema: IdSchema<T>;
249-
/** The schema that was passed to field */
250-
schema: S;
251-
/** The uiSchema that was passed to field */
252-
uiSchema?: UiSchema<T, S, F>;
253-
/** The `registry` object */
254-
registry: Registry<T, S, F>;
255251
};
256252

257253
/** The properties that are passed to an `FieldHelpTemplate` implementation */
258-
export type FieldHelpProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
254+
export type FieldHelpProps<
255+
T = any,
256+
S extends StrictRJSFSchema = RJSFSchema,
257+
F extends FormContextType = any
258+
> = RJSFBaseProps<T, S, F> & {
259259
/** The help information to be rendered */
260260
help?: string | ReactElement;
261261
/** The tree of unique ids for every child field */
262262
idSchema: IdSchema<T>;
263-
/** The schema that was passed to field */
264-
schema: S;
265-
/** The uiSchema that was passed to field */
266-
uiSchema?: UiSchema<T, S, F>;
267263
/** Flag indicating whether there are errors associated with this field */
268264
hasErrors?: boolean;
269-
/** The `registry` object */
270-
registry: Registry<T, S, F>;
271265
};
272266

273267
/** The set of `Fields` stored in the `Registry` */
@@ -282,8 +276,17 @@ export type RegistryWidgetsType<T = any, S extends StrictRJSFSchema = RJSFSchema
282276
[name: string]: Widget<T, S, F>;
283277
};
284278

279+
export type RJSFBaseProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
280+
/** The schema object for the field being described */
281+
schema: S;
282+
/** The uiSchema object for this description field */
283+
uiSchema?: UiSchema<T, S, F>;
284+
/** The `registry` object */
285+
registry: Registry<T, S, F>;
286+
};
287+
285288
/** The set of RJSF templates that can be overridden by themes or users */
286-
export interface TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> {
289+
export type TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
287290
/** The template to use while rendering normal or fixed array fields */
288291
ArrayFieldTemplate: ComponentType<ArrayFieldTemplateProps<T, S, F>>;
289292
/** The template to use while rendering the description for an array field */
@@ -327,7 +330,10 @@ export interface TemplatesType<T = any, S extends StrictRJSFSchema = RJSFSchema,
327330
/** The template to use for the Remove button used for AdditionalProperties and Array items */
328331
RemoveButton: ComponentType<IconButtonProps<T, S, F>>;
329332
};
330-
}
333+
} & {
334+
/** Allow this to support any named `ComponentType` or an object of named `ComponentType`s */
335+
[key: string]: ComponentType<RJSFBaseProps<T, S, F>> | { [key: string]: ComponentType<RJSFBaseProps<T, S, F>> };
336+
};
331337

332338
/** The set of UiSchema options that can be set globally and used as fallbacks at an individual template, field or
333339
* widget level when no field-level value of the option is provided.
@@ -433,7 +439,11 @@ export type Field<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends Fo
433439
>;
434440

435441
/** The properties that are passed to a FieldTemplate implementation */
436-
export type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
442+
export type FieldTemplateProps<
443+
T = any,
444+
S extends StrictRJSFSchema = RJSFSchema,
445+
F extends FormContextType = any
446+
> = RJSFBaseProps<T, S, F> & {
437447
/** The id of the field in the hierarchy. You can use it to render a label targeting the wrapped widget */
438448
id: string;
439449
/** A string containing the base CSS classes, merged with any custom ones defined in your uiSchema */
@@ -474,10 +484,6 @@ export type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema,
474484
* you don't want to clutter the UI
475485
*/
476486
displayLabel?: boolean;
477-
/** The schema object for this field */
478-
schema: S;
479-
/** The uiSchema object for this field */
480-
uiSchema?: UiSchema<T, S, F>;
481487
/** The `formContext` object that was passed to `Form` */
482488
formContext?: F;
483489
/** The formData for this field */
@@ -488,50 +494,44 @@ export type FieldTemplateProps<T = any, S extends StrictRJSFSchema = RJSFSchema,
488494
onKeyChange: (value: string) => () => void;
489495
/** The property drop/removal event handler; Called when a field is removed in an additionalProperty context */
490496
onDropPropertyClick: (value: string) => () => void;
491-
/** The `registry` object */
492-
registry: Registry<T, S, F>;
493497
};
494498

495499
/** The properties that are passed to the `UnsupportedFieldTemplate` implementation */
496-
export type UnsupportedFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
497-
/** The schema object for this field */
498-
schema: S;
500+
export type UnsupportedFieldProps<
501+
T = any,
502+
S extends StrictRJSFSchema = RJSFSchema,
503+
F extends FormContextType = any
504+
> = RJSFBaseProps<T, S, F> & {
499505
/** The tree of unique ids for every child field */
500506
idSchema?: IdSchema<T>;
501507
/** The reason why the schema field has an unsupported type */
502508
reason: string;
503-
/** The `registry` object */
504-
registry: Registry<T, S, F>;
505509
};
506510

507511
/** The properties that are passed to a `TitleFieldTemplate` implementation */
508-
export type TitleFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
512+
export type TitleFieldProps<
513+
T = any,
514+
S extends StrictRJSFSchema = RJSFSchema,
515+
F extends FormContextType = any
516+
> = RJSFBaseProps<T, S, F> & {
509517
/** The id of the field title in the hierarchy */
510518
id: string;
511519
/** The title for the field being rendered */
512520
title: string;
513-
/** The schema object for the field being titled */
514-
schema: S;
515-
/** The uiSchema object for this title field */
516-
uiSchema?: UiSchema<T, S, F>;
517521
/** A boolean value stating if the field is required */
518522
required?: boolean;
519-
/** The `registry` object */
520-
registry: Registry<T, S, F>;
521523
};
522524

523525
/** The properties that are passed to a `DescriptionFieldTemplate` implementation */
524-
export type DescriptionFieldProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
526+
export type DescriptionFieldProps<
527+
T = any,
528+
S extends StrictRJSFSchema = RJSFSchema,
529+
F extends FormContextType = any
530+
> = RJSFBaseProps<T, S, F> & {
525531
/** The id of the field description in the hierarchy */
526532
id: string;
527-
/** The schema object for the field being described */
528-
schema: S;
529-
/** The uiSchema object for this description field */
530-
uiSchema?: UiSchema<T, S, F>;
531533
/** The description of the field being rendered */
532534
description: string | ReactElement;
533-
/** The `registry` object */
534-
registry: Registry<T, S, F>;
535535
};
536536

537537
/** The properties that are passed to a `ArrayFieldTitleTemplate` implementation */
@@ -563,7 +563,7 @@ export type ArrayFieldTemplateItemType<
563563
T = any,
564564
S extends StrictRJSFSchema = RJSFSchema,
565565
F extends FormContextType = any
566-
> = {
566+
> = RJSFBaseProps<T, S, F> & {
567567
/** The html for the item's content */
568568
children: ReactElement;
569569
/** The className string */
@@ -598,20 +598,14 @@ export type ArrayFieldTemplateItemType<
598598
readonly?: boolean;
599599
/** A stable, unique key for the array item */
600600
key: string;
601-
/** The schema object for this array item */
602-
schema: S;
603-
/** The uiSchema object for this array item */
604-
uiSchema?: UiSchema<T, S, F>;
605-
/** The `registry` object */
606-
registry: Registry<T, S, F>;
607601
};
608602

609603
/** The properties that are passed to an ArrayFieldTemplate implementation */
610604
export type ArrayFieldTemplateProps<
611605
T = any,
612606
S extends StrictRJSFSchema = RJSFSchema,
613607
F extends FormContextType = any
614-
> = {
608+
> = RJSFBaseProps<T, S, F> & {
615609
/** A boolean value stating whether new elements can be added to the array */
616610
canAdd?: boolean;
617611
/** The className string */
@@ -630,10 +624,6 @@ export type ArrayFieldTemplateProps<
630624
required?: boolean;
631625
/** A boolean value stating if the field is hiding its errors */
632626
hideError?: boolean;
633-
/** The schema object for this array */
634-
schema: S;
635-
/** The uiSchema object for this array field */
636-
uiSchema?: UiSchema<T, S, F>;
637627
/** A string value containing the title for the array */
638628
title: string;
639629
/** The `formContext` object that was passed to Form */
@@ -644,8 +634,6 @@ export type ArrayFieldTemplateProps<
644634
errorSchema?: ErrorSchema<T>;
645635
/** An array of strings listing all generated error messages from encountered errors for this widget */
646636
rawErrors?: string[];
647-
/** The `registry` object */
648-
registry: Registry<T, S, F>;
649637
};
650638

651639
/** The properties of each element in the ObjectFieldTemplateProps.properties array */
@@ -667,7 +655,7 @@ export type ObjectFieldTemplateProps<
667655
T = any,
668656
S extends StrictRJSFSchema = RJSFSchema,
669657
F extends FormContextType = any
670-
> = {
658+
> = RJSFBaseProps<T, S, F> & {
671659
/** A string value containing the title for the object */
672660
title: string;
673661
/** A string value containing the description for the object */
@@ -684,10 +672,6 @@ export type ObjectFieldTemplateProps<
684672
required?: boolean;
685673
/** A boolean value stating if the field is hiding its errors */
686674
hideError?: boolean;
687-
/** The schema object for this object */
688-
schema: S;
689-
/** The uiSchema object for this object field */
690-
uiSchema?: UiSchema<T, S, F>;
691675
/** An object containing the id for this object & ids for its properties */
692676
idSchema: IdSchema<T>;
693677
/** The optional validation errors in the form of an `ErrorSchema` */
@@ -696,33 +680,31 @@ export type ObjectFieldTemplateProps<
696680
formData?: T;
697681
/** The `formContext` object that was passed to Form */
698682
formContext?: F;
699-
/** The `registry` object */
700-
registry: Registry<T, S, F>;
701683
};
702684

703685
/** The properties that are passed to a WrapIfAdditionalTemplate implementation */
704686
export type WrapIfAdditionalTemplateProps<
705687
T = any,
706688
S extends StrictRJSFSchema = RJSFSchema,
707689
F extends FormContextType = any
708-
> = {
690+
> = RJSFBaseProps<T, S, F> & {
709691
/** The field or widget component instance for this field row */
710692
children: ReactNode;
711693
} & Pick<
712-
FieldTemplateProps<T, S, F>,
713-
| 'id'
714-
| 'classNames'
715-
| 'style'
716-
| 'label'
717-
| 'required'
718-
| 'readonly'
719-
| 'disabled'
720-
| 'schema'
721-
| 'uiSchema'
722-
| 'onKeyChange'
723-
| 'onDropPropertyClick'
724-
| 'registry'
725-
>;
694+
FieldTemplateProps<T, S, F>,
695+
| 'id'
696+
| 'classNames'
697+
| 'style'
698+
| 'label'
699+
| 'required'
700+
| 'readonly'
701+
| 'disabled'
702+
| 'schema'
703+
| 'uiSchema'
704+
| 'onKeyChange'
705+
| 'onDropPropertyClick'
706+
| 'registry'
707+
>;
726708

727709
/** The properties that are passed to a Widget implementation */
728710
export interface WidgetProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any>
@@ -793,7 +775,8 @@ export interface BaseInputTemplateProps<
793775
T = any,
794776
S extends StrictRJSFSchema = RJSFSchema,
795777
F extends FormContextType = any
796-
> extends WidgetProps<T, S, F> {
778+
> extends WidgetProps<T, S, F>,
779+
RJSFBaseProps<T, S, F> {
797780
/** A `BaseInputTemplate` implements a default `onChange` handler that it passes to the HTML input component to handle
798781
* the `ChangeEvent`. Sometimes a widget may need to handle the `ChangeEvent` using custom logic. If that is the case,
799782
* that widget should provide its own handler via this prop.
@@ -802,28 +785,24 @@ export interface BaseInputTemplateProps<
802785
}
803786

804787
/** The type that defines the props used by the Submit button */
805-
export type SubmitButtonProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F extends FormContextType = any> = {
806-
/** The uiSchema for this widget */
807-
uiSchema?: UiSchema<T, S, F>;
808-
/** The `registry` object */
809-
registry: Registry<T, S, F>;
810-
};
788+
export type SubmitButtonProps<
789+
T = any,
790+
S extends StrictRJSFSchema = RJSFSchema,
791+
F extends FormContextType = any
792+
> = RJSFBaseProps<T, S, F>;
811793

812794
/** The type that defines the props for an Icon button, extending from a basic HTML button attributes */
813795
export type IconButtonProps<
814796
T = any,
815797
S extends StrictRJSFSchema = RJSFSchema,
816798
F extends FormContextType = any
817-
> = ButtonHTMLAttributes<HTMLButtonElement> & {
818-
/** An alternative specification for the type of the icon button */
819-
iconType?: string;
820-
/** The name representation or actual react element implementation for the icon */
821-
icon?: string | ReactElement;
822-
/** The uiSchema for this widget */
823-
uiSchema?: UiSchema<T, S, F>;
824-
/** The `registry` object */
825-
registry: Registry<T, S, F>;
826-
};
799+
> = ButtonHTMLAttributes<HTMLButtonElement> &
800+
RJSFBaseProps<T, S, F> & {
801+
/** An alternative specification for the type of the icon button */
802+
iconType?: string;
803+
/** The name representation or actual react element implementation for the icon */
804+
icon?: string | ReactElement;
805+
};
827806

828807
/** The type that defines how to change the behavior of the submit button for the form */
829808
export type UISchemaSubmitButtonOptions = {

0 commit comments

Comments
 (0)