Skip to main content

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.

Try it online

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:

  1. Import the package and the styles - import { Booking } from "@dhx/trial-booking" and its booking.css.
  2. Bind the container with <div bind:this={container} class="widget"></div> and give the class a height.
  3. Declare the prop with export let data, and pass the cards from the parent.
  4. Create the widget in onMount - booking = new Booking(container, { data }).
  5. Answer the confirmation - booking.setConfirmHandler(event => ...) runs when a visitor confirms a slot. The demo waits a second and picks confirm.done() or confirm.error() at random, so both results of the booking dialog are visible.
  6. Destroy it in onDestroy with booking.destructor(). Declare booking outside onMount so onDestroy can reach it.

API reference​

Additional resources​