react-side-sheet-pro 0.1.8 → 0.1.9

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 CHANGED
@@ -151,10 +151,10 @@ Sheet footer component that can be used to display actions or additional informa
151
151
  cd playground/ && npm start
152
152
  ```
153
153
 
154
- ## 🌟 Contributing
154
+ ## 🤝 Contributing
155
155
 
156
156
  We welcome contributions! If you'd like to help improve this project, feel free to open an issue or submit a pull request.
157
157
 
158
- ## License
158
+ ## 📜 License
159
159
 
160
160
  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(stack, idx) {
28
+ var _stack$options$width, _stack;
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 undefined;
35
+ var viewportWidth = document.documentElement.clientWidth;
36
+ var maxWidth = (_stack$options$width = (_stack = stack[stack.length - 1]) === null || _stack === void 0 ? void 0 : _stack.options.width) !== null && _stack$options$width !== void 0 ? _stack$options$width : 0;
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, maxWidth);
44
+ return padding > 0 ? padding : next.options.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,30 @@ 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';
33
67
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, stack.map(function (item, idx) {
34
- var _stack;
35
- var isTop = idx === stack.length - 1;
36
- var isPrevClosing = ((_stack = stack[idx - 1]) === null || _stack === void 0 ? void 0 : _stack.state) === 'closing';
68
+ var _getStackItemMeta2 = getStackItemMeta(stack, idx),
69
+ next = _getStackItemMeta2.next,
70
+ isTop = _getStackItemMeta2.isTop,
71
+ isPrevClosing = _getStackItemMeta2.isPrevClosing,
72
+ isNextTransitioning = _getStackItemMeta2.isNextTransitioning;
37
73
  var _item$options = item.options,
38
74
  width = _item$options.width,
39
75
  closeOnOverlayClick = _item$options.closeOnOverlayClick,
40
76
  className = _item$options.className;
41
- if (config.mountStrategy === 'top-only' && !isTop && !isPrevClosing) return null;
77
+ var isEffectiveTop = isTop || isPrevClosing;
78
+ var isVisible = !(config.mountStrategy === 'top-only' && !isEffectiveTop);
79
+ var paddingValue = isEffectiveTop || isNextTransitioning || !next ? undefined : "".concat(computePadding(stack, idx), "px");
80
+ var elementProps = {
81
+ sideId: item.id,
82
+ options: item.options,
83
+ close: close,
84
+ open: open,
85
+ update: update
86
+ };
42
87
  return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, {
43
88
  key: item.id
44
- }, /*#__PURE__*/_react["default"].createElement("div", {
89
+ }, isVisible && /*#__PURE__*/_react["default"].createElement("div", {
45
90
  className: "sidesheet-overlay",
46
91
  onClick: function onClick() {
47
92
  if (closeOnOverlayClick && item.state === 'open') {
@@ -51,20 +96,11 @@ var SideSheetContainer = exports.SideSheetContainer = function SideSheetContaine
51
96
  }), /*#__PURE__*/_react["default"].createElement("div", {
52
97
  role: "dialog",
53
98
  "aria-modal": "true",
54
- className: (0, _classnames["default"])('sidesheet', "sidesheet-animation-".concat(item.state), {
55
- 'sidesheet-left': config.side === 'left',
56
- 'sidesheet-right': config.side === 'right'
57
- }, className),
58
- style: {
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
- })));
99
+ className: (0, _classnames["default"])('sidesheet', "sidesheet-animation-".concat(item.state), "sidesheet-".concat(config.side), !isVisible && 'sidesheet-invisible', className),
100
+ style: _defineProperty({
101
+ width: isEffectiveTop ? "".concat(width, "px") : '100%'
102
+ }, paddingKey, paddingValue)
103
+ }, item.element(elementProps)));
68
104
  }));
69
105
  };
70
106
  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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "react-side-sheet-pro",
3
3
  "description": "A flexible React SideSheet component for displaying contextual information.",
4
- "version": "0.1.8",
4
+ "version": "0.1.9",
5
5
  "license": "MIT",
6
6
  "keywords": [
7
7
  "react",
@@ -15,6 +15,44 @@ type SideSheetContainerProps = {
15
15
  config: Required<SideSheetOptions>;
16
16
  };
17
17
 
18
+ function getStackItemMeta(stack: SideStackItem[], idx: number) {
19
+ const prev = stack[idx - 1];
20
+ const next = stack[idx + 1];
21
+ return {
22
+ prev,
23
+ next,
24
+ isTop: idx === stack.length - 1,
25
+ isPrevClosing: prev?.state === 'closing',
26
+ isNextTransitioning: next?.state === 'closing' || next?.state === 'opening',
27
+ };
28
+ }
29
+
30
+ function computePadding(
31
+ stack: SideStackItem[],
32
+ idx: number
33
+ ): number | undefined {
34
+ const { next, isTop, isPrevClosing, isNextTransitioning } = getStackItemMeta(
35
+ stack,
36
+ idx
37
+ );
38
+
39
+ if (isTop || isPrevClosing || isNextTransitioning || !next) return undefined;
40
+
41
+ const viewportWidth = document.documentElement.clientWidth;
42
+ const maxWidth = stack[stack.length - 1]?.options.width ?? 0;
43
+
44
+ let padding = 0;
45
+ if (viewportWidth >= 1160) {
46
+ padding = Math.floor((viewportWidth - 960) / 2);
47
+ } else if (viewportWidth >= 768) {
48
+ padding = Math.floor((viewportWidth - 768) / 2);
49
+ }
50
+
51
+ padding = Math.min(padding, maxWidth);
52
+
53
+ return padding > 0 ? padding : next.options.width / 2;
54
+ }
55
+
18
56
  export const SideSheetContainer: React.FC<SideSheetContainerProps> = ({
19
57
  stack,
20
58
  open,
@@ -38,49 +76,64 @@ export const SideSheetContainer: React.FC<SideSheetContainerProps> = ({
38
76
  };
39
77
  }, [stack, close]);
40
78
 
79
+ const paddingKey = config.side === 'left' ? 'paddingLeft' : 'paddingRight';
80
+
41
81
  return (
42
82
  <>
43
83
  {stack.map((item, idx) => {
44
- const isTop = idx === stack.length - 1;
45
- const isPrevClosing = stack[idx - 1]?.state === 'closing';
84
+ const {
85
+ next,
86
+ isTop,
87
+ isPrevClosing,
88
+ isNextTransitioning,
89
+ } = getStackItemMeta(stack, idx);
46
90
  const { width, closeOnOverlayClick, className } = item.options;
47
91
 
48
- if (config.mountStrategy === 'top-only' && !isTop && !isPrevClosing)
49
- return null;
92
+ const isEffectiveTop = isTop || isPrevClosing;
93
+ const isVisible = !(
94
+ config.mountStrategy === 'top-only' && !isEffectiveTop
95
+ );
96
+ const paddingValue =
97
+ isEffectiveTop || isNextTransitioning || !next
98
+ ? undefined
99
+ : `${computePadding(stack, idx)}px`;
100
+
101
+ const elementProps = {
102
+ sideId: item.id,
103
+ options: item.options,
104
+ close,
105
+ open,
106
+ update,
107
+ };
50
108
 
51
109
  return (
52
110
  <React.Fragment key={item.id}>
53
- <div
54
- className="sidesheet-overlay"
55
- onClick={() => {
56
- if (closeOnOverlayClick && item.state === 'open') {
57
- close(item.id);
58
- }
59
- }}
60
- />
111
+ {isVisible && (
112
+ <div
113
+ className="sidesheet-overlay"
114
+ onClick={() => {
115
+ if (closeOnOverlayClick && item.state === 'open') {
116
+ close(item.id);
117
+ }
118
+ }}
119
+ />
120
+ )}
61
121
  <div
62
122
  role="dialog"
63
123
  aria-modal="true"
64
124
  className={classNames(
65
125
  'sidesheet',
66
126
  `sidesheet-animation-${item.state}`,
67
- {
68
- 'sidesheet-left': config.side === 'left',
69
- 'sidesheet-right': config.side === 'right',
70
- },
127
+ `sidesheet-${config.side}`,
128
+ !isVisible && 'sidesheet-invisible',
71
129
  className
72
130
  )}
73
131
  style={{
74
- width: `${isTop || isPrevClosing ? `${width}px` : '100%'}`,
132
+ width: isEffectiveTop ? `${width}px` : '100%',
133
+ [paddingKey]: paddingValue,
75
134
  }}
76
135
  >
77
- {item.element({
78
- sideId: item.id,
79
- options: item.options,
80
- close,
81
- open,
82
- update,
83
- })}
136
+ {item.element(elementProps)}
84
137
  </div>
85
138
  </React.Fragment>
86
139
  );
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;