ag-common 0.0.256 → 0.0.259
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,5 +1,5 @@
|
|
|
1
1
|
import { ISearchDialog, TSearchModalRes } from './types';
|
|
2
|
-
export declare const SearchBase: <T>({ onSelectItem, onSearchTextChange, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }: ISearchDialog<T> & {
|
|
2
|
+
export declare const SearchBase: <T>({ onSelectItem, onSearchTextChange, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, className, texts, }: ISearchDialog<T> & {
|
|
3
3
|
onSearchTextChange?: ((v: string) => void) | undefined;
|
|
4
4
|
onSelectItem?: ((v: TSearchModalRes<T>) => void) | undefined;
|
|
5
5
|
}) => JSX.Element;
|
|
@@ -29,8 +29,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.SearchBase = void 0;
|
|
30
30
|
const helpers_1 = require("../../helpers");
|
|
31
31
|
const TextEdit_1 = require("../TextEdit");
|
|
32
|
+
const styles_1 = require("../../styles");
|
|
32
33
|
const styled_components_1 = __importDefault(require("styled-components"));
|
|
33
34
|
const react_1 = __importStar(require("react"));
|
|
35
|
+
const Base = styled_components_1.default.div `
|
|
36
|
+
display: flex;
|
|
37
|
+
flex-flow: column;
|
|
38
|
+
flex-grow: 1;
|
|
39
|
+
width: 100%;
|
|
40
|
+
`;
|
|
34
41
|
const SearchBox = styled_components_1.default.div `
|
|
35
42
|
padding: 1rem;
|
|
36
43
|
display: flex;
|
|
@@ -39,6 +46,12 @@ const SearchBox = styled_components_1.default.div `
|
|
|
39
46
|
align-items: center;
|
|
40
47
|
width: calc(100% - 2rem);
|
|
41
48
|
margin: auto;
|
|
49
|
+
|
|
50
|
+
@media ${styles_1.smallScreen} {
|
|
51
|
+
margin: 0;
|
|
52
|
+
padding: 0;
|
|
53
|
+
width: 100%;
|
|
54
|
+
}
|
|
42
55
|
`;
|
|
43
56
|
const MagnifyIconSvg = (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 490 490" },
|
|
44
57
|
react_1.default.createElement("path", { fill: "none", stroke: "#000", strokeWidth: "36", strokeLinecap: "round", d: "M280 278a153 153 0 1 0-2 2l170 170m-91-117 110 110-26 26-110-110" })));
|
|
@@ -68,19 +81,22 @@ const Content = styled_components_1.default.div `
|
|
|
68
81
|
max-height: calc(100vh - 20rem);
|
|
69
82
|
overflow-y: auto;
|
|
70
83
|
overflow-x: hidden;
|
|
84
|
+
|
|
85
|
+
flex-grow: 1;
|
|
71
86
|
&[data-hasitems='true'] {
|
|
72
87
|
padding-bottom: 0.5rem;
|
|
73
88
|
}
|
|
89
|
+
@media ${styles_1.smallScreen} {
|
|
90
|
+
margin: 0;
|
|
91
|
+
width: 100%;
|
|
92
|
+
margin-top: 1rem;
|
|
93
|
+
}
|
|
74
94
|
`;
|
|
75
95
|
const Row = styled_components_1.default.div `
|
|
76
96
|
width: 100%;
|
|
77
|
-
height: 100%;
|
|
78
|
-
display: flex;
|
|
79
|
-
flex-flow: column;
|
|
80
|
-
justify-content: center;
|
|
81
|
-
align-items: center;
|
|
82
97
|
`;
|
|
83
|
-
const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }) => {
|
|
98
|
+
const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, className, texts, }) => {
|
|
99
|
+
var _a, _b;
|
|
84
100
|
const [searchText, setSearchText] = (0, react_1.useState)('');
|
|
85
101
|
const resWrap = (foundItem) => {
|
|
86
102
|
if (!foundItem) {
|
|
@@ -91,13 +107,17 @@ const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, closeTe
|
|
|
91
107
|
}
|
|
92
108
|
};
|
|
93
109
|
const filteredItems = displayItems.filter((i) => willDisplayItem(searchText, i));
|
|
94
|
-
|
|
95
|
-
|
|
110
|
+
const showText = (_b = (_a = texts === null || texts === void 0 ? void 0 : texts.totalItems) === null || _a === void 0 ? void 0 : _a.call(texts, filteredItems.length, displayItems.length)) !== null && _b !== void 0 ? _b : `Showing ${filteredItems.length} out of ${displayItems.length} total
|
|
111
|
+
items`;
|
|
112
|
+
return (react_1.default.createElement(Base, { className: className },
|
|
113
|
+
react_1.default.createElement(SearchBox, { "data-type": "search" },
|
|
96
114
|
react_1.default.createElement(TextEdit_1.TextEdit, { placeholder: placeholderText, defaultValue: "", onSubmit: (v) => (0, helpers_1.debounce)(() => {
|
|
97
115
|
setSearchText(v);
|
|
98
116
|
onSearchTextChange === null || onSearchTextChange === void 0 ? void 0 : onSearchTextChange(v);
|
|
99
117
|
}, { key: 'pagesearch', time: 200 }), defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(Icon, null, MagnifyIconSvg), noGrow: true, allowUndo: false, onEscape: () => resWrap(undefined), onClickOutsideWithNoValue: null }),
|
|
100
118
|
react_1.default.createElement(CloseButton, { onClick: () => resWrap(undefined) }, closeText)),
|
|
101
|
-
react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length
|
|
119
|
+
react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length, "data-type": "content" },
|
|
120
|
+
filteredItems.map((i, index) => (react_1.default.createElement(Row, { key: getKeyF(i), onClick: () => resWrap(i) }, renderItem(searchText, i, index)))),
|
|
121
|
+
searchText && react_1.default.createElement(Row, null, showText))));
|
|
102
122
|
};
|
|
103
123
|
exports.SearchBase = SearchBase;
|
|
@@ -17,6 +17,13 @@ export interface ISearchDialog<T> {
|
|
|
17
17
|
* get unique render key
|
|
18
18
|
*/
|
|
19
19
|
getKeyF: (i: T) => string;
|
|
20
|
+
className?: string;
|
|
21
|
+
texts?: {
|
|
22
|
+
/**
|
|
23
|
+
* default if not provided: "showing X out of Y total items"
|
|
24
|
+
*/
|
|
25
|
+
totalItems?: (showing: number, outof: number) => string;
|
|
26
|
+
};
|
|
20
27
|
}
|
|
21
28
|
export declare type TSearchModalRes<T> = undefined | {
|
|
22
29
|
foundItem: T;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useQueryStringSingle = exports.useQueryStringArray = exports.useQueryStringRaw = exports.isServer = void 0;
|
|
4
4
|
const object_1 = require("../../common/helpers/object");
|
|
5
|
+
const common_1 = require("../../common");
|
|
5
6
|
const react_1 = require("react");
|
|
6
7
|
exports.isServer = typeof window === 'undefined';
|
|
7
8
|
/**
|
|
@@ -26,8 +27,13 @@ const useQueryStringRaw = ({ name, queryValues, defaultValue, stringify, parse,
|
|
|
26
27
|
delete qv[name];
|
|
27
28
|
}
|
|
28
29
|
const qs = '?' + (0, object_1.objectToString)(qv, '=', '&');
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
if (!exports.isServer) {
|
|
31
|
+
const loc = window.location.pathname + qs + window.location.hash;
|
|
32
|
+
window.history.replaceState({}, '', loc);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
(0, common_1.info)('cant change url params on server');
|
|
36
|
+
}
|
|
31
37
|
setStateRaw(v);
|
|
32
38
|
};
|
|
33
39
|
//
|