react-side-sheet-pro 0.1.2 → 0.1.4
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 +44 -0
- package/dist/components/SideSheetContainer.js +75 -0
- package/dist/components/SideSheetContent.js +16 -0
- package/dist/components/SideSheetFooter.js +16 -0
- package/dist/components/SideSheetHeader.js +25 -0
- package/dist/components/SideSheetProvider.js +179 -0
- package/dist/constants/defaultOptions.js +45 -0
- package/dist/contexts/SideSheetReducer.js +48 -0
- package/dist/hooks/useSideSheet.js +17 -0
- package/dist/index.js +39 -13833
- package/dist/types/index.js +4 -0
- package/package.json +82 -86
- package/src/components/SideSheetHeader.tsx +5 -2
- package/src/components/SideSheetProvider.tsx +118 -105
- package/src/constants/defaultOptions.ts +25 -22
- package/src/types/index.ts +5 -2
- package/dist/index.css +0 -191
- package/dist/index.d.ts +0 -60
- package/dist/index.esm.d.ts +0 -60
- package/dist/index.esm.js +0 -13825
- package/dist/index.umd.d.ts +0 -60
- package/dist/index.umd.js +0 -13836
- package/dist/index.umd.min.d.ts +0 -60
- package/dist/index.umd.min.js +0 -7
package/package.json
CHANGED
|
@@ -1,86 +1,82 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "react-side-sheet-pro",
|
|
3
|
-
"description": "A flexible React SideSheet component for displaying contextual information.",
|
|
4
|
-
"version": "0.1.
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"keywords": [
|
|
7
|
-
"react",
|
|
8
|
-
"react-component",
|
|
9
|
-
"modal",
|
|
10
|
-
"side-sheet",
|
|
11
|
-
"slide-sheet"
|
|
12
|
-
],
|
|
13
|
-
"main": "dist/index.js",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
},
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
},
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
"
|
|
43
|
-
},
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"react-
|
|
47
|
-
},
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
"@babel/
|
|
54
|
-
"@babel/
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"eslint": "
|
|
68
|
-
"eslint-
|
|
69
|
-
"eslint-
|
|
70
|
-
"eslint-plugin-
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"rollup": "^
|
|
77
|
-
"rollup-plugin-
|
|
78
|
-
"rollup-plugin-
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"ts-loader": "^6.2.1",
|
|
84
|
-
"typescript": "^3.9.3"
|
|
85
|
-
}
|
|
86
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "react-side-sheet-pro",
|
|
3
|
+
"description": "A flexible React SideSheet component for displaying contextual information.",
|
|
4
|
+
"version": "0.1.4",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"react",
|
|
8
|
+
"react-component",
|
|
9
|
+
"modal",
|
|
10
|
+
"side-sheet",
|
|
11
|
+
"slide-sheet"
|
|
12
|
+
],
|
|
13
|
+
"main": "dist/index.js",
|
|
14
|
+
"typings": "index.d.ts",
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"LICENSE"
|
|
19
|
+
],
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=10"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"lint": "eslint './src/**/*.{ts,tsx,js,jsx}'",
|
|
25
|
+
"lint-fix": "eslint --fix './src/**/*.{ts,tsx,js,jsx}'",
|
|
26
|
+
"prettier": "prettier ./src/** ./playground/src/** --write",
|
|
27
|
+
"build": "babel --extensions \".ts,.tsx\" src --out-dir dist"
|
|
28
|
+
},
|
|
29
|
+
"husky": {
|
|
30
|
+
"hooks": {
|
|
31
|
+
"pre-push": "npm run lint"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"repository": "git+https://github.com/richardDobron/react-side-sheet-pro.git",
|
|
35
|
+
"author": "Richard Dobroň",
|
|
36
|
+
"bugs": {
|
|
37
|
+
"url": "https://github.com/richardDobron/react-side-sheet-pro/issues"
|
|
38
|
+
},
|
|
39
|
+
"dependencies": {
|
|
40
|
+
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
|
|
41
|
+
"classnames": "^2.3.1",
|
|
42
|
+
"react-icons": "^4"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"react": "^0.14.0 || ^15.0.0 || ^16 || ^17 || ^18 || ^19",
|
|
46
|
+
"react-dom": "^0.14.0 || ^15.0.0 || ^16 || ^17 || ^18 || ^19"
|
|
47
|
+
},
|
|
48
|
+
"devDependencies": {
|
|
49
|
+
"@babel/cli": "^7.14.3",
|
|
50
|
+
"@babel/core": "^7.14.3",
|
|
51
|
+
"@babel/plugin-proposal-class-properties": "^7.14.3",
|
|
52
|
+
"@babel/preset-env": "^7.14.3",
|
|
53
|
+
"@babel/preset-react": "^7.14.3",
|
|
54
|
+
"@babel/preset-typescript": "^7.16.7",
|
|
55
|
+
"@types/react": "^17.0.9",
|
|
56
|
+
"@types/react-dom": "^17.0.6",
|
|
57
|
+
"@typescript-eslint/eslint-plugin": "^2.24.0",
|
|
58
|
+
"@typescript-eslint/parser": "^2.24.0",
|
|
59
|
+
"@wessberg/rollup-plugin-ts": "^1.2.21",
|
|
60
|
+
"babel-loader": "^8.0.6",
|
|
61
|
+
"babel-plugin-transform-class-properties": "^6.24.1",
|
|
62
|
+
"babel-plugin-typescript-to-proptypes": "^1.3.2",
|
|
63
|
+
"eslint": "6.6.0",
|
|
64
|
+
"eslint-config-airbnb": "18.0.1",
|
|
65
|
+
"eslint-config-prettier": "^6.10.0",
|
|
66
|
+
"eslint-plugin-import": "^2.18.2",
|
|
67
|
+
"eslint-plugin-jest": "^22.6.3",
|
|
68
|
+
"eslint-plugin-jsx-a11y": "^6.2.3",
|
|
69
|
+
"eslint-plugin-prettier": "^3.1.2",
|
|
70
|
+
"eslint-plugin-react": "^7.14.3",
|
|
71
|
+
"prettier": "^1.19.1",
|
|
72
|
+
"rollup": "^1.27.0",
|
|
73
|
+
"rollup-plugin-babel": "^4.3.3",
|
|
74
|
+
"rollup-plugin-commonjs": "^10.1.0",
|
|
75
|
+
"rollup-plugin-copy": "^3.4.0",
|
|
76
|
+
"rollup-plugin-node-resolve": "^5.2.0",
|
|
77
|
+
"rollup-plugin-replace": "^2.2.0",
|
|
78
|
+
"rollup-plugin-terser": "^5.1.2",
|
|
79
|
+
"ts-loader": "^6.2.1",
|
|
80
|
+
"typescript": "^3.9.3"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -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
|
>
|
|
@@ -1,105 +1,118 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
createContext,
|
|
3
|
-
ReactNode,
|
|
4
|
-
useCallback,
|
|
5
|
-
useEffect,
|
|
6
|
-
useReducer,
|
|
7
|
-
useRef,
|
|
8
|
-
} from 'react';
|
|
9
|
-
import { createPortal } from 'react-dom';
|
|
10
|
-
import {
|
|
11
|
-
DEFAULT_OPTIONS,
|
|
12
|
-
DEFAULT_SHEET_OPTIONS,
|
|
13
|
-
} from '../constants/defaultOptions';
|
|
14
|
-
import {
|
|
15
|
-
SideElement,
|
|
16
|
-
SideOptions,
|
|
17
|
-
SideSheetContextValue,
|
|
18
|
-
SideSheetOptions,
|
|
19
|
-
SideStackItem,
|
|
20
|
-
} from '../types';
|
|
21
|
-
import { SideSheetContainer } from './SideSheetContainer';
|
|
22
|
-
import { SideSheetReducer } from '../contexts/SideSheetReducer';
|
|
23
|
-
|
|
24
|
-
export const SideSheetContext = createContext<SideSheetContextValue | null>(
|
|
25
|
-
null
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
export const SideSheetProvider: React.FC<{
|
|
29
|
-
children: ReactNode;
|
|
30
|
-
configuration?: Partial<SideSheetOptions>;
|
|
31
|
-
}> = ({ children, configuration }) => {
|
|
32
|
-
const [stack, dispatch] = useReducer(SideSheetReducer, []);
|
|
33
|
-
const
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
ReactNode,
|
|
4
|
+
useCallback,
|
|
5
|
+
useEffect,
|
|
6
|
+
useReducer,
|
|
7
|
+
useRef,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { createPortal } from 'react-dom';
|
|
10
|
+
import {
|
|
11
|
+
DEFAULT_OPTIONS,
|
|
12
|
+
DEFAULT_SHEET_OPTIONS,
|
|
13
|
+
} from '../constants/defaultOptions';
|
|
14
|
+
import {
|
|
15
|
+
SideElement,
|
|
16
|
+
SideOptions,
|
|
17
|
+
SideSheetContextValue,
|
|
18
|
+
SideSheetOptions,
|
|
19
|
+
SideStackItem,
|
|
20
|
+
} from '../types';
|
|
21
|
+
import { SideSheetContainer } from './SideSheetContainer';
|
|
22
|
+
import { SideSheetReducer } from '../contexts/SideSheetReducer';
|
|
23
|
+
|
|
24
|
+
export const SideSheetContext = createContext<SideSheetContextValue | null>(
|
|
25
|
+
null
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
export const SideSheetProvider: React.FC<{
|
|
29
|
+
children: ReactNode;
|
|
30
|
+
configuration?: Partial<SideSheetOptions>;
|
|
31
|
+
}> = ({ children, configuration }) => {
|
|
32
|
+
const [stack, dispatch] = useReducer(SideSheetReducer, []);
|
|
33
|
+
const stackRef = useRef<SideStackItem[]>(stack);
|
|
34
|
+
const overflowRef = useRef('');
|
|
35
|
+
const idRef = useRef(0);
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
stackRef.current = stack;
|
|
39
|
+
}, [stack]);
|
|
40
|
+
|
|
41
|
+
const open = useCallback((element: SideElement, opts: SideOptions = {}) => {
|
|
42
|
+
const id = ++idRef.current;
|
|
43
|
+
const options = { ...DEFAULT_SHEET_OPTIONS, ...opts };
|
|
44
|
+
if (!config.enableOverflow && stackRef.current.length === 0) {
|
|
45
|
+
overflowRef.current = document.body.style.overflow;
|
|
46
|
+
document.body.style.overflow = 'hidden';
|
|
47
|
+
}
|
|
48
|
+
dispatch({
|
|
49
|
+
type: 'OPEN',
|
|
50
|
+
payload: { id, element, options, state: 'opening' },
|
|
51
|
+
});
|
|
52
|
+
setTimeout(() => {
|
|
53
|
+
dispatch({ type: 'SET_OPEN', id });
|
|
54
|
+
options.onOpen?.(id);
|
|
55
|
+
}, options.animationDuration);
|
|
56
|
+
return id;
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
const close = useCallback(async (id: number | null) => {
|
|
60
|
+
const itemsToClose =
|
|
61
|
+
id === null
|
|
62
|
+
? [...stackRef.current]
|
|
63
|
+
: stackRef.current.filter(i => i.id === id);
|
|
64
|
+
|
|
65
|
+
for (const item of itemsToClose) {
|
|
66
|
+
if (item.options.confirmBeforeClose) {
|
|
67
|
+
const confirmCallback =
|
|
68
|
+
item.options.confirmCallback ?? config.confirmCallback;
|
|
69
|
+
const confirmed = await confirmCallback(
|
|
70
|
+
item.options.confirmMessage ?? config.confirmMessage
|
|
71
|
+
);
|
|
72
|
+
if (!confirmed) return;
|
|
73
|
+
}
|
|
74
|
+
item.options.onClose?.(item.id);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (
|
|
78
|
+
!config.enableOverflow &&
|
|
79
|
+
stackRef.current.length <= itemsToClose.length
|
|
80
|
+
) {
|
|
81
|
+
document.body.style.overflow = overflowRef.current;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const duration =
|
|
85
|
+
itemsToClose[itemsToClose.length - 1]?.options.animationDuration;
|
|
86
|
+
dispatch({ type: 'CLOSE', id });
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
if (id === null) {
|
|
89
|
+
itemsToClose.forEach(item => dispatch({ type: 'REMOVE', id: item.id }));
|
|
90
|
+
} else {
|
|
91
|
+
dispatch({ type: 'REMOVE', id: id! });
|
|
92
|
+
}
|
|
93
|
+
}, duration);
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
96
|
+
const update = useCallback((id: number, options: Partial<SideOptions>) => {
|
|
97
|
+
dispatch({ type: 'UPDATE', id, options });
|
|
98
|
+
}, []);
|
|
99
|
+
const config = { ...DEFAULT_OPTIONS, ...configuration } as Required<
|
|
100
|
+
SideSheetOptions
|
|
101
|
+
>;
|
|
102
|
+
|
|
103
|
+
return (
|
|
104
|
+
<SideSheetContext.Provider value={{ open, close, update, config }}>
|
|
105
|
+
{children}
|
|
106
|
+
{createPortal(
|
|
107
|
+
<SideSheetContainer
|
|
108
|
+
stack={stack}
|
|
109
|
+
close={close}
|
|
110
|
+
open={open}
|
|
111
|
+
update={update}
|
|
112
|
+
config={config}
|
|
113
|
+
/>,
|
|
114
|
+
document.body
|
|
115
|
+
)}
|
|
116
|
+
</SideSheetContext.Provider>
|
|
117
|
+
);
|
|
118
|
+
};
|
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import { SideOptions, SideSheetOptions } from '../types';
|
|
2
|
-
|
|
3
|
-
export const DEFAULT_OPTIONS: Required<SideSheetOptions> = {
|
|
4
|
-
side: 'right',
|
|
5
|
-
|
|
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
|
+
enableOverflow: false,
|
|
6
|
+
mountStrategy: 'all',
|
|
7
|
+
confirmMessage: 'Are you sure you want to close?',
|
|
8
|
+
confirmCallback: async (msg: string) =>
|
|
9
|
+
typeof window !== 'undefined'
|
|
10
|
+
? Promise.resolve(window.confirm(msg))
|
|
11
|
+
: Promise.resolve(true),
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const DEFAULT_SHEET_OPTIONS: Required<SideOptions> = {
|
|
15
|
+
width: 400,
|
|
16
|
+
className: '',
|
|
17
|
+
confirmBeforeClose: false,
|
|
18
|
+
confirmMessage: null,
|
|
19
|
+
confirmCallback: null,
|
|
20
|
+
closeOnOverlayClick: true,
|
|
21
|
+
closeOnEsc: true,
|
|
22
|
+
animationDuration: 240,
|
|
23
|
+
onOpen: () => {},
|
|
24
|
+
onClose: () => {},
|
|
25
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -4,15 +4,18 @@ export type Sides = 'left' | 'right';
|
|
|
4
4
|
|
|
5
5
|
export interface SideSheetOptions {
|
|
6
6
|
side: Sides;
|
|
7
|
+
enableOverflow: boolean;
|
|
7
8
|
mountStrategy: 'all' | 'top-only';
|
|
9
|
+
confirmMessage: string;
|
|
10
|
+
confirmCallback: (message: string) => Promise<boolean>;
|
|
8
11
|
}
|
|
9
12
|
|
|
10
13
|
export interface SideOptions {
|
|
11
14
|
width?: number;
|
|
12
15
|
className?: string;
|
|
13
16
|
confirmBeforeClose?: boolean;
|
|
14
|
-
confirmMessage?: string;
|
|
15
|
-
confirmCallback?: (message: string) => Promise<boolean
|
|
17
|
+
confirmMessage?: string | null;
|
|
18
|
+
confirmCallback?: ((message: string) => Promise<boolean>) | null;
|
|
16
19
|
closeOnOverlayClick?: boolean;
|
|
17
20
|
closeOnEsc?: boolean;
|
|
18
21
|
animationDuration?: number;
|