@adriaanwm/stencil v0.1.9
Stencil 📐
NOTE: This is beta software and is changing rapidly.
Turn specifications into UI building blocks.
This implementation of Stencil turns an OpenApi file into React building blocks. It does this with the help of react-hook-form and react-query.
API
Table of Contents
buildStencil
Create a new stencil
Parameters
openapiDocObject: The OpenAPI document that defines the api.optionsObject: An object containing various configuration options.serverObject: Configuration related to the server.urlString: The URL of the server.
devModeBoolean: When devMode is on, some additional information may be shown when an error occurs. For example if you try to access a field that does not exist it will render a warning component that shows the error. When devMode is false this will be hidden.useTokenFunction: A function that returns the auth token.componentsObject: Some generic components that may be reused in different places.loadingArray: An array of loading components.nameString: The name of the loading component.componentFunction: A function that returns a React component for loading.
useFormObject: Configuration for form fields, buttons, errors, and forms.errorHandlerFunction: A function to handle form errors.fieldsArray of ComponentDefinitions: An array of field component definitions.buttonsArray of ComponentDefinitions: An array of component definitions.formErrorsArray of ComponentDefinitions: An array of component definitions.formsArray of ComponentDefinitions: An array of component definitions.
ComponentDefinition
Defines a component that can be used for some given task. For example a component in useForm.fields is expected to be a form field that will update form data in some way. Stencil is designed to allow for many different versions of components for the same task. For example, you might want to have form fields for different themes. Or you might have many different form fields that can handle text, (eg. a text area, a text input, and a growing text area). You can easily make one of these be the default, while still having the others available in building your form.
Keys
nameString: The name of the component.predicateFunction: A function to determine if the component can be used. This is only applicable to some types of component definitions, namely fields. You will be given the name and details about the field, and can return whether this component can handle the type of field. For example, if the type is boolean, you would return false for a text input component.themeString: The theme name of the field.priorityNumber: The priority of the field. The higher the number, the higher priority it is given. When resolving which field to use as the default, the one with the matching theme and highest priority will be chosen. (This filed will be included in theFieldsobject, and will be used if you let the form render fields itself instead of passing in children. eg.<Form />componentFunction: A function that returns a React component for the field. eg.() => props => <input {...props}/>. For field components, you will normally want to useuseFormContextfrom react hook form to hook the component up to the form state.
stencil
Stencil is the object that is returned by buildStencil. It has a number of useful utilities.
Keys
queriesObject where all keys are generatedQueryHooks: All of the generated react-query hooks for thegetresources. Eg. for apublic/postsendpoint there will be astencil.queries.usePublicPostshook.
generatedQueryHook
TODO: add documentation about stencil.queries
useForm
Parameters
nameString: The name of the url (you can see all available names instencil.urls)methodString: The http method of the form (eg.post,patch,delete)optionsuseFormOptions:
useFormOptions
themeString: Which theme to use, defaults todefaultuseFormOptionsreactHookFormUseFormOptions: The object that will get passed to react-hook-form'suseForm, this is where you can pass along a resolver for validation, or manually pass defaultValues.
useList
Parameters
nameString: The name of the url (you can see all available names instencil.urls)optionsuseListOptions:
useListOptions
additionalFiltersTODO
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago