@dhis2-ui/select 10.9.1 → 10.10.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +18 -4
- package/build/cjs/locales/en/translations.json +7 -5
- package/build/cjs/simple-single-select/__stories__/DefaultPosition.js +38 -0
- package/build/cjs/simple-single-select/__stories__/Dense.js +22 -0
- package/build/cjs/simple-single-select/__stories__/Empty.js +20 -0
- package/build/cjs/simple-single-select/__stories__/EmptyWithEmptyNode.js +28 -0
- package/build/cjs/simple-single-select/__stories__/EmptyWithEmptyText.js +21 -0
- package/build/cjs/simple-single-select/__stories__/FlippedPosition.js +37 -0
- package/build/cjs/simple-single-select/__stories__/InfiniteLoading.js +61 -0
- package/build/cjs/simple-single-select/__stories__/Loading.js +20 -0
- package/build/cjs/simple-single-select/__stories__/ShiftedIntoView.js +28 -0
- package/build/cjs/simple-single-select/__stories__/WithClearButton.js +25 -0
- package/build/cjs/simple-single-select/__stories__/WithCustomLowMaxHeight.js +22 -0
- package/build/cjs/simple-single-select/__stories__/WithCustomOptions.js +48 -0
- package/build/cjs/simple-single-select/__stories__/WithDisabledOption.js +28 -0
- package/build/cjs/simple-single-select/__stories__/WithFilterField.js +36 -0
- package/build/cjs/simple-single-select/__stories__/WithInitialFocus.js +38 -0
- package/build/cjs/simple-single-select/__stories__/WithManyOptions.js +24 -0
- package/build/cjs/simple-single-select/__stories__/WithNoMatchText.js +30 -0
- package/build/cjs/simple-single-select/__stories__/WithOnBlur.js +23 -0
- package/build/cjs/simple-single-select/__stories__/WithOnFocus.js +23 -0
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndDisabled.js +22 -0
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndLoading.js +34 -0
- package/build/cjs/simple-single-select/__stories__/WithOptionsAndLoadingText.js +35 -0
- package/build/cjs/simple-single-select/__stories__/WithPlaceholder.js +23 -0
- package/build/cjs/simple-single-select/__stories__/WithPlaceholderAndSelection.js +25 -0
- package/build/cjs/simple-single-select/__stories__/WithPrefix.js +22 -0
- package/build/cjs/simple-single-select/__stories__/WithPrefixAndSelection.js +25 -0
- package/build/cjs/simple-single-select/__stories__/WithRTL.js +34 -0
- package/build/cjs/simple-single-select/__stories__/WithSelection.js +24 -0
- package/build/cjs/simple-single-select/__stories__/WithSelectionAndDisabled.js +25 -0
- package/build/cjs/simple-single-select/__stories__/WithoutOptionsAndLoading.js +21 -0
- package/build/cjs/simple-single-select/__stories__/WithoutSelection.js +22 -0
- package/build/cjs/simple-single-select/__stories__/options.js +77 -0
- package/build/cjs/simple-single-select/features/keyboard-interactions.test.e2e.js +441 -0
- package/build/cjs/simple-single-select/features/menu-positioning.test.e2e.js +152 -0
- package/build/cjs/simple-single-select/index.js +19 -0
- package/build/cjs/simple-single-select/is-option-hidden.js +22 -0
- package/build/cjs/simple-single-select/menu/empty.js +26 -0
- package/build/cjs/simple-single-select/menu/filter.js +60 -0
- package/build/cjs/simple-single-select/menu/index.js +12 -0
- package/build/cjs/simple-single-select/menu/loading.js +30 -0
- package/build/cjs/simple-single-select/menu/menu.js +158 -0
- package/build/cjs/simple-single-select/menu/no-match.js +28 -0
- package/build/cjs/simple-single-select/menu/option.js +120 -0
- package/build/cjs/simple-single-select/menu/options-list.js +97 -0
- package/build/cjs/simple-single-select/selected-value/clear-button.js +74 -0
- package/build/cjs/simple-single-select/selected-value/container.js +100 -0
- package/build/cjs/simple-single-select/selected-value/index.js +12 -0
- package/build/cjs/simple-single-select/selected-value/placeholder.js +30 -0
- package/build/cjs/simple-single-select/selected-value/prefix.js +30 -0
- package/build/cjs/simple-single-select/selected-value/selected-value.js +119 -0
- package/build/cjs/simple-single-select/shared-prop-types.js +14 -0
- package/build/cjs/simple-single-select/simple-single-select.e2e.stories.js +156 -0
- package/build/cjs/simple-single-select/simple-single-select.js +319 -0
- package/build/cjs/simple-single-select/simple-single-select.prod.stories.js +228 -0
- package/build/cjs/simple-single-select/simple-single-select.test.js +1106 -0
- package/build/cjs/simple-single-select/use-handle-key-press/index.js +19 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-focus-option.js +24 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +177 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +106 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-handle-typing.js +81 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +50 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +30 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +50 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +42 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-page-down.js +45 -0
- package/build/cjs/simple-single-select/use-handle-key-press/use-page-up.js +44 -0
- package/build/cjs/simple-single-select/use-handle-key-press/utils.js +46 -0
- package/build/cjs/simple-single-select-field/index.js +12 -0
- package/build/cjs/simple-single-select-field/simple-single-select-field.js +138 -0
- package/build/cjs/simple-single-select-field/simple-single-select-field.prod.stories.js +188 -0
- package/build/cjs/simple-single-select-field/simple-single-select-field.test.js +133 -0
- package/build/es/index.js +2 -0
- package/build/es/locales/en/translations.json +7 -5
- package/build/es/simple-single-select/__stories__/DefaultPosition.js +29 -0
- package/build/es/simple-single-select/__stories__/Dense.js +13 -0
- package/build/es/simple-single-select/__stories__/Empty.js +11 -0
- package/build/es/simple-single-select/__stories__/EmptyWithEmptyNode.js +19 -0
- package/build/es/simple-single-select/__stories__/EmptyWithEmptyText.js +12 -0
- package/build/es/simple-single-select/__stories__/FlippedPosition.js +28 -0
- package/build/es/simple-single-select/__stories__/InfiniteLoading.js +53 -0
- package/build/es/simple-single-select/__stories__/Loading.js +12 -0
- package/build/es/simple-single-select/__stories__/ShiftedIntoView.js +18 -0
- package/build/es/simple-single-select/__stories__/WithClearButton.js +16 -0
- package/build/es/simple-single-select/__stories__/WithCustomLowMaxHeight.js +13 -0
- package/build/es/simple-single-select/__stories__/WithCustomOptions.js +38 -0
- package/build/es/simple-single-select/__stories__/WithDisabledOption.js +19 -0
- package/build/es/simple-single-select/__stories__/WithFilterField.js +27 -0
- package/build/es/simple-single-select/__stories__/WithInitialFocus.js +29 -0
- package/build/es/simple-single-select/__stories__/WithManyOptions.js +15 -0
- package/build/es/simple-single-select/__stories__/WithNoMatchText.js +21 -0
- package/build/es/simple-single-select/__stories__/WithOnBlur.js +14 -0
- package/build/es/simple-single-select/__stories__/WithOnFocus.js +14 -0
- package/build/es/simple-single-select/__stories__/WithOptionsAndDisabled.js +13 -0
- package/build/es/simple-single-select/__stories__/WithOptionsAndLoading.js +25 -0
- package/build/es/simple-single-select/__stories__/WithOptionsAndLoadingText.js +26 -0
- package/build/es/simple-single-select/__stories__/WithPlaceholder.js +14 -0
- package/build/es/simple-single-select/__stories__/WithPlaceholderAndSelection.js +16 -0
- package/build/es/simple-single-select/__stories__/WithPrefix.js +13 -0
- package/build/es/simple-single-select/__stories__/WithPrefixAndSelection.js +16 -0
- package/build/es/simple-single-select/__stories__/WithRTL.js +25 -0
- package/build/es/simple-single-select/__stories__/WithSelection.js +15 -0
- package/build/es/simple-single-select/__stories__/WithSelectionAndDisabled.js +16 -0
- package/build/es/simple-single-select/__stories__/WithoutOptionsAndLoading.js +12 -0
- package/build/es/simple-single-select/__stories__/WithoutSelection.js +13 -0
- package/build/es/simple-single-select/__stories__/options.js +71 -0
- package/build/es/simple-single-select/features/keyboard-interactions.test.e2e.js +439 -0
- package/build/es/simple-single-select/features/menu-positioning.test.e2e.js +150 -0
- package/build/es/simple-single-select/index.js +2 -0
- package/build/es/simple-single-select/is-option-hidden.js +16 -0
- package/build/es/simple-single-select/menu/empty.js +19 -0
- package/build/es/simple-single-select/menu/filter.js +53 -0
- package/build/es/simple-single-select/menu/index.js +1 -0
- package/build/es/simple-single-select/menu/loading.js +23 -0
- package/build/es/simple-single-select/menu/menu.js +149 -0
- package/build/es/simple-single-select/menu/no-match.js +21 -0
- package/build/es/simple-single-select/menu/option.js +111 -0
- package/build/es/simple-single-select/menu/options-list.js +88 -0
- package/build/es/simple-single-select/selected-value/clear-button.js +68 -0
- package/build/es/simple-single-select/selected-value/container.js +91 -0
- package/build/es/simple-single-select/selected-value/index.js +1 -0
- package/build/es/simple-single-select/selected-value/placeholder.js +23 -0
- package/build/es/simple-single-select/selected-value/prefix.js +23 -0
- package/build/es/simple-single-select/selected-value/selected-value.js +112 -0
- package/build/es/simple-single-select/shared-prop-types.js +7 -0
- package/build/es/simple-single-select/simple-single-select.e2e.stories.js +142 -0
- package/build/es/simple-single-select/simple-single-select.js +310 -0
- package/build/es/simple-single-select/simple-single-select.prod.stories.js +36 -0
- package/build/es/simple-single-select/simple-single-select.test.js +1103 -0
- package/build/es/simple-single-select/use-handle-key-press/index.js +2 -0
- package/build/es/simple-single-select/use-handle-key-press/use-focus-option.js +18 -0
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-combobox.js +171 -0
- package/build/es/simple-single-select/use-handle-key-press/use-handle-key-press-on-filter-input.js +100 -0
- package/build/es/simple-single-select/use-handle-key-press/use-handle-typing.js +75 -0
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-option-on-previous-page.js +44 -0
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-first-visible-option.js +24 -0
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-option-on-next-page.js +44 -0
- package/build/es/simple-single-select/use-handle-key-press/use-highlight-last-visible-option.js +36 -0
- package/build/es/simple-single-select/use-handle-key-press/use-page-down.js +39 -0
- package/build/es/simple-single-select/use-handle-key-press/use-page-up.js +38 -0
- package/build/es/simple-single-select/use-handle-key-press/utils.js +36 -0
- package/build/es/simple-single-select-field/index.js +1 -0
- package/build/es/simple-single-select-field/simple-single-select-field.js +131 -0
- package/build/es/simple-single-select-field/simple-single-select-field.prod.stories.js +172 -0
- package/build/es/simple-single-select-field/simple-single-select-field.test.js +130 -0
- package/package.json +15 -15
- package/types/index.d.ts +184 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Filter = Filter;
|
|
7
|
+
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
+
var _input = require("@dhis2-ui/input");
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _react = _interopRequireDefault(require("react"));
|
|
12
|
+
var _index = _interopRequireDefault(require("../../locales/index.js"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function Filter(_ref) {
|
|
15
|
+
let {
|
|
16
|
+
ariaControls,
|
|
17
|
+
dataTest,
|
|
18
|
+
label,
|
|
19
|
+
placeholder,
|
|
20
|
+
tabIndex,
|
|
21
|
+
value,
|
|
22
|
+
onChange,
|
|
23
|
+
onKeyDown
|
|
24
|
+
} = _ref;
|
|
25
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
26
|
+
"data-test": dataTest,
|
|
27
|
+
className: _style.default.dynamic([["3850436710", [_uiConstants.colors.white, _uiConstants.spacers.dp8, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]]])
|
|
28
|
+
}, /*#__PURE__*/_react.default.createElement(_input.Input, {
|
|
29
|
+
dense: true,
|
|
30
|
+
tabIndex: tabIndex,
|
|
31
|
+
ariaControls: ariaControls,
|
|
32
|
+
ariaHaspopup: "listbox",
|
|
33
|
+
ariaLabel: label || _index.default.t('Search options'),
|
|
34
|
+
dataTest: `${dataTest}-input`,
|
|
35
|
+
value: value,
|
|
36
|
+
onChange: _ref2 => {
|
|
37
|
+
let {
|
|
38
|
+
value
|
|
39
|
+
} = _ref2;
|
|
40
|
+
return onChange(value);
|
|
41
|
+
},
|
|
42
|
+
type: "text",
|
|
43
|
+
name: "filter",
|
|
44
|
+
placeholder: placeholder,
|
|
45
|
+
onKeyDown: (_, e) => onKeyDown(e)
|
|
46
|
+
}), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
47
|
+
id: "3850436710",
|
|
48
|
+
dynamic: [_uiConstants.colors.white, _uiConstants.spacers.dp8, _uiConstants.spacers.dp8, _uiConstants.spacers.dp4, _uiConstants.spacers.dp8]
|
|
49
|
+
}, [`div.__jsx-style-dynamic-selector{height:100%;-webkit-inset-block-start:0;-ms-intb-rlock-start:0;inset-block-start:0;background:${_uiConstants.colors.white};}`]));
|
|
50
|
+
}
|
|
51
|
+
Filter.propTypes = {
|
|
52
|
+
ariaControls: _propTypes.default.string.isRequired,
|
|
53
|
+
value: _propTypes.default.string.isRequired,
|
|
54
|
+
onChange: _propTypes.default.func.isRequired,
|
|
55
|
+
dataTest: _propTypes.default.string,
|
|
56
|
+
label: _propTypes.default.string,
|
|
57
|
+
placeholder: _propTypes.default.string,
|
|
58
|
+
tabIndex: _propTypes.default.string,
|
|
59
|
+
onKeyDown: _propTypes.default.func
|
|
60
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Loading = Loading;
|
|
7
|
+
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
+
var _loader = require("@dhis2-ui/loader");
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _react = _interopRequireDefault(require("react"));
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function Loading(_ref) {
|
|
14
|
+
let {
|
|
15
|
+
message
|
|
16
|
+
} = _ref;
|
|
17
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
18
|
+
className: _style.default.dynamic([["316664301", [_uiConstants.spacers.dp16, _uiConstants.colors.grey700, _uiConstants.theme.fonts, _uiConstants.spacers.dp8, _uiConstants.spacers.dp24]]]) + " " + "container"
|
|
19
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
20
|
+
className: _style.default.dynamic([["316664301", [_uiConstants.spacers.dp16, _uiConstants.colors.grey700, _uiConstants.theme.fonts, _uiConstants.spacers.dp8, _uiConstants.spacers.dp24]]])
|
|
21
|
+
}, /*#__PURE__*/_react.default.createElement(_loader.CircularLoader, {
|
|
22
|
+
small: true
|
|
23
|
+
})), message, /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
24
|
+
id: "316664301",
|
|
25
|
+
dynamic: [_uiConstants.spacers.dp16, _uiConstants.colors.grey700, _uiConstants.theme.fonts, _uiConstants.spacers.dp8, _uiConstants.spacers.dp24]
|
|
26
|
+
}, [`.container.__jsx-style-dynamic-selector{box-sizing:border-box;width:100%;height:100%;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;gap:${_uiConstants.spacers.dp16};-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;color:${_uiConstants.colors.grey700};font-family:${_uiConstants.theme.fonts};font-size:13px;padding-block:${_uiConstants.spacers.dp8};padding-inline:${_uiConstants.spacers.dp24};background:rgba(255,255,255,0.8);}`]));
|
|
27
|
+
}
|
|
28
|
+
Loading.propTypes = {
|
|
29
|
+
message: _propTypes.default.string
|
|
30
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Menu = Menu;
|
|
7
|
+
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
+
var _layer = require("@dhis2-ui/layer");
|
|
10
|
+
var _popper = require("@dhis2-ui/popper");
|
|
11
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
12
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
|
+
var _sharedPropTypes = require("../shared-prop-types.js");
|
|
14
|
+
var _empty = require("./empty.js");
|
|
15
|
+
var _filter = require("./filter.js");
|
|
16
|
+
var _loading = require("./loading.js");
|
|
17
|
+
var _noMatch = require("./no-match.js");
|
|
18
|
+
var _optionsList = require("./options-list.js");
|
|
19
|
+
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); }
|
|
20
|
+
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; }
|
|
21
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
22
|
+
function Menu(_ref) {
|
|
23
|
+
let {
|
|
24
|
+
comboBoxId,
|
|
25
|
+
focussedOptionIndex,
|
|
26
|
+
name,
|
|
27
|
+
options,
|
|
28
|
+
onChange,
|
|
29
|
+
optionComponent,
|
|
30
|
+
dataTest,
|
|
31
|
+
disabled,
|
|
32
|
+
empty,
|
|
33
|
+
filterLabel,
|
|
34
|
+
filterPlaceholder,
|
|
35
|
+
filterValue,
|
|
36
|
+
filterable,
|
|
37
|
+
hidden,
|
|
38
|
+
labelledBy,
|
|
39
|
+
listBoxRef,
|
|
40
|
+
loading,
|
|
41
|
+
loadingText,
|
|
42
|
+
maxHeight,
|
|
43
|
+
noMatchText,
|
|
44
|
+
optionUpdateStrategy,
|
|
45
|
+
selectRef,
|
|
46
|
+
selectedValue,
|
|
47
|
+
tabIndex,
|
|
48
|
+
onBlur,
|
|
49
|
+
onClose,
|
|
50
|
+
onEndReached,
|
|
51
|
+
onFilterChange,
|
|
52
|
+
onFilterInputKeyDown
|
|
53
|
+
} = _ref;
|
|
54
|
+
const [menuWidth, setWidth] = (0, _react.useState)('auto');
|
|
55
|
+
const dataTestPrefix = `${dataTest}-menu`;
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
if (selectRef) {
|
|
58
|
+
const callback = () => setWidth(`${selectRef.offsetWidth}px`);
|
|
59
|
+
callback(); // We want to know the width as soon as the
|
|
60
|
+
|
|
61
|
+
selectRef.addEventListener('resize', callback);
|
|
62
|
+
return () => selectRef.removeEventListener('resize', callback);
|
|
63
|
+
}
|
|
64
|
+
}, [selectRef]);
|
|
65
|
+
if (hidden) {
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
const hasNoFilterMatch = !options.length && filterValue &&
|
|
69
|
+
// We don't want to show the noMatchText when
|
|
70
|
+
// we're in the process of loading options
|
|
71
|
+
!loading;
|
|
72
|
+
const isEmpty = !options.length && !filterValue;
|
|
73
|
+
return /*#__PURE__*/_react.default.createElement(_layer.Layer, {
|
|
74
|
+
onBackdropClick: onClose,
|
|
75
|
+
transparent: true
|
|
76
|
+
}, /*#__PURE__*/_react.default.createElement(_popper.Popper, {
|
|
77
|
+
reference: selectRef,
|
|
78
|
+
placement: "bottom-start",
|
|
79
|
+
observeReferenceResize: true
|
|
80
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
81
|
+
style: {
|
|
82
|
+
width: menuWidth,
|
|
83
|
+
maxHeight
|
|
84
|
+
},
|
|
85
|
+
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "menu"
|
|
86
|
+
}, filterable && /*#__PURE__*/_react.default.createElement("div", {
|
|
87
|
+
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "filter-container"
|
|
88
|
+
}, /*#__PURE__*/_react.default.createElement(_filter.Filter, {
|
|
89
|
+
dataTest: `${dataTestPrefix}-filter`,
|
|
90
|
+
value: filterValue,
|
|
91
|
+
label: filterLabel,
|
|
92
|
+
ariaControls: `${name}-listbox`,
|
|
93
|
+
placeholder: filterPlaceholder,
|
|
94
|
+
tabIndex: tabIndex,
|
|
95
|
+
onChange: onFilterChange,
|
|
96
|
+
onKeyDown: onFilterInputKeyDown
|
|
97
|
+
})), isEmpty && /*#__PURE__*/_react.default.createElement(_empty.Empty, null, empty), hasNoFilterMatch && /*#__PURE__*/_react.default.createElement(_noMatch.NoMatch, null, noMatchText), /*#__PURE__*/_react.default.createElement("div", {
|
|
98
|
+
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "listbox-container"
|
|
99
|
+
}, /*#__PURE__*/_react.default.createElement("div", {
|
|
100
|
+
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "listbox-wrapper"
|
|
101
|
+
}, /*#__PURE__*/_react.default.createElement(_optionsList.OptionsList, {
|
|
102
|
+
ref: listBoxRef,
|
|
103
|
+
comboBoxId: comboBoxId,
|
|
104
|
+
optionComponent: optionComponent,
|
|
105
|
+
dataTest: `${dataTestPrefix}-list`,
|
|
106
|
+
disabled: disabled,
|
|
107
|
+
focussedOptionIndex: focussedOptionIndex,
|
|
108
|
+
labelledBy: labelledBy,
|
|
109
|
+
loading: loading,
|
|
110
|
+
id: `${name}-listbox`,
|
|
111
|
+
optionUpdateStrategy: optionUpdateStrategy,
|
|
112
|
+
options: options,
|
|
113
|
+
selectedValue: selectedValue,
|
|
114
|
+
onBlur: onBlur,
|
|
115
|
+
onChange: onChange,
|
|
116
|
+
onEndReached: onEndReached
|
|
117
|
+
})), loading && /*#__PURE__*/_react.default.createElement("div", {
|
|
118
|
+
className: _style.default.dynamic([["2949029222", [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]]]) + " " + "menu-loading-container"
|
|
119
|
+
}, /*#__PURE__*/_react.default.createElement(_loading.Loading, {
|
|
120
|
+
message: loadingText
|
|
121
|
+
}))), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
122
|
+
id: "2949029222",
|
|
123
|
+
dynamic: [_uiConstants.colors.white, _uiConstants.colors.grey200, _uiConstants.elevations.e300]
|
|
124
|
+
}, [`.menu.__jsx-style-dynamic-selector{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;height:auto;background:${_uiConstants.colors.white};border:1px solid ${_uiConstants.colors.grey200};border-radius:3px;box-shadow:${_uiConstants.elevations.e300};box-sizing:content-box;}`, ".listbox-container.__jsx-style-dynamic-selector{position:relative;-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;overflow:hidden;}", ".listbox-wrapper.__jsx-style-dynamic-selector{overflow:auto;-webkit-box-flex:1;-webkit-flex-grow:1;-ms-flex-positive:1;flex-grow:1;}", ".menu-loading-container.__jsx-style-dynamic-selector{position:absolute;left:0;top:0;width:100%;height:100%;}"]))));
|
|
125
|
+
}
|
|
126
|
+
Menu.propTypes = {
|
|
127
|
+
comboBoxId: _propTypes.default.string.isRequired,
|
|
128
|
+
focussedOptionIndex: _propTypes.default.number.isRequired,
|
|
129
|
+
listBoxRef: _propTypes.default.shape({
|
|
130
|
+
current: _propTypes.default.instanceOf(HTMLElement)
|
|
131
|
+
}).isRequired,
|
|
132
|
+
name: _propTypes.default.string.isRequired,
|
|
133
|
+
options: _propTypes.default.arrayOf(_sharedPropTypes.optionProp).isRequired,
|
|
134
|
+
onChange: _propTypes.default.func.isRequired,
|
|
135
|
+
dataTest: _propTypes.default.string,
|
|
136
|
+
disabled: _propTypes.default.bool,
|
|
137
|
+
empty: _propTypes.default.node,
|
|
138
|
+
filterLabel: _propTypes.default.string,
|
|
139
|
+
filterPlaceholder: _propTypes.default.string,
|
|
140
|
+
filterValue: _propTypes.default.string,
|
|
141
|
+
filterable: _propTypes.default.bool,
|
|
142
|
+
hidden: _propTypes.default.bool,
|
|
143
|
+
labelledBy: _propTypes.default.string,
|
|
144
|
+
loading: _propTypes.default.bool,
|
|
145
|
+
loadingText: _propTypes.default.string,
|
|
146
|
+
maxHeight: _propTypes.default.string,
|
|
147
|
+
noMatchText: _propTypes.default.string,
|
|
148
|
+
optionComponent: _propTypes.default.elementType,
|
|
149
|
+
optionUpdateStrategy: _propTypes.default.oneOf(['off', 'polite', 'assertive']),
|
|
150
|
+
selectRef: _propTypes.default.instanceOf(HTMLElement),
|
|
151
|
+
selectedValue: _propTypes.default.string,
|
|
152
|
+
tabIndex: _propTypes.default.string,
|
|
153
|
+
onBlur: _propTypes.default.func,
|
|
154
|
+
onClose: _propTypes.default.func,
|
|
155
|
+
onEndReached: _propTypes.default.func,
|
|
156
|
+
onFilterChange: _propTypes.default.func,
|
|
157
|
+
onFilterInputKeyDown: _propTypes.default.func
|
|
158
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.NoMatch = void 0;
|
|
7
|
+
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
10
|
+
var _react = _interopRequireDefault(require("react"));
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
const NoMatch = _ref => {
|
|
13
|
+
let {
|
|
14
|
+
children,
|
|
15
|
+
className
|
|
16
|
+
} = _ref;
|
|
17
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
18
|
+
className: _style.default.dynamic([["3788156646", [_uiConstants.colors.grey700, _uiConstants.theme.fonts, _uiConstants.spacers.dp8, _uiConstants.spacers.dp24]]]) + " " + (className || "")
|
|
19
|
+
}, children, /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
20
|
+
id: "3788156646",
|
|
21
|
+
dynamic: [_uiConstants.colors.grey700, _uiConstants.theme.fonts, _uiConstants.spacers.dp8, _uiConstants.spacers.dp24]
|
|
22
|
+
}, [`div.__jsx-style-dynamic-selector{color:${_uiConstants.colors.grey700};font-family:${_uiConstants.theme.fonts};font-size:13px;line-height:16px;padding-block:${_uiConstants.spacers.dp8};padding-inline:${_uiConstants.spacers.dp24};text-align:center;}`]));
|
|
23
|
+
};
|
|
24
|
+
exports.NoMatch = NoMatch;
|
|
25
|
+
NoMatch.propTypes = {
|
|
26
|
+
children: _propTypes.default.string.isRequired,
|
|
27
|
+
className: _propTypes.default.string
|
|
28
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Option = Option;
|
|
7
|
+
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
16
|
+
const VISIBILE_INTERSECTION_RATIO = 0.99;
|
|
17
|
+
function DefaultStyle(_ref) {
|
|
18
|
+
let {
|
|
19
|
+
label,
|
|
20
|
+
disabled,
|
|
21
|
+
highlighted
|
|
22
|
+
} = _ref;
|
|
23
|
+
return /*#__PURE__*/_react.default.createElement("span", {
|
|
24
|
+
className: _style.default.dynamic([["4038065645", [_uiConstants.colors.grey900, _uiConstants.spacers.dp8, _uiConstants.spacers.dp12, _uiConstants.spacers.dp16, _uiConstants.colors.grey200, _uiConstants.colors.teal700, _uiConstants.colors.white, _uiConstants.colors.grey500]]]) + " " + ((0, _classnames.default)('option', {
|
|
25
|
+
disabled,
|
|
26
|
+
active: highlighted
|
|
27
|
+
}) || "")
|
|
28
|
+
}, label, /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
29
|
+
id: "4038065645",
|
|
30
|
+
dynamic: [_uiConstants.colors.grey900, _uiConstants.spacers.dp8, _uiConstants.spacers.dp12, _uiConstants.spacers.dp16, _uiConstants.colors.grey200, _uiConstants.colors.teal700, _uiConstants.colors.white, _uiConstants.colors.grey500]
|
|
31
|
+
}, [`span.__jsx-style-dynamic-selector{display:block;cursor:pointer;font-size:14px;-webkit-text-decoration:none;text-decoration:none;color:${_uiConstants.colors.grey900};padding-block:${_uiConstants.spacers.dp8};padding-inline:${_uiConstants.spacers.dp12};line-height:${_uiConstants.spacers.dp16};}`, `span.__jsx-style-dynamic-selector:hover{background-color:${_uiConstants.colors.grey200};}`, `span.__jsx-style-dynamic-selector:active,span.active.__jsx-style-dynamic-selector{background-color:${_uiConstants.colors.teal700};color:${_uiConstants.colors.white};cursor:auto;}`, `span.disabled.__jsx-style-dynamic-selector{color:${_uiConstants.colors.grey500};cursor:not-allowed;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;}`, "span.disabled.__jsx-style-dynamic-selector:hover{background-color:initial;}"]));
|
|
32
|
+
}
|
|
33
|
+
DefaultStyle.propTypes = {
|
|
34
|
+
label: _propTypes.default.string.isRequired,
|
|
35
|
+
disabled: _propTypes.default.bool,
|
|
36
|
+
highlighted: _propTypes.default.bool
|
|
37
|
+
};
|
|
38
|
+
function Option(_ref2) {
|
|
39
|
+
let {
|
|
40
|
+
comboBoxId,
|
|
41
|
+
index,
|
|
42
|
+
label,
|
|
43
|
+
value,
|
|
44
|
+
onClick,
|
|
45
|
+
component: StyleComponent = DefaultStyle,
|
|
46
|
+
dataTest,
|
|
47
|
+
disabled,
|
|
48
|
+
highlighted,
|
|
49
|
+
listBoxRef,
|
|
50
|
+
onBecameVisible,
|
|
51
|
+
...rest
|
|
52
|
+
} = _ref2;
|
|
53
|
+
const buttonRef = (0, _react.useRef)();
|
|
54
|
+
(0, _react.useEffect)(() => {
|
|
55
|
+
if (onBecameVisible) {
|
|
56
|
+
const scrollableContainer = listBoxRef.current.parentNode;
|
|
57
|
+
const intersectionOptions = {
|
|
58
|
+
root: scrollableContainer,
|
|
59
|
+
threshold: VISIBILE_INTERSECTION_RATIO
|
|
60
|
+
};
|
|
61
|
+
const intersectionHandler = entries => {
|
|
62
|
+
entries.forEach(result => {
|
|
63
|
+
const {
|
|
64
|
+
intersectionRatio
|
|
65
|
+
} = result;
|
|
66
|
+
if (intersectionRatio >= VISIBILE_INTERSECTION_RATIO) {
|
|
67
|
+
onBecameVisible();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const observer = new IntersectionObserver(intersectionHandler, intersectionOptions);
|
|
72
|
+
observer.observe(buttonRef.current);
|
|
73
|
+
return () => observer.disconnect();
|
|
74
|
+
}
|
|
75
|
+
}, [onBecameVisible, listBoxRef]);
|
|
76
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
77
|
+
ref: buttonRef,
|
|
78
|
+
id: `${comboBoxId}-${index}`,
|
|
79
|
+
"data-test": dataTest,
|
|
80
|
+
disabled: disabled,
|
|
81
|
+
role: "option",
|
|
82
|
+
"aria-selected": highlighted || 'false',
|
|
83
|
+
"aria-disabled": disabled,
|
|
84
|
+
"aria-label": label,
|
|
85
|
+
onClick: () => {
|
|
86
|
+
if (!disabled) {
|
|
87
|
+
onClick({
|
|
88
|
+
value,
|
|
89
|
+
label
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
className: "jsx-4228237498"
|
|
94
|
+
}, /*#__PURE__*/_react.default.createElement(StyleComponent, _extends({
|
|
95
|
+
value: value,
|
|
96
|
+
label: label,
|
|
97
|
+
index: index,
|
|
98
|
+
disabled: disabled,
|
|
99
|
+
highlighted: highlighted
|
|
100
|
+
}, rest, {
|
|
101
|
+
className: "jsx-4228237498" + " " + (rest && rest.className != null && rest.className || "")
|
|
102
|
+
}), label), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
103
|
+
id: "4228237498"
|
|
104
|
+
}, ["button.jsx-4228237498{display:block;width:100%;padding:0;border:0;background:0;outline:0;text-align:start;}"]));
|
|
105
|
+
}
|
|
106
|
+
Option.propTypes = {
|
|
107
|
+
comboBoxId: _propTypes.default.string.isRequired,
|
|
108
|
+
index: _propTypes.default.number.isRequired,
|
|
109
|
+
label: _propTypes.default.string.isRequired,
|
|
110
|
+
value: _propTypes.default.string.isRequired,
|
|
111
|
+
onClick: _propTypes.default.func.isRequired,
|
|
112
|
+
component: _propTypes.default.elementType,
|
|
113
|
+
dataTest: _propTypes.default.string,
|
|
114
|
+
disabled: _propTypes.default.bool,
|
|
115
|
+
highlighted: _propTypes.default.bool,
|
|
116
|
+
listBoxRef: _propTypes.default.shape({
|
|
117
|
+
current: _propTypes.default.instanceOf(HTMLElement)
|
|
118
|
+
}),
|
|
119
|
+
onBecameVisible: _propTypes.default.func
|
|
120
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.OptionsList = void 0;
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _isOptionHidden = require("../is-option-hidden.js");
|
|
10
|
+
var _sharedPropTypes = require("../shared-prop-types.js");
|
|
11
|
+
var _option = require("./option.js");
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
+
const OptionsList = exports.OptionsList = /*#__PURE__*/(0, _react.forwardRef)(function OptionsList(_ref, ref) {
|
|
16
|
+
let {
|
|
17
|
+
comboBoxId,
|
|
18
|
+
optionComponent,
|
|
19
|
+
focussedOptionIndex,
|
|
20
|
+
id,
|
|
21
|
+
labelledBy,
|
|
22
|
+
optionUpdateStrategy,
|
|
23
|
+
options,
|
|
24
|
+
selectedValue,
|
|
25
|
+
dataTest,
|
|
26
|
+
disabled,
|
|
27
|
+
loading,
|
|
28
|
+
onChange,
|
|
29
|
+
onBlur,
|
|
30
|
+
onEndReached
|
|
31
|
+
} = _ref;
|
|
32
|
+
// scrolls the highlighted option into view when:
|
|
33
|
+
// * the highlighted option changes
|
|
34
|
+
// * the menu opens
|
|
35
|
+
(0, _react.useEffect)(() => {
|
|
36
|
+
const {
|
|
37
|
+
current: listBox
|
|
38
|
+
} = ref;
|
|
39
|
+
const highlightedOption = listBox.childNodes[focussedOptionIndex];
|
|
40
|
+
if (highlightedOption) {
|
|
41
|
+
const listBoxParent = listBox.parentNode;
|
|
42
|
+
const optionHidden = (0, _isOptionHidden.isOptionHidden)(highlightedOption, listBoxParent);
|
|
43
|
+
if (optionHidden) {
|
|
44
|
+
highlightedOption.scrollIntoView();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}, [focussedOptionIndex, ref]);
|
|
48
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
49
|
+
ref: ref,
|
|
50
|
+
role: "listbox",
|
|
51
|
+
id: id,
|
|
52
|
+
"aria-labelledby": labelledBy,
|
|
53
|
+
"aria-live": optionUpdateStrategy,
|
|
54
|
+
"aria-busy": loading.toString(),
|
|
55
|
+
"data-test": dataTest,
|
|
56
|
+
onBlur: onBlur
|
|
57
|
+
}, options.map((_ref2, index) => {
|
|
58
|
+
let {
|
|
59
|
+
value,
|
|
60
|
+
label,
|
|
61
|
+
component,
|
|
62
|
+
disabled: optionDisabled = false
|
|
63
|
+
} = _ref2;
|
|
64
|
+
const isSelected = value === selectedValue;
|
|
65
|
+
const isLast = index === options.length - 1;
|
|
66
|
+
return /*#__PURE__*/_react.default.createElement(_option.Option, {
|
|
67
|
+
listBoxRef: ref,
|
|
68
|
+
dataTest: `${dataTest}-option`,
|
|
69
|
+
highlighted: focussedOptionIndex === index,
|
|
70
|
+
key: value,
|
|
71
|
+
value: value,
|
|
72
|
+
label: label,
|
|
73
|
+
index: index,
|
|
74
|
+
comboBoxId: comboBoxId,
|
|
75
|
+
disabled: disabled || optionDisabled,
|
|
76
|
+
onClick: isSelected ? () => null : onChange,
|
|
77
|
+
component: component || optionComponent,
|
|
78
|
+
onBecameVisible: isLast ? onEndReached : undefined
|
|
79
|
+
});
|
|
80
|
+
}));
|
|
81
|
+
});
|
|
82
|
+
OptionsList.propTypes = {
|
|
83
|
+
comboBoxId: _propTypes.default.string.isRequired,
|
|
84
|
+
focussedOptionIndex: _propTypes.default.number.isRequired,
|
|
85
|
+
id: _propTypes.default.string.isRequired,
|
|
86
|
+
options: _propTypes.default.arrayOf(_sharedPropTypes.optionProp).isRequired,
|
|
87
|
+
onChange: _propTypes.default.func.isRequired,
|
|
88
|
+
dataTest: _propTypes.default.string,
|
|
89
|
+
disabled: _propTypes.default.bool,
|
|
90
|
+
labelledBy: _propTypes.default.string,
|
|
91
|
+
loading: _propTypes.default.bool,
|
|
92
|
+
optionComponent: _propTypes.default.elementType,
|
|
93
|
+
optionUpdateStrategy: _propTypes.default.oneOf(['off', 'polite', 'assertive']),
|
|
94
|
+
selectedValue: _propTypes.default.string,
|
|
95
|
+
onBlur: _propTypes.default.func,
|
|
96
|
+
onEndReached: _propTypes.default.func
|
|
97
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ClearButton = ClearButtonWithTooltip;
|
|
7
|
+
var _style = _interopRequireDefault(require("styled-jsx/style"));
|
|
8
|
+
var _uiConstants = require("@dhis2/ui-constants");
|
|
9
|
+
var _tooltip = require("@dhis2-ui/tooltip");
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
var _react = _interopRequireDefault(require("react"));
|
|
12
|
+
var _index = _interopRequireDefault(require("../../locales/index.js"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
function ClearButton(_ref) {
|
|
15
|
+
let {
|
|
16
|
+
onClear,
|
|
17
|
+
clearText,
|
|
18
|
+
dataTest
|
|
19
|
+
} = _ref;
|
|
20
|
+
return /*#__PURE__*/_react.default.createElement("button", {
|
|
21
|
+
"aria-label": _index.default.t('{{clearText}}', {
|
|
22
|
+
clearText
|
|
23
|
+
}),
|
|
24
|
+
"data-test": dataTest,
|
|
25
|
+
onClick: e => {
|
|
26
|
+
e.stopPropagation();
|
|
27
|
+
onClear();
|
|
28
|
+
},
|
|
29
|
+
className: _style.default.dynamic([["2606883952", [_uiConstants.colors.grey500, _uiConstants.colors.grey800, _uiConstants.colors.grey200, _uiConstants.theme.focus]]])
|
|
30
|
+
}, /*#__PURE__*/_react.default.createElement("svg", {
|
|
31
|
+
width: "16",
|
|
32
|
+
height: "16",
|
|
33
|
+
viewBox: "0 0 16 16",
|
|
34
|
+
fill: "none",
|
|
35
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
36
|
+
className: _style.default.dynamic([["2606883952", [_uiConstants.colors.grey500, _uiConstants.colors.grey800, _uiConstants.colors.grey200, _uiConstants.theme.focus]]])
|
|
37
|
+
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
38
|
+
d: "M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16Zm3.536-5.879a1 1 0 1 1-1.415 1.414l-2.12-2.12-2.122 2.121a1 1 0 1 1-1.415-1.414L6.586 8 4.464 5.878A1 1 0 1 1 5.88 4.464L8 6.586l2.121-2.121a1 1 0 1 1 1.415 1.414L9.415 8l2.12 2.121Z",
|
|
39
|
+
fill: "none",
|
|
40
|
+
className: _style.default.dynamic([["2606883952", [_uiConstants.colors.grey500, _uiConstants.colors.grey800, _uiConstants.colors.grey200, _uiConstants.theme.focus]]])
|
|
41
|
+
})), /*#__PURE__*/_react.default.createElement(_style.default, {
|
|
42
|
+
id: "2606883952",
|
|
43
|
+
dynamic: [_uiConstants.colors.grey500, _uiConstants.colors.grey800, _uiConstants.colors.grey200, _uiConstants.theme.focus]
|
|
44
|
+
}, ["button.__jsx-style-dynamic-selector{background:none;border:none;display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-align-items:center;-webkit-box-align:center;-ms-flex-align:center;align-items:center;-webkit-box-pack:center;-webkit-justify-content:center;-ms-flex-pack:center;justify-content:center;cursor:pointer;height:24px;width:24px;border-radius:3px;}", `button.__jsx-style-dynamic-selector svg.__jsx-style-dynamic-selector path.__jsx-style-dynamic-selector{fill:${_uiConstants.colors.grey500};}`, `button.__jsx-style-dynamic-selector:hover svg.__jsx-style-dynamic-selector path.__jsx-style-dynamic-selector{fill:${_uiConstants.colors.grey800};}`, `button.__jsx-style-dynamic-selector:hover{background:${_uiConstants.colors.grey200};}`, `button.__jsx-style-dynamic-selector:focus{outline:2px solid ${_uiConstants.theme.focus};}`]));
|
|
45
|
+
}
|
|
46
|
+
ClearButton.propTypes = {
|
|
47
|
+
clearText: _propTypes.default.string.isRequired,
|
|
48
|
+
onClear: _propTypes.default.func.isRequired,
|
|
49
|
+
dataTest: _propTypes.default.string
|
|
50
|
+
};
|
|
51
|
+
function ClearButtonWithTooltip(_ref2) {
|
|
52
|
+
let {
|
|
53
|
+
onClear,
|
|
54
|
+
clearText,
|
|
55
|
+
dataTest
|
|
56
|
+
} = _ref2;
|
|
57
|
+
const clearButton = /*#__PURE__*/_react.default.createElement(ClearButton, {
|
|
58
|
+
onClear: onClear,
|
|
59
|
+
dataTest: dataTest,
|
|
60
|
+
clearText: clearText
|
|
61
|
+
});
|
|
62
|
+
if (!clearText) {
|
|
63
|
+
return clearButton;
|
|
64
|
+
}
|
|
65
|
+
return /*#__PURE__*/_react.default.createElement(_tooltip.Tooltip, {
|
|
66
|
+
openDelay: 500,
|
|
67
|
+
content: clearText
|
|
68
|
+
}, clearButton);
|
|
69
|
+
}
|
|
70
|
+
ClearButtonWithTooltip.propTypes = {
|
|
71
|
+
clearText: _propTypes.default.string.isRequired,
|
|
72
|
+
onClear: _propTypes.default.func.isRequired,
|
|
73
|
+
dataTest: _propTypes.default.string
|
|
74
|
+
};
|