@wix/headless-bookings 0.0.7 → 0.0.8
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/cjs/dist/api/index.d.ts +5 -0
- package/cjs/dist/api/index.js +5 -0
- package/cjs/dist/api/query-service/index.d.ts +23 -0
- package/cjs/dist/api/query-service/index.js +41 -0
- package/cjs/dist/react/booking/Booking.d.ts +35 -0
- package/cjs/dist/react/booking/Booking.js +25 -0
- package/cjs/dist/react/core/booking/Booking.d.ts +58 -0
- package/cjs/dist/react/core/booking/Booking.js +50 -0
- package/cjs/dist/react/core/service/Service.d.ts +106 -0
- package/cjs/dist/react/core/service/Service.js +90 -0
- package/cjs/dist/react/index.d.ts +2 -4
- package/cjs/dist/react/index.js +2 -5
- package/cjs/dist/react/service/Service.d.ts +208 -0
- package/cjs/dist/react/service/Service.js +202 -0
- package/cjs/dist/services/booking/booking.d.ts +85 -0
- package/cjs/dist/services/booking/booking.js +74 -0
- package/cjs/dist/services/index.d.ts +6 -1
- package/cjs/dist/services/index.js +6 -1
- package/cjs/dist/services/{service-service.d.ts → service/service.d.ts} +27 -42
- package/cjs/dist/services/{service-service.js → service/service.js} +49 -48
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +5 -0
- package/dist/api/query-service/index.d.ts +23 -0
- package/dist/api/query-service/index.js +41 -0
- package/dist/react/booking/Booking.d.ts +35 -0
- package/dist/react/booking/Booking.js +25 -0
- package/dist/react/core/booking/Booking.d.ts +58 -0
- package/dist/react/core/booking/Booking.js +50 -0
- package/dist/react/core/service/Service.d.ts +106 -0
- package/dist/react/core/service/Service.js +90 -0
- package/dist/react/index.d.ts +2 -4
- package/dist/react/index.js +2 -5
- package/dist/react/service/Service.d.ts +208 -0
- package/dist/react/service/Service.js +202 -0
- package/dist/services/booking/booking.d.ts +85 -0
- package/dist/services/booking/booking.js +74 -0
- package/dist/services/index.d.ts +6 -1
- package/dist/services/index.js +6 -1
- package/dist/services/{service-service.d.ts → service/service.d.ts} +27 -42
- package/dist/services/{service-service.js → service/service.js} +49 -48
- package/package.json +3 -2
- package/cjs/dist/react/ServiceList.d.ts +0 -50
- package/cjs/dist/react/ServiceList.js +0 -100
- package/cjs/dist/react/ServiceListSort.d.ts +0 -37
- package/cjs/dist/react/ServiceListSort.js +0 -35
- package/cjs/dist/react/core/Service.d.ts +0 -91
- package/cjs/dist/react/core/Service.js +0 -73
- package/cjs/dist/react/core/ServiceList.d.ts +0 -218
- package/cjs/dist/react/core/ServiceList.js +0 -199
- package/cjs/dist/react/test-ids.d.ts +0 -18
- package/cjs/dist/react/test-ids.js +0 -24
- package/cjs/dist/react/types.d.ts +0 -52
- package/cjs/dist/react/types.js +0 -1
- package/cjs/dist/services/services-list-service.d.ts +0 -184
- package/cjs/dist/services/services-list-service.js +0 -168
- package/dist/react/ServiceList.d.ts +0 -50
- package/dist/react/ServiceList.js +0 -100
- package/dist/react/ServiceListSort.d.ts +0 -37
- package/dist/react/ServiceListSort.js +0 -35
- package/dist/react/core/Service.d.ts +0 -91
- package/dist/react/core/Service.js +0 -73
- package/dist/react/core/ServiceList.d.ts +0 -218
- package/dist/react/core/ServiceList.js +0 -199
- package/dist/react/test-ids.d.ts +0 -18
- package/dist/react/test-ids.js +0 -24
- package/dist/react/types.d.ts +0 -52
- package/dist/react/types.js +0 -1
- package/dist/services/services-list-service.d.ts +0 -184
- package/dist/services/services-list-service.js +0 -168
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Service API
|
|
3
|
+
* Fetches a single service by ID or slug from Wix Bookings
|
|
4
|
+
*/
|
|
5
|
+
import { services } from '@wix/bookings';
|
|
6
|
+
/**
|
|
7
|
+
* Fetches a service by its ID
|
|
8
|
+
* @param id - The service ID
|
|
9
|
+
* @returns Object containing the service or null if not found
|
|
10
|
+
*/
|
|
11
|
+
export declare const getServiceById: (id: string) => Promise<{
|
|
12
|
+
service: services.Service;
|
|
13
|
+
} | {
|
|
14
|
+
service: null;
|
|
15
|
+
}>;
|
|
16
|
+
/**
|
|
17
|
+
* Fetches a service by its slug
|
|
18
|
+
* @param slug - The service slug
|
|
19
|
+
* @returns Object containing the service or null if not found
|
|
20
|
+
*/
|
|
21
|
+
export declare const getServiceBySlug: (slug: string) => Promise<{
|
|
22
|
+
service: services.Service | null;
|
|
23
|
+
}>;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Service API
|
|
3
|
+
* Fetches a single service by ID or slug from Wix Bookings
|
|
4
|
+
*/
|
|
5
|
+
import { services } from '@wix/bookings';
|
|
6
|
+
/**
|
|
7
|
+
* Fetches a service by its ID
|
|
8
|
+
* @param id - The service ID
|
|
9
|
+
* @returns Object containing the service or null if not found
|
|
10
|
+
*/
|
|
11
|
+
export const getServiceById = async (id) => {
|
|
12
|
+
try {
|
|
13
|
+
const service = await services.getService(id);
|
|
14
|
+
return { service };
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
console.error(`Failed to load service for id "${id}":`, error);
|
|
18
|
+
return { service: null };
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Fetches a service by its slug
|
|
23
|
+
* @param slug - The service slug
|
|
24
|
+
* @returns Object containing the service or null if not found
|
|
25
|
+
*/
|
|
26
|
+
export const getServiceBySlug = async (slug) => {
|
|
27
|
+
try {
|
|
28
|
+
// Query services where mainSlug.name equals the provided slug
|
|
29
|
+
const result = await services
|
|
30
|
+
.queryServices()
|
|
31
|
+
.eq('mainSlug.name', slug)
|
|
32
|
+
.limit(1)
|
|
33
|
+
.find();
|
|
34
|
+
const service = result.items?.[0] || null;
|
|
35
|
+
return { service };
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
console.error(`Failed to load service for slug "${slug}":`, error);
|
|
39
|
+
return { service: null };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Booking - High-level component for managing bookings
|
|
3
|
+
* Provides root component for booking context
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import type { BookingServiceConfig } from '../../services/booking/booking.js';
|
|
7
|
+
/**
|
|
8
|
+
* Props for Booking.Root component
|
|
9
|
+
*/
|
|
10
|
+
export interface BookingRootProps {
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
bookingServiceConfig: BookingServiceConfig;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Root component that provides booking context to the entire app.
|
|
16
|
+
*
|
|
17
|
+
* @order 1
|
|
18
|
+
* @component
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { Booking } from '@wix/bookings/components';
|
|
22
|
+
*
|
|
23
|
+
* function App() {
|
|
24
|
+
* return (
|
|
25
|
+
* <Booking.Root bookingServiceConfig={config}>
|
|
26
|
+
* {children}
|
|
27
|
+
* </Booking.Root>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const Root: {
|
|
33
|
+
(props: BookingRootProps): React.ReactNode;
|
|
34
|
+
displayName: string;
|
|
35
|
+
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as CoreBooking from '../core/booking/Booking.js';
|
|
3
|
+
/**
|
|
4
|
+
* Root component that provides booking context to the entire app.
|
|
5
|
+
*
|
|
6
|
+
* @order 1
|
|
7
|
+
* @component
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { Booking } from '@wix/bookings/components';
|
|
11
|
+
*
|
|
12
|
+
* function App() {
|
|
13
|
+
* return (
|
|
14
|
+
* <Booking.Root bookingServiceConfig={config}>
|
|
15
|
+
* {children}
|
|
16
|
+
* </Booking.Root>
|
|
17
|
+
* );
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const Root = (props) => {
|
|
22
|
+
const { children, bookingServiceConfig } = props;
|
|
23
|
+
return (_jsx(CoreBooking.Root, { bookingServiceConfig: bookingServiceConfig, children: children }));
|
|
24
|
+
};
|
|
25
|
+
Root.displayName = 'Booking.Root';
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Booking Components
|
|
3
|
+
* Provides low-level access to BookingService via render props and service setup
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { type BookingServiceConfig } from '../../../services/booking/booking.js';
|
|
7
|
+
import type { services, availabilityTimeSlots } from '@wix/bookings';
|
|
8
|
+
/**
|
|
9
|
+
* Props for Booking.Root component
|
|
10
|
+
*/
|
|
11
|
+
export interface RootProps {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
bookingServiceConfig: BookingServiceConfig;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Root component that provides booking context to the entire app.
|
|
17
|
+
*
|
|
18
|
+
* **IMPORTANT**: This should wrap the entire application at BaseLayout level,
|
|
19
|
+
* not individual pages. This ensures selections persist across navigation.
|
|
20
|
+
*
|
|
21
|
+
* @component
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* // In BaseLayout.astro
|
|
25
|
+
* <Booking.Root bookingServiceConfig={config}>
|
|
26
|
+
* {children}
|
|
27
|
+
* </Booking.Root>
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function Root(props: RootProps): React.ReactNode;
|
|
31
|
+
/**
|
|
32
|
+
* Props for Data render prop component
|
|
33
|
+
*/
|
|
34
|
+
export interface DataProps {
|
|
35
|
+
children: (data: {
|
|
36
|
+
selectedServices: services.Service[];
|
|
37
|
+
selectedTimeSlot: availabilityTimeSlots.TimeSlot | null;
|
|
38
|
+
}) => React.ReactNode;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Core component that provides access to booking data via render props.
|
|
42
|
+
* Used internally by higher-level Booking components.
|
|
43
|
+
*
|
|
44
|
+
* @component
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* <Booking.Data>
|
|
48
|
+
* {({ selectedServices }) => (
|
|
49
|
+
* selectedServices.length > 0 ? (
|
|
50
|
+
* <div>{selectedServices.map(s => s.name).join(', ')}</div>
|
|
51
|
+
* ) : (
|
|
52
|
+
* <div>No services selected</div>
|
|
53
|
+
* )
|
|
54
|
+
* )}
|
|
55
|
+
* </Booking.Data>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function Data(props: DataProps): React.ReactNode;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { WixServices, useService } from '@wix/services-manager-react';
|
|
3
|
+
import { createServicesMap } from '@wix/services-manager';
|
|
4
|
+
import { BookingServiceDefinition, BookingService, } from '../../../services/booking/booking.js';
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides booking context to the entire app.
|
|
7
|
+
*
|
|
8
|
+
* **IMPORTANT**: This should wrap the entire application at BaseLayout level,
|
|
9
|
+
* not individual pages. This ensures selections persist across navigation.
|
|
10
|
+
*
|
|
11
|
+
* @component
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* // In BaseLayout.astro
|
|
15
|
+
* <Booking.Root bookingServiceConfig={config}>
|
|
16
|
+
* {children}
|
|
17
|
+
* </Booking.Root>
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function Root(props) {
|
|
21
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(BookingServiceDefinition, BookingService, props.bookingServiceConfig), children: props.children }));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Core component that provides access to booking data via render props.
|
|
25
|
+
* Used internally by higher-level Booking components.
|
|
26
|
+
*
|
|
27
|
+
* @component
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* <Booking.Data>
|
|
31
|
+
* {({ selectedServices }) => (
|
|
32
|
+
* selectedServices.length > 0 ? (
|
|
33
|
+
* <div>{selectedServices.map(s => s.name).join(', ')}</div>
|
|
34
|
+
* ) : (
|
|
35
|
+
* <div>No services selected</div>
|
|
36
|
+
* )
|
|
37
|
+
* )}
|
|
38
|
+
* </Booking.Data>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export function Data(props) {
|
|
42
|
+
const { children } = props;
|
|
43
|
+
const bookingService = useService(BookingServiceDefinition);
|
|
44
|
+
const selectedServices = bookingService.selectedServices.get();
|
|
45
|
+
const selectedTimeSlot = bookingService.selectedTimeSlot.get();
|
|
46
|
+
return children({
|
|
47
|
+
selectedServices,
|
|
48
|
+
selectedTimeSlot,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Service Components
|
|
3
|
+
* Provides low-level access to ServiceService via render props
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { type ServiceServiceConfig } from '../../../services/service/service.js';
|
|
7
|
+
import type { services } from '@wix/bookings';
|
|
8
|
+
/**
|
|
9
|
+
* Props for Service.Root component
|
|
10
|
+
*/
|
|
11
|
+
export interface RootProps {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
serviceServiceConfig: ServiceServiceConfig;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Root component that provides service context.
|
|
17
|
+
*
|
|
18
|
+
* @component
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <Service.Root serviceServiceConfig={{ service }}>
|
|
22
|
+
* {children}
|
|
23
|
+
* </Service.Root>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function Root(props: RootProps): React.ReactNode;
|
|
27
|
+
/**
|
|
28
|
+
* Props for Service render prop component
|
|
29
|
+
*/
|
|
30
|
+
export interface ServiceProps {
|
|
31
|
+
children: (data: {
|
|
32
|
+
service: services.Service;
|
|
33
|
+
isLoading: boolean;
|
|
34
|
+
error: string | null;
|
|
35
|
+
}) => React.ReactNode;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Core component that provides access to full service data via render props.
|
|
39
|
+
*
|
|
40
|
+
* @component
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* <Service.Service>
|
|
44
|
+
* {({ service, isLoading, error }) => (
|
|
45
|
+
* isLoading ? <div>Loading...</div> : <div>{service.name}</div>
|
|
46
|
+
* )}
|
|
47
|
+
* </Service.Service>
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function Service(props: ServiceProps): React.ReactNode;
|
|
51
|
+
/**
|
|
52
|
+
* Props for Info render prop component
|
|
53
|
+
*/
|
|
54
|
+
export interface InfoProps {
|
|
55
|
+
children: (data: {
|
|
56
|
+
name: string;
|
|
57
|
+
description: string;
|
|
58
|
+
}) => React.ReactNode;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Core component that provides access to service catalog info via render props.
|
|
62
|
+
* Includes name and description for static catalog display.
|
|
63
|
+
*
|
|
64
|
+
* @component
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* <Service.Info>
|
|
68
|
+
* {({ name, description }) => (
|
|
69
|
+
* <div>
|
|
70
|
+
* <h1>{name}</h1>
|
|
71
|
+
* <p>{description}</p>
|
|
72
|
+
* </div>
|
|
73
|
+
* )}
|
|
74
|
+
* </Service.Info>
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export declare function Info(props: InfoProps): React.ReactNode;
|
|
78
|
+
/**
|
|
79
|
+
* Props for Actions render prop component
|
|
80
|
+
*/
|
|
81
|
+
export interface ActionsProps {
|
|
82
|
+
children: (actions: {
|
|
83
|
+
select: () => void;
|
|
84
|
+
add: () => void;
|
|
85
|
+
remove: () => void;
|
|
86
|
+
service: services.Service;
|
|
87
|
+
}) => React.ReactNode;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Core component that provides booking selection actions via render props.
|
|
91
|
+
*
|
|
92
|
+
* @component
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* <Service.Actions>
|
|
96
|
+
* {({ select, add, remove, service }) => (
|
|
97
|
+
* <div>
|
|
98
|
+
* <button onClick={select}>Select</button>
|
|
99
|
+
* <button onClick={add}>Add</button>
|
|
100
|
+
* <button onClick={remove}>Remove</button>
|
|
101
|
+
* </div>
|
|
102
|
+
* )}
|
|
103
|
+
* </Service.Actions>
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
export declare function Actions(props: ActionsProps): React.ReactNode;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { WixServices, useService } from '@wix/services-manager-react';
|
|
3
|
+
import { createServicesMap } from '@wix/services-manager';
|
|
4
|
+
import { ServiceServiceDefinition, ServiceService, } from '../../../services/service/service.js';
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides service context.
|
|
7
|
+
*
|
|
8
|
+
* @component
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <Service.Root serviceServiceConfig={{ service }}>
|
|
12
|
+
* {children}
|
|
13
|
+
* </Service.Root>
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function Root(props) {
|
|
17
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ServiceServiceDefinition, ServiceService, props.serviceServiceConfig), children: props.children }));
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Core component that provides access to full service data via render props.
|
|
21
|
+
*
|
|
22
|
+
* @component
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* <Service.Service>
|
|
26
|
+
* {({ service, isLoading, error }) => (
|
|
27
|
+
* isLoading ? <div>Loading...</div> : <div>{service.name}</div>
|
|
28
|
+
* )}
|
|
29
|
+
* </Service.Service>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function Service(props) {
|
|
33
|
+
const serviceService = useService(ServiceServiceDefinition);
|
|
34
|
+
const service = serviceService.service.get();
|
|
35
|
+
const isLoading = serviceService.isLoading.get();
|
|
36
|
+
const error = serviceService.error.get();
|
|
37
|
+
return props.children({ service, isLoading, error });
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Core component that provides access to service catalog info via render props.
|
|
41
|
+
* Includes name and description for static catalog display.
|
|
42
|
+
*
|
|
43
|
+
* @component
|
|
44
|
+
* @example
|
|
45
|
+
* ```tsx
|
|
46
|
+
* <Service.Info>
|
|
47
|
+
* {({ name, description }) => (
|
|
48
|
+
* <div>
|
|
49
|
+
* <h1>{name}</h1>
|
|
50
|
+
* <p>{description}</p>
|
|
51
|
+
* </div>
|
|
52
|
+
* )}
|
|
53
|
+
* </Service.Info>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function Info(props) {
|
|
57
|
+
const serviceService = useService(ServiceServiceDefinition);
|
|
58
|
+
const service = serviceService.service.get();
|
|
59
|
+
return props.children({
|
|
60
|
+
name: service.name || '',
|
|
61
|
+
description: service.description || '',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Core component that provides booking selection actions via render props.
|
|
66
|
+
*
|
|
67
|
+
* @component
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* <Service.Actions>
|
|
71
|
+
* {({ select, add, remove, service }) => (
|
|
72
|
+
* <div>
|
|
73
|
+
* <button onClick={select}>Select</button>
|
|
74
|
+
* <button onClick={add}>Add</button>
|
|
75
|
+
* <button onClick={remove}>Remove</button>
|
|
76
|
+
* </div>
|
|
77
|
+
* )}
|
|
78
|
+
* </Service.Actions>
|
|
79
|
+
* ```
|
|
80
|
+
*/
|
|
81
|
+
export function Actions(props) {
|
|
82
|
+
const serviceService = useService(ServiceServiceDefinition);
|
|
83
|
+
const service = serviceService.service.get();
|
|
84
|
+
return props.children({
|
|
85
|
+
select: serviceService.select,
|
|
86
|
+
add: serviceService.add,
|
|
87
|
+
remove: serviceService.remove,
|
|
88
|
+
service,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
export * as
|
|
2
|
-
export * as Service from './
|
|
3
|
-
export * as ServicesSort from './ServiceListSort.js';
|
|
4
|
-
export * from './test-ids.js';
|
|
1
|
+
export * as Booking from './booking/Booking.js';
|
|
2
|
+
export * as Service from './service/Service.js';
|
package/cjs/dist/react/index.js
CHANGED
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
export * as
|
|
3
|
-
export * as Service from './core/Service.js';
|
|
4
|
-
export * as ServicesSort from './ServiceListSort.js';
|
|
5
|
-
export * from './test-ids.js';
|
|
1
|
+
export * as Booking from './booking/Booking.js';
|
|
2
|
+
export * as Service from './service/Service.js';
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service - High-level component for displaying service information
|
|
3
|
+
* Provides components for displaying service details and booking actions
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
import { AsChildChildren } from '@wix/headless-utils/react';
|
|
7
|
+
import type { services } from '@wix/bookings';
|
|
8
|
+
/**
|
|
9
|
+
* Props for Service.Root component
|
|
10
|
+
*/
|
|
11
|
+
export interface ServiceRootProps {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
service: services.Service;
|
|
14
|
+
asChild?: boolean;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Root component that provides service context to the entire app.
|
|
19
|
+
*
|
|
20
|
+
* @order 1
|
|
21
|
+
* @component
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* import { Service } from '@wix/bookings/components';
|
|
25
|
+
*
|
|
26
|
+
* function ServicePage({ service }) {
|
|
27
|
+
* return (
|
|
28
|
+
* <Service.Root service={service}>
|
|
29
|
+
* <Service.Name />
|
|
30
|
+
* <Service.Description />
|
|
31
|
+
* </Service.Root>
|
|
32
|
+
* );
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare const Root: React.ForwardRefExoticComponent<ServiceRootProps & React.RefAttributes<HTMLElement>>;
|
|
37
|
+
/**
|
|
38
|
+
* Props for Service Name component
|
|
39
|
+
*/
|
|
40
|
+
export interface NameProps {
|
|
41
|
+
asChild?: boolean;
|
|
42
|
+
children?: AsChildChildren<{
|
|
43
|
+
name: string;
|
|
44
|
+
}>;
|
|
45
|
+
className?: string;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Displays the service name with customizable rendering.
|
|
49
|
+
*
|
|
50
|
+
* @component
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* // Default usage
|
|
54
|
+
* <Service.Name className="text-4xl font-bold" />
|
|
55
|
+
*
|
|
56
|
+
* // asChild with primitive
|
|
57
|
+
* <Service.Name asChild>
|
|
58
|
+
* <h1 className="text-4xl font-bold" />
|
|
59
|
+
* </Service.Name>
|
|
60
|
+
*
|
|
61
|
+
* // asChild with custom component
|
|
62
|
+
* <Service.Name asChild>
|
|
63
|
+
* {React.forwardRef(({name, ...props}, ref) => (
|
|
64
|
+
* <h1 ref={ref} {...props} className="text-4xl font-bold">
|
|
65
|
+
* {name}
|
|
66
|
+
* </h1>
|
|
67
|
+
* ))}
|
|
68
|
+
* </Service.Name>
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
export declare const Name: React.ForwardRefExoticComponent<NameProps & React.RefAttributes<HTMLElement>>;
|
|
72
|
+
/**
|
|
73
|
+
* Props for Service Description component
|
|
74
|
+
*/
|
|
75
|
+
export interface DescriptionProps {
|
|
76
|
+
asChild?: boolean;
|
|
77
|
+
children?: AsChildChildren<{
|
|
78
|
+
description: string;
|
|
79
|
+
}>;
|
|
80
|
+
className?: string;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Displays the service description with customizable rendering.
|
|
84
|
+
*
|
|
85
|
+
* @component
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* // Default usage
|
|
89
|
+
* <Service.Description className="text-gray-600" />
|
|
90
|
+
*
|
|
91
|
+
* // asChild with primitive
|
|
92
|
+
* <Service.Description asChild>
|
|
93
|
+
* <p className="text-gray-600" />
|
|
94
|
+
* </Service.Description>
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export declare const Description: React.ForwardRefExoticComponent<DescriptionProps & React.RefAttributes<HTMLElement>>;
|
|
98
|
+
/**
|
|
99
|
+
* Actions namespace with individual action components
|
|
100
|
+
*/
|
|
101
|
+
export declare namespace Actions {
|
|
102
|
+
/**
|
|
103
|
+
* Props for Select action component
|
|
104
|
+
*/
|
|
105
|
+
interface SelectProps {
|
|
106
|
+
asChild?: boolean;
|
|
107
|
+
children?: React.ReactNode;
|
|
108
|
+
className?: string;
|
|
109
|
+
label?: string;
|
|
110
|
+
onClicked?: (event: React.MouseEvent<HTMLButtonElement>, service: services.Service) => void;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Select action component - replaces selection with only this service.
|
|
114
|
+
*
|
|
115
|
+
* @component
|
|
116
|
+
* @example
|
|
117
|
+
* ```tsx
|
|
118
|
+
* // Default button
|
|
119
|
+
* <Service.Actions.Select label="Select This Service" />
|
|
120
|
+
*
|
|
121
|
+
* // With asChild using custom Button component
|
|
122
|
+
* <Service.Actions.Select asChild>
|
|
123
|
+
* <Button variant="primary">Select Service</Button>
|
|
124
|
+
* </Service.Actions.Select>
|
|
125
|
+
*
|
|
126
|
+
* // With onClicked callback for navigation
|
|
127
|
+
* <Service.Actions.Select
|
|
128
|
+
* asChild
|
|
129
|
+
* onClicked={(event, service) => {
|
|
130
|
+
* router.push(`/booking/time-slots/${service._id}`);
|
|
131
|
+
* }}
|
|
132
|
+
* >
|
|
133
|
+
* <Button variant="primary">Select Service</Button>
|
|
134
|
+
* </Service.Actions.Select>
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
const Select: React.ForwardRefExoticComponent<SelectProps & React.RefAttributes<HTMLButtonElement>>;
|
|
138
|
+
/**
|
|
139
|
+
* Props for Add action component
|
|
140
|
+
*/
|
|
141
|
+
interface AddProps {
|
|
142
|
+
asChild?: boolean;
|
|
143
|
+
children?: React.ReactNode;
|
|
144
|
+
className?: string;
|
|
145
|
+
label?: string;
|
|
146
|
+
onClicked?: (event: React.MouseEvent<HTMLButtonElement>, service: services.Service) => void;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Add action component - adds service to selection array.
|
|
150
|
+
*
|
|
151
|
+
* @component
|
|
152
|
+
* @example
|
|
153
|
+
* ```tsx
|
|
154
|
+
* // Default button
|
|
155
|
+
* <Service.Actions.Add label="Add to Selection" />
|
|
156
|
+
*
|
|
157
|
+
* // With asChild using custom Button component
|
|
158
|
+
* <Service.Actions.Add asChild>
|
|
159
|
+
* <Button variant="secondary">Add Service</Button>
|
|
160
|
+
* </Service.Actions.Add>
|
|
161
|
+
*
|
|
162
|
+
* // With onClicked callback for tracking
|
|
163
|
+
* <Service.Actions.Add
|
|
164
|
+
* label="Add to Cart"
|
|
165
|
+
* onClicked={(event, service) => {
|
|
166
|
+
* analytics.track('service_added', { serviceId: service._id });
|
|
167
|
+
* }}
|
|
168
|
+
* />
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
const Add: React.ForwardRefExoticComponent<AddProps & React.RefAttributes<HTMLButtonElement>>;
|
|
172
|
+
/**
|
|
173
|
+
* Props for Remove action component
|
|
174
|
+
*/
|
|
175
|
+
interface RemoveProps {
|
|
176
|
+
asChild?: boolean;
|
|
177
|
+
children?: React.ReactNode;
|
|
178
|
+
className?: string;
|
|
179
|
+
label?: string;
|
|
180
|
+
onClicked?: (event: React.MouseEvent<HTMLButtonElement>, service: services.Service) => void;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Remove action component - removes service from selection array.
|
|
184
|
+
*
|
|
185
|
+
* @component
|
|
186
|
+
* @example
|
|
187
|
+
* ```tsx
|
|
188
|
+
* // Default button
|
|
189
|
+
* <Service.Actions.Remove label="Remove from Selection" />
|
|
190
|
+
*
|
|
191
|
+
* // With asChild using custom Button component
|
|
192
|
+
* <Service.Actions.Remove asChild>
|
|
193
|
+
* <Button variant="destructive">Remove Service</Button>
|
|
194
|
+
* </Service.Actions.Remove>
|
|
195
|
+
*
|
|
196
|
+
* // With onClicked callback for notifications
|
|
197
|
+
* <Service.Actions.Remove
|
|
198
|
+
* asChild
|
|
199
|
+
* onClicked={(event, service) => {
|
|
200
|
+
* toast.success(`${service.name} removed from selection`);
|
|
201
|
+
* }}
|
|
202
|
+
* >
|
|
203
|
+
* <IconButton icon="trash" />
|
|
204
|
+
* </Service.Actions.Remove>
|
|
205
|
+
* ```
|
|
206
|
+
*/
|
|
207
|
+
const Remove: React.ForwardRefExoticComponent<RemoveProps & React.RefAttributes<HTMLButtonElement>>;
|
|
208
|
+
}
|