@opentripplanner/building-blocks 1.0.3 → 1.1.0
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/esm/dropdown/index.js +121 -0
- package/esm/dropdown/index.js.map +1 -0
- package/esm/dropdown/styled.js +19 -0
- package/esm/dropdown/styled.js.map +1 -0
- package/esm/index.js +2 -0
- package/esm/index.js.map +1 -1
- package/esm/utils/dom-query.js +56 -0
- package/esm/utils/dom-query.js.map +1 -0
- package/lib/dropdown/index.d.ts +17 -0
- package/lib/dropdown/index.d.ts.map +1 -0
- package/lib/dropdown/index.js +126 -0
- package/lib/dropdown/index.js.map +1 -0
- package/lib/dropdown/styled.d.ts +8 -0
- package/lib/dropdown/styled.d.ts.map +1 -0
- package/lib/dropdown/styled.js +34 -0
- package/lib/dropdown/styled.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/stories/dropdown.story.d.ts +9 -0
- package/lib/stories/dropdown.story.d.ts.map +1 -0
- package/lib/stories/dropdown.story.js +59 -0
- package/lib/stories/dropdown.story.js.map +1 -0
- package/lib/utils/dom-query.d.ts +19 -0
- package/lib/utils/dom-query.d.ts.map +1 -0
- package/lib/utils/dom-query.js +67 -0
- package/lib/utils/dom-query.js.map +1 -0
- package/package.json +3 -3
- package/src/dropdown/index.tsx +139 -0
- package/src/dropdown/styled.tsx +71 -0
- package/src/index.ts +2 -0
- package/src/stories/dropdown.story.tsx +105 -0
- package/src/utils/dom-query.ts +49 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import { getNextSibling, getPreviousSibling } from "../utils/dom-query";
|
|
4
|
+
import { DropdownButton, DropdownMenu, DropdownWrapper } from "./styled";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Renders a dropdown menu. By default, only a passed "text" is rendered. If clicked,
|
|
8
|
+
* a floating div is rendered below the "text" with list contents inside. Clicking anywhere
|
|
9
|
+
* outside the floating div will close the dropdown.
|
|
10
|
+
*/
|
|
11
|
+
var Dropdown = function Dropdown(_ref) {
|
|
12
|
+
var alignMenuLeft = _ref.alignMenuLeft,
|
|
13
|
+
children = _ref.children,
|
|
14
|
+
className = _ref.className,
|
|
15
|
+
id = _ref.id,
|
|
16
|
+
label = _ref.label,
|
|
17
|
+
listLabel = _ref.listLabel,
|
|
18
|
+
text = _ref.text,
|
|
19
|
+
buttonStyle = _ref.buttonStyle;
|
|
20
|
+
|
|
21
|
+
var _useState = useState(false),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
open = _useState2[0],
|
|
24
|
+
setOpen = _useState2[1];
|
|
25
|
+
|
|
26
|
+
var containerRef = useRef(null);
|
|
27
|
+
var toggleOpen = useCallback(function () {
|
|
28
|
+
return setOpen(!open);
|
|
29
|
+
}, [open, setOpen]); // Argument for document.querySelectorAll to target focusable elements.
|
|
30
|
+
|
|
31
|
+
var queryId = "#".concat(id, " button, #").concat(id, "-label");
|
|
32
|
+
var isList = Array.isArray(children) ? children.every(function (child) {
|
|
33
|
+
return /*#__PURE__*/React.isValidElement(child) && child.type === "li";
|
|
34
|
+
}) : /*#__PURE__*/React.isValidElement(children) && children.type === "li"; // 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
|
|
36
|
+
|
|
37
|
+
useEffect(function () {
|
|
38
|
+
var handleExternalAction = function handleExternalAction(e) {
|
|
39
|
+
var _containerRef$current;
|
|
40
|
+
|
|
41
|
+
if (!(containerRef !== null && containerRef !== void 0 && (_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(e.target))) {
|
|
42
|
+
setOpen(false);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
document.addEventListener("mousedown", handleExternalAction);
|
|
47
|
+
document.addEventListener("focusin", handleExternalAction);
|
|
48
|
+
document.addEventListener("keydown", handleExternalAction);
|
|
49
|
+
return function () {
|
|
50
|
+
document.removeEventListener("mousedown", handleExternalAction);
|
|
51
|
+
document.removeEventListener("focusin", handleExternalAction);
|
|
52
|
+
document.removeEventListener("keydown", handleExternalAction);
|
|
53
|
+
};
|
|
54
|
+
}, [containerRef]);
|
|
55
|
+
var handleKeyDown = useCallback(function (e) {
|
|
56
|
+
var _getPreviousSibling, _getNextSibling;
|
|
57
|
+
|
|
58
|
+
var element = e.target;
|
|
59
|
+
|
|
60
|
+
switch (e.key) {
|
|
61
|
+
case "ArrowUp":
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
(_getPreviousSibling = getPreviousSibling(queryId, element)) === null || _getPreviousSibling === void 0 ? void 0 : _getPreviousSibling.focus();
|
|
64
|
+
break;
|
|
65
|
+
|
|
66
|
+
case "ArrowDown":
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
(_getNextSibling = getNextSibling(queryId, element)) === null || _getNextSibling === void 0 ? void 0 : _getNextSibling.focus();
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case "Escape":
|
|
72
|
+
setOpen(false);
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case " ":
|
|
76
|
+
case "Enter":
|
|
77
|
+
e.preventDefault();
|
|
78
|
+
element.click();
|
|
79
|
+
|
|
80
|
+
if (element.id === "".concat(id, "-label") || element.id === "".concat(id, "-wrapper")) {
|
|
81
|
+
toggleOpen();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
break;
|
|
85
|
+
|
|
86
|
+
default:
|
|
87
|
+
}
|
|
88
|
+
}, [id, toggleOpen]);
|
|
89
|
+
return /*#__PURE__*/React.createElement(DropdownWrapper, {
|
|
90
|
+
className: className,
|
|
91
|
+
id: "".concat(id, "-wrapper"),
|
|
92
|
+
onKeyDown: handleKeyDown,
|
|
93
|
+
ref: containerRef
|
|
94
|
+
}, /*#__PURE__*/React.createElement(DropdownButton // Only set aria-controls when the dropdown is open
|
|
95
|
+
// (otherwise, assistive technologies may not announce the dropdown correctly).
|
|
96
|
+
, {
|
|
97
|
+
"aria-controls": open ? id : undefined,
|
|
98
|
+
"aria-expanded": open,
|
|
99
|
+
"aria-haspopup": "listbox",
|
|
100
|
+
"aria-label": label,
|
|
101
|
+
id: "".concat(id, "-label"),
|
|
102
|
+
onClick: toggleOpen,
|
|
103
|
+
style: buttonStyle,
|
|
104
|
+
title: label
|
|
105
|
+
}, /*#__PURE__*/React.createElement("span", null, text), /*#__PURE__*/React.createElement("span", {
|
|
106
|
+
className: "caret",
|
|
107
|
+
role: "presentation"
|
|
108
|
+
})), open && /*#__PURE__*/React.createElement(DropdownMenu, {
|
|
109
|
+
as: isList && "ul",
|
|
110
|
+
"aria-label": listLabel,
|
|
111
|
+
"aria-labelledby": listLabel ? undefined : "".concat(id, "-label"),
|
|
112
|
+
id: id,
|
|
113
|
+
onClick: toggleOpen,
|
|
114
|
+
alignLeft: alignMenuLeft,
|
|
115
|
+
role: isList && "list",
|
|
116
|
+
tabIndex: -1
|
|
117
|
+
}, children));
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
export default Dropdown;
|
|
121
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/dropdown/index.tsx"],"names":["React","useCallback","useEffect","useRef","useState","getNextSibling","getPreviousSibling","DropdownButton","DropdownMenu","DropdownWrapper","Dropdown","alignMenuLeft","children","className","id","label","listLabel","text","buttonStyle","open","setOpen","containerRef","toggleOpen","queryId","isList","Array","isArray","every","child","isValidElement","type","handleExternalAction","e","current","contains","target","document","addEventListener","removeEventListener","handleKeyDown","element","key","preventDefault","focus","click","undefined"],"mappings":";AAAA,OAAOA,KAAP,IAGEC,WAHF,EAIEC,SAJF,EAKEC,MALF,EAMEC,Q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,\n useRef,\n useState\n} from \"react\";\n\nimport { getNextSibling, getPreviousSibling } from \"../utils/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"],"file":"index.js"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import styled from "styled-components";
|
|
2
|
+
import grey from "../colors/grey";
|
|
3
|
+
export var DropdownButton = styled.button.withConfig({
|
|
4
|
+
displayName: "styled__DropdownButton",
|
|
5
|
+
componentId: "sc-kes9ha-0"
|
|
6
|
+
})(["background:#fff;border:1px solid black;border-radius:5px;color:inherit;padding:5px 7px;transition:all 0.1s ease-in-out;span.caret{border-left:4px solid transparent;border-right:4px solid transparent;border-top:4px solid;color:inherit;display:inline-block;height:0;margin-left:5px;vertical-align:middle;width:0;}&:hover,&[aria-expanded=\"true\"]{background:", ";color:black;cursor:pointer;}"], grey[50]);
|
|
7
|
+
export var DropdownMenu = styled.div.withConfig({
|
|
8
|
+
displayName: "styled__DropdownMenu",
|
|
9
|
+
componentId: "sc-kes9ha-1"
|
|
10
|
+
})(["background-clip:padding-box;background-color:#fff;border-radius:4px;border:1px solid rgba(0,0,0,0.15);box-shadow:0 6px 12px rgba(0,0,0,0.175);color:#333;list-style:none;margin:2px 0 0;min-width:160px;padding:5px 0;position:absolute;", " top:100%;width:100%;z-index:1000;hr{margin:0;padding:0;}a,button{background:transparent;border:none;cursor:pointer;padding:5px 15px;text-align:start;width:100%;&:hover{background:", ";}}"], function (props) {
|
|
11
|
+
return props.alignLeft ? "left: 0;" : "right: 0;";
|
|
12
|
+
}, grey[50]);
|
|
13
|
+
export var DropdownWrapper = styled.span.withConfig({
|
|
14
|
+
displayName: "styled__DropdownWrapper",
|
|
15
|
+
componentId: "sc-kes9ha-2"
|
|
16
|
+
})(["float:", ";position:relative;"], function (props) {
|
|
17
|
+
return props.pullRight ? "right" : "left";
|
|
18
|
+
});
|
|
19
|
+
//# sourceMappingURL=styled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/dropdown/styled.tsx"],"names":["styled","grey","DropdownButton","button","DropdownMenu","div","props","alignLeft","DropdownWrapper","span","pullRight"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,mBAAnB;AACA,OAAOC,IAAP,MAAiB,gBAAjB;AAEA,OAAO,IAAMC,cAAc,GAAGF,MAAM,CAACG,MAAV;AAAA;AAAA;AAAA,8YAsBTF,IAAI,CAAC,EAAD,CAtBK,CAApB;AA4BP,OAAO,IAAMG,YAAY,GAAGJ,MAAM,CAACK,GAAV;AAAA;AAAA;AAAA,gbAYrB,UAAAC,KAAK;AAAA,SAAKA,KAAK,CAACC,SAAN,GAAkB,UAAlB,GAA+B,WAApC;AAAA,CAZgB,EA+BLN,IAAI,CAAC,EAAD,CA/BC,CAAlB;AAoCP,OAAO,IAAMO,eAAe,GAAGR,MAAM,CAACS,IAAV;AAAA;AAAA;AAAA,sCACjB,UAAAH,KAAK;AAAA,SAAKA,KAAK,CAACI,SAAN,GAAkB,OAAlB,GAA4B,MAAjC;AAAA,CADY,CAArB","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"],"file":"styled.js"}
|
package/esm/index.js
CHANGED
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["blue","red","grey"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,eAAjB;AACA,OAAOC,GAAP,MAAgB,cAAhB;AACA,OAAOC,IAAP,MAAiB,eAAjB;AAEA,eAAe;
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["blue","red","grey","Dropdown"],"mappings":"AAAA,OAAOA,IAAP,MAAiB,eAAjB;AACA,OAAOC,GAAP,MAAgB,cAAhB;AACA,OAAOC,IAAP,MAAiB,eAAjB;AACA,OAAOC,QAAP,MAAqB,YAArB;AAEA,SAASA,QAAT;AACA,eAAe;AAAEH,EAAAA,IAAI,EAAJA,IAAF;AAAQC,EAAAA,GAAG,EAAHA,GAAR;AAAaC,EAAAA,IAAI,EAAJA;AAAb,CAAf","sourcesContent":["import blue from \"./colors/blue\";\nimport red from \"./colors/red\";\nimport grey from \"./colors/grey\";\nimport Dropdown from \"./dropdown\";\n\nexport { Dropdown };\nexport default { blue, red, grey };\n"],"file":"index.js"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
function getEntries(query) {
|
|
2
|
+
var entries = Array.from(document.querySelectorAll(query));
|
|
3
|
+
var firstElement = entries[0];
|
|
4
|
+
var lastElement = entries[entries.length - 1];
|
|
5
|
+
return {
|
|
6
|
+
entries: entries,
|
|
7
|
+
firstElement: firstElement,
|
|
8
|
+
lastElement: lastElement
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Helper method to find the next focusable sibling element relative to the
|
|
13
|
+
* specified element.
|
|
14
|
+
*
|
|
15
|
+
* @param {string} query - Argument that gets passed to document.querySelectorAll
|
|
16
|
+
* @param {HTMLElement} element - Specified element (e.target)
|
|
17
|
+
* @returns {HTMLElement} - element to be focused
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export function getNextSibling(query, element) {
|
|
22
|
+
var _getEntries = getEntries(query),
|
|
23
|
+
entries = _getEntries.entries,
|
|
24
|
+
firstElement = _getEntries.firstElement,
|
|
25
|
+
lastElement = _getEntries.lastElement;
|
|
26
|
+
|
|
27
|
+
if (element === lastElement) {
|
|
28
|
+
return firstElement;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
var elementIndex = entries.indexOf(element);
|
|
32
|
+
return entries[elementIndex + 1];
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Helper method to find the previous focusable sibling element relative to the
|
|
36
|
+
* specified element.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} query - Argument that gets passed to document.querySelectorAll
|
|
39
|
+
* @param {HTMLElement} element - Specified element (e.target)
|
|
40
|
+
* @returns {HTMLElement} - element to be focused
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
export function getPreviousSibling(query, element) {
|
|
44
|
+
var _getEntries2 = getEntries(query),
|
|
45
|
+
entries = _getEntries2.entries,
|
|
46
|
+
firstElement = _getEntries2.firstElement,
|
|
47
|
+
lastElement = _getEntries2.lastElement;
|
|
48
|
+
|
|
49
|
+
if (element === firstElement) {
|
|
50
|
+
return lastElement;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var elementIndex = entries.indexOf(element);
|
|
54
|
+
return entries[elementIndex - 1];
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=dom-query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/utils/dom-query.ts"],"names":["getEntries","query","entries","Array","from","document","querySelectorAll","firstElement","lastElement","length","getNextSibling","element","elementIndex","indexOf","getPreviousSibling"],"mappings":"AAAA,SAASA,UAAT,CAAoBC,KAApB,EAAmC;AACjC,MAAMC,OAAO,GAAGC,KAAK,CAACC,IAAN,CAAWC,QAAQ,CAACC,gBAAT,CAA0BL,KAA1B,CAAX,CAAhB;AACA,MAAMM,YAAY,GAAGL,OAAO,CAAC,CAAD,CAA5B;AACA,MAAMM,WAAW,GAAGN,OAAO,CAACA,OAAO,CAACO,MAAR,GAAiB,CAAlB,CAA3B;AAEA,SAAO;AAAEP,IAAAA,OAAO,EAAPA,OAAF;AAAWK,IAAAA,YAAY,EAAZA,YAAX;AAAyBC,IAAAA,WAAW,EAAXA;AAAzB,GAAP;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASE,cAAT,CACLT,KADK,EAELU,OAFK,EAGQ;AACb,oBAA+CX,UAAU,CAACC,KAAD,CAAzD;AAAA,MAAQC,OAAR,eAAQA,OAAR;AAAA,MAAiBK,YAAjB,eAAiBA,YAAjB;AAAA,MAA+BC,WAA/B,eAA+BA,WAA/B;;AAEA,MAAIG,OAAO,KAAKH,WAAhB,EAA6B;AAC3B,WAAOD,YAAP;AACD;;AACD,MAAMK,YAAY,GAAGV,OAAO,CAACW,OAAR,CAAgBF,OAAhB,CAArB;AACA,SAAOT,OAAO,CAACU,YAAY,GAAG,CAAhB,CAAd;AACD;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASE,kBAAT,CACLb,KADK,EAELU,OAFK,EAGQ;AACb,qBAA+CX,UAAU,CAACC,KAAD,CAAzD;AAAA,MAAQC,OAAR,gBAAQA,OAAR;AAAA,MAAiBK,YAAjB,gBAAiBA,YAAjB;AAAA,MAA+BC,WAA/B,gBAA+BA,WAA/B;;AAEA,MAAIG,OAAO,KAAKJ,YAAhB,EAA8B;AAC5B,WAAOC,WAAP;AACD;;AACD,MAAMI,YAAY,GAAGV,OAAO,CAACW,OAAR,CAAgBF,OAAhB,CAArB;AACA,SAAOT,OAAO,CAACU,YAAY,GAAG,CAAhB,CAAd;AACD","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"],"file":"dom-query.js"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import React, { HTMLAttributes } from "react";
|
|
2
|
+
export interface Props extends HTMLAttributes<HTMLElement> {
|
|
3
|
+
alignMenuLeft?: boolean;
|
|
4
|
+
buttonStyle?: React.CSSProperties;
|
|
5
|
+
label?: string;
|
|
6
|
+
listLabel?: string;
|
|
7
|
+
text?: JSX.Element | string;
|
|
8
|
+
nav?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Renders a dropdown menu. By default, only a passed "text" is rendered. If clicked,
|
|
12
|
+
* a floating div is rendered below the "text" with list contents inside. Clicking anywhere
|
|
13
|
+
* outside the floating div will close the dropdown.
|
|
14
|
+
*/
|
|
15
|
+
declare const Dropdown: ({ alignMenuLeft, children, className, id, label, listLabel, text, buttonStyle }: Props) => JSX.Element;
|
|
16
|
+
export default Dropdown;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dropdown/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,cAAc,EAMf,MAAM,OAAO,CAAC;AAKf,MAAM,WAAW,KAAM,SAAQ,cAAc,CAAC,WAAW,CAAC;IACxD,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;IAClC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IAC5B,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED;;;;GAIG;AACH,QAAA,MAAM,QAAQ,oFASX,KAAK,KAAG,WAqGV,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
|
|
10
|
+
var _domQuery = require("../utils/dom-query");
|
|
11
|
+
|
|
12
|
+
var _styled = require("./styled");
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Renders a dropdown menu. By default, only a passed "text" is rendered. If clicked,
|
|
20
|
+
* a floating div is rendered below the "text" with list contents inside. Clicking anywhere
|
|
21
|
+
* outside the floating div will close the dropdown.
|
|
22
|
+
*/
|
|
23
|
+
const Dropdown = ({
|
|
24
|
+
alignMenuLeft,
|
|
25
|
+
children,
|
|
26
|
+
className,
|
|
27
|
+
id,
|
|
28
|
+
label,
|
|
29
|
+
listLabel,
|
|
30
|
+
text,
|
|
31
|
+
buttonStyle
|
|
32
|
+
}) => {
|
|
33
|
+
const [open, setOpen] = (0, _react.useState)(false);
|
|
34
|
+
const containerRef = (0, _react.useRef)(null);
|
|
35
|
+
const toggleOpen = (0, _react.useCallback)(() => setOpen(!open), [open, setOpen]); // Argument for document.querySelectorAll to target focusable elements.
|
|
36
|
+
|
|
37
|
+
const queryId = `#${id} button, #${id}-label`;
|
|
38
|
+
const isList = Array.isArray(children) ? children.every(child => /*#__PURE__*/_react.default.isValidElement(child) && child.type === "li") : /*#__PURE__*/_react.default.isValidElement(children) && children.type === "li"; // Adding document event listeners allows us to close the dropdown
|
|
39
|
+
// when the user interacts with any part of the page that isn't the dropdown
|
|
40
|
+
|
|
41
|
+
(0, _react.useEffect)(() => {
|
|
42
|
+
const handleExternalAction = e => {
|
|
43
|
+
var _containerRef$current;
|
|
44
|
+
|
|
45
|
+
if (!(containerRef !== null && containerRef !== void 0 && (_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(e.target))) {
|
|
46
|
+
setOpen(false);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
document.addEventListener("mousedown", handleExternalAction);
|
|
51
|
+
document.addEventListener("focusin", handleExternalAction);
|
|
52
|
+
document.addEventListener("keydown", handleExternalAction);
|
|
53
|
+
return () => {
|
|
54
|
+
document.removeEventListener("mousedown", handleExternalAction);
|
|
55
|
+
document.removeEventListener("focusin", handleExternalAction);
|
|
56
|
+
document.removeEventListener("keydown", handleExternalAction);
|
|
57
|
+
};
|
|
58
|
+
}, [containerRef]);
|
|
59
|
+
const handleKeyDown = (0, _react.useCallback)(e => {
|
|
60
|
+
var _getPreviousSibling, _getNextSibling;
|
|
61
|
+
|
|
62
|
+
const element = e.target;
|
|
63
|
+
|
|
64
|
+
switch (e.key) {
|
|
65
|
+
case "ArrowUp":
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
(_getPreviousSibling = (0, _domQuery.getPreviousSibling)(queryId, element)) === null || _getPreviousSibling === void 0 ? void 0 : _getPreviousSibling.focus();
|
|
68
|
+
break;
|
|
69
|
+
|
|
70
|
+
case "ArrowDown":
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
(_getNextSibling = (0, _domQuery.getNextSibling)(queryId, element)) === null || _getNextSibling === void 0 ? void 0 : _getNextSibling.focus();
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case "Escape":
|
|
76
|
+
setOpen(false);
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case " ":
|
|
80
|
+
case "Enter":
|
|
81
|
+
e.preventDefault();
|
|
82
|
+
element.click();
|
|
83
|
+
|
|
84
|
+
if (element.id === `${id}-label` || element.id === `${id}-wrapper`) {
|
|
85
|
+
toggleOpen();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
break;
|
|
89
|
+
|
|
90
|
+
default:
|
|
91
|
+
}
|
|
92
|
+
}, [id, toggleOpen]);
|
|
93
|
+
return /*#__PURE__*/_react.default.createElement(_styled.DropdownWrapper, {
|
|
94
|
+
className: className,
|
|
95
|
+
id: `${id}-wrapper`,
|
|
96
|
+
onKeyDown: handleKeyDown,
|
|
97
|
+
ref: containerRef
|
|
98
|
+
}, /*#__PURE__*/_react.default.createElement(_styled.DropdownButton // Only set aria-controls when the dropdown is open
|
|
99
|
+
// (otherwise, assistive technologies may not announce the dropdown correctly).
|
|
100
|
+
, {
|
|
101
|
+
"aria-controls": open ? id : undefined,
|
|
102
|
+
"aria-expanded": open,
|
|
103
|
+
"aria-haspopup": "listbox",
|
|
104
|
+
"aria-label": label,
|
|
105
|
+
id: `${id}-label`,
|
|
106
|
+
onClick: toggleOpen,
|
|
107
|
+
style: buttonStyle,
|
|
108
|
+
title: label
|
|
109
|
+
}, /*#__PURE__*/_react.default.createElement("span", null, text), /*#__PURE__*/_react.default.createElement("span", {
|
|
110
|
+
className: "caret",
|
|
111
|
+
role: "presentation"
|
|
112
|
+
})), open && /*#__PURE__*/_react.default.createElement(_styled.DropdownMenu, {
|
|
113
|
+
as: isList && "ul",
|
|
114
|
+
"aria-label": listLabel,
|
|
115
|
+
"aria-labelledby": listLabel ? undefined : `${id}-label`,
|
|
116
|
+
id: id,
|
|
117
|
+
onClick: toggleOpen,
|
|
118
|
+
alignLeft: alignMenuLeft,
|
|
119
|
+
role: isList && "list",
|
|
120
|
+
tabIndex: -1
|
|
121
|
+
}, children));
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
var _default = Dropdown;
|
|
125
|
+
exports.default = _default;
|
|
126
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/dropdown/index.tsx"],"names":["Dropdown","alignMenuLeft","children","className","id","label","listLabel","text","buttonStyle","open","setOpen","containerRef","toggleOpen","queryId","isList","Array","isArray","every","child","isValidElement","type","handleExternalAction","e","current","contains","target","document","addEventListener","removeEventListener","handleKeyDown","element","key","preventDefault","focus","click","undefined"],"mappings":";;;;;;;AAAA;;AASA;;AACA;;;;;;AAWA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAQ,GAAG,CAAC;AAChBC,EAAAA,aADgB;AAEhBC,EAAAA,QAFgB;AAGhBC,EAAAA,SAHgB;AAIhBC,EAAAA,EAJgB;AAKhBC,EAAAA,KALgB;AAMhBC,EAAAA,SANgB;AAOhBC,EAAAA,IAPgB;AAQhBC,EAAAA;AARgB,CAAD,KASS;AACxB,QAAM,CAACC,IAAD,EAAOC,OAAP,IAAkB,qBAAS,KAAT,CAAxB;AAEA,QAAMC,YAAY,GAAG,mBAAwB,IAAxB,CAArB;AAEA,QAAMC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ANF,EAqBGE,IAAI,iBACH,6BAAC,oBAAD;AACE,IAAA,EAAE,EAAEK,MAAM,IAAI,IADhB;AAEE,kBAAYR,SAFd;AAGE,uBAAiBA,SAAS,GAAG6B,SAAH,GAAgB,GAAE/B,EAAG,QAHjD;AAIE,IAAA,EAAE,EAAEA,EAJN;AAKE,IAAA,OAAO,EAAEQ,UALX;AAME,IAAA,SAAS,EAAEX,aANb;AAOE,IAAA,IAAI,EAAEa,MAAM,IAAI,MAPlB;AAQE,IAAA,QAAQ,EAAE,CAAC;AARb,KAUGZ,QAVH,CAtBJ,CADF;AAsCD,CA9GD;;eAgHeF,Q","sourcesContent":["import React, {\n HTMLAttributes,\n KeyboardEvent,\n useCallback,\n useEffect,\n useRef,\n useState\n} from \"react\";\n\nimport { getNextSibling, getPreviousSibling } from \"../utils/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"],"file":"index.js"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const DropdownButton: import("styled-components").StyledComponent<"button", any, {}, never>;
|
|
2
|
+
export declare const DropdownMenu: import("styled-components").StyledComponent<"div", any, {
|
|
3
|
+
alignLeft?: boolean;
|
|
4
|
+
}, never>;
|
|
5
|
+
export declare const DropdownWrapper: import("styled-components").StyledComponent<"span", any, {
|
|
6
|
+
pullRight?: boolean;
|
|
7
|
+
}, never>;
|
|
8
|
+
//# sourceMappingURL=styled.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styled.d.ts","sourceRoot":"","sources":["../../src/dropdown/styled.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,uEA0B1B,CAAC;AAEF,eAAO,MAAM,YAAY;gBAA4B,OAAO;SAkC3D,CAAC;AAEF,eAAO,MAAM,eAAe;gBAA6B,OAAO;SAG/D,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.DropdownWrapper = exports.DropdownMenu = exports.DropdownButton = void 0;
|
|
9
|
+
|
|
10
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
11
|
+
|
|
12
|
+
var _grey = _interopRequireDefault(require("../colors/grey"));
|
|
13
|
+
|
|
14
|
+
const DropdownButton = _styledComponents.default.button.withConfig({
|
|
15
|
+
displayName: "styled__DropdownButton",
|
|
16
|
+
componentId: "sc-kes9ha-0"
|
|
17
|
+
})(["background:#fff;border:1px solid black;border-radius:5px;color:inherit;padding:5px 7px;transition:all 0.1s ease-in-out;span.caret{border-left:4px solid transparent;border-right:4px solid transparent;border-top:4px solid;color:inherit;display:inline-block;height:0;margin-left:5px;vertical-align:middle;width:0;}&:hover,&[aria-expanded=\"true\"]{background:", ";color:black;cursor:pointer;}"], _grey.default[50]);
|
|
18
|
+
|
|
19
|
+
exports.DropdownButton = DropdownButton;
|
|
20
|
+
|
|
21
|
+
const DropdownMenu = _styledComponents.default.div.withConfig({
|
|
22
|
+
displayName: "styled__DropdownMenu",
|
|
23
|
+
componentId: "sc-kes9ha-1"
|
|
24
|
+
})(["background-clip:padding-box;background-color:#fff;border-radius:4px;border:1px solid rgba(0,0,0,0.15);box-shadow:0 6px 12px rgba(0,0,0,0.175);color:#333;list-style:none;margin:2px 0 0;min-width:160px;padding:5px 0;position:absolute;", " top:100%;width:100%;z-index:1000;hr{margin:0;padding:0;}a,button{background:transparent;border:none;cursor:pointer;padding:5px 15px;text-align:start;width:100%;&:hover{background:", ";}}"], props => props.alignLeft ? "left: 0;" : "right: 0;", _grey.default[50]);
|
|
25
|
+
|
|
26
|
+
exports.DropdownMenu = DropdownMenu;
|
|
27
|
+
|
|
28
|
+
const DropdownWrapper = _styledComponents.default.span.withConfig({
|
|
29
|
+
displayName: "styled__DropdownWrapper",
|
|
30
|
+
componentId: "sc-kes9ha-2"
|
|
31
|
+
})(["float:", ";position:relative;"], props => props.pullRight ? "right" : "left");
|
|
32
|
+
|
|
33
|
+
exports.DropdownWrapper = DropdownWrapper;
|
|
34
|
+
//# sourceMappingURL=styled.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/dropdown/styled.tsx"],"names":["DropdownButton","styled","button","grey","DropdownMenu","div","props","alignLeft","DropdownWrapper","span","pullRight"],"mappings":";;;;;;;;;AAAA;;AACA;;AAEO,MAAMA,cAAc,GAAGC,0BAAOC,MAAV;AAAA;AAAA;AAAA,8YAsBTC,cAAK,EAAL,CAtBS,CAApB;;;;AA4BA,MAAMC,YAAY,GAAGH,0BAAOI,GAAV;AAAA;AAAA;AAAA,gbAYrBC,KAAK,IAAKA,KAAK,CAACC,SAAN,GAAkB,UAAlB,GAA+B,WAZpB,EA+BLJ,cAAK,EAAL,CA/BK,CAAlB;;;;AAoCA,MAAMK,eAAe,GAAGP,0BAAOQ,IAAV;AAAA;AAAA;AAAA,sCACjBH,KAAK,IAAKA,KAAK,CAACI,SAAN,GAAkB,OAAlB,GAA4B,MADrB,CAArB","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"],"file":"styled.js"}
|
package/lib/index.d.ts
CHANGED
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAElC,OAAO,EAAE,QAAQ,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACpB,wBAAmC"}
|
package/lib/index.js
CHANGED
|
@@ -5,6 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
Object.defineProperty(exports, "Dropdown", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function () {
|
|
11
|
+
return _dropdown.default;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
exports.default = void 0;
|
|
9
15
|
|
|
10
16
|
var _blue = _interopRequireDefault(require("./colors/blue"));
|
|
@@ -13,6 +19,8 @@ var _red = _interopRequireDefault(require("./colors/red"));
|
|
|
13
19
|
|
|
14
20
|
var _grey = _interopRequireDefault(require("./colors/grey"));
|
|
15
21
|
|
|
22
|
+
var _dropdown = _interopRequireDefault(require("./dropdown"));
|
|
23
|
+
|
|
16
24
|
var _default = {
|
|
17
25
|
blue: _blue.default,
|
|
18
26
|
red: _red.default,
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["blue","red","grey"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["blue","red","grey"],"mappings":";;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;eAGe;AAAEA,EAAAA,IAAI,EAAJA,aAAF;AAAQC,EAAAA,GAAG,EAAHA,YAAR;AAAaC,EAAAA,IAAI,EAAJA;AAAb,C","sourcesContent":["import blue from \"./colors/blue\";\nimport red from \"./colors/red\";\nimport grey from \"./colors/grey\";\nimport Dropdown from \"./dropdown\";\n\nexport { Dropdown };\nexport default { blue, red, grey };\n"],"file":"index.js"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ComponentMeta } from "@storybook/react";
|
|
3
|
+
declare const _default: ComponentMeta<({ alignMenuLeft, children, className, id, label, listLabel, text, buttonStyle }: import("../dropdown").Props) => JSX.Element>;
|
|
4
|
+
export default _default;
|
|
5
|
+
export declare const DropdownWithLabel: () => React.ReactElement;
|
|
6
|
+
export declare const DropdownWithList: () => React.ReactElement;
|
|
7
|
+
export declare const DropdownWithListAlignMenuLeft: () => React.ReactElement;
|
|
8
|
+
export declare const DropdownAsOtprrNavItem: () => React.ReactElement;
|
|
9
|
+
//# sourceMappingURL=dropdown.story.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropdown.story.d.ts","sourceRoot":"","sources":["../../src/stories/dropdown.story.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;;AAwCjD,wBAGoC;AAEpC,eAAO,MAAM,iBAAiB,QAAO,MAAM,YAS1C,CAAC;AAEF,eAAO,MAAM,gBAAgB,QAAO,MAAM,YAazC,CAAC;AAEF,eAAO,MAAM,6BAA6B,QAAO,MAAM,YActD,CAAC;AAEF,eAAO,MAAM,sBAAsB,QAAO,MAAM,YAgB/C,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DropdownAsOtprrNavItem = exports.DropdownWithListAlignMenuLeft = exports.DropdownWithList = exports.DropdownWithLabel = void 0;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
9
|
+
const dropdown_1 = __importDefault(require("../dropdown"));
|
|
10
|
+
const blue_1 = __importDefault(require("../colors/blue"));
|
|
11
|
+
const options = [
|
|
12
|
+
{ value: "1", label: "One" },
|
|
13
|
+
{ value: "2", label: "Two" },
|
|
14
|
+
{ value: "3", label: "Three" }
|
|
15
|
+
];
|
|
16
|
+
const NavItemWrapper = styled_components_1.default.div `
|
|
17
|
+
align-items: center;
|
|
18
|
+
background: ${blue_1.default[900]};
|
|
19
|
+
display: flex;
|
|
20
|
+
min-height: 50px;
|
|
21
|
+
padding: 0 10px;
|
|
22
|
+
position: relative;
|
|
23
|
+
width: 100%;
|
|
24
|
+
|
|
25
|
+
.navBarItem {
|
|
26
|
+
position: static;
|
|
27
|
+
& > button {
|
|
28
|
+
background: transparent;
|
|
29
|
+
border: none;
|
|
30
|
+
color: white;
|
|
31
|
+
padding: 15px;
|
|
32
|
+
|
|
33
|
+
@media (max-width: 768px) {
|
|
34
|
+
padding: 10px;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
&:hover {
|
|
38
|
+
background: rgba(0, 0, 0, 0.05);
|
|
39
|
+
color: #ececec;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
`;
|
|
44
|
+
exports.default = {
|
|
45
|
+
title: "Building-Blocks/Dropdown",
|
|
46
|
+
component: dropdown_1.default
|
|
47
|
+
};
|
|
48
|
+
const DropdownWithLabel = () => (react_1.default.createElement(dropdown_1.default, { id: "dropdown-with-label", label: "Dropdown with label", listLabel: "Dropdown menu", text: "Dropdown with label" }, "More content here"));
|
|
49
|
+
exports.DropdownWithLabel = DropdownWithLabel;
|
|
50
|
+
const DropdownWithList = () => (react_1.default.createElement(dropdown_1.default, { id: "dropdown-with-ul", label: "Dropdown with ul", listLabel: "Dropdown menu", text: "Dropdown with ul" }, options.map(option => (react_1.default.createElement("li", { key: option.value, value: option.value },
|
|
51
|
+
react_1.default.createElement("button", { type: "button" }, option.label))))));
|
|
52
|
+
exports.DropdownWithList = DropdownWithList;
|
|
53
|
+
const DropdownWithListAlignMenuLeft = () => (react_1.default.createElement(dropdown_1.default, { alignMenuLeft: true, id: "dropdown-with-ul", label: "Dropdown with ul", listLabel: "Dropdown menu", text: "Dropdown with ul" }, options.map(option => (react_1.default.createElement("li", { key: option.value, value: option.value },
|
|
54
|
+
react_1.default.createElement("button", { type: "button" }, option.label))))));
|
|
55
|
+
exports.DropdownWithListAlignMenuLeft = DropdownWithListAlignMenuLeft;
|
|
56
|
+
const DropdownAsOtprrNavItem = () => (react_1.default.createElement(NavItemWrapper, null,
|
|
57
|
+
react_1.default.createElement(dropdown_1.default, { className: "navBarItem", id: "dropdown-navbar", label: "Dropdown navbar", listLabel: "Dropdown within navbar", text: "Icon" }, options.map(option => (react_1.default.createElement("button", { key: option.value, type: "button" }, option.label))))));
|
|
58
|
+
exports.DropdownAsOtprrNavItem = DropdownAsOtprrNavItem;
|
|
59
|
+
//# sourceMappingURL=dropdown.story.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropdown.story.js","sourceRoot":"","sources":["../../src/stories/dropdown.story.tsx"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAE1B,0EAAuC;AACvC,2DAAmC;AACnC,0DAAkC;AAElC,MAAM,OAAO,GAAG;IACd,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE;IAC5B,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE;IAC5B,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE;CAC/B,CAAC;AAEF,MAAM,cAAc,GAAG,2BAAM,CAAC,GAAG,CAAA;;gBAEjB,cAAI,CAAC,GAAG,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;CAyBxB,CAAC;AAEF,kBAAe;IACb,KAAK,EAAE,0BAA0B;IACjC,SAAS,EAAE,kBAAQ;CACc,CAAC;AAE7B,MAAM,iBAAiB,GAAG,GAAuB,EAAE,CAAC,CACzD,8BAAC,kBAAQ,IACP,EAAE,EAAC,qBAAqB,EACxB,KAAK,EAAC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,CAAC,EAAE,CAAC,CACrB,0CAAQ,GAAG,EAAE,MAAM,CAAC,KAAK,EAAE,IAAI,EAAC,QAAQ,IACrC,MAAM,CAAC,KAAK,CACN,CACV,CAAC,CACO,CACI,CAClB,CAAC;AAhBW,QAAA,sBAAsB,0BAgBjC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Helper method to find the next focusable sibling element relative to the
|
|
3
|
+
* specified element.
|
|
4
|
+
*
|
|
5
|
+
* @param {string} query - Argument that gets passed to document.querySelectorAll
|
|
6
|
+
* @param {HTMLElement} element - Specified element (e.target)
|
|
7
|
+
* @returns {HTMLElement} - element to be focused
|
|
8
|
+
*/
|
|
9
|
+
export declare function getNextSibling(query: string, element: EventTarget): HTMLElement;
|
|
10
|
+
/**
|
|
11
|
+
* Helper method to find the previous focusable sibling element relative to the
|
|
12
|
+
* specified element.
|
|
13
|
+
*
|
|
14
|
+
* @param {string} query - Argument that gets passed to document.querySelectorAll
|
|
15
|
+
* @param {HTMLElement} element - Specified element (e.target)
|
|
16
|
+
* @returns {HTMLElement} - element to be focused
|
|
17
|
+
*/
|
|
18
|
+
export declare function getPreviousSibling(query: string, element: EventTarget): HTMLElement;
|
|
19
|
+
//# sourceMappingURL=dom-query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom-query.d.ts","sourceRoot":"","sources":["../../src/utils/dom-query.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,GACnB,WAAW,CAQb;AAED;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,WAAW,GACnB,WAAW,CAQb"}
|