4.6.0 • Published 12 days ago

@wayke-se/components-react v4.6.0

Weekly downloads
46
License
MIT
Repository
github
Last release
12 days ago

Components React

This repository contains components for search and items to use on external websites.

Notes

  • Starting from version 2.0.0 and above will require import of @wayke.se/components-react/assets/default.css in order to apply basic styling to the gallery.

Usage

Install

npm install @wayke-se/components-react

Install peer dependencies

npm install react react-dom styled-components
import React from 'react';
import WaykeComposite from '@wayke-se/components-react'
import '@wayke.se/components-react/assets/default.css';

const ProviderSettings: WaykeProviderSettings = {
  graphQlUrl: "https://gql.wayketech.se/query",
  url: "https://test-ext-api.wayketech.se/vehicles",
  urlMlt: "https://test-ext-api.wayketech.se/vehicles-mlt-ext",
  ecomSettings: {
    url: "OPTIONAL_ECOM_URL",
  },
  googleMapsApiKey: "OPTIONAL_GOOGLE_MAPS_STATIC_API_KEY",
}

const App = () => (
  <WaykeComposite
    provider={ProviderSettings}
  />
);

WaykeComposite uses hash-route, i want to use path-route

In this case you need to make sure that you are in control of the routing where same html file is served for /your/path/to/this/component and /your/path/to/this/component/00000000-0000-0000-0000-000000000000.

import React from 'react';
import { WaykeCompositePath } from '@wayke-se/components-react'
import '@wayke.se/components-react/assets/default.css';

const App = () => (
  <WaykeCompositePath
    composite={{
      ...,
      pathRoute: "your/path/to/this/component/"
    }}
    provider={ProviderSettings}
  />
);

I only want to use the search component

It's recomended to place WaykeProvider close to app-root in order to keep the cache

import React, { useCallback } from 'react';
import { WaykeProvider, WaykeSearch } from '@wayke-se/components-react'

const App = () => {
  const onClickSearchItem = useCallback((id: string) => {
    console.log(id);
  }, []);

  return (
    <WaykeProvider {...ProviderSettings}>
      <WaykeSearch onClickSearchItem={onClickSearchItem} />
    </WaykeProvider>
  );
};

I only want to use the Search Item component

It's recomended to place WaykeItemProvider close to app-root in order to keep the cache

import React, { useCallback } from 'react';
import { WaykeItemProvider, WaykeSearchItem } from '@wayke-se/components-react'
import '@wayke.se/components-react/assets/default.css';

const App = ({}) => {
  const id = 'd01f79a3-7552-49c4-9d4d-deb3aa581c31';

  // Optional, get id when related vehicles are clicked
  const onClickSearchItem = useCallback((id: string) => {
    console.log(id);
  }, []);

  return (
    <WaykeItemProvider {...ProviderSettings}>
      <WaykeSearchItem id={id} onClickSearchItem={onClickSearchItem} />
    </WaykeItemProvider>
  );
};

Components

WaykeComposite

PropertyTypeRequired
providerWaykeProviderSettingstrue
compositeWaykeCompositePropsfalse

WaykeSearchItem

PropertyTypeRequiredValue
idstringtrue
pathRoutestringfalse
hashRoutebooleanfalse
disableResetScrollOnInitbooleanfalse
placeholderImagestringfalse
onClickSearchItemfunctionfalse(id: string) => void
modifyDocumentTitleItembooleanfalse
  • Required
    • id - Guid that represents a vehicle.
  • Optional
    • pathRoute - If set to true, then if a item is clicked it will append /{pathRoute}/guid to the url.
    • hashRoute - If set to true, then if a item is clicked it will append #guid to the url (is not used if pathRoute is set).
    • disableResetScrollOnInit - Loading the item page resets the scroll, here it's possible to disable it.
    • placeholderImage - Provide custom placeholder image when image is missing.
    • onClickSearchItem - Function that can be provided that will be triggered once a item is clicked.
    • modifyDocumentTitleItem - Update document title with vehicle data

WaykeSearch

PropertyTypeValues
pathRoutestring
hashRouteboolean
filterListSearchFilterTypes[]
initialQueryParamsURLSearchParams or stringquery, manufacturer, modelSeries, fuelType, gearboxType, branch, color, environmentClass, properties.segment, drivingWheel, price.min, price.max, mileage.min, mileage.max, modelYear.min, modelYear.max
removeSearchBarboolean
removeFilterOptionsboolean
placeholderImagestring
onClickSearchItemfunction(id: string) => void
modifyDocumentTitleSearchstring
  • Optional
    • pathRoute - If set to true, then if a item is clicked it will append /guid to the url.
    • hashRoute - If set to true, then if a item is clicked it will append #guid to the url (is not used if pathRoute is set).
    • filterList - Select what filters that should be visible and in whiched order, drivingWheel, price, mileage, modelYear
    • initialQueryParams - Set the default filter that should be applid upon init.
    • removeSearchBar - Removes search bar.
    • removeFilterOptions - Removes filter options.
    • placeholderImage - Provide custom placeholder image when image is missing.
    • onClickSearchItem - Function that can be provided that will be triggered once a item is clicked.
    • modifyDocumentTitleSearch - Set custom document title

Types

WaykeCompositeProps

WaykeSearchItem & WaykeSearch combined without id

WaykeProviderSettings

PropertyTypeRequired
urlstringtrue
urlMltstringtrue
graphQlUrlstringtrue
apiKeystringfalse
googleMapsApiKeystringfalse
googleMapsMarkerstringfalse
ecomSettingsEcomSettingsfalse
useQueryParamsFromUrlbooleanfalse
  • Required
    • url - Url to Wayke ext-api.
    • urlMlt - Url to Wayke ext-api for related vehicles. Used when displaying related vehicles for a given vehicle. If not provided url will be used, but then related vehicles are change to latest added.
    • graphQlUrl - Url to the GraphQl endpoint.
  • Optional
    • apiKey - To use with wayke ext-api. If no api key is provided, then the origin of the request is used as a api key.
    • googleMapsApiKey - Google Maps Static will be used if a googleMapsApiKey is provided, else the map will open in another tab (Google Maps). Provide a Google Maps Static API key.
    • googleMapsMarker - Provide a custom marker, url.
    • ecomSettings - Allow the use of ecom.
    • useQueryParamsFromUrl - Reading/writing query strings from/to the url. If true and initialQueryParams also exist, then initialQueryParams is added if the key doesnt exist in the url.

EcomSettings

PropertyTypeRequired
urlStringtrue
useBankIdbooleanfalse
displayBankIdAlertbooleanfalse
serviceLogotypeUrlstringfalse
bankIdThumbprintstringfalse
  • Required
    • url - Wayke ecom url.
  • Optional
    • useBankId: If you want to use Swedish Bank Id to identify the user and fetch their personal information, set this to true (false by default).
    • displayBankIdAlert: By default, the user is identified with BankId to Wayke. To clarify that the purchase is to another retailer, an optional alert can be displayed in the BankId identification step (false by default).
    • serviceLogotypeUrl: Set the logo. By default the manufacturers logo will be used.
    • bankIdThumbprint: Custom bank id certificate thumbprint .

For more information about settings and styling regarding @wayke-se/ecom see https://github.com/wayke-se/wayke-ecom-react.

WaykeItemProviderSettings

PropertyTypeRequired
urlstringtrue
urlMltstringtrue
graphQlUrlstringtrue
apiKeystringfalse
googleMapsApiKeystringfalse
googleMapsMarkerstringfalse
ecomSettingsEcomSettingsfalse
  • Required
    • url - Url to Wayke ext-api.
    • urlMlt - Url to Wayke ext-api for related vehicles. Used when displaying related vehicles for a given vehicle. If not provided url will be used, but then related vehicles are change to latest added.
    • graphQlUrl - Url to the GraphQl endpoint.
  • Optional
    • apiKey - To use with wayke ext-api. If no api key is provided, then the origin of the request is used as a api key.
    • googleMapsApiKey - Google Maps Static will be used if a googleMapsApiKey is provided, else the map will open in another tab (Google Maps). Provide a Google Maps Static API key.
    • googleMapsMarker - Provide a custom marker, url.
    • ecomSettings - Allow the use of ecom.

SearchFilterTypes

PropertyTypeRequiredValues
filterNameSearchFilterNameTypestruemanufacturer, modelSeries, fuelType, gearboxType, branch, color, environmentClass, properties.segment, drivingWheel, price, mileage, modelYear
displayNamestringfalse
  • displayName override default translation of title

Set initial query filter

import WaykeComposite from '@wayke-se/components-react'

const App = () => (
  <WaykeComposite
    provider={ProviderSettings}
    composite={{,
      initialQueryParams,
    }}
  />
)

Custom usage examples

Select only some of the filters

Order will have effect

import WaykeComposite from '@wayke-se/components-react'

const filterList: SearchFilterTypes[] = [
  {
    filterName: 'price',
  },
  {
    filterName: 'modelSeries',
    displayName: 'MODEL SERIES',
  },
];

const App = () => (
  <WaykeComposite
    provider={ProviderSettings}
    composite={{,
      filterList={filterList}
    }}
  />
)

Subscribe to events

import { WaykePubSub}  from '@wayke-se/components-react';

const event = {
  eventName: 'ItemClicked',
  callback: (id) => <('subscribed ItemClicked:', id),
};

WaykePubSub.subscribe(event);
WaykePubSub.unsubscribe(event);
MethodArguments
subscribeEventBase
unsubscribe-
publisheventName: string, ...arg: any

EventBase

eventNamecallback
HashRouteChange(id: string) => void
ItemClicked(id: string) => void
EcomOnUserEvent(userEvent: string, currentStep: string) => void
ImagesClick() => void
OptionsClick() => void
PhonenumberVisible() => void
PhonenumberCall() => void
MailVisible() => void
InsuranceInterest() => void
FinanceInterest() => void
All(eventName: string, data: any[]) => void
  • All - Subscribes to all events.

Theme

It is possible to apply a custom theme using CSS. The things that can be styled are:

  • Primary brand color
  • Secondary brand color
  • Font (regular)
  • Font (bold)

To style the components, copy the following snippet into your CSS file and modify are your needs.

/* === Color === */

/*
  Primary (background-color)
  Used to add primary background-color to elements. Should also include
  a color for text placed on top of the primary color.
*/
.wayke__theme.wayke__color--primary-bg {
  background-color: #ff5a1c;
  color: #fff;
}

/*
  Primary (text color)
  Used to add primary color to text. Make sure to add the same color as
  in the background-color selector above.
*/
.wayke__theme.wayke__color--primary-text {
  color: #ff5a1c;
}

/*
  Secondary (background-color)
  Used to add secondary background-color to elements. Should also include
  a color for text placed on top of the primary color.
*/
.wayke__theme.wayke__color--secondary-bg {
  background-color: #ebebeb;
  color: #ff5a1c;
}

/*
  Accent (background-color)
  Used to add accent background-color to elements. Should also include
  a color for text placed on top of the primary color.
*/
.wayke__theme.wayke__color--accent-bg {
  background-color: #f8f8f8;
  color: #000;
}

/* === Font === */

/*
  Regular
  This is the regular font used on most text elements. It is recommended
  to use a light (300) or regular (400) font for this type.
*/
.wayke__theme.wayke__font--regular {
  font-family: sans-serif;
  font-weight: 300;
  font-style: normal;
  font-stretch: normal;
  letter-spacing: 0.02em;
}

/*
  Bold
  This font will be applied to headings and some other elements using
  the same styling.
*/
.wayke__theme.wayke__font--bold {
  font-family: sans-serif;
  font-weight: 700;
  font-style: normal;
  font-stretch: normal;
  letter-spacing: 0.02em;
}

...or if you want to use it as Sass (.scss):

.wayke__theme {
  $c-primary: #ff5a1c;
  $c-primaryText: #fff; // Text placed on top of $c-primary

  &.wayke__color {
    &--primary-bg {
      background-color: $c-primary;
      color: $c-primaryText;
    }

    &--primary-text {
      color: $c-primary;
    }
  }

  &.wayke__font {
    &--regular {
      font-family: sans-serif;
      font-weight: 300;
    }

    &--bold {
      font-family: sans-serif;
      font-weight: 700;
    }
  }
}

Ecom theme

The default ecom css can be found and imported node_module/@wayke-se/ecom-react/assets/styles/default.css.

It is highly recommended to NOT add or remove any properties defined above in the color selectors. However, since fonts usually requires more configuration we encourage you to add the necessary font styling required to match your current profile. If you add new properties to the font selectors, please be careful and ensure everything looks as intended before going into production.

Run example from repo

This repository contains a example app that uses @wayke-se/components-react.

To start the example create an .env file in root.

WAYKE_HOST=YOUR_HOST_1,YOUR_HOST_2
WAYKE_SEARCH_URL=https://test-ext-api.wayketech.se/vehicles
WAYKE_SEARCH_MLT_URL=https://test-ext-api.wayketech.se/vehicles-mlt-ext
WAYKE_SEARCH_X_API_KEY=YOUR_API_KEY
WAYKE_GRAPH_QL_URL=https://gql.wayketech.se/query
WAYKE_ECOM_URL=https://ecom.wayketech.se
GOOGLE_MAPS_API_KEY=YOUR_GOOGLE_MAPS_STATIC_API_KEY
  • WAYKE_SEARCH_MLT_URL - An optional flag. Will fetch related vehicles to current vehicle. If not provided WAYKE_SEARCH_URL will be used instead, but will fetch latest vehicles.

Then run the following:

npm install
cd example
npm install
npm start

WAYKE_HOST can be used instead of using and exposing the WAYKE_SEARCH_X_API_KEY. If, for example, your development host is test.com.localhost Update your local host file and add: 127.0.0.1 test.com.localhost This will change the origin, while still pointing to localhost. Start the example and open test.com.localhost:5000.

To add more hosts, add all to your local host file and then update WAYKE_HOST (comma separated):

WAYKE_HOST=a.com.localhost,b.com.localhost

a.com.localhost:5000 and b.com.localhost:5000 can now be accessed.

Available Routes (Independent)

WaykeComposite

http://localhost:5000

WaykeSearch With WaykeProvider

http://localhost:5000/search

WaykeSearchItem With WaykeProvider

http://localhost:5000/search-item/d01f79a3-7552-49c4-9d4d-deb3aa581c31

Example repositories

React and Typescript example

https://github.com/wayke-se/components-react-boilerplate

Non-React with/without Typescript example

https://github.com/wayke-se/components-react-example

4.6.1-beta.1

12 days ago

4.6.0

15 days ago

4.6.0-beta.1

15 days ago

4.5.0-beta.1

1 month ago

4.5.0

1 month ago

4.4.0

3 months ago

4.4.0-beta.1

3 months ago

4.3.2

3 months ago

4.3.2-beta.1

3 months ago

4.3.1

3 months ago

4.3.1-beta.1

3 months ago

4.3.0

3 months ago

4.3.0-beta.1

3 months ago

4.2.0-beta.1

4 months ago

4.2.0

4 months ago

4.1.0-beta.1

4 months ago

4.1.0

4 months ago

4.0.1

4 months ago

4.0.0

4 months ago

4.0.0-beta.19

5 months ago

4.0.0-beta.17

5 months ago

4.0.0-beta.16

5 months ago

4.0.0-beta.18

5 months ago

3.8.2

5 months ago

4.0.0-beta.15

5 months ago

4.0.0-beta.14

5 months ago

4.0.0-beta.11

6 months ago

4.0.0-beta.10

6 months ago

4.0.0-beta.13

6 months ago

4.0.0-beta.12

6 months ago

4.0.0-beta.8

6 months ago

4.0.0-beta.9

6 months ago

4.0.0-beta.7

6 months ago

4.0.0-beta.6

6 months ago

4.0.0-beta.5

6 months ago

4.0.0-beta.4

6 months ago

4.0.0-beta.3

6 months ago

4.0.0-beta.2

6 months ago

4.0.0-beta.1

6 months ago

3.9.0-beta.5

6 months ago

3.9.0-beta.6

6 months ago

3.9.0-beta.1

6 months ago

3.9.0-beta.2

6 months ago

3.9.0-beta.3

6 months ago

3.9.0-beta.4

6 months ago

3.8.1

8 months ago

3.8.0

8 months ago

3.8.0-beta.1

8 months ago

3.7.0-beta.1

11 months ago

3.7.0

11 months ago

3.6.2

12 months ago

3.6.2-beta.1

12 months ago

3.6.1-beta.1

1 year ago

3.6.1

1 year ago

3.6.0

1 year ago

3.6.0-beta.1

1 year ago

3.5.3

1 year ago

3.5.3-beta.1

1 year ago

3.5.2

1 year ago

3.5.1

1 year ago

3.5.0

1 year ago

3.4.0

1 year ago

3.3.1

2 years ago

3.3.2

2 years ago

3.3.0

2 years ago

3.2.0

2 years ago

3.1.0

2 years ago

3.1.0-beta.1

2 years ago

3.1.0-beta.2

2 years ago

3.0.0

2 years ago

3.0.0-beta.11

2 years ago

3.0.0-beta.12

2 years ago

3.0.0-beta.13

2 years ago

3.0.0-beta.14

2 years ago

3.0.0-beta.1

2 years ago

3.0.0-beta.3

2 years ago

3.0.0-beta.2

2 years ago

3.0.0-beta.5

2 years ago

3.0.0-beta.4

2 years ago

3.0.0-beta.7

2 years ago

3.0.0-beta.6

2 years ago

3.0.0-beta.9

2 years ago

3.0.0-beta.8

2 years ago

3.0.0-beta.10

2 years ago

2.16.0

2 years ago

2.15.0

2 years ago

2.14.0

2 years ago

2.13.0

2 years ago

2.12.0

2 years ago

2.11.0

3 years ago

2.10.3

3 years ago

2.10.2

3 years ago

2.10.1

3 years ago

2.10.0

3 years ago

2.9.0

3 years ago

2.8.0

3 years ago

2.6.0

3 years ago

2.7.0

3 years ago

2.4.0

3 years ago

2.5.0

3 years ago

2.3.3

3 years ago

2.3.2

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.0

3 years ago

1.9.0

3 years ago

1.8.0

3 years ago

1.7.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.5

3 years ago

1.3.4

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

3 years ago

1.2.6

3 years ago

1.2.5

3 years ago

1.2.4

3 years ago

1.2.3

3 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.29

4 years ago

1.1.28

4 years ago

1.1.27

4 years ago

1.1.26

4 years ago

1.1.25

4 years ago

1.1.24

4 years ago

1.1.23

4 years ago

1.1.22

4 years ago

1.1.21

4 years ago

1.1.20

4 years ago

1.1.19

4 years ago

1.1.18

4 years ago

1.1.17

4 years ago

1.1.16

4 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.12

4 years ago

1.1.13

4 years ago

1.1.11

4 years ago

1.1.9

4 years ago

1.1.7

4 years ago

1.1.10

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.18

4 years ago

1.0.17

4 years ago

1.0.16

4 years ago

1.0.15

4 years ago

1.0.14

4 years ago

1.0.13

4 years ago

1.0.12

4 years ago

1.0.11

4 years ago

1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago