1.1.14 • Published 1 month ago

@omnic/widget-locations v1.1.14

Weekly downloads
-
License
-
Repository
-
Last release
1 month ago

USAGE

Integration in standalone mode

When build in standalone mode the widget exposes window.OMNIC_WIDGET_LOCATIONS_CONFIG config object. Add script tag to your page and pass the config object to the widget like this:

<script>
  window.OMNIC_WIDGET_LOCATIONS_CONFIG = {
    INN: "INN",
    locale: "en",
    map: {
      provider: "google",
      center: [55.75, 37.57],
    },
    onPointClick: (point: CallbackPoint) => {
      // TODO: process point click
    },
  };
</script>

The onPointClick callback will be called when user clicks on a point on the map. The point object has the following structure:

type Coordinates = [number, number];

interface Country {
  uid: string;
  name: string;
  abbreviation: string;
}

interface Region {
  uid: string;
  name: string;
  national_id: string;
}

interface City {
  uid: string;
  name: string;
  region: Region;
  latitude: number;
  country: Country;
  longitude: number;
  national_id: string;
}

interface Location {
  city: City;
  house: string;
  block: string;
  street: string;
  office: string;
  region: Region;
  floor: unknown;
  latitude: number;
  country: Country;
  longitude: number;
  postal_index: string;
  full_address: string;
}

interface LocationPoint {
  uid: string;
  name: string;
  code: string;
  type: number;
  brand: string;
  status: number;
  images: string[];
  schedule: string[];
  max_length: number;
  max_weight: number;
  is_pickup: boolean;
  location: Location;
  description: string;
  is_favorite: boolean;
  pay_by_cash: boolean;
  pay_by_card: boolean;
  is_delivery: boolean;
  near_station?: string;
  location_name?: string;
  is_check_order: boolean;
  round_the_clock: boolean;
  is_dressing_room: boolean;
  near_metro_station?: string;
}

interface NormalizeAddressResponseData {
  country_name: string;
  country_code: string;
  region: string;
  city: string;
  latitude: number;
  longitude: number;
  street: string;
  house: string;
  block: string;
  office: string;
  postal_index: string;
  address: string;
  address_full: string;
  city_place_id: string;
  region_place_id: string;
  place_id: string;
}

export interface DeliveryPoint {
  coords: Coordinates;
  address: Nullable<string>;
}

export interface DeliveryPointWithFullAddress extends Omit<DeliveryPoint, "address"> {
  comment: string;
  address: Nullable<NormalizeAddressResponseData>;
  delivery_time: string;
  apartment_number: string;
  // pay_by_cash: boolean;
  // pay_by_card: boolean;
}

// THIS IS THE TYPE OF THE CALLBACK POINT
type CallbackPoint = LocationPoint | CourierDeliveryPoint;

Then OMNIC_WIDGET_LOCATIONS_CONFIG has the following structure:

PropertyTypeDescription
INNstringINN of the company that uses the widget
fontstringFont family to use
radiusnumberBorder radius of buttons
localestringLocale of the widget. Currently supported: en, ru
countrystringCountry code in ISO 3166-1 Alpha-2 format
paletteobjectPalette config object
palette.primarystringPrimary color of the widget. Example: #ff0000
palette.primary-darkstringDarker version of the primary color. Example: #cc0000
mapobjectMap config object. See below for details
logostringLogo type. Accepts default or llama
map.providerstringMap provider. Currently supported: google
map.centernumber[]Coordinates of the map center. Example: [55.75, 37.57]
map.initialZoomnumberInitial zoom level of the map. Example: 10
hideLogobooleanWhether to hide the logo
startScreenstringStart screen of the widget. Currently supported: map, selector
disableDeliverybooleanWhether to disable delivery option
inputsWidgetInputsControl over widget inputs
handlersWidgetHandlersHandlers config object
hideHeaderbooleanWhether to hide header
hideFiltersbooleanWhether to hide filters
hideDetailsbooleanWhether to hide details
hideSearchInputbooleanWhether to hide search input
hideMapControlsbooleanWhether to hide map controls
hideDeliveryTimebooleanWhether to hide delivery time
hideCloseButtonOnLocationScreenbooleanWhether to hide close button on location screen
disableGeolocationbooleanWhether to disable geolocation
onPointClickfunctionCallback that will be called when user clicks on a point on the map.
onLocationSelectfunctionCallback that will be called when user selects a location Callback will be called with google.maps.places.PlaceResult argument
onCloseLocationSelectorfunctionCallback that will be called when user closes location selector

WidgetInputs type has the following structure:

interface ForwardedInputElement extends Pick<HTMLInputElement, "focus" | "blur"> {
  setValue: (value: string) => void;
}

interface InputConfig {
  name: string;
  ref: RefObject<ForwardedInputElement>;
  onClick?: (name: string) => void;
}

interface WidgetInputs {
  /**
    Widget Map address input
   */
  address: InputConfig;
  /**
   * Widget city input
   */
  city: InputConfig;
  /**
   * Delivery apartment input
   */
  apartment: InputConfig;
  /**
   * Delivery comment input
   */
  comment: InputConfig;
}

WidgetHandlers type has the following structure:

interface LocationSelectorElement {
  open: () => void;
  close: () => void;
}

interface WidgetHandlers {
  locationSelector: RefObject<LocationSelectorElement>;
}

NOTE: when using screen keyboard do not forget to call focus() method for address and city inputs, so that autocomplete will appear.

Include styles.css and widget.umd.js in your page:

<link rel="stylesheet" href="styles.css" />
<script src="widget.umd.js"></script>

After that you can create a div block with id @omnic/widget-locations and widget will be rendered there:

<div id="@omnic/widget-locations"></div>

Integration in React mode

When build in React mode the widget exposes Widget component. First install a package:

npm install @omnic/widget-locations

Then import it and use like this:

import React from "react";

import { Widget } from "@omnic/widget-locations";
import type { LocationPoint, DeliveryPoint } from "@omnic/widget-locations";

import "@omnic/widget-locations/dist/lib/style.css";

const App = () => {
  const onPointClick = (point: LocationPoint | DeliveryPoint) => {
    // TODO: process point click
  };

  return (
    <Widget /> {/* 👈 don't forget to provide `config` props */}
  );
};

Widget component has the following props:

PropertyTypeDescription
configobjectConfig object. See above for details
optionsobjectOptions object
options.baseURLstringBase URL of the widget API. Example: https://widget.omnic.sh

DON'T FORGET to wrap the widget in a div with id @omnic/widget-locations, so that all css styles will be applied correctly.

DEVELOPMENT

Project setup

Install all dependencies:

$ npm install

Then build it in lib mode:

$ npm run build:lib

or standalone mode:

$ npm run build:app

Use npm run dev to start local development server.

API

All API and components are exposed in src/index.ts file.

src/main.tsx file is responsible for rendering the widget in standalone mode or in development mode.

1.1.14

1 month ago

1.1.13-develop.0

3 months ago

1.1.13

3 months ago

1.1.13-OCHN-2119.0

3 months ago

1.1.13-OCHN-2119.3

3 months ago

1.1.13-OCHN-2119.4

3 months ago

1.1.13-OCHN-2119.1

3 months ago

1.1.13-OCHN-2119.2

3 months ago

1.1.12

5 months ago

1.1.11

5 months ago

1.1.10

5 months ago

1.1.9

5 months ago

1.1.8

5 months ago

1.1.7

5 months ago

1.1.6

6 months ago

1.1.5

6 months ago

1.1.4

6 months ago

1.1.4-develop.2

6 months ago

1.1.4-develop.1

6 months ago

1.1.4-develop.0

6 months ago

1.1.3

6 months ago

1.1.3-develop.0

6 months ago

1.1.2

6 months ago

1.1.2-develop.7

6 months ago

1.1.2-develop.6

6 months ago

1.1.2-develop.5

6 months ago

1.1.2-develop.3

6 months ago

1.1.2-develop.2

6 months ago

1.1.2-develop.1

6 months ago

1.1.2-develop.0

6 months ago

1.1.1

6 months ago

1.1.0

6 months ago

1.0.98

6 months ago

1.0.96

6 months ago

1.0.95

6 months ago

1.0.94

6 months ago

1.0.93

6 months ago

1.0.92

7 months ago

1.0.91

7 months ago

1.0.90

7 months ago

1.0.89

7 months ago

1.0.88

7 months ago

1.0.86

7 months ago

1.0.85

7 months ago

1.0.84

7 months ago

1.0.83

7 months ago

1.0.82

7 months ago

1.0.81

7 months ago

1.0.80

7 months ago

1.0.79

7 months ago

1.0.78

7 months ago

1.0.77

7 months ago

1.0.76

7 months ago

1.0.75

7 months ago

1.0.74

7 months ago

1.0.73

7 months ago

1.0.72

7 months ago

1.0.71

7 months ago

1.0.70

7 months ago

1.0.69

7 months ago

1.0.68

7 months ago

1.0.67

7 months ago

1.0.67-dev.3

7 months ago

1.0.67-dev.2

7 months ago

1.0.67-dev.1

7 months ago

1.0.67-dev.0

7 months ago

1.0.66

7 months ago

1.0.65

7 months ago

1.0.64

7 months ago

1.0.63

7 months ago

1.0.62

7 months ago

1.0.61

7 months ago

1.0.60

7 months ago

1.0.59

7 months ago

1.0.58

8 months ago

1.0.57

8 months ago

1.0.56

8 months ago

1.0.55

8 months ago

1.0.54

8 months ago

1.0.53

8 months ago

1.0.52

8 months ago

1.0.51

8 months ago

1.0.50

8 months ago

1.0.48

8 months ago

1.0.47

8 months ago

1.0.46

8 months ago

1.0.45

8 months ago

1.0.44

8 months ago

1.0.43

8 months ago

1.0.42

8 months ago

1.0.41

9 months ago

1.0.40

9 months ago

1.0.39

9 months ago

1.0.38

9 months ago

1.0.37

9 months ago

1.0.36

9 months ago

1.0.35

9 months ago

1.0.34

9 months ago

1.0.33

9 months ago

1.0.32

9 months ago

1.0.31

9 months ago

1.0.30

9 months ago

1.0.29

9 months ago

1.0.28

9 months ago

1.0.27

9 months ago

1.0.26

9 months ago

1.0.25

9 months ago

1.0.24

9 months ago

1.0.23

9 months ago

1.0.22

9 months ago

1.0.21

9 months ago

1.0.20

9 months ago

1.0.19

9 months ago

1.0.17

9 months ago

1.0.15

10 months ago

1.0.14

10 months ago

1.0.13

10 months ago

1.0.12

10 months ago

1.0.11

10 months ago

1.0.10

10 months ago

1.0.9

10 months ago

1.0.8

10 months ago

1.0.7

10 months ago

1.0.6

10 months ago

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago