react-side-sheet-pro 0.1.3 → 0.1.5

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 }; }
@@ -3,14 +3,17 @@ import { ReactNode } from "react";
3
3
  type Sides = "left" | "right";
4
4
  interface SideSheetOptions {
5
5
  side: Sides;
6
+ enableOverflow: boolean;
6
7
  mountStrategy: "all" | "top-only";
8
+ confirmMessage: string;
9
+ confirmCallback: (message: string) => Promise<boolean>;
7
10
  }
8
11
  interface SideOptions {
9
12
  width?: number;
10
13
  className?: string;
11
14
  confirmBeforeClose?: boolean;
12
- confirmMessage?: string;
13
- confirmCallback?: (message: string) => Promise<boolean>;
15
+ confirmMessage?: string | null;
16
+ confirmCallback?: ((message: string) => Promise<boolean>) | null;
14
17
  closeOnOverlayClick?: boolean;
15
18
  closeOnEsc?: boolean;
16
19
  animationDuration?: number;
@@ -47,6 +50,7 @@ declare const SideSheet: {
47
50
  title: string;
48
51
  onClose?: (() => void) | undefined;
49
52
  actions?: import("react").ReactNode;
53
+ className?: string | undefined;
50
54
  }>;
51
55
  Content: import("react").FC<{
52
56
  children: import("react").ReactNode;
package/package.json CHANGED
@@ -1,86 +1,77 @@
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.5",
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
+ "index.d.ts",
19
+ "LICENSE"
20
+ ],
21
+ "engines": {
22
+ "node": ">=10"
23
+ },
24
+ "scripts": {
25
+ "lint": "eslint './src/**/*.{ts,tsx,js,jsx}'",
26
+ "lint-fix": "eslint --fix './src/**/*.{ts,tsx,js,jsx}'",
27
+ "prettier": "prettier ./src/** ./playground/src/** --write",
28
+ "build:js": "babel --extensions \".ts,.tsx\" src --out-dir dist",
29
+ "build:css": "cpx \"src/**/*.css\" dist",
30
+ "build": "npm run build:js && npm run build:css"
31
+ },
32
+ "husky": {
33
+ "hooks": {
34
+ "pre-push": "npm run lint"
35
+ }
36
+ },
37
+ "repository": "git+https://github.com/richardDobron/react-side-sheet-pro.git",
38
+ "author": "Richard Dobroň",
39
+ "bugs": {
40
+ "url": "https://github.com/richardDobron/react-side-sheet-pro/issues"
41
+ },
42
+ "dependencies": {
43
+ "classnames": "^2.3.1",
44
+ "react-icons": "^4"
45
+ },
46
+ "peerDependencies": {
47
+ "react": "^0.14.0 || ^15.0.0 || ^16 || ^17 || ^18 || ^19",
48
+ "react-dom": "^0.14.0 || ^15.0.0 || ^16 || ^17 || ^18 || ^19"
49
+ },
50
+ "devDependencies": {
51
+ "@babel/cli": "^7.14.3",
52
+ "@babel/core": "^7.14.3",
53
+ "@babel/plugin-proposal-class-properties": "^7.14.3",
54
+ "@babel/preset-env": "^7.14.3",
55
+ "@babel/preset-react": "^7.14.3",
56
+ "@babel/preset-typescript": "^7.16.7",
57
+ "@types/react": "^17.0.9",
58
+ "@types/react-dom": "^17.0.6",
59
+ "@typescript-eslint/eslint-plugin": "^2.24.0",
60
+ "@typescript-eslint/parser": "^2.24.0",
61
+ "babel-loader": "^8.0.6",
62
+ "babel-plugin-transform-class-properties": "^6.24.1",
63
+ "babel-plugin-typescript-to-proptypes": "^1.3.2",
64
+ "cpx": "^1.5.0",
65
+ "eslint": "6.6.0",
66
+ "eslint-config-airbnb": "18.0.1",
67
+ "eslint-config-prettier": "^6.10.0",
68
+ "eslint-plugin-import": "^2.18.2",
69
+ "eslint-plugin-jest": "^22.6.3",
70
+ "eslint-plugin-jsx-a11y": "^6.2.3",
71
+ "eslint-plugin-prettier": "^3.1.2",
72
+ "eslint-plugin-react": "^7.14.3",
73
+ "prettier": "^1.19.1",
74
+ "ts-loader": "^6.2.1",
75
+ "typescript": "^3.9.3"
76
+ }
77
+ }
@@ -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>;
@@ -1,60 +0,0 @@
1
- /// <reference types="react" />
2
- import { ReactNode } from "react";
3
- type Sides = "left" | "right";
4
- interface SideSheetOptions {
5
- side: Sides;
6
- mountStrategy: "all" | "top-only";
7
- }
8
- interface SideOptions {
9
- width?: number;
10
- className?: string;
11
- confirmBeforeClose?: boolean;
12
- confirmMessage?: string;
13
- confirmCallback?: (message: string) => Promise<boolean>;
14
- closeOnOverlayClick?: boolean;
15
- closeOnEsc?: boolean;
16
- animationDuration?: number;
17
- onOpen?: (id: number) => void;
18
- onClose?: (id: number) => void;
19
- }
20
- interface SideElementProps {
21
- sideId: number;
22
- close: (id: number | null) => Promise<void>;
23
- open: (element: SideElement, options?: SideOptions) => number;
24
- update: (id: number, options: SideOptions) => void;
25
- options: SideOptions;
26
- }
27
- type SideElement = (props: SideElementProps) => ReactNode;
28
- interface SideStackItem {
29
- id: number;
30
- element: SideElement;
31
- options: Required<SideOptions>;
32
- state: "opening" | "open" | "closing";
33
- }
34
- interface SideSheetContextValue {
35
- open: (el: SideElement, opts?: SideOptions) => number;
36
- close: (id: number | null) => Promise<void>;
37
- update: (id: number, opts: SideOptions) => void;
38
- config: SideSheetOptions;
39
- }
40
- declare const useSideSheet: () => SideSheetContextValue;
41
- declare const SideSheet: {
42
- Provider: import("react").FC<{
43
- children: import("react").ReactNode;
44
- configuration?: Partial<SideSheetOptions> | undefined;
45
- }>;
46
- Header: import("react").FC<{
47
- title: string;
48
- onClose?: (() => void) | undefined;
49
- actions?: import("react").ReactNode;
50
- }>;
51
- Content: import("react").FC<{
52
- children: import("react").ReactNode;
53
- className?: string | undefined;
54
- }>;
55
- Footer: import("react").FC<{
56
- children: import("react").ReactNode;
57
- className?: string | undefined;
58
- }>;
59
- };
60
- export { useSideSheet, Sides, SideSheetOptions, SideOptions, SideElementProps, SideElement, SideStackItem, SideSheetContextValue, SideSheet };