@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.
- package/lib/_virtual/index.css.js +7 -7
- package/lib/_virtual/loading.js +8 -9
- package/lib/button.js +103 -103
- package/lib/button.p.module.css.js +29 -29
- package/lib/index.css +205 -250
- package/lib/index.js +1 -1
- package/lib/public-api.p.css +54 -54
- package/lib/public-api.pcss +54 -54
- package/package.json +9 -10
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"icon": "
|
|
3
|
-
"sizeXS": "
|
|
4
|
-
"sizeS": "
|
|
5
|
-
"sizeM": "
|
|
6
|
-
"sizeL": "
|
|
7
|
-
"light": "
|
|
8
|
-
"dark": "
|
|
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 };
|
package/lib/_virtual/loading.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
107
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
href
|
|
122
|
-
disabled
|
|
123
|
-
className: cn(styles.main, MODE_STYLES[mode], SIZE_STYLES[size], iconPosition === 'right' ? styles.alignIconRight : styles.alignIconLeft, styles[theme],
|
|
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
|
-
|
|
129
|
-
|
|
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",
|
|
143
|
-
"data-test": 'button'
|
|
144
|
-
|
|
145
|
-
ref: handleRef
|
|
146
|
-
|
|
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",
|
|
149
|
-
"data-test": 'button'
|
|
150
|
-
|
|
144
|
+
return /*#__PURE__*/React.createElement("a", {
|
|
145
|
+
"data-test": 'button',
|
|
146
|
+
...restProps,
|
|
151
147
|
ref: handleRef,
|
|
152
|
-
type: type
|
|
153
|
-
|
|
148
|
+
type: type,
|
|
149
|
+
...buttonSharedProps
|
|
150
|
+
}, buttonChildren);
|
|
154
151
|
} else {
|
|
155
|
-
return /*#__PURE__*/React.createElement("button",
|
|
156
|
-
"data-test": 'button'
|
|
157
|
-
|
|
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
|
-
|
|
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
|
|
166
|
+
return (props, propName) => {
|
|
169
167
|
if (typeof props[propName] !== 'undefined') {
|
|
170
|
-
|
|
168
|
+
const cbRes = callback(props, propName);
|
|
171
169
|
|
|
172
170
|
if (cbRes) {
|
|
173
171
|
return cbRes;
|
|
174
172
|
}
|
|
175
173
|
|
|
176
|
-
PropTypes.checkPropTypes(
|
|
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,
|
|
187
|
+
href: validateAdditional(PropTypes.string, props => {
|
|
188
188
|
if (typeof props.notFocusable !== 'undefined') {
|
|
189
|
-
return new Error(
|
|
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']),
|
|
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(
|
|
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,
|
|
207
|
+
notFocusable: validateAdditional(PropTypes.bool, props => {
|
|
208
208
|
if (typeof props.href !== 'undefined' || typeof props.target !== 'undefined') {
|
|
209
|
-
return new Error(
|
|
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": "
|
|
3
|
-
"dark": "
|
|
4
|
-
"flatRight": "
|
|
5
|
-
"flatLeft": "
|
|
6
|
-
"sizeXs": "
|
|
7
|
-
"sizeS": "
|
|
8
|
-
"sizeM": "
|
|
9
|
-
"sizeL": "
|
|
10
|
-
"modeClassic": "
|
|
11
|
-
"modeRock": "
|
|
12
|
-
"modeTransparent": "
|
|
13
|
-
"modeOutline": "
|
|
14
|
-
"modeClear": "
|
|
15
|
-
"alignIconLeft": "
|
|
16
|
-
"alignIconRight": "
|
|
17
|
-
"main": "
|
|
18
|
-
"disabled": "
|
|
19
|
-
"busy": "
|
|
20
|
-
"busyOverlay": "
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"shiftedLeft": "
|
|
28
|
-
"shiftedRight": "
|
|
29
|
-
"shiftedTop": "
|
|
30
|
-
"shiftedBottom": "
|
|
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 };
|