@khanacademy/wonder-blocks-clickable 3.0.4 → 3.0.6
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 +10 -0
- package/dist/components/clickable-behavior.js.flow +1 -2
- package/dist/components/clickable.js.flow +1 -2
- package/dist/es/index.js +79 -103
- package/dist/index.js +79 -103
- package/dist/index.js.flow +1 -2
- package/dist/util/get-clickable-behavior.js.flow +1 -2
- package/dist/util/is-client-side-url.js.flow +1 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-clickable
|
|
2
2
|
|
|
3
|
+
## 3.0.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- c20f48f3: Don't transpile classes when building bundles
|
|
8
|
+
- Updated dependencies [c20f48f3]
|
|
9
|
+
- @khanacademy/wonder-blocks-core@5.0.4
|
|
10
|
+
|
|
11
|
+
## 3.0.5
|
|
12
|
+
|
|
3
13
|
## 3.0.4
|
|
4
14
|
|
|
5
15
|
## 3.0.3
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
|
|
10
9
|
import type { ClickableRole, ClickableState } from "./clickable-behavior";
|
package/dist/es/index.js
CHANGED
|
@@ -33,20 +33,6 @@ function _extends() {
|
|
|
33
33
|
return _extends.apply(this, arguments);
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
function _setPrototypeOf(o, p) {
|
|
37
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
38
|
-
o.__proto__ = p;
|
|
39
|
-
return o;
|
|
40
|
-
};
|
|
41
|
-
return _setPrototypeOf(o, p);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function _inheritsLoose(subClass, superClass) {
|
|
45
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
46
|
-
subClass.prototype.constructor = subClass;
|
|
47
|
-
_setPrototypeOf(subClass, superClass);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
36
|
const getAppropriateTriggersForRole = role => {
|
|
51
37
|
switch (role) {
|
|
52
38
|
case "link":
|
|
@@ -94,9 +80,8 @@ const startState = {
|
|
|
94
80
|
pressed: false,
|
|
95
81
|
waiting: false
|
|
96
82
|
};
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
ClickableBehavior.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
|
|
83
|
+
class ClickableBehavior extends React.Component {
|
|
84
|
+
static getDerivedStateFromProps(props, state) {
|
|
100
85
|
if (props.disabled) {
|
|
101
86
|
return _extends({}, startState, {
|
|
102
87
|
focused: state.focused
|
|
@@ -104,75 +89,74 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
104
89
|
} else {
|
|
105
90
|
return null;
|
|
106
91
|
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
_this.handleClick = e => {
|
|
92
|
+
}
|
|
93
|
+
constructor(props) {
|
|
94
|
+
super(props);
|
|
95
|
+
this.waitingForClick = void 0;
|
|
96
|
+
this.enterClick = void 0;
|
|
97
|
+
this.handleClick = e => {
|
|
114
98
|
const {
|
|
115
99
|
onClick = undefined,
|
|
116
100
|
beforeNav = undefined,
|
|
117
101
|
safeWithNav = undefined
|
|
118
|
-
} =
|
|
119
|
-
if (
|
|
102
|
+
} = this.props;
|
|
103
|
+
if (this.enterClick) {
|
|
120
104
|
return;
|
|
121
105
|
}
|
|
122
106
|
if (onClick || beforeNav || safeWithNav) {
|
|
123
|
-
|
|
107
|
+
this.waitingForClick = false;
|
|
124
108
|
}
|
|
125
|
-
|
|
109
|
+
this.runCallbackAndMaybeNavigate(e);
|
|
126
110
|
};
|
|
127
|
-
|
|
128
|
-
if (!
|
|
129
|
-
|
|
111
|
+
this.handleMouseEnter = e => {
|
|
112
|
+
if (!this.waitingForClick) {
|
|
113
|
+
this.setState({
|
|
130
114
|
hovered: true
|
|
131
115
|
});
|
|
132
116
|
}
|
|
133
117
|
};
|
|
134
|
-
|
|
135
|
-
if (!
|
|
136
|
-
|
|
118
|
+
this.handleMouseLeave = () => {
|
|
119
|
+
if (!this.waitingForClick) {
|
|
120
|
+
this.setState({
|
|
137
121
|
hovered: false,
|
|
138
122
|
pressed: false,
|
|
139
123
|
focused: false
|
|
140
124
|
});
|
|
141
125
|
}
|
|
142
126
|
};
|
|
143
|
-
|
|
144
|
-
|
|
127
|
+
this.handleMouseDown = () => {
|
|
128
|
+
this.setState({
|
|
145
129
|
pressed: true
|
|
146
130
|
});
|
|
147
131
|
};
|
|
148
|
-
|
|
149
|
-
|
|
132
|
+
this.handleMouseUp = e => {
|
|
133
|
+
this.setState({
|
|
150
134
|
pressed: false,
|
|
151
135
|
focused: false
|
|
152
136
|
});
|
|
153
137
|
};
|
|
154
|
-
|
|
155
|
-
|
|
138
|
+
this.handleTouchStart = () => {
|
|
139
|
+
this.setState({
|
|
156
140
|
pressed: true
|
|
157
141
|
});
|
|
158
142
|
};
|
|
159
|
-
|
|
160
|
-
|
|
143
|
+
this.handleTouchEnd = () => {
|
|
144
|
+
this.setState({
|
|
161
145
|
pressed: false
|
|
162
146
|
});
|
|
163
|
-
|
|
147
|
+
this.waitingForClick = true;
|
|
164
148
|
};
|
|
165
|
-
|
|
166
|
-
|
|
149
|
+
this.handleTouchCancel = () => {
|
|
150
|
+
this.setState({
|
|
167
151
|
pressed: false
|
|
168
152
|
});
|
|
169
|
-
|
|
153
|
+
this.waitingForClick = true;
|
|
170
154
|
};
|
|
171
|
-
|
|
155
|
+
this.handleKeyDown = e => {
|
|
172
156
|
const {
|
|
173
157
|
onKeyDown,
|
|
174
158
|
role
|
|
175
|
-
} =
|
|
159
|
+
} = this.props;
|
|
176
160
|
if (onKeyDown) {
|
|
177
161
|
onKeyDown(e);
|
|
178
162
|
}
|
|
@@ -183,18 +167,18 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
183
167
|
} = getAppropriateTriggersForRole(role);
|
|
184
168
|
if (triggerOnEnter && keyCode === keyCodes.enter || triggerOnSpace && keyCode === keyCodes.space) {
|
|
185
169
|
e.preventDefault();
|
|
186
|
-
|
|
170
|
+
this.setState({
|
|
187
171
|
pressed: true
|
|
188
172
|
});
|
|
189
173
|
} else if (!triggerOnEnter && keyCode === keyCodes.enter) {
|
|
190
|
-
|
|
174
|
+
this.enterClick = true;
|
|
191
175
|
}
|
|
192
176
|
};
|
|
193
|
-
|
|
177
|
+
this.handleKeyUp = e => {
|
|
194
178
|
const {
|
|
195
179
|
onKeyUp,
|
|
196
180
|
role
|
|
197
|
-
} =
|
|
181
|
+
} = this.props;
|
|
198
182
|
if (onKeyUp) {
|
|
199
183
|
onKeyUp(e);
|
|
200
184
|
}
|
|
@@ -204,33 +188,31 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
204
188
|
triggerOnSpace
|
|
205
189
|
} = getAppropriateTriggersForRole(role);
|
|
206
190
|
if (triggerOnEnter && keyCode === keyCodes.enter || triggerOnSpace && keyCode === keyCodes.space) {
|
|
207
|
-
|
|
191
|
+
this.setState({
|
|
208
192
|
pressed: false,
|
|
209
193
|
focused: true
|
|
210
194
|
});
|
|
211
|
-
|
|
195
|
+
this.runCallbackAndMaybeNavigate(e);
|
|
212
196
|
} else if (!triggerOnEnter && keyCode === keyCodes.enter) {
|
|
213
|
-
|
|
197
|
+
this.enterClick = false;
|
|
214
198
|
}
|
|
215
199
|
};
|
|
216
|
-
|
|
217
|
-
|
|
200
|
+
this.handleFocus = e => {
|
|
201
|
+
this.setState({
|
|
218
202
|
focused: true
|
|
219
203
|
});
|
|
220
204
|
};
|
|
221
|
-
|
|
222
|
-
|
|
205
|
+
this.handleBlur = e => {
|
|
206
|
+
this.setState({
|
|
223
207
|
focused: false,
|
|
224
208
|
pressed: false
|
|
225
209
|
});
|
|
226
210
|
};
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
return _this;
|
|
211
|
+
this.state = startState;
|
|
212
|
+
this.waitingForClick = false;
|
|
213
|
+
this.enterClick = false;
|
|
231
214
|
}
|
|
232
|
-
|
|
233
|
-
_proto.navigateOrReset = function navigateOrReset(shouldNavigate) {
|
|
215
|
+
navigateOrReset(shouldNavigate) {
|
|
234
216
|
if (shouldNavigate) {
|
|
235
217
|
const {
|
|
236
218
|
history,
|
|
@@ -258,8 +240,8 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
258
240
|
waiting: false
|
|
259
241
|
});
|
|
260
242
|
}
|
|
261
|
-
}
|
|
262
|
-
|
|
243
|
+
}
|
|
244
|
+
handleSafeWithNav(safeWithNav, shouldNavigate) {
|
|
263
245
|
const {
|
|
264
246
|
skipClientNav,
|
|
265
247
|
history
|
|
@@ -285,8 +267,8 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
285
267
|
this.navigateOrReset(shouldNavigate);
|
|
286
268
|
});
|
|
287
269
|
}
|
|
288
|
-
}
|
|
289
|
-
|
|
270
|
+
}
|
|
271
|
+
runCallbackAndMaybeNavigate(e) {
|
|
290
272
|
const {
|
|
291
273
|
onClick = undefined,
|
|
292
274
|
beforeNav = undefined,
|
|
@@ -333,8 +315,8 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
333
315
|
} else {
|
|
334
316
|
this.navigateOrReset(shouldNavigate);
|
|
335
317
|
}
|
|
336
|
-
}
|
|
337
|
-
|
|
318
|
+
}
|
|
319
|
+
render() {
|
|
338
320
|
const childrenProps = this.props.disabled ? _extends({}, disabledHandlers, {
|
|
339
321
|
onFocus: this.handleFocus,
|
|
340
322
|
onBlur: this.handleBlur,
|
|
@@ -359,9 +341,8 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
359
341
|
children
|
|
360
342
|
} = this.props;
|
|
361
343
|
return children && children(this.state, childrenProps);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
}(React.Component);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
365
346
|
ClickableBehavior.defaultProps = {
|
|
366
347
|
disabled: false
|
|
367
348
|
};
|
|
@@ -385,39 +366,35 @@ const _excluded = ["href", "onClick", "skipClientNav", "beforeNav", "safeWithNav
|
|
|
385
366
|
const StyledAnchor = addStyle("a");
|
|
386
367
|
const StyledButton = addStyle("button");
|
|
387
368
|
const StyledLink = addStyle(Link);
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
const useClient = router && !_this.props.skipClientNav && isClientSideUrl(_this.props.href || "");
|
|
396
|
-
if (activeHref && useClient && _this.props.href) {
|
|
369
|
+
class Clickable extends React.Component {
|
|
370
|
+
constructor(...args) {
|
|
371
|
+
super(...args);
|
|
372
|
+
this.getCorrectTag = (clickableState, router, commonProps) => {
|
|
373
|
+
const activeHref = this.props.href && !this.props.disabled;
|
|
374
|
+
const useClient = router && !this.props.skipClientNav && isClientSideUrl(this.props.href || "");
|
|
375
|
+
if (activeHref && useClient && this.props.href) {
|
|
397
376
|
return React.createElement(StyledLink, _extends({}, commonProps, {
|
|
398
|
-
to:
|
|
399
|
-
role:
|
|
400
|
-
target:
|
|
401
|
-
"aria-disabled":
|
|
402
|
-
}),
|
|
377
|
+
to: this.props.href,
|
|
378
|
+
role: this.props.role,
|
|
379
|
+
target: this.props.target || undefined,
|
|
380
|
+
"aria-disabled": this.props.disabled ? "true" : undefined
|
|
381
|
+
}), this.props.children(clickableState));
|
|
403
382
|
} else if (activeHref && !useClient) {
|
|
404
383
|
return React.createElement(StyledAnchor, _extends({}, commonProps, {
|
|
405
|
-
href:
|
|
406
|
-
role:
|
|
407
|
-
target:
|
|
408
|
-
"aria-disabled":
|
|
409
|
-
}),
|
|
384
|
+
href: this.props.href,
|
|
385
|
+
role: this.props.role,
|
|
386
|
+
target: this.props.target || undefined,
|
|
387
|
+
"aria-disabled": this.props.disabled ? "true" : undefined
|
|
388
|
+
}), this.props.children(clickableState));
|
|
410
389
|
} else {
|
|
411
390
|
return React.createElement(StyledButton, _extends({}, commonProps, {
|
|
412
391
|
type: "button",
|
|
413
|
-
"aria-disabled":
|
|
414
|
-
}),
|
|
392
|
+
"aria-disabled": this.props.disabled
|
|
393
|
+
}), this.props.children(clickableState));
|
|
415
394
|
}
|
|
416
395
|
};
|
|
417
|
-
return _this;
|
|
418
396
|
}
|
|
419
|
-
|
|
420
|
-
_proto.renderClickableBehavior = function renderClickableBehavior(router) {
|
|
397
|
+
renderClickableBehavior(router) {
|
|
421
398
|
const _this$props = this.props,
|
|
422
399
|
{
|
|
423
400
|
href,
|
|
@@ -464,12 +441,11 @@ let Clickable = function (_React$Component) {
|
|
|
464
441
|
style: getStyle(state)
|
|
465
442
|
}, childrenProps)));
|
|
466
443
|
}
|
|
467
|
-
}
|
|
468
|
-
|
|
444
|
+
}
|
|
445
|
+
render() {
|
|
469
446
|
return React.createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
}(React.Component);
|
|
447
|
+
}
|
|
448
|
+
}
|
|
473
449
|
Clickable.defaultProps = {
|
|
474
450
|
light: false,
|
|
475
451
|
disabled: false
|
package/dist/index.js
CHANGED
|
@@ -60,20 +60,6 @@ function _extends() {
|
|
|
60
60
|
return _extends.apply(this, arguments);
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
function _setPrototypeOf(o, p) {
|
|
64
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
65
|
-
o.__proto__ = p;
|
|
66
|
-
return o;
|
|
67
|
-
};
|
|
68
|
-
return _setPrototypeOf(o, p);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function _inheritsLoose(subClass, superClass) {
|
|
72
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
73
|
-
subClass.prototype.constructor = subClass;
|
|
74
|
-
_setPrototypeOf(subClass, superClass);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
63
|
const getAppropriateTriggersForRole = role => {
|
|
78
64
|
switch (role) {
|
|
79
65
|
case "link":
|
|
@@ -121,9 +107,8 @@ const startState = {
|
|
|
121
107
|
pressed: false,
|
|
122
108
|
waiting: false
|
|
123
109
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
ClickableBehavior.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
|
|
110
|
+
class ClickableBehavior extends React__namespace.Component {
|
|
111
|
+
static getDerivedStateFromProps(props, state) {
|
|
127
112
|
if (props.disabled) {
|
|
128
113
|
return _extends({}, startState, {
|
|
129
114
|
focused: state.focused
|
|
@@ -131,75 +116,74 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
131
116
|
} else {
|
|
132
117
|
return null;
|
|
133
118
|
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
_this.handleClick = e => {
|
|
119
|
+
}
|
|
120
|
+
constructor(props) {
|
|
121
|
+
super(props);
|
|
122
|
+
this.waitingForClick = void 0;
|
|
123
|
+
this.enterClick = void 0;
|
|
124
|
+
this.handleClick = e => {
|
|
141
125
|
const {
|
|
142
126
|
onClick = undefined,
|
|
143
127
|
beforeNav = undefined,
|
|
144
128
|
safeWithNav = undefined
|
|
145
|
-
} =
|
|
146
|
-
if (
|
|
129
|
+
} = this.props;
|
|
130
|
+
if (this.enterClick) {
|
|
147
131
|
return;
|
|
148
132
|
}
|
|
149
133
|
if (onClick || beforeNav || safeWithNav) {
|
|
150
|
-
|
|
134
|
+
this.waitingForClick = false;
|
|
151
135
|
}
|
|
152
|
-
|
|
136
|
+
this.runCallbackAndMaybeNavigate(e);
|
|
153
137
|
};
|
|
154
|
-
|
|
155
|
-
if (!
|
|
156
|
-
|
|
138
|
+
this.handleMouseEnter = e => {
|
|
139
|
+
if (!this.waitingForClick) {
|
|
140
|
+
this.setState({
|
|
157
141
|
hovered: true
|
|
158
142
|
});
|
|
159
143
|
}
|
|
160
144
|
};
|
|
161
|
-
|
|
162
|
-
if (!
|
|
163
|
-
|
|
145
|
+
this.handleMouseLeave = () => {
|
|
146
|
+
if (!this.waitingForClick) {
|
|
147
|
+
this.setState({
|
|
164
148
|
hovered: false,
|
|
165
149
|
pressed: false,
|
|
166
150
|
focused: false
|
|
167
151
|
});
|
|
168
152
|
}
|
|
169
153
|
};
|
|
170
|
-
|
|
171
|
-
|
|
154
|
+
this.handleMouseDown = () => {
|
|
155
|
+
this.setState({
|
|
172
156
|
pressed: true
|
|
173
157
|
});
|
|
174
158
|
};
|
|
175
|
-
|
|
176
|
-
|
|
159
|
+
this.handleMouseUp = e => {
|
|
160
|
+
this.setState({
|
|
177
161
|
pressed: false,
|
|
178
162
|
focused: false
|
|
179
163
|
});
|
|
180
164
|
};
|
|
181
|
-
|
|
182
|
-
|
|
165
|
+
this.handleTouchStart = () => {
|
|
166
|
+
this.setState({
|
|
183
167
|
pressed: true
|
|
184
168
|
});
|
|
185
169
|
};
|
|
186
|
-
|
|
187
|
-
|
|
170
|
+
this.handleTouchEnd = () => {
|
|
171
|
+
this.setState({
|
|
188
172
|
pressed: false
|
|
189
173
|
});
|
|
190
|
-
|
|
174
|
+
this.waitingForClick = true;
|
|
191
175
|
};
|
|
192
|
-
|
|
193
|
-
|
|
176
|
+
this.handleTouchCancel = () => {
|
|
177
|
+
this.setState({
|
|
194
178
|
pressed: false
|
|
195
179
|
});
|
|
196
|
-
|
|
180
|
+
this.waitingForClick = true;
|
|
197
181
|
};
|
|
198
|
-
|
|
182
|
+
this.handleKeyDown = e => {
|
|
199
183
|
const {
|
|
200
184
|
onKeyDown,
|
|
201
185
|
role
|
|
202
|
-
} =
|
|
186
|
+
} = this.props;
|
|
203
187
|
if (onKeyDown) {
|
|
204
188
|
onKeyDown(e);
|
|
205
189
|
}
|
|
@@ -210,18 +194,18 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
210
194
|
} = getAppropriateTriggersForRole(role);
|
|
211
195
|
if (triggerOnEnter && keyCode === keyCodes.enter || triggerOnSpace && keyCode === keyCodes.space) {
|
|
212
196
|
e.preventDefault();
|
|
213
|
-
|
|
197
|
+
this.setState({
|
|
214
198
|
pressed: true
|
|
215
199
|
});
|
|
216
200
|
} else if (!triggerOnEnter && keyCode === keyCodes.enter) {
|
|
217
|
-
|
|
201
|
+
this.enterClick = true;
|
|
218
202
|
}
|
|
219
203
|
};
|
|
220
|
-
|
|
204
|
+
this.handleKeyUp = e => {
|
|
221
205
|
const {
|
|
222
206
|
onKeyUp,
|
|
223
207
|
role
|
|
224
|
-
} =
|
|
208
|
+
} = this.props;
|
|
225
209
|
if (onKeyUp) {
|
|
226
210
|
onKeyUp(e);
|
|
227
211
|
}
|
|
@@ -231,33 +215,31 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
231
215
|
triggerOnSpace
|
|
232
216
|
} = getAppropriateTriggersForRole(role);
|
|
233
217
|
if (triggerOnEnter && keyCode === keyCodes.enter || triggerOnSpace && keyCode === keyCodes.space) {
|
|
234
|
-
|
|
218
|
+
this.setState({
|
|
235
219
|
pressed: false,
|
|
236
220
|
focused: true
|
|
237
221
|
});
|
|
238
|
-
|
|
222
|
+
this.runCallbackAndMaybeNavigate(e);
|
|
239
223
|
} else if (!triggerOnEnter && keyCode === keyCodes.enter) {
|
|
240
|
-
|
|
224
|
+
this.enterClick = false;
|
|
241
225
|
}
|
|
242
226
|
};
|
|
243
|
-
|
|
244
|
-
|
|
227
|
+
this.handleFocus = e => {
|
|
228
|
+
this.setState({
|
|
245
229
|
focused: true
|
|
246
230
|
});
|
|
247
231
|
};
|
|
248
|
-
|
|
249
|
-
|
|
232
|
+
this.handleBlur = e => {
|
|
233
|
+
this.setState({
|
|
250
234
|
focused: false,
|
|
251
235
|
pressed: false
|
|
252
236
|
});
|
|
253
237
|
};
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
return _this;
|
|
238
|
+
this.state = startState;
|
|
239
|
+
this.waitingForClick = false;
|
|
240
|
+
this.enterClick = false;
|
|
258
241
|
}
|
|
259
|
-
|
|
260
|
-
_proto.navigateOrReset = function navigateOrReset(shouldNavigate) {
|
|
242
|
+
navigateOrReset(shouldNavigate) {
|
|
261
243
|
if (shouldNavigate) {
|
|
262
244
|
const {
|
|
263
245
|
history,
|
|
@@ -285,8 +267,8 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
285
267
|
waiting: false
|
|
286
268
|
});
|
|
287
269
|
}
|
|
288
|
-
}
|
|
289
|
-
|
|
270
|
+
}
|
|
271
|
+
handleSafeWithNav(safeWithNav, shouldNavigate) {
|
|
290
272
|
const {
|
|
291
273
|
skipClientNav,
|
|
292
274
|
history
|
|
@@ -312,8 +294,8 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
312
294
|
this.navigateOrReset(shouldNavigate);
|
|
313
295
|
});
|
|
314
296
|
}
|
|
315
|
-
}
|
|
316
|
-
|
|
297
|
+
}
|
|
298
|
+
runCallbackAndMaybeNavigate(e) {
|
|
317
299
|
const {
|
|
318
300
|
onClick = undefined,
|
|
319
301
|
beforeNav = undefined,
|
|
@@ -360,8 +342,8 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
360
342
|
} else {
|
|
361
343
|
this.navigateOrReset(shouldNavigate);
|
|
362
344
|
}
|
|
363
|
-
}
|
|
364
|
-
|
|
345
|
+
}
|
|
346
|
+
render() {
|
|
365
347
|
const childrenProps = this.props.disabled ? _extends({}, disabledHandlers, {
|
|
366
348
|
onFocus: this.handleFocus,
|
|
367
349
|
onBlur: this.handleBlur,
|
|
@@ -386,9 +368,8 @@ let ClickableBehavior = function (_React$Component) {
|
|
|
386
368
|
children
|
|
387
369
|
} = this.props;
|
|
388
370
|
return children && children(this.state, childrenProps);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
}(React__namespace.Component);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
392
373
|
ClickableBehavior.defaultProps = {
|
|
393
374
|
disabled: false
|
|
394
375
|
};
|
|
@@ -412,39 +393,35 @@ const _excluded = ["href", "onClick", "skipClientNav", "beforeNav", "safeWithNav
|
|
|
412
393
|
const StyledAnchor = wonderBlocksCore.addStyle("a");
|
|
413
394
|
const StyledButton = wonderBlocksCore.addStyle("button");
|
|
414
395
|
const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
const useClient = router && !_this.props.skipClientNav && isClientSideUrl(_this.props.href || "");
|
|
423
|
-
if (activeHref && useClient && _this.props.href) {
|
|
396
|
+
class Clickable extends React__namespace.Component {
|
|
397
|
+
constructor(...args) {
|
|
398
|
+
super(...args);
|
|
399
|
+
this.getCorrectTag = (clickableState, router, commonProps) => {
|
|
400
|
+
const activeHref = this.props.href && !this.props.disabled;
|
|
401
|
+
const useClient = router && !this.props.skipClientNav && isClientSideUrl(this.props.href || "");
|
|
402
|
+
if (activeHref && useClient && this.props.href) {
|
|
424
403
|
return React__namespace.createElement(StyledLink, _extends({}, commonProps, {
|
|
425
|
-
to:
|
|
426
|
-
role:
|
|
427
|
-
target:
|
|
428
|
-
"aria-disabled":
|
|
429
|
-
}),
|
|
404
|
+
to: this.props.href,
|
|
405
|
+
role: this.props.role,
|
|
406
|
+
target: this.props.target || undefined,
|
|
407
|
+
"aria-disabled": this.props.disabled ? "true" : undefined
|
|
408
|
+
}), this.props.children(clickableState));
|
|
430
409
|
} else if (activeHref && !useClient) {
|
|
431
410
|
return React__namespace.createElement(StyledAnchor, _extends({}, commonProps, {
|
|
432
|
-
href:
|
|
433
|
-
role:
|
|
434
|
-
target:
|
|
435
|
-
"aria-disabled":
|
|
436
|
-
}),
|
|
411
|
+
href: this.props.href,
|
|
412
|
+
role: this.props.role,
|
|
413
|
+
target: this.props.target || undefined,
|
|
414
|
+
"aria-disabled": this.props.disabled ? "true" : undefined
|
|
415
|
+
}), this.props.children(clickableState));
|
|
437
416
|
} else {
|
|
438
417
|
return React__namespace.createElement(StyledButton, _extends({}, commonProps, {
|
|
439
418
|
type: "button",
|
|
440
|
-
"aria-disabled":
|
|
441
|
-
}),
|
|
419
|
+
"aria-disabled": this.props.disabled
|
|
420
|
+
}), this.props.children(clickableState));
|
|
442
421
|
}
|
|
443
422
|
};
|
|
444
|
-
return _this;
|
|
445
423
|
}
|
|
446
|
-
|
|
447
|
-
_proto.renderClickableBehavior = function renderClickableBehavior(router) {
|
|
424
|
+
renderClickableBehavior(router) {
|
|
448
425
|
const _this$props = this.props,
|
|
449
426
|
{
|
|
450
427
|
href,
|
|
@@ -491,12 +468,11 @@ let Clickable = function (_React$Component) {
|
|
|
491
468
|
style: getStyle(state)
|
|
492
469
|
}, childrenProps)));
|
|
493
470
|
}
|
|
494
|
-
}
|
|
495
|
-
|
|
471
|
+
}
|
|
472
|
+
render() {
|
|
496
473
|
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
}(React__namespace.Component);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
500
476
|
Clickable.defaultProps = {
|
|
501
477
|
light: false,
|
|
502
478
|
disabled: false
|
package/dist/index.js.flow
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Flowtype definitions for
|
|
2
|
+
* Flowtype definitions for data
|
|
3
3
|
* Generated by Flowgen from a Typescript Definition
|
|
4
4
|
* Flowgen v1.21.0
|
|
5
5
|
* @flow
|
|
6
6
|
*/
|
|
7
|
-
|
|
8
7
|
import * as React from "react";
|
|
9
8
|
import ClickableBehavior from "../components/clickable-behavior";
|
|
10
9
|
declare export default function getClickableBehavior(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-clickable",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.6",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"description": "Clickable component for Wonder-Blocks.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
19
|
"@khanacademy/wonder-blocks-color": "^2.0.1",
|
|
20
|
-
"@khanacademy/wonder-blocks-core": "^5.0.
|
|
20
|
+
"@khanacademy/wonder-blocks-core": "^5.0.4"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"aphrodite": "^1.2.5",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"react-router-dom": "5.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"wb-dev-build-settings": "^0.9.
|
|
30
|
+
"wb-dev-build-settings": "^0.9.5"
|
|
31
31
|
}
|
|
32
32
|
}
|