ag-common 0.0.386 → 0.0.388
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/dist/ui/components/Search/AutoHideSearchBox.d.ts +8 -0
- package/dist/ui/components/Search/AutoHideSearchBox.js +103 -0
- package/dist/ui/components/Search/SearchBox.d.ts +3 -2
- package/dist/ui/components/Search/SearchBox.js +18 -6
- package/dist/ui/components/Search/index.d.ts +1 -0
- package/dist/ui/components/Search/index.js +1 -0
- package/dist/ui/components/TextEdit/TextEdit.js +1 -4
- package/package.json +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface IAutoHideSearchBox {
|
|
3
|
+
searchText: string;
|
|
4
|
+
setSearchText: (val: string, enterPressed: boolean) => void;
|
|
5
|
+
onOpenToggle?: (open: boolean) => void;
|
|
6
|
+
className?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const AutoHideSearchBox: (p: IAutoHideSearchBox) => JSX.Element;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
exports.AutoHideSearchBox = void 0;
|
|
30
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
31
|
+
const react_1 = __importStar(require("react"));
|
|
32
|
+
const helpers_1 = require("../../helpers");
|
|
33
|
+
const icons_1 = require("../../icons");
|
|
34
|
+
const styles_1 = require("../../styles");
|
|
35
|
+
const SearchBox_1 = require("./SearchBox");
|
|
36
|
+
const Base = styled_1.default.div `
|
|
37
|
+
display: flex;
|
|
38
|
+
flex-flow: row;
|
|
39
|
+
align-items: center;
|
|
40
|
+
margin-left: 1rem;
|
|
41
|
+
|
|
42
|
+
@media ${styles_1.bigScreen} {
|
|
43
|
+
width: 20rem;
|
|
44
|
+
}
|
|
45
|
+
`;
|
|
46
|
+
const Icon = styled_1.default.div `
|
|
47
|
+
display: flex;
|
|
48
|
+
margin-right: 0.5rem;
|
|
49
|
+
> svg {
|
|
50
|
+
width: 1.2rem;
|
|
51
|
+
height: 1.2rem;
|
|
52
|
+
fill: white;
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
55
|
+
const SearchBoxStyled = (0, styled_1.default)(SearchBox_1.SearchBox) `
|
|
56
|
+
transition: width 200ms ease-in-out;
|
|
57
|
+
|
|
58
|
+
overflow: hidden;
|
|
59
|
+
padding: 0;
|
|
60
|
+
&[data-open='false'] {
|
|
61
|
+
width: 0;
|
|
62
|
+
padding: 0;
|
|
63
|
+
}
|
|
64
|
+
@media ${styles_1.smallScreen} {
|
|
65
|
+
padding: 0;
|
|
66
|
+
}
|
|
67
|
+
`;
|
|
68
|
+
const AutoHideSearchBox = (p) => {
|
|
69
|
+
const [open, setOpen] = (0, react_1.useState)(!!p.searchText);
|
|
70
|
+
const textEditRef = (0, react_1.createRef)();
|
|
71
|
+
(0, helpers_1.useGranularEffect)(() => {
|
|
72
|
+
var _a;
|
|
73
|
+
const newOpen = !!p.searchText;
|
|
74
|
+
if (newOpen !== open) {
|
|
75
|
+
setOpen(!open);
|
|
76
|
+
(_a = p.onOpenToggle) === null || _a === void 0 ? void 0 : _a.call(p, !open);
|
|
77
|
+
}
|
|
78
|
+
}, [p.searchText], [open]);
|
|
79
|
+
return (react_1.default.createElement(Base, { className: p.className, "data-open": open },
|
|
80
|
+
react_1.default.createElement(Icon, { style: { cursor: 'pointer' }, onClick: () => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
if (open) {
|
|
83
|
+
p.setSearchText('', false);
|
|
84
|
+
}
|
|
85
|
+
setOpen(!open);
|
|
86
|
+
(_a = p.onOpenToggle) === null || _a === void 0 ? void 0 : _a.call(p, !open);
|
|
87
|
+
if (!open) {
|
|
88
|
+
(_b = textEditRef.current) === null || _b === void 0 ? void 0 : _b.focus();
|
|
89
|
+
}
|
|
90
|
+
} },
|
|
91
|
+
open && react_1.default.createElement(icons_1.CrossIcon, null),
|
|
92
|
+
!open && react_1.default.createElement(icons_1.Magnify, { colour: "white" })),
|
|
93
|
+
react_1.default.createElement(SearchBoxStyled, Object.assign({ ref: textEditRef }, p, { className: "", "data-open": open, defaultValue: p.searchText, setSearchText: (val, enter) => {
|
|
94
|
+
//we dont want empty enters to do anything
|
|
95
|
+
if (val === '' && enter) {
|
|
96
|
+
p.setSearchText(val, false);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
p.setSearchText(val, enter);
|
|
100
|
+
}
|
|
101
|
+
} }))));
|
|
102
|
+
};
|
|
103
|
+
exports.AutoHideSearchBox = AutoHideSearchBox;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IRefTextEdit } from '../TextEdit';
|
|
2
3
|
export interface ISearchBox {
|
|
3
4
|
placeholderText?: string;
|
|
4
5
|
searchText: string;
|
|
@@ -6,4 +7,4 @@ export interface ISearchBox {
|
|
|
6
7
|
defaultValue?: string;
|
|
7
8
|
className?: string;
|
|
8
9
|
}
|
|
9
|
-
export declare const SearchBox:
|
|
10
|
+
export declare const SearchBox: React.ForwardRefExoticComponent<ISearchBox & React.RefAttributes<IRefTextEdit>>;
|
|
@@ -50,10 +50,11 @@ const Base = styled_1.default.div `
|
|
|
50
50
|
width: 100%;
|
|
51
51
|
}
|
|
52
52
|
`;
|
|
53
|
-
const
|
|
53
|
+
const MagnifyIcon = styled_1.default.div `
|
|
54
54
|
width: 1.5rem;
|
|
55
55
|
height: 1.5rem;
|
|
56
56
|
margin-right: 0.5rem;
|
|
57
|
+
cursor: pointer;
|
|
57
58
|
`;
|
|
58
59
|
const CrossIconStyled = (0, styled_1.default)(icons_1.CrossIcon) `
|
|
59
60
|
position: absolute;
|
|
@@ -62,14 +63,26 @@ const CrossIconStyled = (0, styled_1.default)(icons_1.CrossIcon) `
|
|
|
62
63
|
right: 2rem;
|
|
63
64
|
}
|
|
64
65
|
`;
|
|
65
|
-
|
|
66
|
+
exports.SearchBox = (0, react_1.forwardRef)((p, ref) => {
|
|
66
67
|
const textEditRef = (0, react_1.createRef)();
|
|
68
|
+
(0, react_1.useImperativeHandle)(ref, () => ({
|
|
69
|
+
setValue: (v) => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
const value = (_a = textEditRef.current) === null || _a === void 0 ? void 0 : _a.getValue();
|
|
72
|
+
if (v === value) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
(_b = textEditRef.current) === null || _b === void 0 ? void 0 : _b.setValue(v);
|
|
76
|
+
},
|
|
77
|
+
focus: () => { var _a; return (_a = textEditRef.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
78
|
+
getValue: () => { var _a; return (_a = textEditRef.current) === null || _a === void 0 ? void 0 : _a.getValue(); },
|
|
79
|
+
}));
|
|
67
80
|
(0, react_1.useEffect)(() => {
|
|
68
81
|
var _a;
|
|
69
|
-
(_a = textEditRef.current) === null || _a === void 0 ? void 0 : _a.setValue(p.searchText);
|
|
82
|
+
(_a = textEditRef === null || textEditRef === void 0 ? void 0 : textEditRef.current) === null || _a === void 0 ? void 0 : _a.setValue(p.searchText);
|
|
70
83
|
}, [p.searchText, textEditRef]);
|
|
71
84
|
return (react_1.default.createElement(Base, Object.assign({ "data-type": "search", className: p.className }, (0, helpers_1.filterDataProps)(p)),
|
|
72
|
-
react_1.default.createElement(TextEdit_1.TextEdit, { ref: textEditRef, placeholder: p.placeholderText, defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(
|
|
85
|
+
react_1.default.createElement(TextEdit_1.TextEdit, { ref: textEditRef, placeholder: p.placeholderText, defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(MagnifyIcon, { onClick: () => { var _a; return p.setSearchText(((_a = textEditRef === null || textEditRef === void 0 ? void 0 : textEditRef.current) === null || _a === void 0 ? void 0 : _a.getValue()) || '', true); } },
|
|
73
86
|
react_1.default.createElement(icons_1.Magnify, null)), noGrow: true, allowUndo: false, onClickOutsideWithNoValue: null, onSubmit: (v, enterPressed) => (0, helpers_1.debounce)(() => {
|
|
74
87
|
p.setSearchText(v, enterPressed);
|
|
75
88
|
}, { key: 'pagesearch', time: 200 }), defaultValue: p.defaultValue }),
|
|
@@ -78,5 +91,4 @@ const SearchBox = (p) => {
|
|
|
78
91
|
(_a = textEditRef.current) === null || _a === void 0 ? void 0 : _a.setValue('');
|
|
79
92
|
p.setSearchText('', true);
|
|
80
93
|
} }))));
|
|
81
|
-
};
|
|
82
|
-
exports.SearchBox = SearchBox;
|
|
94
|
+
});
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./AutoHideSearchBox"), exports);
|
|
17
18
|
__exportStar(require("./Base"), exports);
|
|
18
19
|
__exportStar(require("./Dialog"), exports);
|
|
19
20
|
__exportStar(require("./Inline"), exports);
|
|
@@ -103,10 +103,7 @@ exports.TextEdit = (0, react_2.forwardRef)((p, ref) => {
|
|
|
103
103
|
}
|
|
104
104
|
setValue(v);
|
|
105
105
|
},
|
|
106
|
-
focus: () => {
|
|
107
|
-
var _a, _b;
|
|
108
|
-
(_b = (_a = taref.current) === null || _a === void 0 ? void 0 : _a.focus) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
109
|
-
},
|
|
106
|
+
focus: () => { var _a; return (_a = taref.current) === null || _a === void 0 ? void 0 : _a.focus(); },
|
|
110
107
|
getValue: () => { var _a; return (_a = taref.current) === null || _a === void 0 ? void 0 : _a.value; },
|
|
111
108
|
}));
|
|
112
109
|
(0, useOnClickOutside_1.useOnClickOutside)({
|