mautourco-components 0.2.11 → 0.2.12

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.
@@ -4,6 +4,8 @@ export interface DateTimePickerProps extends Partial<DateTimeProps> {
4
4
  placeholder?: string;
5
5
  disabled?: boolean;
6
6
  onValueChange?: (value: string | string[]) => void;
7
+ /** Default value for the date picker (format: "yyyy-MM-dd" for single, ["yyyy-MM-dd", "yyyy-MM-dd"] for range) */
8
+ defaultValue?: string | string[];
7
9
  /** Whether the calendar icon has full bg*/
8
10
  iconBGFull?: boolean;
9
11
  /** Position of the calendar icon: left or right */
@@ -26,9 +26,37 @@ var formatDateRange = function (dateRange) {
26
26
  return "".concat(format(from, "dd/MM/yyyy"), " - ").concat(format(to, "dd/MM/yyyy"));
27
27
  };
28
28
  var DateTimePicker = function (_a) {
29
- var _b = _a.placeholder, placeholder = _b === void 0 ? "Select date" : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, _d = _a.mode, mode = _d === void 0 ? "both" : _d, _e = _a.selectionMode, selectionMode = _e === void 0 ? "range" : _e, _f = _a.numberOfMonths, numberOfMonths = _f === void 0 ? 2 : _f, _g = _a.disableBeforeToday, disableBeforeToday = _g === void 0 ? true : _g, _h = _a.disableToday, disableToday = _h === void 0 ? false : _h, onValueChange = _a.onValueChange, _j = _a.iconBGFull, iconBGFull = _j === void 0 ? true : _j, _k = _a.iconPosition, iconPosition = _k === void 0 ? "right" : _k, _l = _a.showChevron, showChevron = _l === void 0 ? false : _l;
30
- var _m = useState(""), value = _m[0], setValue = _m[1];
31
- var _o = useState(undefined), selectedDateRange = _o[0], setSelectedDateRange = _o[1];
29
+ var _b = _a.placeholder, placeholder = _b === void 0 ? "Select date" : _b, _c = _a.disabled, disabled = _c === void 0 ? false : _c, _d = _a.mode, mode = _d === void 0 ? "both" : _d, _e = _a.selectionMode, selectionMode = _e === void 0 ? "range" : _e, _f = _a.numberOfMonths, numberOfMonths = _f === void 0 ? 2 : _f, _g = _a.disableBeforeToday, disableBeforeToday = _g === void 0 ? true : _g, _h = _a.disableToday, disableToday = _h === void 0 ? false : _h, onValueChange = _a.onValueChange, defaultValue = _a.defaultValue, _j = _a.iconBGFull, iconBGFull = _j === void 0 ? true : _j, _k = _a.iconPosition, iconPosition = _k === void 0 ? "right" : _k, _l = _a.showChevron, showChevron = _l === void 0 ? false : _l;
30
+ // Parse default value and set initial state
31
+ var parseDefaultValue = function () {
32
+ if (!defaultValue)
33
+ return { value: "", dateRange: undefined };
34
+ try {
35
+ if (selectionMode === "range" && Array.isArray(defaultValue)) {
36
+ // Handle range: ["yyyy-MM-dd", "yyyy-MM-dd"]
37
+ var fromStr = defaultValue[0], toStr = defaultValue[1];
38
+ var from = new Date(fromStr);
39
+ var to = toStr ? new Date(toStr) : from;
40
+ var dateRange = { from: from, to: to };
41
+ var displayValue = formatDateRange(dateRange);
42
+ return { value: displayValue, dateRange: dateRange };
43
+ }
44
+ else if (selectionMode === "single" && typeof defaultValue === "string") {
45
+ // Handle single: "yyyy-MM-dd"
46
+ var date = new Date(defaultValue);
47
+ var dateRange = { from: date, to: date };
48
+ var displayValue = format(date, "dd/MM/yyyy");
49
+ return { value: displayValue, dateRange: dateRange };
50
+ }
51
+ }
52
+ catch (error) {
53
+ console.error("Error parsing default date value:", error);
54
+ }
55
+ return { value: "", dateRange: undefined };
56
+ };
57
+ var initialState = parseDefaultValue();
58
+ var _m = useState(initialState.value), value = _m[0], setValue = _m[1];
59
+ var _o = useState(initialState.dateRange), selectedDateRange = _o[0], setSelectedDateRange = _o[1];
32
60
  var _p = useState(undefined), selectedTime = _p[0], setSelectedTime = _p[1];
33
61
  var _q = useState(false), isOpen = _q[0], setIsOpen = _q[1];
34
62
  var handleDtChange = React.useCallback(function (payload) {
@@ -174,6 +174,6 @@ var RoundTrip = function (_a) {
174
174
  };
175
175
  var pickupDropoffOptions = getPickupDropoffOptions();
176
176
  var accommodationOptions = getAccommodationOptions();
177
- return (_jsx("div", __assign({ className: "round-trip ".concat(className), "data-round-trip-id": id }, { children: _jsxs("div", __assign({ className: "round-trip__content" }, { children: [_jsx("div", __assign({ className: "round-trip__field round-trip__field--pax" }, { children: _jsx(PaxSelector, { label: "Number of pax", value: internalPaxData, onChange: handlePaxChange, placeholder: "2 pax" }) })), _jsxs("div", __assign({ className: "round-trip__field round-trip__field--dates" }, { children: [_jsx(Text, __assign({ size: "sm", variant: "regular", className: "round-trip__field-label" }, { children: "Arrival date - Departure date" })), _jsx(DateTimePicker, { placeholder: "DD/MM/YYYY - DD/MM/YYYY", mode: "calendar", iconPosition: "left", numberOfMonths: 2, iconBGFull: false, showChevron: true, onValueChange: handleDateRangeChange, selectionMode: "range" })] })), _jsx("div", __assign({ className: "round-trip__field round-trip__field--pickup-dropoff" }, { children: _jsx(LocationDropdown, { label: "Pick up / Drop-off point", options: pickupDropoffOptions.options, groups: pickupDropoffOptions.groups, selectedValue: (internalPickupDropoffPoint === null || internalPickupDropoffPoint === void 0 ? void 0 : internalPickupDropoffPoint.id) || null, onSelectionChange: handlePickupDropoffChange, placeholder: "Select pick-up / drop-off point", direction: undefined, type: "airport-port", showGroupTitles: true }) })), _jsx("div", __assign({ className: "round-trip__field round-trip__field--accommodation" }, { children: _jsx(LocationDropdown, { label: "Accommodation", options: accommodationOptions.options, groups: accommodationOptions.groups, selectedValue: (internalAccommodation === null || internalAccommodation === void 0 ? void 0 : internalAccommodation.id) || null, onSelectionChange: handleAccommodationChange, placeholder: "Select accommodation", direction: "dropoff", type: "accommodation", showGroupTitles: false }) }))] })) })));
177
+ return (_jsx("div", __assign({ className: "round-trip ".concat(className), "data-round-trip-id": id }, { children: _jsxs("div", __assign({ className: "round-trip__content" }, { children: [_jsx("div", __assign({ className: "round-trip__field round-trip__field--pax" }, { children: _jsx(PaxSelector, { label: "Number of pax", value: internalPaxData, onChange: handlePaxChange, placeholder: "2 pax" }) })), _jsxs("div", __assign({ className: "round-trip__field round-trip__field--dates" }, { children: [_jsx(Text, __assign({ size: "sm", variant: "regular", className: "round-trip__field-label" }, { children: "Arrival date - Departure date" })), _jsx(DateTimePicker, { placeholder: "DD/MM/YYYY - DD/MM/YYYY", mode: "calendar", iconPosition: "left", numberOfMonths: 2, iconBGFull: false, showChevron: true, onValueChange: handleDateRangeChange, selectionMode: "range", defaultValue: arrivalDate && departureDate ? [arrivalDate, departureDate] : undefined })] })), _jsx("div", __assign({ className: "round-trip__field round-trip__field--pickup-dropoff" }, { children: _jsx(LocationDropdown, { label: "Pick up / Drop-off point", options: pickupDropoffOptions.options, groups: pickupDropoffOptions.groups, selectedValue: (internalPickupDropoffPoint === null || internalPickupDropoffPoint === void 0 ? void 0 : internalPickupDropoffPoint.id) || null, onSelectionChange: handlePickupDropoffChange, placeholder: "Select pick-up / drop-off point", direction: undefined, type: "airport-port", showGroupTitles: true }) })), _jsx("div", __assign({ className: "round-trip__field round-trip__field--accommodation" }, { children: _jsx(LocationDropdown, { label: "Accommodation", options: accommodationOptions.options, groups: accommodationOptions.groups, selectedValue: (internalAccommodation === null || internalAccommodation === void 0 ? void 0 : internalAccommodation.id) || null, onSelectionChange: handleAccommodationChange, placeholder: "Select accommodation", direction: "dropoff", type: "accommodation", showGroupTitles: false }) }))] })) })));
178
178
  };
179
179
  export default RoundTrip;
@@ -174,6 +174,6 @@ var TransferLine = function (_a) {
174
174
  setInternalDropoffPoint(location);
175
175
  onDropoffChange === null || onDropoffChange === void 0 ? void 0 : onDropoffChange(location);
176
176
  };
177
- return (_jsxs("div", __assign({ className: "transfer-line transfer-line--".concat(type, " ").concat(className), "data-transfer-id": id }, { children: [showTitle && (_jsxs("div", __assign({ className: "transfer-line__header" }, { children: [_jsx(Icon, { name: getTypeIcon(), size: "sm", className: "transfer-line__header-icon" }), _jsx(Text, __assign({ size: "sm", variant: "medium", className: "transfer-line__header-label" }, { children: getTypeLabel() }))] }))), _jsxs("div", __assign({ className: "transfer-line__content-container" }, { children: [_jsxs("div", __assign({ className: "transfer-line__content" }, { children: [_jsx("div", __assign({ className: "transfer-line__field transfer-line__field--pax" }, { children: _jsx(PaxSelector, { label: "Number of pax", value: internalPaxData, onChange: handlePaxChange, placeholder: "2 pax" }) })), _jsxs("div", __assign({ className: "transfer-line__field transfer-line__field--date" }, { children: [_jsx(Text, __assign({ size: "sm", variant: "regular", className: "transfer-line__field-label" }, { children: "Transfer date" })), _jsx(DateTimePicker, { placeholder: "DD/MM/YYYY", mode: "calendar", iconPosition: "left", numberOfMonths: 1, iconBGFull: false, showChevron: true, onValueChange: handleDateChange, selectionMode: "single" })] })), _jsx("div", __assign({ className: "transfer-line__field transfer-line__field--pickup" }, { children: _jsx(LocationDropdown, { label: "Pick-up point", options: filterLocations('pickup').options, groups: filterLocations('pickup').groups, selectedValue: (internalPickupPoint === null || internalPickupPoint === void 0 ? void 0 : internalPickupPoint.id) || null, onSelectionChange: handlePickupChange, placeholder: "Select a pick-up point", direction: "pickup", type: type === 'inter-hotel' ? 'accommodation' : type === 'arrival' ? 'airport-port' : 'accommodation', showGroupTitles: false }) })), _jsx("div", __assign({ className: "transfer-line__field transfer-line__field--dropoff" }, { children: _jsx(LocationDropdown, { label: "Drop-off point", options: filterLocations('dropoff').options, groups: filterLocations('dropoff').groups, selectedValue: (internalDropoffPoint === null || internalDropoffPoint === void 0 ? void 0 : internalDropoffPoint.id) || null, onSelectionChange: handleDropoffChange, placeholder: "Select a drop-off point", direction: "dropoff", type: type === 'inter-hotel' ? 'accommodation' : type === 'departure' ? 'airport-port' : 'accommodation', showGroupTitles: false }) }))] })), showDelete && (_jsx("div", __assign({ className: "transfer-line__delete" }, { children: _jsx("button", __assign({ type: "button", className: "transfer-line__delete-btn", onClick: onDelete, "aria-label": "Delete transfer line" }, { children: _jsx(Icon, { name: "delete", size: "sm", className: "transfer-line__delete-icon" }) })) })))] }))] })));
177
+ return (_jsxs("div", __assign({ className: "transfer-line transfer-line--".concat(type, " ").concat(className), "data-transfer-id": id }, { children: [showTitle && (_jsxs("div", __assign({ className: "transfer-line__header" }, { children: [_jsx(Icon, { name: getTypeIcon(), size: "sm", className: "transfer-line__header-icon" }), _jsx(Text, __assign({ size: "sm", variant: "medium", className: "transfer-line__header-label" }, { children: getTypeLabel() }))] }))), _jsxs("div", __assign({ className: "transfer-line__content-container" }, { children: [_jsxs("div", __assign({ className: "transfer-line__content" }, { children: [_jsx("div", __assign({ className: "transfer-line__field transfer-line__field--pax" }, { children: _jsx(PaxSelector, { label: "Number of pax", value: internalPaxData, onChange: handlePaxChange, placeholder: "2 pax" }) })), _jsxs("div", __assign({ className: "transfer-line__field transfer-line__field--date" }, { children: [_jsx(Text, __assign({ size: "sm", variant: "regular", className: "transfer-line__field-label" }, { children: "Transfer date" })), _jsx(DateTimePicker, { placeholder: "DD/MM/YYYY", mode: "calendar", iconPosition: "left", numberOfMonths: 1, iconBGFull: false, showChevron: true, onValueChange: handleDateChange, selectionMode: "single", defaultValue: transferDate })] })), _jsx("div", __assign({ className: "transfer-line__field transfer-line__field--pickup" }, { children: _jsx(LocationDropdown, { label: "Pick-up point", options: filterLocations('pickup').options, groups: filterLocations('pickup').groups, selectedValue: (internalPickupPoint === null || internalPickupPoint === void 0 ? void 0 : internalPickupPoint.id) || null, onSelectionChange: handlePickupChange, placeholder: "Select a pick-up point", direction: "pickup", type: type === 'inter-hotel' ? 'accommodation' : type === 'arrival' ? 'airport-port' : 'accommodation', showGroupTitles: false }) })), _jsx("div", __assign({ className: "transfer-line__field transfer-line__field--dropoff" }, { children: _jsx(LocationDropdown, { label: "Drop-off point", options: filterLocations('dropoff').options, groups: filterLocations('dropoff').groups, selectedValue: (internalDropoffPoint === null || internalDropoffPoint === void 0 ? void 0 : internalDropoffPoint.id) || null, onSelectionChange: handleDropoffChange, placeholder: "Select a drop-off point", direction: "dropoff", type: type === 'inter-hotel' ? 'accommodation' : type === 'departure' ? 'airport-port' : 'accommodation', showGroupTitles: false }) }))] })), showDelete && (_jsx("div", __assign({ className: "transfer-line__delete" }, { children: _jsx("button", __assign({ type: "button", className: "transfer-line__delete-btn", onClick: onDelete, "aria-label": "Delete transfer line" }, { children: _jsx(Icon, { name: "delete", size: "sm", className: "transfer-line__delete-icon" }) })) })))] }))] })));
178
178
  };
179
179
  export default TransferLine;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mautourco-components",
3
- "version": "0.2.11",
3
+ "version": "0.2.12",
4
4
  "private": false,
5
5
  "description": "Bibliothèque de composants Motorco pour le redesign",
6
6
  "main": "dist/index.js",
@@ -9,6 +9,8 @@ export interface DateTimePickerProps extends Partial<DateTimeProps> {
9
9
  placeholder?: string;
10
10
  disabled?: boolean;
11
11
  onValueChange?: (value: string | string[]) => void;
12
+ /** Default value for the date picker (format: "yyyy-MM-dd" for single, ["yyyy-MM-dd", "yyyy-MM-dd"] for range) */
13
+ defaultValue?: string | string[];
12
14
  /** Whether the calendar icon has full bg*/
13
15
  iconBGFull?: boolean;
14
16
  /** Position of the calendar icon: left or right */
@@ -35,12 +37,41 @@ const DateTimePicker: React.FC<DateTimePickerProps> = ({
35
37
  disableBeforeToday = true,
36
38
  disableToday = false,
37
39
  onValueChange,
40
+ defaultValue,
38
41
  iconBGFull = true,
39
42
  iconPosition = "right",
40
43
  showChevron = false,
41
44
  }) => {
42
- const [value, setValue] = useState<string>("");
43
- const [selectedDateRange, setSelectedDateRange] = useState<any>(undefined);
45
+ // Parse default value and set initial state
46
+ const parseDefaultValue = () => {
47
+ if (!defaultValue) return { value: "", dateRange: undefined };
48
+
49
+ try {
50
+ if (selectionMode === "range" && Array.isArray(defaultValue)) {
51
+ // Handle range: ["yyyy-MM-dd", "yyyy-MM-dd"]
52
+ const [fromStr, toStr] = defaultValue;
53
+ const from = new Date(fromStr);
54
+ const to = toStr ? new Date(toStr) : from;
55
+ const dateRange = { from, to };
56
+ const displayValue = formatDateRange(dateRange);
57
+ return { value: displayValue, dateRange };
58
+ } else if (selectionMode === "single" && typeof defaultValue === "string") {
59
+ // Handle single: "yyyy-MM-dd"
60
+ const date = new Date(defaultValue);
61
+ const dateRange = { from: date, to: date };
62
+ const displayValue = format(date, "dd/MM/yyyy");
63
+ return { value: displayValue, dateRange };
64
+ }
65
+ } catch (error) {
66
+ console.error("Error parsing default date value:", error);
67
+ }
68
+
69
+ return { value: "", dateRange: undefined };
70
+ };
71
+
72
+ const initialState = parseDefaultValue();
73
+ const [value, setValue] = useState<string>(initialState.value);
74
+ const [selectedDateRange, setSelectedDateRange] = useState<any>(initialState.dateRange);
44
75
  const [selectedTime, setSelectedTime] = useState<{ hour: string; minute: string; meridiem: "AM" | "PM" } | undefined>(undefined);
45
76
  const [isOpen, setIsOpen] = useState(false);
46
77
 
@@ -298,6 +298,7 @@ const RoundTrip: React.FC<RoundTripProps> = ({
298
298
  showChevron={true}
299
299
  onValueChange={handleDateRangeChange}
300
300
  selectionMode="range"
301
+ defaultValue={arrivalDate && departureDate ? [arrivalDate, departureDate] : undefined}
301
302
  />
302
303
  </div>
303
304
  <div className="round-trip__field round-trip__field--pickup-dropoff">
@@ -1,2 +1,3 @@
1
1
  export { default } from './SearchBarTransfer';
2
2
  export type { SearchBarTransferProps, SearchBarTransferData, TransferMode } from './SearchBarTransfer';
3
+
@@ -311,6 +311,7 @@ const TransferLine: React.FC<TransferLineProps> = ({
311
311
  showChevron={true}
312
312
  onValueChange={handleDateChange}
313
313
  selectionMode="single"
314
+ defaultValue={transferDate}
314
315
  />
315
316
  </div>
316
317