1.4.3 • Published 1 year ago

@ez-digital/react-hubspot-hook-form v1.4.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

HubSpot Form Component

License Issues RELEASES TypeScript LINKEDIN

This package provides a React component to integrate and customize HubSpot forms seamlessly. It leverages react-hook-form for form handling and validation, allowing you to easily include HubSpot forms in your React applications.

Features

  • Fetches and displays HubSpot forms dynamically based on form ID.
  • Customizable form and field styles.
  • Client-side validation with react-hook-form.
  • Handles form submission with HubSpot API integration.
  • Displays success and error messages.

Installation

To install the package, use npm or yarn:

npm install react-hubspot-hook-form

or

yarn add react-hubspot-hook-form

Pure ESM package

This package is pure ESM. It cannot be require()'d from CommonJS.

Usage

It's crucial to keep your PORTAL_ID and HUBSPOT_API_TOKEN secure to prevent unauthorized form submissions and other actions. To achieve this, set up your own server to store these environment variables and handle form requests. Remember, HubSpot mandates that form data requests be submitted from a server, rejecting any client-side requests.

React Example Next.js Example

How to Obtain a HubSpot API Token

To obtain your HubSpot API token, please visit this link.

Props

The HubSpotForm component accepts the following props:

Here's the updated table and corresponding documentation:

Table

PropTypeDefaultDescription
fieldGroupsFieldGroup[]RequiredAn array of field groups to be displayed in the form.
submitButtonTextstringRequiredThe text to display on the submit button.
onSubmitSubmitHandler<T>RequiredThe form submit handler function.
isLoadingbooleanfalseIndicates if the form is currently loading data.
isSubmittingbooleanfalseIndicates if the form is currently being submitted.
isSubmittedbooleanfalseIndicates if the form has been successfully submitted.
loaderReactNodeCustom loaderCustom loader component to display while fetching form data.
skeletonHeightnumber \| string400Height of the skeleton loader.
successMessagestring"The form has been submitted successfully."Message displayed upon successful form submission.
errorMessagestringundefinedMessage displayed upon form submission error.
formStylesReact.CSSProperties{}Custom styles for the form container.
formClassNamestring""Custom class name for the form container.
fieldGroupStylesReact.CSSProperties{}Custom styles for the field groups.
fieldGroupClassNamestring""Custom class name for the field groups.
fieldControlStylesReact.CSSProperties{}Custom styles for the field controls.
fieldControlClassNamestring""Custom class name for the field controls.
labelStylesReact.CSSProperties{}Custom styles for the labels.
labelClassNamestring""Custom class name for the labels.
fieldStylesReact.CSSProperties{}Custom styles for the input fields.
fieldClassNamestring""Custom class name for the input fields.
successMessageStylesReact.CSSProperties{}Custom styles for the success message.
successMessageClassNamestring""Custom class name for the success message.
errorMessageStylesReact.CSSProperties{}Custom styles for the error message.
errorMessageClassNamestring""Custom class name for the error message.
buttonStylesReact.CSSProperties{}Custom styles for the submit button.
buttonClassNamestring""Custom class name for the submit button.

Customization

You can customize the appearance and behavior of the form by passing custom styles and class names for various parts of the form. Additionally, you can provide custom loader components, success messages, and error messages to match the look and feel of your application. Use the provided styles from @ez-digital/react-hubspot-hook-form/style or style the form by yourself.

Example

Here is a more detailed example demonstrating customization:

import React from "react";
import ReactDOM from "react-dom";

import HubSpotForm from "@ez-digital/react-hubspot-hook-form";
import "@ez-digital/react-hubspot-hook-form/style";

const customStyles = {
  formStyles: { padding: "20px", backgroundColor: "#f9f9f9" },
  fieldGroupStyles: { marginBottom: "15px" },
  labelStyles: { fontWeight: "bold" },
  fieldStyles: { padding: "10px", borderRadius: "4px" },
  buttonStyles: { backgroundColor: "#007bff", color: "#fff" },
};

const App = () => {
  return (
    <HubSpotForm
      successMessage="Thank you for your submission!"
      errorMessage="Please correct the errors and try again."
      formStyles={customStyles.formStyles}
      fieldGroupStyles={customStyles.fieldGroupStyles}
      labelStyles={customStyles.labelStyles}
      fieldStyles={customStyles.fieldStyles}
      buttonStyles={customStyles.buttonStyles}
    />
  );
};

ReactDOM.render(<App />, document.getElementById("root"));

TypeScript

The module is written in TypeScript and type definitions are included.

Contributing

Contributions, issues and feature requests are welcome!

Show your support

Give a ⭐️ if you like this project!

License

This package is licensed under the MIT License. See the LICENSE file for more information.

1.4.3

1 year ago

1.4.2

1 year ago

1.4.1

1 year ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago