Socket
Book a DemoInstallSign in
Socket

merchi_product_form

Package Overview
Dependencies
Maintainers
2
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merchi_product_form

A React component for Merchi product forms

latest
Source
npmnpm
Version
1.2.9
Version published
Weekly downloads
25
-26.47%
Maintainers
2
Weekly downloads
 
Created
Source

Merchi Product Form

npm version License: MIT

A React component library for rendering customizable e-commerce product forms for Merchi products. This package provides a seamless integration for Next.js applications, allowing for interactive product forms with various customization options.

Features

  • Interactive product form with real-time price calculations
  • Customizable styling through extensive class name props
  • Support for product variations, groups, and options
  • File upload capability for product customizations
  • Cart and quote request functionality
  • Responsive design suitable for all devices

Table of Contents

Installation

# Using npm
npm install merchi_product_form

# Using yarn
yarn add merchi_product_form

Quick Start

import MerchiProductForm from 'merchi_product_form';

function ProductPage({ product }) {
  return (
    <MerchiProductForm
      initProduct={product}
      onBuyNow={(job) => console.log(job)}
      onGetQuote={(job) => console.log(job)}
    />
  );
}

Usage Example

Here's a complete example of how to use the MerchiProductForm component in a Next.js page:

import MerchiProductForm from 'merchi_product_form';
import { notFound } from 'next/navigation';

export async function fetchProduct(id) {
  const url = `https://api.merchi.co/v6/products/${id}/`;
  try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error(`HTTP error! Status: ${response.status}`);
    }
    const responseJson = await response.json();
    return responseJson.product;
  } catch (e) {
    throw new Error(e);
  }
}

export default async function Page({ params: { id } }) {
  const initProduct = await fetchProduct(id);
  if (!initProduct) return notFound();
  
  const onBuyNow = (job) => {
    // Handle buy now action
    console.log('Buy now job:', job);
  };
  
  const onGetQuote = (job) => {
    // Handle quote request
    console.log('Quote request job:', job);
  };
  
  return (
    <div className="product-container">
      <MerchiProductForm
        initProduct={initProduct}
        onBuyNow={onBuyNow}
        onGetQuote={onGetQuote}
        showCurrency={true}
      />
    </div>
  );
}

Component Props

The MerchiProductForm component accepts the following props:

NameTypeDefaultDescription
apiUrlstring?'https://api.merchi.co/v6/'The Merchi API endpoint URL
initProductProductrequiredThe Merchi product object to use for the form
allowAddToCartboolean?falseControls if the add to cart button is shown
btnNameAddToCartstring?"Add to Cart"The text on the add to cart button
currentUserUser?undefinedA Merchi client object to be used as the form's client
draftApproveCallback(job) => Promise<void> | nullnullAsync callback function that is triggered when drafts are approved
hideTitleboolean?falseHide the product title
hideCostboolean?falseHide the cost (useful for quote requests)
hideCountryboolean?falseHide the country flag
hideCalculatedPriceboolean?falseHide calculated price (useful for quote requests)
hideDomainNameboolean?falseHide product domain
hideQuantityFieldboolean?falseHide the quantity field
hideRequestQuotationButtonboolean?falseHide request quote button
hidePaymentUpfrontButtonboolean?falseHide buy now button
isCartItemboolean?falseUsed if the product form is being used in cart item context
initJob`jobcartItem`undefined
onAddToCart(job) => void?undefinedCallback function for the add to cart button
onBuyNow(job) => void?undefinedCallback function for the buy now button
onGetQuote(job) => void?undefinedCallback function for the get quote button
onSubmit(job) => void?undefinedCallback function that returns the latest job data
productFormIdstring?undefinedOptional ID to be applied to the product form
showCurrencyboolean?falseShow the currency symbol
showCurrencyCodeboolean?falseShow the currency code
showFeatureDeadlineboolean?falseWill display a countdown timer
showGroupBuyStatusboolean?falseWill show the group buy status bar
showUnitPriceboolean?falseShow the unit price to the user

CSS Class Props

The component provides extensive CSS class customization options:

NameTypeDefaultDescription
classNameAlertSellerEditablestring?'alert alert-light'Class for the seller editable alert element
classNameButtonSubmitstring?'btn btn-primary w-100 merchi-embed-form_button-submit'Class for the Submit button element
classNameButtonGroupAddstring?'btn btn-white'Class for the add group button element
classNameButtonGroupRemovestring?'btn btn-danger'Class for the delete group button element
classNameButtonsSubmitContainerstring?'merchi-product-buttons-submit-container'Class for the container of the submit buttons
classNameButtonApproveDraftsstring?'btn btn-success'Class for the approve drafts button element
classNameButtonCloseDraftsstring?'btn btn-secondary'Class for the close drafts button element
classNameFileUploadContainerstring?'merchi-input-file-container'Class for the input file container
classNameFileUploadstring?'merchi-embed-form_dropzone'Class for the dropzone container
classNameFilePreviewContainerstring?'uploaded-variation-file'Class for the file variation upload element
classNameFileUploadTextContainerstring?'merchi-embed-form_dropzone-text-container'Class for the dropzone text element
classNameFilePreviewIconWrapperstring?'uploaded-variation-file-icon-wrapper'Class for the upload variation icon wrapper
classNameFileUploadButtonstring?'btn btn-sm btn-link ml-auto'Class for the file upload button element
classNameFileUploadIconstring?'merchi-embed-form_dropzone-icon'Class for the form dropzone icon element
classNameFileUploadIconSecondstring?'merchi-embed-form_dropzone-icon-plus'Class for the form dropzone plus icon element
classNameFileUploadIconContainerstring?'merchi-embed-form_dropzone-icon-container'Class for the form dropzone icon container
classNameFileListItemstring?'list-group-item no-z-index-hover'Class for file list item element
classNameFileButtonDownloadstring?'btn btn-sm btn-secondary'Class for the file download button element
classNameFileButtonDeletestring?'btn btn-sm btn-danger ml-2'Class for the file delete button element
classNameFileListItemContainerstring?'list-group'Class for the file item list
classNameGroupsContainerstring?'merchi-embed-form_product-group-container'Class for the product variation group container
classNameGroupPriceContainerstring?'merchi-embed-form_product-group-total-cost'Class for the variation group total cost
classNameInputstring?'form-control'Class for form inputs
classNameInventoryStatusstring?'flex-fill'Class for the inventory status element
classNameInputContainerstring?'merchi-embed-form_product-group-input-qty-container'Class for the input container
classNameOptionContainerstring?'merchi-embed-form_checkbox_radio-item'Class for the radio/checkbox container
classNameOptionInputstring?'merchi-embed-form_checkbox_radio-input'Class for the radio input
classNameOptionLabelstring?'merchi-embed-form_checkbox_radio-label'Class for the radio label
classNameOptionSuperstring?'merchi-embed-form_checkbox_radio-super'Class for the checkbox radio super
classNameOptionsCheckboxRadioContainerstring?''Class for the option checkbox/radio container
classNameOptionImagestring?'merchi-embed-form_image-select-option-item-img'Class for the variation image select element
classNameOptionImageContainerstring?'merchi-embed-form_image-select-option-item-container'Class for the variation image container element
classNameOptionColourstring?'merchi-embed-form_color-select-option'Class for the variation colour element
classNameOptionColourContainerstring?'merchi-embed-form_color-select-item'Class for the variation colour container element
classNameProductTitlestring?'merchi-product-title'Class for the product title element
classNameProductOriginTitlestring?'merchi-product-origin-title'Class for the product origin title element
classNameProductTotalContainerstring?'merchi-embed-form_summary-product-cost-container'Class for the product total cost container element
classNameProductTotalstring?'merchi-embed-form_summary-product-cost'Class for the product total cost element
classNameQuantityLabelContainerstring?'merchi-embed-form_quantity-label-container'Class for the product quantity label element
classNameUnitPricestring?undefinedClass for the unit price element

Styling

The component provides extensive customization options through class name props. Here are some of the most commonly used styling props:

<MerchiProductForm
  initProduct={product}
  classNameButtonSubmit="custom-submit-button"
  classNameInput="custom-input"
  classNameProductTitle="custom-product-title"
  classNameProductTotal="custom-product-total"
/>

Advanced Usage

Working with Product Variations

<MerchiProductForm
  initProduct={product}
  classNameGroupsContainer="custom-groups-container"
  classNameOptionContainer="custom-option-container"
  onBuyNow={handleBuyNow}
/>

Handling File Uploads

<MerchiProductForm
  initProduct={product}
  classNameFileUploadContainer="custom-file-upload"
  classNameFilePreviewContainer="custom-file-preview"
  onGetQuote={handleQuoteRequest}
/>

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  • Fork the repository
  • Create your feature branch (git checkout -b feature/amazing-feature)
  • Commit your changes (git commit -m 'Add some amazing feature')
  • Push to the branch (git push origin feature/amazing-feature)
  • Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

For detailed information about all available props, please refer to the TypeScript definitions in the source code.

Keywords

react

FAQs

Package last updated on 16 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts