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.
@@ -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.2",
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,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
- }> = React.memo(({ title, onClose, actions }) => (
9
- <header className="sidesheet-header">
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 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 confirmed = await item.options.confirmCallback(
63
- item.options.confirmMessage
64
- );
65
- if (!confirmed) return;
66
- }
67
- item.options.onClose?.(item.id);
68
- }
69
- const duration =
70
- itemsToClose[itemsToClose.length - 1]?.options.animationDuration;
71
- dispatch({ type: 'CLOSE', id });
72
- setTimeout(() => {
73
- if (id === null) {
74
- stackRef.current.forEach(item =>
75
- dispatch({ type: 'REMOVE', id: item.id })
76
- );
77
- } else {
78
- dispatch({ type: 'REMOVE', id: id! });
79
- }
80
- }, duration);
81
- }, []);
82
-
83
- const update = useCallback((id: number, options: Partial<SideOptions>) => {
84
- dispatch({ type: 'UPDATE', id, options });
85
- }, []);
86
- const config = { ...DEFAULT_OPTIONS, ...configuration } as Required<
87
- SideSheetOptions
88
- >;
89
-
90
- return (
91
- <SideSheetContext.Provider value={{ open, close, update, config }}>
92
- {children}
93
- {createPortal(
94
- <SideSheetContainer
95
- stack={stack}
96
- close={close}
97
- open={open}
98
- update={update}
99
- config={config}
100
- />,
101
- document.body
102
- )}
103
- </SideSheetContext.Provider>
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
- mountStrategy: 'all',
6
- };
7
-
8
- export const DEFAULT_SHEET_OPTIONS: Required<SideOptions> = {
9
- width: 400,
10
- className: '',
11
- confirmBeforeClose: false,
12
- confirmMessage: 'Are you sure you want to close?',
13
- confirmCallback: async (msg: string) =>
14
- typeof window !== 'undefined'
15
- ? Promise.resolve(window.confirm(msg))
16
- : Promise.resolve(true),
17
- closeOnOverlayClick: true,
18
- closeOnEsc: true,
19
- animationDuration: 240,
20
- onOpen: () => {},
21
- onClose: () => {},
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
+ };
@@ -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;