@balby/booking-search 1.0.0 → 1.0.2
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/README.md +3 -3
- package/dist/components/booking-search/date-range-picker.d.ts +2 -0
- package/dist/components/booking-search/guest-selector.d.ts +2 -0
- package/dist/components/booking-search/index.d.ts +24 -0
- package/dist/components/booking-search/location-combobox.d.ts +2 -0
- package/dist/components/booking-search/ui/command.d.ts +67 -0
- package/dist/components/booking-search/ui/dialog.d.ts +14 -0
- package/dist/components/booking-search/ui/popover.d.ts +7 -0
- package/dist/demo.d.ts +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/lib/utils.d.ts +2 -0
- package/dist/types/booking.d.ts +153 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# BookingSearch (React)
|
|
2
2
|
|
|
3
|
-
[](https://www.npmjs.com/package/@balby/booking-search)
|
|
4
4
|
[](./coverage)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
@@ -45,8 +45,8 @@ npm install react react-dom tailwindcss
|
|
|
45
45
|
### Basic Usage
|
|
46
46
|
|
|
47
47
|
```tsx
|
|
48
|
-
import { BookingSearch } from '@booking-search
|
|
49
|
-
import type { BookingSearchPayload, Location, AvailabilityDay } from '@booking-search
|
|
48
|
+
import { BookingSearch } from '@balby/booking-search'
|
|
49
|
+
import type { BookingSearchPayload, Location, AvailabilityDay } from '@balby/booking-search'
|
|
50
50
|
|
|
51
51
|
const locations: Location[] = [
|
|
52
52
|
{ id: '1', name: 'Rome, Italy', type: 'City', countryCode: 'IT' },
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { BookingSearchProps } from "../../types/booking";
|
|
2
|
+
import type { JSX } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* A component that provides a booking search interface. Users can select a destination, date range, and number of guests.
|
|
5
|
+
* It supports both desktop and mobile layouts.
|
|
6
|
+
*
|
|
7
|
+
* @param {Object} props - The properties object.
|
|
8
|
+
* @param {Array} props.availability - The data specifying available dates for booking.
|
|
9
|
+
* @param {Array} props.locations - The list of available locations for selection.
|
|
10
|
+
* @param {Function} props.onSearch - Callback function triggered when the search is submitted. Receives selected search criteria as an argument.
|
|
11
|
+
* @param {Object} [props.defaultValues] - Default values for location, check-in and check-out dates, and guest count.
|
|
12
|
+
* @param {string} [props.searchButtonText='Cerca'] - Text for the search button.
|
|
13
|
+
* @param {string} [props.locationPlaceholder='Dove vuoi andare?'] - Placeholder text for the location input field.
|
|
14
|
+
* @param {number} [props.minNights=1] - Minimum number of nights for the date range picker.
|
|
15
|
+
* @param {number} [props.maxAdults=30] - Maximum number of adult guests allowed.
|
|
16
|
+
* @param {number} [props.maxChildren=10] - Maximum number of child guests allowed.
|
|
17
|
+
* @param {string} [props.className] - Additional CSS class for customizing the component style.
|
|
18
|
+
*
|
|
19
|
+
* @return {JSX.Element} A booking search component containing inputs for location, date range, and guest selection, along with a search button.
|
|
20
|
+
*/
|
|
21
|
+
export declare function BookingSearch({ availability, locations, onSearch, defaultValues, searchButtonText, locationPlaceholder, minNights, maxAdults, maxChildren, className, }: BookingSearchProps): JSX.Element;
|
|
22
|
+
export { LocationCombobox } from "./location-combobox";
|
|
23
|
+
export { DateRangePicker } from "./date-range-picker";
|
|
24
|
+
export { GuestSelector } from "./guest-selector";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
declare const Command: React.ForwardRefExoticComponent<Omit<{
|
|
3
|
+
children?: React.ReactNode;
|
|
4
|
+
} & Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
5
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
6
|
+
} & {
|
|
7
|
+
asChild?: boolean;
|
|
8
|
+
}, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "asChild"> & {
|
|
9
|
+
label?: string;
|
|
10
|
+
shouldFilter?: boolean;
|
|
11
|
+
filter?: (value: string, search: string, keywords?: string[]) => number;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
value?: string;
|
|
14
|
+
onValueChange?: (value: string) => void;
|
|
15
|
+
loop?: boolean;
|
|
16
|
+
disablePointerSelection?: boolean;
|
|
17
|
+
vimBindings?: boolean;
|
|
18
|
+
} & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
19
|
+
declare const CommandInput: React.ForwardRefExoticComponent<Omit<Omit<Pick<Pick<React.DetailedHTMLProps<React.InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>, "key" | keyof React.InputHTMLAttributes<HTMLInputElement>> & {
|
|
20
|
+
ref?: React.Ref<HTMLInputElement>;
|
|
21
|
+
} & {
|
|
22
|
+
asChild?: boolean;
|
|
23
|
+
}, "key" | "asChild" | keyof React.InputHTMLAttributes<HTMLInputElement>>, "onChange" | "value" | "type"> & {
|
|
24
|
+
value?: string;
|
|
25
|
+
onValueChange?: (search: string) => void;
|
|
26
|
+
} & React.RefAttributes<HTMLInputElement>, "ref"> & React.RefAttributes<HTMLInputElement>>;
|
|
27
|
+
declare const CommandList: React.ForwardRefExoticComponent<Omit<{
|
|
28
|
+
children?: React.ReactNode;
|
|
29
|
+
} & Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
30
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
31
|
+
} & {
|
|
32
|
+
asChild?: boolean;
|
|
33
|
+
}, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "asChild"> & {
|
|
34
|
+
label?: string;
|
|
35
|
+
} & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
36
|
+
declare const CommandEmpty: React.ForwardRefExoticComponent<Omit<{
|
|
37
|
+
children?: React.ReactNode;
|
|
38
|
+
} & Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
39
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
40
|
+
} & {
|
|
41
|
+
asChild?: boolean;
|
|
42
|
+
}, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "asChild"> & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
43
|
+
declare const CommandGroup: React.ForwardRefExoticComponent<Omit<{
|
|
44
|
+
children?: React.ReactNode;
|
|
45
|
+
} & Omit<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
46
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
47
|
+
} & {
|
|
48
|
+
asChild?: boolean;
|
|
49
|
+
}, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "asChild">, "value" | "heading"> & {
|
|
50
|
+
heading?: React.ReactNode;
|
|
51
|
+
value?: string;
|
|
52
|
+
forceMount?: boolean;
|
|
53
|
+
} & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
54
|
+
declare const CommandItem: React.ForwardRefExoticComponent<Omit<{
|
|
55
|
+
children?: React.ReactNode;
|
|
56
|
+
} & Omit<Pick<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>> & {
|
|
57
|
+
ref?: React.Ref<HTMLDivElement>;
|
|
58
|
+
} & {
|
|
59
|
+
asChild?: boolean;
|
|
60
|
+
}, "key" | keyof React.HTMLAttributes<HTMLDivElement> | "asChild">, "onSelect" | "value" | "disabled"> & {
|
|
61
|
+
disabled?: boolean;
|
|
62
|
+
onSelect?: (value: string) => void;
|
|
63
|
+
value?: string;
|
|
64
|
+
keywords?: string[];
|
|
65
|
+
forceMount?: boolean;
|
|
66
|
+
} & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
67
|
+
export { Command, CommandInput, CommandList, CommandEmpty, CommandGroup, CommandItem, };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
3
|
+
declare const Dialog: React.FC<DialogPrimitive.DialogProps>;
|
|
4
|
+
declare const DialogTrigger: React.ForwardRefExoticComponent<DialogPrimitive.DialogTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
5
|
+
declare const DialogPortal: React.FC<DialogPrimitive.DialogPortalProps>;
|
|
6
|
+
declare const DialogClose: React.ForwardRefExoticComponent<DialogPrimitive.DialogCloseProps & React.RefAttributes<HTMLButtonElement>>;
|
|
7
|
+
declare const DialogOverlay: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogOverlayProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
8
|
+
declare const DialogContent: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
9
|
+
declare const DialogHeader: {
|
|
10
|
+
({ className, ...props }: React.HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
displayName: string;
|
|
12
|
+
};
|
|
13
|
+
declare const DialogTitle: React.ForwardRefExoticComponent<Omit<DialogPrimitive.DialogTitleProps & React.RefAttributes<HTMLHeadingElement>, "ref"> & React.RefAttributes<HTMLHeadingElement>>;
|
|
14
|
+
export { Dialog, DialogPortal, DialogOverlay, DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogTitle, };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import * as PopoverPrimitive from "@radix-ui/react-popover";
|
|
3
|
+
declare const Popover: React.FC<PopoverPrimitive.PopoverProps>;
|
|
4
|
+
declare const PopoverTrigger: React.ForwardRefExoticComponent<PopoverPrimitive.PopoverTriggerProps & React.RefAttributes<HTMLButtonElement>>;
|
|
5
|
+
declare const PopoverAnchor: React.ForwardRefExoticComponent<PopoverPrimitive.PopoverAnchorProps & React.RefAttributes<HTMLDivElement>>;
|
|
6
|
+
declare const PopoverContent: React.ForwardRefExoticComponent<Omit<PopoverPrimitive.PopoverContentProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
7
|
+
export { Popover, PopoverTrigger, PopoverContent, PopoverAnchor };
|
package/dist/demo.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import "./styles/output.css";
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* BookingSearch Component
|
|
3
|
+
*/
|
|
4
|
+
import "./styles/output.css";
|
|
5
|
+
export { BookingSearch } from "./components/booking-search";
|
|
6
|
+
export { LocationCombobox, DateRangePicker, GuestSelector, } from "./components/booking-search";
|
|
7
|
+
export type { AvailabilityDay, SearchLocation, GuestData, BookingSearchPayload, BookingSearchProps, LocationComboboxProps, DateRangePickerProps, GuestSelectorProps, GuestStepperProps, } from "./types/booking";
|
|
8
|
+
export { cn } from "./lib/utils";
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents availability and price for a single day
|
|
3
|
+
*/
|
|
4
|
+
export interface AvailabilityDay {
|
|
5
|
+
/** Date in ISO format (YYYY-MM-DD) */
|
|
6
|
+
date: string;
|
|
7
|
+
/** Price for this date */
|
|
8
|
+
price: number;
|
|
9
|
+
/** Whether the date is available for booking */
|
|
10
|
+
isAvailable: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Selectable location for booking search
|
|
14
|
+
*/
|
|
15
|
+
export interface SearchLocation {
|
|
16
|
+
id: string;
|
|
17
|
+
name: string;
|
|
18
|
+
/** Type of location (city, hotel, region, etc.) */
|
|
19
|
+
type?: string;
|
|
20
|
+
/** ISO country code */
|
|
21
|
+
countryCode?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Guest data
|
|
25
|
+
*/
|
|
26
|
+
export interface GuestData {
|
|
27
|
+
adults: number;
|
|
28
|
+
children: number;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Payload emitted by the component when user performs a search
|
|
32
|
+
*/
|
|
33
|
+
export interface BookingSearchPayload {
|
|
34
|
+
/** Selected location */
|
|
35
|
+
location: SearchLocation | null;
|
|
36
|
+
/** Check-in date */
|
|
37
|
+
checkIn: Date | null;
|
|
38
|
+
/** Check-out date */
|
|
39
|
+
checkOut: Date | null;
|
|
40
|
+
/** Number of adults */
|
|
41
|
+
adults: number;
|
|
42
|
+
/** Number of children */
|
|
43
|
+
children: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Props for the main BookingSearch component
|
|
47
|
+
*/
|
|
48
|
+
export interface BookingSearchProps {
|
|
49
|
+
/** Availability and prices for dates */
|
|
50
|
+
availability: AvailabilityDay[];
|
|
51
|
+
/** List of available locations for search */
|
|
52
|
+
locations: SearchLocation[];
|
|
53
|
+
/** Callback called when user initiates a search */
|
|
54
|
+
onSearch: (payload: BookingSearchPayload) => void;
|
|
55
|
+
/** Initial values (optional) */
|
|
56
|
+
defaultValues?: Partial<BookingSearchPayload>;
|
|
57
|
+
/** Search button text */
|
|
58
|
+
searchButtonText?: string;
|
|
59
|
+
/** Placeholder for location field */
|
|
60
|
+
locationPlaceholder?: string;
|
|
61
|
+
/** Minimum number of nights required */
|
|
62
|
+
minNights?: number;
|
|
63
|
+
/** Maximum number of adults */
|
|
64
|
+
maxAdults?: number;
|
|
65
|
+
/** Maximum number of children */
|
|
66
|
+
maxChildren?: number;
|
|
67
|
+
/** Custom CSS class */
|
|
68
|
+
className?: string;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Props for the LocationCombobox component
|
|
72
|
+
*/
|
|
73
|
+
export interface LocationComboboxProps {
|
|
74
|
+
/** List of locations to display */
|
|
75
|
+
locations: SearchLocation[];
|
|
76
|
+
/** Currently selected location */
|
|
77
|
+
value: SearchLocation | null;
|
|
78
|
+
/** Callback when location changes */
|
|
79
|
+
onChange: (location: SearchLocation | null) => void;
|
|
80
|
+
/** Optional title for the combobox */
|
|
81
|
+
title?: string;
|
|
82
|
+
/** Placeholder text */
|
|
83
|
+
placeholder?: string;
|
|
84
|
+
/** Whether the combobox is disabled */
|
|
85
|
+
disabled?: boolean;
|
|
86
|
+
/** Custom CSS class */
|
|
87
|
+
className?: string;
|
|
88
|
+
/** Tab index */
|
|
89
|
+
tabIndex?: number;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Props for the DateRangePicker component
|
|
93
|
+
*/
|
|
94
|
+
export interface DateRangePickerProps {
|
|
95
|
+
/** Availability and prices for dates */
|
|
96
|
+
availability: AvailabilityDay[];
|
|
97
|
+
/** Selected date range */
|
|
98
|
+
value: {
|
|
99
|
+
from: Date | null;
|
|
100
|
+
to: Date | null;
|
|
101
|
+
};
|
|
102
|
+
/** Callback when date range changes */
|
|
103
|
+
onChange: (range: {
|
|
104
|
+
from: Date | null;
|
|
105
|
+
to: Date | null;
|
|
106
|
+
}) => void;
|
|
107
|
+
/** Minimum number of nights required */
|
|
108
|
+
minNights?: number;
|
|
109
|
+
/** Whether the picker is disabled */
|
|
110
|
+
disabled?: boolean;
|
|
111
|
+
/** Custom CSS class */
|
|
112
|
+
className?: string;
|
|
113
|
+
/** Tab index */
|
|
114
|
+
tabIndex?: number;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Props for the GuestSelector component
|
|
118
|
+
*/
|
|
119
|
+
export interface GuestSelectorProps {
|
|
120
|
+
/** Current guest data */
|
|
121
|
+
value: GuestData;
|
|
122
|
+
/** Callback when guest data changes */
|
|
123
|
+
onChange: (guests: GuestData) => void;
|
|
124
|
+
/** Maximum number of adults */
|
|
125
|
+
maxAdults?: number;
|
|
126
|
+
/** Maximum number of children */
|
|
127
|
+
maxChildren?: number;
|
|
128
|
+
/** Whether the selector is disabled */
|
|
129
|
+
disabled?: boolean;
|
|
130
|
+
/** Custom CSS class */
|
|
131
|
+
className?: string;
|
|
132
|
+
/** Tab index */
|
|
133
|
+
tabIndex?: number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Props for the GuestStepper component (internal)
|
|
137
|
+
*/
|
|
138
|
+
export interface GuestStepperProps {
|
|
139
|
+
/** Label for the stepper */
|
|
140
|
+
label: string;
|
|
141
|
+
/** Optional description */
|
|
142
|
+
description?: string;
|
|
143
|
+
/** Current value */
|
|
144
|
+
value: number;
|
|
145
|
+
/** Callback to increment */
|
|
146
|
+
onIncrement: () => void;
|
|
147
|
+
/** Callback to decrement */
|
|
148
|
+
onDecrement: () => void;
|
|
149
|
+
/** Minimum value */
|
|
150
|
+
min?: number;
|
|
151
|
+
/** Maximum value */
|
|
152
|
+
max?: number;
|
|
153
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@balby/booking-search",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"dev:css": "bun run build:css && bunx concurrently \"bun --watch index.ts\" \"bun run watch:css\"",
|
|
46
46
|
"build": "bun run build:css && bun build src/index.ts --outdir=dist --target=browser --format=esm",
|
|
47
47
|
"build:css": "tailwindcss -i ./src/styles/globals.css -o ./src/styles/output.css --minify",
|
|
48
|
+
"build:types": "tsc -p tsconfig.build.json",
|
|
48
49
|
"watch:css": "tailwindcss -i ./src/styles/globals.css -o ./src/styles/output.css --watch",
|
|
49
50
|
"type-check": "tsc --noEmit",
|
|
50
51
|
"test": "bun test src/components/booking-search/tests/",
|
|
51
52
|
"test:coverage": "bun test --coverage src/components/booking-search/tests/",
|
|
52
|
-
"prepublishOnly": "bun run type-check && bun run test && bun run build"
|
|
53
|
-
"ts:check": "tsc --noEmit"
|
|
53
|
+
"prepublishOnly": "bun run type-check && bun run test && bun run build"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@happy-dom/global-registrator": "^20.0.11",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"tailwindcss": ">=3.0.0"
|
|
71
71
|
},
|
|
72
72
|
"dependencies": {
|
|
73
|
+
"@balby/booking-search": "^1.0.1",
|
|
73
74
|
"@radix-ui/react-dialog": "^1.1.15",
|
|
74
75
|
"@radix-ui/react-popover": "^1.1.15",
|
|
75
76
|
"@radix-ui/react-slot": "^1.2.4",
|