1.0.0 • Published 10 months ago

@contensis/forms v1.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
10 months ago

@contensis/forms

Render Contensis Forms in your React projects.

Installation

Install with your project's preferred package manager

npm install --save @contensis/forms
yarn add --save @contensis/forms

Usage

Render a Contensis Form with React

import React from 'react';
import ReactDOM from 'react-dom/client';
import { ContensisForm } from '@contensis/forms';

// Our React App
const App = () => {
  return (
    <div className="content">
      <ContensisForm
        apiUrl="https://api-{yourcms}.cloud.contensis.com"
        projectId="website"
        formId="contactForm" />
    </div>
  );
  // avoid CORS - omit apiUrl prop to make Forms API requests from your root domain (same as Delivery API requests)
};

const element = document.getElementById('root') as HTMLElement;
ReactDOM.createRoot(element).render(
    <React.StrictMode>
        <App />
    </React.StrictMode>
);

Customistion

All customisation options are available in the <ContensisForm> component props.

API

Specify which Form to request from the Forms API

proprequiredcomments
apiUrlThe root url for clients to access the Forms API. Omit this prop if your app will be deployed to Contensis Cloud and you currently use a reverse proxy to make requests to the Delivery API.
formIdYThe API id of the form to render
languageThe language variation of the form to render
projectIdYThe API id of the project containing the form to render
versionStatusRender the 'latest' or 'published' version of the form (default 'published')

Event Handlers

Handle or override specific form data and events

proprequiredcomments
onLoadErrorCalled when there has been a problem loading the form content type
onPopulatePopulate the form with your own custom default values
onSubmitCall your own custom actions when a user has completed the form
onSubmitErrorCalled when there has been a problem submitting a user's completed form
onSubmitSuccessCall your own custom actions when a user has submitted a form successfully

Render States

You can override built-in fallback components to render when the form is in a particular state

proprequiredcomments
disabledComponent to render when the Contensis Form is not enabled render
errorComponent to render when the Contensis Form could not be retrieved from the API
loadingComponent to render when the Contensis Form is loading

Example project

You try this out with the React example project

1.0.0

10 months ago

1.0.0-beta.5

10 months ago

1.0.0-beta.4

12 months ago

1.0.0-beta.1

1 year ago

1.0.0-beta.0

1 year ago