@react-fabric/core 1.0.0-beta.51 → 1.0.0-beta.53
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/css/components/_breadcrumbs.css +3 -3
- package/css/components/_menu.css +2 -0
- package/css/components/_modal.css +2 -2
- package/css/core/_aside.css +2 -2
- package/css/theme/_utilities.css +2 -2
- package/dist/cjs/components/actionLabel/ActionLabel.js +23 -5
- package/dist/cjs/components/animations/Animations.js +92 -9
- package/dist/cjs/components/avatar/Avatar.js +33 -3
- package/dist/cjs/components/avatar/AvatarGroup.js +19 -1
- package/dist/cjs/components/badge/Badge.js +31 -2
- package/dist/cjs/components/breadcrumbs/Breadcrumbs.js +30 -1
- package/dist/cjs/components/button/Button.js +25 -2
- package/dist/cjs/components/button/ButtonGroup.js +26 -0
- package/dist/cjs/components/button/ConfirmButton.js +22 -1
- package/dist/cjs/components/button/ToggleButtonGroup.js +38 -12
- package/dist/cjs/components/callout/Callout.js +28 -0
- package/dist/cjs/components/card/Card.js +34 -0
- package/dist/cjs/components/card/CardCover.js +26 -0
- package/dist/cjs/components/card/FlipContent.js +21 -0
- package/dist/cjs/components/chip/Chip.js +22 -1
- package/dist/cjs/components/collapsable/Collapsable.js +26 -0
- package/dist/cjs/components/divider/Divider.js +19 -0
- package/dist/cjs/components/dropdown/Dropdown.js +42 -0
- package/dist/cjs/components/empty/EmptyContent.js +27 -0
- package/dist/cjs/components/icon/Icon.js +27 -1
- package/dist/cjs/components/media/Media.js +56 -0
- package/dist/cjs/components/menu/ContextMenu.js +19 -0
- package/dist/cjs/components/menu/Menu.js +30 -0
- package/dist/cjs/components/menu/MenuItem.js +22 -1
- package/dist/cjs/components/meter/Meter.js +24 -0
- package/dist/cjs/components/navigator/Navigator.js +22 -0
- package/dist/cjs/components/panel/Panel.js +37 -0
- package/dist/cjs/components/panel/PanelGroup.js +24 -0
- package/dist/cjs/components/panel/PanelStack.js +31 -0
- package/dist/cjs/components/progress/ProgressBar.js +21 -0
- package/dist/cjs/components/progress/ProgressCircle.js +20 -0
- package/dist/cjs/components/tabpanel/Tab.js +31 -0
- package/dist/cjs/components/tabpanel/TabPanel.js +33 -0
- package/dist/cjs/context/Global.js +25 -1
- package/dist/cjs/core/aside/Aside.js +39 -2
- package/dist/cjs/core/boundary/ErrorBoundary.js +17 -1
- package/dist/cjs/core/content/Content.js +6 -1
- package/dist/cjs/core/headfoot/HeadFoot.js +42 -0
- package/dist/cjs/core/page/Page.js +26 -1
- package/dist/cjs/core/responsive/Responsive.js +55 -2
- package/dist/cjs/core/section/Section.js +11 -27
- package/dist/cjs/core/theme/ThemeProvider.js +21 -1
- package/dist/cjs/core/viewport/Viewport.js +15 -1
- package/dist/cjs/hooks/useControlledValue.js +12 -0
- package/dist/cjs/hooks/useDebounce.js +13 -0
- package/dist/cjs/hooks/useEffectDebugger.js +52 -0
- package/dist/cjs/hooks/useIsDark.js +8 -0
- package/dist/cjs/hooks/useIsRtl.js +12 -0
- package/dist/cjs/hooks/useOverlayService.js +24 -0
- package/dist/cjs/hooks/usePropToggle.js +16 -5
- package/dist/cjs/hooks/useResize.js +18 -0
- package/dist/cjs/hooks/useResizeObserver.js +19 -0
- package/dist/cjs/hooks/useStorage.js +39 -0
- package/dist/cjs/types/icons.js +4 -0
- package/dist/cjs/typography/Abbr.js +28 -1
- package/dist/cjs/typography/Anchor.js +18 -1
- package/dist/cjs/typography/Mark.js +20 -1
- package/dist/cjs/typography/Text.js +27 -1
- package/dist/cjs/typography/Title.js +16 -1
- package/dist/esm/components/actionLabel/ActionLabel.js +23 -5
- package/dist/esm/components/animations/Animations.js +92 -9
- package/dist/esm/components/avatar/Avatar.js +33 -3
- package/dist/esm/components/avatar/AvatarGroup.js +19 -1
- package/dist/esm/components/badge/Badge.js +32 -3
- package/dist/esm/components/breadcrumbs/Breadcrumbs.js +30 -1
- package/dist/esm/components/button/Button.js +25 -2
- package/dist/esm/components/button/ButtonGroup.js +26 -0
- package/dist/esm/components/button/ConfirmButton.js +22 -1
- package/dist/esm/components/button/ToggleButtonGroup.js +39 -13
- package/dist/esm/components/callout/Callout.js +28 -0
- package/dist/esm/components/card/Card.js +34 -0
- package/dist/esm/components/card/CardCover.js +26 -0
- package/dist/esm/components/card/FlipContent.js +21 -0
- package/dist/esm/components/chip/Chip.js +22 -1
- package/dist/esm/components/collapsable/Collapsable.js +26 -0
- package/dist/esm/components/divider/Divider.js +19 -0
- package/dist/esm/components/dropdown/Dropdown.js +42 -0
- package/dist/esm/components/empty/EmptyContent.js +27 -0
- package/dist/esm/components/icon/Icon.js +27 -1
- package/dist/esm/components/media/Media.js +56 -0
- package/dist/esm/components/menu/ContextMenu.js +19 -0
- package/dist/esm/components/menu/Menu.js +30 -0
- package/dist/esm/components/menu/MenuItem.js +22 -1
- package/dist/esm/components/meter/Meter.js +24 -0
- package/dist/esm/components/navigator/Navigator.js +22 -0
- package/dist/esm/components/panel/Panel.js +37 -0
- package/dist/esm/components/panel/PanelGroup.js +24 -0
- package/dist/esm/components/panel/PanelStack.js +31 -0
- package/dist/esm/components/progress/ProgressBar.js +21 -0
- package/dist/esm/components/progress/ProgressCircle.js +20 -0
- package/dist/esm/components/tabpanel/Tab.js +31 -0
- package/dist/esm/components/tabpanel/TabPanel.js +33 -0
- package/dist/esm/context/Global.js +25 -1
- package/dist/esm/core/aside/Aside.js +39 -2
- package/dist/esm/core/boundary/ErrorBoundary.js +17 -1
- package/dist/esm/core/content/Content.js +6 -1
- package/dist/esm/core/headfoot/HeadFoot.js +42 -0
- package/dist/esm/core/page/Page.js +26 -1
- package/dist/esm/core/responsive/Responsive.js +55 -2
- package/dist/esm/core/section/Section.js +11 -27
- package/dist/esm/core/theme/ThemeProvider.js +21 -1
- package/dist/esm/core/viewport/Viewport.js +15 -1
- package/dist/esm/hooks/useControlledValue.js +12 -0
- package/dist/esm/hooks/useDebounce.js +13 -0
- package/dist/esm/hooks/useEffectDebugger.js +52 -0
- package/dist/esm/hooks/useIsDark.js +8 -0
- package/dist/esm/hooks/useIsRtl.js +12 -0
- package/dist/esm/hooks/useOverlayService.js +24 -0
- package/dist/esm/hooks/usePropToggle.js +16 -5
- package/dist/esm/hooks/useResize.js +18 -0
- package/dist/esm/hooks/useResizeObserver.js +19 -0
- package/dist/esm/hooks/useStorage.js +39 -0
- package/dist/esm/types/icons.js +4 -0
- package/dist/esm/typography/Abbr.js +28 -1
- package/dist/esm/typography/Anchor.js +18 -1
- package/dist/esm/typography/Mark.js +20 -1
- package/dist/esm/typography/Text.js +27 -1
- package/dist/esm/typography/Title.js +16 -1
- package/dist/types/components/actionLabel/ActionLabel.d.ts +21 -2
- package/dist/types/components/animations/Animations.d.ts +80 -1
- package/dist/types/components/avatar/Avatar.d.ts +26 -2
- package/dist/types/components/avatar/AvatarGroup.d.ts +19 -1
- package/dist/types/components/badge/Badge.d.ts +25 -0
- package/dist/types/components/breadcrumbs/Breadcrumbs.d.ts +29 -0
- package/dist/types/components/button/Button.d.ts +23 -2
- package/dist/types/components/button/ButtonGroup.d.ts +26 -1
- package/dist/types/components/button/ConfirmButton.d.ts +23 -3
- package/dist/types/components/button/ToggleButtonGroup.d.ts +39 -11
- package/dist/types/components/callout/Callout.d.ts +26 -1
- package/dist/types/components/card/Card.d.ts +34 -0
- package/dist/types/components/card/CardCover.d.ts +25 -0
- package/dist/types/components/card/FlipContent.d.ts +21 -0
- package/dist/types/components/chip/Chip.d.ts +21 -1
- package/dist/types/components/collapsable/Collapsable.d.ts +26 -0
- package/dist/types/components/divider/Divider.d.ts +19 -0
- package/dist/types/components/dropdown/Dropdown.d.ts +40 -1
- package/dist/types/components/dropdown/DropdownTool.d.ts +25 -0
- package/dist/types/components/empty/EmptyContent.d.ts +26 -1
- package/dist/types/components/icon/Icon.d.ts +27 -2
- package/dist/types/components/media/Media.d.ts +54 -0
- package/dist/types/components/menu/ContextMenu.d.ts +19 -1
- package/dist/types/components/menu/Menu.d.ts +29 -0
- package/dist/types/components/menu/MenuItem.d.ts +22 -2
- package/dist/types/components/meter/Meter.d.ts +24 -0
- package/dist/types/components/navigator/Navigator.d.ts +22 -0
- package/dist/types/components/panel/Panel.d.ts +37 -0
- package/dist/types/components/panel/PanelGroup.d.ts +24 -0
- package/dist/types/components/panel/PanelStack.d.ts +31 -0
- package/dist/types/components/progress/ProgressBar.d.ts +20 -0
- package/dist/types/components/progress/ProgressCircle.d.ts +19 -0
- package/dist/types/components/tabpanel/Tab.d.ts +32 -1
- package/dist/types/components/tabpanel/TabPanel.d.ts +33 -0
- package/dist/types/context/Global.d.ts +24 -1
- package/dist/types/core/aside/Aside.d.ts +38 -1
- package/dist/types/core/boundary/ErrorBoundary.d.ts +17 -1
- package/dist/types/core/content/Content.d.ts +6 -1
- package/dist/types/core/headfoot/HeadFoot.d.ts +40 -0
- package/dist/types/core/page/Page.d.ts +26 -1
- package/dist/types/core/responsive/Responsive.d.ts +52 -1
- package/dist/types/core/section/Section.d.ts +18 -3
- package/dist/types/core/theme/ThemeProvider.d.ts +21 -1
- package/dist/types/core/viewport/Viewport.d.ts +15 -1
- package/dist/types/hooks/useControlledValue.d.ts +13 -2
- package/dist/types/hooks/useDebounce.d.ts +12 -0
- package/dist/types/hooks/useEffectDebugger.d.ts +49 -0
- package/dist/types/hooks/useIsDark.d.ts +8 -0
- package/dist/types/hooks/useIsRtl.d.ts +12 -0
- package/dist/types/hooks/useNavigator.d.ts +18 -1
- package/dist/types/hooks/useOverlayService.d.ts +25 -4
- package/dist/types/hooks/usePropToggle.d.ts +16 -5
- package/dist/types/hooks/useResize.d.ts +18 -0
- package/dist/types/hooks/useResizeObserver.d.ts +19 -0
- package/dist/types/hooks/useStorage.d.ts +38 -0
- package/dist/types/types/icons.d.ts +4 -0
- package/dist/types/typography/Abbr.d.ts +28 -1
- package/dist/types/typography/Anchor.d.ts +19 -2
- package/dist/types/typography/Copy.d.ts +15 -0
- package/dist/types/typography/Mark.d.ts +20 -1
- package/dist/types/typography/Text.d.ts +27 -1
- package/dist/types/typography/Title.d.ts +16 -1
- package/package.json +3 -3
- package/src/components/actionLabel/ActionLabel.tsx +23 -5
- package/src/components/animations/Animations.tsx +93 -14
- package/src/components/avatar/Avatar.tsx +32 -3
- package/src/components/avatar/AvatarGroup.tsx +19 -1
- package/src/components/badge/Badge.tsx +33 -3
- package/src/components/breadcrumbs/Breadcrumbs.tsx +30 -1
- package/src/components/button/Button.tsx +24 -2
- package/src/components/button/ButtonGroup.tsx +26 -0
- package/src/components/button/ConfirmButton.tsx +22 -1
- package/src/components/button/ToggleButtonGroup.tsx +70 -43
- package/src/components/callout/Callout.tsx +27 -0
- package/src/components/card/Card.tsx +34 -0
- package/src/components/card/CardCover.tsx +25 -0
- package/src/components/card/FlipContent.tsx +21 -0
- package/src/components/chip/Chip.tsx +21 -1
- package/src/components/collapsable/Collapsable.tsx +26 -0
- package/src/components/divider/Divider.tsx +19 -0
- package/src/components/dropdown/Dropdown.tsx +40 -0
- package/src/components/dropdown/DropdownTool.tsx +25 -0
- package/src/components/empty/EmptyContent.tsx +26 -0
- package/src/components/icon/Icon.tsx +27 -1
- package/src/components/media/Media.tsx +54 -0
- package/src/components/menu/ContextMenu.tsx +19 -0
- package/src/components/menu/Menu.tsx +29 -0
- package/src/components/menu/MenuItem.tsx +22 -1
- package/src/components/meter/Meter.tsx +24 -0
- package/src/components/navigator/Navigator.tsx +22 -0
- package/src/components/panel/Panel.tsx +37 -0
- package/src/components/panel/PanelGroup.tsx +24 -0
- package/src/components/panel/PanelStack.tsx +31 -0
- package/src/components/progress/ProgressBar.tsx +20 -0
- package/src/components/progress/ProgressCircle.tsx +19 -0
- package/src/components/tabpanel/Tab.tsx +31 -0
- package/src/components/tabpanel/TabPanel.tsx +33 -0
- package/src/context/Global.tsx +24 -1
- package/src/core/aside/Aside.tsx +39 -2
- package/src/core/boundary/ErrorBoundary.tsx +17 -1
- package/src/core/content/Content.tsx +6 -1
- package/src/core/headfoot/HeadFoot.tsx +40 -0
- package/src/core/page/Page.tsx +26 -1
- package/src/core/responsive/Responsive.tsx +53 -2
- package/src/core/section/Section.tsx +25 -2
- package/src/core/theme/ThemeProvider.tsx +21 -1
- package/src/core/viewport/Viewport.tsx +15 -1
- package/src/hooks/useControlledValue.tsx +12 -0
- package/src/hooks/useDebounce.ts +12 -0
- package/src/hooks/useEffectDebugger.ts +49 -0
- package/src/hooks/useIsDark.ts +8 -0
- package/src/hooks/useIsRtl.ts +12 -0
- package/src/hooks/useNavigator.tsx +18 -0
- package/src/hooks/useOverlayService.tsx +24 -0
- package/src/hooks/usePropToggle.ts +16 -5
- package/src/hooks/useResize.ts +18 -0
- package/src/hooks/useResizeObserver.ts +19 -0
- package/src/hooks/useStorage.ts +38 -0
- package/src/types/icons.ts +5 -1
- package/src/typography/Abbr.tsx +28 -1
- package/src/typography/Anchor.tsx +18 -1
- package/src/typography/Copy.tsx +15 -0
- package/src/typography/Mark.tsx +20 -1
- package/src/typography/Text.tsx +27 -1
- package/src/typography/Title.tsx +16 -1
|
@@ -84,6 +84,39 @@ export interface TabPanelProps extends ChildrenProp<typeof Tab> {
|
|
|
84
84
|
|
|
85
85
|
// TODO: implement append/prepend tab-bar items
|
|
86
86
|
|
|
87
|
+
/**
|
|
88
|
+
* A component that provides a tabbed interface for displaying content.
|
|
89
|
+
* It allows users to switch between different tabs, each containing its own content.
|
|
90
|
+
* It supports various orientations, justify options, and variants for the tab header.
|
|
91
|
+
* It also provides hooks for handling tab changes before and after they occur.
|
|
92
|
+
* This component is useful for organizing content into separate sections that can be easily navigated by the user.
|
|
93
|
+
* It can be customized with different styles and behaviors to fit the needs of the application.
|
|
94
|
+
*
|
|
95
|
+
* @param {TabPanelProps} props - The properties for the TabPanel component.
|
|
96
|
+
* @returns {JSX.Element} The rendered TabPanel component.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```jsx
|
|
100
|
+
* <TabPanel
|
|
101
|
+
* orientation="top"
|
|
102
|
+
* activeTab="tab1"
|
|
103
|
+
* justify="start"
|
|
104
|
+
* variant="solid"
|
|
105
|
+
* tabFlex={true}
|
|
106
|
+
* onBeforeChange={(nextTab, currentTab) => {
|
|
107
|
+
* console.log(`Switching from ${currentTab} to ${nextTab}`);
|
|
108
|
+
* return true; // or false to prevent change
|
|
109
|
+
* }}
|
|
110
|
+
* onChange={(id) => console.log(`Active tab changed to: ${id}`)}
|
|
111
|
+
* >
|
|
112
|
+
* <Tab id="tab1" label="Tab 1">Content for Tab 1</Tab>
|
|
113
|
+
* <Tab id="tab2" label="Tab 2">Content for Tab 2</Tab>
|
|
114
|
+
* <Tab id="tab3" label="Tab 3">Content for Tab 3</Tab>
|
|
115
|
+
* </TabPanel>
|
|
116
|
+
* ```
|
|
117
|
+
*
|
|
118
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/core-components-tabpanel--docs} for more details.
|
|
119
|
+
*/
|
|
87
120
|
export const TabPanel = ({
|
|
88
121
|
children,
|
|
89
122
|
headerClassName,
|
package/src/context/Global.tsx
CHANGED
|
@@ -232,13 +232,36 @@ export const ApplicationProvider: FC<GlobalProps> = ({
|
|
|
232
232
|
export const useGlobals = () => useContext(GlobalContext);
|
|
233
233
|
|
|
234
234
|
/**
|
|
235
|
-
* global application context
|
|
235
|
+
* Hook to access the global application context.
|
|
236
|
+
* This hook provides access to the global context values, including the current locale, calendar, and color scheme.
|
|
237
|
+
*
|
|
238
|
+
* @returns {GlobalContextType} The global context values excluding the error element.
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```jsx
|
|
242
|
+
* const { changeLocale, currentLocale, toggleColorScheme } = useApplicationContext();
|
|
243
|
+
* ```
|
|
236
244
|
*/
|
|
237
245
|
export const useApplicationContext = () => {
|
|
238
246
|
const { errorElement, ...rest } = useContext(GlobalContext);
|
|
239
247
|
return rest;
|
|
240
248
|
};
|
|
241
249
|
|
|
250
|
+
/**
|
|
251
|
+
* Hook to access the notification manager from the global context.
|
|
252
|
+
* This hook provides methods to show alerts, errors, messages, and toasts.
|
|
253
|
+
* It returns a reference to the notification manager, which can be used to display notifications in the application.
|
|
254
|
+
*
|
|
255
|
+
* @returns {NotificationManagerRef} The notification manager reference.
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```jsx
|
|
259
|
+
* const notificationService = useNotificationService();
|
|
260
|
+
* notificationService.showMessage("Hello World");
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/core-components-notifications--notifications} for more details on available methods.
|
|
264
|
+
*/
|
|
242
265
|
export const useNotificationService = () => {
|
|
243
266
|
const { notificationManager } = useContext(GlobalContext);
|
|
244
267
|
return notificationManager ?? {};
|
package/src/core/aside/Aside.tsx
CHANGED
|
@@ -105,7 +105,44 @@ export interface AsideProps
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
/**
|
|
108
|
-
*
|
|
108
|
+
* A sidebar component that can be collapsed, resized, and has a flyout feature.
|
|
109
|
+
* It supports a title, icon, actions, and loading state.
|
|
110
|
+
* It can be aligned to the start or end of the page.
|
|
111
|
+
*
|
|
112
|
+
* @param {AsideProps} props - The properties for the Aside component.
|
|
113
|
+
* @returns {JSX.Element} The rendered Aside component.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```jsx
|
|
117
|
+
* <Aside
|
|
118
|
+
* title="Sidebar Title"
|
|
119
|
+
* icon={CoreIcons.menu}
|
|
120
|
+
* iconBg="bg-gray-200"
|
|
121
|
+
* iconColor="text-gray-800"
|
|
122
|
+
* rtlFlip={true}
|
|
123
|
+
* className="custom-aside"
|
|
124
|
+
* bodyClassName="custom-aside-body"
|
|
125
|
+
* headerClassName="custom-aside-header"
|
|
126
|
+
* resizeable={true}
|
|
127
|
+
* flyout={true}
|
|
128
|
+
* onFlyout={() => console.log("Flyout triggered")}
|
|
129
|
+
* collapsed={false}
|
|
130
|
+
* collapsable={true}
|
|
131
|
+
* onCollapse={() => console.log("Collapsed toggled")}
|
|
132
|
+
* actions={<button>Action</button>}
|
|
133
|
+
* loading={false}
|
|
134
|
+
* align="start"
|
|
135
|
+
* width="20rem"
|
|
136
|
+
* minWidth="2rem"
|
|
137
|
+
* maxWidth="30vw"
|
|
138
|
+
* data-testid="aside-test"
|
|
139
|
+
* data-test-value="aside-value"
|
|
140
|
+
* >
|
|
141
|
+
* <Content>This is the content of the aside.</Content>
|
|
142
|
+
* </Aside>
|
|
143
|
+
* ```
|
|
144
|
+
*
|
|
145
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/core-application--aside} for more details.
|
|
109
146
|
*/
|
|
110
147
|
export const Aside = ({
|
|
111
148
|
children,
|
|
@@ -273,7 +310,7 @@ export const Aside = ({
|
|
|
273
310
|
{...resizeHandleProps}
|
|
274
311
|
className={classNames(
|
|
275
312
|
"fabric-asideResizer",
|
|
276
|
-
"before:absolute before:inset-0 before:w-1 before:top-1/2 before:-translate-y-1/2 before:transition-all",
|
|
313
|
+
"before:absolute before:inset-0 before:w-1 before:top-1/2 before:-translate-y-1/2 before:transition-all before:delay-150",
|
|
277
314
|
)}
|
|
278
315
|
/>
|
|
279
316
|
)}
|
|
@@ -91,7 +91,23 @@ const ErrorStack = ({ error, stack }: KeyValue) => {
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
/**
|
|
94
|
-
*
|
|
94
|
+
* ErrorBoundary component to catch JavaScript errors anywhere in the child component tree,
|
|
95
|
+
* log those errors, and display a fallback UI.
|
|
96
|
+
* It can also display a custom error element if provided.
|
|
97
|
+
* This component is useful for preventing the entire application from crashing
|
|
98
|
+
* when an error occurs in a part of the component tree.
|
|
99
|
+
* It can be used to wrap any part of the application.
|
|
100
|
+
* It supports custom error display components and provides a default error message.
|
|
101
|
+
* It also conditionally displays the error stack trace in development mode.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```jsx
|
|
105
|
+
* <ErrorBoundary errorElement={CustomErrorComponent}>
|
|
106
|
+
* <YourComponent />
|
|
107
|
+
* </ErrorBoundary>
|
|
108
|
+
* ```
|
|
109
|
+
*
|
|
110
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/core-application--error-boundary}
|
|
95
111
|
*/
|
|
96
112
|
export class ErrorBoundary extends Component<
|
|
97
113
|
{
|
|
@@ -51,7 +51,12 @@ export interface ContentProps
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Content component that wraps children in a section element.
|
|
55
|
+
* It uses a resize observer to handle resizing and a debounced scroll handler.
|
|
56
|
+
* It also includes an error boundary to catch any errors in the children.
|
|
57
|
+
*
|
|
58
|
+
* @param {ContentProps} props - The properties for the Content component.
|
|
59
|
+
* @returns A section element containing the children wrapped in an error boundary.
|
|
55
60
|
*/
|
|
56
61
|
export const Content = ({
|
|
57
62
|
ref,
|
|
@@ -72,10 +72,50 @@ const HeadFoot = ({
|
|
|
72
72
|
);
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Header component that wraps children in a header element.
|
|
77
|
+
* It uses the HeadFoot component to handle layout and styling.
|
|
78
|
+
* It accepts properties for direction, alignment, and justification,
|
|
79
|
+
* allowing for flexible layout configurations.
|
|
80
|
+
* The `as` prop is set to "header" to render the element as a header.
|
|
81
|
+
* The `area` prop is set to "head" to indicate that this is a header area.
|
|
82
|
+
* It can be used to create a consistent header layout across an application.
|
|
83
|
+
*
|
|
84
|
+
* @param {HeadFootProps} props - The properties for the Header component.
|
|
85
|
+
* @returns A header element containing the children wrapped in the HeadFoot component.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```jsx
|
|
89
|
+
* <Header className="custom-header" dir="ltr">
|
|
90
|
+
* <h1>Header content goes here</h1>
|
|
91
|
+
* </Header>
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
75
94
|
export const Header = (props: HeadFootProps) => (
|
|
76
95
|
<HeadFoot as="header" area="head" {...props} />
|
|
77
96
|
);
|
|
78
97
|
|
|
98
|
+
/**
|
|
99
|
+
* Footer component that wraps children in a footer element.
|
|
100
|
+
* It uses the HeadFoot component to handle layout and styling.
|
|
101
|
+
* It accepts properties for direction, alignment, and justification,
|
|
102
|
+
* allowing for flexible layout configurations.
|
|
103
|
+
* The `as` prop is set to "footer" to render the element as a footer.
|
|
104
|
+
* The `area` prop is set to "foot" to indicate that this is a footer area.
|
|
105
|
+
* It can be used to create a consistent footer layout across an application.
|
|
106
|
+
* * The Footer component is designed to be flexible and can be styled with custom classes.
|
|
107
|
+
* It supports both default and flex layouts, allowing for alignment and justification of its children.
|
|
108
|
+
*
|
|
109
|
+
* @param {HeadFootProps} props - The properties for the Footer component.
|
|
110
|
+
* @returns A footer element containing the children wrapped in the HeadFoot component.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```jsx
|
|
114
|
+
* <Footer className="custom-footer" dir="ltr">
|
|
115
|
+
* <p>Footer content goes here</p>
|
|
116
|
+
* </Footer>
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
79
119
|
export const Footer = (props: HeadFootProps) => (
|
|
80
120
|
<HeadFoot as="footer" area="foot" {...props} />
|
|
81
121
|
);
|
package/src/core/page/Page.tsx
CHANGED
|
@@ -55,7 +55,32 @@ export interface PageProps
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
|
-
*
|
|
58
|
+
* Page component that wraps children in a div element.
|
|
59
|
+
* It includes a title section with an optional icon and a loading indicator.
|
|
60
|
+
* The component can be styled with a paper effect, page icon and title.
|
|
61
|
+
* It also accepts a loading prop to display a loading indicator.
|
|
62
|
+
*
|
|
63
|
+
* @param {PageProps} props - The properties for the Page component.
|
|
64
|
+
* @returns A div element containing the title and children, with optional loading indicator.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* ```jsx
|
|
68
|
+
* <Page
|
|
69
|
+
* title="My Page"
|
|
70
|
+
* icon="home"
|
|
71
|
+
* iconBg="bg-blue-500"
|
|
72
|
+
* iconColor="text-white"
|
|
73
|
+
* loading={false}
|
|
74
|
+
* paper={true}
|
|
75
|
+
* data-testid="my-page"
|
|
76
|
+
* data-test-value="page-value"
|
|
77
|
+
* >
|
|
78
|
+
* <p>This is the content of the page.</p>
|
|
79
|
+
* </Page>
|
|
80
|
+
* // Renders a page with a title, icon, and content.
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/core-application--page} for more details.
|
|
59
84
|
*/
|
|
60
85
|
export const Page = ({
|
|
61
86
|
ref,
|
|
@@ -92,7 +92,20 @@ export interface ColProps
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
/**
|
|
95
|
-
*
|
|
95
|
+
* Container component that wraps children in a div element.
|
|
96
|
+
* It supports full width, gutter size, and additional CSS classes.
|
|
97
|
+
* It can be used to create a responsive layout with optional gutters for spacing.
|
|
98
|
+
* It accepts properties for full width, gutter size, and additional CSS classes.
|
|
99
|
+
*
|
|
100
|
+
* @param {ContainerProps} props - The properties for the Container component.
|
|
101
|
+
* @returns A div element containing the children with optional full width and gutter size.
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* ```jsx
|
|
105
|
+
* <Container fullWidth={true} gutter="16px" className="custom-container">
|
|
106
|
+
* <p>This is a container with full width and gutter.</p>
|
|
107
|
+
* </Container>
|
|
108
|
+
* ```
|
|
96
109
|
*/
|
|
97
110
|
export const Container = ({
|
|
98
111
|
children,
|
|
@@ -116,6 +129,26 @@ export const Container = ({
|
|
|
116
129
|
);
|
|
117
130
|
};
|
|
118
131
|
|
|
132
|
+
/**
|
|
133
|
+
* Row component that allows for flexible layout of columns.
|
|
134
|
+
* It supports various flex properties, alignment, and wrapping.
|
|
135
|
+
* It can be used to create a responsive layout with optional gutters for spacing.
|
|
136
|
+
* It accepts properties for gutter size, orientation, alignment, justification, and additional CSS classes.
|
|
137
|
+
*
|
|
138
|
+
* @param {RowProps} props - The properties for the Row component.
|
|
139
|
+
* @returns A div element representing a row with the specified flex and alignment properties.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```jsx
|
|
143
|
+
* <Row gutter="16px" orient="row" align="center" justify="between">
|
|
144
|
+
* <Col flex="fill">Column 1</Col>
|
|
145
|
+
* <Col flex="fill">Column 2</Col>
|
|
146
|
+
* </Row>
|
|
147
|
+
* // Renders a row with two columns, each taking equal space, centered vertically and spaced evenly.
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/core-application--responsive} for more details.
|
|
151
|
+
*/
|
|
119
152
|
export const Row = ({
|
|
120
153
|
children,
|
|
121
154
|
gutter,
|
|
@@ -148,6 +181,24 @@ export const Row = ({
|
|
|
148
181
|
);
|
|
149
182
|
};
|
|
150
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Column component that allows for flexible layout within a row.
|
|
186
|
+
* It supports various flex properties, alignment, and truncation.
|
|
187
|
+
* It can be used to create a responsive layout with optional stretching of inner content.
|
|
188
|
+
* It accepts properties for flex size, alignment, truncation, and additional CSS classes.
|
|
189
|
+
*
|
|
190
|
+
* @param {ColProps} props - The properties for the Col component.
|
|
191
|
+
* @returns A div element representing a column with the specified flex and alignment properties.
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```jsx
|
|
195
|
+
* <Col flex="fill" align="center" truncate className="custom-col">
|
|
196
|
+
* <p>This is a column with flexible layout.</p>
|
|
197
|
+
* </Col>
|
|
198
|
+
* ```
|
|
199
|
+
*
|
|
200
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/core-application--responsive} for more details.
|
|
201
|
+
*/
|
|
151
202
|
export const Col = ({
|
|
152
203
|
children,
|
|
153
204
|
flex,
|
|
@@ -167,7 +218,7 @@ export const Col = ({
|
|
|
167
218
|
flex === "full" && "flex-full",
|
|
168
219
|
flex === "auto" && "flex-auto",
|
|
169
220
|
flex === "initial" && "flex-initial",
|
|
170
|
-
flex === "content" && "flex-
|
|
221
|
+
flex === "content" && "flex-content",
|
|
171
222
|
align && `self-${align}`,
|
|
172
223
|
truncate && "truncate",
|
|
173
224
|
)}
|
|
@@ -22,25 +22,48 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import classNames from "classnames";
|
|
25
|
-
import {
|
|
25
|
+
import {
|
|
26
|
+
TestProps,
|
|
27
|
+
type ChildrenProp,
|
|
28
|
+
type CssProp,
|
|
29
|
+
type RefProp,
|
|
30
|
+
} from "../../types";
|
|
26
31
|
import { ErrorBoundary } from "../boundary/ErrorBoundary";
|
|
27
32
|
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
34
|
+
* A component that represents a section of content within a page, with templated grid layout.
|
|
35
|
+
* It can be used to group related content together and can be styled with additional CSS classes.
|
|
36
|
+
* It supports RTL (right-to-left) text direction.
|
|
37
|
+
*
|
|
38
|
+
* @param {ChildrenProp} children - The children to be rendered inside the section.
|
|
39
|
+
* @param {CssProp} className - Additional CSS classes to apply to the section.
|
|
40
|
+
* @param {RefProp<HTMLDivElement>} ref - A ref to the section element.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```jsx
|
|
44
|
+
* <Section className="my-section" ref={sectionRef}>
|
|
45
|
+
* <p>This is a section.</p>
|
|
46
|
+
* </Section>
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/core-application--section} for more details.
|
|
30
50
|
*/
|
|
31
51
|
export const Section = ({
|
|
32
52
|
children,
|
|
33
53
|
className,
|
|
34
54
|
dir,
|
|
35
55
|
ref,
|
|
56
|
+
...rest
|
|
36
57
|
}: ChildrenProp &
|
|
37
58
|
CssProp &
|
|
59
|
+
TestProps &
|
|
38
60
|
RefProp<HTMLDivElement> & { dir?: "ltr" | "rtl" }) => {
|
|
39
61
|
return (
|
|
40
62
|
<div
|
|
41
63
|
data-ref="section"
|
|
42
64
|
dir={dir}
|
|
43
65
|
ref={ref}
|
|
66
|
+
{...rest}
|
|
44
67
|
className={classNames(
|
|
45
68
|
"fabric-section",
|
|
46
69
|
className,
|
|
@@ -61,7 +61,27 @@ export interface ThemeProps {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* This component provides a way to set the theme for the application.
|
|
65
|
+
* It allows you to set the primary, accent, and tint colors, as well as the color scheme and rounding.
|
|
66
|
+
* It uses CSS variables to apply the colors and styles.
|
|
67
|
+
* It also applies the branding className to the root element.
|
|
68
|
+
* The component uses the `useApplicationContext` hook to get the current color scheme from the application context.
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```jsx
|
|
72
|
+
* <ThemeProvider
|
|
73
|
+
* branding="my-branding"
|
|
74
|
+
* primaryColor="#ff0000"
|
|
75
|
+
* accentColor="#00ff00"
|
|
76
|
+
* tintColor="#0000ff"
|
|
77
|
+
* colorScheme="dark"
|
|
78
|
+
* rounding="md"
|
|
79
|
+
* >
|
|
80
|
+
* <div>Your content here</div>
|
|
81
|
+
* </ThemeProvider>
|
|
82
|
+
* ```
|
|
83
|
+
*
|
|
84
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/story/core-application--theme-provider} for more details.
|
|
65
85
|
*/
|
|
66
86
|
export const ThemeProvider = ({
|
|
67
87
|
children,
|
|
@@ -25,7 +25,21 @@ import classNames from "classnames";
|
|
|
25
25
|
import { type PropsWithChildren } from "react";
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* This component is used to create a full-screen viewport
|
|
29
|
+
* that can be used to display content in a grid layout.
|
|
30
|
+
* It is typically used as a container for the main content of the application.
|
|
31
|
+
* It is styled to take up the full width and height of the viewport,
|
|
32
|
+
* and it uses absolute positioning to ensure it covers the entire screen.
|
|
33
|
+
* The component accepts children as props, allowing you to nest other components inside it.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```jsx
|
|
37
|
+
* <Viewport>
|
|
38
|
+
* <YourContentComponent />
|
|
39
|
+
* </Viewport>
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/core-application--viewport} for more details.
|
|
29
43
|
*/
|
|
30
44
|
export const Viewport = ({ children }: PropsWithChildren) => {
|
|
31
45
|
return (
|
|
@@ -24,6 +24,18 @@
|
|
|
24
24
|
import { useDeferredValue, useState } from "react";
|
|
25
25
|
import { useEffectDebugger } from "./useEffectDebugger";
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Custom hook to manage a controlled value with a default fallback for inputs.
|
|
29
|
+
* It updates the current value whenever the deferred value changes.
|
|
30
|
+
* This is useful for scenarios where you want to control the value of a component
|
|
31
|
+
* while also providing a default value if the controlled value is not set.
|
|
32
|
+
* This hook is particularly useful for form inputs or components that require a controlled value
|
|
33
|
+
* but also need to handle cases where the value might not be immediately available.
|
|
34
|
+
*
|
|
35
|
+
* @param value - The controlled value that may change.
|
|
36
|
+
* @param defaultValue - The default value to use if the controlled value is not set.
|
|
37
|
+
* @returns An object containing the current value and a function to update it.
|
|
38
|
+
*/
|
|
27
39
|
export const useControlledValue = <T extends AnyObject = string>(
|
|
28
40
|
value: T,
|
|
29
41
|
defaultValue: T,
|
package/src/hooks/useDebounce.ts
CHANGED
|
@@ -23,6 +23,18 @@
|
|
|
23
23
|
|
|
24
24
|
import { useMemo, useRef } from "react";
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Custom hook to debounce a function.
|
|
28
|
+
* This hook delays the processing of the function until after a specified delay period
|
|
29
|
+
* has elapsed since the last time the function was invoked. This is useful for optimizing
|
|
30
|
+
* performance in scenarios where a function may be called frequently, such as during
|
|
31
|
+
* user input or window resizing events.
|
|
32
|
+
*
|
|
33
|
+
* @param callback - The function to debounce.
|
|
34
|
+
* @param deps - The dependency array for the hook.
|
|
35
|
+
* @param delay - The debounce delay in milliseconds.
|
|
36
|
+
* @returns A debounced version of the callback function.
|
|
37
|
+
*/
|
|
26
38
|
export const useDebounce = (
|
|
27
39
|
callback: undefined | ((...rest: AnyObject) => AnyObject),
|
|
28
40
|
deps: AnyObject[],
|
|
@@ -86,6 +86,19 @@ const compareInputs = (
|
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Custom hook to debug useMemo hooks.
|
|
91
|
+
* It compares the current and previous dependency arrays and logs any differences.
|
|
92
|
+
* @param func - The function to be memoized or executed in the effect.
|
|
93
|
+
* @param inputs - The dependency array for the hook.
|
|
94
|
+
* @param prefix - A prefix for the log messages to identify the hook.
|
|
95
|
+
* @returns The result of the memoized function or the effect.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```jsx
|
|
99
|
+
* const value = useMemoDebugger(() => computeValue(), [dependency1, dependency2], "MyComponent");
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
89
102
|
export const useMemoDebugger = <T>(
|
|
90
103
|
func: () => T,
|
|
91
104
|
inputs: DependencyList,
|
|
@@ -108,6 +121,24 @@ export const useMemoDebugger = <T>(
|
|
|
108
121
|
}, inputs);
|
|
109
122
|
};
|
|
110
123
|
|
|
124
|
+
/**
|
|
125
|
+
* Custom hook to debug useEffect and useLayoutEffect hooks.
|
|
126
|
+
* It compares the current and previous dependency arrays and logs any differences.
|
|
127
|
+
* @param func - The effect function to be executed.
|
|
128
|
+
* @param inputs - The dependency array for the effect.
|
|
129
|
+
* @param prefix - A prefix for the log messages to identify the effect.
|
|
130
|
+
* @returns A cleanup function if the effect returns one.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```jsx
|
|
134
|
+
* useEffectDebugger(() => {
|
|
135
|
+
* // Effect logic here
|
|
136
|
+
* return () => {
|
|
137
|
+
* // Cleanup logic here
|
|
138
|
+
* };
|
|
139
|
+
* }, [dependency1, dependency2], "MyComponent");
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
111
142
|
export const useEffectDebugger = (
|
|
112
143
|
func: EffectCallback,
|
|
113
144
|
inputs: DependencyList,
|
|
@@ -130,6 +161,24 @@ export const useEffectDebugger = (
|
|
|
130
161
|
}, inputs);
|
|
131
162
|
};
|
|
132
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Custom hook to debug useLayoutEffect hooks.
|
|
166
|
+
* It compares the current and previous dependency arrays and logs any differences.
|
|
167
|
+
* @param func - The layout effect function to be executed.
|
|
168
|
+
* @param inputs - The dependency array for the layout effect.
|
|
169
|
+
* @param prefix - A prefix for the log messages to identify the layout effect.
|
|
170
|
+
* @returns A cleanup function if the layout effect returns one.
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```jsx
|
|
174
|
+
* useLayoutEffectDebugger(() => {
|
|
175
|
+
* // Layout effect logic here
|
|
176
|
+
* return () => {
|
|
177
|
+
* // Cleanup logic here
|
|
178
|
+
* };
|
|
179
|
+
* }, [dependency1, dependency2], "MyComponent");
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
133
182
|
export const useLayoutEffectDebugger = (
|
|
134
183
|
func: EffectCallback,
|
|
135
184
|
inputs: DependencyList,
|
package/src/hooks/useIsDark.ts
CHANGED
|
@@ -24,6 +24,14 @@
|
|
|
24
24
|
import { useCallback, useState } from "react";
|
|
25
25
|
import { useLayoutEffectDebugger } from "./useEffectDebugger";
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Custom hook to determine if the current theme is dark.
|
|
29
|
+
* It checks the background color of the document's root element
|
|
30
|
+
* and sets the `isDark` state based on the red component of the RGB color.
|
|
31
|
+
* If the red component is less than 50, it considers the theme to be dark.
|
|
32
|
+
*
|
|
33
|
+
* @returns {boolean} - Returns true if the theme is dark, false otherwise.
|
|
34
|
+
*/
|
|
27
35
|
export const useIsDark = () => {
|
|
28
36
|
const [isDark, setDark] = useState(false);
|
|
29
37
|
const checkTheme = useCallback(() => {
|
package/src/hooks/useIsRtl.ts
CHANGED
|
@@ -25,6 +25,18 @@ import { useState } from "react";
|
|
|
25
25
|
import { useTranslation } from "react-i18next";
|
|
26
26
|
import { useLayoutEffectDebugger } from "./useEffectDebugger";
|
|
27
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Custom hook to determine if the current locale is RTL (Right-to-Left).
|
|
30
|
+
* It uses the i18n instance from react-i18next to check the direction.
|
|
31
|
+
*
|
|
32
|
+
* @returns {boolean} - Returns true if the current locale is RTL, false otherwise.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```jsx
|
|
36
|
+
* const isRtl = useIsRtl();
|
|
37
|
+
* // This will return true if the current locale is RTL, false otherwise.
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
28
40
|
export const useIsRtl = () => {
|
|
29
41
|
const { i18n } = useTranslation("core");
|
|
30
42
|
const [isRtl, setIsRtl] = useState(false);
|
|
@@ -23,6 +23,24 @@
|
|
|
23
23
|
|
|
24
24
|
import { useCallback, useMemo, useRef, useState } from "react";
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* Custom hook to manage navigation through a list of items.
|
|
28
|
+
* It provides functionality to navigate forward and backward,
|
|
29
|
+
* and keeps track of the current index and total count of items.
|
|
30
|
+
*
|
|
31
|
+
* @param totalCount - Total number of items to navigate through.
|
|
32
|
+
* @param defaultIndex - Initial index to start navigation from.
|
|
33
|
+
* @returns An object containing the current index, a function to navigate,
|
|
34
|
+
* a label for the current position, and a function to set the current index.
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* ```jsx
|
|
38
|
+
* const { headLabel, onNavigate, currentIndex, setCurrentIndex } = useNavigator(5, 0);
|
|
39
|
+
* // headLabel will show "1/5"
|
|
40
|
+
* // onNavigate(1) will move to the next item, and onNavigate(-1) will move to the previous item.
|
|
41
|
+
* // currentIndex will be updated accordingly.
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
26
44
|
export const useNavigator = (totalCount = 0, defaultIndex = 0) => {
|
|
27
45
|
const [currentIndex, setCurrentIndex] = useState(defaultIndex);
|
|
28
46
|
const refCurrent = useRef(defaultIndex);
|
|
@@ -31,6 +31,30 @@ import { type ModalProps } from "../types";
|
|
|
31
31
|
|
|
32
32
|
type OverlayComponent = ElementType<ModalProps<AnyObject>>;
|
|
33
33
|
|
|
34
|
+
/**
|
|
35
|
+
* Hook to manage overlay components like modals or flyouts.
|
|
36
|
+
* It provides a way to open an overlay with specified properties and handle its closure.
|
|
37
|
+
* This hook returns the current overlay component and a function to open it with props.
|
|
38
|
+
* It is useful for scenarios where you need to display overlays dynamically,
|
|
39
|
+
* such as modals, flyouts, or any other overlay components in a React application.
|
|
40
|
+
* The `openOverlay` function returns a promise that resolves with the result
|
|
41
|
+
* of the overlay when it is closed, allowing you to handle the result in a controlled manner.
|
|
42
|
+
*
|
|
43
|
+
* @param ModalOrFlyout - The component to be used as an overlay.
|
|
44
|
+
* @returns An array containing the current overlay and a function to open it.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```jsx
|
|
48
|
+
* const [Overlay, openOverlay] = useOverlayService(MyModalComponent);
|
|
49
|
+
* // To open the overlay:
|
|
50
|
+
* const handleOpen = async () => {
|
|
51
|
+
* const result = await openOverlay({ title: "My Modal", content: "Hello World" });
|
|
52
|
+
* console.log(result); // Handle the result from the overlay
|
|
53
|
+
* };
|
|
54
|
+
* <button onClick={handleOpen}>Open Modal</button>
|
|
55
|
+
* <Overlay />
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
34
58
|
export const useOverlayService = (
|
|
35
59
|
ModalOrFlyout: OverlayComponent,
|
|
36
60
|
): [
|