Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@commercelayer/react-components

commercelayer5.8kMIT4.22.0TypeScript support: included

The Official Commerce Layer React Components

reactjs, jamstack, headless, ecommerce, api, react-components, commercelayer

readme

Commerce Layer React Components

A collection of reusable React components that makes it super fast and simple to build your own custom commerce UI, leveraging Commerce Layer API.

What is Commerce Layer?

Commerce Layer is a multi-market commerce API and order management system that lets you add global shopping capabilities to any website, mobile app, chatbot, wearable, voice, or IoT device, with ease. Compose your stack with the best-of-breed tools you already mastered and love. Make any experience shoppable, anywhere, through a blazing-fast, enterprise-grade, and secure API.

Getting started

For a constantly updated list of the available and soon-to-come micro frontends provided by Commerce Layer's react componente, please refer to this interactive documentation that will provide you with all the necessary information about the involved web components and help you get started in a snap.

Installation

Commerce Layer React Components are available as an npm package:

// npm
npm install @commercelayer/react-components

// yarn
yarn add @commercelayer/react-components

// pnpm
pnpm add @commercelayer/react-components

Authentication

All requests to Commerce Layer API must be authenticated with an OAuth2 bearer token. Hence, to use these components, you need to get a valid access token. Once you got it, you can pass it as prop — together with the endpoint of your Commerce Layer organization — to the CommerceLayer component, as follow:

<CommerceLayer
  accessToken="your-access-token"
  endpoint="https://yourdomain.commercelayer.io">

  {/* ... child components */}

</CommerceLayer>

This token will be used to authorize the API calls of all its child components. That's why the presence of (at least) one CommerceLayer component is mandatory — it must wrap every other component you need to use.

Please note that — in case you need to fetch data with different tokens (i.e. from different organizations or using apps with different roles and permissions) — nothing prevents you from putting as many CommerceLayer components you want in the same page.

You can check our documentation for more information about the available authorization flows and leverage Commerce Layer JS Auth to easily interact with our authentication API.

Need help?

License

This repository is published under the MIT license.

changelog

3.12.7 (2022-05-26)

Bug Fixes

  • Reset shipping method selector when add or remove a coupon (88ca65d)

Performance Improvements

  • autoSelectSingleShippingMethod accept even a function (69c6b2e)

3.12.6 (2022-05-25)

Performance Improvements

  • Add autoSelectSingleShippingMethod prop to Shipment component (d24b6f7)

3.12.5 (2022-05-23)

Bug Fixes

  • List of stock transfers (67dd33e)

3.12.4 (2022-05-20)

Bug Fixes

  • Expose parentRef for custom children function (c92587e)

3.12.3 (2022-05-13)

Bug Fixes

  • Lose order data when reload the thank you page (c7b5935)
  • The StockTransferField reads HTML attribute properly (b310f6f)

3.12.2 (2022-05-12)

Bug Fixes

  • Disabled the place order button (35754d8)

3.12.1 (2022-05-10)

Bug Fixes

3.12.0 (2022-05-06)

Features

  • Update order attributes by attributes prop if an order is already loaded (111c202)

Performance Improvements

  • Improve network requests (b4ef18e)

3.11.2 (2022-05-03)

Bug Fixes

  • Children props types (60e9b46)
  • Children props types (7cdcaa6)
  • Duplicate payment_source request (12699c2)
  • Duplicate error messages (197b97c)

Performance Improvements

  • Use labelFreeOver when the amount is equal to zero (e514cfa)

3.11.1 (2022-05-02)

Bug Fixes

  • Stock transferts visualization and improve the resources include (441c611)

Performance Improvements

  • Add new GenericField component (83f9ae6)

3.11.0 (2022-04-14)

Bug Fixes

  • Rename SkuContainer to SkusContainer (39d03a9)

Features

  • Add buyNowMode and checkoutUrl props to AddToCartButton (c6a8535)
  • Allow to use Sku context by cart components (9794859)

3.10.0 (2022-04-12)

Bug Fixes

  • Check billing and shipping address (6dc7389)
  • Update klarna order (a78b9ba)

Features

  • Add Klarna components (21bbc01)
  • Add klarna_payments to gateways configuration (87f2520)
  • Add order info to klarna payment (8c5249d)
  • Add place order after the authorization flow (eeec7ff)
  • Add place order callback flow (4afda53)
  • Import Klarna external JS script (888465b)
  • Show Klarna widget (638c252)

3.9.5 (2022-04-12)

Bug Fixes

  • Callback response from Errors component (eac98be)

Performance Improvements

  • Clean message if title and detail are equal (2ff8cc7)

3.9.4 (2022-04-11)

Bug Fixes

  • Include line_items.item (27bc292)

3.9.3 (2022-04-08)

Bug Fixes

  • Check if there is do_not_ship set to true and the order doesn't have the shipping address (c282728)
  • Reload the order when a coupon is added or removed (ecbff39)
  • Set @commercelayer/js-auth to latest version 2.3.0 (4b5ec96)

3.9.2 (2022-04-05)

Bug Fixes

  • Rehydrate payment source among payment components (789af62)

Performance Improvements

  • Add value to onSubmit callback as prop and reset form after submitting (ad739c2)

3.9.1 (2022-04-01)

Bug Fixes

  • Show selected customer card (e3eaab8)

3.9.0 (2022-03-31)

Features

  • Add new SKUs components (ae7b03c)

3.8.2 (2022-03-29)

Bug Fixes

  • Filter line_items by item_type to show the correct error (3667350)

3.8.1 (2022-03-29)

Bug Fixes

3.8.0 (2022-03-28)

Bug Fixes

  • Show checkout.com card after placing an order (1083750)
  • Wrong key for line_2 attribute (03b84a9)

Features

  • Add new markup and props to LineItemOptions (7a5450d)
  • check for out of stock and shipping method available for shipments (38000b6)

Performance Improvements

  • Set attribute field to errors handler (0f60a39)

3.7.0 (2022-03-24)

Features

  • Add new prop placeholderTranslation to GiftCardOrCouponInputProps (e30c4ab)
  • apply both gift_card and coupon on the same order (ed751fa)

3.6.4 (2022-03-17)

Performance Improvements

  • Update library @ac-dev/state-service (491f062)

3.6.3 (2022-03-17)

Bug Fixes

  • Restore payment source patch to save card details (4d9b3d6)

3.6.2 (2022-03-16)

Bug Fixes

  • Rehydrate payment source props (0db600b)

3.6.1 (2022-03-10)

Performance Improvements

  • Add nullify payment source (0a76d7a)

3.6.0 (2022-03-08)

Features

  • Add sorti for customer addresses (9916a77)

Performance Improvements

  • Remove unused reset prop (18c9a67)

3.5.2 (2022-03-07)

Bug Fixes

  • Get remove coupon response by onClick (0e7b8d7)

3.5.1 (2022-03-02)

Bug Fixes

  • Automatic place order for Paypal and Checkout.com (c3f73ee)

3.5.0 (2022-02-28)

Features

  • Add data testing attribute to PaymentMethod component (7e08b86)

3.4.4 (2022-02-28)

Bug Fixes

  • Edit default success_url and failure_url by configuration object (ddc61f3)

3.4.3 (2022-02-25)

Bug Fixes

  • Select Adyen customer card (90442ed)

3.4.2 (2022-02-24)

Bug Fixes

  • Place order without payment source when order total amount is equal to zero (a9f13d3)
  • Types (677eac1)

3.4.1 (2022-02-24)

Bug Fixes

  • Disable button when the order is equal to zero (7d40ac4)
  • Select customer card with Adyen (f2cc9c3)

3.4.0 (2022-02-23)

Bug Fixes

  • Expose customer email through onBlur function (e552ae1)

Features

  • CheckoutLink is linked to hosted checkout by default with a boolean prop hostedCheckout (b19cf7f)

3.3.0 (2022-02-23)

Bug Fixes

Features

  • Add customer payment (38ccef2)
  • Create checkout.com components (dd54cf6)
  • Set success_url and failure_url with window.location.href value (8d2416f)
  • Update checkout_com_payments with card token (e27ec3c)

3.2.4 (2022-02-09)

Bug Fixes

  • Allow uppercase letters in customer email input (3d77828)

3.2.3 (2022-02-01)

Bug Fixes

  • Reset state selector value (90fdb3f)

3.2.2 (2022-02-01)

Bug Fixes

  • Remove reset shipping address by isBusiness prop (a640f2f)

3.2.1 (2022-01-31)

Bug Fixes

  • Save line_2 value properly (4689e90)

3.2.0 (2022-01-28)

Bug Fixes

  • Reset form properly when isBusiness changes (1e2fbbd)

Features

  • Add onChange prop to BaseSelectComponentProps (5a51b8e)
  • Expose address as param of onSelect function (29ee53e)

3.1.0 (2022-01-28)

Bug Fixes

  • API request without any includes (a3dfb19)
  • Console warning if children are null or boolean (a13f5a4)
  • Filter addresses by shipping_country_lock if it has a value (2f835b6)
  • Order does not include resources after updating/creating a coupon (6ff1460)
  • Reset form when isBusiness prop changes status (2c7da18)
  • Show label free if the price is equal to zero (406d03d)

Features

  • Add new prop isBusiness to BillingAddressForm (f49c17b)

3.0.1 (2022-01-26)

Bug Fixes

  • import getSdk in example page (97e2247)

3.0.0 (2022-01-24)

Performance Improvements

BREAKING CHANGES

  • Remove cjs version

2.53.3 (2022-01-24)

Performance Improvements

2.53.2 (2022-01-24)

Bug Fixes

  • Import only countries and states packages (f31c663)

2.53.1 (2022-01-17)

Bug Fixes

  • Show multiple bundles in a single order (6b454a9)

2.53.0 (2022-01-17)

Bug Fixes

Features

  • Add new prop placeholder and set placeholder image if src is empty (1717e98)

2.52.1 (2021-12-21)

Bug Fixes

2.52.0 (2021-12-21)

Bug Fixes

Features

  • Add new component AdjustmentAmount (231863c)
  • Add new prop typeAccepted to LineItemsCount (1317bdd)

2.51.3 (2021-12-17)

Bug Fixes

  • Diable AddToCart button and show availability without a VariantSelector (ecd4d5a)

2.51.2 (2021-12-16)

Bug Fixes

2.51.1 (2021-12-16)

Bug Fixes

2.51.0 (2021-12-16)

Bug Fixes

  • Redirect flow with Adyen 3DS-1 (1e14e00)

Features

  • Add new component LineItemsEmpty (45b5127)

2.50.7 (2021-12-13)

Bug Fixes

  • Cannot read property 'map' (378d77d)

2.50.6 (2021-12-13)

Bug Fixes

2.50.5 (2021-12-10)

Bug Fixes

  • Remove useMemo (a66cbf2)
  • Show card details and paypal gateway (1835f13)

2.50.4 (2021-12-10)

Bug Fixes

  • Address country lock controller (faff60a)
  • Place an order with total amount equal to zero (ec72aa6)
  • Show GiftCardOrCouponRemoveButton properly (89e378d)

2.50.3 (2021-12-09)

Bug Fixes

  • Duplicate customer addresses (10d03a7)
  • Hydrate props properly (89049cd)

2.50.2 (2021-12-07)

Bug Fixes

  • Add useMemo and force refresh by accessToken (45b612b)

2.50.1 (2021-12-07)

Bug Fixes

  • Expose lineItem prop to LineItem components (5b39f31)

2.50.0 (2021-12-07)

Bug Fixes

  • Read Stripe payment_method attribute if options attribute is not available (3633657)

Features

  • Expose types and add shipmentId to ShippingMethodRadioButton onChange prop (8d9ca25)

2.49.8 (2021-12-06)

Bug Fixes

  • Expose htmlFor prop for ShippingMethodName component (95ffd2a)

2.49.7 (2021-12-02)

Bug Fixes

  • Add RedirectShopper (c6233b7)
  • Clean order when it is placed (67b9387)
  • Expose prices resource within Price custom children props (40f58b3)

2.49.6 (2021-12-02)

Bug Fixes

  • Show payment method amount correctly (b3e5048)

2.49.5 (2021-12-01)

Bug Fixes

  • Manage resources to include (90917d9)
  • Save customer address book and include order resources (4854f64)

2.49.4 (2021-11-30)

Bug Fixes

  • Include resources to order request (635d84a)

2.49.3 (2021-11-30)

Bug Fixes

  • Include resources to order (2e5d4d4)

2.49.2 (2021-11-29)

Bug Fixes

  • Force include resources to order query (14daa83)

2.49.1 (2021-11-29)

Bug Fixes

  • Revert minimize-js version (6448fb8)

2.49.0 (2021-11-29)

Features

  • Add new prop showShippingMethodPrice to AvailabilityTemplate and force the include line_items within LineItemsContainer (128ea63)

2.48.3 (2021-11-24)

Bug Fixes

  • Disable AddToCartButton when inventory quantity is zero (819580f)

2.48.2 (2021-11-24)

Bug Fixes

2.48.1 (2021-11-24)

Bug Fixes

  • Expose text prop as AvailabilityTemplate children props (346fc9b)

2.48.0 (2021-11-24)

Bug Fixes

Features

  • Add handleCallback prop to VariantSelector (8824427)

2.47.1 (2021-11-23)

Bug Fixes

2.47.0 (2021-11-23)

Features

  • Add bundles and adjstments (32eddb6)
  • Add new sdk to VariantReducer and ItemReducer (3ea29f8)
  • Add semantic-release, build by tsc, tsc-alias, and minimize-js (10d42da)
  • Implement new sdk and improve network requests (546b893)
  • Implement new SDK to Availabilty and Variant components (9e3fbfb)
  • Implement new SDK to CommerceLayer and Prices components (ec32544)
  • Implement new SDK to customer addresses (974c5be)
  • Implement new SDK to Payment components (3dda2fb)
  • Implement new SDK to Shipments components (aa0626a)
  • Implement new SDK to the order reducer (680d4fd)
  • Rename LineItemSkuCode component to LineItemCode (9a061c2)
  • Rewrite OrderContext and OrderReducer, minimize API requests (b52414b)
  • Start implementing new SDK (4107d1e)