diff --git a/docs/assets/trial-booking.png b/docs/assets/trial-booking.png new file mode 100644 index 0000000..907c153 Binary files /dev/null and b/docs/assets/trial-booking.png differ diff --git a/docs/guides/integration-with-angular.md b/docs/guides/integration-with-angular.md new file mode 100644 index 0000000..1393402 --- /dev/null +++ b/docs/guides/integration-with-angular.md @@ -0,0 +1,326 @@ +--- +sidebar_label: Integration with Angular +title: Integration with Angular +description: You can learn about the integration with Angular in the documentation of the DHTMLX JavaScript Booking library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Booking. +--- + +# Integration with Angular + +:::tip +You should be familiar with basic concepts and patterns of **Angular** before reading this documentation. To refresh your knowledge, please refer to the [**Angular documentation**](https://angular.io/docs). +::: + +DHTMLX Booking is compatible with **Angular**. We have prepared code examples on how to use DHTMLX Booking with **Angular**. For more information, refer to the corresponding [**Example on GitHub**](https://github.com/DHTMLX/angular-booking-demo). + +## Creating a project + +:::info +Before you start to create a new project, install [**Angular CLI**](https://angular.io/cli) and [**Node.js**](https://nodejs.org/en/). +::: + +Create a new **my-angular-booking-app** project using Angular CLI. Run the following command for this purpose: + +~~~json +ng new my-angular-booking-app +~~~ + +:::note +If you want to follow this guide, disable Server-Side Rendering (SSR) and Static Site Generation (SSG/Prerendering) when creating new Angular app! +::: + +The command above installs all the necessary tools, so you don't need to run any additional commands. + +### Installation of dependencies + +Go to the new created app directory: + +~~~json +cd my-angular-booking-app +~~~ + +Install dependencies and start the dev server. For this, use the [**yarn**](https://yarnpkg.com/) package manager: + +~~~json +yarn +yarn start +~~~ + +The app should run on a localhost (for instance `http://localhost:3000`). + +## Creating Booking + +Now you should get the DHTMLX Booking source code. First of all, stop the app and proceed with installing the Booking package. + +### Step 1. Package installation + +Download the [**trial Booking package**](/how-to-start/#installing-trial-booking-via-npm-and-yarn) and follow steps mentioned in the README file. Note that trial Booking is available 30 days only. + +### Step 2. Component creation + +Now you need to create an Angular component, to add Booking into the application. Create the ***booking*** folder in the ***src/app/*** directory, add a new file into it and name it ***booking.component.ts***. Then complete the steps described below. + +#### Import source files + +Open the file and import Booking source files. Note that: + +- if you use PRO version and install the Booking package from a local folder, the imported path looks like this: + +~~~jsx +import { Booking } from 'dhx-booking-package'; +~~~ + +- if you use the trial version of Booking, specify the following path: + +~~~jsx +import { Booking } from '@dhx/trial-booking'; +~~~ + +:::info +In this tutorial you can see how to configure the **trial** version of Booking. +::: + +#### Set the container and initialize Booking + +To display Booking on the page, you need to set the container to render the component inside and initialize Booking using the corresponding constructor: + +~~~jsx {1,8,12-13,18-19} title="booking.component.ts" +import { Booking } from '@dhx/trial-booking'; +import { Component, ElementRef, OnInit, ViewChild, OnDestroy, ViewEncapsulation } from '@angular/core'; + +@Component({ + encapsulation: ViewEncapsulation.None, + selector: "booking", // a template name used in the "app.component.ts" file as + styleUrls: ["./booking.component.css"], // include a css file + template: `
`, +}) + +export class BookingComponent implements OnInit, OnDestroy { + // initialize container for Booking + @ViewChild('container', { static: true }) booking_container!: ElementRef; + + private _booking!: Booking; + + ngOnInit() { + // initialize the Booking component + this._booking = new Booking(this.booking_container.nativeElement, {}); + } + + ngOnDestroy(): void { + this._booking.destructor(); // destruct Booking + } +} +~~~ + +#### Adding styles + +To display Booking correctly, you need to provide the corresponding styles. For this purpose, you can create the ***booking.component.css*** file in the **src/app/booking/** directory and specify important styles for Booking and its container: + +~~~css title="booking.component.css" +/* import Booking styles */ +@import "@dhx/trial-booking/dist/booking.css"; + +/* specify styles for initial page */ +html, +body { + margin: 0; + padding: 0; + height: 100%; +} + +/* specify styles for the Booking container */ +.widget { + height: 100%; +} +~~~ + +#### Loading data + +To add data into Booking, you need to provide a data set. You can create the ***data.ts*** file in the ***src/app/booking/*** directory and add some data into it: + +~~~jsx title="data.ts" +export function getData() : any { + function getDate(addDays : any, hoursValue = 0, minutesValue = 0) { + const date = new Date(); + const secondsValue = 0; // round to minutes + const msValue = 0; + + date.setDate(date.getDate() + addDays); + date.setHours(hoursValue, minutesValue, secondsValue, msValue); + + return date.getTime(); + } + + return [ + { + id: "ee828b5d-a034-420c-889b-978840015d6a", + title: "Natalie Tyson", + category: "Therapist", + subtitle: "2 years of experiece", + details: "Cleveland Clinic\n9500 Euclid Ave", + preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/01.jpg", + price: "$35", + review: { + stars: 4, + count: 120 + }, + slots: [ + { + from: 9, + to: 20, + days: [1, 2, 3, 4, 5] + }, + { + from: 10, + to: 18, + days: [6, 0] + } + ] + }, + { + id: "9b037564-77be-429f-b719-eebbe499027a", + title: "Emma Johnson", + category: "Cardiologist", + subtitle: "2 years of experience", + details: "Stanford Health Care\n1468 Madison Ave", + preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/03.jpg", + price: "$25", + review: { + stars: 5, + count: 10 + }, + slots: [ + { + from: 14, + to: 17, + size: 30, + gap: 10 + }, + { + from: 12, + to: 19, + size: 50, + gap: 20, + days: [2], + dates: [getDate(0)] + }, + { + from: "18:30", + to: 20, + size: 20, + gap: 20, + days: [3, 4, 5] + }, + ], + usedSlots: [getDate(0, 12), getDate(0, 18)] + }, + // ... + ]; +} +~~~ + +Then open the ***booking.component.ts*** file. Import the file with data and specify the corresponding data properties to the configuration object of Booking within the `ngOnInit()` method, as shown below. + +~~~jsx {2,18,20} title="booking.component.ts" +import { Booking } from '@dhx/trial-booking'; +import { getData } from "./data"; // import data +import { Component, ElementRef, OnInit, ViewChild, OnDestroy, ViewEncapsulation } from '@angular/core'; + +@Component({ + encapsulation: ViewEncapsulation.None, + selector: "booking", + styleUrls: ["./booking.component.css"], + template: `
`, +}) + +export class BookingComponent implements OnInit, OnDestroy { + @ViewChild('container', { static: true }) booking_container!: ElementRef; + + private _booking!: Booking; + + ngOnInit() { + const data = getData(); // initialize data property + this._booking = new Booking(this.booking_container.nativeElement, { + data + }); + } + + ngOnDestroy(): void { + this._booking.destructor(); + } +} +~~~ + +Now the Booking component is ready to use. When the element will be added to the page, it will initialize the Booking with data. You can provide necessary configuration settings as well. Visit our [Booking API docs](/api/overview/booking-properties-overview/) to check the full list of available properties. + +#### Handling events + +When a user makes some action in the Booking, it invokes an event. You can use these events to detect the action and run the desired code for it. See the [full list of events](/api/overview/booking-events-overview/). + +Open the ***booking.component.ts*** file and complete the `ngOnInit()` method as in: + +~~~jsx {7-10} title="booking.component.ts" +// ... +ngOnInit() { + this._booking = new Booking(this.booking_container.nativeElement, { + date: new Date(2024, 5, 10), + }); + + // output the id of the selected slot + this._booking.api.on("select-slot", (obj) => { + console.log(obj.id); + }); +} + +ngOnDestroy(): void { + this._booking.destructor(); +} +~~~ + +### Step 3. Adding Booking into the app + +To add the ***BookingComponent*** component into the app, open the ***src/app/app.component.ts*** file and replace the default code with the following one: + +~~~jsx {5} title="app.component.ts" +import { Component } from "@angular/core"; + +@Component({ + selector: "app-root", + template: `` // a template created in the "booking.component.ts" file +}) +export class AppComponent { + name = ""; +} +~~~ + +Then create the ***app.module.ts*** file in the ***src/app/*** directory and specify the *BookingComponent* as shown below: + +~~~jsx {4-5,8} title="app.module.ts" +import { NgModule } from "@angular/core"; +import { BrowserModule } from "@angular/platform-browser"; + +import { AppComponent } from "./app.component"; +import { BookingComponent } from "./booking/booking.component"; + +@NgModule({ + declarations: [AppComponent, BookingComponent], + imports: [BrowserModule], + bootstrap: [AppComponent] +}) +export class AppModule {} +~~~ + +The last step is to open the ***src/main.ts*** file and replace the existing code with the following one: + +~~~jsx title="main.ts" +import { platformBrowserDynamic } from "@angular/platform-browser-dynamic"; +import { AppModule } from "./app/app.module"; +platformBrowserDynamic() + .bootstrapModule(AppModule) + .catch((err) => console.error(err)); +~~~ + +After that, you can start the app to see Booking loaded with data on a page. + +![Booking initialization](../assets/trial-booking.png) + +Now you know how to integrate DHTMLX Booking with Angular. You can customize the code according to your specific requirements. The final example you can find on [**GitHub**](https://github.com/DHTMLX/angular-booking-demo). diff --git a/docs/guides/integration-with-react.md b/docs/guides/integration-with-react.md new file mode 100644 index 0000000..247a47b --- /dev/null +++ b/docs/guides/integration-with-react.md @@ -0,0 +1,287 @@ +--- +sidebar_label: Integration with React +title: Integration with React +description: You can learn about the integration with React in the documentation of the DHTMLX JavaScript Booking library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Booking. +--- + +# Integration with React + +:::tip +You should be familiar with the basic concepts and patterns of [**React**](https://react.dev) before reading this documentation. To refresh your knowledge, please refer to the [**React documentation**](https://reactjs.org/docs/getting-started.html). +::: + +DHTMLX Booking is compatible with **React**. We have prepared code examples on how to use DHTMLX Booking with **React**. For more information, refer to the corresponding [**Example on GitHub**](https://github.com/DHTMLX/react-booking-demo). + +## Creating a project + +:::info +Before you start to create a new project, install [**Vite**](https://vite.dev/) (optional) and [**Node.js**](https://nodejs.org/en/). +::: + +You can create a basic **React** project or use **React with Vite**. Let's name the project as **my-react-booking-app**: + +~~~json +npx create-react-app my-react-booking-app +~~~ + +### Installation of dependencies + +Go to the new created app directory: + +~~~json +cd my-react-booking-app +~~~ + +Install dependencies and start the dev server. For this, use a package manager: + +- if you use [**yarn**](https://yarnpkg.com/), run the following commands: + +~~~json +yarn +yarn start +~~~ + +- if you use [**npm**](https://www.npmjs.com/), run the following commands: + +~~~json +npm install +npm run dev +~~~ + +The app should run on a localhost (for instance `http://localhost:3000`). + +## Creating Booking + +Now you should get the DHTMLX Booking source code. First of all, stop the app and proceed with installing the Booking package. + +### Step 1. Package installation + +Download the [**trial Booking package**](/how-to-start/#installing-trial-booking-via-npm-and-yarn) and follow steps mentioned in the README file. Note that trial Booking is available 30 days only. + +### Step 2. Component creation + +Now you need to create a React component, to add an Booking into the application. Create a new file in the ***src/*** directory and name it ***Booking.jsx***. + +#### Import source files + +Open the ***Booking.jsx*** file and import Booking source files. Note that: + +- if you use PRO version and install the Booking package from a local folder, the import paths look like this: + +~~~jsx title="Booking.jsx" +import { Booking } from 'dhx-booking-package'; +import 'dhx-booking-package/dist/booking.css'; +~~~ + +Note that depending on the used package, the source files can be minified. In this case make sure that you are importing the CSS file as ***booking.min.css***. + +- if you use the trial version of Booking, specify the following paths: + +~~~jsx title="Booking.jsx" +import { Booking } from '@dhx/trial-booking'; +import "@dhx/trial-booking/dist/booking.css"; +~~~ + +:::info +In this tutorial you can see how to configure the **trial** version of Booking. +::: + +#### Setting the container and adding Booking + +To display Booking on the page, you need to create the container for Booking, and initialize this component using the corresponding constructor: + +~~~jsx {2,6,9-10,17} title="Booking.jsx" +import { useEffect, useRef } from "react"; +import { Booking } from "@dhx/trial-booking"; +import "@dhx/trial-booking/dist/booking.css"; // include Booking styles + +export default function BookingComponent(props) { + let container = useRef(); // initialize container for Booking + + useEffect(() => { + // initialize the Booking component + const booking = new Booking(container.current, {}); + + return () => { + booking.destructor(); // destruct Booking + }; + }, []); + + return
; +} +~~~ + +#### Adding styles + +To display Booking correctly, you need to specify important styles for Booking and its container in the main css file of the project: + +~~~css title="index.css" +/* specify styles for initial page */ +html, +body, +#root { + height: 100%; + padding: 0; + margin: 0; +} + +/* specify styles for the Booking container */ +.widget { + height: 100%; +} +~~~ + +#### Loading data + +To add data into the Booking, you need to provide a data set. You can create the ***data.js*** file in the ***src/*** directory and add some data into it: + +~~~jsx title="data.js" +export function getData() { + function getDate(addDays, hoursValue = 0, minutesValue = 0) { + const date = new Date(); + const secondsValue = 0; // round to minutes + const msValue = 0; + + date.setDate(date.getDate() + addDays); + date.setHours(hoursValue, minutesValue, secondsValue, msValue); + + return date.getTime(); + } + + return [ + { + id: "ee828b5d-a034-420c-889b-978840015d6a", + title: "Natalie Tyson", + category: "Therapist", + subtitle: "2 years of experiece", + details: "Cleveland Clinic\n9500 Euclid Ave", + preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/01.jpg", + price: "$35", + review: { + stars: 4, + count: 120 + }, + slots: [ + { + from: 9, + to: 20, + days: [1, 2, 3, 4, 5] + }, + { + from: 10, + to: 18, + days: [6, 0] + } + ] + }, + { + id: "9b037564-77be-429f-b719-eebbe499027a", + title: "Emma Johnson", + category: "Cardiologist", + subtitle: "2 years of experience", + details: "Stanford Health Care\n1468 Madison Ave", + preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/03.jpg", + price: "$25", + review: { + stars: 5, + count: 10 + }, + slots: [ + { + from: 14, + to: 17, + size: 30, + gap: 10 + }, + { + from: 12, + to: 19, + size: 50, + gap: 20, + days: [2], + dates: [getDate(0)] + }, + { + from: "18:30", + to: 20, + size: 20, + gap: 20, + days: [3, 4, 5] + } + ], + usedSlots: [getDate(0, 12), getDate(0, 18)] + }, + // ... + ]; +} +~~~ + +Then open the ***App.js*** file and import data. After this you can pass data into the new created `` components as **props**: + +~~~jsx {2,5-6} title="App.js" +import Booking from "./Booking"; +import { getData } from "./data"; + +function App() { + const dataset = getData(); + return ; +} + +export default App; +~~~ + +Go to the ***Booking.jsx*** file and apply the passed **props** to the Booking configuration object: + +~~~jsx {5,10} title="Booking.jsx" +import { useEffect, useRef } from "react"; +import { Booking } from "@dhx/trial-booking"; +import "@dhx/trial-booking/dist/booking.css"; + +export default function BookingComponent(props) { + let container = useRef(); + + useEffect(() => { + const booking = new Booking(container.current, { + data: props.data + // other configuration properties + }); + + return () => { + booking.destructor(); + } + }, []); + + return
; +} +~~~ + +Now the Booking component is ready to use. When the element will be added to the page, it will initialize the Booking with data. You can provide necessary configuration settings as well. Visit our [Booking API docs](/api/overview/booking-properties-overview/) to check the full list of available properties. + +#### Handling events + +When a user makes some action in the Booking, it invokes an event. You can use these events to detect the action and run the desired code for it. See the [full list of events](/api/overview/booking-events-overview/). + +Open ***Booking.jsx*** and complete the `useEffect()` method in the following way: + +~~~jsx {5-8} title="Booking.jsx" +// ... +useEffect(() => { + const booking = new Booking(container.current, {}); + + // output the id of the selected slot + booking.api.on("select-slot", (obj) => { + console.log(obj.id); + }); + + return () => { + booking.destructor(); + } +}, []); +// ... +~~~ + +After that, you can start the app to see Booking loaded with data on a page. + +![Booking initialization](../assets/trial-booking.png) + +Now you know how to integrate DHTMLX Booking with React. You can customize the code according to your specific requirements. The final example you can find on [**GitHub**](https://github.com/DHTMLX/react-booking-demo). diff --git a/docs/guides/integration-with-svelte.md b/docs/guides/integration-with-svelte.md new file mode 100644 index 0000000..dfb77a2 --- /dev/null +++ b/docs/guides/integration-with-svelte.md @@ -0,0 +1,300 @@ +--- +sidebar_label: Integration with Svelte +title: Integration with Svelte +description: You can learn about the integration with Svelte in the documentation of the DHTMLX JavaScript Booking library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Booking. +--- + +# Integration with Svelte + +:::tip +You should be familiar with the basic concepts and patterns of **Svelte** before reading this documentation. To refresh your knowledge, please refer to the [**Svelte documentation**](https://svelte.dev/). +::: + +DHTMLX Booking is compatible with **Svelte**. We have prepared code examples on how to use DHTMLX Booking with **Svelte**. For more information, refer to the corresponding [**Example on GitHub**](https://github.com/DHTMLX/svelte-booking-demo). + +## Creating a project + +:::info +Before you start to create a new project, install [**Vite**](https://vite.dev/) (optional) and [**Node.js**](https://nodejs.org/en/). +::: + +To create a **Svelte** JS project, run the following command: + +~~~json +npm create vite@latest +~~~ + +Let's name the project as **my-svelte-booking-app**. + +### Installation of dependencies + +Go to the app directory: + +~~~json +cd my-svelte-booking-app +~~~ + +Install dependencies and start the dev server. For this, use a package manager: + +- if you use [**yarn**](https://yarnpkg.com/), run the following commands: + +~~~jsx +yarn +yarn start // or yarn dev +~~~ + +- if you use [**npm**](https://www.npmjs.com/), run the following commands: + +~~~json +npm install +npm run dev +~~~ + +The app should run on a localhost (for instance `http://localhost:3000`). + +## Creating Booking + +Now you should get the DHTMLX Booking source code. First of all, stop the app and proceed with installing the Booking package. + +### Step 1. Package installation + +Download the [**trial Booking package**](/how-to-start/#installing-trial-booking-via-npm-and-yarn) and follow steps mentioned in the README file. Note that trial Booking is available 30 days only. + +### Step 2. Component creation + +Now you need to create a Svelte component, to add Booking into the application. Let's create a new file in the ***src/*** directory and name it ***Booking.svelte***. + +#### Import source files + +Open the ***Booking.svelte*** file and import Booking source files. Note that: + +- if you use PRO version and install the Booking package from a local folder, the import paths look like this: + +~~~html title="Booking.svelte" + +~~~ + +Note that depending on the used package, the source files can be minified. In this case make sure that you are importing the CSS file as ***booking.min.css***. + +- if you use the trial version of Booking, specify the following paths: + +~~~html title="Booking.svelte" + +~~~ + +:::info +In this tutorial you can see how to configure the **trial** version of Booking. +::: + +#### Setting the container and adding Booking + +To display Booking on the page, you need to create the container for Booking, and initialize this component using the corresponding constructor: + +~~~html {3,6,10-11,19} title="Booking.svelte" + + +
+~~~ + +#### Adding styles + +To display Booking correctly, you need to specify important styles for Booking and its container in the main css file of the project: + +~~~css title="main.css" +/* specify styles for initial page */ +html, +body, +#app { /* make sure that you use the #app root container */ + height: 100%; + padding: 0; + margin: 0; +} + +/* specify styles for the Booking container */ +.widget { + height: 100%; +} +~~~ + +#### Loading data + +To add data into the Booking, we need to provide a data set. You can create the ***data.js*** file in the ***src/*** directory and add some data into it: + +~~~jsx title="data.js" +export function getData() { + function getDate(addDays, hoursValue = 0, minutesValue = 0) { + const date = new Date(); + const secondsValue = 0; // round to minutes + const msValue = 0; + + date.setDate(date.getDate() + addDays); + date.setHours(hoursValue, minutesValue, secondsValue, msValue); + + return date.getTime(); + } + + return [ + { + id: "ee828b5d-a034-420c-889b-978840015d6a", + title: "Natalie Tyson", + category: "Therapist", + subtitle: "2 years of experiece", + details: "Cleveland Clinic\n9500 Euclid Ave", + preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/01.jpg", + price: "$35", + review: { + stars: 4, + count: 120 + }, + slots: [ + { + from: 9, + to: 20, + days: [1, 2, 3, 4, 5] + }, + { + from: 10, + to: 18, + days: [6, 0] + } + ] + }, + { + id: "9b037564-77be-429f-b719-eebbe499027a", + title: "Emma Johnson", + category: "Cardiologist", + subtitle: "2 years of experience", + details: "Stanford Health Care\n1468 Madison Ave", + preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/03.jpg", + price: "$25", + review: { + stars: 5, + count: 10 + }, + slots: [ + { + from: 14, + to: 17, + size: 30, + gap: 10 + }, + { + from: 12, + to: 19, + size: 50, + gap: 20, + days: [2], + dates: [getDate(0)] + }, + { + from: "18:30", + to: 20, + size: 20, + gap: 20, + days: [3, 4, 5] + } + ], + usedSlots: [getDate(0, 12), getDate(0, 18)] + }, + // ... + ]; +} +~~~ + +Then open the ***App.svelte*** file, import data, and pass it into the new created `` components as **props**: + +~~~html {3,5,8} title="App.svelte" + + + +~~~ + +Go to the ***Booking.svelte*** file and apply the passed **props** to the Booking configuration object: + +~~~html {6,13} title="Booking.svelte" + + +
+~~~ + +Now the Booking component is ready to use. When the element will be added to the page, it will initialize the Booking with data. You can provide necessary configuration settings as well. Visit our [Booking API docs](/api/overview/booking-properties-overview/) to check the full list of available properties. + +#### Handling events + +When a user makes some action in the Booking, it invokes an event. You can use these events to detect the action and run the desired code for it. See the [full list of events](/api/overview/booking-events-overview/). + +Open ***Booking.svelte*** and complete the `onMount()` method in the following way: + +~~~html {8-11} title="Booking.svelte" + + +// ... +~~~ + +After that, you can start the app to see Booking loaded with data on a page. + +![Booking initialization](../assets/trial-booking.png) + +Now you know how to integrate DHTMLX Booking with Svelte. You can customize the code according to your specific requirements. The final example you can find on [**GitHub**](https://github.com/DHTMLX/svelte-booking-demo). diff --git a/docs/guides/integration-with-vue.md b/docs/guides/integration-with-vue.md new file mode 100644 index 0000000..6000775 --- /dev/null +++ b/docs/guides/integration-with-vue.md @@ -0,0 +1,309 @@ +--- +sidebar_label: Integration with Vue +title: Integration with Vue +description: You can learn about the integration with Vue in the documentation of the DHTMLX JavaScript Booking library. Browse developer guides and API reference, try out code examples and live demos, and download a free 30-day evaluation version of DHTMLX Booking. +--- + +# Integration with Vue + +:::tip +You should be familiar with the basic concepts and patterns of [**Vue**](https://vuejs.org/) before reading this documentation. To refresh your knowledge, please refer to the [**Vue 3 documentation**](https://vuejs.org/guide/introduction.html#getting-started). +::: + +DHTMLX Booking is compatible with **Vue**. We have prepared code examples on how to use DHTMLX Booking with **Vue 3**. For more information, refer to the corresponding [**Example on GitHub**](https://github.com/DHTMLX/vue-booking-demo). + +## Creating a project + +:::info +Before you start to create a new project, install [**Node.js**](https://nodejs.org/en/). +::: + +To create a **Vue** project, run the following command: + +~~~json +npm create vue@latest +~~~ + +This command installs and executes `create-vue`, the official **Vue** project scaffolding tool. Check the details in the [Vue.js Quick Start](https://vuejs.org/guide/quick-start.html#creating-a-vue-application). + +Let's name the project as **my-vue-booking-app**. + +### Installation of dependencies + +Go to the app directory: + +~~~json +cd my-vue-booking-app +~~~ + +Install dependencies and start the dev server. For this, use a package manager: + +- if you use [**yarn**](https://yarnpkg.com/), run the following commands: + +~~~jsx +yarn +yarn start // or yarn dev +~~~ + +- if you use [**npm**](https://www.npmjs.com/), run the following commands: + +~~~json +npm install +npm run dev +~~~ + +The app should run on a localhost (for instance `http://localhost:3000`). + +## Creating Booking + +Now you should get the DHTMLX Booking source code. First of all, stop the app and proceed with installing the Booking package. + +### Step 1. Package installation + +Download the [**trial Booking package**](/how-to-start/#installing-trial-booking-via-npm-and-yarn) and follow steps mentioned in the README file. Note that trial Booking is available 30 days only. + +### Step 2. Component creation + +Now you need to create a Vue component, to add Booking into the application. Create a new file in the ***src/components/*** directory and name it ***Booking.vue***. + +#### Import source files + +Open the ***Booking.vue*** file and import Booking source files. Note that: + +- if you use PRO version and install the Booking package from a local folder, the import paths look like this: + +~~~html title="Booking.vue" + +~~~ + +Note that depending on the used package, the source files can be minified. In this case make sure that you are importing the CSS file as ***booking.min.css***. + +- if you use the trial version of Booking, specify the following paths: + +~~~html title="Booking.vue" + + + +~~~ + +#### Adding styles + +To display Booking correctly, you need to specify important styles for Booking and its container in the main css file of the project: + +~~~css title="main.css" +/* specify styles for initial page */ +html, +body, +#app { /* make sure that you use the #app root container */ + height: 100%; + padding: 0; + margin: 0; +} + +/* specify styles for the Booking container */ +.widget { + height: 100%; +} +~~~ + +#### Loading data + +To add data into the Booking, you need to provide a data set. You can create the ***data.js*** file in the ***src/*** directory and add some data into it: + +~~~jsx title="data.js" +export function getData() { + function getDate(addDays, hoursValue = 0, minutesValue = 0) { + const date = new Date(); + const secondsValue = 0; // round to minutes + const msValue = 0; + + date.setDate(date.getDate() + addDays); + date.setHours(hoursValue, minutesValue, secondsValue, msValue); + + return date.getTime(); + } + + return [ + { + id: "ee828b5d-a034-420c-889b-978840015d6a", + title: "Natalie Tyson", + category: "Therapist", + subtitle: "2 years of experiece", + details: "Cleveland Clinic\n9500 Euclid Ave", + preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/01.jpg", + price: "$35", + review: { + stars: 4, + count: 120 + }, + slots: [ + { + from: 9, + to: 20, + days: [1, 2, 3, 4, 5] + }, + { + from: 10, + to: 18, + days: [6, 0] + } + ] + }, + { + id: "9b037564-77be-429f-b719-eebbe499027a", + title: "Emma Johnson", + category: "Cardiologist", + subtitle: "2 years of experience", + details: "Stanford Health Care\n1468 Madison Ave", + preview: "https://snippet.dhtmlx.com/codebase/data/booking/01/img/03.jpg", + price: "$25", + review: { + stars: 5, + count: 10 + }, + slots: [ + { + from: 14, + to: 17, + size: 30, + gap: 10 + }, + { + from: 12, + to: 19, + size: 50, + gap: 20, + days: [2], + dates: [getDate(0)] + }, + { + from: "18:30", + to: 20, + size: 20, + gap: 20, + days: [3, 4, 5] + } + ], + usedSlots: [getDate(0, 12), getDate(0, 18)] + }, + // ... + ]; +} +~~~ + +Then open the ***App.vue*** file, import data, and initialize it via the inner `data()` method. After this you can pass data into the new created `` component as **props**: + +~~~html {3,7-10,15} title="App.vue" + + + +~~~ + +Go to the ***Booking.vue*** file and apply the passed **props** to the Booking configuration object: + +~~~html {6,10} title="Booking.vue" + + + +~~~ + +Now the Booking component is ready to use. When the element will be added to the page, it will initialize the Booking with data. You can provide necessary configuration settings as well. Visit our [Booking API docs](/api/overview/booking-properties-overview/) to check the full list of available properties. + +#### Handling events + +When a user makes some action in the Booking, it invokes an event. You can use these events to detect the action and run the desired code for it. See the [full list of events](/api/overview/booking-events-overview/). + +Open ***Booking.vue*** and complete the `mounted()` method: + +~~~html {8-11} title="Booking.vue" + + + +~~~ + +After that, you can start the app to see Booking loaded with data on a page. + +![Booking initialization](../assets/trial-booking.png) + +Now you know how to integrate DHTMLX Booking with Vue. You can customize the code according to your specific requirements. The final example you can find on [**GitHub**](https://github.com/DHTMLX/vue-booking-demo). diff --git a/sidebars.js b/sidebars.js index b1d743e..234795d 100644 --- a/sidebars.js +++ b/sidebars.js @@ -31,12 +31,12 @@ module.exports = { link: { type: "doc", id: "api/overview/booking-methods-overview" - }, + }, items: [ "api/methods/booking-serialize-method", "api/methods/booking-setconfig-method", "api/methods/booking-setconfirmhandler-method", - "api/methods/booking-setlocale-method", + "api/methods/booking-setlocale-method" ] }, // Booking internal methods @@ -61,7 +61,7 @@ module.exports = { "api/internal/booking-exec", "api/internal/booking-intercept", "api/internal/booking-on", - "api/internal/booking-setnext", + "api/internal/booking-setnext" ] }, { @@ -76,9 +76,9 @@ module.exports = { items: [ // "api/internal/booking_innermethodname_method", "api/internal/booking-getreactivestate", - "api/internal/booking-getstate", + "api/internal/booking-getstate" ] - }, + } ] }, { @@ -97,7 +97,7 @@ module.exports = { "api/events/booking-filterdata-event", "api/events/booking-selectslot-event", "api/events/booking-selectitem-event", - "api/events/booking-selectitemdate-event", + "api/events/booking-selectitemdate-event" ] }, { @@ -122,11 +122,30 @@ module.exports = { "api/config/booking-locale", "api/config/booking-slotgap", "api/config/booking-slotsize", - "api/config/booking-start", + "api/config/booking-start" ] } ] }, + //start Backend and frameworks integration + { + type: "category", + label: "Backend and frameworks integration", + link: { + type: 'generated-index', + title: "Backend and frameworks integration", + keywords: ['backend and frameworks integration'], + image: '/img/docusaurus.png' + }, + items: [ + "guides/saving-reservations", + "guides/integration-with-angular", + "guides/integration-with-react", + "guides/integration-with-vue", + "guides/integration-with-svelte" + ] + }, + // end Backend and frameworks integration { type: "category", label: "Guides", @@ -136,16 +155,15 @@ module.exports = { type: 'generated-index', title: 'Guides', keywords: ['guides'], - image: '/img/docusaurus.png', + image: '/img/docusaurus.png' }, items: [ "guides/initialization", "guides/loading-data", "guides/configuration", "guides/localization", - "guides/saving-reservations", - "guides/styling", - ], - }, + "guides/styling" + ] + } ] };