UNPKG

2.84 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var tslib_1 = require("tslib");
4exports.mapAttributesToState = function (_a) {
5 var _b = _a.isDisabled, isDisabled = _b === void 0 ? false : _b, _c = _a.isActive, isActive = _c === void 0 ? false : _c, _d = _a.isFocus, isFocus = _d === void 0 ? false : _d, _e = _a.isHover, isHover = _e === void 0 ? false : _e, _f = _a.isSelected, isSelected = _f === void 0 ? false : _f;
6 if (isDisabled) {
7 return 'disabled';
8 }
9 if (isSelected && isFocus) {
10 return 'focusSelected';
11 }
12 if (isSelected) {
13 return 'selected';
14 }
15 if (isActive) {
16 return 'active';
17 }
18 if (isHover) {
19 return 'hover';
20 }
21 if (isFocus) {
22 return 'focus';
23 }
24 return 'default';
25};
26exports.filterProps = function (
27// @ts-ignore - createAnalyticsEvent is injected from WithAnalyticsEvents HOC
28_a, type) {
29 var createAnalyticsEvent = _a.createAnalyticsEvent, props = tslib_1.__rest(_a,
30 // @ts-ignore - createAnalyticsEvent is injected from WithAnalyticsEvents HOC
31 ["createAnalyticsEvent"]);
32 if (type === 'span') {
33 var target = props.target, href = props.href, rest = tslib_1.__rest(props, ["target", "href"]);
34 return rest;
35 }
36 return props;
37};
38exports.getLoadingStyle = function (isLoading) { return ({
39 transition: 'opacity 0.3s',
40 opacity: isLoading ? 0 : 1,
41}); };
42exports.composeRefs = function () {
43 var refs = [];
44 for (var _i = 0; _i < arguments.length; _i++) {
45 refs[_i] = arguments[_i];
46 }
47 return function (x) {
48 refs
49 .filter(function (r) { return !!r; })
50 .forEach(function (ref) {
51 if (typeof ref === 'function') {
52 ref(x);
53 }
54 else {
55 ref.current = x;
56 }
57 });
58 };
59};
60/**
61 * Convert a hex colour code to RGBA.
62 * @param {String} hex Hex colour code.
63 * @param {Number} alpha Optional alpha value (defaults to 1).
64 */
65function hex2rgba(hex, alpha) {
66 if (alpha === void 0) { alpha = 1; }
67 if (/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)) {
68 var colorArr = hex.substring(1).split('');
69 if (colorArr.length === 3) {
70 colorArr = [
71 colorArr[0],
72 colorArr[0],
73 colorArr[1],
74 colorArr[1],
75 colorArr[2],
76 colorArr[2],
77 ];
78 }
79 var color = "0x" + colorArr.join('');
80 // FIXME: `>>` operand can validly take a string value
81 var r = (color >> 16) & 255;
82 var g = (color >> 8) & 255;
83 var b = color & 255;
84 return "rgba(" + [r, g, b].join(',') + ", " + alpha + ")";
85 }
86 throw new Error('Bad Hex');
87}
88exports.hex2rgba = hex2rgba;
89//# sourceMappingURL=utils.js.map
\No newline at end of file