@longline/aqua-ui 1.0.221 → 1.0.223

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.
Files changed (32) hide show
  1. package/containers/Openable/Openable.d.ts +3 -0
  2. package/containers/Openable/Openable.js +15 -24
  3. package/controls/ListView/ColumnsManager/ColumnsManager.js +8 -23
  4. package/formatters/CountryFormatter/CountryFormatter.d.ts +1 -1
  5. package/formatters/CountryFormatter/CountryFormatter.js +1 -1
  6. package/formatters/DivisionFormatter/DivisionFormatter.d.ts +13 -0
  7. package/formatters/DivisionFormatter/DivisionFormatter.js +18 -0
  8. package/formatters/DivisionFormatter/DivisionUtil.d.ts +21 -0
  9. package/formatters/DivisionFormatter/DivisionUtil.js +5044 -0
  10. package/formatters/DivisionFormatter/index.d.ts +1 -0
  11. package/formatters/DivisionFormatter/index.js +1 -0
  12. package/hooks/useOutsideClose/index.d.ts +1 -0
  13. package/hooks/useOutsideClose/index.js +1 -0
  14. package/hooks/useOutsideClose/useOutsideClose.d.ts +75 -0
  15. package/hooks/useOutsideClose/useOutsideClose.js +104 -0
  16. package/inputs/DateInput/DateInput.js +8 -15
  17. package/inputs/Dropdown/Dropdown.js +8 -17
  18. package/inputs/MonthRange/MonthRange.js +10 -21
  19. package/map/controls/Geocoder/Geocoder.js +8 -17
  20. package/map/controls/Geocoder/GeocoderEntry.js +2 -2
  21. package/map/controls/Geocoder/GeocoderList.js +1 -1
  22. package/modules/CountryDropdown/CountryDropdown.d.ts +7 -0
  23. package/modules/CountryDropdown/CountryDropdown.js +26 -0
  24. package/modules/CountryDropdown/index.d.ts +1 -0
  25. package/modules/CountryDropdown/index.js +1 -0
  26. package/modules/DivisionDropdown/DivisionDropdown.d.ts +10 -0
  27. package/modules/DivisionDropdown/DivisionDropdown.js +29 -0
  28. package/modules/DivisionDropdown/index.d.ts +1 -0
  29. package/modules/DivisionDropdown/index.js +1 -0
  30. package/modules/Filter/Filter.js +8 -20
  31. package/package.json +1 -1
  32. package/services/Dialog/Dialog.js +13 -17
@@ -0,0 +1 @@
1
+ export * from './DivisionFormatter';
@@ -0,0 +1 @@
1
+ export * from './DivisionFormatter';
@@ -0,0 +1 @@
1
+ export * from './useOutsideClose';
@@ -0,0 +1 @@
1
+ export * from './useOutsideClose';
@@ -0,0 +1,75 @@
1
+ import * as React from "react";
2
+ type UseOutsideCloseOptions = {
3
+ /**
4
+ * Whether the outside-close behavior is active (the component that uses
5
+ * this is open)
6
+ */
7
+ open: boolean;
8
+ /**
9
+ * Refs that should be considered "inside"
10
+ */
11
+ refs: React.RefObject<HTMLElement>[];
12
+ /**
13
+ * Callback when the user clicks outside (or pressed Escape if enabled)
14
+ */
15
+ onClose: () => void;
16
+ /**
17
+ * Whether Escape should also trigger `onClose`.
18
+ * @default false
19
+ */
20
+ escapeToClose?: boolean;
21
+ /**
22
+ * Whether blur (focus leaving all refs) should trigger `onClose`.
23
+ * @default false
24
+ */
25
+ blurToClose?: boolean;
26
+ };
27
+ /**
28
+ * React hook that closes a component (via `onClose`) when the user interacts
29
+ * outside of one or more referenced elements. Commonly used for dropdowns,
30
+ * popovers, tooltips, or modals.
31
+ *
32
+ * ## Features
33
+ * - Detects clicks outside the provided refs and calls `onClose`.
34
+ * - Optionally closes on `Escape` key press (`escapeToClose`).
35
+ * - Optionally closes when focus leaves all refs (`blurToClose`).
36
+ * - No-op when `active` is `false` (no listeners attached).
37
+ *
38
+ * ## Usage
39
+ * ```tsx
40
+ * const toggleRef = useRef<HTMLButtonElement>(null);
41
+ * const menuRef = useRef<HTMLDivElement>(null);
42
+ *
43
+ * useOutsideClose({
44
+ * open: isOpen,
45
+ * refs: [toggleRef, menuRef],
46
+ * onClose: () => setIsOpen(false),
47
+ * escapeToClose: true,
48
+ * blurToClose: true,
49
+ * });
50
+ *
51
+ * return (
52
+ * <div>
53
+ * <button ref={toggleRef} onClick={() => setIsOpen(v => !v)}>Toggle</button>
54
+ * {isOpen && <div ref={menuRef}>Menu content</div>}
55
+ * </div>
56
+ * );
57
+ * ```
58
+ *
59
+ * ## Parameters
60
+ * @param {Object} options - Configuration object.
61
+ * @param {boolean} options.open - Whether the hook is active. If `false`, no listeners are attached.
62
+ * @param {React.RefObject<HTMLElement>[]} options.refs - Elements that are considered "inside".
63
+ * Interactions within these elements will not trigger `onClose`.
64
+ * @param {() => void} options.onClose - Callback fired when the user clicks outside, presses Escape
65
+ * (if enabled), or tabs focus away (if enabled).
66
+ * @param {boolean} [options.escapeToClose=false] - If `true`, pressing Escape will call `onClose`.
67
+ * @param {boolean} [options.blurToClose=false] - If `true`, moving focus outside all refs will call `onClose`.
68
+ *
69
+ * ## Notes
70
+ * - This hook attaches global listeners to `document` while active and cleans them up automatically.
71
+ * - The hook works with any number of refs. Make sure you pass **stable refs** (e.g. from `useRef`),
72
+ * not inline ref callbacks.
73
+ */
74
+ declare function useOutsideClose({ open, refs, onClose, escapeToClose, blurToClose, }: UseOutsideCloseOptions): void;
75
+ export { useOutsideClose };
@@ -0,0 +1,104 @@
1
+ import * as React from "react";
2
+ /**
3
+ * React hook that closes a component (via `onClose`) when the user interacts
4
+ * outside of one or more referenced elements. Commonly used for dropdowns,
5
+ * popovers, tooltips, or modals.
6
+ *
7
+ * ## Features
8
+ * - Detects clicks outside the provided refs and calls `onClose`.
9
+ * - Optionally closes on `Escape` key press (`escapeToClose`).
10
+ * - Optionally closes when focus leaves all refs (`blurToClose`).
11
+ * - No-op when `active` is `false` (no listeners attached).
12
+ *
13
+ * ## Usage
14
+ * ```tsx
15
+ * const toggleRef = useRef<HTMLButtonElement>(null);
16
+ * const menuRef = useRef<HTMLDivElement>(null);
17
+ *
18
+ * useOutsideClose({
19
+ * open: isOpen,
20
+ * refs: [toggleRef, menuRef],
21
+ * onClose: () => setIsOpen(false),
22
+ * escapeToClose: true,
23
+ * blurToClose: true,
24
+ * });
25
+ *
26
+ * return (
27
+ * <div>
28
+ * <button ref={toggleRef} onClick={() => setIsOpen(v => !v)}>Toggle</button>
29
+ * {isOpen && <div ref={menuRef}>Menu content</div>}
30
+ * </div>
31
+ * );
32
+ * ```
33
+ *
34
+ * ## Parameters
35
+ * @param {Object} options - Configuration object.
36
+ * @param {boolean} options.open - Whether the hook is active. If `false`, no listeners are attached.
37
+ * @param {React.RefObject<HTMLElement>[]} options.refs - Elements that are considered "inside".
38
+ * Interactions within these elements will not trigger `onClose`.
39
+ * @param {() => void} options.onClose - Callback fired when the user clicks outside, presses Escape
40
+ * (if enabled), or tabs focus away (if enabled).
41
+ * @param {boolean} [options.escapeToClose=false] - If `true`, pressing Escape will call `onClose`.
42
+ * @param {boolean} [options.blurToClose=false] - If `true`, moving focus outside all refs will call `onClose`.
43
+ *
44
+ * ## Notes
45
+ * - This hook attaches global listeners to `document` while active and cleans them up automatically.
46
+ * - The hook works with any number of refs. Make sure you pass **stable refs** (e.g. from `useRef`),
47
+ * not inline ref callbacks.
48
+ */
49
+ function useOutsideClose(_a) {
50
+ var open = _a.open, refs = _a.refs, onClose = _a.onClose, _b = _a.escapeToClose, escapeToClose = _b === void 0 ? false : _b, _c = _a.blurToClose, blurToClose = _c === void 0 ? false : _c;
51
+ // Events get added to the component only when it opens, and removed
52
+ // when it closes. This way, components aren't listening for document-wide
53
+ // events when they're closed.
54
+ React.useEffect(function () {
55
+ // If component isn't open, then do nothing:
56
+ if (!open)
57
+ return undefined;
58
+ // When the HTML document gets clicked, see if the click in side one of
59
+ // the HTML elements that were passed in. If so, do nothing. It outside
60
+ // these elements, close the component.
61
+ var handleClick = function (e) {
62
+ var target = e.target;
63
+ var clickedInside = refs.some(function (ref) { return ref.current && ref.current.contains(target); });
64
+ if (!clickedInside) {
65
+ onClose();
66
+ }
67
+ };
68
+ // When the ESC key is pressed (and this feature has been enabled),
69
+ // close the component.
70
+ var handleKeyDown = function (e) {
71
+ if (escapeToClose && e.key === "Escape") {
72
+ onClose();
73
+ }
74
+ };
75
+ var handleBlur = function (e) {
76
+ if (!blurToClose)
77
+ return;
78
+ var target = e.relatedTarget; // where focus is going
79
+ var focusedInside = refs.some(function (ref) { return ref.current && target && ref.current.contains(target); });
80
+ if (!focusedInside) {
81
+ onClose();
82
+ }
83
+ };
84
+ // Add event listeners:
85
+ document.addEventListener("mousedown", handleClick);
86
+ if (escapeToClose) {
87
+ document.addEventListener("keydown", handleKeyDown);
88
+ }
89
+ if (blurToClose) {
90
+ document.addEventListener("focusin", handleBlur); // focusin bubbles
91
+ }
92
+ // Remove event listeners:
93
+ return function () {
94
+ document.removeEventListener("mousedown", handleClick);
95
+ if (escapeToClose) {
96
+ document.removeEventListener("keydown", handleKeyDown);
97
+ }
98
+ if (blurToClose) {
99
+ document.removeEventListener("focusin", handleBlur);
100
+ }
101
+ };
102
+ }, [open, refs, onClose, escapeToClose, blurToClose]);
103
+ }
104
+ export { useOutsideClose };
@@ -30,6 +30,7 @@ import { createPortal } from 'react-dom';
30
30
  import { usePopper } from 'react-popper';
31
31
  import { Selector } from './Selector';
32
32
  import { Body } from './Body';
33
+ import { useOutsideClose } from '../../hooks/useOutsideClose';
33
34
  var DateInputBase = function (props) {
34
35
  var wrapperRef = React.useRef(null);
35
36
  var bodyRef = React.useRef(null);
@@ -47,21 +48,13 @@ var DateInputBase = function (props) {
47
48
  };
48
49
  var _a = React.useState(function () { return parseDate(props.value, null); }), value = _a[0], setValue = _a[1];
49
50
  var _b = React.useState(false), open = _b[0], setOpen = _b[1];
50
- // Add (and remove) document-wide event listener for mousedown.
51
- React.useEffect(function () {
52
- document.addEventListener('mousedown', handleClickOutside);
53
- return function () { return document.removeEventListener('mousedown', handleClickOutside); };
54
- }, []);
55
- //
56
- // Handle document-wide mousedown event by closing the Selector.
57
- // (This only happens if there actually is a Selector).
58
- //
59
- var handleClickOutside = function (e) {
60
- var elem = e.target;
61
- if (wrapperRef.current && bodyRef.current && !wrapperRef.current.contains(elem) && !bodyRef.current.contains(elem)) {
62
- setOpen(false);
63
- }
64
- };
51
+ useOutsideClose({
52
+ open: open,
53
+ refs: [wrapperRef, bodyRef],
54
+ onClose: function () { return setOpen(false); },
55
+ escapeToClose: true,
56
+ blurToClose: true
57
+ });
65
58
  // Open the dropdown.
66
59
  var doOpen = function () {
67
60
  setOpen(true);
@@ -81,6 +81,7 @@ import { Selector } from './Selector';
81
81
  import { Pill } from './Pill';
82
82
  import { ListRow } from '../../containers/List/ListRow';
83
83
  import { ListCell } from '../../containers/List';
84
+ import { useOutsideClose } from '../../hooks/useOutsideClose';
84
85
  var sameWidth = {
85
86
  name: "sameWidth",
86
87
  enabled: true,
@@ -107,27 +108,10 @@ var DropdownBase = function (props) {
107
108
  var _b = React.useState(false), open = _b[0], setOpen = _b[1];
108
109
  // Current search query.
109
110
  var _c = React.useState(null), search = _c[0], setSearch = _c[1];
110
- // A mousedown event listener is attached to the document. When the document
111
- // is clicked anywhere but this Dropdown, the Dropdown closes.
112
- React.useEffect(function () {
113
- // Listen for document-wide mousedown/keydown events when Dropdown mounts.
114
- document.addEventListener('mousedown', handleClickOutside);
115
- return function () {
116
- // Clean up document-wide mousedown/keydown events when Dropdown unmounts.
117
- document.removeEventListener('mousedown', handleClickOutside);
118
- };
119
- }, []);
120
111
  // When value props changes, change local state value also.
121
112
  React.useEffect(function () {
122
113
  setValue(props.value);
123
114
  }, [props.value]);
124
- // Handle document-wide mousedown event by closing the Dropdown.
125
- var handleClickOutside = function (event) {
126
- var elem = event.target;
127
- if (wrapperRef.current && bodyRef.current && !wrapperRef.current.contains(elem) && !bodyRef.current.contains(elem)) {
128
- doClose();
129
- }
130
- };
131
115
  // Open the dropdown.
132
116
  var doOpen = function () {
133
117
  setOpen(true);
@@ -160,6 +144,13 @@ var DropdownBase = function (props) {
160
144
  setTimeout(props.onClose, 300);
161
145
  }
162
146
  };
147
+ useOutsideClose({
148
+ open: open,
149
+ refs: [wrapperRef, bodyRef],
150
+ onClose: doClose,
151
+ escapeToClose: true,
152
+ blurToClose: true
153
+ });
163
154
  // The selector was clicked, open the Dropdown, or close
164
155
  // it if it was open.
165
156
  var handleSelectorClicked = function () {
@@ -30,33 +30,22 @@ import { createPortal } from 'react-dom';
30
30
  import { usePopper } from 'react-popper';
31
31
  import { Selector } from './Selector';
32
32
  import { Body } from './Body';
33
+ import { useOutsideClose } from '../../hooks/useOutsideClose';
33
34
  var MonthRangeBase = function (props) {
34
35
  var wrapperRef = React.useRef(null);
35
36
  var bodyRef = React.useRef(null);
36
37
  var _a = React.useState(props.value), value = _a[0], setValue = _a[1];
37
38
  var _b = React.useState(false), open = _b[0], setOpen = _b[1];
38
- // Add (and remove) document-wide event listener for mousedown.
39
- React.useEffect(function () {
40
- document.addEventListener('mousedown', handleClickOutside);
41
- return function () { return document.removeEventListener('mousedown', handleClickOutside); };
42
- }, []);
43
- //
44
- // Handle document-wide mousedown event by closing the Selector.
45
- // (This only happens if there actually is a Selector).
46
- //
47
- var handleClickOutside = function (e) {
48
- var elem = e.target;
49
- if (wrapperRef.current && bodyRef.current && !wrapperRef.current.contains(elem) && !bodyRef.current.contains(elem)) {
50
- setOpen(false);
51
- }
52
- };
53
- // Open the dropdown.
54
- var doOpen = function () {
55
- setOpen(true);
56
- };
39
+ useOutsideClose({
40
+ open: open,
41
+ refs: [wrapperRef, bodyRef],
42
+ onClose: function () { return setOpen(false); },
43
+ escapeToClose: true,
44
+ blurToClose: true
45
+ });
57
46
  var handleToggle = function () {
58
47
  if (!open) {
59
- doOpen();
48
+ setOpen(true);
60
49
  // Update popper position.
61
50
  if (update)
62
51
  update();
@@ -76,7 +65,7 @@ var MonthRangeBase = function (props) {
76
65
  if (props.ghost)
77
66
  return;
78
67
  if (e.key == ' ' && !open)
79
- doOpen();
68
+ setOpen(true);
80
69
  if (e.key == 'Escape' && open)
81
70
  setOpen(false);
82
71
  };
@@ -32,6 +32,7 @@ import { GeocoderEntry } from './GeocoderEntry';
32
32
  import { GeocoderList } from './GeocoderList';
33
33
  import { GeocoderSelector } from './GeocoderSelector';
34
34
  import { MapControl } from '../base/MapControl';
35
+ import { useOutsideClose } from '../../../hooks/useOutsideClose';
35
36
  var GeocoderBase = function (props) {
36
37
  var wrapperRef = React.useRef(null);
37
38
  var map = useMap().current;
@@ -54,6 +55,13 @@ var GeocoderBase = function (props) {
54
55
  if (wrapperRef)
55
56
  wrapperRef.current.querySelector('input').focus();
56
57
  };
58
+ useOutsideClose({
59
+ open: features.length > 0,
60
+ refs: [wrapperRef],
61
+ onClose: clear,
62
+ escapeToClose: true,
63
+ blurToClose: true
64
+ });
57
65
  //
58
66
  // Call mapbox geocoder API, and store results in state.
59
67
  //
@@ -82,15 +90,6 @@ var GeocoderBase = function (props) {
82
90
  }
83
91
  setTimer(window.setTimeout(function () { return lookup(q); }, 350));
84
92
  };
85
- //
86
- // Handle document-wide mousedown event by closing the list.
87
- //
88
- var handleClickOutside = function () {
89
- var elem = event.target;
90
- if (wrapperRef && !wrapperRef.current.contains(elem)) {
91
- clear();
92
- }
93
- };
94
93
  var handleChange = function (newq) {
95
94
  setQ(newq);
96
95
  lookupDebounced(newq);
@@ -130,14 +129,6 @@ var GeocoderBase = function (props) {
130
129
  break;
131
130
  }
132
131
  };
133
- React.useEffect(function () {
134
- // Listen for document-wide mousedown event when control mounts.
135
- document.addEventListener('mousedown', handleClickOutside);
136
- // Clean up document-wide mousedown event when control unmounts.
137
- return function () {
138
- document.removeEventListener('mousedown', handleClickOutside);
139
- };
140
- });
141
132
  return (React.createElement(MapControl, { x: props.x, y: props.y },
142
133
  React.createElement("div", { className: props.className, onKeyDown: function (e) { return handleKeyDown(e); }, ref: wrapperRef },
143
134
  React.createElement(GeocoderSelector, { placeholder: props.placeholder, searchIcon: props.searchIcon, value: q, onChange: handleChange }),
@@ -5,10 +5,10 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
5
5
  /** @module @ignore */
6
6
  import * as React from 'react';
7
7
  import styled from 'styled-components';
8
- import { ListRow } from '../../../containers/List';
8
+ import { ListCell, ListRow } from '../../../containers/List';
9
9
  var GeocoderEntry = function (props) {
10
10
  return React.createElement(ListRow, { onClick: props.onClick, active: props.selected },
11
- React.createElement("div", { style: { width: '100%' } },
11
+ React.createElement(ListCell, null,
12
12
  React.createElement(ResultText, null, props.feature.properties.name_preferred),
13
13
  React.createElement(ResultPlace, null, props.feature.properties.full_address)));
14
14
  };
@@ -11,7 +11,7 @@ import { List } from '../../../containers/List';
11
11
  */
12
12
  var GeocoderListBase = function (props) {
13
13
  return React.createElement("div", { className: props.className },
14
- React.createElement(List, { tall: true, maxItems: 5, contract: true }, props.children));
14
+ React.createElement(List, { maxItems: 5, contract: true }, props.children));
15
15
  };
16
16
  var GeocoderList = styled(GeocoderListBase)(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n position: absolute;\n width: 100%;\n left: 0;\n ", "\n ", "\n \n"], ["\n position: absolute;\n width: 100%;\n left: 0;\n ", "\n ", "\n \n"])), function (p) { return !p.upwards && css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n top: 42px;\n "], ["\n top: 42px;\n "]))); }, function (p) { return p.upwards && css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n bottom: 42px;\n "], ["\n bottom: 42px;\n "]))); });
17
17
  export { GeocoderList };
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { IDropdownProps } from '../../inputs/Dropdown';
3
+ /**
4
+ * A dropdown preconfigured for country selection. Shows country flags.
5
+ */
6
+ declare const CountryDropdown: (props: IDropdownProps) => React.JSX.Element;
7
+ export { CountryDropdown };
@@ -0,0 +1,26 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import * as React from 'react';
13
+ import { Dropdown } from '../../inputs/Dropdown';
14
+ import { Countries } from '../../formatters/CountryFormatter/Countries';
15
+ import { CountryFormatter } from '../../formatters/CountryFormatter';
16
+ /**
17
+ * A dropdown preconfigured for country selection. Shows country flags.
18
+ */
19
+ var CountryDropdown = function (props) {
20
+ var _a = React.useState(null), q = _a[0], setQ = _a[1];
21
+ var data = Object.keys(Countries)
22
+ .filter(function (c) { return Countries[c][0].toLocaleLowerCase().includes((q || "").toLocaleLowerCase()); });
23
+ return (React.createElement(Dropdown, __assign({ data: data, onSearch: setQ, placeholder: props.placeholder || "Country", label: function (item) { return React.createElement(CountryFormatter, { type: 'both', value: item }); } }, props),
24
+ React.createElement(Dropdown.Column, null, function (item) { return React.createElement(CountryFormatter, { type: 'both', value: item }); })));
25
+ };
26
+ export { CountryDropdown };
@@ -0,0 +1 @@
1
+ export * from './CountryDropdown';
@@ -0,0 +1 @@
1
+ export * from './CountryDropdown';
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ import { IDropdownProps } from '../../inputs/Dropdown';
3
+ interface IProps extends IDropdownProps {
4
+ country: string;
5
+ }
6
+ /**
7
+ * A dropdown preconfigured for division selection (for a particular country).
8
+ */
9
+ declare const DivisionDropdown: (props: IProps) => React.JSX.Element;
10
+ export { DivisionDropdown };
@@ -0,0 +1,29 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import * as React from 'react';
13
+ import { Dropdown } from '../../inputs/Dropdown';
14
+ import { DivisionUtil } from '../../formatters/DivisionFormatter/DivisionUtil';
15
+ /**
16
+ * A dropdown preconfigured for division selection (for a particular country).
17
+ */
18
+ var DivisionDropdown = function (props) {
19
+ var _a = React.useState(null), q = _a[0], setQ = _a[1];
20
+ // Get current country's divisions.
21
+ var divisions = DivisionUtil.getDivisions(props.country);
22
+ // Apply search query to divisions, then sort by division name.
23
+ var data = Object.keys(divisions)
24
+ .filter(function (d) { return divisions[d].toLocaleLowerCase().includes((q || "").toLocaleLowerCase()); })
25
+ .sort(function (a, b) { return divisions[a].localeCompare(divisions[b], 'en'); });
26
+ return (React.createElement(Dropdown, __assign({ data: data, onSearch: setQ, placeholder: props.placeholder || "Province", label: function (item) { return divisions[item]; } }, props),
27
+ React.createElement(Dropdown.Column, null, function (item) { return divisions[item]; })));
28
+ };
29
+ export { DivisionDropdown };
@@ -0,0 +1 @@
1
+ export * from './DivisionDropdown';
@@ -0,0 +1 @@
1
+ export * from './DivisionDropdown';
@@ -30,30 +30,18 @@ import { createPortal } from 'react-dom';
30
30
  import { usePopper } from 'react-popper';
31
31
  import { FilterButton } from '../../controls/FilterButton';
32
32
  import { GlassPane } from '../../containers/GlassPane';
33
+ import { useOutsideClose } from '../../hooks/useOutsideClose';
33
34
  var FilterBase = function (props) {
34
35
  var buttonRef = React.useRef(null);
35
36
  var paneRef = React.useRef(null);
36
37
  var _a = React.useState(false), open = _a[0], setOpen = _a[1];
37
- React.useEffect(function () {
38
- // Listen for document-wide mousedown/keydown events when panel mounts.
39
- document.addEventListener('mousedown', handleClickOutside);
40
- document.addEventListener('keydown', handleKeyDown);
41
- return function () {
42
- // Clean up document-wide mousedown/keydown events when panel unmounts.
43
- document.removeEventListener('mousedown', handleClickOutside);
44
- document.removeEventListener('keydown', handleKeyDown);
45
- };
46
- }, []);
47
- var handleClickOutside = function (e) {
48
- var elem = e.target;
49
- if (buttonRef.current && paneRef.current && !buttonRef.current.contains(elem) && !paneRef.current.contains(elem)) {
50
- setOpen(false);
51
- }
52
- };
53
- var handleKeyDown = function (e) {
54
- if (e.key == 'Escape')
55
- setOpen(false);
56
- };
38
+ useOutsideClose({
39
+ open: open,
40
+ refs: [paneRef, buttonRef],
41
+ onClose: function () { return setOpen(false); },
42
+ escapeToClose: true,
43
+ blurToClose: true
44
+ });
57
45
  var _b = usePopper(buttonRef.current, paneRef.current, {
58
46
  placement: 'bottom-end',
59
47
  modifiers: [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@longline/aqua-ui",
3
- "version": "1.0.221",
3
+ "version": "1.0.223",
4
4
  "description": "AquaUI",
5
5
  "author": "Alexander van Oostenrijk / Longline Environment",
6
6
  "license": "Commercial",
@@ -32,6 +32,7 @@ import { DialogFooter } from './DialogFooter';
32
32
  import { AlertDialog } from './AlertDialog';
33
33
  import { ConfirmDialog } from './ConfirmDialog';
34
34
  import { XhrDialog } from './XhrDialog';
35
+ import { useOutsideClose } from '../../hooks/useOutsideClose';
35
36
  /**
36
37
  * A Dialog is an overlay window that is shown when the Dialog’s `open`
37
38
  * attribute is set to `true`. The calling code is responsible for setting
@@ -48,26 +49,21 @@ var DialogBase = function (props) {
48
49
  preEnter: true,
49
50
  unmountOnExit: true
50
51
  }), _b = _a[0], status = _b.status, isMounted = _b.isMounted, isEnter = _b.isEnter, toggle = _a[1];
52
+ var close = function () {
53
+ if (!props.canClose && !props.onClose)
54
+ return;
55
+ props.onClose();
56
+ };
57
+ useOutsideClose({
58
+ open: props.open,
59
+ refs: [windowRef],
60
+ onClose: close,
61
+ escapeToClose: true,
62
+ blurToClose: true
63
+ });
51
64
  React.useEffect(function () {
52
65
  toggle(props.open);
53
66
  }, [props.open]);
54
- // Listen for document-wide mousedown event when component mounts.
55
- React.useEffect(function () {
56
- document.addEventListener('mousedown', handleClickOutside);
57
- return function () {
58
- // Clean up document-wide mousedown event when component unmounts.
59
- document.removeEventListener('mousedown', handleClickOutside);
60
- };
61
- });
62
- // Handle document-wide mousedown event by sending a dialog close event.
63
- // When clicking outside of it, a Dialog can close only if its canClose
64
- // prop is not set to false.
65
- var handleClickOutside = function (event) {
66
- var elem = event.target;
67
- if (windowRef.current && !windowRef.current.contains(elem) && props.onClose && props.canClose !== false) {
68
- props.onClose();
69
- }
70
- };
71
67
  return (React.createElement(React.Fragment, null, isMounted && React.createElement(React.Fragment, null,
72
68
  createPortal(React.createElement(DialogBackground, { status: status }), document.body),
73
69
  createPortal(React.createElement(DialogWindow, { inverted: props.inverted, width: props.width, ref: windowRef, status: status }, props.children), document.body))));