Skip to content

Commit fa2b610

Browse files
committed
[update] config, info and cardTemplates updated
1 parent cc2c34f commit fa2b610

3 files changed

Lines changed: 32 additions & 19 deletions

File tree

docs/api/config/booking-cardtemplate.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ You can also specify which fields to display using the [`cardShape`](/api/config
1919
### Usage
2020

2121
~~~jsx {}
22-
cardTemplate?: (item: obj) => string;
22+
cardTemplate?: ({item: obj}) => string;
2323
~~~
2424

2525
### Parameters
@@ -45,10 +45,12 @@ In the example below we create a function that takes the `card` object and retur
4545
flex-direction: column;
4646
gap: 4px;
4747
}
48-
// other styles
48+
/* other styles */
4949
</style>
5050

5151
<script>
52+
const { Booking, template } = booking; //import template helper
53+
5254
function cardPreviewTemplate({ card }) {
5355
return `
5456
<div class="custom-preview" data-action="preview-click">
@@ -69,11 +71,11 @@ In the example below we create a function that takes the `card` object and retur
6971
`;
7072
}
7173
72-
const widget = new Booking("#root", {
73-
data,
74-
cardTemplate: template(card => cardPreviewTemplate(card)),
75-
});
76-
// other parameters
74+
const widget = new Booking("#root", {
75+
data,
76+
cardTemplate: template(card => cardPreviewTemplate(card)), // pass the function to Booking configuration
77+
});
78+
// other parameters
7779
</script>
7880
~~~
7981

docs/api/config/booking-infotemplate.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ description: You can learn about the infoTemplate config in the documentation of
1313
### Usage
1414

1515
~~~jsx {}
16-
infoTemplate?: (item: obj, slot: obj) => string;
16+
infoTemplate?: ({item: obj, slot: number}) => string;
1717
~~~
1818

1919
### Parameters
2020

21-
`infoTemplate` takes the `card` item object and selected `slot` object as input and returns a string of HTML.
21+
`infoTemplate` takes the `card` item object and selected `slot` timestamp as input and returns a string of HTML.
2222

2323

2424
### Example
@@ -27,7 +27,6 @@ In the example below, we define the `cardInfoTemplate` function that will genera
2727

2828
~~~html
2929
<style>
30-
/* custom info */
3130
.custom-info {
3231
display: flex;
3332
flex-direction: column;
@@ -45,10 +44,12 @@ In the example below, we define the `cardInfoTemplate` function that will genera
4544
background: rgba(128, 128, 155, 0.12);
4645
border-radius: 8px;
4746
}
48-
// other styles
47+
/* other styles */
4948
</style>
5049

5150
<script>
51+
const { Booking, template } = booking; // import template helper
52+
5253
function cardInfoTemplate({
5354
item,
5455
slot,
@@ -69,6 +70,11 @@ In the example below, we define the `cardInfoTemplate` function that will genera
6970
</div>
7071
`;
7172
}
73+
74+
const widget = new Booking("#root", {
75+
data,
76+
infoTemplate: template(item => cardInfoTemplate(item)), // pass the function to the widget configuration
77+
});
7278
</script>
7379
~~~
7480

docs/guides/configuration.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ First, create a function that takes a card object and returns a string of HTML.
9090
flex-direction: column;
9191
gap: 4px;
9292
}
93-
// other styles
93+
/* other styles */
9494
</style>
9595

9696
<script>
97+
const { Booking, template } = booking;
98+
9799
function cardPreviewTemplate({ card }) {
98100
return `
99101
<div class="custom-preview" data-action="preview-click">
@@ -116,9 +118,11 @@ First, create a function that takes a card object and returns a string of HTML.
116118
</script>
117119
~~~
118120

119-
Then you need to assign the`cardTemplate` property to your custom template function.
121+
Then you also need to import the template helper and assign the`cardTemplate` property to your custom template function.
120122

121123
~~~jsx
124+
const { Booking, template } = booking;
125+
122126
const widget = new Booking("#root", {
123127
data,
124128
cardTemplate: template(card => cardPreviewTemplate(card)),
@@ -436,7 +440,6 @@ To apply a template, you need to define the function that will generate the cust
436440

437441
~~~html
438442
<style>
439-
/* custom info */
440443
.custom-info {
441444
display: flex;
442445
flex-direction: column;
@@ -454,10 +457,12 @@ To apply a template, you need to define the function that will generate the cust
454457
background: rgba(128, 128, 155, 0.12);
455458
border-radius: 8px;
456459
}
457-
// other styles
460+
/* other styles */
458461
</style>
459462

460463
<script>
464+
const { Booking, template } = booking;
465+
461466
function cardInfoTemplate({
462467
item,
463468
slot,
@@ -481,14 +486,14 @@ To apply a template, you need to define the function that will generate the cust
481486
</script>
482487
~~~
483488

484-
Then pass the `infoTemplate` function into the Booking configuration as follows:
489+
Then you also need to import the template helper and pass the `infoTemplate` function into the Booking configuration as follows:
485490

486491
~~~jsx
492+
const { Booking, template } = booking;
493+
487494
const widget = new Booking("#root", {
488495
data,
489-
infoTemplate: template(item =>
490-
cardInfoTemplate(item)
491-
),
496+
infoTemplate: template(item => cardInfoTemplate(item)),
492497
});
493498
~~~
494499

0 commit comments

Comments
 (0)