ag-common 0.0.255 → 0.0.258
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, }: 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,9 +81,16 @@ 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%;
|
|
@@ -80,7 +100,7 @@ const Row = styled_components_1.default.div `
|
|
|
80
100
|
justify-content: center;
|
|
81
101
|
align-items: center;
|
|
82
102
|
`;
|
|
83
|
-
const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }) => {
|
|
103
|
+
const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, className, }) => {
|
|
84
104
|
const [searchText, setSearchText] = (0, react_1.useState)('');
|
|
85
105
|
const resWrap = (foundItem) => {
|
|
86
106
|
if (!foundItem) {
|
|
@@ -91,13 +111,13 @@ const SearchBase = ({ onSelectItem, onSearchTextChange, placeholderText, closeTe
|
|
|
91
111
|
}
|
|
92
112
|
};
|
|
93
113
|
const filteredItems = displayItems.filter((i) => willDisplayItem(searchText, i));
|
|
94
|
-
return (react_1.default.createElement(
|
|
95
|
-
react_1.default.createElement(SearchBox,
|
|
114
|
+
return (react_1.default.createElement(Base, { className: className },
|
|
115
|
+
react_1.default.createElement(SearchBox, { "data-type": "search" },
|
|
96
116
|
react_1.default.createElement(TextEdit_1.TextEdit, { placeholder: placeholderText, defaultValue: "", onSubmit: (v) => (0, helpers_1.debounce)(() => {
|
|
97
117
|
setSearchText(v);
|
|
98
118
|
onSearchTextChange === null || onSearchTextChange === void 0 ? void 0 : onSearchTextChange(v);
|
|
99
119
|
}, { 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
120
|
react_1.default.createElement(CloseButton, { onClick: () => resWrap(undefined) }, closeText)),
|
|
101
|
-
react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length }, filteredItems.map((i, index) => (react_1.default.createElement(Row, { key: getKeyF(i), onClick: () => resWrap(i) }, renderItem(searchText, i, index)))))));
|
|
121
|
+
react_1.default.createElement(Content, { "data-hasitems": !!filteredItems.length, "data-type": "content" }, filteredItems.map((i, index) => (react_1.default.createElement(Row, { key: getKeyF(i), onClick: () => resWrap(i) }, renderItem(searchText, i, index)))))));
|
|
102
122
|
};
|
|
103
123
|
exports.SearchBase = SearchBase;
|
|
@@ -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
|
//
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.258",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@storybook/react": "6.5.6",
|
|
41
41
|
"@storybook/theming": "6.5.6",
|
|
42
42
|
"@types/jsonwebtoken": "8.5.8",
|
|
43
|
-
"@types/node": "17.0.
|
|
43
|
+
"@types/node": "17.0.38",
|
|
44
44
|
"@types/react": "17.0.43",
|
|
45
45
|
"@types/react-dom": "17.0.14",
|
|
46
46
|
"@types/styled-components": "5.1.25",
|