1.7.2 • Published 2 months ago

@partslogic/ui v1.7.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

example workflow

Partslogic

@partslogic/ui is a library of React components that helps you build e-commerce sites faster and easier.

We have Basic components which can be used with any API and Wrapper components that uses our @partslogic/ui backend API.

Installation

@partslogic/ui is available as an npm package.

// with npm
npm i @partslogic/ui

// with yarn
yarn add @partslogic/ui

Please note that react >= 18 and react-dom >= 18 are peer dependencies. So you need to install those libraries as well.

  • If you are using a bundler like webpack you can install react in this way:
// with npm
npm i react react-dom

// with yarn
yarn add react react-dom

You can also use the react CDN to add react to your application if you are not using a bundler:

<script src="https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js" crossorigin></script>
<script src="https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js" crossorigin></script>

Usage

ESM modules

As early as possible in your application, require and configure your API_KEY:

import { config } from '@partslogic/ui';
config({APY_KEY: "Your api key"})

Then you can import components and styles:

// Import components using absolute path
import { FitmentSelector, ListWrapper } from '@partslogic/ui';

// Import all styles
import '@partslogic/ui/build/index.css';

Usage with basic components (ESM modules)

When you use our basic components you are responsible to pass the data you want to show.

import React from 'react';
import ReactDOM from 'react-dom';
import {FitmentSelector} from '@partslogic/ui';
function App() {
  return (
    <FitmentSelector
        clearButtonText="Reset"
        labels={[
          { id: 1, name: 'Year' },
          { id: 2, name: 'Make' },
          { id: 3, name: 'Model' },
        ]}
        labelsData={{
          Make: [
            { id: 1, name: 'Make 1' },
            { id: 2, name: 'Make 2' },
            { id: 3, name: 'Make 3' },
          ],
          Model: [
            { id: 1, name: 'Model 1' },
            { id: 2, name: 'Model 2' },
            { id: 3, name: 'Model 3' },
          ],
          Year: [
            { id: 1, name: 2020 },
            { id: 2, name: 2019 },
            { id: 3, name: 2018 },
          ],
        }}
        orientation="horizontal"
        searchButtonText="Search"
        selectedValues={{
          Year: '1',
        }}
    />);
}
const root = ReactDOM.createRoot(document.querySelector('#app'))
root.render(<App />);

Usage with our wrapper components (ESM modules)

When you use our wrapper components you just have to put our component in your JSX and we do all the work to fetch and show data. You can customize these components passing some props and/or overriding css classes.

import React from 'react';
import ReactDOM from 'react-dom';
import {FitmentSelectorWrapper} from '@partslogic/ui';

function App() {
  return (
    <FitmentSelectorWrapper styled orientation="vertical" />);
}
const root = reactDOM.createRoot(document.querySelector('#app');
root.render(<App />));

CDN

Initializing the library

To use our UI components, the site needs 4 things:

  • React

  • ReactDOM

  • The javascript file of the library

  • The css file of the library

The following snippet can be inserted into any HTML file, or template that accepts HTML format. You can add @partslogic/ui as a <script> tags:

  <!-- React and ReactDOM -->
  <script src="https://cdn.jsdelivr.net/npm/react@18/umd/react.production.min.js" crossorigin></script>
  <script src="https://cdn.jsdelivr.net/npm/react-dom@18/umd/react-dom.production.min.js" crossorigin></script>

  <!-- Partslogic Library JS and CSS -->
  <script crossorigin src="https://cdn.jsdelivr.net/npm/@partslogic/ui@1.7.1/build/index.umd.js"></script>
  <link href="https://cdn.jsdelivr.net/npm/@partslogic/ui@1.7.1/build/index.css" rel="stylesheet" type="text/css" />

  <!-- Partslogic Initialization -->
  <script>
      const API_KEY = "";
      const GROUP_ID = "";
      const initPL = () => {
          window.PartslogicUi.config({
              API_KEY
          })
          window.PartslogicUi.groupId = GROUP_ID;
          window.PartslogicUi.ready = true;
          // This event will let all the components know that PL is ready,
          // so we can avoid race conditions.
          const readyEvent = new Event("Partslogic Ready");
          window.dispatchEvent(readyEvent);
      }
      // This event will let us know the libraries finished loading
      window.addEventListener("DOMContentLoaded", initPL);
  </script>

Instantiating a component

  <!-- Add a node to the DOM where we can instantiate the component -->
  <div id="pl-searchbar"></div>
  <script>
      const renderSearchbar = () => {
          const searchBarContainer = document.querySelector('#pl-searchbar');
          const root = window.ReactDOM.createRoot(searchBarContainer);
          const SearchBar = window.PartslogicUi.PartslogicSearchBarWrapper;
          const RESULTS_PAGE = "/search";
          const onSubmit = (data) => {
              let params = new URLSearchParams();
              params.set('q', data);
              window.location.href = `${window.location.origin}${RESULTS_PAGE}?${params.toString()}`;
          }
          const element = window.React.createElement(SearchBar, {
              onSubmit: onSubmit,
              styled: true,
          });
          root.render(element);

          // Tip: root.unmount() will unmount the component
      }
      // if the library was already intialized, render the component
      if (window.PartslogicUi && window.PartslogicUi.ready) {
          renderSearchbar();
      }
      // if not, wait until it is, and then render it
      else {
          window.addEventListener("Partslogic Ready", renderSearchbar)
      }
  </script>
1.7.2

2 months ago

1.7.1

4 months ago

1.7.0

4 months ago

1.6.3

4 months ago

1.6.2

5 months ago

1.5.5

6 months ago

1.5.4

6 months ago

1.5.3

6 months ago

1.6.1

5 months ago

1.5.2

6 months ago

1.6.0

5 months ago

1.5.1

6 months ago

1.5.0

6 months ago

1.4.1

7 months ago

1.3.2

9 months ago

1.4.0

7 months ago

1.5.7

5 months ago

1.5.6

5 months ago

1.2.0

12 months ago

1.3.1

11 months ago

1.3.0

11 months ago

1.1.1

1 year ago

1.1.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.0.17-alpha.0

2 years ago

0.0.16-alpha.0

2 years ago

0.0.15-alpha.0

2 years ago

0.0.14-alpha.0

2 years ago

0.0.13-alpha.0

2 years ago

0.0.12-alpha.0

2 years ago

0.0.9-alpha.0

2 years ago

0.0.10-alpha.0

2 years ago

0.0.11-alpha.0

2 years ago

0.0.8-alpha.0

2 years ago

0.0.6-alpha.0

2 years ago

0.0.7-alpha.0

2 years ago

0.0.5-alpha.0

2 years ago

0.0.4-alpha.0

2 years ago

0.0.3-alpha.0

2 years ago

0.0.2-alpha.0

2 years ago

0.0.1-alpha.0

2 years ago