@khanacademy/wonder-blocks-clickable 2.4.4 → 2.4.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.
Files changed (30) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/dist/components/clickable-behavior.d.ts +248 -0
  3. package/dist/components/clickable-behavior.js.flow +296 -0
  4. package/dist/components/clickable.d.ts +150 -0
  5. package/dist/components/clickable.js.flow +176 -0
  6. package/dist/es/index.js +147 -147
  7. package/dist/index.d.ts +7 -0
  8. package/dist/index.js +169 -171
  9. package/dist/index.js.flow +18 -2
  10. package/dist/util/get-clickable-behavior.d.ts +25 -0
  11. package/dist/util/get-clickable-behavior.js.flow +19 -0
  12. package/dist/util/is-client-side-url.d.ts +7 -0
  13. package/dist/util/is-client-side-url.js.flow +14 -0
  14. package/package.json +5 -5
  15. package/src/components/__tests__/{clickable-behavior.test.js → clickable-behavior.test.tsx} +140 -84
  16. package/src/components/__tests__/{clickable.test.js → clickable.test.tsx} +28 -27
  17. package/src/components/{clickable-behavior.js → clickable-behavior.ts} +82 -104
  18. package/src/components/{clickable.js → clickable.tsx} +111 -168
  19. package/src/{index.js → index.ts} +5 -6
  20. package/src/util/__tests__/{get-clickable-behavior.test.js → get-clickable-behavior.test.tsx} +2 -3
  21. package/src/util/__tests__/{is-client-side-url.js.test.js → is-client-side-url.js.test.ts} +3 -4
  22. package/src/util/{get-clickable-behavior.js → get-clickable-behavior.ts} +11 -5
  23. package/src/util/{is-client-side-url.js → is-client-side-url.ts} +0 -1
  24. package/tsconfig.json +12 -0
  25. package/tsconfig.tsbuildinfo +1 -0
  26. package/src/components/__docs__/accessibility.stories.mdx +0 -152
  27. package/src/components/__docs__/clickable-behavior.argtypes.js +0 -64
  28. package/src/components/__docs__/clickable-behavior.stories.js +0 -178
  29. package/src/components/__docs__/clickable.argtypes.js +0 -237
  30. package/src/components/__docs__/clickable.stories.js +0 -307
package/dist/index.js CHANGED
@@ -2,8 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
6
- var _extends = require('@babel/runtime/helpers/extends');
7
5
  var React = require('react');
8
6
  var aphrodite = require('aphrodite');
9
7
  var reactRouterDom = require('react-router-dom');
@@ -14,28 +12,68 @@ var Color = require('@khanacademy/wonder-blocks-color');
14
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
13
 
16
14
  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);
15
+ if (e && e.__esModule) return e;
16
+ var n = Object.create(null);
17
+ if (e) {
18
+ Object.keys(e).forEach(function (k) {
19
+ if (k !== 'default') {
20
+ var d = Object.getOwnPropertyDescriptor(e, k);
21
+ Object.defineProperty(n, k, d.get ? d : {
22
+ enumerable: true,
23
+ get: function () { return e[k]; }
24
+ });
25
+ }
26
+ });
27
+ }
28
+ n["default"] = e;
29
+ return Object.freeze(n);
32
30
  }
33
31
 
34
- var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
35
- var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
36
32
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
37
33
  var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
38
34
 
35
+ function _objectWithoutPropertiesLoose(source, excluded) {
36
+ if (source == null) return {};
37
+ var target = {};
38
+ var sourceKeys = Object.keys(source);
39
+ var key, i;
40
+ for (i = 0; i < sourceKeys.length; i++) {
41
+ key = sourceKeys[i];
42
+ if (excluded.indexOf(key) >= 0) continue;
43
+ target[key] = source[key];
44
+ }
45
+ return target;
46
+ }
47
+
48
+ function _extends() {
49
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
50
+ for (var i = 1; i < arguments.length; i++) {
51
+ var source = arguments[i];
52
+ for (var key in source) {
53
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
54
+ target[key] = source[key];
55
+ }
56
+ }
57
+ }
58
+ return target;
59
+ };
60
+ return _extends.apply(this, arguments);
61
+ }
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
+
39
77
  const getAppropriateTriggersForRole = role => {
40
78
  switch (role) {
41
79
  case "link":
@@ -43,7 +81,6 @@ const getAppropriateTriggersForRole = role => {
43
81
  triggerOnEnter: true,
44
82
  triggerOnSpace: false
45
83
  };
46
-
47
84
  case "checkbox":
48
85
  case "radio":
49
86
  case "listbox":
@@ -51,7 +88,6 @@ const getAppropriateTriggersForRole = role => {
51
88
  triggerOnEnter: false,
52
89
  triggerOnSpace: true
53
90
  };
54
-
55
91
  case "button":
56
92
  case "menuitem":
57
93
  case "menu":
@@ -63,7 +99,6 @@ const getAppropriateTriggersForRole = role => {
63
99
  };
64
100
  }
65
101
  };
66
-
67
102
  const disabledHandlers = {
68
103
  onClick: () => void 0,
69
104
  onMouseEnter: () => void 0,
@@ -86,161 +121,143 @@ const startState = {
86
121
  pressed: false,
87
122
  waiting: false
88
123
  };
89
- class ClickableBehavior extends React__namespace.Component {
90
- static getDerivedStateFromProps(props, state) {
124
+ let ClickableBehavior = function (_React$Component) {
125
+ _inheritsLoose(ClickableBehavior, _React$Component);
126
+ ClickableBehavior.getDerivedStateFromProps = function getDerivedStateFromProps(props, state) {
91
127
  if (props.disabled) {
92
- return _extends__default["default"]({}, startState, {
128
+ return _extends({}, startState, {
93
129
  focused: state.focused
94
130
  });
95
131
  } else {
96
132
  return null;
97
133
  }
98
- }
99
-
100
- constructor(props) {
101
- super(props);
102
-
103
- this.handleClick = e => {
134
+ };
135
+ function ClickableBehavior(props) {
136
+ var _this;
137
+ _this = _React$Component.call(this, props) || this;
138
+ _this.waitingForClick = void 0;
139
+ _this.enterClick = void 0;
140
+ _this.handleClick = e => {
104
141
  const {
105
142
  onClick = undefined,
106
143
  beforeNav = undefined,
107
144
  safeWithNav = undefined
108
- } = this.props;
109
-
110
- if (this.enterClick) {
145
+ } = _this.props;
146
+ if (_this.enterClick) {
111
147
  return;
112
148
  }
113
-
114
149
  if (onClick || beforeNav || safeWithNav) {
115
- this.waitingForClick = false;
150
+ _this.waitingForClick = false;
116
151
  }
117
-
118
- this.runCallbackAndMaybeNavigate(e);
152
+ _this.runCallbackAndMaybeNavigate(e);
119
153
  };
120
-
121
- this.handleMouseEnter = e => {
122
- if (!this.waitingForClick) {
123
- this.setState({
154
+ _this.handleMouseEnter = e => {
155
+ if (!_this.waitingForClick) {
156
+ _this.setState({
124
157
  hovered: true
125
158
  });
126
159
  }
127
160
  };
128
-
129
- this.handleMouseLeave = () => {
130
- if (!this.waitingForClick) {
131
- this.setState({
161
+ _this.handleMouseLeave = () => {
162
+ if (!_this.waitingForClick) {
163
+ _this.setState({
132
164
  hovered: false,
133
165
  pressed: false,
134
166
  focused: false
135
167
  });
136
168
  }
137
169
  };
138
-
139
- this.handleMouseDown = () => {
140
- this.setState({
170
+ _this.handleMouseDown = () => {
171
+ _this.setState({
141
172
  pressed: true
142
173
  });
143
174
  };
144
-
145
- this.handleMouseUp = e => {
146
- this.setState({
175
+ _this.handleMouseUp = e => {
176
+ _this.setState({
147
177
  pressed: false,
148
178
  focused: false
149
179
  });
150
180
  };
151
-
152
- this.handleTouchStart = () => {
153
- this.setState({
181
+ _this.handleTouchStart = () => {
182
+ _this.setState({
154
183
  pressed: true
155
184
  });
156
185
  };
157
-
158
- this.handleTouchEnd = () => {
159
- this.setState({
186
+ _this.handleTouchEnd = () => {
187
+ _this.setState({
160
188
  pressed: false
161
189
  });
162
- this.waitingForClick = true;
190
+ _this.waitingForClick = true;
163
191
  };
164
-
165
- this.handleTouchCancel = () => {
166
- this.setState({
192
+ _this.handleTouchCancel = () => {
193
+ _this.setState({
167
194
  pressed: false
168
195
  });
169
- this.waitingForClick = true;
196
+ _this.waitingForClick = true;
170
197
  };
171
-
172
- this.handleKeyDown = e => {
198
+ _this.handleKeyDown = e => {
173
199
  const {
174
200
  onKeyDown,
175
201
  role
176
- } = this.props;
177
-
202
+ } = _this.props;
178
203
  if (onKeyDown) {
179
204
  onKeyDown(e);
180
205
  }
181
-
182
206
  const keyCode = e.which || e.keyCode;
183
207
  const {
184
208
  triggerOnEnter,
185
209
  triggerOnSpace
186
210
  } = getAppropriateTriggersForRole(role);
187
-
188
211
  if (triggerOnEnter && keyCode === keyCodes.enter || triggerOnSpace && keyCode === keyCodes.space) {
189
212
  e.preventDefault();
190
- this.setState({
213
+ _this.setState({
191
214
  pressed: true
192
215
  });
193
216
  } else if (!triggerOnEnter && keyCode === keyCodes.enter) {
194
- this.enterClick = true;
217
+ _this.enterClick = true;
195
218
  }
196
219
  };
197
-
198
- this.handleKeyUp = e => {
220
+ _this.handleKeyUp = e => {
199
221
  const {
200
222
  onKeyUp,
201
223
  role
202
- } = this.props;
203
-
224
+ } = _this.props;
204
225
  if (onKeyUp) {
205
226
  onKeyUp(e);
206
227
  }
207
-
208
228
  const keyCode = e.which || e.keyCode;
209
229
  const {
210
230
  triggerOnEnter,
211
231
  triggerOnSpace
212
232
  } = getAppropriateTriggersForRole(role);
213
-
214
233
  if (triggerOnEnter && keyCode === keyCodes.enter || triggerOnSpace && keyCode === keyCodes.space) {
215
- this.setState({
234
+ _this.setState({
216
235
  pressed: false,
217
236
  focused: true
218
237
  });
219
- this.runCallbackAndMaybeNavigate(e);
238
+ _this.runCallbackAndMaybeNavigate(e);
220
239
  } else if (!triggerOnEnter && keyCode === keyCodes.enter) {
221
- this.enterClick = false;
240
+ _this.enterClick = false;
222
241
  }
223
242
  };
224
-
225
- this.handleFocus = e => {
226
- this.setState({
243
+ _this.handleFocus = e => {
244
+ _this.setState({
227
245
  focused: true
228
246
  });
229
247
  };
230
-
231
- this.handleBlur = e => {
232
- this.setState({
248
+ _this.handleBlur = e => {
249
+ _this.setState({
233
250
  focused: false,
234
251
  pressed: false
235
252
  });
236
253
  };
237
-
238
- this.state = startState;
239
- this.waitingForClick = false;
240
- this.enterClick = false;
254
+ _this.state = startState;
255
+ _this.waitingForClick = false;
256
+ _this.enterClick = false;
257
+ return _this;
241
258
  }
242
-
243
- navigateOrReset(shouldNavigate) {
259
+ var _proto = ClickableBehavior.prototype;
260
+ _proto.navigateOrReset = function navigateOrReset(shouldNavigate) {
244
261
  if (shouldNavigate) {
245
262
  const {
246
263
  history,
@@ -248,7 +265,6 @@ class ClickableBehavior extends React__namespace.Component {
248
265
  skipClientNav,
249
266
  target = undefined
250
267
  } = this.props;
251
-
252
268
  if (href) {
253
269
  if (target === "_blank") {
254
270
  window.open(href, "_blank");
@@ -269,14 +285,12 @@ class ClickableBehavior extends React__namespace.Component {
269
285
  waiting: false
270
286
  });
271
287
  }
272
- }
273
-
274
- handleSafeWithNav(safeWithNav, shouldNavigate) {
288
+ };
289
+ _proto.handleSafeWithNav = function handleSafeWithNav(safeWithNav, shouldNavigate) {
275
290
  const {
276
291
  skipClientNav,
277
292
  history
278
293
  } = this.props;
279
-
280
294
  if (history && !skipClientNav || this.props.target === "_blank") {
281
295
  safeWithNav();
282
296
  this.navigateOrReset(shouldNavigate);
@@ -287,22 +301,19 @@ class ClickableBehavior extends React__namespace.Component {
287
301
  waiting: true
288
302
  });
289
303
  }
290
-
291
304
  return safeWithNav().then(() => {
292
305
  if (!this.state.waiting) {
293
306
  this.setState({
294
307
  waiting: true
295
308
  });
296
309
  }
297
-
298
310
  return;
299
311
  }).catch(error => {}).finally(() => {
300
312
  this.navigateOrReset(shouldNavigate);
301
313
  });
302
314
  }
303
- }
304
-
305
- runCallbackAndMaybeNavigate(e) {
315
+ };
316
+ _proto.runCallbackAndMaybeNavigate = function runCallbackAndMaybeNavigate(e) {
306
317
  const {
307
318
  onClick = undefined,
308
319
  beforeNav = undefined,
@@ -312,21 +323,16 @@ class ClickableBehavior extends React__namespace.Component {
312
323
  } = this.props;
313
324
  let shouldNavigate = true;
314
325
  let canSubmit = true;
315
-
316
326
  if (onClick) {
317
327
  onClick(e);
318
328
  }
319
-
320
329
  if (e.defaultPrevented) {
321
330
  shouldNavigate = false;
322
331
  canSubmit = false;
323
332
  }
324
-
325
333
  e.preventDefault();
326
-
327
334
  if (!href && type === "submit" && canSubmit) {
328
335
  let target = e.currentTarget;
329
-
330
336
  while (target) {
331
337
  if (target instanceof window.HTMLFormElement) {
332
338
  const event = new window.Event("submit", {
@@ -335,11 +341,9 @@ class ClickableBehavior extends React__namespace.Component {
335
341
  target.dispatchEvent(event);
336
342
  break;
337
343
  }
338
-
339
344
  target = target.parentElement;
340
345
  }
341
346
  }
342
-
343
347
  if (beforeNav) {
344
348
  this.setState({
345
349
  waiting: true
@@ -356,10 +360,9 @@ class ClickableBehavior extends React__namespace.Component {
356
360
  } else {
357
361
  this.navigateOrReset(shouldNavigate);
358
362
  }
359
- }
360
-
361
- render() {
362
- const childrenProps = this.props.disabled ? _extends__default["default"]({}, disabledHandlers, {
363
+ };
364
+ _proto.render = function render() {
365
+ const childrenProps = this.props.disabled ? _extends({}, disabledHandlers, {
363
366
  onFocus: this.handleFocus,
364
367
  onBlur: this.handleBlur,
365
368
  tabIndex: this.props.tabIndex
@@ -383,9 +386,9 @@ class ClickableBehavior extends React__namespace.Component {
383
386
  children
384
387
  } = this.props;
385
388
  return children && children(this.state, childrenProps);
386
- }
387
-
388
- }
389
+ };
390
+ return ClickableBehavior;
391
+ }(React__namespace.Component);
389
392
  ClickableBehavior.defaultProps = {
390
393
  disabled: false
391
394
  };
@@ -394,7 +397,6 @@ const isClientSideUrl = href => {
394
397
  if (typeof href !== "string") {
395
398
  return false;
396
399
  }
397
-
398
400
  return !/^(https?:)?\/\//i.test(href) && !/^([^#]*#[\w-]*|[\w\-.]+:)/.test(href);
399
401
  };
400
402
 
@@ -403,7 +405,6 @@ function getClickableBehavior(href, skipClientNav, router) {
403
405
  if (router && skipClientNav !== true && href && isClientSideUrl(href)) {
404
406
  return ClickableBehaviorWithRouter;
405
407
  }
406
-
407
408
  return ClickableBehavior;
408
409
  }
409
410
 
@@ -411,60 +412,58 @@ const _excluded = ["href", "onClick", "skipClientNav", "beforeNav", "safeWithNav
411
412
  const StyledAnchor = wonderBlocksCore.addStyle("a");
412
413
  const StyledButton = wonderBlocksCore.addStyle("button");
413
414
  const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
414
- class Clickable extends React__namespace.Component {
415
- constructor(...args) {
416
- super(...args);
417
-
418
- this.getCorrectTag = (clickableState, router, commonProps) => {
419
- const activeHref = this.props.href && !this.props.disabled;
420
- const useClient = router && !this.props.skipClientNav && isClientSideUrl(this.props.href || "");
421
-
422
- if (activeHref && useClient && this.props.href) {
423
- return React__namespace.createElement(StyledLink, _extends__default["default"]({}, commonProps, {
424
- to: this.props.href,
425
- role: this.props.role,
426
- target: this.props.target || undefined,
427
- "aria-disabled": this.props.disabled ? "true" : undefined
428
- }), this.props.children(clickableState));
415
+ let Clickable = function (_React$Component) {
416
+ _inheritsLoose(Clickable, _React$Component);
417
+ function Clickable(...args) {
418
+ var _this;
419
+ _this = _React$Component.call.apply(_React$Component, [this].concat(args)) || this;
420
+ _this.getCorrectTag = (clickableState, router, commonProps) => {
421
+ const activeHref = _this.props.href && !_this.props.disabled;
422
+ const useClient = router && !_this.props.skipClientNav && isClientSideUrl(_this.props.href || "");
423
+ if (activeHref && useClient && _this.props.href) {
424
+ return React__namespace.createElement(StyledLink, _extends({}, commonProps, {
425
+ to: _this.props.href,
426
+ role: _this.props.role,
427
+ target: _this.props.target || undefined,
428
+ "aria-disabled": _this.props.disabled ? "true" : undefined
429
+ }), _this.props.children(clickableState));
429
430
  } else if (activeHref && !useClient) {
430
- return React__namespace.createElement(StyledAnchor, _extends__default["default"]({}, commonProps, {
431
- href: this.props.href,
432
- role: this.props.role,
433
- target: this.props.target || undefined,
434
- "aria-disabled": this.props.disabled ? "true" : undefined
435
- }), this.props.children(clickableState));
431
+ return React__namespace.createElement(StyledAnchor, _extends({}, commonProps, {
432
+ href: _this.props.href,
433
+ role: _this.props.role,
434
+ target: _this.props.target || undefined,
435
+ "aria-disabled": _this.props.disabled ? "true" : undefined
436
+ }), _this.props.children(clickableState));
436
437
  } else {
437
- return React__namespace.createElement(StyledButton, _extends__default["default"]({}, commonProps, {
438
+ return React__namespace.createElement(StyledButton, _extends({}, commonProps, {
438
439
  type: "button",
439
- "aria-disabled": this.props.disabled
440
- }), this.props.children(clickableState));
440
+ "aria-disabled": _this.props.disabled
441
+ }), _this.props.children(clickableState));
441
442
  }
442
443
  };
444
+ return _this;
443
445
  }
444
-
445
- renderClickableBehavior(router) {
446
+ var _proto = Clickable.prototype;
447
+ _proto.renderClickableBehavior = function renderClickableBehavior(router) {
446
448
  const _this$props = this.props,
447
- {
448
- href,
449
- onClick,
450
- skipClientNav,
451
- beforeNav = undefined,
452
- safeWithNav = undefined,
453
- style,
454
- target = undefined,
455
- testId,
456
- onKeyDown,
457
- onKeyUp,
458
- hideDefaultFocusRing,
459
- light,
460
- disabled
461
- } = _this$props,
462
- restProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded);
463
-
449
+ {
450
+ href,
451
+ onClick,
452
+ skipClientNav,
453
+ beforeNav = undefined,
454
+ safeWithNav = undefined,
455
+ style,
456
+ target = undefined,
457
+ testId,
458
+ onKeyDown,
459
+ onKeyUp,
460
+ hideDefaultFocusRing,
461
+ light,
462
+ disabled
463
+ } = _this$props,
464
+ restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
464
465
  const ClickableBehavior = getClickableBehavior(href, skipClientNav, router);
465
-
466
466
  const getStyle = state => [styles.reset, styles.link, !hideDefaultFocusRing && state.focused && (light ? styles.focusedLight : styles.focused), disabled && styles.disabled, style];
467
-
468
467
  if (beforeNav) {
469
468
  return React__namespace.createElement(ClickableBehavior, {
470
469
  href: href,
@@ -474,7 +473,7 @@ class Clickable extends React__namespace.Component {
474
473
  onKeyDown: onKeyDown,
475
474
  onKeyUp: onKeyUp,
476
475
  disabled: disabled
477
- }, (state, childrenProps) => this.getCorrectTag(state, router, _extends__default["default"]({}, restProps, {
476
+ }, (state, childrenProps) => this.getCorrectTag(state, router, _extends({}, restProps, {
478
477
  "data-test-id": testId,
479
478
  style: getStyle(state)
480
479
  }, childrenProps)));
@@ -487,18 +486,17 @@ class Clickable extends React__namespace.Component {
487
486
  onKeyUp: onKeyUp,
488
487
  target: target,
489
488
  disabled: disabled
490
- }, (state, childrenProps) => this.getCorrectTag(state, router, _extends__default["default"]({}, restProps, {
489
+ }, (state, childrenProps) => this.getCorrectTag(state, router, _extends({}, restProps, {
491
490
  "data-test-id": testId,
492
491
  style: getStyle(state)
493
492
  }, childrenProps)));
494
493
  }
495
- }
496
-
497
- render() {
494
+ };
495
+ _proto.render = function render() {
498
496
  return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
499
- }
500
-
501
- }
497
+ };
498
+ return Clickable;
499
+ }(React__namespace.Component);
502
500
  Clickable.defaultProps = {
503
501
  light: false,
504
502
  disabled: false
@@ -1,2 +1,18 @@
1
- // @flow
2
- export * from "../src/index.js";
1
+ /**
2
+ * Flowtype definitions for index
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import type {
9
+ ChildrenProps,
10
+ ClickableState,
11
+ ClickableRole,
12
+ } from "./components/clickable-behavior";
13
+ import Clickable from "./components/clickable";
14
+ declare export { default as ClickableBehavior } from "./components/clickable-behavior";
15
+ declare export { default as getClickableBehavior } from "./util/get-clickable-behavior";
16
+ declare export { isClientSideUrl } from "./util/is-client-side-url";
17
+ declare export { Clickable as default };
18
+ export type { ChildrenProps, ClickableState, ClickableRole };
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Returns either the default ClickableBehavior or a react-router aware version.
3
+ *
4
+ * The react-router aware version is returned if `router` is a react-router-dom
5
+ * router, `skipClientNav` is not `true`, and `href` is an internal URL.
6
+ *
7
+ * The `router` can be accessed via __RouterContext (imported from 'react-router')
8
+ * from a component rendered as a descendant of a BrowserRouter.
9
+ * See https://reacttraining.com/react-router/web/guides/basic-components.
10
+ */
11
+ import * as React from "react";
12
+ import ClickableBehavior from "../components/clickable-behavior";
13
+ export default function getClickableBehavior(
14
+ /**
15
+ * The URL to navigate to.
16
+ */
17
+ href?: string,
18
+ /**
19
+ * Should we skip using the react router and go to the page directly.
20
+ */
21
+ skipClientNav?: boolean,
22
+ /**
23
+ * router object added to the React context object by react-router-dom.
24
+ */
25
+ router?: any): React.ComponentType<JSX.LibraryManagedAttributes<typeof ClickableBehavior, React.ComponentProps<typeof ClickableBehavior>>>;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Flowtype definitions for get-clickable-behavior
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ import * as React from "react";
9
+ import ClickableBehavior from "../components/clickable-behavior";
10
+ declare export default function getClickableBehavior(
11
+ href?: string,
12
+ skipClientNav?: boolean,
13
+ router?: any
14
+ ): React.ComponentType<
15
+ JSX.LibraryManagedAttributes<
16
+ typeof ClickableBehavior,
17
+ React.ComponentProps<typeof ClickableBehavior>
18
+ >
19
+ >;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Returns:
3
+ * - false for hrefs staring with http://, https://, //.
4
+ * - false for '#', 'javascript:...', 'mailto:...', 'tel:...', etc.
5
+ * - true for all other values, e.g. /foo/bar
6
+ */
7
+ export declare const isClientSideUrl: (href: string) => boolean;
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Flowtype definitions for is-client-side-url
3
+ * Generated by Flowgen from a Typescript Definition
4
+ * Flowgen v1.21.0
5
+ * @flow
6
+ */
7
+
8
+ /**
9
+ * Returns:
10
+ * - false for hrefs staring with http://, https://, //.
11
+ * - false for '#', 'javascript:...', 'mailto:...', 'tel:...', etc.
12
+ * - true for all other values, e.g. /foo/bar
13
+ */
14
+ declare export var isClientSideUrl: (href: string) => boolean;