mautourco-components 0.1.2 → 0.2.0
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/dist/components/atoms/Checkbox/Checkbox.js +7 -1
- package/dist/components/atoms/Icon/Icon.d.ts +1 -1
- package/dist/components/atoms/Icon/Icon.js +22 -1
- package/dist/components/atoms/Icon/icons/BuildingIcon.d.ts +8 -0
- package/dist/components/atoms/Icon/icons/BuildingIcon.js +36 -0
- package/dist/components/atoms/Icon/icons/CalendarOutlineIcon.d.ts +8 -0
- package/dist/components/atoms/Icon/icons/CalendarOutlineIcon.js +36 -0
- package/dist/components/atoms/Icon/icons/HomeIcon.d.ts +8 -0
- package/dist/components/atoms/Icon/icons/HomeIcon.js +25 -0
- package/dist/components/atoms/Icon/icons/MinusIcon.d.ts +8 -0
- package/dist/components/atoms/Icon/icons/MinusIcon.js +25 -0
- package/dist/components/atoms/Icon/icons/PlaneIcon.d.ts +8 -0
- package/dist/components/atoms/Icon/icons/PlaneIcon.js +36 -0
- package/dist/components/atoms/Icon/icons/PlusIcon.d.ts +8 -0
- package/dist/components/atoms/Icon/icons/PlusIcon.js +25 -0
- package/dist/components/atoms/Icon/icons/ShipIcon.d.ts +8 -0
- package/dist/components/atoms/Icon/icons/ShipIcon.js +36 -0
- package/dist/components/atoms/Illustration/Illustration.d.ts +14 -0
- package/dist/components/atoms/Illustration/Illustration.js +33 -0
- package/dist/components/atoms/Illustration/illustrations.d.ts +51 -0
- package/dist/components/atoms/Illustration/illustrations.js +97 -0
- package/dist/components/atoms/RatingStar/RatingStar.d.ts +40 -0
- package/dist/components/atoms/RatingStar/RatingStar.js +54 -0
- package/dist/components/atoms/SegmentedButton/SegmentedButton.d.ts +27 -0
- package/dist/components/atoms/SegmentedButton/SegmentedButton.js +49 -0
- package/dist/components/atoms/Slider/Slider.d.ts +52 -0
- package/dist/components/atoms/Slider/Slider.js +30 -0
- package/dist/components/molecules/Calendar/CalendarInput.d.ts +34 -0
- package/dist/components/molecules/Calendar/CalendarInput.js +49 -0
- package/dist/components/molecules/Calendar/DateTime.d.ts +25 -0
- package/dist/components/molecules/Calendar/DateTime.js +106 -0
- package/dist/components/molecules/Calendar/TimePicker.d.ts +16 -0
- package/dist/components/molecules/Calendar/TimePicker.js +91 -0
- package/dist/components/molecules/LocationDropdown/LocationDropdown.d.ts +34 -0
- package/dist/components/molecules/LocationDropdown/LocationDropdown.js +120 -0
- package/dist/components/molecules/LocationDropdown/index.d.ts +2 -0
- package/dist/components/molecules/LocationDropdown/index.js +1 -0
- package/dist/components/molecules/RatingTab/RatingTab.d.ts +39 -0
- package/dist/components/molecules/RatingTab/RatingTab.js +41 -0
- package/dist/components/molecules/TabGroup/TabGroup.d.ts +17 -0
- package/dist/components/molecules/TabGroup/TabGroup.js +30 -0
- package/dist/components/organisms/CardContainer/CardContainer.d.ts +37 -0
- package/dist/components/organisms/CardContainer/CardContainer.js +27 -0
- package/dist/components/organisms/DateTimePicker/DateTimePicker.d.ts +15 -0
- package/dist/components/organisms/DateTimePicker/DateTimePicker.js +66 -0
- package/dist/components/organisms/Dialog/Dialog.d.ts +103 -0
- package/dist/components/organisms/Dialog/Dialog.js +162 -0
- package/dist/components/organisms/PaxSelector/PaxSelector.d.ts +63 -0
- package/dist/components/organisms/PaxSelector/PaxSelector.js +402 -0
- package/dist/components/organisms/RoundTrip/RoundTrip.d.ts +54 -0
- package/dist/components/organisms/RoundTrip/RoundTrip.js +179 -0
- package/dist/components/organisms/RoundTrip/index.d.ts +2 -0
- package/dist/components/organisms/RoundTrip/index.js +1 -0
- package/dist/components/organisms/SearchBarTransfer/SearchBarTransfer.d.ts +35 -0
- package/dist/components/organisms/SearchBarTransfer/SearchBarTransfer.js +192 -0
- package/dist/components/organisms/SearchBarTransfer/index.d.ts +2 -0
- package/dist/components/organisms/SearchBarTransfer/index.js +1 -0
- package/dist/components/organisms/TransferLine/TransferLine.d.ts +53 -0
- package/dist/components/organisms/TransferLine/TransferLine.js +179 -0
- package/dist/components/ui/button.d.ts +10 -0
- package/dist/components/ui/button.js +56 -0
- package/dist/components/ui/calendar.d.ts +8 -0
- package/dist/components/ui/calendar.js +87 -0
- package/dist/components/ui/popover.d.ts +7 -0
- package/dist/components/ui/popover.js +42 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.js +18 -0
- package/dist/lib/utils.d.ts +7 -0
- package/dist/lib/utils.js +13 -0
- package/package.json +21 -12
- package/src/components/atoms/Button/Button.css +34 -34
- package/src/components/atoms/Checkbox/Checkbox.tsx +83 -69
- package/src/components/atoms/Icon/Icon.tsx +30 -2
- package/src/components/atoms/Icon/icons/BuildingIcon.tsx +50 -0
- package/src/components/atoms/Icon/icons/CalendarOutlineIcon.tsx +50 -0
- package/src/components/atoms/Icon/icons/HomeIcon.tsx +52 -0
- package/src/components/atoms/Icon/icons/MinusIcon.tsx +45 -0
- package/src/components/atoms/Icon/icons/PlaneIcon.tsx +50 -0
- package/src/components/atoms/Icon/icons/PlusIcon.tsx +45 -0
- package/src/components/atoms/Icon/icons/ShipIcon.tsx +50 -0
- package/src/components/atoms/Illustration/Illustration.tsx +28 -0
- package/src/components/atoms/Illustration/illustrations.ts +116 -0
- package/src/components/atoms/RatingStar/RatingStar.tsx +114 -0
- package/src/components/atoms/SegmentedButton/SegmentedButton.tsx +94 -0
- package/src/components/atoms/Slider/Slider.tsx +95 -0
- package/src/components/molecules/Calendar/CalendarInput.tsx +135 -0
- package/src/components/molecules/Calendar/DateTime.tsx +172 -0
- package/src/components/molecules/Calendar/TimePicker.tsx +174 -0
- package/src/components/molecules/LocationDropdown/LocationDropdown.tsx +234 -0
- package/src/components/molecules/LocationDropdown/index.ts +2 -0
- package/src/components/molecules/RatingTab/RatingTab.tsx +96 -0
- package/src/components/molecules/TabGroup/TabGroup.tsx +60 -0
- package/src/components/molecules/UserCard/UserCard.stories.tsx +2 -2
- package/src/components/organisms/CardContainer/CardContainer.tsx +66 -0
- package/src/components/organisms/DateTimePicker/DateTimePicker.tsx +110 -0
- package/src/components/organisms/Dialog/Dialog.tsx +352 -0
- package/src/components/organisms/PaxSelector/PaxSelector.tsx +979 -0
- package/src/components/organisms/RoundTrip/RoundTrip.tsx +335 -0
- package/src/components/organisms/RoundTrip/index.ts +2 -0
- package/src/components/organisms/SearchBarTransfer/SearchBarTransfer.tsx +388 -0
- package/src/components/organisms/SearchBarTransfer/index.ts +2 -0
- package/src/components/organisms/TransferLine/TransferLine.tsx +369 -0
- package/src/components/ui/button.tsx +60 -0
- package/src/components/ui/calendar.tsx +246 -0
- package/src/components/ui/popover.tsx +46 -0
- package/src/styles/components/calendar.css +86 -0
- package/src/styles/components/checkbox.css +130 -132
- package/src/styles/components/dropdown.css +40 -40
- package/src/styles/components/forms.css +51 -51
- package/src/styles/components/illustration.css +7 -0
- package/src/styles/components/molecule/calendarInput.css +157 -0
- package/src/styles/components/molecule/dateTime.css +14 -0
- package/src/styles/components/molecule/location-dropdown.css +204 -0
- package/src/styles/components/molecule/timePicker.css +79 -0
- package/src/styles/components/multiselect-dropdown.css +230 -231
- package/src/styles/components/organism/card-container.css +49 -0
- package/src/styles/components/organism/dialog.css +241 -0
- package/src/styles/components/organism/pax-selector.css +702 -0
- package/src/styles/components/organism/round-trip.css +55 -0
- package/src/styles/components/organism/search-bar-transfer.css +128 -0
- package/src/styles/components/organism/transfer-line.css +86 -0
- package/src/styles/components/rating-star.css +39 -0
- package/src/styles/components/rating-tab.css +83 -0
- package/src/styles/components/segmented-button.css +134 -0
- package/src/styles/components/selected-value.css +16 -16
- package/src/styles/components/slider.css +86 -0
- package/src/styles/components/typography.css +36 -36
- package/src/styles/tokens/tokens.css +1093 -1093
- package/dist/components/atoms/Typography/Heading/Heading.d.ts +0 -9
- package/dist/components/atoms/Typography/Heading/Heading.js +0 -25
- package/dist/components/atoms/Typography/Text/Text.d.ts +0 -10
- package/dist/components/atoms/Typography/Text/Text.js +0 -77
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Tab, { TabProps } from '../../atoms/Tab/Tab';
|
|
3
|
+
|
|
4
|
+
export type TabItem<T = string> = {
|
|
5
|
+
label: string;
|
|
6
|
+
value: T;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export interface TabGroupProps<T = string> {
|
|
11
|
+
items: TabItem<T>[];
|
|
12
|
+
size?: TabProps['size'];
|
|
13
|
+
variant?: TabProps['variant'];
|
|
14
|
+
active?: T;
|
|
15
|
+
defaultActive?: T;
|
|
16
|
+
onChange?: (value: T) => void;
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function TabGroup<T = string>({
|
|
21
|
+
items,
|
|
22
|
+
size = 'lg',
|
|
23
|
+
variant = 'inline',
|
|
24
|
+
active,
|
|
25
|
+
defaultActive,
|
|
26
|
+
onChange,
|
|
27
|
+
className = '',
|
|
28
|
+
}: TabGroupProps<T>) {
|
|
29
|
+
const [internalActive, setInternalActive] = React.useState<T | undefined>(
|
|
30
|
+
defaultActive ?? items[0]?.value
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const isControlled = active !== undefined;
|
|
34
|
+
const current = (isControlled ? active : internalActive) as T | undefined;
|
|
35
|
+
|
|
36
|
+
const handleClick = (item: TabItem<T>) => {
|
|
37
|
+
if (item.disabled) return;
|
|
38
|
+
if (!isControlled) setInternalActive(item.value);
|
|
39
|
+
onChange?.(item.value);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className={`tab-group flex ${className}`} role="tablist">
|
|
44
|
+
{items.map((it) => (
|
|
45
|
+
<Tab
|
|
46
|
+
key={String(it.value)}
|
|
47
|
+
isActive={current === it.value}
|
|
48
|
+
size={size}
|
|
49
|
+
variant={variant}
|
|
50
|
+
disabled={it.disabled}
|
|
51
|
+
onClick={() => handleClick(it)}
|
|
52
|
+
>
|
|
53
|
+
{it.label}
|
|
54
|
+
</Tab>
|
|
55
|
+
))}
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default TabGroup;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Meta, StoryObj } from '@storybook/react-
|
|
1
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
2
|
|
|
3
3
|
import { UserCard } from './UserCard';
|
|
4
4
|
|
|
@@ -33,4 +33,4 @@ export const Default: Story = {
|
|
|
33
33
|
<UserCard {...args} />
|
|
34
34
|
</div>
|
|
35
35
|
),
|
|
36
|
-
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
export type CardContainerSpacing = 'compact' | 'normal' | 'relaxed' | 'chill';
|
|
4
|
+
|
|
5
|
+
export interface CardContainerProps {
|
|
6
|
+
/**
|
|
7
|
+
* The content to be displayed inside the card container
|
|
8
|
+
*/
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Spacing variant for the card container padding
|
|
13
|
+
* - compact: 8px padding
|
|
14
|
+
* - normal: 12px padding
|
|
15
|
+
* - relaxed: 16px padding
|
|
16
|
+
* - chill: 24px padding
|
|
17
|
+
*/
|
|
18
|
+
spacing?: CardContainerSpacing;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Additional CSS classes to apply to the card container
|
|
22
|
+
*/
|
|
23
|
+
className?: string;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Optional click handler
|
|
27
|
+
*/
|
|
28
|
+
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Optional data attributes for testing or tracking
|
|
32
|
+
*/
|
|
33
|
+
'data-testid'?: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* CardContainer is a versatile UI element that groups related content,
|
|
38
|
+
* such as text, images, buttons, or interactive elements.
|
|
39
|
+
*
|
|
40
|
+
* It supports different spacing variants to control the visual density
|
|
41
|
+
* and padding of the container.
|
|
42
|
+
*/
|
|
43
|
+
export const CardContainer: React.FC<CardContainerProps> = ({
|
|
44
|
+
children,
|
|
45
|
+
spacing = 'normal',
|
|
46
|
+
className = '',
|
|
47
|
+
onClick,
|
|
48
|
+
'data-testid': testId,
|
|
49
|
+
}) => {
|
|
50
|
+
const baseClass = 'card-container';
|
|
51
|
+
const spacingClass = `card-container--spacing-${spacing}`;
|
|
52
|
+
const classes = [baseClass, spacingClass, className].filter(Boolean).join(' ');
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div
|
|
56
|
+
className={classes}
|
|
57
|
+
onClick={onClick}
|
|
58
|
+
data-testid={testId}
|
|
59
|
+
>
|
|
60
|
+
{children}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export default CardContainer;
|
|
66
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import React, { useState } from "react";
|
|
2
|
+
import CalendarInput from "../../molecules/Calendar/CalendarInput";
|
|
3
|
+
import DateTime, { DateTimeProps } from "../../molecules/Calendar/DateTime";
|
|
4
|
+
import { Popover, PopoverTrigger, PopoverContent } from "../../ui/popover";
|
|
5
|
+
|
|
6
|
+
import { format } from "date-fns";
|
|
7
|
+
|
|
8
|
+
export interface DateTimePickerProps extends Partial<DateTimeProps> {
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
onValueChange?: (value: string | string[]) => void;
|
|
12
|
+
/** Whether the calendar icon has full bg*/
|
|
13
|
+
iconBGFull?: boolean;
|
|
14
|
+
/** Position of the calendar icon: left or right */
|
|
15
|
+
iconPosition?: "left" | "right";
|
|
16
|
+
/** Show chevron on the right when icon is on the left */
|
|
17
|
+
showChevron?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const formatDateRange = (dateRange: any) => {
|
|
21
|
+
if (!dateRange || !dateRange.from) return "";
|
|
22
|
+
const from = dateRange.from;
|
|
23
|
+
const to = dateRange.to ?? dateRange.from;
|
|
24
|
+
|
|
25
|
+
if (+from === +to) return format(from, "dd/MM/yyyy");
|
|
26
|
+
return `${format(from, "dd/MM/yyyy")} - ${format(to, "dd/MM/yyyy")}`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const DateTimePicker: React.FC<DateTimePickerProps> = ({
|
|
30
|
+
placeholder = "Select date",
|
|
31
|
+
disabled = false,
|
|
32
|
+
mode = "both",
|
|
33
|
+
selectionMode = "range",
|
|
34
|
+
numberOfMonths = 2,
|
|
35
|
+
disableBeforeToday = true,
|
|
36
|
+
disableToday = false,
|
|
37
|
+
onValueChange,
|
|
38
|
+
iconBGFull = true,
|
|
39
|
+
iconPosition = "right",
|
|
40
|
+
showChevron = false,
|
|
41
|
+
}) => {
|
|
42
|
+
const [value, setValue] = useState<string>("");
|
|
43
|
+
const [selectedDateRange, setSelectedDateRange] = useState<any>(undefined);
|
|
44
|
+
const [selectedTime, setSelectedTime] = useState<{ hour: string; minute: string; meridiem: "AM" | "PM" } | undefined>(undefined);
|
|
45
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
46
|
+
|
|
47
|
+
const handleDtChange = React.useCallback((payload: { dateRange?: any; time?: { hour: string; minute: string; meridiem: "AM" | "PM" } }) => {
|
|
48
|
+
const datePart = formatDateRange(payload.dateRange);
|
|
49
|
+
const time = payload.time ? `${payload.time.hour}:${payload.time.minute} ${payload.time.meridiem}` : "";
|
|
50
|
+
const combined = [datePart, time].filter(Boolean).join(" ");
|
|
51
|
+
setValue(combined);
|
|
52
|
+
setSelectedDateRange(payload.dateRange);
|
|
53
|
+
setSelectedTime(payload.time);
|
|
54
|
+
|
|
55
|
+
// Return date strings in yyyy-MM-dd format for both modes
|
|
56
|
+
if (payload.dateRange) {
|
|
57
|
+
if (selectionMode === "range") {
|
|
58
|
+
// Return array of date strings for range mode
|
|
59
|
+
const from = payload.dateRange.from;
|
|
60
|
+
const to = payload.dateRange.to ?? payload.dateRange.from;
|
|
61
|
+
|
|
62
|
+
if (from && to) {
|
|
63
|
+
const fromStr = format(from, "yyyy-MM-dd");
|
|
64
|
+
const toStr = format(to, "yyyy-MM-dd");
|
|
65
|
+
onValueChange?.([fromStr, toStr]);
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
// Return single date string in yyyy-MM-dd format for single mode
|
|
69
|
+
const date = payload.dateRange.from;
|
|
70
|
+
if (date) {
|
|
71
|
+
const dateStr = format(date, "yyyy-MM-dd");
|
|
72
|
+
onValueChange?.(dateStr);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, [onValueChange, selectionMode]);
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<Popover open={isOpen} onOpenChange={setIsOpen}>
|
|
80
|
+
<PopoverTrigger asChild>
|
|
81
|
+
<div>
|
|
82
|
+
<CalendarInput
|
|
83
|
+
placeholder={placeholder}
|
|
84
|
+
value={value}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
iconBGFull={iconBGFull}
|
|
87
|
+
iconPosition={iconPosition}
|
|
88
|
+
showChevron={showChevron}
|
|
89
|
+
isOpen={isOpen}
|
|
90
|
+
/>
|
|
91
|
+
</div>
|
|
92
|
+
</PopoverTrigger>
|
|
93
|
+
|
|
94
|
+
<PopoverContent className="w-auto p-0 border-transparent">
|
|
95
|
+
<DateTime
|
|
96
|
+
mode={mode}
|
|
97
|
+
selectionMode={selectionMode}
|
|
98
|
+
numberOfMonths={numberOfMonths as 1 | 2}
|
|
99
|
+
disableBeforeToday={disableBeforeToday}
|
|
100
|
+
disableToday={disableToday}
|
|
101
|
+
onChange={handleDtChange}
|
|
102
|
+
defaultDateRange={selectedDateRange}
|
|
103
|
+
defaultTime={selectedTime}
|
|
104
|
+
/>
|
|
105
|
+
</PopoverContent>
|
|
106
|
+
</Popover>
|
|
107
|
+
);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export default DateTimePicker;
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
import React, { useEffect, useCallback, useRef } from 'react';
|
|
2
|
+
import { createPortal } from 'react-dom';
|
|
3
|
+
import { useMobile } from '../../../hooks/useMobile';
|
|
4
|
+
import Button from '../../atoms/Button/Button';
|
|
5
|
+
import Icon from '../../atoms/Icon/Icon';
|
|
6
|
+
import '../../../styles/components/organism/dialog.css';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Size variants for the Dialog component
|
|
10
|
+
*/
|
|
11
|
+
export type DialogSize = 'desktop' | 'tablet' | 'mobile' | 'full' | 'responsive';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Props for the Dialog component
|
|
15
|
+
*/
|
|
16
|
+
export interface DialogProps {
|
|
17
|
+
/**
|
|
18
|
+
* Whether the dialog is open
|
|
19
|
+
*/
|
|
20
|
+
isOpen: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Callback when the dialog should close
|
|
23
|
+
*/
|
|
24
|
+
onClose: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Title displayed in the dialog header
|
|
27
|
+
*/
|
|
28
|
+
title: string;
|
|
29
|
+
/**
|
|
30
|
+
* Content to be rendered in the dialog body
|
|
31
|
+
*/
|
|
32
|
+
children: React.ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* Footer content or buttons. If not provided, default Cancel/Save buttons are shown
|
|
35
|
+
*/
|
|
36
|
+
footer?: React.ReactNode;
|
|
37
|
+
/**
|
|
38
|
+
* Size variant of the dialog
|
|
39
|
+
* @default 'responsive'
|
|
40
|
+
*/
|
|
41
|
+
size?: DialogSize;
|
|
42
|
+
/**
|
|
43
|
+
* Text for the primary action button (when using default footer)
|
|
44
|
+
* @default 'Save and update'
|
|
45
|
+
*/
|
|
46
|
+
primaryButtonText?: string;
|
|
47
|
+
/**
|
|
48
|
+
* Text for the secondary action button (when using default footer)
|
|
49
|
+
* @default 'Cancel'
|
|
50
|
+
*/
|
|
51
|
+
secondaryButtonText?: string;
|
|
52
|
+
/**
|
|
53
|
+
* Callback for primary button click (when using default footer)
|
|
54
|
+
*/
|
|
55
|
+
onPrimaryClick?: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Callback for secondary button click (when using default footer)
|
|
58
|
+
*/
|
|
59
|
+
onSecondaryClick?: () => void;
|
|
60
|
+
/**
|
|
61
|
+
* Whether to show the footer
|
|
62
|
+
* @default true
|
|
63
|
+
*/
|
|
64
|
+
showFooter?: boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Whether to show the close button in the header
|
|
67
|
+
* @default true
|
|
68
|
+
*/
|
|
69
|
+
showCloseButton?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Whether clicking the overlay closes the dialog
|
|
72
|
+
* @default true
|
|
73
|
+
*/
|
|
74
|
+
closeOnOverlayClick?: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Whether pressing Escape closes the dialog
|
|
77
|
+
* @default true
|
|
78
|
+
*/
|
|
79
|
+
closeOnEscape?: boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Additional CSS classes for the dialog content
|
|
82
|
+
*/
|
|
83
|
+
className?: string;
|
|
84
|
+
/**
|
|
85
|
+
* ID for aria-labelledby
|
|
86
|
+
*/
|
|
87
|
+
ariaLabelledBy?: string;
|
|
88
|
+
/**
|
|
89
|
+
* ID for aria-describedby
|
|
90
|
+
*/
|
|
91
|
+
ariaDescribedBy?: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Dialog component - A modal dialog that adapts to different screen sizes
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* <Dialog
|
|
100
|
+
* isOpen={isOpen}
|
|
101
|
+
* onClose={() => setIsOpen(false)}
|
|
102
|
+
* title="Edit Information"
|
|
103
|
+
* onPrimaryClick={handleSave}
|
|
104
|
+
* >
|
|
105
|
+
* <p>Your content here</p>
|
|
106
|
+
* </Dialog>
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export const Dialog: React.FC<DialogProps> = ({
|
|
110
|
+
isOpen,
|
|
111
|
+
onClose,
|
|
112
|
+
title,
|
|
113
|
+
children,
|
|
114
|
+
footer,
|
|
115
|
+
size = 'responsive',
|
|
116
|
+
primaryButtonText = 'Save and update',
|
|
117
|
+
secondaryButtonText = 'Cancel',
|
|
118
|
+
onPrimaryClick,
|
|
119
|
+
onSecondaryClick,
|
|
120
|
+
showFooter = true,
|
|
121
|
+
showCloseButton = true,
|
|
122
|
+
closeOnOverlayClick = true,
|
|
123
|
+
closeOnEscape = true,
|
|
124
|
+
className = '',
|
|
125
|
+
ariaLabelledBy,
|
|
126
|
+
ariaDescribedBy,
|
|
127
|
+
}) => {
|
|
128
|
+
const { isMobile, isTablet, isDesktop } = useMobile();
|
|
129
|
+
const dialogRef = useRef<HTMLDivElement>(null);
|
|
130
|
+
const previousFocusRef = useRef<HTMLElement | null>(null);
|
|
131
|
+
|
|
132
|
+
// Determine the actual size based on responsive setting
|
|
133
|
+
const getActualSize = (): Exclude<DialogSize, 'responsive'> => {
|
|
134
|
+
if (size !== 'responsive') return size;
|
|
135
|
+
if (isMobile) return 'mobile';
|
|
136
|
+
if (isTablet) return 'tablet';
|
|
137
|
+
return 'desktop';
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const actualSize = getActualSize();
|
|
141
|
+
const isMobileSize = actualSize === 'mobile';
|
|
142
|
+
const isTabletSize = actualSize === 'tablet';
|
|
143
|
+
|
|
144
|
+
// Handle escape key
|
|
145
|
+
const handleKeyDown = useCallback(
|
|
146
|
+
(event: KeyboardEvent) => {
|
|
147
|
+
if (closeOnEscape && event.key === 'Escape') {
|
|
148
|
+
onClose();
|
|
149
|
+
}
|
|
150
|
+
},
|
|
151
|
+
[closeOnEscape, onClose]
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
// Handle overlay click
|
|
155
|
+
const handleOverlayClick = useCallback(
|
|
156
|
+
(event: React.MouseEvent<HTMLDivElement>) => {
|
|
157
|
+
if (closeOnOverlayClick && event.target === event.currentTarget) {
|
|
158
|
+
onClose();
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
[closeOnOverlayClick, onClose]
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
// Focus management and scroll lock
|
|
165
|
+
useEffect(() => {
|
|
166
|
+
if (isOpen) {
|
|
167
|
+
// Store current focus
|
|
168
|
+
previousFocusRef.current = document.activeElement as HTMLElement;
|
|
169
|
+
|
|
170
|
+
// Focus the dialog
|
|
171
|
+
if (dialogRef.current) {
|
|
172
|
+
dialogRef.current.focus();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Lock body scroll
|
|
176
|
+
document.body.style.overflow = 'hidden';
|
|
177
|
+
|
|
178
|
+
// Add escape listener
|
|
179
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
180
|
+
} else {
|
|
181
|
+
// Unlock body scroll
|
|
182
|
+
document.body.style.overflow = '';
|
|
183
|
+
|
|
184
|
+
// Restore focus
|
|
185
|
+
if (previousFocusRef.current) {
|
|
186
|
+
previousFocusRef.current.focus();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
return () => {
|
|
191
|
+
document.body.style.overflow = '';
|
|
192
|
+
document.removeEventListener('keydown', handleKeyDown);
|
|
193
|
+
};
|
|
194
|
+
}, [isOpen, handleKeyDown]);
|
|
195
|
+
|
|
196
|
+
// Handle secondary button click
|
|
197
|
+
const handleSecondaryClick = () => {
|
|
198
|
+
if (onSecondaryClick) {
|
|
199
|
+
onSecondaryClick();
|
|
200
|
+
} else {
|
|
201
|
+
onClose();
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
// Handle primary button click
|
|
206
|
+
const handlePrimaryClick = () => {
|
|
207
|
+
if (onPrimaryClick) {
|
|
208
|
+
onPrimaryClick();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// Generate unique IDs for accessibility
|
|
213
|
+
const titleId = ariaLabelledBy || `dialog-title-${title.replace(/\s+/g, '-').toLowerCase()}`;
|
|
214
|
+
const bodyId = ariaDescribedBy || `dialog-body-${title.replace(/\s+/g, '-').toLowerCase()}`;
|
|
215
|
+
|
|
216
|
+
// Build class names
|
|
217
|
+
const contentClasses = [
|
|
218
|
+
'dialog__content',
|
|
219
|
+
`dialog__content--${actualSize}`,
|
|
220
|
+
size === 'responsive' ? 'dialog__content--responsive' : '',
|
|
221
|
+
className,
|
|
222
|
+
]
|
|
223
|
+
.filter(Boolean)
|
|
224
|
+
.join(' ');
|
|
225
|
+
|
|
226
|
+
const headerClasses = [
|
|
227
|
+
'dialog__header',
|
|
228
|
+
isMobileSize ? 'dialog__header--mobile' : '',
|
|
229
|
+
size === 'responsive' ? 'dialog__header--responsive' : '',
|
|
230
|
+
]
|
|
231
|
+
.filter(Boolean)
|
|
232
|
+
.join(' ');
|
|
233
|
+
|
|
234
|
+
const titleClasses = [
|
|
235
|
+
'dialog__title',
|
|
236
|
+
isMobileSize ? 'dialog__title--mobile' : '',
|
|
237
|
+
isTabletSize ? 'dialog__title--tablet' : '',
|
|
238
|
+
size === 'responsive' ? 'dialog__title--responsive' : '',
|
|
239
|
+
]
|
|
240
|
+
.filter(Boolean)
|
|
241
|
+
.join(' ');
|
|
242
|
+
|
|
243
|
+
const closeButtonClasses = 'dialog__close-button';
|
|
244
|
+
|
|
245
|
+
const bodyClasses = [
|
|
246
|
+
'dialog__body',
|
|
247
|
+
isMobileSize ? 'dialog__body--mobile' : '',
|
|
248
|
+
size === 'responsive' ? 'dialog__body--responsive' : '',
|
|
249
|
+
]
|
|
250
|
+
.filter(Boolean)
|
|
251
|
+
.join(' ');
|
|
252
|
+
|
|
253
|
+
const footerClasses = [
|
|
254
|
+
'dialog__footer',
|
|
255
|
+
isMobileSize ? 'dialog__footer--mobile' : '',
|
|
256
|
+
size === 'responsive' ? 'dialog__footer--responsive' : '',
|
|
257
|
+
]
|
|
258
|
+
.filter(Boolean)
|
|
259
|
+
.join(' ');
|
|
260
|
+
|
|
261
|
+
const footerButtonsClasses = [
|
|
262
|
+
'dialog__footer-buttons',
|
|
263
|
+
isMobileSize ? 'dialog__footer-buttons--mobile' : '',
|
|
264
|
+
size === 'responsive' ? 'dialog__footer-buttons--responsive' : '',
|
|
265
|
+
]
|
|
266
|
+
.filter(Boolean)
|
|
267
|
+
.join(' ');
|
|
268
|
+
|
|
269
|
+
if (!isOpen) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const dialogContent = (
|
|
274
|
+
<>
|
|
275
|
+
{/* Overlay */}
|
|
276
|
+
<div
|
|
277
|
+
className="dialog-overlay"
|
|
278
|
+
onClick={handleOverlayClick}
|
|
279
|
+
aria-hidden="true"
|
|
280
|
+
/>
|
|
281
|
+
|
|
282
|
+
{/* Dialog container */}
|
|
283
|
+
<div
|
|
284
|
+
className="dialog"
|
|
285
|
+
role="dialog"
|
|
286
|
+
aria-modal="true"
|
|
287
|
+
aria-labelledby={titleId}
|
|
288
|
+
aria-describedby={bodyId}
|
|
289
|
+
ref={dialogRef}
|
|
290
|
+
tabIndex={-1}
|
|
291
|
+
onClick={handleOverlayClick}
|
|
292
|
+
>
|
|
293
|
+
{/* Dialog content */}
|
|
294
|
+
<div className={contentClasses}>
|
|
295
|
+
{/* Header */}
|
|
296
|
+
<div className={headerClasses}>
|
|
297
|
+
<h2 id={titleId} className={titleClasses}>
|
|
298
|
+
{title}
|
|
299
|
+
</h2>
|
|
300
|
+
{showCloseButton && (
|
|
301
|
+
<button
|
|
302
|
+
type="button"
|
|
303
|
+
className={closeButtonClasses}
|
|
304
|
+
onClick={onClose}
|
|
305
|
+
aria-label="Close dialog"
|
|
306
|
+
>
|
|
307
|
+
<Icon name="close" size="md" />
|
|
308
|
+
</button>
|
|
309
|
+
)}
|
|
310
|
+
</div>
|
|
311
|
+
|
|
312
|
+
{/* Body */}
|
|
313
|
+
<div id={bodyId} className={bodyClasses}>
|
|
314
|
+
<div className="dialog__body-content">{children}</div>
|
|
315
|
+
</div>
|
|
316
|
+
|
|
317
|
+
{/* Footer */}
|
|
318
|
+
{showFooter && (
|
|
319
|
+
<div className={footerClasses}>
|
|
320
|
+
{footer ? (
|
|
321
|
+
footer
|
|
322
|
+
) : (
|
|
323
|
+
<div className={footerButtonsClasses}>
|
|
324
|
+
<Button
|
|
325
|
+
variant="outline-secondary"
|
|
326
|
+
size={isMobileSize ? 'sm' : 'md'}
|
|
327
|
+
onClick={handleSecondaryClick}
|
|
328
|
+
>
|
|
329
|
+
{secondaryButtonText}
|
|
330
|
+
</Button>
|
|
331
|
+
<Button
|
|
332
|
+
variant="secondary"
|
|
333
|
+
size={isMobileSize ? 'sm' : 'md'}
|
|
334
|
+
onClick={handlePrimaryClick}
|
|
335
|
+
>
|
|
336
|
+
{primaryButtonText}
|
|
337
|
+
</Button>
|
|
338
|
+
</div>
|
|
339
|
+
)}
|
|
340
|
+
</div>
|
|
341
|
+
)}
|
|
342
|
+
</div>
|
|
343
|
+
</div>
|
|
344
|
+
</>
|
|
345
|
+
);
|
|
346
|
+
|
|
347
|
+
// Use portal to render at the document body level
|
|
348
|
+
return createPortal(dialogContent, document.body);
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
export default Dialog;
|
|
352
|
+
|