react-side-sheet-pro 0.1.3 → 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.
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+
3
+ var _react = _interopRequireDefault(require("react"));
4
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
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.3",
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
- "module": "dist/index.esm.js",
15
- "jsnext:main": "dist/index.esm.js",
16
- "browser:min": "dist/index.umd.min.js",
17
- "browser": "dist/index.umd.js",
18
- "typings": "dist/index.d.ts",
19
- "files": [
20
- "dist",
21
- "src",
22
- "LICENSE"
23
- ],
24
- "engines": {
25
- "node": ">=10"
26
- },
27
- "scripts": {
28
- "lint": "eslint './src/**/*.{ts,tsx,js,jsx}'",
29
- "lint-fix": "eslint --fix './src/**/*.{ts,tsx,js,jsx}'",
30
- "prettier": "prettier ./src/** ./playground/src/** --write",
31
- "build": "rollup -c",
32
- "dev": "rollup -c -w"
33
- },
34
- "husky": {
35
- "hooks": {
36
- "pre-push": "npm run lint"
37
- }
38
- },
39
- "repository": "git+https://github.com/richardDobron/react-side-sheet-pro.git",
40
- "author": "Richard Dobroň",
41
- "bugs": {
42
- "url": "https://github.com/richardDobron/react-side-sheet-pro/issues"
43
- },
44
- "dependencies": {
45
- "classnames": "^2.3.1",
46
- "react-icons": "^4"
47
- },
48
- "peerDependencies": {
49
- "react": "^0.14.0 || ^15.0.0 || ^16 || ^17 || ^18 || ^19",
50
- "react-dom": "^0.14.0 || ^15.0.0 || ^16 || ^17 || ^18 || ^19"
51
- },
52
- "devDependencies": {
53
- "@babel/cli": "^7.14.3",
54
- "@babel/core": "^7.14.3",
55
- "@babel/plugin-proposal-class-properties": "^7.14.3",
56
- "@babel/preset-env": "^7.14.3",
57
- "@babel/preset-react": "^7.14.3",
58
- "@babel/preset-typescript": "^7.16.7",
59
- "@types/react": "^17.0.9",
60
- "@types/react-dom": "^17.0.6",
61
- "@typescript-eslint/eslint-plugin": "^2.24.0",
62
- "@typescript-eslint/parser": "^2.24.0",
63
- "@wessberg/rollup-plugin-ts": "^1.2.21",
64
- "babel-loader": "^8.0.6",
65
- "babel-plugin-transform-class-properties": "^6.24.1",
66
- "babel-plugin-typescript-to-proptypes": "^1.3.2",
67
- "eslint": "6.6.0",
68
- "eslint-config-airbnb": "18.0.1",
69
- "eslint-config-prettier": "^6.10.0",
70
- "eslint-plugin-import": "^2.18.2",
71
- "eslint-plugin-jest": "^22.6.3",
72
- "eslint-plugin-jsx-a11y": "^6.2.3",
73
- "eslint-plugin-prettier": "^3.1.2",
74
- "eslint-plugin-react": "^7.14.3",
75
- "prettier": "^1.19.1",
76
- "rollup": "^1.27.0",
77
- "rollup-plugin-babel": "^4.3.3",
78
- "rollup-plugin-commonjs": "^10.1.0",
79
- "rollup-plugin-copy": "^3.4.0",
80
- "rollup-plugin-node-resolve": "^5.2.0",
81
- "rollup-plugin-replace": "^2.2.0",
82
- "rollup-plugin-terser": "^5.1.2",
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,107 +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 idRef = useRef(0);
34
- const stackRef = useRef<SideStackItem[]>(stack);
35
-
36
- useEffect(() => {
37
- stackRef.current = stack;
38
- }, [stack]);
39
-
40
- const open = useCallback((element: SideElement, opts: SideOptions = {}) => {
41
- const id = ++idRef.current;
42
- const options = { ...DEFAULT_SHEET_OPTIONS, ...opts };
43
- dispatch({
44
- type: 'OPEN',
45
- payload: { id, element, options, state: 'opening' },
46
- });
47
- setTimeout(() => {
48
- dispatch({ type: 'SET_OPEN', id });
49
- options.onOpen?.(id);
50
- }, options.animationDuration);
51
- return id;
52
- }, []);
53
-
54
- const close = useCallback(async (id: number | null) => {
55
- const itemsToClose =
56
- id === null
57
- ? [...stackRef.current]
58
- : stackRef.current.filter(i => i.id === id);
59
-
60
- for (const item of itemsToClose) {
61
- if (item.options.confirmBeforeClose) {
62
- const confirmCallback =
63
- item.options.confirmCallback ?? config.confirmCallback;
64
- const confirmed = await confirmCallback(
65
- item.options.confirmMessage ?? config.confirmMessage
66
- );
67
- if (!confirmed) return;
68
- }
69
- item.options.onClose?.(item.id);
70
- }
71
- const duration =
72
- itemsToClose[itemsToClose.length - 1]?.options.animationDuration;
73
- dispatch({ type: 'CLOSE', id });
74
- setTimeout(() => {
75
- if (id === null) {
76
- stackRef.current.forEach(item =>
77
- dispatch({ type: 'REMOVE', id: item.id })
78
- );
79
- } else {
80
- dispatch({ type: 'REMOVE', id: id! });
81
- }
82
- }, duration);
83
- }, []);
84
-
85
- const update = useCallback((id: number, options: Partial<SideOptions>) => {
86
- dispatch({ type: 'UPDATE', id, options });
87
- }, []);
88
- const config = { ...DEFAULT_OPTIONS, ...configuration } as Required<
89
- SideSheetOptions
90
- >;
91
-
92
- return (
93
- <SideSheetContext.Provider value={{ open, close, update, config }}>
94
- {children}
95
- {createPortal(
96
- <SideSheetContainer
97
- stack={stack}
98
- close={close}
99
- open={open}
100
- update={update}
101
- config={config}
102
- />,
103
- document.body
104
- )}
105
- </SideSheetContext.Provider>
106
- );
107
- };
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
+ };
@@ -2,12 +2,13 @@ import { SideOptions, SideSheetOptions } from '../types';
2
2
 
3
3
  export const DEFAULT_OPTIONS: Required<SideSheetOptions> = {
4
4
  side: 'right',
5
+ enableOverflow: false,
5
6
  mountStrategy: 'all',
6
7
  confirmMessage: 'Are you sure you want to close?',
7
8
  confirmCallback: async (msg: string) =>
8
- typeof window !== 'undefined'
9
- ? Promise.resolve(window.confirm(msg))
10
- : Promise.resolve(true),
9
+ typeof window !== 'undefined'
10
+ ? Promise.resolve(window.confirm(msg))
11
+ : Promise.resolve(true),
11
12
  };
12
13
 
13
14
  export const DEFAULT_SHEET_OPTIONS: Required<SideOptions> = {
@@ -4,6 +4,7 @@ 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';
8
9
  confirmMessage: string;
9
10
  confirmCallback: (message: string) => Promise<boolean>;
package/dist/index.css DELETED
@@ -1,191 +0,0 @@
1
- .sidesheet-overlay {
2
- opacity: 0.3;
3
- transition: all 0.4s;
4
- background: #000;
5
- bottom: 0;
6
- left: 0;
7
- position: fixed;
8
- right: 0;
9
- top: 0;
10
- visibility: visible;
11
- z-index: 10000;
12
- }
13
-
14
- .sidesheet-right {
15
- right: 0;
16
- transform: translateX(100%);
17
- }
18
-
19
- .sidesheet-left {
20
- left: 0;
21
- transform: translateX(-100%);
22
- }
23
-
24
- .sidesheet-right.sidesheet-animation-open {
25
- animation: sidesheet-open-right 240ms cubic-bezier(0, 0, 0.3, 1);
26
- }
27
-
28
- .sidesheet-left.sidesheet-animation-open {
29
- animation: sidesheet-open-left 240ms cubic-bezier(0, 0, 0.3, 1);
30
- }
31
-
32
- .sidesheet.sidesheet-animation-open {
33
- transform: translateX(0);
34
- }
35
-
36
- .sidesheet-right.sidesheet-animation-closing {
37
- animation: sidesheet-close-right 240ms cubic-bezier(0, 0, 0.3, 1);
38
- }
39
-
40
- .sidesheet-left.sidesheet-animation-closing {
41
- animation: sidesheet-close-left 240ms cubic-bezier(0, 0, 0.3, 1);
42
- }
43
-
44
- @keyframes sidesheet-open-right {
45
- from {
46
- transform: translateX(100%);
47
- }
48
- to {
49
- transform: translateX(0);
50
- }
51
- }
52
-
53
- @keyframes sidesheet-close-right {
54
- from {
55
- transform: translateX(0);
56
- }
57
- to {
58
- transform: translateX(100%);
59
- }
60
- }
61
-
62
- @keyframes sidesheet-open-left {
63
- from {
64
- transform: translateX(-100%);
65
- }
66
- to {
67
- transform: translateX(0);
68
- }
69
- }
70
-
71
- @keyframes sidesheet-close-left {
72
- from {
73
- transform: translateX(0);
74
- }
75
- to {
76
- transform: translateX(-100%);
77
- }
78
- }
79
-
80
- .sidesheet {
81
- flex-direction: column;
82
- display: flex;
83
- flex-wrap: nowrap;
84
- background: #f1f3f4;
85
- bottom: 0;
86
- right: 0;
87
- max-width: 100%;
88
- overflow-x: hidden;
89
- overflow-y: auto;
90
- position: fixed;
91
- z-index: 10000;
92
- top: 0;
93
- width: 100%;
94
- box-shadow: 0 0 10px -5px rgba(0, 0, 0, 0.2), 0 0 24px 2px rgba(0, 0, 0, 0.14),
95
- 0 0 30px 5px rgba(0, 0, 0, 0.12);
96
- transition: transform 0.3s ease, width 0.3s ease;
97
- }
98
-
99
- .sheet-white {
100
- background: #fff;
101
- }
102
-
103
- .sidesheet-header .sidesheet-header-btn {
104
- background: transparent;
105
- border: none;
106
- cursor: pointer;
107
- padding: 7px;
108
- }
109
-
110
- .sidesheet-header {
111
- padding: 12px;
112
- gap: 16px;
113
- border-bottom: 1px solid #dadce0;
114
- background: #fff;
115
- display: flex;
116
- justify-content: space-between;
117
- align-items: center;
118
- }
119
-
120
- .sidesheet-header svg {
121
- width: 24px;
122
- height: 24px;
123
- display: block;
124
- }
125
-
126
- .sidesheet-header .sidesheet-header-btn {
127
- border-radius: 50%;
128
- height: 40px;
129
- line-height: 40px;
130
- align-items: center;
131
- width: 40px;
132
- justify-content: center;
133
- display: flex;
134
- opacity: 0.8;
135
- }
136
-
137
- .sidesheet-header .sidesheet-header-btn:hover {
138
- opacity: 1;
139
- }
140
-
141
- .sidesheet-header .sidesheet-header-btn:focus {
142
- background-color: rgba(64, 64, 64, 0.12);
143
- }
144
-
145
- .sidesheet-header-close:hover {
146
- cursor: pointer;
147
- }
148
-
149
- .sidesheet-header-title {
150
- font-size: 20px;
151
- font-weight: 400;
152
- align-items: center;
153
- display: flex;
154
- flex: 1 1 auto;
155
- overflow: hidden;
156
- text-overflow: ellipsis;
157
- white-space: nowrap;
158
- padding: 6px 0;
159
- }
160
-
161
- .sidesheet-content.sidesheet-centered {
162
- margin: 0 auto;
163
- max-width: 768px;
164
- width: 100%;
165
- }
166
-
167
- .sidesheet-content {
168
- flex: 1 1 auto;
169
- overflow-y: auto;
170
- position: relative;
171
- }
172
-
173
- .sidesheet-content.sidesheet-padding {
174
- padding: 24px;
175
- }
176
-
177
- .sidesheet-card {
178
- background: #fff;
179
- border-radius: 8px;
180
- padding: 24px;
181
- box-shadow: 0 0 0 1px #dadce0;
182
- }
183
-
184
- .sidesheet-footer {
185
- padding: 16px;
186
- border-top: 1px solid #dadce0;
187
- background: #fff;
188
- display: flex;
189
- justify-content: space-between;
190
- align-items: center;
191
- }