react-side-sheet-pro 0.1.2 → 0.1.3
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
CHANGED
|
@@ -94,6 +94,8 @@ export const App = () => {
|
|
|
94
94
|
)
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
+
// Wrap your app with the SideSheet.Provider to manage side sheets globally
|
|
98
|
+
|
|
97
99
|
export default () => (
|
|
98
100
|
<SideSheet.Provider>
|
|
99
101
|
<App />
|
|
@@ -101,6 +103,48 @@ export default () => (
|
|
|
101
103
|
)
|
|
102
104
|
```
|
|
103
105
|
|
|
106
|
+
## 🧩 Compound Components
|
|
107
|
+
|
|
108
|
+
### `Sheet.Provider`
|
|
109
|
+
|
|
110
|
+
Sheet provider component that manages the state of all side sheets in your application. It should wrap your main application component.
|
|
111
|
+
|
|
112
|
+
### `Sheet.Header`
|
|
113
|
+
|
|
114
|
+
Sheet header component that displays the title and can include custom actions. It also provides custom `onClick` function for a button to close the sheet.
|
|
115
|
+
|
|
116
|
+
#### Header props
|
|
117
|
+
|
|
118
|
+
| Name | Required | Default | Description |
|
|
119
|
+
|-------------|----------|-----------|------------------------------------------|
|
|
120
|
+
| `title` | yes | | Title of the header. |
|
|
121
|
+
| `onClose` | no | undefined | Callback function to close the sheet. |
|
|
122
|
+
| `actions` | no | undefined | Custom actions to render in the header. |
|
|
123
|
+
| `className` | no | undefined | Custom CSS class for additional styling. |
|
|
124
|
+
|
|
125
|
+
### `Sheet.Content`
|
|
126
|
+
|
|
127
|
+
Sheet content component that wraps the main content of the side sheet. Can be styled using custom classes.
|
|
128
|
+
|
|
129
|
+
#### Content props
|
|
130
|
+
|
|
131
|
+
| Name | Required | Default | Description |
|
|
132
|
+
|-------------|----------|-----------|-------------------------------------------|
|
|
133
|
+
| `children` | yes | | Content to display inside the side sheet. |
|
|
134
|
+
| `className` | no | undefined | Custom CSS class for additional styling. |
|
|
135
|
+
|
|
136
|
+
### `Sheet.Footer`
|
|
137
|
+
|
|
138
|
+
Sheet footer component that can be used to display actions or additional information at the bottom of the side sheet. Can be styled using custom classes.
|
|
139
|
+
|
|
140
|
+
#### Footer props
|
|
141
|
+
|
|
142
|
+
| Name | Required | Default | Description |
|
|
143
|
+
|-------------|----------|-----------|------------------------------------------|
|
|
144
|
+
| `children` | yes | | Content to display inside the footer. |
|
|
145
|
+
| `className` | no | undefined | Custom CSS class for additional styling. |
|
|
146
|
+
|
|
147
|
+
|
|
104
148
|
## 🧪 Testing
|
|
105
149
|
|
|
106
150
|
```bash
|
package/package.json
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import React, { ReactNode } from 'react';
|
|
2
2
|
import { HiX } from 'react-icons/hi';
|
|
3
|
+
import classNames from 'classnames';
|
|
3
4
|
|
|
4
5
|
export const SideSheetHeader: React.FC<{
|
|
5
6
|
title: string;
|
|
6
7
|
onClose?: () => void;
|
|
7
8
|
actions?: ReactNode;
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
className?: string;
|
|
10
|
+
}> = React.memo(({ title, onClose, actions, className }) => (
|
|
11
|
+
<header className={classNames('sidesheet-header', className)}>
|
|
10
12
|
{onClose && (
|
|
11
13
|
<button
|
|
14
|
+
type="button"
|
|
12
15
|
className="sidesheet-header-close sidesheet-header-btn"
|
|
13
16
|
onClick={onClose}
|
|
14
17
|
>
|
|
@@ -59,8 +59,10 @@ export const SideSheetProvider: React.FC<{
|
|
|
59
59
|
|
|
60
60
|
for (const item of itemsToClose) {
|
|
61
61
|
if (item.options.confirmBeforeClose) {
|
|
62
|
-
const
|
|
63
|
-
item.options.
|
|
62
|
+
const confirmCallback =
|
|
63
|
+
item.options.confirmCallback ?? config.confirmCallback;
|
|
64
|
+
const confirmed = await confirmCallback(
|
|
65
|
+
item.options.confirmMessage ?? config.confirmMessage
|
|
64
66
|
);
|
|
65
67
|
if (!confirmed) return;
|
|
66
68
|
}
|
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import { SideOptions, SideSheetOptions } from '../types';
|
|
2
|
-
|
|
3
|
-
export const DEFAULT_OPTIONS: Required<SideSheetOptions> = {
|
|
4
|
-
side: 'right',
|
|
5
|
-
mountStrategy: 'all',
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
1
|
+
import { SideOptions, SideSheetOptions } from '../types';
|
|
2
|
+
|
|
3
|
+
export const DEFAULT_OPTIONS: Required<SideSheetOptions> = {
|
|
4
|
+
side: 'right',
|
|
5
|
+
mountStrategy: 'all',
|
|
6
|
+
confirmMessage: 'Are you sure you want to close?',
|
|
7
|
+
confirmCallback: async (msg: string) =>
|
|
8
|
+
typeof window !== 'undefined'
|
|
9
|
+
? Promise.resolve(window.confirm(msg))
|
|
10
|
+
: Promise.resolve(true),
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const DEFAULT_SHEET_OPTIONS: Required<SideOptions> = {
|
|
14
|
+
width: 400,
|
|
15
|
+
className: '',
|
|
16
|
+
confirmBeforeClose: false,
|
|
17
|
+
confirmMessage: null,
|
|
18
|
+
confirmCallback: null,
|
|
19
|
+
closeOnOverlayClick: true,
|
|
20
|
+
closeOnEsc: true,
|
|
21
|
+
animationDuration: 240,
|
|
22
|
+
onOpen: () => {},
|
|
23
|
+
onClose: () => {},
|
|
24
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -5,14 +5,16 @@ export type Sides = 'left' | 'right';
|
|
|
5
5
|
export interface SideSheetOptions {
|
|
6
6
|
side: Sides;
|
|
7
7
|
mountStrategy: 'all' | 'top-only';
|
|
8
|
+
confirmMessage: string;
|
|
9
|
+
confirmCallback: (message: string) => Promise<boolean>;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
export interface SideOptions {
|
|
11
13
|
width?: number;
|
|
12
14
|
className?: string;
|
|
13
15
|
confirmBeforeClose?: boolean;
|
|
14
|
-
confirmMessage?: string;
|
|
15
|
-
confirmCallback?: (message: string) => Promise<boolean
|
|
16
|
+
confirmMessage?: string | null;
|
|
17
|
+
confirmCallback?: ((message: string) => Promise<boolean>) | null;
|
|
16
18
|
closeOnOverlayClick?: boolean;
|
|
17
19
|
closeOnEsc?: boolean;
|
|
18
20
|
animationDuration?: number;
|