DHTMLX Booking. Svelte integration example
Demo of DHTMLX Booking integration with Svelte using the official GitHub demo. Shows the component wrapper, a confirm handler, and cleanup on destroy. For a step-by-step setup, see the detailed Svelte integration guide.
View on GitHub - open the repository and click "Open in Codespaces" on the README page to launch a configured Svelte app with DHTMLX Booking. No local setup required.
Svelte binds the container with bind:this={container}, which gives the component the DOM node the widget needs. The wrapper stays small, since the widget renders itself and takes its settings from one configuration object.
onMount creates the instance once the bound element is on the page, so the node exists before the widget looks for it. The cards arrive from the parent as a data prop and go straight into the configuration. In that same callback the demo calls setConfirmHandler, which answers each slot a visitor confirms. The instance is kept in a variable so onDestroy can call destructor() when Svelte removes the component.
Solution overview
To run DHTMLX Booking inside a Svelte application:
- Import the package and the styles -
import { Booking } from "@dhx/trial-booking"and itsbooking.css. - Bind the container with
<div bind:this={container} class="widget"></div>and give the class a height. - Declare the prop with
export let data, and pass the cards from the parent. - Create the widget in
onMount-booking = new Booking(container, { data }). - Answer the confirmation -
booking.setConfirmHandler(event => ...)runs when a visitor confirms a slot. The demo waits a second and picksconfirm.done()orconfirm.error()at random, so both results of the booking dialog are visible. - Destroy it in
onDestroywithbooking.destructor(). DeclarebookingoutsideonMountsoonDestroycan reach it.
API reference
- Integration with Svelte: Component setup, styles, and cleanup
- data: The card and slot format the prop carries
- setConfirmHandler(): Handling a confirmed slot and reporting the result
- Properties overview: Every configuration property
Related examples
- Vue integration: the widget inside a Vue component
- React integration: the widget inside a React component
- Styling with custom CSS: match the widget to the colors of your app