@instructure/ui-buttons 11.6.0 → 11.6.1-snapshot-129
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/CHANGELOG.md +57 -323
- package/es/BaseButton/{index.js → v1/index.js} +2 -2
- package/es/BaseButton/v2/index.js +304 -0
- package/es/BaseButton/v2/props.js +26 -0
- package/es/BaseButton/v2/styles.js +578 -0
- package/es/Button/{index.js → v1/index.js} +2 -2
- package/es/{CondensedButton → Button/v1}/theme.js +1 -1
- package/es/Button/v2/index.js +121 -0
- package/es/Button/v2/props.js +26 -0
- package/es/CloseButton/{index.js → v1/index.js} +2 -2
- package/es/CloseButton/v2/index.js +130 -0
- package/es/CloseButton/v2/props.js +26 -0
- package/es/CloseButton/v2/styles.js +68 -0
- package/es/CondensedButton/{index.js → v1/index.js} +2 -2
- package/es/{Button → CondensedButton/v1}/theme.js +1 -1
- package/es/CondensedButton/v2/index.js +111 -0
- package/es/CondensedButton/v2/props.js +26 -0
- package/es/IconButton/{index.js → v1/index.js} +2 -2
- package/es/IconButton/{theme.js → v1/theme.js} +1 -1
- package/es/IconButton/v2/index.js +121 -0
- package/es/IconButton/v2/props.js +26 -0
- package/es/ToggleButton/{index.js → v1/index.js} +2 -2
- package/es/ToggleButton/v2/index.js +121 -0
- package/es/ToggleButton/v2/props.js +26 -0
- package/es/exports/a.js +29 -0
- package/es/exports/b.js +29 -0
- package/lib/BaseButton/{index.js → v1/index.js} +3 -3
- package/lib/BaseButton/v2/index.js +311 -0
- package/lib/BaseButton/v2/props.js +31 -0
- package/lib/BaseButton/v2/styles.js +584 -0
- package/lib/Button/v1/index.js +128 -0
- package/lib/Button/{theme.js → v1/theme.js} +1 -1
- package/lib/Button/{index.js → v2/index.js} +3 -4
- package/lib/Button/v2/props.js +31 -0
- package/lib/CloseButton/{index.js → v1/index.js} +4 -4
- package/lib/CloseButton/v2/index.js +136 -0
- package/lib/CloseButton/v2/props.js +31 -0
- package/lib/CloseButton/v2/styles.js +74 -0
- package/lib/CondensedButton/{index.js → v1/index.js} +3 -3
- package/lib/CondensedButton/{theme.js → v1/theme.js} +1 -1
- package/lib/CondensedButton/v2/index.js +116 -0
- package/lib/CondensedButton/v2/props.js +31 -0
- package/lib/IconButton/{index.js → v1/index.js} +3 -3
- package/lib/IconButton/{theme.js → v1/theme.js} +1 -1
- package/lib/IconButton/v2/index.js +126 -0
- package/lib/IconButton/v2/props.js +31 -0
- package/lib/ToggleButton/{index.js → v1/index.js} +4 -4
- package/lib/ToggleButton/v2/index.js +127 -0
- package/lib/ToggleButton/v2/props.js +31 -0
- package/lib/{index.js → exports/a.js} +12 -12
- package/lib/exports/b.js +47 -0
- package/package.json +46 -24
- package/src/BaseButton/{index.tsx → v1/index.tsx} +3 -3
- package/src/BaseButton/{props.ts → v1/props.ts} +1 -1
- package/src/BaseButton/v2/README.md +15 -0
- package/src/BaseButton/v2/index.tsx +343 -0
- package/src/BaseButton/v2/props.ts +226 -0
- package/src/BaseButton/v2/styles.ts +640 -0
- package/src/Button/{index.tsx → v1/index.tsx} +2 -2
- package/src/Button/{props.ts → v1/props.ts} +1 -1
- package/src/{CondensedButton → Button/v1}/theme.ts +1 -1
- package/src/Button/v2/README.md +338 -0
- package/src/Button/v2/index.tsx +137 -0
- package/src/Button/v2/props.ts +159 -0
- package/src/CloseButton/{index.tsx → v1/index.tsx} +2 -2
- package/src/CloseButton/{props.ts → v1/props.ts} +1 -1
- package/src/CloseButton/v2/README.md +70 -0
- package/src/CloseButton/v2/index.tsx +142 -0
- package/src/CloseButton/v2/props.ts +148 -0
- package/src/CloseButton/v2/styles.ts +81 -0
- package/src/CondensedButton/{index.tsx → v1/index.tsx} +2 -2
- package/src/CondensedButton/{props.ts → v1/props.ts} +1 -1
- package/src/{Button → CondensedButton/v1}/theme.ts +1 -1
- package/src/CondensedButton/v2/README.md +75 -0
- package/src/CondensedButton/v2/index.tsx +129 -0
- package/src/CondensedButton/v2/props.ts +134 -0
- package/src/IconButton/{index.tsx → v1/index.tsx} +2 -2
- package/src/IconButton/{props.ts → v1/props.ts} +1 -1
- package/src/IconButton/{theme.ts → v1/theme.ts} +1 -1
- package/src/IconButton/v2/README.md +86 -0
- package/src/IconButton/v2/index.tsx +138 -0
- package/src/IconButton/v2/props.ts +166 -0
- package/src/ToggleButton/{index.tsx → v1/index.tsx} +2 -2
- package/src/ToggleButton/{props.ts → v1/props.ts} +1 -1
- package/src/ToggleButton/v2/README.md +85 -0
- package/src/ToggleButton/v2/index.tsx +133 -0
- package/src/ToggleButton/v2/props.ts +143 -0
- package/src/exports/a.ts +40 -0
- package/src/exports/b.ts +40 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/BaseButton/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/BaseButton/v1/index.d.ts.map +1 -0
- package/types/BaseButton/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/BaseButton/v1/props.d.ts.map +1 -0
- package/types/BaseButton/v1/styles.d.ts.map +1 -0
- package/types/BaseButton/v1/theme.d.ts.map +1 -0
- package/types/BaseButton/v2/index.d.ts +48 -0
- package/types/BaseButton/v2/index.d.ts.map +1 -0
- package/types/BaseButton/v2/props.d.ts +118 -0
- package/types/BaseButton/v2/props.d.ts.map +1 -0
- package/types/BaseButton/v2/styles.d.ts +5 -0
- package/types/BaseButton/v2/styles.d.ts.map +1 -0
- package/types/Button/{index.d.ts → v1/index.d.ts} +2 -2
- package/types/Button/v1/index.d.ts.map +1 -0
- package/types/Button/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/Button/v1/props.d.ts.map +1 -0
- package/types/Button/v1/theme.d.ts +2 -0
- package/types/Button/v1/theme.d.ts.map +1 -0
- package/types/Button/v2/index.d.ts +51 -0
- package/types/Button/v2/index.d.ts.map +1 -0
- package/types/Button/v2/props.d.ts +82 -0
- package/types/Button/v2/props.d.ts.map +1 -0
- package/types/CloseButton/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/CloseButton/v1/index.d.ts.map +1 -0
- package/types/CloseButton/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/CloseButton/v1/props.d.ts.map +1 -0
- package/types/CloseButton/v1/styles.d.ts.map +1 -0
- package/types/CloseButton/v1/theme.d.ts.map +1 -0
- package/types/CloseButton/v2/index.d.ts +46 -0
- package/types/CloseButton/v2/index.d.ts.map +1 -0
- package/types/CloseButton/v2/props.d.ts +77 -0
- package/types/CloseButton/v2/props.d.ts.map +1 -0
- package/types/CloseButton/v2/styles.d.ts +15 -0
- package/types/CloseButton/v2/styles.d.ts.map +1 -0
- package/types/CondensedButton/{index.d.ts → v1/index.d.ts} +2 -2
- package/types/CondensedButton/v1/index.d.ts.map +1 -0
- package/types/CondensedButton/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/CondensedButton/v1/props.d.ts.map +1 -0
- package/types/CondensedButton/v1/theme.d.ts +2 -0
- package/types/CondensedButton/v1/theme.d.ts.map +1 -0
- package/types/CondensedButton/v2/index.d.ts +45 -0
- package/types/CondensedButton/v2/index.d.ts.map +1 -0
- package/types/CondensedButton/v2/props.d.ts +69 -0
- package/types/CondensedButton/v2/props.d.ts.map +1 -0
- package/types/IconButton/{index.d.ts → v1/index.d.ts} +2 -2
- package/types/IconButton/v1/index.d.ts.map +1 -0
- package/types/IconButton/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/IconButton/v1/props.d.ts.map +1 -0
- package/types/IconButton/v1/theme.d.ts +2 -0
- package/types/IconButton/v1/theme.d.ts.map +1 -0
- package/types/IconButton/v2/index.d.ts +51 -0
- package/types/IconButton/v2/index.d.ts.map +1 -0
- package/types/IconButton/v2/props.d.ts +85 -0
- package/types/IconButton/v2/props.d.ts.map +1 -0
- package/types/ToggleButton/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/ToggleButton/v1/index.d.ts.map +1 -0
- package/types/ToggleButton/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/ToggleButton/v1/props.d.ts.map +1 -0
- package/types/ToggleButton/v2/index.d.ts +43 -0
- package/types/ToggleButton/v2/index.d.ts.map +1 -0
- package/types/ToggleButton/v2/props.d.ts +75 -0
- package/types/ToggleButton/v2/props.d.ts.map +1 -0
- package/types/exports/a.d.ts +13 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +13 -0
- package/types/exports/b.d.ts.map +1 -0
- package/es/index.js +0 -29
- package/src/index.ts +0 -37
- package/types/BaseButton/index.d.ts.map +0 -1
- package/types/BaseButton/props.d.ts.map +0 -1
- package/types/BaseButton/styles.d.ts.map +0 -1
- package/types/BaseButton/theme.d.ts.map +0 -1
- package/types/Button/index.d.ts.map +0 -1
- package/types/Button/props.d.ts.map +0 -1
- package/types/Button/theme.d.ts +0 -2
- package/types/Button/theme.d.ts.map +0 -1
- package/types/CloseButton/index.d.ts.map +0 -1
- package/types/CloseButton/props.d.ts.map +0 -1
- package/types/CloseButton/styles.d.ts.map +0 -1
- package/types/CloseButton/theme.d.ts.map +0 -1
- package/types/CondensedButton/index.d.ts.map +0 -1
- package/types/CondensedButton/props.d.ts.map +0 -1
- package/types/CondensedButton/theme.d.ts +0 -2
- package/types/CondensedButton/theme.d.ts.map +0 -1
- package/types/IconButton/index.d.ts.map +0 -1
- package/types/IconButton/props.d.ts.map +0 -1
- package/types/IconButton/theme.d.ts +0 -2
- package/types/IconButton/theme.d.ts.map +0 -1
- package/types/ToggleButton/index.d.ts.map +0 -1
- package/types/ToggleButton/props.d.ts.map +0 -1
- package/types/index.d.ts +0 -13
- package/types/index.d.ts.map +0 -1
- /package/es/BaseButton/{props.js → v1/props.js} +0 -0
- /package/es/BaseButton/{styles.js → v1/styles.js} +0 -0
- /package/es/BaseButton/{theme.js → v1/theme.js} +0 -0
- /package/es/Button/{props.js → v1/props.js} +0 -0
- /package/es/CloseButton/{props.js → v1/props.js} +0 -0
- /package/es/CloseButton/{styles.js → v1/styles.js} +0 -0
- /package/es/CloseButton/{theme.js → v1/theme.js} +0 -0
- /package/es/CondensedButton/{props.js → v1/props.js} +0 -0
- /package/es/IconButton/{props.js → v1/props.js} +0 -0
- /package/es/ToggleButton/{props.js → v1/props.js} +0 -0
- /package/lib/BaseButton/{props.js → v1/props.js} +0 -0
- /package/lib/BaseButton/{styles.js → v1/styles.js} +0 -0
- /package/lib/BaseButton/{theme.js → v1/theme.js} +0 -0
- /package/lib/Button/{props.js → v1/props.js} +0 -0
- /package/lib/CloseButton/{props.js → v1/props.js} +0 -0
- /package/lib/CloseButton/{styles.js → v1/styles.js} +0 -0
- /package/lib/CloseButton/{theme.js → v1/theme.js} +0 -0
- /package/lib/CondensedButton/{props.js → v1/props.js} +0 -0
- /package/lib/IconButton/{props.js → v1/props.js} +0 -0
- /package/lib/ToggleButton/{props.js → v1/props.js} +0 -0
- /package/src/BaseButton/{README.md → v1/README.md} +0 -0
- /package/src/BaseButton/{styles.ts → v1/styles.ts} +0 -0
- /package/src/BaseButton/{theme.ts → v1/theme.ts} +0 -0
- /package/src/Button/{README.md → v1/README.md} +0 -0
- /package/src/CloseButton/{README.md → v1/README.md} +0 -0
- /package/src/CloseButton/{styles.ts → v1/styles.ts} +0 -0
- /package/src/CloseButton/{theme.ts → v1/theme.ts} +0 -0
- /package/src/CondensedButton/{README.md → v1/README.md} +0 -0
- /package/src/IconButton/{README.md → v1/README.md} +0 -0
- /package/src/ToggleButton/{README.md → v1/README.md} +0 -0
- /package/types/BaseButton/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/BaseButton/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/CloseButton/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/CloseButton/{theme.d.ts → v1/theme.d.ts} +0 -0
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = exports.BaseButton = void 0;
|
|
8
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _keycode = _interopRequireDefault(require("keycode"));
|
|
11
|
+
var _getElementType = require("@instructure/ui-react-utils/lib/getElementType.js");
|
|
12
|
+
var _getInteraction = require("@instructure/ui-react-utils/lib/getInteraction.js");
|
|
13
|
+
var _passthroughProps = require("@instructure/ui-react-utils/lib/passthroughProps.js");
|
|
14
|
+
var _isActiveElement = require("@instructure/ui-dom-utils/lib/isActiveElement.js");
|
|
15
|
+
var _hasVisibleChildren = require("@instructure/ui-a11y-utils/lib/hasVisibleChildren.js");
|
|
16
|
+
var _renderIconWithProps = require("@instructure/ui-icons/lib/IconPropsProvider/renderIconWithProps.js");
|
|
17
|
+
var _latest = require("@instructure/ui-view/latest");
|
|
18
|
+
var _uiUtils = require("@instructure/ui-utils");
|
|
19
|
+
var _combineDataCid = require("@instructure/ui-utils/lib/combineDataCid.js");
|
|
20
|
+
var _emotion = require("@instructure/emotion");
|
|
21
|
+
var _styles = _interopRequireDefault(require("./styles"));
|
|
22
|
+
var _props = require("./props");
|
|
23
|
+
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
24
|
+
const _excluded = ["type", "size", "elementRef", "as", "href", "color", "focusColor", "textAlign", "shape", "display", "withBackground", "withBorder", "isCondensed", "margin", "cursor", "onClick", "renderIcon", "tabIndex", "styles", "makeStyles", "withFocusOutline"];
|
|
25
|
+
var _dec, _class, _BaseButton;
|
|
26
|
+
/*
|
|
27
|
+
* The MIT License (MIT)
|
|
28
|
+
*
|
|
29
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
30
|
+
*
|
|
31
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
32
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
33
|
+
* in the Software without restriction, including without limitation the rights
|
|
34
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
35
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
36
|
+
* furnished to do so, subject to the following conditions:
|
|
37
|
+
*
|
|
38
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
39
|
+
* copies or substantial portions of the Software.
|
|
40
|
+
*
|
|
41
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
42
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
43
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
44
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
45
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
46
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
47
|
+
* SOFTWARE.
|
|
48
|
+
*/
|
|
49
|
+
// TODO these have to be imported in separate lines because otherwise `isSafari` will be missing from the babel build
|
|
50
|
+
// this bug is very likely caused by `babel-plugin-transform-imports` and can be reverted once it is removed from the codebase
|
|
51
|
+
const buttonSizeToIconSize = {
|
|
52
|
+
small: 'sm',
|
|
53
|
+
medium: 'md',
|
|
54
|
+
large: 'lg',
|
|
55
|
+
condensedSmall: 'xs',
|
|
56
|
+
condensedMedium: 'xs'
|
|
57
|
+
};
|
|
58
|
+
const buttonColorToIconColor = {
|
|
59
|
+
'primary': 'inherit',
|
|
60
|
+
'primary-inverse': 'inherit',
|
|
61
|
+
'secondary': 'inherit',
|
|
62
|
+
'success': 'inherit',
|
|
63
|
+
'danger': 'inherit',
|
|
64
|
+
'ai-primary': 'inherit',
|
|
65
|
+
'ai-secondary': 'ai'
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
---
|
|
70
|
+
category: components/utilities
|
|
71
|
+
---
|
|
72
|
+
**/
|
|
73
|
+
let BaseButton = exports.BaseButton = (_dec = (0, _emotion.withStyle)(_styles.default), _dec(_class = (_BaseButton = class BaseButton extends _react.Component {
|
|
74
|
+
constructor(...args) {
|
|
75
|
+
super(...args);
|
|
76
|
+
this.ref = null;
|
|
77
|
+
this.handleElementRef = el => {
|
|
78
|
+
const elementRef = this.props.elementRef;
|
|
79
|
+
this.ref = el;
|
|
80
|
+
if (typeof elementRef === 'function') {
|
|
81
|
+
elementRef(el);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
this.handleClick = event => {
|
|
85
|
+
const onClick = this.props.onClick;
|
|
86
|
+
const interaction = this.interaction;
|
|
87
|
+
if (interaction !== 'enabled') {
|
|
88
|
+
event.preventDefault();
|
|
89
|
+
event.stopPropagation();
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
if (typeof onClick === 'function') {
|
|
93
|
+
onClick(event);
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
this.handleKeyDown = event => {
|
|
97
|
+
const _this$props = this.props,
|
|
98
|
+
onClick = _this$props.onClick,
|
|
99
|
+
onKeyDown = _this$props.onKeyDown,
|
|
100
|
+
href = _this$props.href;
|
|
101
|
+
const interaction = this.interaction;
|
|
102
|
+
if (typeof onKeyDown === 'function') {
|
|
103
|
+
onKeyDown(event);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// behave like a button when space key is pressed
|
|
107
|
+
const _keycode$codes = _keycode.default.codes,
|
|
108
|
+
space = _keycode$codes.space,
|
|
109
|
+
enter = _keycode$codes.enter;
|
|
110
|
+
if (this.elementType !== 'button' && [space, enter].includes(event.keyCode)) {
|
|
111
|
+
event.preventDefault();
|
|
112
|
+
event.stopPropagation();
|
|
113
|
+
if (typeof onClick === 'function' && interaction === 'enabled') {
|
|
114
|
+
onClick(event);
|
|
115
|
+
}
|
|
116
|
+
if (href) {
|
|
117
|
+
this.ref && this.ref.click();
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
componentDidMount() {
|
|
123
|
+
var _this$props$makeStyle, _this$props2;
|
|
124
|
+
(_this$props$makeStyle = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props2, this.makeStylesVariables);
|
|
125
|
+
}
|
|
126
|
+
componentDidUpdate() {
|
|
127
|
+
var _this$props$makeStyle2, _this$props3;
|
|
128
|
+
(_this$props$makeStyle2 = (_this$props3 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props3, this.makeStylesVariables);
|
|
129
|
+
}
|
|
130
|
+
get makeStylesVariables() {
|
|
131
|
+
return {
|
|
132
|
+
isDisabled: this.isDisabled,
|
|
133
|
+
hasOnlyIconVisible: this.hasOnlyIconVisible,
|
|
134
|
+
isEnabled: this.isEnabled
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
get hasOnlyIconVisible() {
|
|
138
|
+
const _this$props4 = this.props,
|
|
139
|
+
children = _this$props4.children,
|
|
140
|
+
renderIcon = _this$props4.renderIcon;
|
|
141
|
+
return !!(renderIcon && !(0, _hasVisibleChildren.hasVisibleChildren)(children));
|
|
142
|
+
}
|
|
143
|
+
get elementType() {
|
|
144
|
+
return (0, _getElementType.getElementType)(BaseButton, this.props);
|
|
145
|
+
}
|
|
146
|
+
get interaction() {
|
|
147
|
+
return (0, _getInteraction.getInteraction)({
|
|
148
|
+
props: this.props
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
get isDisabled() {
|
|
152
|
+
return this.interaction === 'disabled';
|
|
153
|
+
}
|
|
154
|
+
get isReadOnly() {
|
|
155
|
+
return this.interaction === 'readonly';
|
|
156
|
+
}
|
|
157
|
+
get isEnabled() {
|
|
158
|
+
return this.interaction === 'enabled';
|
|
159
|
+
}
|
|
160
|
+
get focusColor() {
|
|
161
|
+
const _this$props5 = this.props,
|
|
162
|
+
color = _this$props5.color,
|
|
163
|
+
focusColor = _this$props5.focusColor,
|
|
164
|
+
withBackground = _this$props5.withBackground;
|
|
165
|
+
|
|
166
|
+
// Give user specified focusColor preference
|
|
167
|
+
if (focusColor) {
|
|
168
|
+
return focusColor;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// The `primary-inverse` background has an info focus outline
|
|
172
|
+
// by default since it is replacing the `light` button variant.
|
|
173
|
+
// Override the focus color with info even though it is
|
|
174
|
+
// an inverse color
|
|
175
|
+
if (color === 'primary-inverse' && withBackground) {
|
|
176
|
+
return 'info';
|
|
177
|
+
}
|
|
178
|
+
return color.includes('inverse') ? 'inverse' : 'info';
|
|
179
|
+
}
|
|
180
|
+
get focused() {
|
|
181
|
+
return (0, _isActiveElement.isActiveElement)(this.ref);
|
|
182
|
+
}
|
|
183
|
+
focus() {
|
|
184
|
+
this.ref && this.ref.focus();
|
|
185
|
+
}
|
|
186
|
+
renderChildren() {
|
|
187
|
+
const _this$props6 = this.props,
|
|
188
|
+
renderIcon = _this$props6.renderIcon,
|
|
189
|
+
children = _this$props6.children,
|
|
190
|
+
styles = _this$props6.styles,
|
|
191
|
+
size = _this$props6.size,
|
|
192
|
+
color = _this$props6.color;
|
|
193
|
+
const wrappedChildren = (0, _jsxRuntime.jsx)("span", {
|
|
194
|
+
css: styles === null || styles === void 0 ? void 0 : styles.children,
|
|
195
|
+
children: children
|
|
196
|
+
});
|
|
197
|
+
if (!renderIcon) {
|
|
198
|
+
return wrappedChildren;
|
|
199
|
+
}
|
|
200
|
+
const hasOnlyIconVisible = this.hasOnlyIconVisible;
|
|
201
|
+
const iconSize = buttonSizeToIconSize[size];
|
|
202
|
+
const iconColor = buttonColorToIconColor[color];
|
|
203
|
+
const wrappedIcon = (0, _jsxRuntime.jsx)("span", {
|
|
204
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconSVG,
|
|
205
|
+
children: (0, _renderIconWithProps.renderIconWithProps)(renderIcon, iconSize, iconColor)
|
|
206
|
+
});
|
|
207
|
+
const flexChildren = hasOnlyIconVisible ? (0, _jsxRuntime.jsxs)("span", {
|
|
208
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconOnly,
|
|
209
|
+
children: [wrappedIcon, children]
|
|
210
|
+
}) : [(0, _jsxRuntime.jsx)("span", {
|
|
211
|
+
css: styles === null || styles === void 0 ? void 0 : styles.iconWrapper,
|
|
212
|
+
children: wrappedIcon
|
|
213
|
+
}, "icon"), (0, _jsxRuntime.jsx)("span", {
|
|
214
|
+
css: styles === null || styles === void 0 ? void 0 : styles.childrenWrapper,
|
|
215
|
+
children: wrappedChildren
|
|
216
|
+
}, "children")];
|
|
217
|
+
return (0, _jsxRuntime.jsx)("span", {
|
|
218
|
+
css: styles === null || styles === void 0 ? void 0 : styles.childrenLayout,
|
|
219
|
+
children: flexChildren
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
render() {
|
|
223
|
+
const _this$props7 = this.props,
|
|
224
|
+
type = _this$props7.type,
|
|
225
|
+
size = _this$props7.size,
|
|
226
|
+
elementRef = _this$props7.elementRef,
|
|
227
|
+
as = _this$props7.as,
|
|
228
|
+
href = _this$props7.href,
|
|
229
|
+
color = _this$props7.color,
|
|
230
|
+
focusColor = _this$props7.focusColor,
|
|
231
|
+
textAlign = _this$props7.textAlign,
|
|
232
|
+
shape = _this$props7.shape,
|
|
233
|
+
display = _this$props7.display,
|
|
234
|
+
withBackground = _this$props7.withBackground,
|
|
235
|
+
withBorder = _this$props7.withBorder,
|
|
236
|
+
isCondensed = _this$props7.isCondensed,
|
|
237
|
+
margin = _this$props7.margin,
|
|
238
|
+
cursor = _this$props7.cursor,
|
|
239
|
+
onClick = _this$props7.onClick,
|
|
240
|
+
renderIcon = _this$props7.renderIcon,
|
|
241
|
+
tabIndex = _this$props7.tabIndex,
|
|
242
|
+
styles = _this$props7.styles,
|
|
243
|
+
makeStyles = _this$props7.makeStyles,
|
|
244
|
+
withFocusOutline = _this$props7.withFocusOutline,
|
|
245
|
+
props = (0, _objectWithoutProperties2.default)(_this$props7, _excluded);
|
|
246
|
+
const isDisabled = this.isDisabled,
|
|
247
|
+
isReadOnly = this.isReadOnly,
|
|
248
|
+
elementType = this.elementType;
|
|
249
|
+
// only add 0 tabIndex value if it doesn't have it by default, see
|
|
250
|
+
// https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/tabindex
|
|
251
|
+
let needsZeroTabIndex = true;
|
|
252
|
+
if (typeof elementType == 'string') {
|
|
253
|
+
if (['button', 'frame', 'iframe', 'input', 'object', 'select', 'textarea', 'summary'].includes(elementType)) {
|
|
254
|
+
needsZeroTabIndex = false;
|
|
255
|
+
}
|
|
256
|
+
if (href && (elementType === 'a' || elementType === 'area')) {
|
|
257
|
+
needsZeroTabIndex = false;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
let tabIndexValue = tabIndex;
|
|
261
|
+
// In Safari, a button cannot get focus unless it has an explicit 0 tabindex
|
|
262
|
+
if (onClick && as && needsZeroTabIndex || (0, _uiUtils.isSafari)() && as) {
|
|
263
|
+
tabIndexValue = tabIndex || 0;
|
|
264
|
+
}
|
|
265
|
+
return (0, _jsxRuntime.jsx)(_latest.View, {
|
|
266
|
+
...(0, _passthroughProps.passthroughProps)(props),
|
|
267
|
+
as: elementType,
|
|
268
|
+
focusColor: this.focusColor,
|
|
269
|
+
position: "relative",
|
|
270
|
+
display: display,
|
|
271
|
+
width: display === 'block' ? '100%' : 'auto',
|
|
272
|
+
borderRadius: shape === 'circle' ? 'circle' : 'medium',
|
|
273
|
+
background: "transparent",
|
|
274
|
+
padding: "none",
|
|
275
|
+
borderWidth: "none",
|
|
276
|
+
margin: margin,
|
|
277
|
+
cursor: isDisabled ? 'not-allowed' : cursor,
|
|
278
|
+
href: href,
|
|
279
|
+
type: href ? void 0 : type,
|
|
280
|
+
elementRef: this.handleElementRef,
|
|
281
|
+
onClick: this.handleClick,
|
|
282
|
+
onKeyDown: this.handleKeyDown,
|
|
283
|
+
role: onClick && as !== 'button' ? 'button' : void 0,
|
|
284
|
+
tabIndex: tabIndexValue,
|
|
285
|
+
disabled: isDisabled || isReadOnly,
|
|
286
|
+
css: styles === null || styles === void 0 ? void 0 : styles.baseButton,
|
|
287
|
+
withFocusOutline: withFocusOutline,
|
|
288
|
+
"data-cid": (0, _combineDataCid.combineDataCid)('BaseButton', this.props),
|
|
289
|
+
children: (0, _jsxRuntime.jsx)("span", {
|
|
290
|
+
css: styles === null || styles === void 0 ? void 0 : styles.content,
|
|
291
|
+
children: this.renderChildren()
|
|
292
|
+
})
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
}, _BaseButton.displayName = "BaseButton", _BaseButton.componentId = 'BaseButton', _BaseButton.allowedProps = _props.allowedProps, _BaseButton.defaultProps = {
|
|
296
|
+
type: 'button',
|
|
297
|
+
size: 'medium',
|
|
298
|
+
as: 'button',
|
|
299
|
+
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
300
|
+
interaction: void 0,
|
|
301
|
+
color: 'secondary',
|
|
302
|
+
shape: 'rectangle',
|
|
303
|
+
display: 'inline-block',
|
|
304
|
+
textAlign: 'start',
|
|
305
|
+
withBackground: true,
|
|
306
|
+
withBorder: true,
|
|
307
|
+
isCondensed: false,
|
|
308
|
+
margin: '0',
|
|
309
|
+
cursor: 'pointer'
|
|
310
|
+
}, _BaseButton)) || _class);
|
|
311
|
+
var _default = exports.default = BaseButton;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.allowedProps = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* The MIT License (MIT)
|
|
9
|
+
*
|
|
10
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
+
*
|
|
12
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
+
* in the Software without restriction, including without limitation the rights
|
|
15
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
+
* furnished to do so, subject to the following conditions:
|
|
18
|
+
*
|
|
19
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
+
* copies or substantial portions of the Software.
|
|
21
|
+
*
|
|
22
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
+
* SOFTWARE.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
const allowedProps = exports.allowedProps = ['as', 'children', 'color', 'cursor', 'display', 'elementRef', 'focusColor', 'href', 'interaction', 'isCondensed', 'margin', 'onClick', 'onKeyDown', 'renderIcon', 'shape', 'size', 'tabIndex', 'textAlign', 'type', 'withBackground', 'withBorder'];
|