@appdirect/design-system 0.0.0-stage → 0.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 +12 -2
- package/dist/Buttons/ActionIcon.tsx +37 -0
- package/dist/Buttons/Button.module.css +5 -0
- package/dist/Buttons/Button.tsx +124 -0
- package/dist/Buttons/CloseButton.tsx +83 -0
- package/dist/Buttons/index.ts +20 -0
- package/dist/Combobox/AutocompleteClearable.tsx +128 -0
- package/dist/Combobox/Combobox.tsx +37 -0
- package/dist/Combobox/Multiselect.tsx +158 -0
- package/dist/Combobox/SearchableSelect.tsx +131 -0
- package/dist/Combobox/Select.tsx +154 -0
- package/dist/Combobox/index.ts +20 -0
- package/dist/ComplexComponents/DashboardWidget/DashboardWidget.tsx +313 -0
- package/dist/ComplexComponents/DashboardWidget/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/index.tsx +177 -0
- package/dist/ComplexComponents/DataTable/CustomBottomToolbar/utils.ts +35 -0
- package/dist/ComplexComponents/DataTable/CustomToolbarAlertBannerContent/index.tsx +74 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/DateRangeSelectorFilter/index.tsx +358 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterChip.tsx +48 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/DateRangeFilter.tsx +26 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterRenderer.tsx +71 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/FilterSystem.tsx +158 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/MultiSelectFilter.tsx +79 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/SingleSelectFilter.tsx +65 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/index.ts +70 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/FilterSystem/types.ts +140 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/ResultCount/index.tsx +76 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SearchFilter.tsx +73 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/SelectFilter.tsx +50 -0
- package/dist/ComplexComponents/DataTable/CustomTopToolbar/index.tsx +788 -0
- package/dist/ComplexComponents/DataTable/DataTable.tsx +582 -0
- package/dist/ComplexComponents/DataTable/ErrorOverlay/index.tsx +29 -0
- package/dist/ComplexComponents/DataTable/SortableHeaderCell/index.tsx +57 -0
- package/dist/ComplexComponents/DataTable/index.ts +2 -0
- package/dist/ComplexComponents/DataTable/translations/en.ts +115 -0
- package/dist/ComplexComponents/DataTable/translations/index.ts +23 -0
- package/dist/ComplexComponents/KeyInsight/KeyInsights.tsx +221 -0
- package/dist/ComplexComponents/KeyInsight/index.ts +2 -0
- package/dist/ComplexComponents/NameValue/NameValue.tsx +175 -0
- package/dist/ComplexComponents/NameValue/NameValueItem.tsx +100 -0
- package/dist/ComplexComponents/NameValue/index.ts +4 -0
- package/dist/ComplexComponents/PageContentHeader/DescriptionBlock.tsx +65 -0
- package/dist/ComplexComponents/PageContentHeader/PageContentHeader.tsx +383 -0
- package/dist/ComplexComponents/PageContentHeader/index.ts +4 -0
- package/dist/ComplexComponents/Utilities/CopyButton.tsx +82 -0
- package/dist/ComplexComponents/Utilities/index.ts +2 -0
- package/dist/DataDisplay/Alert.tsx +130 -0
- package/dist/DataDisplay/Avatar.tsx +216 -0
- package/dist/DataDisplay/Badge.tsx +119 -0
- package/dist/DataDisplay/Card.module.css +26 -0
- package/dist/DataDisplay/Card.tsx +163 -0
- package/dist/DataDisplay/Chip.tsx +66 -0
- package/dist/DataDisplay/Indicator.tsx +122 -0
- package/dist/DataDisplay/List.tsx +90 -0
- package/dist/DataDisplay/Pill.tsx +125 -0
- package/dist/DataDisplay/Progress.tsx +77 -0
- package/dist/DataDisplay/Table.tsx +57 -0
- package/dist/DataDisplay/ThemeIcon.tsx +67 -0
- package/dist/DataDisplay/index.ts +41 -0
- package/dist/Inputs/Checkbox.tsx +94 -0
- package/dist/Inputs/ColorInput.tsx +124 -0
- package/dist/Inputs/DropZone.tsx +78 -0
- package/dist/Inputs/FileInput.tsx +120 -0
- package/dist/Inputs/NumberInput.tsx +125 -0
- package/dist/Inputs/Radio.tsx +86 -0
- package/dist/Inputs/RadioGroup.tsx +90 -0
- package/dist/Inputs/SegmentedControl.tsx +64 -0
- package/dist/Inputs/Slider.tsx +69 -0
- package/dist/Inputs/Switch.tsx +67 -0
- package/dist/Inputs/TextArea.tsx +126 -0
- package/dist/Inputs/TextInput.tsx +167 -0
- package/dist/Inputs/index.ts +51 -0
- package/dist/Layout/Box.tsx +82 -0
- package/dist/Layout/Center.tsx +17 -0
- package/dist/Layout/Container.tsx +17 -0
- package/dist/Layout/Flex.tsx +18 -0
- package/dist/Layout/Grid.tsx +31 -0
- package/dist/Layout/Group.tsx +54 -0
- package/dist/Layout/Inline.tsx +86 -0
- package/dist/Layout/SimpleGrid.tsx +50 -0
- package/dist/Layout/Stack.tsx +86 -0
- package/dist/Layout/index.ts +29 -0
- package/dist/Misc/Divider.tsx +27 -0
- package/dist/Misc/Paper.tsx +47 -0
- package/dist/Misc/index.ts +15 -0
- package/dist/Navigation/Breadcrumb.tsx +138 -0
- package/dist/Navigation/NavLink.tsx +37 -0
- package/dist/Navigation/Stepper.tsx +17 -0
- package/dist/Navigation/Tabs.tsx +29 -0
- package/dist/Navigation/index.ts +17 -0
- package/dist/Overlays/Drawer.tsx +123 -0
- package/dist/Overlays/Menu.tsx +192 -0
- package/dist/Overlays/Modal.tsx +159 -0
- package/dist/Overlays/Popover.tsx +319 -0
- package/dist/Overlays/Tooltip.tsx +131 -0
- package/dist/Overlays/index.ts +19 -0
- package/dist/Shell/AppShellLayout.tsx +56 -0
- package/dist/Shell/HeaderBar.tsx +26 -0
- package/dist/Shell/SidebarNav.tsx +47 -0
- package/dist/Shell/SidebarNavLink.tsx +50 -0
- package/dist/Shell/SingleColumnLayout.tsx +22 -0
- package/dist/Shell/TertiaryColumnLayout.tsx +32 -0
- package/dist/Shell/index.ts +17 -0
- package/dist/Typography/Code.tsx +27 -0
- package/dist/Typography/Kbd.tsx +87 -0
- package/dist/Typography/Text.tsx +27 -0
- package/dist/Typography/Title.tsx +34 -0
- package/dist/Typography/index.ts +21 -0
- package/dist/bin/ds-audit.js +521 -0
- package/dist/config.ts +226 -0
- package/dist/contracts/Alert.json +80 -0
- package/dist/contracts/Badge.json +78 -0
- package/dist/contracts/Box.json +52 -0
- package/dist/contracts/Button.json +111 -0
- package/dist/contracts/DataTable.json +68 -0
- package/dist/contracts/Grid.json +35 -0
- package/dist/contracts/Group.json +44 -0
- package/dist/contracts/Inline.json +73 -0
- package/dist/contracts/PageContentHeader.json +107 -0
- package/dist/contracts/Stack.json +62 -0
- package/dist/contracts/ds-component-contract.v1.json +23 -0
- package/dist/contracts/index.json +55 -0
- package/dist/css/foundations.css +703 -0
- package/dist/css/mantine.css +1777 -0
- package/dist/hooks/useTableHandlers.ts +179 -0
- package/dist/hooks/useTableRenderFunctions.tsx +283 -0
- package/dist/hooks/useTableState.ts +81 -0
- package/dist/index.ts +210 -0
- package/dist/types.ts +202 -0
- package/package.json +56 -4
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { Drawer as MantineDrawer, DrawerProps as MantineDrawerProps } from '@mantine/core';
|
|
5
|
+
import { ComponentSize } from '../config';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Enhanced Drawer props extending Mantine's DrawerProps
|
|
9
|
+
*/
|
|
10
|
+
export interface DSDrawerProps extends Omit<MantineDrawerProps, 'size' | 'position'> {
|
|
11
|
+
/** Whether the drawer is open */
|
|
12
|
+
opened: boolean;
|
|
13
|
+
/** Callback fired when drawer should close */
|
|
14
|
+
onClose: () => void;
|
|
15
|
+
/** Drawer title */
|
|
16
|
+
title?: React.ReactNode;
|
|
17
|
+
/** Drawer content */
|
|
18
|
+
children: React.ReactNode;
|
|
19
|
+
/** Drawer size from design system scale */
|
|
20
|
+
size?: ComponentSize;
|
|
21
|
+
/** Position of the drawer */
|
|
22
|
+
position?: 'right';
|
|
23
|
+
/** Whether to show close button */
|
|
24
|
+
withCloseButton?: boolean;
|
|
25
|
+
/** Whether clicking overlay closes drawer */
|
|
26
|
+
closeOnClickOutside?: boolean;
|
|
27
|
+
/** Whether pressing escape closes drawer */
|
|
28
|
+
closeOnEscape?: boolean;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* AppDirect Design System Drawer Component
|
|
33
|
+
*
|
|
34
|
+
* A sliding overlay component built on top of Mantine's Drawer with
|
|
35
|
+
* consistent design system styling for right-side drawer layouts.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* // Basic usage
|
|
40
|
+
* <Drawer
|
|
41
|
+
* opened={opened}
|
|
42
|
+
* onClose={() => setOpened(false)}
|
|
43
|
+
* title="Settings"
|
|
44
|
+
* >
|
|
45
|
+
* <p>Drawer content goes here</p>
|
|
46
|
+
* </Drawer>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```tsx
|
|
51
|
+
* // Different sizes
|
|
52
|
+
* <Drawer
|
|
53
|
+
* opened={opened}
|
|
54
|
+
* onClose={close}
|
|
55
|
+
* title="Navigation"
|
|
56
|
+
* size="sm"
|
|
57
|
+
* >
|
|
58
|
+
* <Navigation />
|
|
59
|
+
* </Drawer>
|
|
60
|
+
*
|
|
61
|
+
* <Drawer
|
|
62
|
+
* opened={opened}
|
|
63
|
+
* onClose={close}
|
|
64
|
+
* title="Details"
|
|
65
|
+
* size="lg"
|
|
66
|
+
* >
|
|
67
|
+
* <Details />
|
|
68
|
+
* </Drawer>
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```tsx
|
|
73
|
+
* // Custom behavior
|
|
74
|
+
* <Drawer
|
|
75
|
+
* opened={opened}
|
|
76
|
+
* onClose={close}
|
|
77
|
+
* title="Modal Dialog"
|
|
78
|
+
* closeOnClickOutside={false}
|
|
79
|
+
* closeOnEscape={false}
|
|
80
|
+
* withCloseButton={true}
|
|
81
|
+
* >
|
|
82
|
+
* <Form />
|
|
83
|
+
* </Drawer>
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
export const Drawer = forwardRef<HTMLDivElement, DSDrawerProps>(
|
|
87
|
+
(
|
|
88
|
+
{
|
|
89
|
+
opened,
|
|
90
|
+
onClose,
|
|
91
|
+
title,
|
|
92
|
+
children,
|
|
93
|
+
size = 'md',
|
|
94
|
+
position = 'right',
|
|
95
|
+
withCloseButton = true,
|
|
96
|
+
closeOnClickOutside = true,
|
|
97
|
+
closeOnEscape = true,
|
|
98
|
+
...props
|
|
99
|
+
},
|
|
100
|
+
ref
|
|
101
|
+
) => {
|
|
102
|
+
return (
|
|
103
|
+
<MantineDrawer
|
|
104
|
+
ref={ref}
|
|
105
|
+
opened={opened}
|
|
106
|
+
onClose={onClose}
|
|
107
|
+
title={title}
|
|
108
|
+
size={size}
|
|
109
|
+
position={position}
|
|
110
|
+
withCloseButton={withCloseButton}
|
|
111
|
+
closeOnClickOutside={closeOnClickOutside}
|
|
112
|
+
closeOnEscape={closeOnEscape}
|
|
113
|
+
radius={0}
|
|
114
|
+
shadow="lg"
|
|
115
|
+
{...props}
|
|
116
|
+
>
|
|
117
|
+
{children}
|
|
118
|
+
</MantineDrawer>
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
|
|
123
|
+
Drawer.displayName = 'Drawer';
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { Menu as MantineMenu, MenuProps as MantineMenuProps } from '@mantine/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Menu Item interface for structured menu data
|
|
8
|
+
*/
|
|
9
|
+
export interface MenuItem {
|
|
10
|
+
/** Unique identifier for the menu item */
|
|
11
|
+
id: string;
|
|
12
|
+
/** Menu item label */
|
|
13
|
+
label: string;
|
|
14
|
+
/** Left section icon */
|
|
15
|
+
leftSection?: React.ReactNode;
|
|
16
|
+
/** Right section content (badge, shortcut, etc.) */
|
|
17
|
+
rightSection?: React.ReactNode;
|
|
18
|
+
/** Click handler */
|
|
19
|
+
onClick?: () => void;
|
|
20
|
+
/** Whether item is disabled */
|
|
21
|
+
disabled?: boolean;
|
|
22
|
+
/** Item color for semantic styling */
|
|
23
|
+
color?: 'red' | 'default';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Menu Section interface for organizing menu items
|
|
28
|
+
*/
|
|
29
|
+
export interface MenuSection {
|
|
30
|
+
/** Section title/label */
|
|
31
|
+
title?: string;
|
|
32
|
+
/** Array of menu items in this section */
|
|
33
|
+
items: MenuItem[];
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface LegacyMenuProps extends Omit<MantineMenuProps, 'children' | 'trigger'> {
|
|
37
|
+
/** Menu trigger element */
|
|
38
|
+
trigger: React.ReactNode;
|
|
39
|
+
/** Array of menu sections */
|
|
40
|
+
sections: MenuSection[];
|
|
41
|
+
/** Mantine-composed children are not used with the legacy API */
|
|
42
|
+
children?: never;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Thin Menu wrapper over Mantine Menu.
|
|
47
|
+
*
|
|
48
|
+
* Preferred usage mirrors Mantine composition directly:
|
|
49
|
+
* `Menu -> Menu.Target -> Menu.Dropdown -> Menu.Item`.
|
|
50
|
+
*
|
|
51
|
+
* The legacy `trigger + sections` API is still supported to avoid breaking
|
|
52
|
+
* existing DS consumers while Menu moves to a 1:1 Mantine/Figma prop model.
|
|
53
|
+
*/
|
|
54
|
+
export type DSMenuProps = MantineMenuProps | LegacyMenuProps;
|
|
55
|
+
|
|
56
|
+
const isLegacyMenuProps = (props: DSMenuProps): props is LegacyMenuProps =>
|
|
57
|
+
'trigger' in props && 'sections' in props;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* AppDirect Design System Menu Component
|
|
61
|
+
*
|
|
62
|
+
* A dropdown menu component built on top of Mantine's Menu with
|
|
63
|
+
* consistent design system styling.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```tsx
|
|
67
|
+
* // Mantine-aligned composition
|
|
68
|
+
* <Menu shadow="md" width={220}>
|
|
69
|
+
* <Menu.Target>
|
|
70
|
+
* <Button>Actions</Button>
|
|
71
|
+
* </Menu.Target>
|
|
72
|
+
*
|
|
73
|
+
* <Menu.Dropdown>
|
|
74
|
+
* <Menu.Item>Edit</Menu.Item>
|
|
75
|
+
* <Menu.Item>Duplicate</Menu.Item>
|
|
76
|
+
* <Menu.Divider />
|
|
77
|
+
* <Menu.Label>Danger zone</Menu.Label>
|
|
78
|
+
* <Menu.Item color="red">Delete</Menu.Item>
|
|
79
|
+
* </Menu.Dropdown>
|
|
80
|
+
* </Menu>
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* // Legacy structured API still supported during migration
|
|
86
|
+
* <Menu
|
|
87
|
+
* trigger={<Button>Menu</Button>}
|
|
88
|
+
* sections={[
|
|
89
|
+
* {
|
|
90
|
+
* title: "Application",
|
|
91
|
+
* items: [
|
|
92
|
+
* {
|
|
93
|
+
* id: "settings",
|
|
94
|
+
* label: "Settings",
|
|
95
|
+
* leftSection: <RiSettingsLine size={14} />,
|
|
96
|
+
* onClick: () => console.log('Settings')
|
|
97
|
+
* },
|
|
98
|
+
* {
|
|
99
|
+
* id: "search",
|
|
100
|
+
* label: "Search",
|
|
101
|
+
* leftSection: <RiSearchLine size={14} />,
|
|
102
|
+
* rightSection: "⌘K",
|
|
103
|
+
* onClick: () => console.log('Search')
|
|
104
|
+
* }
|
|
105
|
+
* ]
|
|
106
|
+
* },
|
|
107
|
+
* {
|
|
108
|
+
* title: "Danger Zone",
|
|
109
|
+
* items: [
|
|
110
|
+
* {
|
|
111
|
+
* id: "delete-account",
|
|
112
|
+
* label: "Delete Account",
|
|
113
|
+
* leftSection: <RiDeleteBinLine size={14} />,
|
|
114
|
+
* color: "red",
|
|
115
|
+
* onClick: () => console.log('Delete Account')
|
|
116
|
+
* }
|
|
117
|
+
* ]
|
|
118
|
+
* }
|
|
119
|
+
* ]}
|
|
120
|
+
* />
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
const MenuRoot = forwardRef<HTMLDivElement, DSMenuProps>((props, _ref) => {
|
|
124
|
+
if (isLegacyMenuProps(props)) {
|
|
125
|
+
const {
|
|
126
|
+
trigger,
|
|
127
|
+
sections,
|
|
128
|
+
shadow = 'md',
|
|
129
|
+
radius = 'sm',
|
|
130
|
+
...menuProps
|
|
131
|
+
} = props;
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<MantineMenu
|
|
135
|
+
shadow={shadow}
|
|
136
|
+
radius={radius}
|
|
137
|
+
{...menuProps}
|
|
138
|
+
>
|
|
139
|
+
<MantineMenu.Target>{trigger}</MantineMenu.Target>
|
|
140
|
+
|
|
141
|
+
<MantineMenu.Dropdown>
|
|
142
|
+
{sections.map((section, sectionIndex) => (
|
|
143
|
+
<React.Fragment key={sectionIndex}>
|
|
144
|
+
{sectionIndex > 0 && <MantineMenu.Divider />}
|
|
145
|
+
|
|
146
|
+
{section.title && (
|
|
147
|
+
<MantineMenu.Label>{section.title}</MantineMenu.Label>
|
|
148
|
+
)}
|
|
149
|
+
|
|
150
|
+
{section.items.map((item) => (
|
|
151
|
+
<MantineMenu.Item
|
|
152
|
+
key={item.id}
|
|
153
|
+
leftSection={item.leftSection}
|
|
154
|
+
rightSection={item.rightSection}
|
|
155
|
+
onClick={item.onClick}
|
|
156
|
+
disabled={item.disabled}
|
|
157
|
+
color={item.color}
|
|
158
|
+
>
|
|
159
|
+
{item.label}
|
|
160
|
+
</MantineMenu.Item>
|
|
161
|
+
))}
|
|
162
|
+
</React.Fragment>
|
|
163
|
+
))}
|
|
164
|
+
</MantineMenu.Dropdown>
|
|
165
|
+
</MantineMenu>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const {
|
|
170
|
+
shadow = 'md',
|
|
171
|
+
radius = 'sm',
|
|
172
|
+
...menuProps
|
|
173
|
+
} = props;
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<MantineMenu
|
|
177
|
+
shadow={shadow}
|
|
178
|
+
radius={radius}
|
|
179
|
+
{...menuProps}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
MenuRoot.displayName = 'Menu';
|
|
185
|
+
|
|
186
|
+
export const Menu = Object.assign(MenuRoot, {
|
|
187
|
+
Target: MantineMenu.Target,
|
|
188
|
+
Dropdown: MantineMenu.Dropdown,
|
|
189
|
+
Item: MantineMenu.Item,
|
|
190
|
+
Label: MantineMenu.Label,
|
|
191
|
+
Divider: MantineMenu.Divider,
|
|
192
|
+
});
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { Modal as MantineModal, ModalProps as MantineModalProps, Stack } from '@mantine/core';
|
|
5
|
+
import { Inline } from '..';
|
|
6
|
+
import { Button } from '../Buttons';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Thin Design System wrapper over Mantine Modal.
|
|
10
|
+
*
|
|
11
|
+
* Keeps the core Mantine shell props (`title`, `size`, `withCloseButton`,
|
|
12
|
+
* `children`, etc.) while applying DS defaults like `radius="sm"`.
|
|
13
|
+
*/
|
|
14
|
+
export interface DSModalProps extends Omit<MantineModalProps, 'title'> {
|
|
15
|
+
/** Modal title */
|
|
16
|
+
title?: React.ReactNode;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* AppDirect Design System Modal Component
|
|
21
|
+
*
|
|
22
|
+
* A modal dialog component built on top of Mantine's Modal with
|
|
23
|
+
* consistent design system styling.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```tsx
|
|
27
|
+
* // Simple content modal
|
|
28
|
+
* <Modal
|
|
29
|
+
* opened={infoOpened}
|
|
30
|
+
* onClose={() => setInfoOpened(false)}
|
|
31
|
+
* title="Information"
|
|
32
|
+
* size="sm"
|
|
33
|
+
* >
|
|
34
|
+
* <Text>This is some information content.</Text>
|
|
35
|
+
* </Modal>
|
|
36
|
+
* ```
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```tsx
|
|
40
|
+
* // Confirmation buttons composed inside children
|
|
41
|
+
* <Modal
|
|
42
|
+
* opened={confirmOpened}
|
|
43
|
+
* onClose={() => setConfirmOpened(false)}
|
|
44
|
+
* title="Confirm Action"
|
|
45
|
+
* >
|
|
46
|
+
* <Stack gap="md">
|
|
47
|
+
* <Text>Are you sure you want to perform this action?</Text>
|
|
48
|
+
* <Inline justify="flex-end" gap="sm">
|
|
49
|
+
* <Button variant="outline">Cancel</Button>
|
|
50
|
+
* <Button variant="primary">Confirm</Button>
|
|
51
|
+
* </Inline>
|
|
52
|
+
* </Stack>
|
|
53
|
+
* </Modal>
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export const Modal = forwardRef<HTMLDivElement, DSModalProps>(
|
|
57
|
+
(
|
|
58
|
+
{
|
|
59
|
+
title,
|
|
60
|
+
size = 'md',
|
|
61
|
+
withCloseButton = true,
|
|
62
|
+
closeOnClickOutside = true,
|
|
63
|
+
closeOnEscape = true,
|
|
64
|
+
padding = 'md',
|
|
65
|
+
centered = true,
|
|
66
|
+
...props
|
|
67
|
+
},
|
|
68
|
+
ref
|
|
69
|
+
) => {
|
|
70
|
+
return (
|
|
71
|
+
<MantineModal
|
|
72
|
+
ref={ref}
|
|
73
|
+
title={title}
|
|
74
|
+
size={size}
|
|
75
|
+
withCloseButton={withCloseButton}
|
|
76
|
+
closeOnClickOutside={closeOnClickOutside}
|
|
77
|
+
closeOnEscape={closeOnEscape}
|
|
78
|
+
padding={padding}
|
|
79
|
+
centered={centered}
|
|
80
|
+
radius="sm"
|
|
81
|
+
{...props}
|
|
82
|
+
/>
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
Modal.displayName = 'Modal';
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Pre-configured confirmation helper built on top of Modal.
|
|
91
|
+
*/
|
|
92
|
+
export interface ConfirmationModalProps extends Omit<DSModalProps, 'children'> {
|
|
93
|
+
/** Confirmation button label */
|
|
94
|
+
confirmLabel?: string;
|
|
95
|
+
/** Cancel button label */
|
|
96
|
+
cancelLabel?: string;
|
|
97
|
+
/** Confirmation button variant */
|
|
98
|
+
confirmVariant?: 'primary' | 'danger';
|
|
99
|
+
/** Confirm action handler */
|
|
100
|
+
onConfirm?: () => void;
|
|
101
|
+
/** Cancel action handler */
|
|
102
|
+
onCancel?: () => void;
|
|
103
|
+
/** Whether confirm button is loading */
|
|
104
|
+
confirmLoading?: boolean;
|
|
105
|
+
/** Optional content shown above the confirmation actions */
|
|
106
|
+
children?: React.ReactNode;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export const ConfirmationModal = forwardRef<HTMLDivElement, ConfirmationModalProps>(
|
|
110
|
+
(
|
|
111
|
+
{
|
|
112
|
+
confirmLabel = 'Confirm',
|
|
113
|
+
cancelLabel = 'Cancel',
|
|
114
|
+
confirmVariant = 'primary',
|
|
115
|
+
onConfirm,
|
|
116
|
+
onCancel,
|
|
117
|
+
confirmLoading = false,
|
|
118
|
+
onClose,
|
|
119
|
+
children,
|
|
120
|
+
...props
|
|
121
|
+
},
|
|
122
|
+
ref
|
|
123
|
+
) => {
|
|
124
|
+
const handleCancel = () => {
|
|
125
|
+
onCancel?.();
|
|
126
|
+
onClose();
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const handleConfirm = () => {
|
|
130
|
+
onConfirm?.();
|
|
131
|
+
|
|
132
|
+
if (!confirmLoading) {
|
|
133
|
+
onClose();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<Modal
|
|
139
|
+
ref={ref}
|
|
140
|
+
onClose={onClose}
|
|
141
|
+
{...props}
|
|
142
|
+
>
|
|
143
|
+
<Stack gap="md">
|
|
144
|
+
{children}
|
|
145
|
+
<Inline justify="flex-end" gap="sm">
|
|
146
|
+
<Button variant="outline" onClick={handleCancel}>
|
|
147
|
+
{cancelLabel}
|
|
148
|
+
</Button>
|
|
149
|
+
<Button variant={confirmVariant} onClick={handleConfirm} loading={confirmLoading}>
|
|
150
|
+
{confirmLabel}
|
|
151
|
+
</Button>
|
|
152
|
+
</Inline>
|
|
153
|
+
</Stack>
|
|
154
|
+
</Modal>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
ConfirmationModal.displayName = 'ConfirmationModal';
|