@opentripplanner/building-blocks 3.0.1-alpha.1 → 3.0.2-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.
@@ -1,111 +1,97 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
5
17
  });
6
- exports.default = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _domQuery = require("../focus-trap-wrapper/dom-query");
9
- var _styled = require("./styled");
10
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
11
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const react_1 = __importStar(require("react"));
27
+ const dom_query_1 = require("../focus-trap-wrapper/dom-query");
28
+ const styled_1 = require("./styled");
12
29
  /**
13
30
  * Renders a dropdown menu. By default, only a passed "text" is rendered. If clicked,
14
31
  * a floating div is rendered below the "text" with list contents inside. Clicking anywhere
15
32
  * outside the floating div will close the dropdown.
16
33
  */
17
- const Dropdown = ({
18
- alignMenuLeft,
19
- children,
20
- className,
21
- id,
22
- label,
23
- listLabel,
24
- text,
25
- buttonStyle
26
- }) => {
27
- const [open, setOpen] = (0, _react.useState)(false);
28
- const containerRef = (0, _react.useRef)(null);
29
- const toggleOpen = (0, _react.useCallback)(() => setOpen(!open), [open, setOpen]);
30
-
31
- // Argument for document.querySelectorAll to target focusable elements.
32
- const queryId = `#${id} button, #${id}-label`;
33
- const isList = Array.isArray(children) ? children.every(child => /*#__PURE__*/_react.default.isValidElement(child) && child.type === "li") : /*#__PURE__*/_react.default.isValidElement(children) && children.type === "li";
34
-
35
- // Adding document event listeners allows us to close the dropdown
36
- // when the user interacts with any part of the page that isn't the dropdown
37
- (0, _react.useEffect)(() => {
38
- const handleExternalAction = e => {
39
- var _containerRef$current;
40
- if (!(containerRef !== null && containerRef !== void 0 && (_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(e.target))) {
41
- setOpen(false);
42
- }
43
- };
44
- document.addEventListener("mousedown", handleExternalAction);
45
- document.addEventListener("focusin", handleExternalAction);
46
- document.addEventListener("keydown", handleExternalAction);
47
- return () => {
48
- document.removeEventListener("mousedown", handleExternalAction);
49
- document.removeEventListener("focusin", handleExternalAction);
50
- document.removeEventListener("keydown", handleExternalAction);
51
- };
52
- }, [containerRef]);
53
- const handleKeyDown = (0, _react.useCallback)(e => {
54
- var _getPreviousSibling, _getNextSibling;
55
- const element = e.target;
56
- switch (e.key) {
57
- case "ArrowUp":
58
- e.preventDefault();
59
- (_getPreviousSibling = (0, _domQuery.getPreviousSibling)(queryId, element)) === null || _getPreviousSibling === void 0 || _getPreviousSibling.focus();
60
- break;
61
- case "ArrowDown":
62
- e.preventDefault();
63
- (_getNextSibling = (0, _domQuery.getNextSibling)(queryId, element)) === null || _getNextSibling === void 0 || _getNextSibling.focus();
64
- break;
65
- case "Escape":
66
- setOpen(false);
67
- break;
68
- case " ":
69
- case "Enter":
70
- e.preventDefault();
71
- element.click();
72
- if (element.id === `${id}-label` || element.id === `${id}-wrapper`) {
73
- toggleOpen();
34
+ const Dropdown = ({ alignMenuLeft, children, className, id, label, listLabel, text, buttonStyle }) => {
35
+ const [open, setOpen] = (0, react_1.useState)(false);
36
+ const containerRef = (0, react_1.useRef)(null);
37
+ const toggleOpen = (0, react_1.useCallback)(() => setOpen(!open), [open, setOpen]);
38
+ // Argument for document.querySelectorAll to target focusable elements.
39
+ const queryId = `#${id} button, #${id}-label`;
40
+ const isList = Array.isArray(children)
41
+ ? children.every(child => react_1.default.isValidElement(child) && child.type === "li")
42
+ : react_1.default.isValidElement(children) && children.type === "li";
43
+ // Adding document event listeners allows us to close the dropdown
44
+ // when the user interacts with any part of the page that isn't the dropdown
45
+ (0, react_1.useEffect)(() => {
46
+ const handleExternalAction = (e) => {
47
+ var _a;
48
+ if (!((_a = containerRef === null || containerRef === void 0 ? void 0 : containerRef.current) === null || _a === void 0 ? void 0 : _a.contains(e.target))) {
49
+ setOpen(false);
50
+ }
51
+ };
52
+ document.addEventListener("mousedown", handleExternalAction);
53
+ document.addEventListener("focusin", handleExternalAction);
54
+ document.addEventListener("keydown", handleExternalAction);
55
+ return () => {
56
+ document.removeEventListener("mousedown", handleExternalAction);
57
+ document.removeEventListener("focusin", handleExternalAction);
58
+ document.removeEventListener("keydown", handleExternalAction);
59
+ };
60
+ }, [containerRef]);
61
+ const handleKeyDown = (0, react_1.useCallback)((e) => {
62
+ var _a, _b;
63
+ const element = e.target;
64
+ switch (e.key) {
65
+ case "ArrowUp":
66
+ e.preventDefault();
67
+ (_a = (0, dom_query_1.getPreviousSibling)(queryId, element)) === null || _a === void 0 ? void 0 : _a.focus();
68
+ break;
69
+ case "ArrowDown":
70
+ e.preventDefault();
71
+ (_b = (0, dom_query_1.getNextSibling)(queryId, element)) === null || _b === void 0 ? void 0 : _b.focus();
72
+ break;
73
+ case "Escape":
74
+ setOpen(false);
75
+ break;
76
+ case " ":
77
+ case "Enter":
78
+ e.preventDefault();
79
+ element.click();
80
+ if (element.id === `${id}-label` || element.id === `${id}-wrapper`) {
81
+ toggleOpen();
82
+ }
83
+ break;
84
+ default:
74
85
  }
75
- break;
76
- default:
77
- }
78
- }, [id, toggleOpen]);
79
- return /*#__PURE__*/_react.default.createElement(_styled.DropdownWrapper, {
80
- className: className,
81
- id: `${id}-wrapper`,
82
- onKeyDown: handleKeyDown,
83
- ref: containerRef
84
- }, /*#__PURE__*/_react.default.createElement(_styled.DropdownButton
85
- // Only set aria-controls when the dropdown is open
86
- // (otherwise, assistive technologies may not announce the dropdown correctly).
87
- , {
88
- "aria-controls": open ? id : undefined,
89
- "aria-expanded": open,
90
- "aria-haspopup": "listbox",
91
- "aria-label": label,
92
- id: `${id}-label`,
93
- onClick: toggleOpen,
94
- style: buttonStyle,
95
- title: label
96
- }, /*#__PURE__*/_react.default.createElement("span", null, text), /*#__PURE__*/_react.default.createElement("span", {
97
- className: "caret",
98
- role: "presentation"
99
- })), open && /*#__PURE__*/_react.default.createElement(_styled.DropdownMenu, {
100
- as: isList && "ul",
101
- "aria-label": listLabel,
102
- "aria-labelledby": listLabel ? undefined : `${id}-label`,
103
- id: id,
104
- onClick: toggleOpen,
105
- alignLeft: alignMenuLeft,
106
- role: isList && "list",
107
- tabIndex: -1
108
- }, children));
86
+ }, [id, toggleOpen]);
87
+ return (react_1.default.createElement(styled_1.DropdownWrapper, { className: className, id: `${id}-wrapper`, onKeyDown: handleKeyDown, ref: containerRef },
88
+ react_1.default.createElement(styled_1.DropdownButton
89
+ // Only set aria-controls when the dropdown is open
90
+ // (otherwise, assistive technologies may not announce the dropdown correctly).
91
+ , { "aria-controls": open ? id : undefined, "aria-expanded": open, "aria-haspopup": "listbox", "aria-label": label, id: `${id}-label`, onClick: toggleOpen, style: buttonStyle, title: label, type: "button" },
92
+ react_1.default.createElement("span", null, text),
93
+ react_1.default.createElement("span", { className: "caret", role: "presentation" })),
94
+ open && (react_1.default.createElement(styled_1.DropdownMenu, { as: isList && "ul", "aria-label": listLabel, "aria-labelledby": listLabel ? undefined : `${id}-label`, id: id, onClick: toggleOpen, alignLeft: alignMenuLeft, role: isList && "listbox", tabIndex: -1 }, children))));
109
95
  };
110
- var _default = exports.default = Dropdown;
96
+ exports.default = Dropdown;
111
97
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_react","_interopRequireWildcard","require","_domQuery","_styled","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","Dropdown","alignMenuLeft","children","className","id","label","listLabel","text","buttonStyle","open","setOpen","useState","containerRef","useRef","toggleOpen","useCallback","queryId","isList","Array","isArray","every","child","React","isValidElement","type","useEffect","handleExternalAction","_containerRef$current","current","contains","target","document","addEventListener","removeEventListener","handleKeyDown","_getPreviousSibling","_getNextSibling","element","key","preventDefault","getPreviousSibling","focus","getNextSibling","click","createElement","DropdownWrapper","onKeyDown","ref","DropdownButton","undefined","onClick","style","title","role","DropdownMenu","as","alignLeft","tabIndex","_default","exports"],"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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AASA,IAAAC,SAAA,GAAAD,OAAA;AAIA,IAAAE,OAAA,GAAAF,OAAA;AAAyE,SAAAG,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAL,wBAAAK,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAI,UAAA,SAAAJ,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAK,OAAA,EAAAL,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAG,GAAA,CAAAN,CAAA,UAAAG,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AAO,EAAC,IAAI,EAAC,cAAc,GAAG,CAC/B;QAChB,IAAI,IAAI,CACP,8BAAC,qBAAY,IACX,EAAE,EAAE,MAAM,IAAI,IAAI,gBACN,SAAS,qBACJ,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,EAAE,QAAQ,EACtD,EAAE,EAAE,EAAE,EACN,OAAO,EAAE,UAAU,EACnB,SAAS,EAAE,aAAa,EACxB,IAAI,EAAE,MAAM,IAAI,SAAS,EACzB,QAAQ,EAAE,CAAC,CAAC,IAEX,QAAQ,CACI,CAChB,CACe,CACnB,CAAC;AACJ,CAAC,CAAC;AAEF,kBAAe,QAAQ,CAAC"}
@@ -1,22 +1,75 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
7
6
  exports.DropdownWrapper = exports.DropdownMenu = exports.DropdownButton = void 0;
8
- var _styledComponents = _interopRequireDefault(require("styled-components"));
9
- var _grey = _interopRequireDefault(require("../colors/grey"));
10
- const DropdownButton = exports.DropdownButton = _styledComponents.default.button.withConfig({
11
- displayName: "styled__DropdownButton",
12
- componentId: "sc-kes9ha-0"
13
- })(["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]);
14
- const DropdownMenu = exports.DropdownMenu = _styledComponents.default.div.withConfig({
15
- displayName: "styled__DropdownMenu",
16
- componentId: "sc-kes9ha-1"
17
- })(["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]);
18
- const DropdownWrapper = exports.DropdownWrapper = _styledComponents.default.span.withConfig({
19
- displayName: "styled__DropdownWrapper",
20
- componentId: "sc-kes9ha-2"
21
- })(["float:", ";position:relative;"], props => props.pullRight ? "right" : "left");
7
+ const styled_components_1 = __importDefault(require("styled-components"));
8
+ const grey_1 = __importDefault(require("../colors/grey"));
9
+ exports.DropdownButton = styled_components_1.default.button `
10
+ background: #fff;
11
+ border: 1px solid black;
12
+ border-radius: 5px;
13
+ color: inherit;
14
+ padding: 5px 7px;
15
+ transition: all 0.1s ease-in-out;
16
+
17
+ span.caret {
18
+ border-left: 4px solid transparent;
19
+ border-right: 4px solid transparent;
20
+ border-top: 4px solid;
21
+ color: inherit;
22
+ display: inline-block;
23
+ height: 0;
24
+ margin-left: 5px;
25
+ vertical-align: middle;
26
+ width: 0;
27
+ }
28
+
29
+ &:hover,
30
+ &[aria-expanded="true"] {
31
+ background: ${grey_1.default[50]};
32
+ color: black;
33
+ cursor: pointer;
34
+ }
35
+ `;
36
+ exports.DropdownMenu = styled_components_1.default.div `
37
+ background-clip: padding-box;
38
+ background-color: #fff;
39
+ border-radius: 4px;
40
+ border: 1px solid rgba(0, 0, 0, 0.15);
41
+ box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
42
+ color: #333;
43
+ list-style: none;
44
+ margin: 2px 0 0;
45
+ min-width: 160px;
46
+ padding: 5px 0;
47
+ position: absolute;
48
+ ${props => (props.alignLeft ? "left: 0;" : "right: 0;")}
49
+ top: 100%;
50
+ width: 100%;
51
+ z-index: 1000;
52
+
53
+ hr {
54
+ margin: 0;
55
+ padding: 0;
56
+ }
57
+ a,
58
+ button {
59
+ background: transparent;
60
+ border: none;
61
+ cursor: pointer;
62
+ padding: 5px 15px;
63
+ text-align: start;
64
+ width: 100%;
65
+
66
+ &:hover {
67
+ background: ${grey_1.default[50]};
68
+ }
69
+ }
70
+ `;
71
+ exports.DropdownWrapper = styled_components_1.default.span `
72
+ float: ${props => (props.pullRight ? "right" : "left")};
73
+ position: relative;
74
+ `;
22
75
  //# sourceMappingURL=styled.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"styled.js","names":["_styledComponents","_interopRequireDefault","require","_grey","DropdownButton","exports","styled","button","withConfig","displayName","componentId","grey","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,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,KAAA,GAAAF,sBAAA,CAAAC,OAAA;AAEO,MAAME,cAAc,GAAAC,OAAA,CAAAD,cAAA,GAAGE,yBAAM,CAACC,MAAM,CAAAC,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,8YAsBzBC,aAAI,CAAC,EAAE,CAAC,CAIzB;AAEM,MAAMC,YAAY,GAAAP,OAAA,CAAAO,YAAA,GAAGN,yBAAM,CAACO,GAAG,CAAAL,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,gbAYlCI,KAAK,IAAKA,KAAK,CAACC,SAAS,GAAG,UAAU,GAAG,WAAY,EAmBrCJ,aAAI,CAAC,EAAE,CAAC,CAG3B;AAEM,MAAMK,eAAe,GAAAX,OAAA,CAAAW,eAAA,GAAGV,yBAAM,CAACW,IAAI,CAAAT,UAAA;EAAAC,WAAA;EAAAC,WAAA;AAAA,sCAC/BI,KAAK,IAAKA,KAAK,CAACI,SAAS,GAAG,OAAO,GAAG,MAAO,CAEvD","ignoreList":[]}
1
+ {"version":3,"file":"styled.js","sourceRoot":"","sources":["../../src/dropdown/styled.tsx"],"names":[],"mappings":";;;;;;AAAA,0EAAuC;AACvC,0DAAkC;AAErB,QAAA,cAAc,GAAG,2BAAM,CAAC,MAAM,CAAA;;;;;;;;;;;;;;;;;;;;;;kBAsBzB,cAAI,CAAC,EAAE,CAAC;;;;CAIzB,CAAC;AAEW,QAAA,YAAY,GAAG,2BAAM,CAAC,GAAG,CAAyB;;;;;;;;;;;;IAY3D,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,WAAW,CAAC;;;;;;;;;;;;;;;;;;;oBAmBrC,cAAI,CAAC,EAAE,CAAC;;;CAG3B,CAAC;AAEW,QAAA,eAAe,GAAG,2BAAM,CAAC,IAAI,CAAyB;WACxD,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;;CAEvD,CAAC"}
@@ -1,21 +1,12 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getNextSibling = getNextSibling;
7
- exports.getPreviousSibling = getPreviousSibling;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPreviousSibling = exports.getNextSibling = void 0;
8
4
  function getEntries(query) {
9
- const entries = Array.from(document.querySelectorAll(query));
10
- const firstElement = entries[0];
11
- const lastElement = entries[entries.length - 1];
12
- return {
13
- entries,
14
- firstElement,
15
- lastElement
16
- };
5
+ const entries = Array.from(document.querySelectorAll(query));
6
+ const firstElement = entries[0];
7
+ const lastElement = entries[entries.length - 1];
8
+ return { entries, firstElement, lastElement };
17
9
  }
18
-
19
10
  /**
20
11
  * Helper method to find the next focusable sibling element relative to the
21
12
  * specified element.
@@ -25,18 +16,14 @@ function getEntries(query) {
25
16
  * @returns {HTMLElement} - element to be focused
26
17
  */
27
18
  function getNextSibling(query, element) {
28
- const {
29
- entries,
30
- firstElement,
31
- lastElement
32
- } = getEntries(query);
33
- if (element === lastElement) {
34
- return firstElement;
35
- }
36
- const elementIndex = entries.indexOf(element);
37
- return entries[elementIndex + 1];
19
+ const { entries, firstElement, lastElement } = getEntries(query);
20
+ if (element === lastElement) {
21
+ return firstElement;
22
+ }
23
+ const elementIndex = entries.indexOf(element);
24
+ return entries[elementIndex + 1];
38
25
  }
39
-
26
+ exports.getNextSibling = getNextSibling;
40
27
  /**
41
28
  * Helper method to find the previous focusable sibling element relative to the
42
29
  * specified element.
@@ -46,15 +33,12 @@ function getNextSibling(query, element) {
46
33
  * @returns {HTMLElement} - element to be focused
47
34
  */
48
35
  function getPreviousSibling(query, element) {
49
- const {
50
- entries,
51
- firstElement,
52
- lastElement
53
- } = getEntries(query);
54
- if (element === firstElement) {
55
- return lastElement;
56
- }
57
- const elementIndex = entries.indexOf(element);
58
- return entries[elementIndex - 1];
36
+ const { entries, firstElement, lastElement } = getEntries(query);
37
+ if (element === firstElement) {
38
+ return lastElement;
39
+ }
40
+ const elementIndex = entries.indexOf(element);
41
+ return entries[elementIndex - 1];
59
42
  }
43
+ exports.getPreviousSibling = getPreviousSibling;
60
44
  //# sourceMappingURL=dom-query.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dom-query.js","names":["getEntries","query","entries","Array","from","document","querySelectorAll","firstElement","lastElement","length","getNextSibling","element","elementIndex","indexOf","getPreviousSibling"],"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,MAAMC,OAAO,GAAGC,KAAK,CAACC,IAAI,CAACC,QAAQ,CAACC,gBAAgB,CAACL,KAAK,CAAC,CAAC;EAC5D,MAAMM,YAAY,GAAGL,OAAO,CAAC,CAAC,CAAC;EAC/B,MAAMM,WAAW,GAAGN,OAAO,CAACA,OAAO,CAACO,MAAM,GAAG,CAAC,CAAC;EAE/C,OAAO;IAAEP,OAAO;IAAEK,YAAY;IAAEC;EAAY,CAAC;AAC/C;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,cAAcA,CAC5BT,KAAa,EACbU,OAAoB,EACP;EACb,MAAM;IAAET,OAAO;IAAEK,YAAY;IAAEC;EAAY,CAAC,GAAGR,UAAU,CAACC,KAAK,CAAC;EAEhE,IAAIU,OAAO,KAAKH,WAAW,EAAE;IAC3B,OAAOD,YAAY;EACrB;EACA,MAAMK,YAAY,GAAGV,OAAO,CAACW,OAAO,CAACF,OAAsB,CAAC;EAC5D,OAAOT,OAAO,CAACU,YAAY,GAAG,CAAC,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASE,kBAAkBA,CAChCb,KAAa,EACbU,OAAoB,EACP;EACb,MAAM;IAAET,OAAO;IAAEK,YAAY;IAAEC;EAAY,CAAC,GAAGR,UAAU,CAACC,KAAK,CAAC;EAEhE,IAAIU,OAAO,KAAKJ,YAAY,EAAE;IAC5B,OAAOC,WAAW;EACpB;EACA,MAAMI,YAAY,GAAGV,OAAO,CAACW,OAAO,CAACF,OAA4B,CAAC;EAClE,OAAOT,OAAO,CAACU,YAAY,GAAG,CAAC,CAAC;AAClC","ignoreList":[]}
1
+ {"version":3,"file":"dom-query.js","sourceRoot":"","sources":["../../src/focus-trap-wrapper/dom-query.ts"],"names":[],"mappings":";;;AAAA,SAAS,UAAU,CAAC,KAAa;IAC/B,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7D,MAAM,YAAY,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IAChC,MAAM,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAEhD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC;AAChD,CAAC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,KAAa,EACb,OAAoB;IAEpB,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAEjE,IAAI,OAAO,KAAK,WAAW,EAAE;QAC3B,OAAO,YAA2B,CAAC;KACpC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,OAAsB,CAAC,CAAC;IAC7D,OAAO,OAAO,CAAC,YAAY,GAAG,CAAC,CAAgB,CAAC;AAClD,CAAC;AAXD,wCAWC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAChC,KAAa,EACb,OAAoB;IAEpB,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IAEjE,IAAI,OAAO,KAAK,YAAY,EAAE;QAC5B,OAAO,WAA0B,CAAC;KACnC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC,OAA4B,CAAC,CAAC;IACnE,OAAO,OAAO,CAAC,YAAY,GAAG,CAAC,CAAgB,CAAC;AAClD,CAAC;AAXD,gDAWC"}
@@ -1,56 +1,57 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- Object.defineProperty(exports, "getNextSibling", {
8
- enumerable: true,
9
- get: function () {
10
- return _domQuery.getNextSibling;
11
- }
12
- });
13
- Object.defineProperty(exports, "getPreviousSibling", {
14
- enumerable: true,
15
- get: function () {
16
- return _domQuery.getPreviousSibling;
17
- }
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
18
17
  });
19
- var _react = _interopRequireWildcard(require("react"));
20
- var _domQuery = require("./dom-query");
21
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
22
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
23
- const FocusTrapWrapper = ({
24
- children,
25
- closePopup = null,
26
- focusElements = ["button", "a", "input", "select"],
27
- id
28
- }) => {
29
- const queryId = focusElements.map(el => `#${id}-focus-trap ${el}:not([disabled])`).join(", ");
30
- const handleKeyDown = (0, _react.useCallback)(e => {
31
- const element = e.target;
32
- switch (e.key) {
33
- case "Escape":
34
- closePopup();
35
- break;
36
- case "Tab":
37
- e.preventDefault();
38
- if (e.shiftKey) {
39
- var _getPreviousSibling;
40
- (_getPreviousSibling = (0, _domQuery.getPreviousSibling)(queryId, element)) === null || _getPreviousSibling === void 0 || _getPreviousSibling.focus();
41
- } else {
42
- var _getNextSibling;
43
- (_getNextSibling = (0, _domQuery.getNextSibling)(queryId, element)) === null || _getNextSibling === void 0 || _getNextSibling.focus();
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.getPreviousSibling = exports.getNextSibling = void 0;
27
+ const react_1 = __importStar(require("react"));
28
+ const dom_query_1 = require("./dom-query");
29
+ Object.defineProperty(exports, "getNextSibling", { enumerable: true, get: function () { return dom_query_1.getNextSibling; } });
30
+ Object.defineProperty(exports, "getPreviousSibling", { enumerable: true, get: function () { return dom_query_1.getPreviousSibling; } });
31
+ const FocusTrapWrapper = ({ children, closePopup = null, focusElements = ["button", "a", "input", "select"], id }) => {
32
+ const queryId = focusElements
33
+ .map(el => `#${id}-focus-trap ${el}:not([disabled])`)
34
+ .join(", ");
35
+ const handleKeyDown = (0, react_1.useCallback)(e => {
36
+ var _a, _b;
37
+ const element = e.target;
38
+ switch (e.key) {
39
+ case "Escape":
40
+ closePopup();
41
+ break;
42
+ case "Tab":
43
+ e.preventDefault();
44
+ if (e.shiftKey) {
45
+ (_a = (0, dom_query_1.getPreviousSibling)(queryId, element)) === null || _a === void 0 ? void 0 : _a.focus();
46
+ }
47
+ else {
48
+ (_b = (0, dom_query_1.getNextSibling)(queryId, element)) === null || _b === void 0 ? void 0 : _b.focus();
49
+ }
50
+ break;
51
+ default:
44
52
  }
45
- break;
46
- default:
47
- }
48
- }, [closePopup]);
49
- return /*#__PURE__*/_react.default.createElement("div", {
50
- id: `${id}-focus-trap`,
51
- onKeyDown: handleKeyDown,
52
- role: "presentation"
53
- }, children);
53
+ }, [closePopup]);
54
+ return (react_1.default.createElement("div", { id: `${id}-focus-trap`, onKeyDown: handleKeyDown, role: "presentation" }, children));
54
55
  };
55
- var _default = exports.default = FocusTrapWrapper;
56
+ exports.default = FocusTrapWrapper;
56
57
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_react","_interopRequireWildcard","require","_domQuery","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","FocusTrapWrapper","children","closePopup","focusElements","id","queryId","map","el","join","handleKeyDown","useCallback","element","target","key","preventDefault","shiftKey","_getPreviousSibling","getPreviousSibling","focus","_getNextSibling","getNextSibling","createElement","onKeyDown","role","_default","exports"],"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=\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