@omnic/widget-locations 1.0.14 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,48 +1,225 @@
1
- # Super Cool Widget
1
+ # OMNIC Widget Locations
2
2
 
3
- ## Инициализация проекта
3
+ # USAGE
4
4
 
5
- ```bash
6
- $ npm install
5
+ ## Integration in `standalone` mode
6
+
7
+ When build in `standalone` mode the widget exposes `window.OMNIC_WIDGET_LOCATIONS_CONFIG` config object.
8
+ Add script tag to your page and pass the config object to the widget like this:
9
+
10
+ ```html
11
+ <script>
12
+ window.OMNIC_WIDGET_LOCATIONS_CONFIG = {
13
+ INN: "INN",
14
+ locale: "en",
15
+ map: {
16
+ provider: "google",
17
+ center: [55.75, 37.57],
18
+ },
19
+ onPointClick: (point: CallbackPoint) => {
20
+ // TODO: process point click
21
+ },
22
+ };
23
+ </script>
7
24
  ```
8
25
 
9
- ## Сборка в режиме `React` библиотеки
26
+ The `onPointClick` callback will be called when user clicks on a point on the map. The `point` object has the following structure:
10
27
 
11
- ```bash
12
- $ npm run build:lib
28
+ ```typescript
29
+ type Coordinates = [number, number];
30
+
31
+ interface Country {
32
+ uid: string;
33
+ name: string;
34
+ abbreviation: string;
35
+ }
36
+
37
+ interface Region {
38
+ uid: string;
39
+ name: string;
40
+ national_id: string;
41
+ }
42
+
43
+ interface City {
44
+ uid: string;
45
+ name: string;
46
+ region: Region;
47
+ latitude: number;
48
+ country: Country;
49
+ longitude: number;
50
+ national_id: string;
51
+ }
52
+
53
+ interface Location {
54
+ city: City;
55
+ house: string;
56
+ block: string;
57
+ street: string;
58
+ office: string;
59
+ region: Region;
60
+ floor: unknown;
61
+ latitude: number;
62
+ country: Country;
63
+ longitude: number;
64
+ postal_index: string;
65
+ full_address: string;
66
+ }
67
+
68
+ interface LocationPoint {
69
+ uid: string;
70
+ name: string;
71
+ code: string;
72
+ type: number;
73
+ brand: string;
74
+ status: number;
75
+ images: string[];
76
+ schedule: string[];
77
+ max_length: number;
78
+ max_weight: number;
79
+ is_pickup: boolean;
80
+ location: Location;
81
+ description: string;
82
+ is_favorite: boolean;
83
+ pay_by_cash: boolean;
84
+ pay_by_card: boolean;
85
+ is_delivery: boolean;
86
+ near_station?: string;
87
+ location_name?: string;
88
+ is_check_order: boolean;
89
+ round_the_clock: boolean;
90
+ is_dressing_room: boolean;
91
+ near_metro_station?: string;
92
+ }
93
+
94
+ interface CourierPoint {
95
+ coords: Coordinates;
96
+ address: null | string;
97
+ }
98
+
99
+ interface CourierDeliveryPoint extends CourierPoint {
100
+ comment: string;
101
+ pay_by_cash: boolean;
102
+ pay_by_card: boolean;
103
+ delivery_time: string;
104
+ apartment_number: string;
105
+ }
106
+
107
+ // THIS IS THE TYPE OF THE CALLBACK POINT
108
+ type CallbackPoint = LocationPoint | CourierDeliveryPoint;
13
109
  ```
14
110
 
15
- Далее можно перейти в раздел `clients/react`, установить зависимости и протестировать
111
+ Then `OMNIC_WIDGET_LOCATIONS_CONFIG` has the following structure:
16
112
 
17
- ```bash
18
- $ cd clients/react
19
- $ npm install
20
- $ npm link
21
- $ npm run dev
113
+ | Property | Type | Description |
114
+ | -------------------- | -------- | -------------------------------------------------------------------- |
115
+ | INN | string | INN of the company that uses the widget |
116
+ | font | string | Font family to use |
117
+ | radius | number | Border radius of buttons |
118
+ | locale | string | Locale of the widget. Currently supported: `en`, `ru` |
119
+ | palette | object | Palette config object |
120
+ | palette.primary | string | Primary color of the widget. Example: `#ff0000` |
121
+ | palette.primary-dark | string | Darker version of the primary color. Example: `#cc0000` |
122
+ | map | object | Map config object. See below for details |
123
+ | map.provider | string | Map provider. Currently supported: `google`, `yandex` |
124
+ | map.center | number[] | Coordinates of the map center. Example: `[55.75, 37.57]` |
125
+ | onPointClick | function | Callback that will be called when user clicks on a point on the map. |
126
+
127
+ Include `styles.css` and `widget.umd.js` in your page:
128
+
129
+ ```html
130
+ <link rel="stylesheet" href="styles.css" />
131
+ <script src="widget.umd.js"></script>
132
+ ```
133
+
134
+ After that you can create a div block with id `@omnic/widget-locations` and widget will be rendered there:
135
+
136
+ ```html
137
+ <div id="@omnic/widget-locations"></div>
22
138
  ```
23
139
 
24
- ## Сборка в режиме `standalone` приложения
140
+ ## Integration in `React` mode
141
+
142
+ When build in `React` mode the widget exposes `Widget` component. First install a package:
25
143
 
26
144
  ```bash
27
- $ npm run build:app
145
+ npm install @omnic/widget-locations
146
+ ```
147
+
148
+ Then import it and use like this:
149
+
150
+ ```tsx
151
+ import React from "react";
152
+ import { Widget } from "@omnic/widget-locations";
153
+ import type { LocationPoint, CourierPoint } from "@omnic/widget-locations";
154
+
155
+ const App = () => {
156
+ const onPointClick = (point: LocationPoint | CourierPoint) => {
157
+ // TODO: process point click
158
+ };
159
+
160
+ return (
161
+ <div id="@omnic/widget-locations">
162
+ <Widget
163
+ config={{
164
+ INN: "INN",
165
+ locale: "en",
166
+ map: {
167
+ provider: "google",
168
+ center: [40.1772, 44.50349],
169
+ },
170
+ radius: 2,
171
+ font: "Roboto",
172
+ palette: {
173
+ primary: "#0cb834",
174
+ "primary-dark": "#079b1f",
175
+ },
176
+ onPointClick: console.log,
177
+ }}
178
+ options={{
179
+ baseURL: "https://widget.omnic.sh",
180
+ }}
181
+ />
182
+ </div>
183
+ );
184
+ };
28
185
  ```
29
186
 
30
- Далее можно перейти в раздел `clients/vanilla`, установить зависимости и протестировать
187
+ `Widget` component has the following props:
188
+
189
+ | Property | Type | Description |
190
+ | --------------- | ------ | -------------------------------------------------------------- |
191
+ | config | object | Config object. See above for details |
192
+ | options | object | Options object |
193
+ | options.baseURL | string | Base URL of the widget API. Example: `https://widget.omnic.sh` |
194
+
195
+ DO NOT FORGET to wrap the widget in a div with id `@omnic/widget-locations`, so that all css styles will be applied correctly.
196
+
197
+ # DEVELOPMENT
198
+
199
+ ## Project setup
200
+
201
+ Install all dependencies:
31
202
 
32
203
  ```bash
33
- $ cd clients/vanilla
34
204
  $ npm install
35
- $ npm run dev
36
205
  ```
37
206
 
38
- ## Локальная разработка
207
+ Then build it in `lib` mode:
208
+
209
+ ```bash
210
+ $ npm run build:lib
211
+ ```
212
+
213
+ or `standalone` mode:
39
214
 
40
215
  ```bash
41
- $ npm run dev
216
+ $ npm run build:app
42
217
  ```
43
218
 
44
- ## Инкапсуляция библиотеки
219
+ Use `npm run dev` to start local development server.
220
+
221
+ # API
45
222
 
46
- Всё API что должно быть доступно клиенту должно быть экспортировано в `src/index.ts` фале.
223
+ All API and components are exposed in `src/index.ts` file.
47
224
 
48
- `src/main.tsx` файл отвечает за рендеринг приложения в режиме `standalone` или в режиме разработки.
225
+ `src/main.tsx` file is responsible for rendering the widget in `standalone` mode or in development mode.
@@ -1,2 +1,2 @@
1
1
  import { MapProvider } from '../types/config';
2
- export declare const useMapFactory: (provider: MapProvider) => import("react").FC<import("../types/map").MapProps> | import("react").NamedExoticComponent<import("../types/map").MapProps>;
2
+ export declare const useMapFactory: (provider: MapProvider) => import("react").FC<import("..").MapProps> | import("react").NamedExoticComponent<import("..").MapProps>;
@@ -64,6 +64,8 @@ export declare const resources: {
64
64
  delivery_time: string;
65
65
  apartment_number: string;
66
66
  comment: string;
67
+ pay_by_cash: string;
68
+ pay_by_card: string;
67
69
  };
68
70
  courier_balloon: {
69
71
  title: string;
@@ -134,6 +136,8 @@ export declare const resources: {
134
136
  delivery_time: string;
135
137
  apartment_number: string;
136
138
  comment: string;
139
+ pay_by_cash: string;
140
+ pay_by_card: string;
137
141
  };
138
142
  courier_balloon: {
139
143
  title: string;
@@ -1 +1,7 @@
1
1
  export * from "./views/Widget";
2
+ export * from "./types/map";
3
+ export * from "./types/cities";
4
+ export * from "./types/config";
5
+ export * from "./types/countries";
6
+ export * from "./types/points";
7
+ export * from "./types/regions";
@@ -10,22 +10,22 @@ export interface PointsList {
10
10
  }
11
11
  export interface LocationPoint {
12
12
  uid: string;
13
- type: number;
14
- code: string;
15
13
  name: string;
14
+ code: string;
15
+ type: number;
16
16
  brand: string;
17
17
  status: number;
18
18
  images: string[];
19
- location: Location;
20
- is_pickup: boolean;
21
- max_weight: number;
19
+ schedule: string[];
22
20
  max_length: number;
21
+ max_weight: number;
22
+ is_pickup: boolean;
23
+ location: Location;
23
24
  description: string;
24
- schedule: Schedule[];
25
- is_delivery: boolean;
26
- pay_by_card: boolean;
27
- pay_by_cash: boolean;
28
25
  is_favorite: boolean;
26
+ pay_by_cash: boolean;
27
+ pay_by_card: boolean;
28
+ is_delivery: boolean;
29
29
  near_station?: string;
30
30
  location_name?: string;
31
31
  is_check_order: boolean;
@@ -44,13 +44,6 @@ export interface CourierDeliveryPoint extends CourierPoint {
44
44
  delivery_time: string;
45
45
  apartment_number: string;
46
46
  }
47
- export interface Schedule {
48
- end: string;
49
- day: number;
50
- start: string;
51
- time?: string;
52
- work_day?: boolean;
53
- }
54
47
  export interface Location {
55
48
  city: City;
56
49
  house: string;