@duffel/components 3.3.1 → 3.4.0
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 +117 -36
- package/components/DuffelCardForm/lib/types.d.ts +4 -2
- package/components/MapboxPlacesLookup/MapboxPlacesLookup.d.ts +9 -0
- package/components/MapboxPlacesLookup/MapboxPlacesLookupCustomElement.d.ts +13 -0
- package/components/MapboxPlacesLookup/lib/getPlacesFromMapboxClient.d.ts +7 -0
- package/custom-elements.d.ts +1 -0
- package/custom-elements.js +51 -22
- package/custom-elements.js.map +4 -4
- package/index.js +4 -4
- package/index.js.map +3 -3
- package/package.json +6 -11
- package/stories/MapboxPlacesLookup.stories.d.ts +5 -0
- package/tsconfig.tsbuildinfo +1 -1
- /package/components/{AirlineLogo → shared}/AirlineLogo.d.ts +0 -0
package/README.md
CHANGED
|
@@ -2,67 +2,148 @@
|
|
|
2
2
|
|
|
3
3
|
This package is a component library to help you build your travel product using the [Duffel API](https://duffel.com/docs).
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Getting started
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
There are 3 different ways to integrate the components into your website. This will depend on which technology you are using. We'll use the ancillaries component as an example, but the same steps will apply for other components.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
yarn add @duffel/components
|
|
11
|
-
# -- or --
|
|
12
|
-
npm i @duffel/components
|
|
13
|
-
```
|
|
9
|
+
### Integrating React component
|
|
14
10
|
|
|
15
|
-
|
|
11
|
+
1. Install the package:
|
|
16
12
|
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
```sh
|
|
14
|
+
yarn add @duffel/components
|
|
15
|
+
# -- or --
|
|
16
|
+
npm i @duffel/components
|
|
17
|
+
```
|
|
21
18
|
|
|
22
|
-
|
|
19
|
+
2. Import the component from `@duffel/components`
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
```javascript
|
|
22
|
+
import { DuffelAncillaries } from "@duffel/components";
|
|
23
|
+
```
|
|
25
24
|
|
|
26
|
-
|
|
25
|
+
3. Render the component with the desired props
|
|
27
26
|
|
|
28
|
-
|
|
27
|
+
```jsx
|
|
28
|
+
<DuffelAncillaries
|
|
29
|
+
offer_id="fixture_off_1"
|
|
30
|
+
services={["bags", "seats"]}
|
|
31
|
+
passengers={[...]}
|
|
32
|
+
onPayloadReady={console.log}
|
|
33
|
+
/>
|
|
34
|
+
```
|
|
29
35
|
|
|
30
|
-
|
|
36
|
+
### Integrating HTML custom element
|
|
31
37
|
|
|
32
|
-
|
|
38
|
+
If you are not using React but still in a node environment, you can:
|
|
33
39
|
|
|
34
|
-
|
|
40
|
+
1. Install the package:
|
|
35
41
|
|
|
36
|
-
|
|
42
|
+
```sh
|
|
43
|
+
yarn add @duffel/components
|
|
44
|
+
# -- or --
|
|
45
|
+
npm i @duffel/components
|
|
46
|
+
```
|
|
37
47
|
|
|
38
|
-
|
|
48
|
+
2. Import the component render function and event listeners from `@duffel/components/custom-elements`
|
|
39
49
|
|
|
40
|
-
|
|
50
|
+
```javascript
|
|
51
|
+
import {
|
|
52
|
+
renderDuffelAncillariesCustomElement,
|
|
53
|
+
onDuffelAncillariesPayloadReady,
|
|
54
|
+
} from "@duffel/components/custom-elements";
|
|
55
|
+
```
|
|
41
56
|
|
|
42
|
-
|
|
57
|
+
3. Include the custom element in your HTML
|
|
43
58
|
|
|
44
|
-
|
|
59
|
+
```html
|
|
60
|
+
<duffel-ancillaries></duffel-ancillaries>
|
|
61
|
+
```
|
|
45
62
|
|
|
46
|
-
|
|
63
|
+
4. Call the render function with the right properties to render the custom element:
|
|
47
64
|
|
|
48
|
-
|
|
65
|
+
```javascript
|
|
66
|
+
renderDuffelAncillariesCustomElement({
|
|
67
|
+
offer_id: "fixture_off_1",
|
|
68
|
+
services: ["bags", "seats"],
|
|
69
|
+
passengers: [...],
|
|
70
|
+
});
|
|
71
|
+
```
|
|
49
72
|
|
|
50
|
-
|
|
73
|
+
5. Set up listeners for events triggered by the component:
|
|
51
74
|
|
|
52
|
-
|
|
75
|
+
```javascript
|
|
76
|
+
onDuffelAncillariesPayloadReady((data, metadata) => {
|
|
77
|
+
console.table(data);
|
|
78
|
+
console.table(metadata);
|
|
79
|
+
});
|
|
80
|
+
```
|
|
53
81
|
|
|
54
|
-
|
|
82
|
+
### Integrating custom element without node
|
|
55
83
|
|
|
56
|
-
|
|
84
|
+
If you are not in a node environment and can't rely on npm to install the package, we make it available through our CDN. Here's how to integrate it:
|
|
57
85
|
|
|
58
|
-
|
|
86
|
+
1. Include a script tag
|
|
59
87
|
|
|
60
|
-
|
|
88
|
+
```html
|
|
89
|
+
<!--
|
|
90
|
+
Replace VERSION with the desired version.
|
|
91
|
+
You can find them all on https://www.npmjs.com/package/@duffel/components?activeTab=versions
|
|
92
|
+
|
|
93
|
+
Replace COMPONENT with the desired component you'd like to use.
|
|
94
|
+
You can find the components available in the `./cdn-dist` directory after running `yarn build-and-publish --dry-run`
|
|
95
|
+
|
|
96
|
+
For example, for the duffel ancillaries component on version 3.3.1, use:
|
|
97
|
+
https://assets.duffel.com/components/3.3.1/duffel-ancillaries.js
|
|
98
|
+
-->
|
|
61
99
|
|
|
62
|
-
|
|
100
|
+
<script src="https://assets.duffel.com/components/VERSION/COMPONENT.js"></script>
|
|
101
|
+
```
|
|
63
102
|
|
|
64
|
-
|
|
103
|
+
2. Include the custom element tag in your HTML:
|
|
65
104
|
|
|
66
|
-
|
|
105
|
+
```html
|
|
106
|
+
<duffel-ancillaries></duffel-ancillaries>
|
|
107
|
+
```
|
|
67
108
|
|
|
68
|
-
|
|
109
|
+
3. Render the component with the required data. You can safely call this function as many times as you want, e.g., when your passenger data changes.
|
|
110
|
+
|
|
111
|
+
```javascript
|
|
112
|
+
const duffelAncillariesElement = document.querySelector("duffel-ancillaries");
|
|
113
|
+
|
|
114
|
+
duffelAncillariesElement.render({
|
|
115
|
+
offer_id: "fixture_off_1",
|
|
116
|
+
services: ["bags", "seats"],
|
|
117
|
+
passengers: [...],
|
|
118
|
+
});
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
4. Listen to the 'onPayloadReady' event on the component. `event.detail.data` contains the payload you need to send to Duffel's API to create an order.
|
|
122
|
+
|
|
123
|
+
```javascript
|
|
124
|
+
const duffelAncillariesElement =
|
|
125
|
+
document.querySelector("duffel-ancillaries");
|
|
126
|
+
|
|
127
|
+
duffelAncillariesElement.addEventListener("onPayloadReady", (event) =>
|
|
128
|
+
console.log("onPayloadReady\n", event.detail)
|
|
129
|
+
);
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## FAQ
|
|
133
|
+
|
|
134
|
+
### Are there integration guides?
|
|
135
|
+
|
|
136
|
+
- [Integrating the ancillaries component into your booking flow](https://duffel.com/docs/guides/ancillaries-component).
|
|
137
|
+
- [Collecting payments with Duffel Payments](https://duffel.com/docs/guides/collecting-customer-card-payments)
|
|
138
|
+
|
|
139
|
+
More guides are coming soon.
|
|
140
|
+
|
|
141
|
+
The `examples` folder is a great way to get started quickly and see fully functioning examples for every component.
|
|
142
|
+
|
|
143
|
+
### What components are available through npm?
|
|
144
|
+
|
|
145
|
+
The list of React components can be found in `src/index.ts`. If you are using custom elements, you can find all render functions and event listeners in `src/custom-elements.ts`.
|
|
146
|
+
|
|
147
|
+
### What components are available through the CDN?
|
|
148
|
+
|
|
149
|
+
Please check `entryPoints` in `config/esbuild.base.config.js`. It lists all the components we'll build and upload to the CDN.
|
|
@@ -39,9 +39,11 @@ export interface DuffelCardFormProps {
|
|
|
39
39
|
*/
|
|
40
40
|
styles?: DuffelCardFormStyles;
|
|
41
41
|
/**
|
|
42
|
-
* If you want to develop with a
|
|
42
|
+
* If you want to develop with in a different environment of the token proxy, you can choose it here.
|
|
43
|
+
*
|
|
44
|
+
* @default: `production`
|
|
43
45
|
*/
|
|
44
|
-
|
|
46
|
+
tokenProxyEnvironment?: "development" | "staging" | "production";
|
|
45
47
|
/**
|
|
46
48
|
* The actions you'd like the component to perform.
|
|
47
49
|
*
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Place } from "./lib/getPlacesFromMapboxClient";
|
|
3
|
+
export interface MapboxPlacesLookupProps {
|
|
4
|
+
mapboxPublicKey: string;
|
|
5
|
+
onPlaceSelected: (selection: Place) => void;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
inputClassName?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const MapboxPlacesLookup: React.FC<MapboxPlacesLookupProps>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { MapboxPlacesLookupProps } from "./MapboxPlacesLookup";
|
|
2
|
+
declare const CUSTOM_ELEMENT_TAG = "duffel-mapbox-places-lookup";
|
|
3
|
+
declare global {
|
|
4
|
+
namespace JSX {
|
|
5
|
+
interface IntrinsicElements {
|
|
6
|
+
[CUSTOM_ELEMENT_TAG]: React.DetailedHTMLProps<React.HTMLAttributes<HTMLElement>, HTMLElement>;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
type MapboxPlacesLookupCustomElementRenderArguments = Pick<MapboxPlacesLookupProps, "mapboxPublicKey" | "placeholder" | "inputClassName">;
|
|
11
|
+
export declare function renderMapboxPlacesLookupCustomElement(props: MapboxPlacesLookupCustomElementRenderArguments): void;
|
|
12
|
+
export declare function onMapboxPlacesLookupPlaceSelected(onPlaceSelected: MapboxPlacesLookupProps["onPlaceSelected"]): void;
|
|
13
|
+
export {};
|
package/custom-elements.d.ts
CHANGED
|
@@ -8,3 +8,4 @@ export { renderDuffelStaysRatingCustomElement } from "./components/Stays/StaysRa
|
|
|
8
8
|
export { renderDuffelStaysAmenitiesCustomElement } from "./components/Stays/StaysAmenitiesCustomElement";
|
|
9
9
|
export { renderDuffelStaysSummaryCustomElement } from "./components/Stays/StaysSummaryCustomElement";
|
|
10
10
|
export { renderDuffelStaysRoomRateCardCustomElement } from "./components/Stays/StaysRoomRateCardCustomElement";
|
|
11
|
+
export { renderMapboxPlacesLookupCustomElement, onMapboxPlacesLookupPlaceSelected, } from "./components/MapboxPlacesLookup/MapboxPlacesLookupCustomElement";
|