Skip to content

Commit 73cae31

Browse files
committed
Refactor types and improve build configuration
- Split types.ts into internalTypes.ts and publicTypes.ts for better organization - Make type definitions public by separating public API types from internal-only types - Rename types for consistency (with backward compatibility aliases): - CardComponentPropsType → CardComponentProps - CardComponentType → CardComponent - InputSelectDataType → InputSelectData - SectionPropsType → SectionProps - CardModalType → CardModal - Export public types from index.ts for better API discoverability - Keep types.ts as the main import point for all types (re-exports from publicTypes.ts and internalTypes.ts) - Improve build configuration and tooling Documentation updates: - Update Mods.md to show how to import types from the package instead of inline definitions - Update Usage.md to use new type names and improve custom form input examples - Replace email example with comprehensive phone number example in Usage.md - Update all documentation screenshots with fresh captures from live application - Update screenshots: array.png, array2.png, card.png, collapsed.png, dependency1.png, dependency2.png, modal.png, reference.png, section.png - Remove visualDemo.gif as it is no longer referenced in documentation
1 parent 0d2a249 commit 73cae31

34 files changed

+831
-696
lines changed

docs/Mods.md

Lines changed: 63 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -4,106 +4,63 @@ Mods provide for the customization of the Form Builder component, such as the de
44

55
## Type Definition
66

7-
Type definitions are available via [TypeScript](https://github.com/microsoft/TypeScript).
8-
9-
The type definition for Mods is as follows:
7+
All types used in mods are exported from the package and can be imported directly. When you import types from the package, TypeScript automatically provides type checking.
108

119
```typescript
12-
interface Mods {
13-
customFormInputs?: {
14-
[key: string]: FormInputType;
15-
};
16-
components?: {
17-
add?: (properties?: {
18-
[key: string]: any;
19-
}) => ReactElement | ReactElement[] | [];
20-
};
21-
tooltipDescriptions?: {
22-
add?: string;
23-
cardObjectName?: string;
24-
cardDisplayName?: string;
25-
cardDescription?: string;
26-
cardInputType?: string;
27-
cardSectionObjectName?: string;
28-
cardSectionDisplayName?: string;
29-
cardSectionDescription?: string;
30-
};
31-
labels?: {
32-
formNameLabel?: string;
33-
formDescriptionLabel?: string;
34-
objectNameLabel?: string;
35-
displayNameLabel?: string;
36-
descriptionLabel?: string;
37-
inputTypeLabel?: string;
38-
addElementLabel?: string;
39-
addSectionLabel?: string;
40-
};
41-
showFormHead?: boolean;
42-
deactivatedFormInputs?: Array<string>;
43-
newElementDefaultDataOptions?: {
44-
title: string;
45-
type?: string;
46-
description?: string;
47-
$ref?: string;
48-
default?: string | number;
49-
};
50-
newElementDefaultUiSchema?: { [key: string]: any };
51-
}
10+
import type {
11+
Mods,
12+
FormInput,
13+
Match,
14+
CardComponent,
15+
CardComponentProps,
16+
ModLabels,
17+
DataOptions,
18+
AddFormObjectParameters,
19+
DefinitionData,
20+
DataType,
21+
JsonSchemaProperty,
22+
UiSchemaProperty,
23+
} from '@ginkgo-bioworks/react-json-schema-form-builder';
5224
```
5325

54-
`tooltipDescriptions` and `labels` describe how some of the labels and tooltips in the Form Builder are to be customized. `showFormHead` is a boolean which controls whether the top section of the Form Builder, which contains inputs for the Form Name and Form Description, are show. It is set to `true` by default.
26+
### Mods
5527

56-
A single `FormInput` has a type definition `FormInputType` as follows:
28+
The `Mods` type is the main interface for customizing the Form Builder. It includes:
5729

58-
```typescript
59-
interface FormInputType {
60-
displayName: string;
61-
// given a data and ui schema, determine if the object is of this input type
62-
matchIf: Array<MatchType>;
63-
// allowed keys for ui:options
64-
possibleOptions?: Array<string>;
65-
defaultDataSchema: {
66-
[key: string]: any;
67-
};
68-
defaultUiSchema: {
69-
[key: string]: any;
70-
};
71-
// the data schema type
72-
type: DataType;
73-
// inputs on the preview card
74-
cardBody: CardComponentType;
75-
// inputs for the modal
76-
modalBody?: CardComponentType;
77-
}
78-
```
30+
- `customFormInputs?: Record<string, FormInput>` - Define custom form input types
31+
- `components?: { add?: (properties?: AddFormObjectParameters) => ReactElement | ReactElement[] | [] }` - Customize the "Add" button component
32+
- `tooltipDescriptions?: { ... }` - Customize tooltip text (see [Tooltips and Labels](#tooltips-and-labels) section)
33+
- `labels?: ModLabels` - Customize label text (see [Tooltips and Labels](#tooltips-and-labels) section)
34+
- `showFormHead?: boolean` - Control visibility of the form header (default: `true`)
35+
- `deactivatedFormInputs?: Array<string>` - Hide specific default input types
36+
- `newElementDefaultDataOptions?: DataOptions` - Set default options for new form elements
37+
- `newElementDefaultUiSchema?: UiSchemaProperty | Record<string, unknown>` - Set default UI schema for new form elements
7938

80-
The `displayName` is the full name of the desired form input. For example, **Short Answer** is the `displayName` for the `shortAnswer` form input.
39+
**Additional types:**
40+
- `AddFormObjectParameters` - Used in `components.add` callback to add form elements programmatically (see [Usage documentation](Usage.md#customizing-add-buttons) for details)
41+
- `DataOptions` - Type for `newElementDefaultDataOptions`, includes `title`, `type`, `description`, `$ref`, and `default` properties
8142

82-
`matchIf` is an array of scenarios that will cause the `FormBuilder` to recognize a piece of Data and UI schema as this custom input type. For more information, see the *Matching Algorithm* section on this page.
43+
### FormInput
8344

84-
`possibleOptions` is the set of possible values that can appear after `ui:option` in the UI schema for this component.
45+
The `FormInput` type defines a custom form input. Key properties:
8546

86-
`defaultDataSchema` is the data schema that gets filled into the component when a user switches to this input type. This default data schema must be a match in the `matchIf` array, or otherwise when the user switches to the Input Type, it will be immediately unrecognzied and instead be captured by the next applicable input type.
47+
- `displayName: string` - The full name shown in the Input Type dropdown (e.g., "Short Answer")
48+
- `matchIf: Array<Match>` - Array of matching criteria to identify this input type (see [Matching Algorithm](#matching-algorithm) section)
49+
- `possibleOptions?: Array<string>` - Allowed keys for `ui:options` in the UI schema
50+
- `defaultDataSchema: JsonSchemaProperty | Record<string, unknown>` - Default data schema when switching to this input type (must match one of the `matchIf` criteria)
51+
- `defaultUiSchema: UiSchemaProperty | Record<string, unknown>` - Default UI schema when switching to this input type (must match one of the `matchIf` criteria)
52+
- `type: DataType` - The JSON Schema data type (see `DataType` below)
53+
- `cardBody: CardComponent` - React component rendered in the expanded card
54+
- `modalBody?: CardComponent` - Optional React component rendered in the modal (pencil icon)
8755

88-
`defaultUiSchema` is the ui schema that gets filled into the component when a user switches to this input type. It functions similarly to the `defaultDataSchema`, and must pass the requirements in `matchIf`.
56+
### DataType
8957

90-
`type` is the Data Schema type that this input type defaults to. While a custom form input can have multiple types (would need to be defined in the `matchIf` array), this refers to the type that gets assigned immediately after a user selects this input type in the dropdown. The possible `DataType` options supported by `react-jsonschema-form` are as follows:
58+
The `DataType` is a union type representing JSON Schema data types supported by `react-jsonschema-form`:
9159

9260
```typescript
93-
type DataType =
94-
| 'string'
95-
| 'number'
96-
| 'boolean'
97-
| 'integer'
98-
| 'array'
99-
| 'object'
100-
| 'null';
61+
type DataType = 'string' | 'number' | 'boolean' | 'integer' | 'array' | 'object' | 'null';
10162
```
10263

103-
`cardBody` refers to a React component that gets rendered in the card itself, when expanded. This React component gets a set of `Parameters` that provide additional information about the FormInput, such as the `title` or the `default` properties. For more information, see the *Parameters* section.
104-
105-
`cardModal` refers to the React component that appears inside the modal that appears when the form builder clicks on the pencil icon. This React component also receives the same `Parameters` object, which is explained in further detail in the *Parameters* section.
106-
10764
The `FormBuilder` component takes a prop `mods`, which is a `Mods` type object.
10865

10966
## Custom Form Inputs
@@ -116,87 +73,38 @@ Custom input types are encoded in exactly the same way the Default input types a
11673

11774
### Matching Algorithm
11875

119-
The `matchIf` array in a `FormInput` contains a series of `MatchType` objects, which represent different possible 'scenarios' that the `FormBuilder` may encounter when parsing a set of Data and UI Schema. The `MatchType` is defined as follows:
120-
121-
```typescript
122-
interface MatchType {
123-
types: Array<DataType>;
124-
widget?: string;
125-
field?: string;
126-
format?: string;
127-
$ref?: boolean;
128-
enum?: boolean;
129-
}
130-
```
76+
The `matchIf` array in a `FormInput` contains a series of `Match` objects, which represent different possible 'scenarios' that the `FormBuilder` may encounter when parsing a set of Data and UI Schema. The `Match` type is exported and can be imported from the package.
13177

132-
`types` refers to the set of possible input types that can register in a particular scenario.
78+
**Match properties:**
13379

134-
`widget` is the value for the key `ui:widget` that can exist in the UI schema for this scenario.
80+
- `types: Array<DataType>` - The set of possible JSON Schema data types that can register in this scenario
81+
- `widget?: string` - The value for `ui:widget` that can exist in the UI schema for this scenario
82+
- `field?: string` - The value for `ui:field` that can exist in the UI schema for this scenario
83+
- `format?: string` - The value for `format` that can exist in the Data schema for this scenario
84+
- `$ref?: boolean` - If `true`, matches when the data schema has a `$ref` property (reference to a definition)
85+
- `enum?: boolean` - If `true`, matches when the data schema has an `enum` property
13586

136-
`field` is the value for the key `ui:field` that can exist in the UI schema for this scenario.
137-
138-
`format` is the value for the key `format` that can exist in the Data schema for this scenario.
139-
140-
`$ref` is a boolean that evaluates to true if, in this scenario, the input type is a reference to a field in `definitions` in the Data Schema (in other words, the data schema has a property `$ref`).
141-
142-
`enum` is a boolean that evaluates to true if the component has a property `enum` in the Data Schema.
87+
Import the type from the package to see its complete definition.
14388

14489
### Component Types
14590

146-
`cardBody` and `modalBody` are components whose props have a type of `CardComponentType`:
91+
`cardBody` and `modalBody` are components whose props have a type of `CardComponent`. Both `CardComponent` and `CardComponentProps` are exported and can be imported from the package.
14792

148-
```typescript
149-
type CardComponentType = FunctionComponent<{
150-
parameters: CardComponentPropsType;
151-
onChange: (newParams: CardComponentPropsType) => void;
152-
mods?: Mods;
153-
}>;
154-
```
93+
**CardComponent** is a React function component that receives:
94+
- `parameters: CardComponentProps` - The props/parameters for the form input
95+
- `onChange: (newParams: CardComponentProps) => void` - Callback to update the parameters
96+
- `mods?: Mods` - Optional mods configuration
15597

156-
`CardComponentPropsType` is a type that describes most params passed between cards and modals.
98+
**CardComponentProps** describes the parameters passed to card and modal components. It includes properties such as:
99+
- Form element properties: `name`, `title`, `description`, `required`, `type`
100+
- JSON Schema validation: `minLength`, `maxLength`, `pattern`, `minimum`, `maximum`, `enum`, etc.
101+
- UI Schema properties: `ui:options`, `ui:placeholder`, `ui:autofocus`, `ui:autocomplete`, etc.
102+
- Dependencies: `dependents`, `dependent`, `parent`
103+
- References: `$ref`, `definitionData`, `definitionUi`
157104

158-
```typescript
159-
interface CardComponentPropsType {
160-
name: string;
161-
required?: boolean;
162-
hideKey?: boolean;
163-
definitionData?: { [key: string]: any };
164-
definitionUi?: { [key: string]: any };
165-
neighborNames?: string[];
166-
dependents?: { children: string[]; value?: any }[];
167-
dependent?: boolean;
168-
parent?: string;
169-
'ui:options'?: { [key: string]: any };
170-
category?: string;
171-
schema?: { [key: string]: any };
172-
type?: string;
173-
'ui:column'?: string;
174-
minLength?: number;
175-
maxLength?: number;
176-
pattern?: string;
177-
'ui:autofocus'?: boolean;
178-
'ui:placeholder'?: string;
179-
minItems?: number;
180-
maxItems?: number;
181-
title?: string;
182-
$ref?: string;
183-
format?: string;
184-
'ui:autocomplete'?: string;
185-
default?: string | number | boolean;
186-
items?: { [key: string]: any };
187-
'ui:*items'?: { [key: string]: any };
188-
multipleOf?: number | null;
189-
minimum?: number | null;
190-
exclusiveMinimum?: number | null;
191-
maximum?: number | null;
192-
exclusiveMaximum?: number | null;
193-
enum?: (number | string)[];
194-
enumNames?: string[] | null;
195-
description?: string;
196-
}
197-
```
105+
Import the types from the package to see their complete definitions.
198106

199-
It can hold any number of keys pointing to specific values. One common example is `default`, which stores the default value specified by the builder for this `FormInput`.
107+
One common example is the `default` property, which stores the default value specified by the builder for this `FormInput`.
200108

201109
## Tooltips and Labels
202110

0 commit comments

Comments
 (0)