@rc-component/drawer 1.2.0 → 1.3.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 CHANGED
@@ -1,15 +1,13 @@
1
- # rc-drawer
1
+ # @rc-component/drawer
2
2
 
3
- [![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![codecov](https://codecov.io/gh/react-component/drawer/branch/master/graph/badge.svg)](https://codecov.io/gh/react-component/drawer) [![node version][node-image]][node-url] [![npm download][download-image]][download-url]
3
+ [![NPM version][npm-image]][npm-url] [![dumi](https://img.shields.io/badge/docs%20by-dumi-blue?style=flat-square)](https://github.com/umijs/dumi) [![build status][github-actions-image]][github-actions-url] [![codecov](https://codecov.io/gh/react-component/drawer/branch/master/graph/badge.svg)](https://codecov.io/gh/react-component/drawer) [![npm download][download-image]][download-url]
4
4
 
5
- [npm-image]: http://img.shields.io/npm/v/rc-drawer.svg?style=flat-square
6
- [npm-url]: http://npmjs.org/package/rc-drawer
7
- [github-actions-image]: https://github.com/react-component/drawer/workflows/CI/badge.svg
8
- [github-actions-url]: https://github.com/react-component/drawer/actions
9
- [node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square
10
- [node-url]: http://nodejs.org/download/
11
- [download-image]: https://img.shields.io/npm/dm/rc-drawer.svg?style=flat-square
12
- [download-url]: https://npmjs.org/package/rc-drawer
5
+ [npm-image]: http://img.shields.io/npm/v/@rc-component/drawer.svg?style=flat-square
6
+ [npm-url]: http://npmjs.org/package/@rc-component/drawer
7
+ [github-actions-image]: https://github.com/react-component/drawer/actions/workflows/react-component-ci.yml/badge.svg
8
+ [github-actions-url]: https://github.com/react-component/drawer/actions/workflows/react-component-ci.yml
9
+ [download-image]: https://img.shields.io/npm/dm/@rc-component/drawer.svg?style=flat-square
10
+ [download-url]: https://npmjs.org/package/@rc-component/drawer
13
11
 
14
12
  ## Example
15
13
 
@@ -18,7 +16,7 @@ https://drawer-react-component.vercel.app/
18
16
  ## Usage
19
17
 
20
18
  ```js
21
- import Drawer from 'rc-drawer';
19
+ import Drawer from '@rc-component/drawer';
22
20
  import React from 'react';
23
21
  import ReactDom from 'react-dom';
24
22
 
@@ -31,7 +29,7 @@ ReactDom.render(
31
29
 
32
30
  ## Install
33
31
 
34
- [![rc-drawer](https://nodei.co/npm/rc-drawer.png)](https://npmjs.org/package/rc-drawer)
32
+ [![@rc-component/drawer](https://nodei.co/npm/@rc-component/drawer.png)](https://npmjs.org/package/@rc-component/drawer)
35
33
 
36
34
  ## Browser Support
37
35
 
@@ -45,7 +43,7 @@ ReactDom.render(
45
43
  | ------------------ | --------------------------------------------------------------------------- | -------------------------------------- | ----------------------------------------------------------------------------- |
46
44
  | className | string | null | - |
47
45
  | classNames | { mask?: string; content?: string; wrapper?: string; } | - | pass className to target area |
48
- | styles | { mask?: CSSProperties; content?: CSSProperties; wrapper?: CSSProperties; } | - | pass style to target area |
46
+ | styles | { mask?: CSSProperties; content?: CSSProperties; wrapper?: CSSProperties; } | `rc-drawer` | pass style to target area |
49
47
  | prefixCls | string | 'drawer' | prefix class |
50
48
  | width | string \| number | null | drawer content wrapper width, drawer level transition width |
51
49
  | height | string \| number | null | drawer content wrapper height, drawer level transition height |
package/es/Drawer.d.ts CHANGED
@@ -27,8 +27,8 @@ export interface DrawerProps extends Omit<DrawerPopupProps, 'prefixCls' | 'inlin
27
27
  maxSize?: number;
28
28
  /** Default size for uncontrolled resizable drawer */
29
29
  defaultSize?: number | string;
30
- /** Resizable configuration - object with optional callbacks */
31
- resizable?: {
30
+ /** Resizable configuration - boolean to enable/disable or object with optional callbacks */
31
+ resizable?: boolean | {
32
32
  onResize?: (size: number) => void;
33
33
  onResizeStart?: () => void;
34
34
  onResizeEnd?: () => void;
package/es/DrawerPanel.js CHANGED
@@ -1,5 +1,5 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import classNames from 'classnames';
2
+ import { clsx } from 'clsx';
3
3
  import * as React from 'react';
4
4
  import { RefContext } from "./context";
5
5
  import pickAttrs from "@rc-component/util/es/pickAttrs";
@@ -19,7 +19,7 @@ const DrawerPanel = props => {
19
19
  // =============================== Render ===============================
20
20
 
21
21
  return /*#__PURE__*/React.createElement("div", _extends({
22
- className: classNames(`${prefixCls}-section`, className),
22
+ className: clsx(`${prefixCls}-section`, className),
23
23
  role: "dialog",
24
24
  ref: mergedRef
25
25
  }, pickAttrs(props, {
@@ -41,7 +41,7 @@ export interface DrawerPopupProps extends DrawerPanelEvents, DrawerPanelAccessib
41
41
  drawerRender?: (node: React.ReactNode) => React.ReactNode;
42
42
  /** Default size for uncontrolled resizable drawer */
43
43
  defaultSize?: number | string;
44
- resizable?: {
44
+ resizable?: boolean | {
45
45
  onResize?: (size: number) => void;
46
46
  onResizeStart?: () => void;
47
47
  onResizeEnd?: () => void;
package/es/DrawerPopup.js CHANGED
@@ -1,5 +1,5 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import classNames from 'classnames';
2
+ import { clsx } from 'clsx';
3
3
  import CSSMotion from '@rc-component/motion';
4
4
  import KeyCode from "@rc-component/util/es/KeyCode";
5
5
  import pickAttrs from "@rc-component/util/es/pickAttrs";
@@ -161,7 +161,7 @@ const DrawerPopup = (props, ref) => {
161
161
  className: motionMaskClassName,
162
162
  style: motionMaskStyle
163
163
  }, maskRef) => /*#__PURE__*/React.createElement("div", {
164
- className: classNames(`${prefixCls}-mask`, motionMaskClassName, drawerClassNames?.mask, maskClassName),
164
+ className: clsx(`${prefixCls}-mask`, motionMaskClassName, drawerClassNames?.mask, maskClassName),
165
165
  style: {
166
166
  ...motionMaskStyle,
167
167
  ...maskStyle,
@@ -214,9 +214,11 @@ const DrawerPopup = (props, ref) => {
214
214
 
215
215
  // =========================== Resize ===========================
216
216
  const wrapperRef = React.useRef(null);
217
+ const isResizable = !!resizable;
218
+ const resizeConfig = typeof resizable === 'object' && resizable || {};
217
219
  const onInternalResize = useEvent(size => {
218
220
  setCurrentSize(size);
219
- resizable?.onResize?.(size);
221
+ resizeConfig.onResize?.(size);
220
222
  });
221
223
  const {
222
224
  dragElementProps,
@@ -230,8 +232,8 @@ const DrawerPopup = (props, ref) => {
230
232
  containerRef: wrapperRef,
231
233
  currentSize: mergedSize,
232
234
  onResize: onInternalResize,
233
- onResizeStart: resizable?.onResizeStart,
234
- onResizeEnd: resizable?.onResizeEnd
235
+ onResizeStart: resizeConfig.onResizeStart,
236
+ onResizeEnd: resizeConfig.onResizeEnd
235
237
  });
236
238
 
237
239
  // =========================== Events ===========================
@@ -264,7 +266,7 @@ const DrawerPopup = (props, ref) => {
264
266
  id: id,
265
267
  containerRef: motionRef,
266
268
  prefixCls: prefixCls,
267
- className: classNames(className, drawerClassNames?.section),
269
+ className: clsx(className, drawerClassNames?.section),
268
270
  style: {
269
271
  ...style,
270
272
  ...styles?.section
@@ -274,7 +276,7 @@ const DrawerPopup = (props, ref) => {
274
276
  }), eventHandlers), children);
275
277
  return /*#__PURE__*/React.createElement("div", _extends({
276
278
  ref: wrapperRef,
277
- className: classNames(`${prefixCls}-content-wrapper`, isDragging && `${prefixCls}-content-wrapper-dragging`, drawerClassNames?.wrapper, !isDragging && motionClassName),
279
+ className: clsx(`${prefixCls}-content-wrapper`, isDragging && `${prefixCls}-content-wrapper-dragging`, drawerClassNames?.wrapper, !isDragging && motionClassName),
278
280
  style: {
279
281
  ...motionStyle,
280
282
  ...wrapperStyle,
@@ -282,7 +284,7 @@ const DrawerPopup = (props, ref) => {
282
284
  }
283
285
  }, pickAttrs(props, {
284
286
  data: true
285
- })), resizable && /*#__PURE__*/React.createElement("div", dragElementProps), drawerRender ? drawerRender(content) : content);
287
+ })), isResizable && /*#__PURE__*/React.createElement("div", dragElementProps), drawerRender ? drawerRender(content) : content);
286
288
  });
287
289
 
288
290
  // >>>>> Container
@@ -295,7 +297,7 @@ const DrawerPopup = (props, ref) => {
295
297
  return /*#__PURE__*/React.createElement(DrawerContext.Provider, {
296
298
  value: mergedContext
297
299
  }, /*#__PURE__*/React.createElement("div", {
298
- className: classNames(prefixCls, `${prefixCls}-${placement}`, rootClassName, {
300
+ className: clsx(prefixCls, `${prefixCls}-${placement}`, rootClassName, {
299
301
  [`${prefixCls}-open`]: open,
300
302
  [`${prefixCls}-inline`]: inline
301
303
  }),
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import classNames from 'classnames';
2
+ import { clsx } from 'clsx';
3
3
  import { useEvent } from '@rc-component/util';
4
4
  export default function useDrag(options) {
5
5
  const {
@@ -82,7 +82,7 @@ export default function useDrag(options) {
82
82
  };
83
83
  }
84
84
  }, [isDragging, handleMouseMove, handleMouseUp]);
85
- const dragElementClassName = classNames(`${prefixCls}-dragger`, `${prefixCls}-dragger-${direction}`, {
85
+ const dragElementClassName = clsx(`${prefixCls}-dragger`, `${prefixCls}-dragger-${direction}`, {
86
86
  [`${prefixCls}-dragger-dragging`]: isDragging,
87
87
  [`${prefixCls}-dragger-horizontal`]: isHorizontal,
88
88
  [`${prefixCls}-dragger-vertical`]: !isHorizontal
package/lib/Drawer.d.ts CHANGED
@@ -27,8 +27,8 @@ export interface DrawerProps extends Omit<DrawerPopupProps, 'prefixCls' | 'inlin
27
27
  maxSize?: number;
28
28
  /** Default size for uncontrolled resizable drawer */
29
29
  defaultSize?: number | string;
30
- /** Resizable configuration - object with optional callbacks */
31
- resizable?: {
30
+ /** Resizable configuration - boolean to enable/disable or object with optional callbacks */
31
+ resizable?: boolean | {
32
32
  onResize?: (size: number) => void;
33
33
  onResizeStart?: () => void;
34
34
  onResizeEnd?: () => void;
@@ -4,14 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _classnames = _interopRequireDefault(require("classnames"));
7
+ var _clsx = require("clsx");
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
  var _context = require("./context");
10
10
  var _pickAttrs = _interopRequireDefault(require("@rc-component/util/lib/pickAttrs"));
11
11
  var _ref = require("@rc-component/util/lib/ref");
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
13
14
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
16
16
  const DrawerPanel = props => {
17
17
  const {
@@ -28,7 +28,7 @@ const DrawerPanel = props => {
28
28
  // =============================== Render ===============================
29
29
 
30
30
  return /*#__PURE__*/React.createElement("div", _extends({
31
- className: (0, _classnames.default)(`${prefixCls}-section`, className),
31
+ className: (0, _clsx.clsx)(`${prefixCls}-section`, className),
32
32
  role: "dialog",
33
33
  ref: mergedRef
34
34
  }, (0, _pickAttrs.default)(props, {
@@ -41,7 +41,7 @@ export interface DrawerPopupProps extends DrawerPanelEvents, DrawerPanelAccessib
41
41
  drawerRender?: (node: React.ReactNode) => React.ReactNode;
42
42
  /** Default size for uncontrolled resizable drawer */
43
43
  defaultSize?: number | string;
44
- resizable?: {
44
+ resizable?: boolean | {
45
45
  onResize?: (size: number) => void;
46
46
  onResizeStart?: () => void;
47
47
  onResizeEnd?: () => void;
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- var _classnames = _interopRequireDefault(require("classnames"));
7
+ var _clsx = require("clsx");
8
8
  var _motion = _interopRequireDefault(require("@rc-component/motion"));
9
9
  var _KeyCode = _interopRequireDefault(require("@rc-component/util/lib/KeyCode"));
10
10
  var _pickAttrs = _interopRequireDefault(require("@rc-component/util/lib/pickAttrs"));
@@ -170,7 +170,7 @@ const DrawerPopup = (props, ref) => {
170
170
  className: motionMaskClassName,
171
171
  style: motionMaskStyle
172
172
  }, maskRef) => /*#__PURE__*/React.createElement("div", {
173
- className: (0, _classnames.default)(`${prefixCls}-mask`, motionMaskClassName, drawerClassNames?.mask, maskClassName),
173
+ className: (0, _clsx.clsx)(`${prefixCls}-mask`, motionMaskClassName, drawerClassNames?.mask, maskClassName),
174
174
  style: {
175
175
  ...motionMaskStyle,
176
176
  ...maskStyle,
@@ -223,9 +223,11 @@ const DrawerPopup = (props, ref) => {
223
223
 
224
224
  // =========================== Resize ===========================
225
225
  const wrapperRef = React.useRef(null);
226
+ const isResizable = !!resizable;
227
+ const resizeConfig = typeof resizable === 'object' && resizable || {};
226
228
  const onInternalResize = (0, _util2.useEvent)(size => {
227
229
  setCurrentSize(size);
228
- resizable?.onResize?.(size);
230
+ resizeConfig.onResize?.(size);
229
231
  });
230
232
  const {
231
233
  dragElementProps,
@@ -239,8 +241,8 @@ const DrawerPopup = (props, ref) => {
239
241
  containerRef: wrapperRef,
240
242
  currentSize: mergedSize,
241
243
  onResize: onInternalResize,
242
- onResizeStart: resizable?.onResizeStart,
243
- onResizeEnd: resizable?.onResizeEnd
244
+ onResizeStart: resizeConfig.onResizeStart,
245
+ onResizeEnd: resizeConfig.onResizeEnd
244
246
  });
245
247
 
246
248
  // =========================== Events ===========================
@@ -273,7 +275,7 @@ const DrawerPopup = (props, ref) => {
273
275
  id: id,
274
276
  containerRef: motionRef,
275
277
  prefixCls: prefixCls,
276
- className: (0, _classnames.default)(className, drawerClassNames?.section),
278
+ className: (0, _clsx.clsx)(className, drawerClassNames?.section),
277
279
  style: {
278
280
  ...style,
279
281
  ...styles?.section
@@ -283,7 +285,7 @@ const DrawerPopup = (props, ref) => {
283
285
  }), eventHandlers), children);
284
286
  return /*#__PURE__*/React.createElement("div", _extends({
285
287
  ref: wrapperRef,
286
- className: (0, _classnames.default)(`${prefixCls}-content-wrapper`, isDragging && `${prefixCls}-content-wrapper-dragging`, drawerClassNames?.wrapper, !isDragging && motionClassName),
288
+ className: (0, _clsx.clsx)(`${prefixCls}-content-wrapper`, isDragging && `${prefixCls}-content-wrapper-dragging`, drawerClassNames?.wrapper, !isDragging && motionClassName),
287
289
  style: {
288
290
  ...motionStyle,
289
291
  ...wrapperStyle,
@@ -291,7 +293,7 @@ const DrawerPopup = (props, ref) => {
291
293
  }
292
294
  }, (0, _pickAttrs.default)(props, {
293
295
  data: true
294
- })), resizable && /*#__PURE__*/React.createElement("div", dragElementProps), drawerRender ? drawerRender(content) : content);
296
+ })), isResizable && /*#__PURE__*/React.createElement("div", dragElementProps), drawerRender ? drawerRender(content) : content);
295
297
  });
296
298
 
297
299
  // >>>>> Container
@@ -304,7 +306,7 @@ const DrawerPopup = (props, ref) => {
304
306
  return /*#__PURE__*/React.createElement(_context.default.Provider, {
305
307
  value: mergedContext
306
308
  }, /*#__PURE__*/React.createElement("div", {
307
- className: (0, _classnames.default)(prefixCls, `${prefixCls}-${placement}`, rootClassName, {
309
+ className: (0, _clsx.clsx)(prefixCls, `${prefixCls}-${placement}`, rootClassName, {
308
310
  [`${prefixCls}-open`]: open,
309
311
  [`${prefixCls}-inline`]: inline
310
312
  }),
@@ -5,9 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = useDrag;
7
7
  var React = _interopRequireWildcard(require("react"));
8
- var _classnames = _interopRequireDefault(require("classnames"));
8
+ var _clsx = require("clsx");
9
9
  var _util = require("@rc-component/util");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
11
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
12
  function useDrag(options) {
@@ -91,7 +90,7 @@ function useDrag(options) {
91
90
  };
92
91
  }
93
92
  }, [isDragging, handleMouseMove, handleMouseUp]);
94
- const dragElementClassName = (0, _classnames.default)(`${prefixCls}-dragger`, `${prefixCls}-dragger-${direction}`, {
93
+ const dragElementClassName = (0, _clsx.clsx)(`${prefixCls}-dragger`, `${prefixCls}-dragger-${direction}`, {
95
94
  [`${prefixCls}-dragger-dragging`]: isDragging,
96
95
  [`${prefixCls}-dragger-horizontal`]: isHorizontal,
97
96
  [`${prefixCls}-dragger-vertical`]: !isHorizontal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rc-component/drawer",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "drawer component for react",
5
5
  "keywords": [
6
6
  "react",
@@ -46,7 +46,7 @@
46
46
  "@rc-component/motion": "^1.1.4",
47
47
  "@rc-component/portal": "^2.0.0",
48
48
  "@rc-component/util": "^1.2.1",
49
- "classnames": "^2.2.6"
49
+ "clsx": "^2.1.1"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@ant-design/icons": "^5.3.0",
@@ -54,7 +54,6 @@
54
54
  "@rc-component/np": "^1.0.0",
55
55
  "@testing-library/jest-dom": "^6.2.0",
56
56
  "@testing-library/react": "^16.3.0",
57
- "@types/classnames": "^2.2.9",
58
57
  "@types/jest": "^29.5.11",
59
58
  "@types/node": "^24.3.0",
60
59
  "@types/raf": "^3.4.0",
@@ -64,7 +63,7 @@
64
63
  "antd": "^5.12.7",
65
64
  "dumi": "^2.2.0",
66
65
  "eslint": "^8.56.0",
67
- "eslint-plugin-jest": "^27.6.0",
66
+ "eslint-plugin-jest": "^29.0.1",
68
67
  "eslint-plugin-unicorn": "^51.0.1",
69
68
  "father": "^4.0.0",
70
69
  "glob": "^10.3.10",