rsuite 5.26.1 → 5.27.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.
Files changed (42) hide show
  1. package/Button/styles/index.less +12 -1
  2. package/CHANGELOG.md +11 -0
  3. package/cjs/Button/Button.d.ts +4 -0
  4. package/cjs/Button/Button.js +18 -9
  5. package/cjs/Message/Message.d.ts +4 -0
  6. package/cjs/Message/Message.js +8 -2
  7. package/cjs/Notification/Notification.d.ts +3 -0
  8. package/cjs/Notification/Notification.js +8 -2
  9. package/cjs/Schema/Schema.d.ts +2 -1
  10. package/cjs/Schema/Schema.js +2 -1
  11. package/cjs/toaster/ToastContainer.d.ts +6 -1
  12. package/cjs/toaster/ToastContainer.js +12 -5
  13. package/cjs/toaster/ToastContext.d.ts +6 -0
  14. package/cjs/toaster/ToastContext.js +16 -0
  15. package/cjs/toaster/toaster.js +7 -5
  16. package/cjs/toaster/useToaster.js +1 -1
  17. package/dist/rsuite-rtl.css +38 -5
  18. package/dist/rsuite-rtl.min.css +1 -1
  19. package/dist/rsuite-rtl.min.css.map +1 -1
  20. package/dist/rsuite.css +38 -5
  21. package/dist/rsuite.js +18 -7
  22. package/dist/rsuite.js.map +1 -1
  23. package/dist/rsuite.min.css +1 -1
  24. package/dist/rsuite.min.css.map +1 -1
  25. package/dist/rsuite.min.js +1 -1
  26. package/dist/rsuite.min.js.map +1 -1
  27. package/esm/Button/Button.d.ts +4 -0
  28. package/esm/Button/Button.js +18 -9
  29. package/esm/Message/Message.d.ts +4 -0
  30. package/esm/Message/Message.js +8 -3
  31. package/esm/Notification/Notification.d.ts +3 -0
  32. package/esm/Notification/Notification.js +8 -3
  33. package/esm/Schema/Schema.d.ts +2 -1
  34. package/esm/Schema/Schema.js +3 -2
  35. package/esm/toaster/ToastContainer.d.ts +6 -1
  36. package/esm/toaster/ToastContainer.js +11 -5
  37. package/esm/toaster/ToastContext.d.ts +6 -0
  38. package/esm/toaster/ToastContext.js +6 -0
  39. package/esm/toaster/toaster.js +7 -5
  40. package/esm/toaster/useToaster.js +1 -1
  41. package/package.json +1 -1
  42. package/styles/variables.less +3 -0
@@ -21,6 +21,10 @@ export interface ButtonProps extends WithAsProps, React.HTMLAttributes<HTMLEleme
21
21
  disabled?: boolean;
22
22
  /** Ripple after button click */
23
23
  ripple?: boolean;
24
+ /** The icon element placed _before_ the button text */
25
+ startIcon?: React.ReactNode;
26
+ /** The icon element placed _after_ the button text */
27
+ endIcon?: React.ReactNode;
24
28
  /** Defines HTML button type attribute */
25
29
  type?: 'button' | 'reset' | 'submit';
26
30
  }
@@ -2,9 +2,9 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _taggedTemplateLiteralLoose from "@babel/runtime/helpers/esm/taggedTemplateLiteralLoose";
3
3
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
4
4
 
5
- var _templateObject;
5
+ var _templateObject, _templateObject2, _templateObject3;
6
6
 
7
- import React, { useContext } from 'react';
7
+ import React, { useCallback, useContext } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { ButtonGroupContext } from '../ButtonGroup';
10
10
  import SafeAnchor from '../SafeAnchor';
@@ -26,8 +26,10 @@ var Button = /*#__PURE__*/React.forwardRef(function (props, ref) {
26
26
  _props$ripple = props.ripple,
27
27
  ripple = _props$ripple === void 0 ? true : _props$ripple,
28
28
  sizeProp = props.size,
29
+ startIcon = props.startIcon,
30
+ endIcon = props.endIcon,
29
31
  typeProp = props.type,
30
- rest = _objectWithoutPropertiesLoose(props, ["as", "active", "appearance", "block", "className", "children", "classPrefix", "color", "disabled", "loading", "ripple", "size", "type"]);
32
+ rest = _objectWithoutPropertiesLoose(props, ["as", "active", "appearance", "block", "className", "children", "classPrefix", "color", "disabled", "loading", "ripple", "size", "startIcon", "endIcon", "type"]);
31
33
 
32
34
  var buttonGroup = useContext(ButtonGroupContext);
33
35
  var size = sizeProp !== null && sizeProp !== void 0 ? sizeProp : buttonGroup === null || buttonGroup === void 0 ? void 0 : buttonGroup.size;
@@ -43,10 +45,17 @@ var Button = /*#__PURE__*/React.forwardRef(function (props, ref) {
43
45
  loading: loading,
44
46
  block: block
45
47
  }));
46
- var rippleElement = ripple && !isOneOf(appearance, ['link', 'ghost']) ? /*#__PURE__*/React.createElement(Ripple, null) : null;
47
- var spin = /*#__PURE__*/React.createElement("span", {
48
- className: prefix(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["spin"])))
49
- });
48
+ var renderButtonContent = useCallback(function () {
49
+ var spin = /*#__PURE__*/React.createElement("span", {
50
+ className: prefix(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["spin"])))
51
+ });
52
+ var rippleElement = ripple && !isOneOf(appearance, ['link', 'ghost']) ? /*#__PURE__*/React.createElement(Ripple, null) : null;
53
+ return /*#__PURE__*/React.createElement(React.Fragment, null, loading && spin, startIcon ? /*#__PURE__*/React.createElement("span", {
54
+ className: prefix(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["start-icon"])))
55
+ }, startIcon) : null, children, endIcon ? /*#__PURE__*/React.createElement("span", {
56
+ className: prefix(_templateObject3 || (_templateObject3 = _taggedTemplateLiteralLoose(["end-icon"])))
57
+ }, endIcon) : null, rippleElement);
58
+ }, [appearance, children, endIcon, loading, prefix, ripple, startIcon]);
50
59
 
51
60
  if (rest.href) {
52
61
  return /*#__PURE__*/React.createElement(SafeAnchor, _extends({}, rest, {
@@ -55,7 +64,7 @@ var Button = /*#__PURE__*/React.forwardRef(function (props, ref) {
55
64
  "aria-disabled": disabled,
56
65
  disabled: disabled,
57
66
  className: classes
58
- }), loading && spin, children, rippleElement);
67
+ }), renderButtonContent());
59
68
  }
60
69
 
61
70
  var Component = as || 'button';
@@ -68,7 +77,7 @@ var Button = /*#__PURE__*/React.forwardRef(function (props, ref) {
68
77
  disabled: disabled,
69
78
  "aria-disabled": disabled,
70
79
  className: classes
71
- }), loading && spin, children, rippleElement);
80
+ }), renderButtonContent());
72
81
  });
73
82
  Button.displayName = 'Button';
74
83
  Button.propTypes = {
@@ -9,6 +9,10 @@ export interface MessageProps extends WithAsProps {
9
9
  * Delay automatic removal of messages.
10
10
  * When set to 0, the message is not automatically removed.
11
11
  * (Unit: milliseconds)
12
+ *
13
+ * @default 2000
14
+ * @deprecated Use `toaster.push(<Message />, { duration: 2000 })` instead.
15
+ *
12
16
  */
13
17
  duration?: number;
14
18
  /** The title of the message */
@@ -4,10 +4,11 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
4
4
 
5
5
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
6
6
 
7
- import React, { useState, useCallback } from 'react';
7
+ import React, { useState, useCallback, useContext } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { useClassNames, useTimeout, MESSAGE_STATUS_ICONS, STATUS, useIsMounted } from '../utils';
10
10
  import CloseButton from '../CloseButton';
11
+ import ToastContext from '../toaster/ToastContext';
11
12
  var Message = /*#__PURE__*/React.forwardRef(function (props, ref) {
12
13
  var _withClassPrefix;
13
14
 
@@ -37,9 +38,13 @@ var Message = /*#__PURE__*/React.forwardRef(function (props, ref) {
37
38
  merge = _useClassNames.merge,
38
39
  prefix = _useClassNames.prefix;
39
40
 
40
- var isMounted = useIsMounted(); // Timed close message
41
+ var isMounted = useIsMounted();
41
42
 
42
- var _useTimeout = useTimeout(onClose, duration, duration > 0),
43
+ var _useContext = useContext(ToastContext),
44
+ usedToaster = _useContext.usedToaster; // Timed close message
45
+
46
+
47
+ var _useTimeout = useTimeout(onClose, duration, usedToaster && duration > 0),
43
48
  clear = _useTimeout.clear;
44
49
 
45
50
  var handleClose = useCallback(function (event) {
@@ -8,6 +8,9 @@ export interface NotificationProps extends WithAsProps {
8
8
  * Delay automatic removal of messages.
9
9
  * When set to 0, the message is not automatically removed.
10
10
  * (Unit: milliseconds)
11
+ *
12
+ * @default 4500
13
+ * @deprecated Use `toaster.push(<Notification />, { duration: 4500 })` instead.
11
14
  */
12
15
  duration?: number;
13
16
  /**
@@ -4,10 +4,11 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
4
4
 
5
5
  var _templateObject, _templateObject2;
6
6
 
7
- import React, { useCallback, useState } from 'react';
7
+ import React, { useCallback, useState, useContext } from 'react';
8
8
  import PropTypes from 'prop-types';
9
9
  import { useClassNames, useTimeout, MESSAGE_STATUS_ICONS, useIsMounted } from '../utils';
10
10
  import CloseButton from '../CloseButton';
11
+ import ToastContext from '../toaster/ToastContext';
11
12
  var Notification = /*#__PURE__*/React.forwardRef(function (props, ref) {
12
13
  var _props$as = props.as,
13
14
  Component = _props$as === void 0 ? 'div' : _props$as,
@@ -32,9 +33,13 @@ var Notification = /*#__PURE__*/React.forwardRef(function (props, ref) {
32
33
  merge = _useClassNames.merge,
33
34
  prefix = _useClassNames.prefix;
34
35
 
35
- var isMounted = useIsMounted(); // Timed close message
36
+ var isMounted = useIsMounted();
36
37
 
37
- var _useTimeout = useTimeout(onClose, duration, duration > 0),
38
+ var _useContext = useContext(ToastContext),
39
+ usedToaster = _useContext.usedToaster; // Timed close message
40
+
41
+
42
+ var _useTimeout = useTimeout(onClose, duration, usedToaster && duration > 0),
38
43
  clear = _useTimeout.clear; // Click to trigger to close the message
39
44
 
40
45
 
@@ -1,4 +1,4 @@
1
- import { SchemaModel, StringType, NumberType, ArrayType, DateType, ObjectType, BooleanType } from 'schema-typed';
1
+ import { SchemaModel, StringType, NumberType, ArrayType, DateType, ObjectType, BooleanType, MixedType } from 'schema-typed';
2
2
  declare const SchemaTyped: {
3
3
  Model: typeof SchemaModel;
4
4
  Types: {
@@ -8,6 +8,7 @@ declare const SchemaTyped: {
8
8
  DateType: typeof DateType;
9
9
  ObjectType: typeof ObjectType;
10
10
  BooleanType: typeof BooleanType;
11
+ MixedType: typeof MixedType;
11
12
  };
12
13
  };
13
14
  export default SchemaTyped;
@@ -1,4 +1,4 @@
1
- import { SchemaModel, StringType, NumberType, ArrayType, DateType, ObjectType, BooleanType } from 'schema-typed';
1
+ import { SchemaModel, StringType, NumberType, ArrayType, DateType, ObjectType, BooleanType, MixedType } from 'schema-typed';
2
2
  var SchemaTyped = {
3
3
  Model: SchemaModel,
4
4
  Types: {
@@ -7,7 +7,8 @@ var SchemaTyped = {
7
7
  ArrayType: ArrayType,
8
8
  DateType: DateType,
9
9
  ObjectType: ObjectType,
10
- BooleanType: BooleanType
10
+ BooleanType: BooleanType,
11
+ MixedType: MixedType
11
12
  }
12
13
  };
13
14
  export default SchemaTyped;
@@ -7,11 +7,16 @@ export interface ToastContainerProps extends WithAsProps {
7
7
  placement?: PlacementType;
8
8
  /** Set the message to appear in the specified container */
9
9
  container?: HTMLElement | (() => HTMLElement);
10
+ /** The number of milliseconds to wait before automatically closing a message. */
11
+ duration?: number;
10
12
  callback?: (ref: React.RefObject<ToastContainerInstance>) => void;
11
13
  }
14
+ interface PushOptions {
15
+ duration?: number;
16
+ }
12
17
  export interface ToastContainerInstance {
13
18
  root: HTMLElement;
14
- push: (message: React.ReactNode) => string;
19
+ push: (message: React.ReactNode, options?: PushOptions) => string;
15
20
  remove: (key: string) => void;
16
21
  clear: () => void;
17
22
  destroy: () => void;
@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
5
5
  import kebabCase from 'lodash/kebabCase';
6
6
  import Transition from '../Animation/Transition';
7
7
  import { useClassNames, guid, createChainedFunction, render } from '../utils';
8
+ import ToastContext from './ToastContext';
8
9
  export var toastPlacements = ['topCenter', 'bottomCenter', 'topStart', 'topEnd', 'bottomStart', 'bottomEnd'];
9
10
 
10
11
  var useMessages = function useMessages() {
@@ -19,14 +20,14 @@ var useMessages = function useMessages() {
19
20
 
20
21
  return key;
21
22
  }, [messages]);
22
- var push = useCallback(function (message) {
23
+ var push = useCallback(function (message, options) {
23
24
  var key = guid();
24
25
  setMessages(function (prevMessages) {
25
- return [].concat(prevMessages, [{
26
+ return [].concat(prevMessages, [_extends({
26
27
  key: key,
27
28
  visible: true,
28
29
  node: message
29
- }]);
30
+ }, options)]);
30
31
  });
31
32
  return key;
32
33
  }, []);
@@ -118,6 +119,7 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
118
119
 
119
120
  return /*#__PURE__*/React.cloneElement(item.node, _extends({}, rest, {
120
121
  ref: ref,
122
+ duration: item.duration,
121
123
  // Remove the message after the specified time.
122
124
  onClose: createChainedFunction((_item$node = item.node) === null || _item$node === void 0 ? void 0 : (_item$node$props = _item$node.props) === null || _item$node$props === void 0 ? void 0 : _item$node$props.onClose, function () {
123
125
  return remove(item.key);
@@ -126,13 +128,17 @@ var ToastContainer = /*#__PURE__*/React.forwardRef(function (props, ref) {
126
128
  }));
127
129
  });
128
130
  });
129
- return /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
131
+ return /*#__PURE__*/React.createElement(ToastContext.Provider, {
132
+ value: {
133
+ usedToaster: true
134
+ }
135
+ }, /*#__PURE__*/React.createElement(Component, _extends({}, rest, {
130
136
  ref: function ref(selfRef) {
131
137
  rootRef.current = selfRef;
132
138
  callback === null || callback === void 0 ? void 0 : callback(selfRef);
133
139
  },
134
140
  className: classes
135
- }), elements);
141
+ }), elements));
136
142
  });
137
143
 
138
144
  ToastContainer.getInstance = function (props) {
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export interface ToastContextProps {
3
+ usedToaster?: boolean;
4
+ }
5
+ declare const ToastContext: React.Context<ToastContextProps>;
6
+ export default ToastContext;
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ var ToastContext = /*#__PURE__*/React.createContext({
3
+ usedToaster: false
4
+ });
5
+ ToastContext.displayName = 'ToastContext';
6
+ export default ToastContext;
@@ -1,3 +1,4 @@
1
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
1
2
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
3
4
  import ToastContainer from './ToastContainer';
@@ -58,23 +59,24 @@ var toaster = function toaster(message) {
58
59
  };
59
60
 
60
61
  toaster.push = function (message, options) {
61
- var _options;
62
-
63
62
  if (options === void 0) {
64
63
  options = {};
65
64
  }
66
65
 
67
- var containerId = (_options = options) === null || _options === void 0 ? void 0 : _options.placement;
66
+ var _options = options,
67
+ containerId = _options.placement,
68
+ restOptions = _objectWithoutPropertiesLoose(_options, ["placement"]);
69
+
68
70
  var container = getContainer(containerId);
69
71
 
70
72
  if (container !== null && container !== void 0 && container.current) {
71
- return container.current.push(message);
73
+ return container.current.push(message, restOptions);
72
74
  }
73
75
 
74
76
  return createContainer(containerId !== null && containerId !== void 0 ? containerId : '', options).then(function (ref) {
75
77
  var _ref$current;
76
78
 
77
- return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.push(message);
79
+ return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.push(message, restOptions);
78
80
  });
79
81
  };
80
82
 
@@ -14,7 +14,7 @@ var useToaster = function useToaster() {
14
14
  var _toasters$current;
15
15
 
16
16
  var customToaster = toasters === null || toasters === void 0 ? void 0 : (_toasters$current = toasters.current) === null || _toasters$current === void 0 ? void 0 : _toasters$current.get((options === null || options === void 0 ? void 0 : options.placement) || 'topCenter');
17
- return customToaster ? customToaster.push(message) : toaster.push(message, options);
17
+ return customToaster ? customToaster.push(message, options) : toaster.push(message, options);
18
18
  },
19
19
  remove: function remove(key) {
20
20
  toasters ? Array.from(toasters.current).forEach(function (_ref) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rsuite",
3
- "version": "5.26.1",
3
+ "version": "5.27.0",
4
4
  "description": "A suite of react components",
5
5
  "main": "cjs/index.js",
6
6
  "module": "esm/index.js",
@@ -247,6 +247,9 @@
247
247
  // Ghost Button
248
248
  @btn-ghost-border-width: 1px;
249
249
 
250
+ // Button with icons (not IconButton)
251
+ @btn-icon-gap: 5px;
252
+
250
253
  // Button Loading
251
254
  @btn-loading-spin-default-diameter: 18px;
252
255
  @btn-loading-spin-xs-diameter: 16px;