react-side-sheet-pro 0.1.8 → 0.2.0
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 +7 -4
- package/dist/components/SideSheetContainer.js +69 -21
- package/dist/components/SideSheetProvider.js +0 -2
- package/dist/constants/defaultOptions.js +0 -1
- package/dist/index.css +6 -1
- package/index.d.ts +10 -6
- package/package.json +1 -1
- package/src/components/SideSheetContainer.tsx +99 -25
- package/src/constants/defaultOptions.ts +3 -2
- package/src/index.css +6 -1
- package/src/types/index.ts +10 -4
package/README.md
CHANGED
|
@@ -42,10 +42,10 @@ yarn add react-side-sheet-pro
|
|
|
42
42
|
## ⚡️ Quick Start
|
|
43
43
|
```typescript jsx
|
|
44
44
|
import React from 'react'
|
|
45
|
-
import { SideSheet,
|
|
45
|
+
import { SideSheet, SideComponent, useSideSheet } from 'react-side-sheet-pro'
|
|
46
46
|
import 'react-side-sheet-pro/dist/index.css'
|
|
47
47
|
|
|
48
|
-
const UserDetails:
|
|
48
|
+
const UserDetails: SideComponent<{ user: any }> = ({
|
|
49
49
|
user,
|
|
50
50
|
sideId,
|
|
51
51
|
close,
|
|
@@ -68,6 +68,8 @@ const UserDetails: React.FC<SideElementProps & { user: any }> = ({
|
|
|
68
68
|
</>
|
|
69
69
|
)
|
|
70
70
|
|
|
71
|
+
UserDetails.defaultWidth = 900
|
|
72
|
+
|
|
71
73
|
export const App = () => {
|
|
72
74
|
const { open } = useSideSheet()
|
|
73
75
|
|
|
@@ -84,6 +86,7 @@ export const App = () => {
|
|
|
84
86
|
/>
|
|
85
87
|
),
|
|
86
88
|
{
|
|
89
|
+
// you can override the default width set on the component
|
|
87
90
|
width: 600,
|
|
88
91
|
}
|
|
89
92
|
)
|
|
@@ -151,10 +154,10 @@ Sheet footer component that can be used to display actions or additional informa
|
|
|
151
154
|
cd playground/ && npm start
|
|
152
155
|
```
|
|
153
156
|
|
|
154
|
-
##
|
|
157
|
+
## 🤝 Contributing
|
|
155
158
|
|
|
156
159
|
We welcome contributions! If you'd like to help improve this project, feel free to open an issue or submit a pull request.
|
|
157
160
|
|
|
158
|
-
## License
|
|
161
|
+
## 📜 License
|
|
159
162
|
|
|
160
163
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -10,6 +9,40 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
10
9
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
11
10
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
12
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
15
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
16
|
+
function getStackItemMeta(stack, idx) {
|
|
17
|
+
var prev = stack[idx - 1];
|
|
18
|
+
var next = stack[idx + 1];
|
|
19
|
+
return {
|
|
20
|
+
prev: prev,
|
|
21
|
+
next: next,
|
|
22
|
+
isTop: idx === stack.length - 1,
|
|
23
|
+
isPrevClosing: (prev === null || prev === void 0 ? void 0 : prev.state) === 'closing',
|
|
24
|
+
isNextTransitioning: (next === null || next === void 0 ? void 0 : next.state) === 'closing' || (next === null || next === void 0 ? void 0 : next.state) === 'opening'
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function computePadding(resolved, stack, idx) {
|
|
28
|
+
var _resolved;
|
|
29
|
+
var _getStackItemMeta = getStackItemMeta(stack, idx),
|
|
30
|
+
next = _getStackItemMeta.next,
|
|
31
|
+
isTop = _getStackItemMeta.isTop,
|
|
32
|
+
isPrevClosing = _getStackItemMeta.isPrevClosing,
|
|
33
|
+
isNextTransitioning = _getStackItemMeta.isNextTransitioning;
|
|
34
|
+
if (isTop || isPrevClosing || isNextTransitioning || !next) return;
|
|
35
|
+
var viewportWidth = document.documentElement.clientWidth;
|
|
36
|
+
var width = resolved[resolved.length - 1].width;
|
|
37
|
+
var padding = 0;
|
|
38
|
+
if (viewportWidth >= 1160) {
|
|
39
|
+
padding = Math.floor((viewportWidth - 960) / 2);
|
|
40
|
+
} else if (viewportWidth >= 768) {
|
|
41
|
+
padding = Math.floor((viewportWidth - 768) / 2);
|
|
42
|
+
}
|
|
43
|
+
padding = Math.min(padding, width);
|
|
44
|
+
return padding > 0 ? padding : ((_resolved = resolved[idx + 1]) === null || _resolved === void 0 ? void 0 : _resolved.width) / 2;
|
|
45
|
+
}
|
|
13
46
|
var SideSheetContainer = exports.SideSheetContainer = function SideSheetContainer(_ref) {
|
|
14
47
|
var stack = _ref.stack,
|
|
15
48
|
open = _ref.open,
|
|
@@ -30,18 +63,42 @@ var SideSheetContainer = exports.SideSheetContainer = function SideSheetContaine
|
|
|
30
63
|
document.removeEventListener('keydown', onKeyDown);
|
|
31
64
|
};
|
|
32
65
|
}, [stack, close]);
|
|
66
|
+
var paddingKey = config.side === 'left' ? 'paddingLeft' : 'paddingRight';
|
|
67
|
+
var resolved = stack.map(function (item) {
|
|
68
|
+
var _ref2, _item$options$width;
|
|
69
|
+
var elementProps = {
|
|
70
|
+
sideId: item.id,
|
|
71
|
+
options: item.options,
|
|
72
|
+
close: close,
|
|
73
|
+
open: open,
|
|
74
|
+
update: update
|
|
75
|
+
};
|
|
76
|
+
var element = item.element(elementProps);
|
|
77
|
+
var width = (_ref2 = (_item$options$width = item.options.width) !== null && _item$options$width !== void 0 ? _item$options$width : element.type.defaultWidth) !== null && _ref2 !== void 0 ? _ref2 : 400;
|
|
78
|
+
return {
|
|
79
|
+
id: item.id,
|
|
80
|
+
element: element,
|
|
81
|
+
width: width
|
|
82
|
+
};
|
|
83
|
+
});
|
|
33
84
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, stack.map(function (item, idx) {
|
|
34
|
-
var
|
|
35
|
-
|
|
36
|
-
|
|
85
|
+
var _getStackItemMeta2 = getStackItemMeta(stack, idx),
|
|
86
|
+
next = _getStackItemMeta2.next,
|
|
87
|
+
isTop = _getStackItemMeta2.isTop,
|
|
88
|
+
isPrevClosing = _getStackItemMeta2.isPrevClosing,
|
|
89
|
+
isNextTransitioning = _getStackItemMeta2.isNextTransitioning;
|
|
37
90
|
var _item$options = item.options,
|
|
38
|
-
width = _item$options.width,
|
|
39
91
|
closeOnOverlayClick = _item$options.closeOnOverlayClick,
|
|
40
92
|
className = _item$options.className;
|
|
41
|
-
|
|
93
|
+
var isEffectiveTop = isTop || isPrevClosing;
|
|
94
|
+
var isVisible = !(config.mountStrategy === 'top-only' && !isEffectiveTop);
|
|
95
|
+
var paddingValue = isEffectiveTop || isNextTransitioning || !next ? undefined : "".concat(computePadding(resolved, stack, idx), "px");
|
|
96
|
+
var _resolved$idx = resolved[idx],
|
|
97
|
+
element = _resolved$idx.element,
|
|
98
|
+
width = _resolved$idx.width;
|
|
42
99
|
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, {
|
|
43
100
|
key: item.id
|
|
44
|
-
}, /*#__PURE__*/_react["default"].createElement("div", {
|
|
101
|
+
}, isVisible && /*#__PURE__*/_react["default"].createElement("div", {
|
|
45
102
|
className: "sidesheet-overlay",
|
|
46
103
|
onClick: function onClick() {
|
|
47
104
|
if (closeOnOverlayClick && item.state === 'open') {
|
|
@@ -51,20 +108,11 @@ var SideSheetContainer = exports.SideSheetContainer = function SideSheetContaine
|
|
|
51
108
|
}), /*#__PURE__*/_react["default"].createElement("div", {
|
|
52
109
|
role: "dialog",
|
|
53
110
|
"aria-modal": "true",
|
|
54
|
-
className: (0, _classnames["default"])('sidesheet', "sidesheet-animation-".concat(item.state),
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
width: "".concat(isTop || isPrevClosing ? "".concat(width, "px") : '100%')
|
|
60
|
-
}
|
|
61
|
-
}, item.element({
|
|
62
|
-
sideId: item.id,
|
|
63
|
-
options: item.options,
|
|
64
|
-
close: close,
|
|
65
|
-
open: open,
|
|
66
|
-
update: update
|
|
67
|
-
})));
|
|
111
|
+
className: (0, _classnames["default"])('sidesheet', "sidesheet-animation-".concat(item.state), "sidesheet-".concat(config.side), !isVisible && 'sidesheet-invisible', className),
|
|
112
|
+
style: _defineProperty({
|
|
113
|
+
width: isEffectiveTop ? "".concat(width, "px") : '100%'
|
|
114
|
+
}, paddingKey, paddingValue)
|
|
115
|
+
}, element));
|
|
68
116
|
}));
|
|
69
117
|
};
|
|
70
118
|
SideSheetContainer.propTypes = {
|
|
@@ -44,9 +44,7 @@ var SideSheetProvider = exports.SideSheetProvider = function SideSheetProvider(_
|
|
|
44
44
|
(0, _react.useEffect)(function () {
|
|
45
45
|
stackRef.current = stack;
|
|
46
46
|
if (!config.enableOverflow) {
|
|
47
|
-
console.warn([document.body.style.overflow, stack.length, overflowRef.current]);
|
|
48
47
|
if (!stack.length) {
|
|
49
|
-
console.warn(overflowRef.current);
|
|
50
48
|
if (overflowRef.current !== null) {
|
|
51
49
|
document.body.style.overflow = overflowRef.current;
|
|
52
50
|
overflowRef.current = null;
|
package/dist/index.css
CHANGED
|
@@ -93,13 +93,18 @@
|
|
|
93
93
|
width: 100%;
|
|
94
94
|
box-shadow: 0 0 10px -5px rgba(0, 0, 0, 0.2), 0 0 24px 2px rgba(0, 0, 0, 0.14),
|
|
95
95
|
0 0 30px 5px rgba(0, 0, 0, 0.12);
|
|
96
|
-
transition: transform 0.3s ease, width 0.3s ease
|
|
96
|
+
transition: transform 0.3s ease, width 0.3s ease, padding-right 0.3s ease,
|
|
97
|
+
padding-left 0.3s ease;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
.sheet-white {
|
|
100
101
|
background: #fff;
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
.sidesheet-invisible {
|
|
105
|
+
display: none;
|
|
106
|
+
}
|
|
107
|
+
|
|
103
108
|
.sidesheet-header .sidesheet-header-btn {
|
|
104
109
|
background: transparent;
|
|
105
110
|
border: none;
|
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
2
|
+
import { ComponentType, JSXElementConstructor, ReactElement } from "react";
|
|
3
3
|
type Sides = "left" | "right";
|
|
4
4
|
interface SideSheetOptions {
|
|
5
5
|
side: Sides;
|
|
@@ -24,19 +24,23 @@ interface SideOptions {
|
|
|
24
24
|
interface SideElementProps {
|
|
25
25
|
sideId: number | string;
|
|
26
26
|
close: (id: number | string | null, force?: boolean) => Promise<void>;
|
|
27
|
-
open: (element:
|
|
27
|
+
open: (element: SideComponent, options?: SideOptions) => number | string;
|
|
28
28
|
update: (id: number | string, options: SideOptions) => void;
|
|
29
29
|
options: SideOptions;
|
|
30
|
+
width?: number;
|
|
30
31
|
}
|
|
31
|
-
type
|
|
32
|
+
type SideComponent<P = {}> =
|
|
33
|
+
ComponentType<P & SideElementProps> & {
|
|
34
|
+
defaultWidth?: number;
|
|
35
|
+
};
|
|
32
36
|
interface SideStackItem {
|
|
33
37
|
id: number | string;
|
|
34
|
-
element:
|
|
38
|
+
element: SideComponent;
|
|
35
39
|
options: Required<SideOptions>;
|
|
36
40
|
state: "opening" | "open" | "closing";
|
|
37
41
|
}
|
|
38
42
|
interface SideSheetContextValue {
|
|
39
|
-
open: (el:
|
|
43
|
+
open: (el: SideComponent, opts?: SideOptions) => number | string;
|
|
40
44
|
close: (id: number | string | null, force?: boolean) => Promise<void>;
|
|
41
45
|
update: (id: number | string, opts: SideOptions) => void;
|
|
42
46
|
config: SideSheetOptions;
|
|
@@ -62,4 +66,4 @@ declare const SideSheet: {
|
|
|
62
66
|
className?: string | undefined;
|
|
63
67
|
}>;
|
|
64
68
|
};
|
|
65
|
-
export { useSideSheet, Sides, SideSheetOptions, SideOptions, SideElementProps,
|
|
69
|
+
export { useSideSheet, Sides, SideSheetOptions, SideOptions, SideElementProps, SideComponent, SideStackItem, SideSheetContextValue, SideSheet };
|
package/package.json
CHANGED
|
@@ -2,6 +2,7 @@ import React, { useEffect } from 'react';
|
|
|
2
2
|
import classNames from 'classnames';
|
|
3
3
|
import {
|
|
4
4
|
SideElement,
|
|
5
|
+
SideElementProps,
|
|
5
6
|
SideOptions,
|
|
6
7
|
SideSheetOptions,
|
|
7
8
|
SideStackItem,
|
|
@@ -15,6 +16,51 @@ type SideSheetContainerProps = {
|
|
|
15
16
|
config: Required<SideSheetOptions>;
|
|
16
17
|
};
|
|
17
18
|
|
|
19
|
+
type ResolvedItem = {
|
|
20
|
+
id: number | string;
|
|
21
|
+
element: React.ReactElement;
|
|
22
|
+
width: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function getStackItemMeta(stack: SideStackItem[], idx: number) {
|
|
26
|
+
const prev = stack[idx - 1];
|
|
27
|
+
const next = stack[idx + 1];
|
|
28
|
+
return {
|
|
29
|
+
prev,
|
|
30
|
+
next,
|
|
31
|
+
isTop: idx === stack.length - 1,
|
|
32
|
+
isPrevClosing: prev?.state === 'closing',
|
|
33
|
+
isNextTransitioning: next?.state === 'closing' || next?.state === 'opening',
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function computePadding(
|
|
38
|
+
resolved: ResolvedItem[],
|
|
39
|
+
stack: SideStackItem[],
|
|
40
|
+
idx: number
|
|
41
|
+
): number | undefined {
|
|
42
|
+
const { next, isTop, isPrevClosing, isNextTransitioning } = getStackItemMeta(
|
|
43
|
+
stack,
|
|
44
|
+
idx
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
if (isTop || isPrevClosing || isNextTransitioning || !next) return;
|
|
48
|
+
|
|
49
|
+
const viewportWidth = document.documentElement.clientWidth;
|
|
50
|
+
const { width } = resolved[resolved.length - 1];
|
|
51
|
+
|
|
52
|
+
let padding = 0;
|
|
53
|
+
if (viewportWidth >= 1160) {
|
|
54
|
+
padding = Math.floor((viewportWidth - 960) / 2);
|
|
55
|
+
} else if (viewportWidth >= 768) {
|
|
56
|
+
padding = Math.floor((viewportWidth - 768) / 2);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
padding = Math.min(padding, width);
|
|
60
|
+
|
|
61
|
+
return padding > 0 ? padding : resolved[idx + 1]?.width / 2;
|
|
62
|
+
}
|
|
63
|
+
|
|
18
64
|
export const SideSheetContainer: React.FC<SideSheetContainerProps> = ({
|
|
19
65
|
stack,
|
|
20
66
|
open,
|
|
@@ -38,49 +84,77 @@ export const SideSheetContainer: React.FC<SideSheetContainerProps> = ({
|
|
|
38
84
|
};
|
|
39
85
|
}, [stack, close]);
|
|
40
86
|
|
|
87
|
+
const paddingKey = config.side === 'left' ? 'paddingLeft' : 'paddingRight';
|
|
88
|
+
|
|
89
|
+
const resolved: ResolvedItem[] = stack.map(item => {
|
|
90
|
+
const elementProps = {
|
|
91
|
+
sideId: item.id,
|
|
92
|
+
options: item.options,
|
|
93
|
+
close,
|
|
94
|
+
open,
|
|
95
|
+
update,
|
|
96
|
+
} as SideElementProps;
|
|
97
|
+
|
|
98
|
+
const element = item.element(elementProps);
|
|
99
|
+
const width = item.options.width ?? element.type.defaultWidth ?? 400;
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
id: item.id,
|
|
103
|
+
element,
|
|
104
|
+
width,
|
|
105
|
+
};
|
|
106
|
+
});
|
|
107
|
+
|
|
41
108
|
return (
|
|
42
109
|
<>
|
|
43
110
|
{stack.map((item, idx) => {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
111
|
+
const {
|
|
112
|
+
next,
|
|
113
|
+
isTop,
|
|
114
|
+
isPrevClosing,
|
|
115
|
+
isNextTransitioning,
|
|
116
|
+
} = getStackItemMeta(stack, idx);
|
|
47
117
|
|
|
48
|
-
|
|
49
|
-
|
|
118
|
+
const { closeOnOverlayClick, className } = item.options;
|
|
119
|
+
|
|
120
|
+
const isEffectiveTop = isTop || isPrevClosing;
|
|
121
|
+
const isVisible = !(
|
|
122
|
+
config.mountStrategy === 'top-only' && !isEffectiveTop
|
|
123
|
+
);
|
|
124
|
+
const paddingValue =
|
|
125
|
+
isEffectiveTop || isNextTransitioning || !next
|
|
126
|
+
? undefined
|
|
127
|
+
: `${computePadding(resolved, stack, idx)}px`;
|
|
128
|
+
const { element, width } = resolved[idx];
|
|
50
129
|
|
|
51
130
|
return (
|
|
52
131
|
<React.Fragment key={item.id}>
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
132
|
+
{isVisible && (
|
|
133
|
+
<div
|
|
134
|
+
className="sidesheet-overlay"
|
|
135
|
+
onClick={() => {
|
|
136
|
+
if (closeOnOverlayClick && item.state === 'open') {
|
|
137
|
+
close(item.id);
|
|
138
|
+
}
|
|
139
|
+
}}
|
|
140
|
+
/>
|
|
141
|
+
)}
|
|
61
142
|
<div
|
|
62
143
|
role="dialog"
|
|
63
144
|
aria-modal="true"
|
|
64
145
|
className={classNames(
|
|
65
146
|
'sidesheet',
|
|
66
147
|
`sidesheet-animation-${item.state}`,
|
|
67
|
-
{
|
|
68
|
-
|
|
69
|
-
'sidesheet-right': config.side === 'right',
|
|
70
|
-
},
|
|
148
|
+
`sidesheet-${config.side}`,
|
|
149
|
+
!isVisible && 'sidesheet-invisible',
|
|
71
150
|
className
|
|
72
151
|
)}
|
|
73
152
|
style={{
|
|
74
|
-
width:
|
|
153
|
+
width: isEffectiveTop ? `${width}px` : '100%',
|
|
154
|
+
[paddingKey]: paddingValue,
|
|
75
155
|
}}
|
|
76
156
|
>
|
|
77
|
-
{
|
|
78
|
-
sideId: item.id,
|
|
79
|
-
options: item.options,
|
|
80
|
-
close,
|
|
81
|
-
open,
|
|
82
|
-
update,
|
|
83
|
-
})}
|
|
157
|
+
{element}
|
|
84
158
|
</div>
|
|
85
159
|
</React.Fragment>
|
|
86
160
|
);
|
|
@@ -11,9 +11,10 @@ export const DEFAULT_OPTIONS: Required<SideSheetOptions> = {
|
|
|
11
11
|
: Promise.resolve(true),
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
export const DEFAULT_SHEET_OPTIONS: Required<SideOptions
|
|
14
|
+
export const DEFAULT_SHEET_OPTIONS: Required<Omit<SideOptions, 'width'>> & {
|
|
15
|
+
width?: number;
|
|
16
|
+
} = {
|
|
15
17
|
id: '',
|
|
16
|
-
width: 400,
|
|
17
18
|
className: '',
|
|
18
19
|
confirmBeforeClose: false,
|
|
19
20
|
confirmMessage: null,
|
package/src/index.css
CHANGED
|
@@ -93,13 +93,18 @@
|
|
|
93
93
|
width: 100%;
|
|
94
94
|
box-shadow: 0 0 10px -5px rgba(0, 0, 0, 0.2), 0 0 24px 2px rgba(0, 0, 0, 0.14),
|
|
95
95
|
0 0 30px 5px rgba(0, 0, 0, 0.12);
|
|
96
|
-
transition: transform 0.3s ease, width 0.3s ease
|
|
96
|
+
transition: transform 0.3s ease, width 0.3s ease, padding-right 0.3s ease,
|
|
97
|
+
padding-left 0.3s ease;
|
|
97
98
|
}
|
|
98
99
|
|
|
99
100
|
.sheet-white {
|
|
100
101
|
background: #fff;
|
|
101
102
|
}
|
|
102
103
|
|
|
104
|
+
.sidesheet-invisible {
|
|
105
|
+
display: none;
|
|
106
|
+
}
|
|
107
|
+
|
|
103
108
|
.sidesheet-header .sidesheet-header-btn {
|
|
104
109
|
background: transparent;
|
|
105
110
|
border: none;
|
package/src/types/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ComponentType, ReactElement } from 'react';
|
|
2
2
|
|
|
3
3
|
export type Sides = 'left' | 'right';
|
|
4
4
|
|
|
@@ -27,17 +27,23 @@ export interface SideOptions {
|
|
|
27
27
|
export interface SideElementProps {
|
|
28
28
|
sideId: number | string;
|
|
29
29
|
close: (id: number | string | null) => Promise<void>;
|
|
30
|
-
open: (element:
|
|
30
|
+
open: (element: SideComponent, options?: SideOptions) => number | string;
|
|
31
31
|
update: (id: number | string, options: SideOptions) => void;
|
|
32
32
|
options: SideOptions;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
export type
|
|
35
|
+
export type SideComponent<P = {}> = ComponentType<P & SideElementProps> & {
|
|
36
|
+
defaultWidth?: number;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export type SideElement = (
|
|
40
|
+
props: SideElementProps
|
|
41
|
+
) => ReactElement<any, SideComponent>;
|
|
36
42
|
|
|
37
43
|
export interface SideStackItem {
|
|
38
44
|
id: number | string;
|
|
39
45
|
element: SideElement;
|
|
40
|
-
options: Required<SideOptions
|
|
46
|
+
options: Required<Omit<SideOptions, 'width'>> & { width?: number };
|
|
41
47
|
state: 'opening' | 'open' | 'closing';
|
|
42
48
|
}
|
|
43
49
|
|