@khanacademy/wonder-blocks-clickable 2.2.1 → 2.2.2
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 +6 -0
- package/dist/es/index.js +13 -12
- package/dist/index.js +435 -141
- package/package.json +2 -3
- package/src/components/__tests__/clickable-behavior.test.js +42 -0
- package/src/components/__tests__/clickable.test.js +1 -0
- package/src/components/clickable-behavior.js +3 -1
- package/src/components/clickable.stories.js +4 -4
- package/LICENSE +0 -21
package/CHANGELOG.md
ADDED
package/dist/es/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
2
2
|
import _extends from '@babel/runtime/helpers/extends';
|
|
3
|
-
import
|
|
3
|
+
import * as React from 'react';
|
|
4
4
|
import { StyleSheet } from 'aphrodite';
|
|
5
5
|
import { withRouter, Link } from 'react-router-dom';
|
|
6
6
|
import { __RouterContext } from 'react-router';
|
|
@@ -52,7 +52,9 @@ const disabledHandlers = {
|
|
|
52
52
|
onKeyUp: () => void 0,
|
|
53
53
|
onFocus: () => void 0,
|
|
54
54
|
onBlur: () => void 0,
|
|
55
|
-
|
|
55
|
+
// Clickable components should still be tabbable so they can
|
|
56
|
+
// be used as anchors.
|
|
57
|
+
tabIndex: 0
|
|
56
58
|
};
|
|
57
59
|
const keyCodes = {
|
|
58
60
|
enter: 13,
|
|
@@ -143,7 +145,7 @@ const startState = {
|
|
|
143
145
|
* See https://reacttraining.com/react-router/web/guides/basic-components.
|
|
144
146
|
*/
|
|
145
147
|
|
|
146
|
-
class ClickableBehavior extends Component {
|
|
148
|
+
class ClickableBehavior extends React.Component {
|
|
147
149
|
static getDerivedStateFromProps(props, state) {
|
|
148
150
|
// If new props are disabled, reset the hovered/focused/pressed states
|
|
149
151
|
if (props.disabled) {
|
|
@@ -574,7 +576,7 @@ const StyledLink = addStyle(Link);
|
|
|
574
576
|
* ```
|
|
575
577
|
*/
|
|
576
578
|
|
|
577
|
-
class Clickable extends Component {
|
|
579
|
+
class Clickable extends React.Component {
|
|
578
580
|
constructor(...args) {
|
|
579
581
|
super(...args);
|
|
580
582
|
|
|
@@ -584,21 +586,21 @@ class Clickable extends Component {
|
|
|
584
586
|
// needs it to refine this.props.href to a string.
|
|
585
587
|
|
|
586
588
|
if (activeHref && useClient && this.props.href) {
|
|
587
|
-
return /*#__PURE__*/createElement(StyledLink, _extends({}, commonProps, {
|
|
589
|
+
return /*#__PURE__*/React.createElement(StyledLink, _extends({}, commonProps, {
|
|
588
590
|
to: this.props.href,
|
|
589
591
|
role: this.props.role,
|
|
590
592
|
target: this.props.target || undefined,
|
|
591
593
|
"aria-disabled": this.props.disabled ? "true" : undefined
|
|
592
594
|
}), this.props.children(clickableState));
|
|
593
595
|
} else if (activeHref && !useClient) {
|
|
594
|
-
return /*#__PURE__*/createElement(StyledAnchor, _extends({}, commonProps, {
|
|
596
|
+
return /*#__PURE__*/React.createElement(StyledAnchor, _extends({}, commonProps, {
|
|
595
597
|
href: this.props.href,
|
|
596
598
|
role: this.props.role,
|
|
597
599
|
target: this.props.target || undefined,
|
|
598
600
|
"aria-disabled": this.props.disabled ? "true" : undefined
|
|
599
601
|
}), this.props.children(clickableState));
|
|
600
602
|
} else {
|
|
601
|
-
return /*#__PURE__*/createElement(StyledButton, _extends({}, commonProps, {
|
|
603
|
+
return /*#__PURE__*/React.createElement(StyledButton, _extends({}, commonProps, {
|
|
602
604
|
type: "button",
|
|
603
605
|
disabled: this.props.disabled
|
|
604
606
|
}), this.props.children(clickableState));
|
|
@@ -630,7 +632,7 @@ class Clickable extends Component {
|
|
|
630
632
|
const getStyle = state => [styles.reset, styles.link, !hideDefaultFocusRing && state.focused && (light ? styles.focusedLight : styles.focused), style];
|
|
631
633
|
|
|
632
634
|
if (beforeNav) {
|
|
633
|
-
return /*#__PURE__*/createElement(ClickableBehavior, {
|
|
635
|
+
return /*#__PURE__*/React.createElement(ClickableBehavior, {
|
|
634
636
|
href: href,
|
|
635
637
|
onClick: onClick,
|
|
636
638
|
beforeNav: beforeNav,
|
|
@@ -643,7 +645,7 @@ class Clickable extends Component {
|
|
|
643
645
|
style: getStyle(state)
|
|
644
646
|
}, childrenProps)));
|
|
645
647
|
} else {
|
|
646
|
-
return /*#__PURE__*/createElement(ClickableBehavior, {
|
|
648
|
+
return /*#__PURE__*/React.createElement(ClickableBehavior, {
|
|
647
649
|
href: href,
|
|
648
650
|
onClick: onClick,
|
|
649
651
|
safeWithNav: safeWithNav,
|
|
@@ -659,7 +661,7 @@ class Clickable extends Component {
|
|
|
659
661
|
}
|
|
660
662
|
|
|
661
663
|
render() {
|
|
662
|
-
return /*#__PURE__*/createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
664
|
+
return /*#__PURE__*/React.createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
663
665
|
}
|
|
664
666
|
|
|
665
667
|
} // Source: https://gist.github.com/MoOx/9137295
|
|
@@ -709,5 +711,4 @@ const styles = StyleSheet.create({
|
|
|
709
711
|
}
|
|
710
712
|
});
|
|
711
713
|
|
|
712
|
-
export default
|
|
713
|
-
export { ClickableBehavior, getClickableBehavior, isClientSideUrl };
|
|
714
|
+
export { ClickableBehavior, Clickable as default, getClickableBehavior, isClientSideUrl };
|
package/dist/index.js
CHANGED
|
@@ -82,7 +82,7 @@ module.exports =
|
|
|
82
82
|
/******/
|
|
83
83
|
/******/
|
|
84
84
|
/******/ // Load entry module and return exports
|
|
85
|
-
/******/ return __webpack_require__(__webpack_require__.s =
|
|
85
|
+
/******/ return __webpack_require__(__webpack_require__.s = 10);
|
|
86
86
|
/******/ })
|
|
87
87
|
/************************************************************************/
|
|
88
88
|
/******/ ([
|
|
@@ -166,7 +166,9 @@ const disabledHandlers = {
|
|
|
166
166
|
onKeyUp: () => void 0,
|
|
167
167
|
onFocus: () => void 0,
|
|
168
168
|
onBlur: () => void 0,
|
|
169
|
-
|
|
169
|
+
// Clickable components should still be tabbable so they can
|
|
170
|
+
// be used as anchors.
|
|
171
|
+
tabIndex: 0
|
|
170
172
|
};
|
|
171
173
|
const keyCodes = {
|
|
172
174
|
enter: 13,
|
|
@@ -675,142 +677,459 @@ module.exports = require("@khanacademy/wonder-blocks-core");
|
|
|
675
677
|
|
|
676
678
|
/***/ }),
|
|
677
679
|
/* 6 */
|
|
678
|
-
/***/ (function(module,
|
|
680
|
+
/***/ (function(module, exports) {
|
|
679
681
|
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
/* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(10);
|
|
685
|
-
/* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
|
|
682
|
+
module.exports =
|
|
683
|
+
/******/
|
|
684
|
+
function (modules) {
|
|
685
|
+
// webpackBootstrap
|
|
686
686
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
* mixing colors together.
|
|
690
|
-
*/
|
|
687
|
+
/******/
|
|
688
|
+
// The module cache
|
|
691
689
|
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
// with r,g,b,a keys.
|
|
690
|
+
/******/
|
|
691
|
+
var installedModules = {};
|
|
692
|
+
/******/
|
|
696
693
|
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
throw new Error(`Failed to parse color: ${color}`);
|
|
700
|
-
}
|
|
694
|
+
/******/
|
|
695
|
+
// The require function
|
|
701
696
|
|
|
702
|
-
|
|
697
|
+
/******/
|
|
703
698
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
r: parseInt(`${color3Match[1]}${color3Match[1]}`, 16),
|
|
707
|
-
g: parseInt(`${color3Match[2]}${color3Match[2]}`, 16),
|
|
708
|
-
b: parseInt(`${color3Match[3]}${color3Match[3]}`, 16),
|
|
709
|
-
a: 1
|
|
710
|
-
};
|
|
711
|
-
}
|
|
699
|
+
function __webpack_require__(moduleId) {
|
|
700
|
+
/******/
|
|
712
701
|
|
|
713
|
-
|
|
702
|
+
/******/
|
|
703
|
+
// Check if module is in cache
|
|
704
|
+
|
|
705
|
+
/******/
|
|
706
|
+
if (installedModules[moduleId]) {
|
|
707
|
+
/******/
|
|
708
|
+
return installedModules[moduleId].exports;
|
|
709
|
+
/******/
|
|
710
|
+
}
|
|
711
|
+
/******/
|
|
712
|
+
// Create a new module (and put it into the cache)
|
|
713
|
+
|
|
714
|
+
/******/
|
|
714
715
|
|
|
715
|
-
if (color6Match) {
|
|
716
|
-
return {
|
|
717
|
-
r: parseInt(color6Match[1], 16),
|
|
718
|
-
g: parseInt(color6Match[2], 16),
|
|
719
|
-
b: parseInt(color6Match[3], 16),
|
|
720
|
-
a: 1
|
|
721
|
-
};
|
|
722
|
-
}
|
|
723
716
|
|
|
724
|
-
|
|
717
|
+
var module = installedModules[moduleId] = {
|
|
718
|
+
/******/
|
|
719
|
+
i: moduleId,
|
|
720
|
+
|
|
721
|
+
/******/
|
|
722
|
+
l: false,
|
|
723
|
+
|
|
724
|
+
/******/
|
|
725
|
+
exports: {}
|
|
726
|
+
/******/
|
|
725
727
|
|
|
726
|
-
if (rgbaMatch) {
|
|
727
|
-
return {
|
|
728
|
-
r: parseFloat(rgbaMatch[1]),
|
|
729
|
-
g: parseFloat(rgbaMatch[2]),
|
|
730
|
-
b: parseFloat(rgbaMatch[3]),
|
|
731
|
-
a: rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1
|
|
732
728
|
};
|
|
729
|
+
/******/
|
|
730
|
+
|
|
731
|
+
/******/
|
|
732
|
+
// Execute the module function
|
|
733
|
+
|
|
734
|
+
/******/
|
|
735
|
+
|
|
736
|
+
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
737
|
+
/******/
|
|
738
|
+
|
|
739
|
+
/******/
|
|
740
|
+
// Flag the module as loaded
|
|
741
|
+
|
|
742
|
+
/******/
|
|
743
|
+
|
|
744
|
+
module.l = true;
|
|
745
|
+
/******/
|
|
746
|
+
|
|
747
|
+
/******/
|
|
748
|
+
// Return the exports of the module
|
|
749
|
+
|
|
750
|
+
/******/
|
|
751
|
+
|
|
752
|
+
return module.exports;
|
|
753
|
+
/******/
|
|
733
754
|
}
|
|
755
|
+
/******/
|
|
756
|
+
|
|
757
|
+
/******/
|
|
758
|
+
|
|
759
|
+
/******/
|
|
760
|
+
// expose the modules object (__webpack_modules__)
|
|
761
|
+
|
|
762
|
+
/******/
|
|
763
|
+
|
|
764
|
+
|
|
765
|
+
__webpack_require__.m = modules;
|
|
766
|
+
/******/
|
|
767
|
+
|
|
768
|
+
/******/
|
|
769
|
+
// expose the module cache
|
|
770
|
+
|
|
771
|
+
/******/
|
|
772
|
+
|
|
773
|
+
__webpack_require__.c = installedModules;
|
|
774
|
+
/******/
|
|
775
|
+
|
|
776
|
+
/******/
|
|
777
|
+
// define getter function for harmony exports
|
|
778
|
+
|
|
779
|
+
/******/
|
|
780
|
+
|
|
781
|
+
__webpack_require__.d = function (exports, name, getter) {
|
|
782
|
+
/******/
|
|
783
|
+
if (!__webpack_require__.o(exports, name)) {
|
|
784
|
+
/******/
|
|
785
|
+
Object.defineProperty(exports, name, {
|
|
786
|
+
enumerable: true,
|
|
787
|
+
get: getter
|
|
788
|
+
});
|
|
789
|
+
/******/
|
|
790
|
+
}
|
|
791
|
+
/******/
|
|
792
|
+
|
|
793
|
+
};
|
|
794
|
+
/******/
|
|
795
|
+
|
|
796
|
+
/******/
|
|
797
|
+
// define __esModule on exports
|
|
798
|
+
|
|
799
|
+
/******/
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
__webpack_require__.r = function (exports) {
|
|
803
|
+
/******/
|
|
804
|
+
if (typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
805
|
+
/******/
|
|
806
|
+
Object.defineProperty(exports, Symbol.toStringTag, {
|
|
807
|
+
value: 'Module'
|
|
808
|
+
});
|
|
809
|
+
/******/
|
|
810
|
+
}
|
|
811
|
+
/******/
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
Object.defineProperty(exports, '__esModule', {
|
|
815
|
+
value: true
|
|
816
|
+
});
|
|
817
|
+
/******/
|
|
818
|
+
};
|
|
819
|
+
/******/
|
|
820
|
+
|
|
821
|
+
/******/
|
|
822
|
+
// create a fake namespace object
|
|
823
|
+
|
|
824
|
+
/******/
|
|
825
|
+
// mode & 1: value is a module id, require it
|
|
826
|
+
|
|
827
|
+
/******/
|
|
828
|
+
// mode & 2: merge all properties of value into the ns
|
|
829
|
+
|
|
830
|
+
/******/
|
|
831
|
+
// mode & 4: return value when already ns object
|
|
832
|
+
|
|
833
|
+
/******/
|
|
834
|
+
// mode & 8|1: behave like require
|
|
835
|
+
|
|
836
|
+
/******/
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
__webpack_require__.t = function (value, mode) {
|
|
840
|
+
/******/
|
|
841
|
+
if (mode & 1) value = __webpack_require__(value);
|
|
842
|
+
/******/
|
|
843
|
+
|
|
844
|
+
if (mode & 8) return value;
|
|
845
|
+
/******/
|
|
846
|
+
|
|
847
|
+
if (mode & 4 && typeof value === 'object' && value && value.__esModule) return value;
|
|
848
|
+
/******/
|
|
849
|
+
|
|
850
|
+
var ns = Object.create(null);
|
|
851
|
+
/******/
|
|
734
852
|
|
|
735
|
-
|
|
736
|
-
|
|
853
|
+
__webpack_require__.r(ns);
|
|
854
|
+
/******/
|
|
737
855
|
|
|
738
856
|
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
857
|
+
Object.defineProperty(ns, 'default', {
|
|
858
|
+
enumerable: true,
|
|
859
|
+
value: value
|
|
860
|
+
});
|
|
861
|
+
/******/
|
|
743
862
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
863
|
+
if (mode & 2 && typeof value != 'string') for (var key in value) __webpack_require__.d(ns, key, function (key) {
|
|
864
|
+
return value[key];
|
|
865
|
+
}.bind(null, key));
|
|
866
|
+
/******/
|
|
867
|
+
|
|
868
|
+
return ns;
|
|
869
|
+
/******/
|
|
870
|
+
};
|
|
871
|
+
/******/
|
|
872
|
+
|
|
873
|
+
/******/
|
|
874
|
+
// getDefaultExport function for compatibility with non-harmony modules
|
|
875
|
+
|
|
876
|
+
/******/
|
|
877
|
+
|
|
878
|
+
|
|
879
|
+
__webpack_require__.n = function (module) {
|
|
880
|
+
/******/
|
|
881
|
+
var getter = module && module.__esModule ?
|
|
882
|
+
/******/
|
|
883
|
+
function getDefault() {
|
|
884
|
+
return module['default'];
|
|
885
|
+
} :
|
|
886
|
+
/******/
|
|
887
|
+
function getModuleExports() {
|
|
888
|
+
return module;
|
|
748
889
|
};
|
|
890
|
+
/******/
|
|
749
891
|
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
return `rgba(${r},${g},${b},${color.a.toFixed(2)})`;
|
|
753
|
-
}
|
|
754
|
-
}; // Adjust the alpha value of a color.
|
|
892
|
+
__webpack_require__.d(getter, 'a', getter);
|
|
893
|
+
/******/
|
|
755
894
|
|
|
756
895
|
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
896
|
+
return getter;
|
|
897
|
+
/******/
|
|
898
|
+
};
|
|
899
|
+
/******/
|
|
900
|
+
|
|
901
|
+
/******/
|
|
902
|
+
// Object.prototype.hasOwnProperty.call
|
|
903
|
+
|
|
904
|
+
/******/
|
|
905
|
+
|
|
906
|
+
|
|
907
|
+
__webpack_require__.o = function (object, property) {
|
|
908
|
+
return Object.prototype.hasOwnProperty.call(object, property);
|
|
909
|
+
};
|
|
910
|
+
/******/
|
|
911
|
+
|
|
912
|
+
/******/
|
|
913
|
+
// __webpack_public_path__
|
|
914
|
+
|
|
915
|
+
/******/
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
__webpack_require__.p = "";
|
|
919
|
+
/******/
|
|
920
|
+
|
|
921
|
+
/******/
|
|
922
|
+
|
|
923
|
+
/******/
|
|
924
|
+
// Load entry module and return exports
|
|
761
925
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
}
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
926
|
+
/******/
|
|
927
|
+
|
|
928
|
+
return __webpack_require__(__webpack_require__.s = 1);
|
|
929
|
+
/******/
|
|
930
|
+
}
|
|
931
|
+
/************************************************************************/
|
|
932
|
+
|
|
933
|
+
/******/
|
|
934
|
+
([
|
|
935
|
+
/* 0 */
|
|
936
|
+
|
|
937
|
+
/***/
|
|
938
|
+
function (module, __webpack_exports__, __webpack_require__) {
|
|
939
|
+
"use strict";
|
|
940
|
+
/* harmony export (binding) */
|
|
941
|
+
|
|
942
|
+
__webpack_require__.d(__webpack_exports__, "a", function () {
|
|
943
|
+
return fade;
|
|
778
944
|
});
|
|
779
|
-
|
|
945
|
+
/* harmony export (binding) */
|
|
780
946
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
}
|
|
811
|
-
|
|
947
|
+
|
|
948
|
+
__webpack_require__.d(__webpack_exports__, "b", function () {
|
|
949
|
+
return mix;
|
|
950
|
+
});
|
|
951
|
+
/**
|
|
952
|
+
* A color manipulation library useful for dynamically
|
|
953
|
+
* mixing colors together.
|
|
954
|
+
*/
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
const color6Regexp = /^#([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i;
|
|
958
|
+
const color3Regexp = /^#([0-9a-f])([0-9a-f])([0-9a-f])$/i;
|
|
959
|
+
const rgbaRegexp = /^rgba?\(\s*(\d+),\s*(\d+),\s*(\d+)(?:,\s*([\d.]+))?\s*\)$/i; // Parse a color in #abcdef, rgb(...), or rgba(...) form into an object
|
|
960
|
+
// with r,g,b,a keys.
|
|
961
|
+
|
|
962
|
+
const parse = color => {
|
|
963
|
+
if (typeof color !== "string") {
|
|
964
|
+
throw new Error(`Failed to parse color: ${color}`);
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
const color3Match = color.match(color3Regexp);
|
|
968
|
+
|
|
969
|
+
if (color3Match) {
|
|
970
|
+
return {
|
|
971
|
+
r: parseInt(`${color3Match[1]}${color3Match[1]}`, 16),
|
|
972
|
+
g: parseInt(`${color3Match[2]}${color3Match[2]}`, 16),
|
|
973
|
+
b: parseInt(`${color3Match[3]}${color3Match[3]}`, 16),
|
|
974
|
+
a: 1
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
const color6Match = color.match(color6Regexp);
|
|
979
|
+
|
|
980
|
+
if (color6Match) {
|
|
981
|
+
return {
|
|
982
|
+
r: parseInt(color6Match[1], 16),
|
|
983
|
+
g: parseInt(color6Match[2], 16),
|
|
984
|
+
b: parseInt(color6Match[3], 16),
|
|
985
|
+
a: 1
|
|
986
|
+
};
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
const rgbaMatch = color.match(rgbaRegexp);
|
|
990
|
+
|
|
991
|
+
if (rgbaMatch) {
|
|
992
|
+
return {
|
|
993
|
+
r: parseFloat(rgbaMatch[1]),
|
|
994
|
+
g: parseFloat(rgbaMatch[2]),
|
|
995
|
+
b: parseFloat(rgbaMatch[3]),
|
|
996
|
+
a: rgbaMatch[4] ? parseFloat(rgbaMatch[4]) : 1
|
|
997
|
+
};
|
|
998
|
+
}
|
|
999
|
+
|
|
1000
|
+
throw new Error(`Failed to parse color: ${color}`);
|
|
1001
|
+
}; // Stringify the color in an `rgba()` or `#abcdef` format.
|
|
1002
|
+
|
|
1003
|
+
|
|
1004
|
+
const format = color => {
|
|
1005
|
+
const r = Math.round(color.r);
|
|
1006
|
+
const g = Math.round(color.g);
|
|
1007
|
+
const b = Math.round(color.b);
|
|
1008
|
+
|
|
1009
|
+
if (color.a === 1) {
|
|
1010
|
+
const _s = c => {
|
|
1011
|
+
const asString = c.toString(16);
|
|
1012
|
+
return asString.length === 1 ? asString + asString : asString;
|
|
1013
|
+
};
|
|
1014
|
+
|
|
1015
|
+
return `#${_s(r)}${_s(g)}${_s(b)}`;
|
|
1016
|
+
} else {
|
|
1017
|
+
return `rgba(${r},${g},${b},${color.a.toFixed(2)})`;
|
|
1018
|
+
}
|
|
1019
|
+
}; // Adjust the alpha value of a color.
|
|
812
1020
|
|
|
813
1021
|
|
|
1022
|
+
const fade = (color, percentage) => {
|
|
1023
|
+
if (percentage < 0 || percentage > 1) {
|
|
1024
|
+
throw new Error("Percentage must be between 0 and 1");
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
const components = parse(color);
|
|
1028
|
+
return format({ ...components,
|
|
1029
|
+
a: components.a * percentage
|
|
1030
|
+
});
|
|
1031
|
+
}; // Mix a color into a background color, using the alpha channel of the base
|
|
1032
|
+
// color to determine the linear blend.
|
|
1033
|
+
|
|
1034
|
+
|
|
1035
|
+
const mix = (color, background) => {
|
|
1036
|
+
const colorObj = parse(color);
|
|
1037
|
+
const bgObj = parse(background);
|
|
1038
|
+
return format({
|
|
1039
|
+
r: colorObj.r * colorObj.a + bgObj.r * (1 - colorObj.a),
|
|
1040
|
+
g: colorObj.g * colorObj.a + bgObj.g * (1 - colorObj.a),
|
|
1041
|
+
b: colorObj.b * colorObj.a + bgObj.b * (1 - colorObj.a),
|
|
1042
|
+
a: bgObj.a
|
|
1043
|
+
});
|
|
1044
|
+
};
|
|
1045
|
+
/***/
|
|
1046
|
+
|
|
1047
|
+
},
|
|
1048
|
+
/* 1 */
|
|
1049
|
+
|
|
1050
|
+
/***/
|
|
1051
|
+
function (module, __webpack_exports__, __webpack_require__) {
|
|
1052
|
+
"use strict";
|
|
1053
|
+
|
|
1054
|
+
__webpack_require__.r(__webpack_exports__);
|
|
1055
|
+
/* harmony export (binding) */
|
|
1056
|
+
|
|
1057
|
+
|
|
1058
|
+
__webpack_require__.d(__webpack_exports__, "default", function () {
|
|
1059
|
+
return Color;
|
|
1060
|
+
});
|
|
1061
|
+
/* harmony export (binding) */
|
|
1062
|
+
|
|
1063
|
+
|
|
1064
|
+
__webpack_require__.d(__webpack_exports__, "SemanticColor", function () {
|
|
1065
|
+
return SemanticColor;
|
|
1066
|
+
});
|
|
1067
|
+
/* harmony import */
|
|
1068
|
+
|
|
1069
|
+
|
|
1070
|
+
var _util_utils_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
1071
|
+
/* harmony reexport (safe) */
|
|
1072
|
+
|
|
1073
|
+
|
|
1074
|
+
__webpack_require__.d(__webpack_exports__, "mix", function () {
|
|
1075
|
+
return _util_utils_js__WEBPACK_IMPORTED_MODULE_0__["b"];
|
|
1076
|
+
});
|
|
1077
|
+
/* harmony reexport (safe) */
|
|
1078
|
+
|
|
1079
|
+
|
|
1080
|
+
__webpack_require__.d(__webpack_exports__, "fade", function () {
|
|
1081
|
+
return _util_utils_js__WEBPACK_IMPORTED_MODULE_0__["a"];
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
const offBlack = "#21242c";
|
|
1085
|
+
const white = "#ffffff";
|
|
1086
|
+
const Color = {
|
|
1087
|
+
// Product
|
|
1088
|
+
blue: "#1865f2",
|
|
1089
|
+
purple: "#9059ff",
|
|
1090
|
+
green: "#00a60e",
|
|
1091
|
+
gold: "#ffb100",
|
|
1092
|
+
red: "#d92916",
|
|
1093
|
+
// Neutral
|
|
1094
|
+
offBlack,
|
|
1095
|
+
offBlack64: Object(_util_utils_js__WEBPACK_IMPORTED_MODULE_0__[
|
|
1096
|
+
/* fade */
|
|
1097
|
+
"a"])(offBlack, 0.64),
|
|
1098
|
+
offBlack50: Object(_util_utils_js__WEBPACK_IMPORTED_MODULE_0__[
|
|
1099
|
+
/* fade */
|
|
1100
|
+
"a"])(offBlack, 0.5),
|
|
1101
|
+
offBlack32: Object(_util_utils_js__WEBPACK_IMPORTED_MODULE_0__[
|
|
1102
|
+
/* fade */
|
|
1103
|
+
"a"])(offBlack, 0.32),
|
|
1104
|
+
offBlack16: Object(_util_utils_js__WEBPACK_IMPORTED_MODULE_0__[
|
|
1105
|
+
/* fade */
|
|
1106
|
+
"a"])(offBlack, 0.16),
|
|
1107
|
+
offBlack8: Object(_util_utils_js__WEBPACK_IMPORTED_MODULE_0__[
|
|
1108
|
+
/* fade */
|
|
1109
|
+
"a"])(offBlack, 0.08),
|
|
1110
|
+
offWhite: "#f7f8fa",
|
|
1111
|
+
white,
|
|
1112
|
+
white64: Object(_util_utils_js__WEBPACK_IMPORTED_MODULE_0__[
|
|
1113
|
+
/* fade */
|
|
1114
|
+
"a"])(white, 0.64),
|
|
1115
|
+
white50: Object(_util_utils_js__WEBPACK_IMPORTED_MODULE_0__[
|
|
1116
|
+
/* fade */
|
|
1117
|
+
"a"])(white, 0.5),
|
|
1118
|
+
// Brand
|
|
1119
|
+
darkBlue: "#0a2a66",
|
|
1120
|
+
teal: "#14bf96",
|
|
1121
|
+
lightBlue: "#37c5fd",
|
|
1122
|
+
pink: "#fa50ae"
|
|
1123
|
+
};
|
|
1124
|
+
const SemanticColor = {
|
|
1125
|
+
controlDefault: Color.blue,
|
|
1126
|
+
controlDestructive: Color.red
|
|
1127
|
+
};
|
|
1128
|
+
/***/
|
|
1129
|
+
}
|
|
1130
|
+
/******/
|
|
1131
|
+
]);
|
|
1132
|
+
|
|
814
1133
|
/***/ }),
|
|
815
1134
|
/* 7 */
|
|
816
1135
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
@@ -828,6 +1147,7 @@ const SemanticColor = {
|
|
|
828
1147
|
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(5);
|
|
829
1148
|
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__);
|
|
830
1149
|
/* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(6);
|
|
1150
|
+
/* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__);
|
|
831
1151
|
/* harmony import */ var _util_get_clickable_behavior_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(3);
|
|
832
1152
|
/* harmony import */ var _util_is_client_side_url_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(1);
|
|
833
1153
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
@@ -996,10 +1316,10 @@ const styles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
|
|
|
996
1316
|
cursor: "pointer"
|
|
997
1317
|
},
|
|
998
1318
|
focused: {
|
|
999
|
-
outline: `solid 2px ${
|
|
1319
|
+
outline: `solid 2px ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5___default.a.blue}`
|
|
1000
1320
|
},
|
|
1001
1321
|
focusedLight: {
|
|
1002
|
-
outline: `solid 2px ${
|
|
1322
|
+
outline: `solid 2px ${_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5___default.a.white}`
|
|
1003
1323
|
}
|
|
1004
1324
|
});
|
|
1005
1325
|
|
|
@@ -1017,32 +1337,6 @@ module.exports = require("react-router");
|
|
|
1017
1337
|
|
|
1018
1338
|
/***/ }),
|
|
1019
1339
|
/* 10 */
|
|
1020
|
-
/***/ (function(module, exports) {
|
|
1021
|
-
|
|
1022
|
-
function _extends() {
|
|
1023
|
-
module.exports = _extends = Object.assign || function (target) {
|
|
1024
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
1025
|
-
var source = arguments[i];
|
|
1026
|
-
|
|
1027
|
-
for (var key in source) {
|
|
1028
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1029
|
-
target[key] = source[key];
|
|
1030
|
-
}
|
|
1031
|
-
}
|
|
1032
|
-
}
|
|
1033
|
-
|
|
1034
|
-
return target;
|
|
1035
|
-
};
|
|
1036
|
-
|
|
1037
|
-
module.exports["default"] = module.exports, module.exports.__esModule = true;
|
|
1038
|
-
return _extends.apply(this, arguments);
|
|
1039
|
-
}
|
|
1040
|
-
|
|
1041
|
-
module.exports = _extends;
|
|
1042
|
-
module.exports["default"] = module.exports, module.exports.__esModule = true;
|
|
1043
|
-
|
|
1044
|
-
/***/ }),
|
|
1045
|
-
/* 11 */
|
|
1046
1340
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
1047
1341
|
|
|
1048
1342
|
"use strict";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-clickable",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"description": "Clickable component for Wonder-Blocks.",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -27,6 +27,5 @@
|
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"wb-dev-build-settings": "^0.2.0"
|
|
30
|
-
}
|
|
31
|
-
"gitHead": "9ebea88533e702011165072f090a377e02fa3f0f"
|
|
30
|
+
}
|
|
32
31
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
// @flow
|
|
3
3
|
import * as React from "react";
|
|
4
|
+
import {render, screen} from "@testing-library/react";
|
|
4
5
|
import {MemoryRouter, Switch, Route} from "react-router-dom";
|
|
5
6
|
import {mount, shallow} from "enzyme";
|
|
7
|
+
import "jest-enzyme";
|
|
6
8
|
|
|
7
9
|
import getClickableBehavior from "../../util/get-clickable-behavior.js";
|
|
8
10
|
import ClickableBehavior from "../clickable-behavior.js";
|
|
@@ -275,6 +277,46 @@ describe("ClickableBehavior", () => {
|
|
|
275
277
|
expect(button.state("focused")).toEqual(false);
|
|
276
278
|
});
|
|
277
279
|
|
|
280
|
+
test("tabIndex should be 0", () => {
|
|
281
|
+
// Arrange
|
|
282
|
+
// Act
|
|
283
|
+
render(
|
|
284
|
+
<ClickableBehavior disabled={false} onClick={(e) => {}}>
|
|
285
|
+
{(state, childrenProps) => {
|
|
286
|
+
return (
|
|
287
|
+
<button data-test-id="test-button-1" {...childrenProps}>
|
|
288
|
+
Label
|
|
289
|
+
</button>
|
|
290
|
+
);
|
|
291
|
+
}}
|
|
292
|
+
</ClickableBehavior>,
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
// Assert
|
|
296
|
+
const button = screen.getByTestId("test-button-1");
|
|
297
|
+
expect(button).toHaveAttribute("tabIndex", "0");
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
test("tabIndex should be 0 even for disabled components", () => {
|
|
301
|
+
// Arrange
|
|
302
|
+
// Act
|
|
303
|
+
render(
|
|
304
|
+
<ClickableBehavior disabled={true} onClick={(e) => {}}>
|
|
305
|
+
{(state, childrenProps) => {
|
|
306
|
+
return (
|
|
307
|
+
<button data-test-id="test-button-2" {...childrenProps}>
|
|
308
|
+
Label
|
|
309
|
+
</button>
|
|
310
|
+
);
|
|
311
|
+
}}
|
|
312
|
+
</ClickableBehavior>,
|
|
313
|
+
);
|
|
314
|
+
|
|
315
|
+
// Assert
|
|
316
|
+
const button = screen.getByTestId("test-button-2");
|
|
317
|
+
expect(button).toHaveAttribute("tabIndex", "0");
|
|
318
|
+
});
|
|
319
|
+
|
|
278
320
|
it("does not change state if disabled", () => {
|
|
279
321
|
const onClick = jest.fn();
|
|
280
322
|
const button = shallow(
|
|
@@ -223,7 +223,9 @@ const disabledHandlers = {
|
|
|
223
223
|
onKeyUp: () => void 0,
|
|
224
224
|
onFocus: () => void 0,
|
|
225
225
|
onBlur: () => void 0,
|
|
226
|
-
|
|
226
|
+
// Clickable components should still be tabbable so they can
|
|
227
|
+
// be used as anchors.
|
|
228
|
+
tabIndex: 0,
|
|
227
229
|
};
|
|
228
230
|
|
|
229
231
|
const keyCodes = {
|
|
@@ -15,7 +15,7 @@ export default {
|
|
|
15
15
|
title: "Navigation/Clickable",
|
|
16
16
|
};
|
|
17
17
|
|
|
18
|
-
export const
|
|
18
|
+
export const Basic: StoryComponentType = () => (
|
|
19
19
|
<View>
|
|
20
20
|
<View style={styles.centerText}>
|
|
21
21
|
<Clickable
|
|
@@ -56,7 +56,7 @@ export const basic: StoryComponentType = () => (
|
|
|
56
56
|
</View>
|
|
57
57
|
);
|
|
58
58
|
|
|
59
|
-
export const
|
|
59
|
+
export const KeyboardNavigation: StoryComponentType = () => (
|
|
60
60
|
<View>
|
|
61
61
|
<Clickable
|
|
62
62
|
href="https://www.khanacademy.org/about/tos"
|
|
@@ -77,14 +77,14 @@ export const keyboardNavigation: StoryComponentType = () => (
|
|
|
77
77
|
</View>
|
|
78
78
|
);
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
KeyboardNavigation.parameters = {
|
|
81
81
|
chromatic: {
|
|
82
82
|
// we don't need screenshots because this story only tests behavior.
|
|
83
83
|
disableSnapshot: true,
|
|
84
84
|
},
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
export const
|
|
87
|
+
export const KeyboardNavigationTab: StoryComponentType = () => (
|
|
88
88
|
<View>
|
|
89
89
|
<Clickable role="tab" aria-controls="panel-1" id="tab-1">
|
|
90
90
|
{({hovered, focused, pressed}) => (
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Khan Academy
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|