npm.io
1.0.5 • Published 4 years ago

react-products-gallery

Licence
ISC
Version
1.0.5
Deps
0
Size
21 kB
Vulns
0
Weekly
0

This library allows developers to easily integrate online shopping component into their React applications. It uses Rollup as a bundler and Material-UI for rendering major parts of its UI.

See this component in action.

Installation

npm install react-products-gallery

Usage

import ProductsGallery from 'react-products-gallery'

const products = [
  {
    id: 1,
    name: 'Antarctic Star Space Heater',
    currency: '

Component Props

Name Type Description
products array Check out the payload example from above. image, specs, and description are optional
options object Check out the list of available options from the table below
callbacks object Check out the list of available callbacks from the table below
Options
Name Type Default Description
wrapperStyles object {} Inline style object for the top-level wrapper element
autoSelectProduct boolean true If true, the first product will be selected by default upon data load and search.
searchInputAutoFocus boolean false If true, search field will be focused by default upon initialization of the component.
searchInputPlaceholder string "Find the product of your dreams" Placeholder text for the search field.
mobileWidth number 768 The boundary width of the component (in pixels) where it turns into mobile-friendly UI.
debounceDelay number 350 The debounce delay for the search result (in milliseconds) to become effective.
Callbacks
Name Type Parameters Description
onSelectProduct function (product: object) Fired when a product is selected from the left-hand list
onUpdateSearch function (keyword: string) Fired when the search keyword is changed. (Debounced)
onClearSearch function None Fired when the clear button of search field is clicked.
onAddToCart function (product: object) Fired when the cart button of the product detail section is clicked.
, price: 16.7, image: 'https://m.media-amazon.com/images/I/random-product-image-167.jpg', specs: [ { property: 'Color', value: 'Black' }, { property: 'Power Source', value: 'Corded Electric' }, //... ], description: 'Lorem ipsum dolor sit amet', }, //... ]; // ... render() { return( <ProductsGallery products={products} callbacks={{ onAddToCart: (product) => {} }} options={{ mobileWidth: 600 }} /> ) }

Component Props

Name Type Description
products __INLINE_CODE_0__ Check out the payload example from above. __INLINE_CODE_1__, __INLINE_CODE_2__, and __INLINE_CODE_3__ are optional
options __INLINE_CODE_4__ Check out the list of available options from the table below
callbacks __INLINE_CODE_5__ Check out the list of available callbacks from the table below
Options
Name Type Default Description
wrapperStyles __INLINE_CODE_6__ __INLINE_CODE_7__ Inline style object for the top-level wrapper element
autoSelectProduct __INLINE_CODE_8__ __INLINE_CODE_9__ If __INLINE_CODE_10__, the first product will be selected by default upon data load and search.
searchInputAutoFocus __INLINE_CODE_11__ __INLINE_CODE_12__ If __INLINE_CODE_13__, search field will be focused by default upon initialization of the component.
searchInputPlaceholder __INLINE_CODE_14__ __INLINE_CODE_15__ Placeholder text for the search field.
mobileWidth __INLINE_CODE_16__ 768 The boundary width of the component (in pixels) where it turns into mobile-friendly UI.
debounceDelay __INLINE_CODE_17__ 350 The debounce delay for the search result (in milliseconds) to become effective.
Callbacks
Name Type Parameters Description
onSelectProduct __INLINE_CODE_18__ __INLINE_CODE_19__ Fired when a product is selected from the left-hand list
onUpdateSearch __INLINE_CODE_20__ __INLINE_CODE_21__ Fired when the search keyword is changed. (Debounced)
onClearSearch __INLINE_CODE_22__ None Fired when the clear button of search field is clicked.
onAddToCart __INLINE_CODE_23__ __INLINE_CODE_24__ Fired when the cart button of the product detail section is clicked.

Keywords