@khanacademy/wonder-blocks-icon-button 3.4.17 → 3.4.19
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 +17 -0
- package/dist/index.js +229 -0
- package/dist/index.js.flow +2 -0
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-icon-button
|
|
2
2
|
|
|
3
|
+
## 3.4.19
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [496119f2]
|
|
8
|
+
- @khanacademy/wonder-blocks-clickable@2.4.4
|
|
9
|
+
- @khanacademy/wonder-blocks-core@4.6.2
|
|
10
|
+
- @khanacademy/wonder-blocks-icon@1.2.35
|
|
11
|
+
|
|
12
|
+
## 3.4.18
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- @khanacademy/wonder-blocks-clickable@2.4.3
|
|
17
|
+
- @khanacademy/wonder-blocks-core@4.6.1
|
|
18
|
+
- @khanacademy/wonder-blocks-icon@1.2.34
|
|
19
|
+
|
|
3
20
|
## 3.4.17
|
|
4
21
|
|
|
5
22
|
### Patch Changes
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _extends = require('@babel/runtime/helpers/extends');
|
|
4
|
+
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var reactRouter = require('react-router');
|
|
7
|
+
var wonderBlocksClickable = require('@khanacademy/wonder-blocks-clickable');
|
|
8
|
+
var aphrodite = require('aphrodite');
|
|
9
|
+
var reactRouterDom = require('react-router-dom');
|
|
10
|
+
var Color = require('@khanacademy/wonder-blocks-color');
|
|
11
|
+
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
12
|
+
var Icon = require('@khanacademy/wonder-blocks-icon');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
+
|
|
16
|
+
function _interopNamespace(e) {
|
|
17
|
+
if (e && e.__esModule) return e;
|
|
18
|
+
var n = Object.create(null);
|
|
19
|
+
if (e) {
|
|
20
|
+
Object.keys(e).forEach(function (k) {
|
|
21
|
+
if (k !== 'default') {
|
|
22
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
23
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function () { return e[k]; }
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
n["default"] = e;
|
|
31
|
+
return Object.freeze(n);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
35
|
+
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
36
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
37
|
+
var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
|
|
38
|
+
var Icon__default = /*#__PURE__*/_interopDefaultLegacy(Icon);
|
|
39
|
+
|
|
40
|
+
const _excluded$1 = ["skipClientNav", "color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "style", "testId", "waiting"];
|
|
41
|
+
const StyledAnchor = wonderBlocksCore.addStyle("a");
|
|
42
|
+
const StyledButton = wonderBlocksCore.addStyle("button");
|
|
43
|
+
const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
|
|
44
|
+
class IconButtonCore extends React__namespace.Component {
|
|
45
|
+
renderInner(router) {
|
|
46
|
+
const _this$props = this.props,
|
|
47
|
+
{
|
|
48
|
+
skipClientNav,
|
|
49
|
+
color,
|
|
50
|
+
disabled,
|
|
51
|
+
focused,
|
|
52
|
+
hovered,
|
|
53
|
+
href,
|
|
54
|
+
icon,
|
|
55
|
+
kind,
|
|
56
|
+
light,
|
|
57
|
+
pressed,
|
|
58
|
+
style,
|
|
59
|
+
testId
|
|
60
|
+
} = _this$props,
|
|
61
|
+
restProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$1);
|
|
62
|
+
|
|
63
|
+
const buttonColor = color === "destructive" ? Color.SemanticColor.controlDestructive : Color.SemanticColor.controlDefault;
|
|
64
|
+
|
|
65
|
+
const buttonStyles = _generateStyles(buttonColor, kind, light);
|
|
66
|
+
|
|
67
|
+
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
|
|
68
|
+
const child = React__namespace.createElement(Icon__default["default"], {
|
|
69
|
+
size: "medium",
|
|
70
|
+
color: "currentColor",
|
|
71
|
+
icon: icon
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const commonProps = _extends__default["default"]({
|
|
75
|
+
"data-test-id": testId,
|
|
76
|
+
style: [defaultStyle, style]
|
|
77
|
+
}, restProps);
|
|
78
|
+
|
|
79
|
+
if (href && !disabled) {
|
|
80
|
+
return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends__default["default"]({}, commonProps, {
|
|
81
|
+
to: href
|
|
82
|
+
}), child) : React__namespace.createElement(StyledAnchor, _extends__default["default"]({}, commonProps, {
|
|
83
|
+
href: href
|
|
84
|
+
}), child);
|
|
85
|
+
} else {
|
|
86
|
+
return React__namespace.createElement(StyledButton, _extends__default["default"]({
|
|
87
|
+
type: "button"
|
|
88
|
+
}, commonProps, {
|
|
89
|
+
disabled: disabled
|
|
90
|
+
}), child);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
render() {
|
|
95
|
+
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
const sharedStyles = aphrodite.StyleSheet.create({
|
|
100
|
+
shared: {
|
|
101
|
+
position: "relative",
|
|
102
|
+
display: "inline-flex",
|
|
103
|
+
alignItems: "center",
|
|
104
|
+
justifyContent: "center",
|
|
105
|
+
boxSizing: "border-box",
|
|
106
|
+
height: 40,
|
|
107
|
+
width: 40,
|
|
108
|
+
padding: 0,
|
|
109
|
+
cursor: "pointer",
|
|
110
|
+
border: "none",
|
|
111
|
+
outline: "none",
|
|
112
|
+
textDecoration: "none",
|
|
113
|
+
background: "none",
|
|
114
|
+
margin: -8,
|
|
115
|
+
touchAction: "manipulation",
|
|
116
|
+
":focus": {
|
|
117
|
+
WebkitTapHighlightColor: "rgba(0,0,0,0)"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
120
|
+
disabled: {
|
|
121
|
+
cursor: "default"
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
const styles = {};
|
|
125
|
+
|
|
126
|
+
const _generateStyles = (color, kind, light) => {
|
|
127
|
+
const buttonType = color + kind + light.toString();
|
|
128
|
+
|
|
129
|
+
if (styles[buttonType]) {
|
|
130
|
+
return styles[buttonType];
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (light && kind !== "primary") {
|
|
134
|
+
throw new Error("Light is only supported for primary IconButtons");
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const {
|
|
138
|
+
white,
|
|
139
|
+
offBlack32,
|
|
140
|
+
offBlack64,
|
|
141
|
+
offBlack
|
|
142
|
+
} = Color__default["default"];
|
|
143
|
+
const newStyles = {
|
|
144
|
+
default: {},
|
|
145
|
+
focus: {
|
|
146
|
+
color: light ? white : color,
|
|
147
|
+
borderWidth: 2,
|
|
148
|
+
borderColor: light ? white : color,
|
|
149
|
+
borderStyle: "solid",
|
|
150
|
+
borderRadius: 4
|
|
151
|
+
},
|
|
152
|
+
active: {
|
|
153
|
+
color: light ? Color.mix(Color.fade(color, 0.32), white) : Color.mix(offBlack32, color),
|
|
154
|
+
borderWidth: 2,
|
|
155
|
+
borderColor: light ? Color.mix(Color.fade(color, 0.32), white) : Color.mix(offBlack32, color),
|
|
156
|
+
borderStyle: "solid",
|
|
157
|
+
borderRadius: 4
|
|
158
|
+
},
|
|
159
|
+
disabled: {
|
|
160
|
+
color: light ? Color.mix(Color.fade(white, 0.32), color) : offBlack32,
|
|
161
|
+
cursor: "default"
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
if (kind === "primary") {
|
|
166
|
+
newStyles["default"] = {
|
|
167
|
+
color: light ? white : color
|
|
168
|
+
};
|
|
169
|
+
} else if (kind === "secondary") {
|
|
170
|
+
newStyles["default"] = {
|
|
171
|
+
color: offBlack
|
|
172
|
+
};
|
|
173
|
+
} else if (kind === "tertiary") {
|
|
174
|
+
newStyles["default"] = {
|
|
175
|
+
color: offBlack64
|
|
176
|
+
};
|
|
177
|
+
} else {
|
|
178
|
+
throw new Error("IconButton kind not recognized");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
styles[buttonType] = aphrodite.StyleSheet.create(newStyles);
|
|
182
|
+
return styles[buttonType];
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
const _excluded = ["onClick", "href", "skipClientNav", "tabIndex", "target"];
|
|
186
|
+
class IconButton extends React__namespace.Component {
|
|
187
|
+
renderClickableBehavior(router) {
|
|
188
|
+
const _this$props = this.props,
|
|
189
|
+
{
|
|
190
|
+
onClick,
|
|
191
|
+
href,
|
|
192
|
+
skipClientNav,
|
|
193
|
+
tabIndex,
|
|
194
|
+
target
|
|
195
|
+
} = _this$props,
|
|
196
|
+
sharedProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded);
|
|
197
|
+
|
|
198
|
+
const ClickableBehavior = wonderBlocksClickable.getClickableBehavior(href, skipClientNav, router);
|
|
199
|
+
return React__namespace.createElement(ClickableBehavior, {
|
|
200
|
+
disabled: sharedProps.disabled,
|
|
201
|
+
href: href,
|
|
202
|
+
onClick: onClick,
|
|
203
|
+
role: "button",
|
|
204
|
+
target: target
|
|
205
|
+
}, (state, _ref) => {
|
|
206
|
+
let childrenProps = _extends__default["default"]({}, _ref);
|
|
207
|
+
|
|
208
|
+
return React__namespace.createElement(IconButtonCore, _extends__default["default"]({}, sharedProps, state, childrenProps, {
|
|
209
|
+
skipClientNav: skipClientNav,
|
|
210
|
+
href: href,
|
|
211
|
+
target: target,
|
|
212
|
+
tabIndex: tabIndex
|
|
213
|
+
}));
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
render() {
|
|
218
|
+
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
IconButton.defaultProps = {
|
|
223
|
+
color: "default",
|
|
224
|
+
kind: "primary",
|
|
225
|
+
light: false,
|
|
226
|
+
disabled: false
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
module.exports = IconButton;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-icon-button",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.19",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^2.4.
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^2.4.4",
|
|
20
20
|
"@khanacademy/wonder-blocks-color": "^1.2.0",
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^4.6.
|
|
22
|
-
"@khanacademy/wonder-blocks-icon": "^1.2.
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^4.6.2",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^1.2.35"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"aphrodite": "^1.2.5",
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"react-router-dom": "5.3.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"wb-dev-build-settings": "^0.
|
|
31
|
+
"wb-dev-build-settings": "^0.7.0"
|
|
32
32
|
}
|
|
33
33
|
}
|