@rescui/button 0.17.1 → 0.18.1

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.
@@ -1,10 +1,10 @@
1
1
  var styles = {
2
- "icon": "_icon_1hf44po_4",
3
- "sizeXS": "_sizeXS_1hf44po_14",
4
- "sizeS": "_sizeS_1hf44po_18",
5
- "sizeM": "_sizeM_1hf44po_22",
6
- "sizeL": "_sizeL_1hf44po_26",
7
- "light": "_light_1hf44po_30",
8
- "dark": "_dark_1hf44po_34"
2
+ "icon": "_icon_ons1cf_4",
3
+ "sizeXS": "_sizeXS_ons1cf_14",
4
+ "sizeS": "_sizeS_ons1cf_18",
5
+ "sizeM": "_sizeM_ons1cf_22",
6
+ "sizeL": "_sizeL_ons1cf_26",
7
+ "light": "_light_ons1cf_30",
8
+ "dark": "_dark_ons1cf_34"
9
9
  };
10
10
  export { styles as default };
@@ -1,22 +1,21 @@
1
1
  import _extends from '@babel/runtime-corejs3/helpers/esm/extends';
2
- import _objectWithoutProperties from '@babel/runtime-corejs3/helpers/esm/objectWithoutProperties';
3
2
  import React from 'react';
4
3
  import PropTypes from 'prop-types';
5
4
  import cn from 'classnames';
6
5
  import styles from './index.css.js';
7
- var _excluded = ["theme", "size", "className"];
8
- var sizeStyles = {
6
+ const sizeStyles = {
9
7
  "xs": styles.sizeXS,
10
8
  "s": styles.sizeS,
11
9
  "m": styles.sizeM,
12
10
  "l": styles.sizeL
13
11
  };
14
- var LoadingIcon = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
15
- var theme = _ref.theme,
16
- size = _ref.size,
17
- className = _ref.className,
18
- props = _objectWithoutProperties(_ref, _excluded);
19
-
12
+ const LoadingIcon = /*#__PURE__*/React.forwardRef((_ref, ref) => {
13
+ let {
14
+ theme,
15
+ size,
16
+ className,
17
+ ...props
18
+ } = _ref;
20
19
  return /*#__PURE__*/React.createElement("svg", _extends({
21
20
  viewBox: "0 0 24 24"
22
21
  }, props, {
package/lib/button.js CHANGED
@@ -1,21 +1,4 @@
1
- import "core-js/modules/es.object.to-string.js";
2
- import "core-js/modules/web.dom-collections.for-each.js";
3
- import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
4
- import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
5
- import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
6
- var _excluded = ["className", "children", "href", "type", "disabled", "size", "theme", "icon", "iconPosition", "busy", "allowMultiline", "defaultMultiline", "flat", "notFocusable", "highlighted", "shifted", "mode"];
7
-
8
- function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
9
-
10
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? Object.defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
11
-
12
1
  import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
13
- import _flatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/flat";
14
- import _Object$keys from "@babel/runtime-corejs3/core-js-stable/object/keys";
15
- import _Object$getOwnPropertySymbols from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols";
16
- import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
17
- import _Object$getOwnPropertyDescriptor from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor";
18
- import _Object$getOwnPropertyDescriptors from "@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors";
19
2
  import React, { useState, useRef, cloneElement } from 'react';
20
3
  import cn from 'classnames';
21
4
  import PropTypes from 'prop-types';
@@ -24,61 +7,52 @@ import { useResizeObserver } from '@rescui/use-resize-observer';
24
7
  import LoadingIcon from './_virtual/loading.js';
25
8
  import styles from './button.p.module.css.js';
26
9
 
27
- var calculateShifted = function calculateShifted(shiftedProp, side) {
28
- return shiftedProp === 'all' || shiftedProp === side || Array.isArray(shiftedProp) && _includesInstanceProperty(shiftedProp).call(shiftedProp, side);
29
- };
10
+ const calculateShifted = (shiftedProp, side) => shiftedProp === 'all' || shiftedProp === side || Array.isArray(shiftedProp) && _includesInstanceProperty(shiftedProp).call(shiftedProp, side);
30
11
 
31
- var MODE_STYLES = {
12
+ const MODE_STYLES = {
32
13
  classic: styles.modeClassic,
33
14
  rock: styles.modeRock,
34
15
  transparent: styles.modeTransparent,
35
16
  outline: styles.modeOutline,
36
17
  clear: styles.modeClear
37
18
  };
38
- var SIZE_STYLES = {
19
+ const SIZE_STYLES = {
39
20
  xs: styles.sizeXs,
40
21
  s: styles.sizeS,
41
22
  m: styles.sizeM,
42
23
  l: styles.sizeL
43
24
  };
44
- var Button = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line complexity
45
- function (_ref, forwardedRef) {
46
- var _cn;
47
-
48
- var className = _ref.className,
49
- children = _ref.children,
50
- href = _ref.href,
51
- _ref$type = _ref.type,
52
- type = _ref$type === void 0 ? 'button' : _ref$type,
53
- disabled = _ref.disabled,
54
- _ref$size = _ref.size,
55
- size = _ref$size === void 0 ? 'm' : _ref$size,
56
- themeFromProps = _ref.theme,
57
- icon = _ref.icon,
58
- _ref$iconPosition = _ref.iconPosition,
59
- iconPosition = _ref$iconPosition === void 0 ? 'left' : _ref$iconPosition,
60
- _ref$busy = _ref.busy,
61
- busy = _ref$busy === void 0 ? false : _ref$busy,
62
- _ref$allowMultiline = _ref.allowMultiline,
63
- allowMultiline = _ref$allowMultiline === void 0 ? false : _ref$allowMultiline,
64
- _ref$defaultMultiline = _ref.defaultMultiline,
65
- defaultMultiline = _ref$defaultMultiline === void 0 ? false : _ref$defaultMultiline,
66
- flat = _flatInstanceProperty(_ref),
67
- notFocusable = _ref.notFocusable,
68
- highlighted = _ref.highlighted,
69
- shifted = _ref.shifted,
70
- _ref$mode = _ref.mode,
71
- mode = _ref$mode === void 0 ? 'classic' : _ref$mode,
72
- restProps = _objectWithoutProperties(_ref, _excluded);
73
-
74
- var _useState = useState(defaultMultiline),
75
- _useState2 = _slicedToArray(_useState, 2),
76
- multiline = _useState2[0],
77
- setMultiline = _useState2[1];
78
-
79
- var ref = useRef(null);
80
-
81
- var handleRef = function handleRef(el) {
25
+ const Button = /*#__PURE__*/React.forwardRef( // eslint-disable-next-line complexity
26
+ (_ref, forwardedRef) => {
27
+ let {
28
+ className,
29
+ children,
30
+ href,
31
+ type = 'button',
32
+ disabled,
33
+ size = 'm',
34
+ theme: themeFromProps,
35
+ icon,
36
+ iconPosition = 'left',
37
+ busy = false,
38
+ allowMultiline = false,
39
+ defaultMultiline = false,
40
+ flat,
41
+ notFocusable,
42
+ highlighted
43
+ /* supported only for clear mode */
44
+ ,
45
+ shifted
46
+ /* supported only for clear mode */
47
+ ,
48
+ mode = 'classic',
49
+ ...restProps
50
+ } = _ref;
51
+ const [multiline, setMultiline] = useState(defaultMultiline);
52
+ const contentRef = useRef(null);
53
+ const ref = useRef(null);
54
+
55
+ const handleRef = el => {
82
56
  ref.current = el;
83
57
 
84
58
  if (forwardedRef) {
@@ -90,21 +64,23 @@ function (_ref, forwardedRef) {
90
64
  }
91
65
  };
92
66
 
93
- useResizeObserver(ref, function (entry) {
94
- var target = entry.target;
95
- var height = entry.contentRect.height;
96
- var targetStyles = getComputedStyle(target);
97
- var singleLineBlockSize = parseInt(targetStyles.lineHeight, 10);
67
+ useResizeObserver(contentRef, entry => {
68
+ const target = entry.target;
69
+ const {
70
+ height
71
+ } = entry.contentRect;
72
+ const targetStyles = getComputedStyle(target);
73
+ const singleLineBlockSize = parseInt(targetStyles.lineHeight, 10);
98
74
  setMultiline(height > singleLineBlockSize);
99
75
  });
100
- var theme = useThemeWithUndefined(themeFromProps);
101
- var shiftedLeft = calculateShifted(shifted, 'left');
102
- var shiftedRight = calculateShifted(shifted, 'right');
103
- var shiftedTop = calculateShifted(shifted, 'top');
104
- var shiftedBottom = calculateShifted(shifted, 'bottom'); // check for ignored jsx values and empty string, more info https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored
76
+ const theme = useThemeWithUndefined(themeFromProps);
77
+ const shiftedLeft = calculateShifted(shifted, 'left');
78
+ const shiftedRight = calculateShifted(shifted, 'right');
79
+ const shiftedTop = calculateShifted(shifted, 'top');
80
+ const shiftedBottom = calculateShifted(shifted, 'bottom'); // check for ignored jsx values and empty string, more info https://reactjs.org/docs/jsx-in-depth.html#booleans-null-and-undefined-are-ignored
105
81
 
106
- var isWithoutText = children === null || typeof children === 'undefined' || children === false || children === true || children === '';
107
- var iconSlot;
82
+ const isWithoutText = children === null || typeof children === 'undefined' || children === false || children === true || children === '';
83
+ let iconSlot;
108
84
 
109
85
  if ( /*#__PURE__*/React.isValidElement(icon) && busy) {
110
86
  iconSlot = /*#__PURE__*/React.createElement(LoadingIcon, {
@@ -116,17 +92,36 @@ function (_ref, forwardedRef) {
116
92
  });
117
93
  }
118
94
 
119
- var showBusyOverlay = ! /*#__PURE__*/React.isValidElement(icon) && busy;
120
- var buttonSharedProps = {
121
- href: href,
122
- disabled: disabled,
123
- className: cn(styles.main, MODE_STYLES[mode], SIZE_STYLES[size], iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft, styles[theme], (_cn = {}, _defineProperty(_cn, styles.disabled, disabled), _defineProperty(_cn, styles.flatLeft, flat === 'left'), _defineProperty(_cn, styles.flatRight, flat === 'right'), _defineProperty(_cn, styles.highlighted, highlighted), _defineProperty(_cn, styles.withIcon, !!icon), _defineProperty(_cn, styles.withoutText, isWithoutText), _defineProperty(_cn, styles.shiftedLeft, shiftedLeft), _defineProperty(_cn, styles.shiftedRight, shiftedRight), _defineProperty(_cn, styles.shiftedTop, shiftedTop), _defineProperty(_cn, styles.shiftedBottom, shiftedBottom), _defineProperty(_cn, styles.multiline, multiline), _defineProperty(_cn, styles.allowMultiline, allowMultiline), _defineProperty(_cn, styles.busy, busy), _defineProperty(_cn, styles.busyOverlay, showBusyOverlay), _cn), className)
95
+ const showBusyOverlay = ! /*#__PURE__*/React.isValidElement(icon) && busy;
96
+ const buttonSharedProps = {
97
+ href,
98
+ disabled,
99
+ className: cn(styles.main, MODE_STYLES[mode], SIZE_STYLES[size], iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft, styles[theme], {
100
+ [styles.disabled]: disabled,
101
+ [styles.flatLeft]: flat === 'left',
102
+ [styles.flatRight]: flat === 'right',
103
+ [styles.highlighted]: highlighted,
104
+ [styles.withoutText]: isWithoutText,
105
+ [styles.shiftedLeft]: shiftedLeft,
106
+ [styles.shiftedRight]: shiftedRight,
107
+ [styles.shiftedTop]: shiftedTop,
108
+ [styles.shiftedBottom]: shiftedBottom,
109
+ [styles.multiline]: multiline,
110
+ [styles.allowMultiline]: allowMultiline,
111
+ [styles.busy]: busy,
112
+ [styles.busyOverlay]: showBusyOverlay
113
+ }, className)
124
114
  }; // Google Translate replaces TextNodes on page which is leading to a React error on manipulating buttonChildren e.g. when switching to the busy state.
125
115
  // To prevent this we wrap text node in a span element which itself will not be replaced by Google Translate.
126
116
  // More info here: https://github.com/facebook/react/issues/11538
127
117
 
128
- var buttonContent = !isWithoutText && typeof children === 'string' ? /*#__PURE__*/React.createElement("span", null, children) : children;
129
- var buttonChildren = /*#__PURE__*/React.createElement(React.Fragment, null, iconSlot, showBusyOverlay && /*#__PURE__*/React.createElement(LoadingIcon, {
118
+ const buttonContent = !isWithoutText && /*#__PURE__*/React.createElement("span", {
119
+ className: styles.content,
120
+ "data-rs-internal": "button__content",
121
+ "data-test": "button__content",
122
+ ref: contentRef
123
+ }, children);
124
+ const buttonChildren = /*#__PURE__*/React.createElement(React.Fragment, null, iconSlot, showBusyOverlay && /*#__PURE__*/React.createElement(LoadingIcon, {
130
125
  className: styles.busyIcon,
131
126
  size: size,
132
127
  "data-test": "busy-icon"
@@ -139,41 +134,46 @@ function (_ref, forwardedRef) {
139
134
  /** use <div> tag for preventing button controls elements behavior for example 'space' button press support. */
140
135
 
141
136
 
142
- return /*#__PURE__*/React.createElement("div", _objectSpread(_objectSpread({
143
- "data-test": 'button'
144
- }, restProps), {}, {
145
- ref: handleRef
146
- }, buttonSharedProps), buttonChildren);
137
+ return /*#__PURE__*/React.createElement("div", {
138
+ "data-test": 'button',
139
+ ...restProps,
140
+ ref: handleRef,
141
+ ...buttonSharedProps
142
+ }, buttonChildren);
147
143
  } else if (href) {
148
- return /*#__PURE__*/React.createElement("a", _objectSpread(_objectSpread({
149
- "data-test": 'button'
150
- }, restProps), {}, {
144
+ return /*#__PURE__*/React.createElement("a", {
145
+ "data-test": 'button',
146
+ ...restProps,
151
147
  ref: handleRef,
152
- type: type
153
- }, buttonSharedProps), buttonChildren);
148
+ type: type,
149
+ ...buttonSharedProps
150
+ }, buttonChildren);
154
151
  } else {
155
- return /*#__PURE__*/React.createElement("button", _objectSpread(_objectSpread({
156
- "data-test": 'button'
157
- }, restProps), {}, {
152
+ return /*#__PURE__*/React.createElement("button", {
153
+ "data-test": 'button',
154
+ ...restProps,
158
155
  ref: handleRef,
159
156
 
160
157
  /* eslint-disable-next-line react/button-has-type */
161
- type: type
162
- }, buttonSharedProps), buttonChildren);
158
+ type: type,
159
+ ...buttonSharedProps
160
+ }, buttonChildren);
163
161
  }
164
162
  });
165
163
  Button.displayName = 'Button';
166
164
 
167
165
  function validateAdditional(propType, callback) {
168
- return function (props, propName) {
166
+ return (props, propName) => {
169
167
  if (typeof props[propName] !== 'undefined') {
170
- var cbRes = callback(props, propName);
168
+ const cbRes = callback(props, propName);
171
169
 
172
170
  if (cbRes) {
173
171
  return cbRes;
174
172
  }
175
173
 
176
- PropTypes.checkPropTypes(_defineProperty({}, propName, propType), props, 'prop', 'Button');
174
+ PropTypes.checkPropTypes({
175
+ [propName]: propType
176
+ }, props, 'prop', 'Button');
177
177
  }
178
178
 
179
179
  return null;
@@ -184,9 +184,9 @@ Button.propTypes = {
184
184
  className: PropTypes.string,
185
185
  children: PropTypes.node,
186
186
  disabled: PropTypes.bool,
187
- href: validateAdditional(PropTypes.string, function (props) {
187
+ href: validateAdditional(PropTypes.string, props => {
188
188
  if (typeof props.notFocusable !== 'undefined') {
189
- return new Error("'href' prop cannot be used with 'notFocusable' prop");
189
+ return new Error(`'href' prop cannot be used with 'notFocusable' prop`);
190
190
  }
191
191
 
192
192
  return null;
@@ -194,9 +194,9 @@ Button.propTypes = {
194
194
  icon: PropTypes.node,
195
195
  iconPosition: PropTypes.oneOf(['left', 'right']),
196
196
  size: PropTypes.oneOf(['l', 'm', 's', 'xs']),
197
- mode: validateAdditional(PropTypes.oneOf(['classic', 'rock', 'transparent', 'outline', 'clear']), function (props) {
197
+ mode: validateAdditional(PropTypes.oneOf(['classic', 'rock', 'transparent', 'outline', 'clear']), props => {
198
198
  if (typeof props.shifted !== 'undefined' && props.mode !== 'clear') {
199
- return new Error("'shifted' prop cannot be used when 'mode' prop is not 'clear'.");
199
+ return new Error(`'shifted' prop cannot be used when 'mode' prop is not 'clear'.`);
200
200
  }
201
201
 
202
202
  return null;
@@ -204,9 +204,9 @@ Button.propTypes = {
204
204
  theme: PropTypes.oneOf(['light', 'dark']),
205
205
  type: PropTypes.oneOf(['button', 'submit', 'reset']),
206
206
  onClick: PropTypes.func,
207
- notFocusable: validateAdditional(PropTypes.bool, function (props) {
207
+ notFocusable: validateAdditional(PropTypes.bool, props => {
208
208
  if (typeof props.href !== 'undefined' || typeof props.target !== 'undefined') {
209
- return new Error("'notFocusable' prop cannot be used with 'href' and 'target' props");
209
+ return new Error(`'notFocusable' prop cannot be used with 'href' and 'target' props`);
210
210
  }
211
211
 
212
212
  return null;
@@ -1,32 +1,32 @@
1
1
  var styles = {
2
- "light": "_light_14w89nx_6",
3
- "dark": "_dark_14w89nx_9",
4
- "flatRight": "_flatRight_14w89nx_13",
5
- "flatLeft": "_flatLeft_14w89nx_16",
6
- "sizeXs": "_sizeXs_14w89nx_20",
7
- "sizeS": "_sizeS_14w89nx_23",
8
- "sizeM": "_sizeM_14w89nx_26",
9
- "sizeL": "_sizeL_14w89nx_29",
10
- "modeClassic": "_modeClassic_14w89nx_33",
11
- "modeRock": "_modeRock_14w89nx_36",
12
- "modeTransparent": "_modeTransparent_14w89nx_39",
13
- "modeOutline": "_modeOutline_14w89nx_42",
14
- "modeClear": "_modeClear_14w89nx_45",
15
- "alignIconLeft": "_alignIconLeft_14w89nx_49",
16
- "alignIconRight": "_alignIconRight_14w89nx_52",
17
- "main": "_main_14w89nx_56",
18
- "disabled": "_disabled_14w89nx_122",
19
- "busy": "_busy_14w89nx_132",
20
- "busyOverlay": "_busyOverlay_14w89nx_136",
21
- "allowMultiline": "_allowMultiline_14w89nx_176",
22
- "multiline": "_multiline_14w89nx_180",
23
- "withoutText": "_withoutText_14w89nx_184",
24
- "withIcon": "_withIcon_14w89nx_192",
25
- "icon": "_icon_14w89nx_198",
26
- "busyIcon": "_busyIcon_14w89nx_212",
27
- "shiftedLeft": "_shiftedLeft_14w89nx_229",
28
- "shiftedRight": "_shiftedRight_14w89nx_232",
29
- "shiftedTop": "_shiftedTop_14w89nx_235",
30
- "shiftedBottom": "_shiftedBottom_14w89nx_238"
2
+ "light": "_light_c0yiq4_6",
3
+ "dark": "_dark_c0yiq4_9",
4
+ "flatRight": "_flatRight_c0yiq4_13",
5
+ "flatLeft": "_flatLeft_c0yiq4_16",
6
+ "sizeXs": "_sizeXs_c0yiq4_20",
7
+ "sizeS": "_sizeS_c0yiq4_23",
8
+ "sizeM": "_sizeM_c0yiq4_26",
9
+ "sizeL": "_sizeL_c0yiq4_29",
10
+ "modeClassic": "_modeClassic_c0yiq4_33",
11
+ "modeRock": "_modeRock_c0yiq4_36",
12
+ "modeTransparent": "_modeTransparent_c0yiq4_39",
13
+ "modeOutline": "_modeOutline_c0yiq4_42",
14
+ "modeClear": "_modeClear_c0yiq4_45",
15
+ "alignIconLeft": "_alignIconLeft_c0yiq4_49",
16
+ "alignIconRight": "_alignIconRight_c0yiq4_52",
17
+ "main": "_main_c0yiq4_56",
18
+ "disabled": "_disabled_c0yiq4_133",
19
+ "busy": "_busy_c0yiq4_143",
20
+ "busyOverlay": "_busyOverlay_c0yiq4_147",
21
+ "icon": "_icon_c0yiq4_182",
22
+ "allowMultiline": "_allowMultiline_c0yiq4_195",
23
+ "multiline": "_multiline_c0yiq4_199",
24
+ "withoutText": "_withoutText_c0yiq4_203",
25
+ "busyIcon": "_busyIcon_c0yiq4_208",
26
+ "content": "_content_c0yiq4_224",
27
+ "shiftedLeft": "_shiftedLeft_c0yiq4_229",
28
+ "shiftedRight": "_shiftedRight_c0yiq4_232",
29
+ "shiftedTop": "_shiftedTop_c0yiq4_235",
30
+ "shiftedBottom": "_shiftedBottom_c0yiq4_238"
31
31
  };
32
32
  export { styles as default };