@cashub/ui 0.43.4 → 0.43.5
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/form/SearchSelect.js +158 -0
- package/form/index.js +7 -0
- package/package.json +1 -1
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _styledComponents = _interopRequireDefault(require("styled-components"));
|
|
8
|
+
var _fa = require("react-icons/fa");
|
|
9
|
+
var _react = require("react");
|
|
10
|
+
var _Checkbox = _interopRequireDefault(require("./Checkbox"));
|
|
11
|
+
var _md = require("react-icons/md");
|
|
12
|
+
var _inputPlaceholder = _interopRequireDefault(require("../styles/mixin/inputPlaceholder"));
|
|
13
|
+
var _scrollbar = _interopRequireDefault(require("../styles/mixin/scrollbar"));
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
|
|
16
|
+
const _excluded = ["options", "status", "placeholder", "onInnerSearch", "onOuterSearch", "onOuterReset", "onToggleOptions"];
|
|
17
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
18
|
+
function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
|
|
19
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
23
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
24
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
25
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
|
|
26
|
+
const SearchSelect = _ref => {
|
|
27
|
+
let {
|
|
28
|
+
options,
|
|
29
|
+
status = 'idle',
|
|
30
|
+
placeholder = 'Search',
|
|
31
|
+
onInnerSearch,
|
|
32
|
+
onOuterSearch,
|
|
33
|
+
onOuterReset,
|
|
34
|
+
onToggleOptions
|
|
35
|
+
} = _ref,
|
|
36
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
37
|
+
const containerRef = (0, _react.useRef)();
|
|
38
|
+
const [outerKeyword, setOuterKeyword] = (0, _react.useState)('');
|
|
39
|
+
const [innerKeyword, setInnerKeyword] = (0, _react.useState)('');
|
|
40
|
+
const [showDropdown, setShowDropdown] = (0, _react.useState)(false);
|
|
41
|
+
const [dropdownWidth, setDropdownWidth] = (0, _react.useState)(0);
|
|
42
|
+
const handleSearch = (keyword, target) => {
|
|
43
|
+
if (onOuterSearch && target === 'outer') {
|
|
44
|
+
onOuterSearch(keyword);
|
|
45
|
+
} else if (onInnerSearch && target === 'inner') {
|
|
46
|
+
onInnerSearch(keyword);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const handleKeyUp = (event, target) => {
|
|
50
|
+
if (event.key !== 'Enter') return;
|
|
51
|
+
const keyword = target === 'outer' ? outerKeyword : innerKeyword;
|
|
52
|
+
handleSearch(keyword, target);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// close dropdown when click outside of the component
|
|
56
|
+
(0, _react.useEffect)(() => {
|
|
57
|
+
if (!containerRef.current || !showDropdown) return;
|
|
58
|
+
const handleClick = event => {
|
|
59
|
+
var _containerRef$current;
|
|
60
|
+
if (!((_containerRef$current = containerRef.current) !== null && _containerRef$current !== void 0 && _containerRef$current.contains(event.target))) {
|
|
61
|
+
setShowDropdown(false);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
document.addEventListener('click', handleClick);
|
|
65
|
+
return () => document.removeEventListener('click', handleClick);
|
|
66
|
+
}, [showDropdown]);
|
|
67
|
+
|
|
68
|
+
// align container width to dropdown
|
|
69
|
+
(0, _react.useEffect)(() => {
|
|
70
|
+
if (!containerRef.current) return;
|
|
71
|
+
const observer = new ResizeObserver(entries => {
|
|
72
|
+
const newWidth = entries[0].contentRect.width;
|
|
73
|
+
setDropdownWidth(newWidth);
|
|
74
|
+
});
|
|
75
|
+
observer.observe(containerRef.current);
|
|
76
|
+
return () => observer.disconnect();
|
|
77
|
+
}, []);
|
|
78
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Container, {
|
|
79
|
+
ref: containerRef,
|
|
80
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(InputWrapper, _objectSpread(_objectSpread({
|
|
81
|
+
noMargin: true,
|
|
82
|
+
onClick: () => setShowDropdown(true)
|
|
83
|
+
}, props), {}, {
|
|
84
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_fa.FaSearch, {
|
|
85
|
+
onClick: () => handleSearch(outerKeyword, 'outer')
|
|
86
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Input, {
|
|
87
|
+
type: "text",
|
|
88
|
+
placeholder: placeholder,
|
|
89
|
+
onChange: event => setOuterKeyword(event.target.value),
|
|
90
|
+
onKeyUp: event => handleKeyUp(event, 'outer'),
|
|
91
|
+
onFocus: () => setShowDropdown(true),
|
|
92
|
+
value: outerKeyword
|
|
93
|
+
}), onOuterReset && /*#__PURE__*/(0, _jsxRuntime.jsx)(_md.MdClose, {
|
|
94
|
+
onClick: onOuterReset,
|
|
95
|
+
style: {
|
|
96
|
+
visibility: status === 'empty' ? 'visible' : 'hidden'
|
|
97
|
+
}
|
|
98
|
+
})]
|
|
99
|
+
})), showDropdown && /*#__PURE__*/(0, _jsxRuntime.jsxs)(Dropdown, {
|
|
100
|
+
style: {
|
|
101
|
+
width: dropdownWidth
|
|
102
|
+
},
|
|
103
|
+
children: [onOuterReset && status === 'empty' && /*#__PURE__*/(0, _jsxRuntime.jsx)(MessageWrapper, {
|
|
104
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Message, {
|
|
105
|
+
children: "Data Not Found"
|
|
106
|
+
})
|
|
107
|
+
}), status !== 'empty' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
|
|
108
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(InputWrapper, {
|
|
109
|
+
border: true,
|
|
110
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_fa.FaSearch, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(Input, {
|
|
111
|
+
type: "text",
|
|
112
|
+
placeholder: "Search",
|
|
113
|
+
onChange: event => setInnerKeyword(event.target.value),
|
|
114
|
+
onKeyUp: event => handleKeyUp(event, 'inner'),
|
|
115
|
+
value: innerKeyword
|
|
116
|
+
})]
|
|
117
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(OptionList, {
|
|
118
|
+
children: options.map((option, index) => {
|
|
119
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Option, {
|
|
120
|
+
onClick: () => onToggleOptions(index),
|
|
121
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Checkbox.default, {
|
|
122
|
+
checked: option.checked,
|
|
123
|
+
htmlFor: option.text,
|
|
124
|
+
noMargin: true,
|
|
125
|
+
onChange: () => onToggleOptions(index),
|
|
126
|
+
text: option.text
|
|
127
|
+
})
|
|
128
|
+
}, index);
|
|
129
|
+
})
|
|
130
|
+
})]
|
|
131
|
+
})]
|
|
132
|
+
})]
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const Container = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n min-width: 160px;\n max-width: 320px;\n"])));
|
|
136
|
+
const InputWrapper = _styledComponents.default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n height: 36px;\n background: var(--color-background1);\n border-radius: var(--border-radius-l);\n padding: var(--spacing-s);\n margin: var(--spacing-xs);\n gap: var(--spacing-xs);\n\n > svg {\n color: var(--font-on-mute);\n }\n\n ", "\n\n ", "\n\n ", "\n"])), _ref2 => {
|
|
137
|
+
let {
|
|
138
|
+
backgroundReverse
|
|
139
|
+
} = _ref2;
|
|
140
|
+
return backgroundReverse && 'background: var(--color-background2);';
|
|
141
|
+
}, _ref3 => {
|
|
142
|
+
let {
|
|
143
|
+
border
|
|
144
|
+
} = _ref3;
|
|
145
|
+
return border && 'border: var(--border-width) solid var(--border-color);';
|
|
146
|
+
}, _ref4 => {
|
|
147
|
+
let {
|
|
148
|
+
noMargin
|
|
149
|
+
} = _ref4;
|
|
150
|
+
return noMargin && 'margin: 0;';
|
|
151
|
+
});
|
|
152
|
+
const Input = _styledComponents.default.input(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n background: transparent;\n border: none;\n font-size: var(--font-body1);\n color: var(--font-on-background);\n outline: none;\n flex:1;\n min-width: 0;\n\n ", "\n"])), (0, _inputPlaceholder.default)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n color: var(--font-on-mute);\n "]))));
|
|
153
|
+
const Dropdown = _styledComponents.default.div(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n inset: 44px auto auto 0px;\n background: var(--color-background1);\n color: var(--font-on-background);\n border: var(--border-width) solid var(--border-color);\n border-radius: var(--border-radius);\n box-shadow: var(--box-shadow);\n z-index: 1;\n padding-bottom: var(--spacing-xs);\n overflow-y: auto;\n max-height: min(320px, ((50vh - 36px) - 20px) - 36px);\n ", "\n"])), _scrollbar.default);
|
|
154
|
+
const OptionList = _styledComponents.default.div(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral([""])));
|
|
155
|
+
const Option = _styledComponents.default.div(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n padding: 12px var(--spacing-s);\n cursor: pointer;\n\n &:hover {\n background: var(--color-hover);\n }\n"])));
|
|
156
|
+
const MessageWrapper = _styledComponents.default.div(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n width: 100%;\n text-align: center;\n margin-top: var(--spacing-xs);\n"])));
|
|
157
|
+
const Message = _styledComponents.default.p(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n margin: 0;\n padding: 12px var(--spacing-s);\n"])));
|
|
158
|
+
var _default = exports.default = SearchSelect;
|
package/form/index.js
CHANGED
|
@@ -51,6 +51,12 @@ Object.defineProperty(exports, "RadioButton", {
|
|
|
51
51
|
return _RadioButton.default;
|
|
52
52
|
}
|
|
53
53
|
});
|
|
54
|
+
Object.defineProperty(exports, "SearchSelect", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _SearchSelect.default;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
54
60
|
Object.defineProperty(exports, "Searchbox", {
|
|
55
61
|
enumerable: true,
|
|
56
62
|
get: function () {
|
|
@@ -94,4 +100,5 @@ var _Slider = _interopRequireDefault(require("./Slider"));
|
|
|
94
100
|
var _SwitchButton = _interopRequireDefault(require("./SwitchButton"));
|
|
95
101
|
var _Textarea = _interopRequireDefault(require("./Textarea"));
|
|
96
102
|
var _TreeView = _interopRequireDefault(require("./TreeView"));
|
|
103
|
+
var _SearchSelect = _interopRequireDefault(require("./SearchSelect"));
|
|
97
104
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|