@opentripplanner/building-blocks 2.0.0 → 2.1.1-alpha.1
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/LICENSE +21 -0
- package/README.md +1 -0
- package/esm/alert/Alert.js +79 -0
- package/esm/alert/Alert.js.map +1 -0
- package/esm/colors/blue.js.map +1 -1
- package/esm/colors/grey.js.map +1 -1
- package/esm/colors/red.js.map +1 -1
- package/esm/dropdown/index.js +19 -30
- package/esm/dropdown/index.js.map +1 -1
- package/esm/dropdown/styled.js.map +1 -1
- package/esm/focus-trap-wrapper/dom-query.js +8 -13
- package/esm/focus-trap-wrapper/dom-query.js.map +1 -1
- package/esm/focus-trap-wrapper/index.js +7 -16
- package/esm/focus-trap-wrapper/index.js.map +1 -1
- package/esm/index.js +2 -1
- package/esm/index.js.map +1 -1
- package/esm/stories/ColorPalette.js +0 -2
- package/esm/stories/ColorPalette.js.map +1 -1
- package/i18n/en-US.yml +4 -0
- package/i18n/fr.yml +4 -0
- package/lib/alert/Alert.d.ts +13 -0
- package/lib/alert/Alert.d.ts.map +1 -0
- package/lib/alert/Alert.js +76 -0
- package/lib/alert/Alert.js.map +1 -0
- package/lib/colors/blue.js +1 -2
- package/lib/colors/blue.js.map +1 -1
- package/lib/colors/grey.js +1 -2
- package/lib/colors/grey.js.map +1 -1
- package/lib/colors/red.js +1 -2
- package/lib/colors/red.js.map +1 -1
- package/lib/dropdown/index.js +13 -30
- package/lib/dropdown/index.js.map +1 -1
- package/lib/dropdown/styled.js +3 -15
- package/lib/dropdown/styled.js.map +1 -1
- package/lib/focus-trap-wrapper/dom-query.js +2 -9
- package/lib/focus-trap-wrapper/dom-query.js.map +1 -1
- package/lib/focus-trap-wrapper/index.js +6 -22
- package/lib/focus-trap-wrapper/index.js.map +1 -1
- package/lib/index.js +4 -14
- package/lib/index.js.map +1 -1
- package/lib/stories/ColorPalette.js +1 -9
- package/lib/stories/ColorPalette.js.map +1 -1
- package/package.json +13 -9
- package/src/alert/Alert.tsx +136 -0
- package/src/stories/__snapshots__/alerts.story.tsx.snap +104 -0
- package/src/stories/__snapshots__/dropdown.story.tsx.snap +9 -9
- package/src/stories/__snapshots__/index.story.tsx.snap +30 -30
- package/src/stories/alerts.story.tsx +77 -0
- package/tsconfig.tsbuildinfo +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 OpenTripPlanner Project
|
|
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.
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useState } from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import AnimateHeight from "react-animate-height";
|
|
5
|
+
import { ChevronUp } from "@styled-icons/bootstrap/ChevronUp";
|
|
6
|
+
import { Bell } from "@styled-icons/bootstrap/Bell";
|
|
7
|
+
import { useIntl } from "react-intl";
|
|
8
|
+
import blue from "../colors/blue";
|
|
9
|
+
var AlertContainer = styled.div.withConfig({
|
|
10
|
+
displayName: "Alert__AlertContainer",
|
|
11
|
+
componentId: "sc-2vlo3n-0"
|
|
12
|
+
})(["background-color:", ";display:grid;grid-template-columns:50px auto auto;grid-template-rows:minmax(25px,auto) auto;max-width:715px;padding:1.5em 2em;svg{align-self:center;grid-column:1;grid-row:1 / span 2;justify-self:start;}button{background:transparent;border:none;width:40px;svg{transform:", ";transition:all 0.2s ease-in;}}@media (max-width:550px){grid-template-columns:40px auto auto;padding:1.25em 1.25em;}"], function (props) {
|
|
13
|
+
return props.backgroundColor ? props.backgroundColor : blue[50];
|
|
14
|
+
}, function (props) {
|
|
15
|
+
return !props.expandAlert && "rotate(180deg)";
|
|
16
|
+
});
|
|
17
|
+
var ButtonContainer = styled.span.withConfig({
|
|
18
|
+
displayName: "Alert__ButtonContainer",
|
|
19
|
+
componentId: "sc-2vlo3n-1"
|
|
20
|
+
})(["align-items:center;display:flex;justify-content:center;justify-self:right;"]);
|
|
21
|
+
var AlertHeader = styled.span.withConfig({
|
|
22
|
+
displayName: "Alert__AlertHeader",
|
|
23
|
+
componentId: "sc-2vlo3n-2"
|
|
24
|
+
})(["align-self:center;font-weight:700;grid-column:2;"]);
|
|
25
|
+
var AlertSubheader = styled(AlertHeader).withConfig({
|
|
26
|
+
displayName: "Alert__AlertSubheader",
|
|
27
|
+
componentId: "sc-2vlo3n-3"
|
|
28
|
+
})(["font-weight:400;margin-top:0.3em;"]);
|
|
29
|
+
var AlertContent = styled.div.withConfig({
|
|
30
|
+
displayName: "Alert__AlertContent",
|
|
31
|
+
componentId: "sc-2vlo3n-4"
|
|
32
|
+
})(["grid-column:2;grid-row:3;"]);
|
|
33
|
+
var ContentPadding = styled.div.withConfig({
|
|
34
|
+
displayName: "Alert__ContentPadding",
|
|
35
|
+
componentId: "sc-2vlo3n-5"
|
|
36
|
+
})(["margin-top:", ";"], function (props) {
|
|
37
|
+
return props.collapsible ? "1em" : ".5em";
|
|
38
|
+
});
|
|
39
|
+
var Alert = function Alert(_ref) {
|
|
40
|
+
var alertHeader = _ref.alertHeader,
|
|
41
|
+
alertSubheader = _ref.alertSubheader,
|
|
42
|
+
backgroundColor = _ref.backgroundColor,
|
|
43
|
+
children = _ref.children,
|
|
44
|
+
collapsible = _ref.collapsible,
|
|
45
|
+
_ref$Icon = _ref.Icon,
|
|
46
|
+
Icon = _ref$Icon === void 0 ? Bell : _ref$Icon;
|
|
47
|
+
var _useState = useState(false),
|
|
48
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
49
|
+
expandAlert = _useState2[0],
|
|
50
|
+
setExpandAlert = _useState2[1];
|
|
51
|
+
var intl = useIntl();
|
|
52
|
+
var label = intl.formatMessage({
|
|
53
|
+
id: "otpUi.buildingBlocks.alert.expand",
|
|
54
|
+
defaultMessage: "Expand"
|
|
55
|
+
});
|
|
56
|
+
return /*#__PURE__*/React.createElement(AlertContainer, {
|
|
57
|
+
backgroundColor: backgroundColor,
|
|
58
|
+
expandAlert: expandAlert,
|
|
59
|
+
collapsible: collapsible
|
|
60
|
+
}, /*#__PURE__*/React.createElement(Icon, {
|
|
61
|
+
size: 24
|
|
62
|
+
}), /*#__PURE__*/React.createElement(AlertHeader, null, alertHeader), /*#__PURE__*/React.createElement(ButtonContainer, null, collapsible && /*#__PURE__*/React.createElement("button", {
|
|
63
|
+
type: "button",
|
|
64
|
+
onClick: function onClick() {
|
|
65
|
+
return setExpandAlert(!expandAlert);
|
|
66
|
+
},
|
|
67
|
+
"aria-label": label,
|
|
68
|
+
title: label
|
|
69
|
+
}, /*#__PURE__*/React.createElement(ChevronUp, {
|
|
70
|
+
size: 16
|
|
71
|
+
}))), alertSubheader && /*#__PURE__*/React.createElement(AlertSubheader, null, alertSubheader), children && /*#__PURE__*/React.createElement(AlertContent, null, /*#__PURE__*/React.createElement(AnimateHeight, {
|
|
72
|
+
duration: 500,
|
|
73
|
+
height: collapsible ? expandAlert ? "auto" : 0 : "auto"
|
|
74
|
+
}, /*#__PURE__*/React.createElement(ContentPadding, {
|
|
75
|
+
collapsible: collapsible
|
|
76
|
+
}, children))));
|
|
77
|
+
};
|
|
78
|
+
export default Alert;
|
|
79
|
+
//# sourceMappingURL=Alert.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Alert.js","names":["React","useState","styled","AnimateHeight","ChevronUp","Bell","useIntl","blue","AlertContainer","div","withConfig","displayName","componentId","props","backgroundColor","expandAlert","ButtonContainer","span","AlertHeader","AlertSubheader","AlertContent","ContentPadding","collapsible","Alert","_ref","alertHeader","alertSubheader","children","_ref$Icon","Icon","_useState","_useState2","_slicedToArray","setExpandAlert","intl","label","formatMessage","id","defaultMessage","createElement","size","type","onClick","title","duration","height"],"sources":["../../src/alert/Alert.tsx"],"sourcesContent":["import React, { ReactChild, useState } from \"react\";\nimport styled from \"styled-components\";\nimport AnimateHeight from \"react-animate-height\";\nimport { ChevronUp } from \"@styled-icons/bootstrap/ChevronUp\";\nimport { Bell } from \"@styled-icons/bootstrap/Bell\";\nimport { StyledIcon } from \"@styled-icons/styled-icon\";\nimport { useIntl } from \"react-intl\";\nimport blue from \"../colors/blue\";\n\ninterface Props {\n alertHeader: string;\n alertSubheader?: string;\n backgroundColor?: string;\n collapsible?: boolean;\n children?: ReactChild;\n Icon?: StyledIcon;\n}\n\nconst AlertContainer = styled.div<{\n backgroundColor: string;\n collapsible: boolean;\n expandAlert: boolean;\n}>`\n background-color: ${props =>\n props.backgroundColor ? props.backgroundColor : blue[50]};\n display: grid;\n grid-template-columns: 50px auto auto;\n grid-template-rows: minmax(25px, auto) auto;\n max-width: 715px;\n padding: 1.5em 2em;\n\n svg {\n align-self: center;\n grid-column: 1;\n grid-row: 1 / span 2;\n justify-self: start;\n }\n\n button {\n background: transparent;\n border: none;\n width: 40px;\n\n svg {\n transform: ${props => !props.expandAlert && \"rotate(180deg)\"};\n transition: all 0.2s ease-in;\n }\n }\n\n @media (max-width: 550px) {\n grid-template-columns: 40px auto auto;\n padding: 1.25em 1.25em;\n }\n`;\n\nconst ButtonContainer = styled.span`\n align-items: center;\n display: flex;\n justify-content: center;\n justify-self: right;\n`;\n\nconst AlertHeader = styled.span`\n align-self: center;\n font-weight: 700;\n grid-column: 2;\n`;\n\nconst AlertSubheader = styled(AlertHeader)`\n font-weight: 400;\n margin-top: 0.3em;\n`;\n\nconst AlertContent = styled.div`\n grid-column: 2;\n grid-row: 3;\n`;\n\nconst ContentPadding = styled.div<{\n collapsible: boolean;\n}>`\n margin-top: ${props => (props.collapsible ? \"1em\" : \".5em\")};\n`;\n\nconst Alert = ({\n alertHeader,\n alertSubheader,\n backgroundColor,\n children,\n collapsible,\n Icon = Bell\n}: Props): JSX.Element => {\n const [expandAlert, setExpandAlert] = useState(false);\n const intl = useIntl();\n const label = intl.formatMessage({\n id: \"otpUi.buildingBlocks.alert.expand\",\n defaultMessage: \"Expand\"\n });\n return (\n <AlertContainer\n backgroundColor={backgroundColor}\n expandAlert={expandAlert}\n collapsible={collapsible}\n >\n <Icon size={24} />\n <AlertHeader>{alertHeader}</AlertHeader>\n <ButtonContainer>\n {collapsible && (\n <button\n type=\"button\"\n onClick={() => setExpandAlert(!expandAlert)}\n aria-label={label}\n title={label}\n >\n <ChevronUp size={16} />\n </button>\n )}\n </ButtonContainer>\n {alertSubheader && <AlertSubheader>{alertSubheader}</AlertSubheader>}\n {children && (\n <AlertContent>\n <AnimateHeight\n duration={500}\n height={collapsible ? (expandAlert ? \"auto\" : 0) : \"auto\"}\n >\n <ContentPadding collapsible={collapsible}>\n {children}\n </ContentPadding>\n </AnimateHeight>\n </AlertContent>\n )}\n </AlertContainer>\n );\n};\n\nexport default Alert;\n"],"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B,cAAc,QAAEO,cAA+B,CAAC,EACnEC,QAAQ,iBACP3B,KAAA,CAAAuC,aAAA,CAACnB,YAAY,qBACXpB,KAAA,CAAAuC,aAAA,CAACpC,aAAa;IACZyC,QAAQ,EAAE,GAAI;IACdC,MAAM,EAAEvB,WAAW,GAAIP,WAAW,GAAG,MAAM,GAAG,CAAC,GAAI;EAAO,gBAE1Df,KAAA,CAAAuC,aAAA,CAAClB,cAAc;IAACC,WAAW,EAAEA;EAAY,GACtCK,QACa,CACH,CACH,CAEF,CAAC;AAErB,CAAC;AAED,eAAeJ,KAAK","ignoreList":[]}
|
package/esm/colors/blue.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"blue.js","names":["blue"],"sources":["../../src/colors/blue.ts"],"sourcesContent":["const blue = {\n 50: \"#E5ECF3\",\n 100: \"#CCDAE7\",\n 200: \"#B2C7DB\",\n 300: \"#99B5CF\",\n 400: \"#7FA2C2\",\n 500: \"#6690B7\",\n 600: \"#4D7EAB\",\n // 700 and above text is WCAG AA accessible on white backgrounds.\n 700: \"#336B9E\",\n // 800 and above text is WCAG AAA accessible on white backgrounds.\n 800: \"#1A5992\",\n 900: \"#004686\"\n};\n\nexport default blue;\n"],"mappings":"AAAA,IAAMA,IAAI,GAAG;EACX,EAAE,EAAE,SAAS;EACb,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd;EACA,GAAG,EAAE,SAAS;EACd;EACA,GAAG,EAAE,SAAS;EACd,GAAG,EAAE;AACP,CAAC;AAED,eAAeA,IAAI","ignoreList":[]}
|
package/esm/colors/grey.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"grey.js","names":["grey"],"sources":["../../src/colors/grey.ts"],"sourcesContent":["const grey = {\n 50: \"#ECECEC\",\n 100: \"#D9D9D9\",\n 200: \"#C5C5C5\",\n 300: \"#B3B3B3\",\n 400: \"#9F9F9F\",\n 500: \"#8C8C8C\",\n 600: \"#797979\",\n // 700 and above text is WCAG AA accessible on white backgrounds.\n 700: \"#666666\",\n // 800 and above text is WCAG AAA accessible on white backgrounds.\n 800: \"#535353\",\n 900: \"#404040\"\n};\n\nexport default grey;\n"],"mappings":"AAAA,IAAMA,IAAI,GAAG;EACX,EAAE,EAAE,SAAS;EACb,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd;EACA,GAAG,EAAE,SAAS;EACd;EACA,GAAG,EAAE,SAAS;EACd,GAAG,EAAE;AACP,CAAC;AAED,eAAeA,IAAI","ignoreList":[]}
|
package/esm/colors/red.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"red.js","names":["red"],"sources":["../../src/colors/red.ts"],"sourcesContent":["const red = {\n 50: \"#F7E7E6\",\n 100: \"#EFCFCE\",\n 200: \"#E7B6B4\",\n 300: \"#DF9E9C\",\n 400: \"#D78683\",\n 500: \"#CF6E6B\",\n 600: \"#C75652\",\n // 700 and above text is WCAG AA accessible on white backgrounds.\n 700: \"#BF3E3A\",\n 800: \"#B72620\",\n // 900 text is WCAG AAA accessible on white backgrounds.\n 900: \"#AF0E08\"\n};\n\nexport default red;\n"],"mappings":"AAAA,IAAMA,GAAG,GAAG;EACV,EAAE,EAAE,SAAS;EACb,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd;EACA,GAAG,EAAE,SAAS;EACd,GAAG,EAAE,SAAS;EACd;EACA,GAAG,EAAE;AACP,CAAC;AAED,eAAeA,GAAG","ignoreList":[]}
|
package/esm/dropdown/index.js
CHANGED
|
@@ -2,7 +2,6 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { getNextSibling, getPreviousSibling } from "../focus-trap-wrapper/dom-query";
|
|
4
4
|
import { DropdownButton, DropdownMenu, DropdownWrapper } from "./styled";
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Renders a dropdown menu. By default, only a passed "text" is rendered. If clicked,
|
|
8
7
|
* a floating div is rendered below the "text" with list contents inside. Clicking anywhere
|
|
@@ -10,39 +9,37 @@ import { DropdownButton, DropdownMenu, DropdownWrapper } from "./styled";
|
|
|
10
9
|
*/
|
|
11
10
|
var Dropdown = function Dropdown(_ref) {
|
|
12
11
|
var alignMenuLeft = _ref.alignMenuLeft,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
children = _ref.children,
|
|
13
|
+
className = _ref.className,
|
|
14
|
+
id = _ref.id,
|
|
15
|
+
label = _ref.label,
|
|
16
|
+
listLabel = _ref.listLabel,
|
|
17
|
+
text = _ref.text,
|
|
18
|
+
buttonStyle = _ref.buttonStyle;
|
|
21
19
|
var _useState = useState(false),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
21
|
+
open = _useState2[0],
|
|
22
|
+
setOpen = _useState2[1];
|
|
26
23
|
var containerRef = useRef(null);
|
|
27
24
|
var toggleOpen = useCallback(function () {
|
|
28
25
|
return setOpen(!open);
|
|
29
|
-
}, [open, setOpen]);
|
|
26
|
+
}, [open, setOpen]);
|
|
30
27
|
|
|
28
|
+
// Argument for document.querySelectorAll to target focusable elements.
|
|
31
29
|
var queryId = "#".concat(id, " button, #").concat(id, "-label");
|
|
32
30
|
var isList = Array.isArray(children) ? children.every(function (child) {
|
|
33
31
|
return /*#__PURE__*/React.isValidElement(child) && child.type === "li";
|
|
34
|
-
}) : /*#__PURE__*/React.isValidElement(children) && children.type === "li";
|
|
35
|
-
// when the user interacts with any part of the page that isn't the dropdown
|
|
32
|
+
}) : /*#__PURE__*/React.isValidElement(children) && children.type === "li";
|
|
36
33
|
|
|
34
|
+
// Adding document event listeners allows us to close the dropdown
|
|
35
|
+
// when the user interacts with any part of the page that isn't the dropdown
|
|
37
36
|
useEffect(function () {
|
|
38
37
|
var handleExternalAction = function handleExternalAction(e) {
|
|
39
38
|
var _containerRef$current;
|
|
40
|
-
|
|
41
39
|
if (!(containerRef !== null && containerRef !== void 0 && (_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(e.target))) {
|
|
42
40
|
setOpen(false);
|
|
43
41
|
}
|
|
44
42
|
};
|
|
45
|
-
|
|
46
43
|
document.addEventListener("mousedown", handleExternalAction);
|
|
47
44
|
document.addEventListener("focusin", handleExternalAction);
|
|
48
45
|
document.addEventListener("keydown", handleExternalAction);
|
|
@@ -54,35 +51,27 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
54
51
|
}, [containerRef]);
|
|
55
52
|
var handleKeyDown = useCallback(function (e) {
|
|
56
53
|
var _getPreviousSibling, _getNextSibling;
|
|
57
|
-
|
|
58
54
|
var element = e.target;
|
|
59
|
-
|
|
60
55
|
switch (e.key) {
|
|
61
56
|
case "ArrowUp":
|
|
62
57
|
e.preventDefault();
|
|
63
|
-
(_getPreviousSibling = getPreviousSibling(queryId, element)) === null || _getPreviousSibling === void 0
|
|
58
|
+
(_getPreviousSibling = getPreviousSibling(queryId, element)) === null || _getPreviousSibling === void 0 || _getPreviousSibling.focus();
|
|
64
59
|
break;
|
|
65
|
-
|
|
66
60
|
case "ArrowDown":
|
|
67
61
|
e.preventDefault();
|
|
68
|
-
(_getNextSibling = getNextSibling(queryId, element)) === null || _getNextSibling === void 0
|
|
62
|
+
(_getNextSibling = getNextSibling(queryId, element)) === null || _getNextSibling === void 0 || _getNextSibling.focus();
|
|
69
63
|
break;
|
|
70
|
-
|
|
71
64
|
case "Escape":
|
|
72
65
|
setOpen(false);
|
|
73
66
|
break;
|
|
74
|
-
|
|
75
67
|
case " ":
|
|
76
68
|
case "Enter":
|
|
77
69
|
e.preventDefault();
|
|
78
70
|
element.click();
|
|
79
|
-
|
|
80
71
|
if (element.id === "".concat(id, "-label") || element.id === "".concat(id, "-wrapper")) {
|
|
81
72
|
toggleOpen();
|
|
82
73
|
}
|
|
83
|
-
|
|
84
74
|
break;
|
|
85
|
-
|
|
86
75
|
default:
|
|
87
76
|
}
|
|
88
77
|
}, [id, toggleOpen]);
|
|
@@ -91,7 +80,8 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
91
80
|
id: "".concat(id, "-wrapper"),
|
|
92
81
|
onKeyDown: handleKeyDown,
|
|
93
82
|
ref: containerRef
|
|
94
|
-
}, /*#__PURE__*/React.createElement(DropdownButton
|
|
83
|
+
}, /*#__PURE__*/React.createElement(DropdownButton
|
|
84
|
+
// Only set aria-controls when the dropdown is open
|
|
95
85
|
// (otherwise, assistive technologies may not announce the dropdown correctly).
|
|
96
86
|
, {
|
|
97
87
|
"aria-controls": open ? id : undefined,
|
|
@@ -116,6 +106,5 @@ var Dropdown = function Dropdown(_ref) {
|
|
|
116
106
|
tabIndex: -1
|
|
117
107
|
}, children));
|
|
118
108
|
};
|
|
119
|
-
|
|
120
109
|
export default Dropdown;
|
|
121
110
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useCallback","useEffect","useRef","useState","getNextSibling","getPreviousSibling","DropdownButton","DropdownMenu","DropdownWrapper","Dropdown","_ref","alignMenuLeft","children","className","id","label","listLabel","text","buttonStyle","_useState","_useState2","_slicedToArray","open","setOpen","containerRef","toggleOpen","queryId","concat","isList","Array","isArray","every","child","isValidElement","type","handleExternalAction","e","_containerRef$current","current","contains","target","document","addEventListener","removeEventListener","handleKeyDown","_getPreviousSibling","_getNextSibling","element","key","preventDefault","focus","click","createElement","onKeyDown","ref","undefined","onClick","style","title","role","as","alignLeft","tabIndex"],"sources":["../../src/dropdown/index.tsx"],"sourcesContent":["import React, {\n HTMLAttributes,\n KeyboardEvent,\n useCallback,\n useEffect,\n useRef,\n useState\n} from \"react\";\n\nimport {\n getNextSibling,\n getPreviousSibling\n} from \"../focus-trap-wrapper/dom-query\";\nimport { DropdownButton, DropdownMenu, DropdownWrapper } from \"./styled\";\n\nexport interface Props extends HTMLAttributes<HTMLElement> {\n alignMenuLeft?: boolean;\n buttonStyle?: React.CSSProperties;\n label?: string;\n listLabel?: string;\n text?: JSX.Element | string;\n nav?: boolean;\n}\n\n/**\n * Renders a dropdown menu. By default, only a passed \"text\" is rendered. If clicked,\n * a floating div is rendered below the \"text\" with list contents inside. Clicking anywhere\n * outside the floating div will close the dropdown.\n */\nconst Dropdown = ({\n alignMenuLeft,\n children,\n className,\n id,\n label,\n listLabel,\n text,\n buttonStyle\n}: Props): JSX.Element => {\n const [open, setOpen] = useState(false);\n\n const containerRef = useRef<HTMLSpanElement>(null);\n\n const toggleOpen = useCallback(() => setOpen(!open), [open, setOpen]);\n\n // Argument for document.querySelectorAll to target focusable elements.\n const queryId = `#${id} button, #${id}-label`;\n\n const isList = Array.isArray(children)\n ? children.every(\n child => React.isValidElement(child) && child.type === \"li\"\n )\n : React.isValidElement(children) && children.type === \"li\";\n\n // Adding document event listeners allows us to close the dropdown\n // when the user interacts with any part of the page that isn't the dropdown\n useEffect(() => {\n const handleExternalAction = (e: Event): void => {\n if (!containerRef?.current?.contains(e.target as HTMLElement)) {\n setOpen(false);\n }\n };\n document.addEventListener(\"mousedown\", handleExternalAction);\n document.addEventListener(\"focusin\", handleExternalAction);\n document.addEventListener(\"keydown\", handleExternalAction);\n return () => {\n document.removeEventListener(\"mousedown\", handleExternalAction);\n document.removeEventListener(\"focusin\", handleExternalAction);\n document.removeEventListener(\"keydown\", handleExternalAction);\n };\n }, [containerRef]);\n\n const handleKeyDown = useCallback(\n (e: KeyboardEvent): void => {\n const element = e.target as HTMLElement;\n switch (e.key) {\n case \"ArrowUp\":\n e.preventDefault();\n getPreviousSibling(queryId, element)?.focus();\n break;\n case \"ArrowDown\":\n e.preventDefault();\n getNextSibling(queryId, element)?.focus();\n break;\n case \"Escape\":\n setOpen(false);\n break;\n case \" \":\n case \"Enter\":\n e.preventDefault();\n element.click();\n if (element.id === `${id}-label` || element.id === `${id}-wrapper`) {\n toggleOpen();\n }\n break;\n default:\n }\n },\n [id, toggleOpen]\n );\n\n return (\n <DropdownWrapper\n className={className}\n id={`${id}-wrapper`}\n onKeyDown={handleKeyDown}\n ref={containerRef}\n >\n <DropdownButton\n // Only set aria-controls when the dropdown is open\n // (otherwise, assistive technologies may not announce the dropdown correctly).\n aria-controls={open ? id : undefined}\n aria-expanded={open}\n aria-haspopup=\"listbox\"\n aria-label={label}\n id={`${id}-label`}\n onClick={toggleOpen}\n style={buttonStyle}\n title={label}\n >\n <span>{text}</span>\n <span className=\"caret\" role=\"presentation\" />\n </DropdownButton>\n {open && (\n <DropdownMenu\n as={isList && \"ul\"}\n aria-label={listLabel}\n aria-labelledby={listLabel ? undefined : `${id}-label`}\n id={id}\n onClick={toggleOpen}\n alignLeft={alignMenuLeft}\n role={isList && \"list\"}\n tabIndex={-1}\n >\n {children}\n </DropdownMenu>\n )}\n </DropdownWrapper>\n );\n};\n\nexport default Dropdown;\n"],"mappings":";AAAA,OAAOA,KAAK,IAGVC,WAAW,EACXC,SAAS,EACTC,MAAM,EACNC,QAAQ,QACH,OAAO;AAEd,SACEC,cAAc,EACdC,kBAAkB,QACb,iCAAiC;AACxC,SAASC,cAAc,EAAEC,YAAY,EAAEC,eAAe,QAAQ,UAAU;AAWxE;AACA;AACA;AACA;AACA;AACA,IAAMC,QAAQ,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AElD,aAAc;IACzBgD,IAAI,EAAE/B,MAAM,IAAI,MAAO;IACvBkC,QAAQ,EAAE,CAAC;EAAE,GAEZlD,QACW,CAED,CAAC;AAEtB,CAAC;AAED,eAAeH,QAAQ","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"styled.js","names":["styled","grey","DropdownButton","button","withConfig","displayName","componentId","DropdownMenu","div","props","alignLeft","DropdownWrapper","span","pullRight"],"sources":["../../src/dropdown/styled.tsx"],"sourcesContent":["import styled from \"styled-components\";\nimport grey from \"../colors/grey\";\n\nexport const DropdownButton = styled.button`\n background: #fff;\n border: 1px solid black;\n border-radius: 5px;\n color: inherit;\n padding: 5px 7px;\n transition: all 0.1s ease-in-out;\n\n span.caret {\n border-left: 4px solid transparent;\n border-right: 4px solid transparent;\n border-top: 4px solid;\n color: inherit;\n display: inline-block;\n height: 0;\n margin-left: 5px;\n vertical-align: middle;\n width: 0;\n }\n\n &:hover,\n &[aria-expanded=\"true\"] {\n background: ${grey[50]};\n color: black;\n cursor: pointer;\n }\n`;\n\nexport const DropdownMenu = styled.div<{ alignLeft?: boolean }>`\n background-clip: padding-box;\n background-color: #fff;\n border-radius: 4px;\n border: 1px solid rgba(0, 0, 0, 0.15);\n box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);\n color: #333;\n list-style: none;\n margin: 2px 0 0;\n min-width: 160px;\n padding: 5px 0;\n position: absolute;\n ${props => (props.alignLeft ? \"left: 0;\" : \"right: 0;\")}\n top: 100%;\n width: 100%;\n z-index: 1000;\n\n hr {\n margin: 0;\n padding: 0;\n }\n a,\n button {\n background: transparent;\n border: none;\n cursor: pointer;\n padding: 5px 15px;\n text-align: start;\n width: 100%;\n\n &:hover {\n background: ${grey[50]};\n }\n }\n`;\n\nexport const DropdownWrapper = styled.span<{ pullRight?: boolean }>`\n float: ${props => (props.pullRight ? \"right\" : \"left\")};\n position: relative;\n`;\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,mBAAmB;AACtC,OAAOC,IAAI,MAAM,gBAAgB;AAEjC,OAAO,IAAMC,cAAc,GAAGF,MAAM,CAACG,MAAM,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,8YAsBzBL,IAAI,CAAC,EAAE,CAAC,CAIzB;AAED,OAAO,IAAMM,YAAY,GAAGP,MAAM,CAACQ,GAAG,CAAAJ,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,gbAYlC,UAAAG,KAAK;EAAA,OAAKA,KAAK,CAACC,SAAS,GAAG,UAAU,GAAG,WAAW;AAAA,CAAC,EAmBrCT,IAAI,CAAC,EAAE,CAAC,CAG3B;AAED,OAAO,IAAMU,eAAe,GAAGX,MAAM,CAACY,IAAI,CAAAR,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,sCAC/B,UAAAG,KAAK;EAAA,OAAKA,KAAK,CAACI,SAAS,GAAG,OAAO,GAAG,MAAM;AAAA,CAAC,CAEvD","ignoreList":[]}
|
|
@@ -8,6 +8,7 @@ function getEntries(query) {
|
|
|
8
8
|
lastElement: lastElement
|
|
9
9
|
};
|
|
10
10
|
}
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* Helper method to find the next focusable sibling element relative to the
|
|
13
14
|
* specified element.
|
|
@@ -16,21 +17,18 @@ function getEntries(query) {
|
|
|
16
17
|
* @param {HTMLElement} element - Specified element (e.target)
|
|
17
18
|
* @returns {HTMLElement} - element to be focused
|
|
18
19
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
20
|
export function getNextSibling(query, element) {
|
|
22
21
|
var _getEntries = getEntries(query),
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
entries = _getEntries.entries,
|
|
23
|
+
firstElement = _getEntries.firstElement,
|
|
24
|
+
lastElement = _getEntries.lastElement;
|
|
27
25
|
if (element === lastElement) {
|
|
28
26
|
return firstElement;
|
|
29
27
|
}
|
|
30
|
-
|
|
31
28
|
var elementIndex = entries.indexOf(element);
|
|
32
29
|
return entries[elementIndex + 1];
|
|
33
30
|
}
|
|
31
|
+
|
|
34
32
|
/**
|
|
35
33
|
* Helper method to find the previous focusable sibling element relative to the
|
|
36
34
|
* specified element.
|
|
@@ -39,17 +37,14 @@ export function getNextSibling(query, element) {
|
|
|
39
37
|
* @param {HTMLElement} element - Specified element (e.target)
|
|
40
38
|
* @returns {HTMLElement} - element to be focused
|
|
41
39
|
*/
|
|
42
|
-
|
|
43
40
|
export function getPreviousSibling(query, element) {
|
|
44
41
|
var _getEntries2 = getEntries(query),
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
42
|
+
entries = _getEntries2.entries,
|
|
43
|
+
firstElement = _getEntries2.firstElement,
|
|
44
|
+
lastElement = _getEntries2.lastElement;
|
|
49
45
|
if (element === firstElement) {
|
|
50
46
|
return lastElement;
|
|
51
47
|
}
|
|
52
|
-
|
|
53
48
|
var elementIndex = entries.indexOf(element);
|
|
54
49
|
return entries[elementIndex - 1];
|
|
55
50
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"dom-query.js","names":["getEntries","query","entries","Array","from","document","querySelectorAll","firstElement","lastElement","length","getNextSibling","element","_getEntries","elementIndex","indexOf","getPreviousSibling","_getEntries2"],"sources":["../../src/focus-trap-wrapper/dom-query.ts"],"sourcesContent":["function getEntries(query: string) {\n const entries = Array.from(document.querySelectorAll(query));\n const firstElement = entries[0];\n const lastElement = entries[entries.length - 1];\n\n return { entries, firstElement, lastElement };\n}\n\n/**\n * Helper method to find the next focusable sibling element relative to the\n * specified element.\n *\n * @param {string} query - Argument that gets passed to document.querySelectorAll\n * @param {HTMLElement} element - Specified element (e.target)\n * @returns {HTMLElement} - element to be focused\n */\nexport function getNextSibling(\n query: string,\n element: EventTarget\n): HTMLElement {\n const { entries, firstElement, lastElement } = getEntries(query);\n\n if (element === lastElement) {\n return firstElement as HTMLElement;\n }\n const elementIndex = entries.indexOf(element as HTMLElement);\n return entries[elementIndex + 1] as HTMLElement;\n}\n\n/**\n * Helper method to find the previous focusable sibling element relative to the\n * specified element.\n *\n * @param {string} query - Argument that gets passed to document.querySelectorAll\n * @param {HTMLElement} element - Specified element (e.target)\n * @returns {HTMLElement} - element to be focused\n */\nexport function getPreviousSibling(\n query: string,\n element: EventTarget\n): HTMLElement {\n const { entries, firstElement, lastElement } = getEntries(query);\n\n if (element === firstElement) {\n return lastElement as HTMLElement;\n }\n const elementIndex = entries.indexOf(element as HTMLButtonElement);\n return entries[elementIndex - 1] as HTMLElement;\n}\n"],"mappings":"AAAA,SAASA,UAAUA,CAACC,KAAa,EAAE;EACjC,IAAMC,OAAO,GAAGC,KAAK,CAACC,IAAI,CAACC,QAAQ,CAACC,gBAAgB,CAACL,KAAK,CAAC,CAAC;EAC5D,IAAMM,YAAY,GAAGL,OAAO,CAAC,CAAC,CAAC;EAC/B,IAAMM,WAAW,GAAGN,OAAO,CAACA,OAAO,CAACO,MAAM,GAAG,CAAC,CAAC;EAE/C,OAAO;IAAEP,OAAO,EAAPA,OAAO;IAAEK,YAAY,EAAZA,YAAY;IAAEC,WAAW,EAAXA;EAAY,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,cAAcA,CAC5BT,KAAa,EACbU,OAAoB,EACP;EACb,IAAAC,WAAA,GAA+CZ,UAAU,CAACC,KAAK,CAAC;IAAxDC,OAAO,GAAAU,WAAA,CAAPV,OAAO;IAAEK,YAAY,GAAAK,WAAA,CAAZL,YAAY;IAAEC,WAAW,GAAAI,WAAA,CAAXJ,WAAW;EAE1C,IAAIG,OAAO,KAAKH,WAAW,EAAE;IAC3B,OAAOD,YAAY;EACrB;EACA,IAAMM,YAAY,GAAGX,OAAO,CAACY,OAAO,CAACH,OAAsB,CAAC;EAC5D,OAAOT,OAAO,CAACW,YAAY,GAAG,CAAC,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASE,kBAAkBA,CAChCd,KAAa,EACbU,OAAoB,EACP;EACb,IAAAK,YAAA,GAA+ChB,UAAU,CAACC,KAAK,CAAC;IAAxDC,OAAO,GAAAc,YAAA,CAAPd,OAAO;IAAEK,YAAY,GAAAS,YAAA,CAAZT,YAAY;IAAEC,WAAW,GAAAQ,YAAA,CAAXR,WAAW;EAE1C,IAAIG,OAAO,KAAKJ,YAAY,EAAE;IAC5B,OAAOC,WAAW;EACpB;EACA,IAAMK,YAAY,GAAGX,OAAO,CAACY,OAAO,CAACH,OAA4B,CAAC;EAClE,OAAOT,OAAO,CAACW,YAAY,GAAG,CAAC,CAAC;AAClC","ignoreList":[]}
|
|
@@ -1,39 +1,31 @@
|
|
|
1
1
|
import React, { useCallback } from "react";
|
|
2
2
|
import { getNextSibling, getPreviousSibling } from "./dom-query";
|
|
3
|
-
|
|
4
3
|
var FocusTrapWrapper = function FocusTrapWrapper(_ref) {
|
|
5
4
|
var children = _ref.children,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
_ref$closePopup = _ref.closePopup,
|
|
6
|
+
closePopup = _ref$closePopup === void 0 ? null : _ref$closePopup,
|
|
7
|
+
_ref$focusElements = _ref.focusElements,
|
|
8
|
+
focusElements = _ref$focusElements === void 0 ? ["button", "a", "input", "select"] : _ref$focusElements,
|
|
9
|
+
id = _ref.id;
|
|
11
10
|
var queryId = focusElements.map(function (el) {
|
|
12
11
|
return "#".concat(id, "-focus-trap ").concat(el, ":not([disabled])");
|
|
13
12
|
}).join(", ");
|
|
14
13
|
var handleKeyDown = useCallback(function (e) {
|
|
15
14
|
var element = e.target;
|
|
16
|
-
|
|
17
15
|
switch (e.key) {
|
|
18
16
|
case "Escape":
|
|
19
17
|
closePopup();
|
|
20
18
|
break;
|
|
21
|
-
|
|
22
19
|
case "Tab":
|
|
23
20
|
e.preventDefault();
|
|
24
|
-
|
|
25
21
|
if (e.shiftKey) {
|
|
26
22
|
var _getPreviousSibling;
|
|
27
|
-
|
|
28
|
-
(_getPreviousSibling = getPreviousSibling(queryId, element)) === null || _getPreviousSibling === void 0 ? void 0 : _getPreviousSibling.focus();
|
|
23
|
+
(_getPreviousSibling = getPreviousSibling(queryId, element)) === null || _getPreviousSibling === void 0 || _getPreviousSibling.focus();
|
|
29
24
|
} else {
|
|
30
25
|
var _getNextSibling;
|
|
31
|
-
|
|
32
|
-
(_getNextSibling = getNextSibling(queryId, element)) === null || _getNextSibling === void 0 ? void 0 : _getNextSibling.focus();
|
|
26
|
+
(_getNextSibling = getNextSibling(queryId, element)) === null || _getNextSibling === void 0 || _getNextSibling.focus();
|
|
33
27
|
}
|
|
34
|
-
|
|
35
28
|
break;
|
|
36
|
-
|
|
37
29
|
default:
|
|
38
30
|
}
|
|
39
31
|
}, [closePopup]);
|
|
@@ -43,7 +35,6 @@ var FocusTrapWrapper = function FocusTrapWrapper(_ref) {
|
|
|
43
35
|
role: "presentation"
|
|
44
36
|
}, children);
|
|
45
37
|
};
|
|
46
|
-
|
|
47
38
|
export { getNextSibling, getPreviousSibling };
|
|
48
39
|
export default FocusTrapWrapper;
|
|
49
40
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["React","useCallback","getNextSibling","getPreviousSibling","FocusTrapWrapper","_ref","children","_ref$closePopup","closePopup","_ref$focusElements","focusElements","id","queryId","map","el","concat","join","handleKeyDown","e","element","target","key","preventDefault","shiftKey","_getPreviousSibling","focus","_getNextSibling","createElement","onKeyDown","role"],"sources":["../../src/focus-trap-wrapper/index.tsx"],"sourcesContent":["import React, { ReactNode, useCallback } from \"react\";\nimport { getNextSibling, getPreviousSibling } from \"./dom-query\";\n\nconst FocusTrapWrapper = ({\n children,\n closePopup = null,\n focusElements = [\"button\", \"a\", \"input\", \"select\"],\n id\n}: {\n children: ReactNode | ReactNode[];\n closePopup?: (arg?: boolean) => void;\n id: string;\n focusElements?: string[];\n}): JSX.Element => {\n const queryId = focusElements\n .map(el => `#${id}-focus-trap ${el}:not([disabled])`)\n .join(\", \");\n const handleKeyDown = useCallback(\n e => {\n const element = e.target as HTMLElement;\n switch (e.key) {\n case \"Escape\":\n closePopup();\n break;\n case \"Tab\":\n e.preventDefault();\n if (e.shiftKey) {\n getPreviousSibling(queryId, element)?.focus();\n } else {\n getNextSibling(queryId, element)?.focus();\n }\n break;\n default:\n }\n },\n [closePopup]\n );\n\n return (\n <div id={`${id}-focus-trap`} onKeyDown={handleKeyDown} role=\"presentation\">\n {children}\n </div>\n );\n};\n\nexport { getNextSibling, getPreviousSibling };\n\nexport default FocusTrapWrapper;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAeC,WAAW,QAAQ,OAAO;AACrD,SAASC,cAAc,EAAEC,kBAAkB,QAAQ,aAAa;AAEhE,IAAMC,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAAC,IAAA,EAUH;EAAA,IATjBC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;IAAAC,eAAA,GAAAF,IAAA,CACRG,UAAU;IAAVA,UAAU,GAAAD,eAAA,cAAG,IAAI,GAAAA,eAAA;IAAAE,kBAAA,GAAAJ,IAAA,CACjBK,aAAa;IAAbA,aAAa,GAAAD,kBAAA,cAAG,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,QAAQ,CAAC,GAAAA,kBAAA;IAClDE,EAAE,GAAAN,IAAA,CAAFM,EAAE;EAOF,IAAMC,OAAO,GAAGF,aAAa,CAC1BG,GAAG,CAAC,UAAAC,EAAE;IAAA,WAAAC,MAAA,CAAQJ,EAAE,kBAAAI,MAAA,CAAeD,EAAE;EAAA,CAAkB,CAAC,CACpDE,IAAI,CAAC,IAAI,CAAC;EACb,IAAMC,aAAa,GAAGhB,WAAW,CAC/B,UAAAiB,CAAC,EAAI;IACH,IAAMC,OAAO,GAAGD,CAAC,CAACE,MAAqB;IACvC,QAAQF,CAAC,CAACG,GAAG;MACX,KAAK,QAAQ;QACXb,UAAU,CAAC,CAAC;QACZ;MACF,KAAK,KAAK;QACRU,CAAC,CAACI,cAAc,CAAC,CAAC;QAClB,IAAIJ,CAAC,CAACK,QAAQ,EAAE;UAAA,IAAAC,mBAAA;UACd,CAAAA,mBAAA,GAAArB,kBAAkB,CAACS,OAAO,EAAEO,OAAO,CAAC,cAAAK,mBAAA,eAApCA,mBAAA,CAAsCC,KAAK,CAAC,CAAC;QAC/C,CAAC,MAAM;UAAA,IAAAC,eAAA;UACL,CAAAA,eAAA,GAAAxB,cAAc,CAACU,OAAO,EAAEO,OAAO,CAAC,cAAAO,eAAA,eAAhCA,eAAA,CAAkCD,KAAK,CAAC,CAAC;QAC3C;QACA;MACF;IACF;EACF,CAAC,EACD,CAACjB,UAAU,CACb,CAAC;EAED,oBACER,KAAA,CAAA2B,aAAA;IAAKhB,EAAE,KAAAI,MAAA,CAAKJ,EAAE,gBAAc;IAACiB,SAAS,EAAEX,aAAc;IAACY,IAAI,EAAC;EAAc,GACvEvB,QACE,CAAC;AAEV,CAAC;AAED,SAASJ,cAAc,EAAEC,kBAAkB;AAE3C,eAAeC,gBAAgB","ignoreList":[]}
|
package/esm/index.js
CHANGED
|
@@ -2,8 +2,9 @@ import blue from "./colors/blue";
|
|
|
2
2
|
import red from "./colors/red";
|
|
3
3
|
import grey from "./colors/grey";
|
|
4
4
|
import Dropdown from "./dropdown";
|
|
5
|
-
import FocusTrapWrapper, { getNextSibling, getPreviousSibling } from "./focus-trap-wrapper";
|
|
5
|
+
import FocusTrapWrapper, { getNextSibling, getPreviousSibling } from "./focus-trap-wrapper";
|
|
6
6
|
|
|
7
|
+
// TODO: Fix exports
|
|
7
8
|
export { Dropdown, FocusTrapWrapper, getNextSibling, getPreviousSibling };
|
|
8
9
|
export default {
|
|
9
10
|
blue: blue,
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.js","names":["blue","red","grey","Dropdown","FocusTrapWrapper","getNextSibling","getPreviousSibling"],"sources":["../src/index.ts"],"sourcesContent":["import blue from \"./colors/blue\";\nimport red from \"./colors/red\";\nimport grey from \"./colors/grey\";\nimport Dropdown from \"./dropdown\";\nimport FocusTrapWrapper, {\n getNextSibling,\n getPreviousSibling\n} from \"./focus-trap-wrapper\";\n\n// TODO: Fix exports\nexport { Dropdown, FocusTrapWrapper, getNextSibling, getPreviousSibling };\nexport default { blue, red, grey };\n"],"mappings":"AAAA,OAAOA,IAAI,MAAM,eAAe;AAChC,OAAOC,GAAG,MAAM,cAAc;AAC9B,OAAOC,IAAI,MAAM,eAAe;AAChC,OAAOC,QAAQ,MAAM,YAAY;AACjC,OAAOC,gBAAgB,IACrBC,cAAc,EACdC,kBAAkB,QACb,sBAAsB;;AAE7B;AACA,SAASH,QAAQ,EAAEC,gBAAgB,EAAEC,cAAc,EAAEC,kBAAkB;AACvE,eAAe;EAAEN,IAAI,EAAJA,IAAI;EAAEC,GAAG,EAAHA,GAAG;EAAEC,IAAI,EAAJA;AAAK,CAAC","ignoreList":[]}
|
|
@@ -11,7 +11,6 @@ var ColorBlock = styled.div.withConfig({
|
|
|
11
11
|
}, function (props) {
|
|
12
12
|
return getMostReadableTextColor(props.hex, "#ffffff") === "#ffffff" ? "1px 1px 2px black" : "";
|
|
13
13
|
});
|
|
14
|
-
|
|
15
14
|
var ColorPalette = function ColorPalette(_ref) {
|
|
16
15
|
var color = _ref.color;
|
|
17
16
|
var colorArray = Object.entries(color);
|
|
@@ -22,6 +21,5 @@ var ColorPalette = function ColorPalette(_ref) {
|
|
|
22
21
|
}, /*#__PURE__*/React.createElement("p", null, hue[0]), /*#__PURE__*/React.createElement("p", null, hue[1]));
|
|
23
22
|
}));
|
|
24
23
|
};
|
|
25
|
-
|
|
26
24
|
export default ColorPalette;
|
|
27
25
|
//# sourceMappingURL=ColorPalette.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"ColorPalette.js","names":["React","styled","getMostReadableTextColor","ColorBlock","div","withConfig","displayName","componentId","props","hex","ColorPalette","_ref","color","colorArray","Object","entries","createElement","Fragment","map","hue","key"],"sources":["../../src/stories/ColorPalette.tsx"],"sourcesContent":["import React from \"react\";\n\nimport styled from \"styled-components\";\nimport { getMostReadableTextColor } from \"@opentripplanner/core-utils/lib/route\";\n\nexport interface Hue {\n [key: number]: string;\n}\n\ninterface Props {\n color: Hue;\n}\n\nconst ColorBlock = styled.div<{ hex: string }>`\n align-items: center;\n background-color: ${props => props.hex};\n color: ${props => getMostReadableTextColor(props.hex, \"#ffffff\")};\n text-shadow: ${props =>\n getMostReadableTextColor(props.hex, \"#ffffff\") === \"#ffffff\"\n ? \"1px 1px 2px black\"\n : \"\"};\n display: flex;\n font-family: Arial, Helvetica, sans-serif;\n height: 40px;\n justify-content: space-between;\n margin: 0;\n padding: 10px;\n width: 300px;\n\n &:first-of-type {\n border-radius: 8px 8px 0 0;\n }\n &:last-of-type {\n border-radius: 0 0 8px 8px;\n }\n`;\n\nconst ColorPalette = ({ color }: Props): JSX.Element => {\n const colorArray: Array<Hue> = Object.entries(color);\n\n return (\n <>\n {colorArray.map(\n (hue: Hue): JSX.Element => {\n return (\n <ColorBlock key={hue[0]} hex={hue[1]}>\n <p>{hue[0]}</p>\n <p>{hue[1]}</p>\n </ColorBlock>\n );\n }\n )}\n </>\n );\n};\nexport default ColorPalette;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,OAAOC,MAAM,MAAM,mBAAmB;AACtC,SAASC,wBAAwB,QAAQ,uCAAuC;AAUhF,IAAMC,UAAU,GAAGF,MAAM,CAACG,GAAG,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,mSAEP,UAAAC,KAAK;EAAA,OAAIA,KAAK,CAACC,GAAG;AAAA,GAC7B,UAAAD,KAAK;EAAA,OAAIN,wBAAwB,CAACM,KAAK,CAACC,GAAG,EAAE,SAAS,CAAC;AAAA,GACjD,UAAAD,KAAK;EAAA,OAClBN,wBAAwB,CAACM,KAAK,CAACC,GAAG,EAAE,SAAS,CAAC,KAAK,SAAS,GACxD,mBAAmB,GACnB,EAAE;AAAA,EAeT;AAED,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CAAAC,IAAA,EAAsC;EAAA,IAAhCC,KAAK,GAAAD,IAAA,CAALC,KAAK;EAC3B,IAAMC,UAAsB,GAAGC,MAAM,CAACC,OAAO,CAACH,KAAK,CAAC;EAEpD,oBACEZ,KAAA,CAAAgB,aAAA,CAAAhB,KAAA,CAAAiB,QAAA,QACGJ,UAAU,CAACK,GAAG,CACb,UAACC,GAAQ,EAAkB;IACzB,oBACEnB,KAAA,CAAAgB,aAAA,CAACb,UAAU;MAACiB,GAAG,EAAED,GAAG,CAAC,CAAC,CAAE;MAACV,GAAG,EAAEU,GAAG,CAAC,CAAC;IAAE,gBACnCnB,KAAA,CAAAgB,aAAA,YAAIG,GAAG,CAAC,CAAC,CAAK,CAAC,eACfnB,KAAA,CAAAgB,aAAA,YAAIG,GAAG,CAAC,CAAC,CAAK,CACJ,CAAC;EAEjB,CACF,CACA,CAAC;AAEP,CAAC;AACD,eAAeT,YAAY","ignoreList":[]}
|
package/i18n/en-US.yml
ADDED
package/i18n/fr.yml
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactChild } from "react";
|
|
2
|
+
import { StyledIcon } from "@styled-icons/styled-icon";
|
|
3
|
+
interface Props {
|
|
4
|
+
alertHeader: string;
|
|
5
|
+
alertSubheader?: string;
|
|
6
|
+
backgroundColor?: string;
|
|
7
|
+
collapsible?: boolean;
|
|
8
|
+
children?: ReactChild;
|
|
9
|
+
Icon?: StyledIcon;
|
|
10
|
+
}
|
|
11
|
+
declare const Alert: ({ alertHeader, alertSubheader, backgroundColor, children, collapsible, Icon }: Props) => JSX.Element;
|
|
12
|
+
export default Alert;
|
|
13
|
+
//# sourceMappingURL=Alert.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Alert.d.ts","sourceRoot":"","sources":["../../src/alert/Alert.tsx"],"names":[],"mappings":"AAAA,OAAc,EAAE,UAAU,EAAY,MAAM,OAAO,CAAC;AAKpD,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAIvD,UAAU,KAAK;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,QAAQ,CAAC,EAAE,UAAU,CAAC;IACtB,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB;AAoED,QAAA,MAAM,KAAK,kFAOR,KAAK,KAAG,WA0CV,CAAC;AAEF,eAAe,KAAK,CAAC"}
|