ag-common 0.0.189 → 0.0.192
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/SearchModal/SearchModal.d.ts +6 -0
- package/dist/ui/components/SearchModal/SearchModal.js +123 -0
- package/dist/ui/components/SearchModal/index.d.ts +3 -31
- package/dist/ui/components/SearchModal/index.js +5 -132
- package/dist/ui/components/SearchModal/searchDialog.d.ts +7 -0
- package/dist/ui/components/SearchModal/searchDialog.js +32 -0
- package/dist/ui/components/SearchModal/types.d.ts +25 -0
- package/dist/ui/components/SearchModal/types.js +2 -0
- package/dist/ui/components/TextEdit/TextEdit.d.ts +5 -1
- package/dist/ui/components/TextEdit/TextEdit.js +9 -5
- package/dist/ui/helpers/useOnScroll.d.ts +10 -1
- package/dist/ui/helpers/useOnScroll.js +10 -6
- package/package.json +1 -1
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { ISearchDialog, TSearchModalRes } from './types';
|
|
3
|
+
export declare const SearchModal: <T>({ res, wrapper, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }: ISearchDialog<T> & {
|
|
4
|
+
res: (v: TSearchModalRes<T>) => void;
|
|
5
|
+
wrapper: HTMLDivElement;
|
|
6
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,123 @@
|
|
|
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.SearchModal = void 0;
|
|
30
|
+
const debounce_1 = require("../../helpers/debounce");
|
|
31
|
+
const media_1 = require("../../styles/media");
|
|
32
|
+
const Modal_1 = require("../Modal");
|
|
33
|
+
const TextEdit_1 = require("../TextEdit/TextEdit");
|
|
34
|
+
const styled_components_1 = __importDefault(require("styled-components"));
|
|
35
|
+
const react_1 = __importStar(require("react"));
|
|
36
|
+
const ModalStyled = (0, styled_components_1.default)(Modal_1.Modal) `
|
|
37
|
+
display: flex;
|
|
38
|
+
flex-flow: column;
|
|
39
|
+
top: 10rem;
|
|
40
|
+
@media ${media_1.bigScreen} {
|
|
41
|
+
width: 50vw;
|
|
42
|
+
max-width: 60rem;
|
|
43
|
+
}
|
|
44
|
+
@media ${media_1.smallScreen} {
|
|
45
|
+
max-width: 95vw;
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
const SearchBox = styled_components_1.default.div `
|
|
49
|
+
padding: 1rem;
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-flow: row;
|
|
52
|
+
justify-content: center;
|
|
53
|
+
align-items: center;
|
|
54
|
+
`;
|
|
55
|
+
const MagnifyIconSvg = (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 490 490" },
|
|
56
|
+
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" })));
|
|
57
|
+
const Icon = styled_components_1.default.div `
|
|
58
|
+
width: 1.5rem;
|
|
59
|
+
height: 1.5rem;
|
|
60
|
+
margin-right: 0.5rem;
|
|
61
|
+
`;
|
|
62
|
+
const CloseButton = styled_components_1.default.div `
|
|
63
|
+
font-weight: bold;
|
|
64
|
+
margin-left: 1rem;
|
|
65
|
+
font-size: 1.1rem;
|
|
66
|
+
z-index: 1;
|
|
67
|
+
color: #333;
|
|
68
|
+
cursor: pointer;
|
|
69
|
+
&:hover {
|
|
70
|
+
text-decoration: underline;
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
const Content = styled_components_1.default.div `
|
|
74
|
+
display: flex;
|
|
75
|
+
flex-flow: column;
|
|
76
|
+
justify-content: flex-start;
|
|
77
|
+
align-items: center;
|
|
78
|
+
max-height: calc(100vh - 20rem);
|
|
79
|
+
overflow-y: auto;
|
|
80
|
+
padding-bottom: 0.5rem;
|
|
81
|
+
`;
|
|
82
|
+
const Row = styled_components_1.default.div `
|
|
83
|
+
width: 100%;
|
|
84
|
+
height: 100%;
|
|
85
|
+
display: flex;
|
|
86
|
+
flex-flow: column;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
align-items: center;
|
|
89
|
+
`;
|
|
90
|
+
const SearchModal = ({ res, wrapper, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }) => {
|
|
91
|
+
let originalStyle;
|
|
92
|
+
(0, react_1.useEffect)(() => {
|
|
93
|
+
if (originalStyle === undefined) {
|
|
94
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
95
|
+
originalStyle = window.getComputedStyle(document.body).overflow || '';
|
|
96
|
+
document.body.style.overflow = 'hidden';
|
|
97
|
+
}
|
|
98
|
+
}, []);
|
|
99
|
+
const [searchText, setSearchText] = (0, react_1.useState)('');
|
|
100
|
+
const resWrap = (foundItem) => {
|
|
101
|
+
try {
|
|
102
|
+
document.body.style.overflow = originalStyle || '';
|
|
103
|
+
if (!foundItem) {
|
|
104
|
+
res(undefined);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
res({ foundItem, searchText });
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
finally {
|
|
111
|
+
wrapper.remove();
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
const filteredItems = displayItems.filter((i) => willDisplayItem(searchText, i));
|
|
115
|
+
return (react_1.default.createElement(ModalStyled, { position: "center", topPosition: "center", open: true, setOpen: () => resWrap(undefined), showCloseButton: false, closeOnClickOutside: true },
|
|
116
|
+
react_1.default.createElement(SearchBox, null,
|
|
117
|
+
react_1.default.createElement(TextEdit_1.TextEdit, { placeholder: placeholderText, defaultValue: "", onSubmit: (v) => (0, debounce_1.debounce)(() => {
|
|
118
|
+
setSearchText(v);
|
|
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) }),
|
|
120
|
+
react_1.default.createElement(CloseButton, { onClick: () => resWrap(undefined) }, closeText)),
|
|
121
|
+
react_1.default.createElement(Content, null, filteredItems.map((i) => (react_1.default.createElement(Row, { key: getKeyF(i), onClick: () => resWrap(i) }, renderItem(searchText, i)))))));
|
|
122
|
+
};
|
|
123
|
+
exports.SearchModal = SearchModal;
|
|
@@ -1,31 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
closeText?: string;
|
|
5
|
-
/**
|
|
6
|
-
* method run to render each filtered item
|
|
7
|
-
*/
|
|
8
|
-
renderItem: (searchText: string, item: T) => JSX.Element | string;
|
|
9
|
-
/**
|
|
10
|
-
* all potential items
|
|
11
|
-
*/
|
|
12
|
-
displayItems: T[];
|
|
13
|
-
/**
|
|
14
|
-
* run to filter items by search text
|
|
15
|
-
*/
|
|
16
|
-
willDisplayItem: (searchText: string, item: T) => boolean;
|
|
17
|
-
/**
|
|
18
|
-
* get unique render key
|
|
19
|
-
*/
|
|
20
|
-
getKeyF: (i: T) => string;
|
|
21
|
-
}
|
|
22
|
-
export declare type TSearchModalRes<T> = undefined | {
|
|
23
|
-
foundItem: T;
|
|
24
|
-
searchText: string;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* opens a searchmodal programatically, and resolves to either undefined, or the selected item
|
|
28
|
-
* @param p
|
|
29
|
-
* @returns
|
|
30
|
-
*/
|
|
31
|
-
export declare const searchDialog: <T>(p: ISearchDialog<T>) => Promise<TSearchModalRes<T>>;
|
|
1
|
+
export * from './types';
|
|
2
|
+
export * from './SearchModal';
|
|
3
|
+
export * from './searchDialog';
|
|
@@ -10,137 +10,10 @@ var __createBinding = (this && this.__createBinding) || (Object.create ? (functi
|
|
|
10
10
|
if (k2 === undefined) k2 = k;
|
|
11
11
|
o[k2] = m[k];
|
|
12
12
|
}));
|
|
13
|
-
var
|
|
14
|
-
|
|
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
36
15
|
};
|
|
37
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const Modal_1 = require("../Modal");
|
|
42
|
-
const TextEdit_1 = require("../TextEdit/TextEdit");
|
|
43
|
-
const styled_components_1 = __importDefault(require("styled-components"));
|
|
44
|
-
const react_dom_1 = __importDefault(require("react-dom"));
|
|
45
|
-
const react_1 = __importStar(require("react"));
|
|
46
|
-
const ModalStyled = (0, styled_components_1.default)(Modal_1.Modal) `
|
|
47
|
-
display: flex;
|
|
48
|
-
flex-flow: column;
|
|
49
|
-
top: 10rem;
|
|
50
|
-
@media ${media_1.bigScreen} {
|
|
51
|
-
width: 50vw;
|
|
52
|
-
max-width: 60rem;
|
|
53
|
-
}
|
|
54
|
-
@media ${media_1.smallScreen} {
|
|
55
|
-
max-width: 95vw;
|
|
56
|
-
}
|
|
57
|
-
`;
|
|
58
|
-
const SearchBox = styled_components_1.default.div `
|
|
59
|
-
padding: 1rem;
|
|
60
|
-
display: flex;
|
|
61
|
-
flex-flow: row;
|
|
62
|
-
justify-content: center;
|
|
63
|
-
align-items: center;
|
|
64
|
-
`;
|
|
65
|
-
const MagnifyIconSvg = (react_1.default.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 490 490" },
|
|
66
|
-
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" })));
|
|
67
|
-
const Icon = styled_components_1.default.div `
|
|
68
|
-
width: 1.5rem;
|
|
69
|
-
height: 1.5rem;
|
|
70
|
-
margin-right: 0.5rem;
|
|
71
|
-
`;
|
|
72
|
-
const CloseButton = styled_components_1.default.div `
|
|
73
|
-
font-weight: bold;
|
|
74
|
-
margin-left: 1rem;
|
|
75
|
-
font-size: 1.1rem;
|
|
76
|
-
z-index: 1;
|
|
77
|
-
color: #333;
|
|
78
|
-
cursor: pointer;
|
|
79
|
-
&:hover {
|
|
80
|
-
text-decoration: underline;
|
|
81
|
-
}
|
|
82
|
-
`;
|
|
83
|
-
const Content = styled_components_1.default.div `
|
|
84
|
-
display: flex;
|
|
85
|
-
flex-flow: column;
|
|
86
|
-
justify-content: flex-start;
|
|
87
|
-
align-items: center;
|
|
88
|
-
max-height: calc(100vh - 20rem);
|
|
89
|
-
overflow-y: auto;
|
|
90
|
-
padding-bottom: 0.5rem;
|
|
91
|
-
`;
|
|
92
|
-
const Row = styled_components_1.default.div `
|
|
93
|
-
width: 100%;
|
|
94
|
-
height: 100%;
|
|
95
|
-
display: flex;
|
|
96
|
-
flex-flow: column;
|
|
97
|
-
justify-content: center;
|
|
98
|
-
align-items: center;
|
|
99
|
-
`;
|
|
100
|
-
const SearchModal = ({ res, wrapper, placeholderText, closeText, renderItem, displayItems, willDisplayItem, getKeyF, }) => {
|
|
101
|
-
let originalStyle;
|
|
102
|
-
(0, react_1.useEffect)(() => {
|
|
103
|
-
if (originalStyle === undefined) {
|
|
104
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
105
|
-
originalStyle = window.getComputedStyle(document.body).overflow || '';
|
|
106
|
-
document.body.style.overflow = 'hidden';
|
|
107
|
-
}
|
|
108
|
-
}, []);
|
|
109
|
-
const [searchText, setSearchText] = (0, react_1.useState)('');
|
|
110
|
-
const resWrap = (foundItem) => {
|
|
111
|
-
try {
|
|
112
|
-
document.body.style.overflow = originalStyle || '';
|
|
113
|
-
if (!foundItem) {
|
|
114
|
-
res(undefined);
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
res({ foundItem, searchText });
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
finally {
|
|
121
|
-
wrapper.remove();
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
const filteredItems = displayItems.filter((i) => willDisplayItem(searchText, i));
|
|
125
|
-
return (react_1.default.createElement(ModalStyled, { position: "center", topPosition: "center", open: true, setOpen: () => resWrap(undefined), showCloseButton: false, closeOnClickOutside: true },
|
|
126
|
-
react_1.default.createElement(SearchBox, null,
|
|
127
|
-
react_1.default.createElement(TextEdit_1.TextEdit, { placeholder: placeholderText, defaultValue: "", onSubmit: (v) => (0, debounce_1.debounce)(() => {
|
|
128
|
-
setSearchText(v);
|
|
129
|
-
}, { key: 'pagesearch', time: 200 }), defaultEditing: { focus: true }, singleLine: true, leftContent: react_1.default.createElement(Icon, null, MagnifyIconSvg), noGrow: true, allowUndo: false }),
|
|
130
|
-
react_1.default.createElement(CloseButton, { onClick: () => resWrap(undefined) }, closeText)),
|
|
131
|
-
react_1.default.createElement(Content, null, filteredItems.map((i) => (react_1.default.createElement(Row, { key: getKeyF(i), onClick: () => resWrap(i) }, renderItem(searchText, i)))))));
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* opens a searchmodal programatically, and resolves to either undefined, or the selected item
|
|
135
|
-
* @param p
|
|
136
|
-
* @returns
|
|
137
|
-
*/
|
|
138
|
-
const searchDialog = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
139
|
-
const placeholderText = p.placeholderText || '';
|
|
140
|
-
const closeText = p.closeText || 'CLOSE';
|
|
141
|
-
return new Promise((res) => {
|
|
142
|
-
const wrapper = document.body.appendChild(document.createElement('div'));
|
|
143
|
-
react_dom_1.default.render(react_1.default.createElement(SearchModal, Object.assign({}, p, { placeholderText: placeholderText, closeText: closeText, res: (r) => res(r), wrapper: wrapper })), wrapper);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
146
|
-
exports.searchDialog = searchDialog;
|
|
17
|
+
__exportStar(require("./types"), exports);
|
|
18
|
+
__exportStar(require("./SearchModal"), exports);
|
|
19
|
+
__exportStar(require("./searchDialog"), exports);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ISearchDialog, TSearchModalRes } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* opens a searchmodal programatically, and resolves to either undefined, or the selected item
|
|
4
|
+
* @param p
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export declare const searchDialog: <T>(p: ISearchDialog<T>) => Promise<TSearchModalRes<T>>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.searchDialog = void 0;
|
|
16
|
+
const SearchModal_1 = require("./SearchModal");
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const react_dom_1 = __importDefault(require("react-dom"));
|
|
19
|
+
/**
|
|
20
|
+
* opens a searchmodal programatically, and resolves to either undefined, or the selected item
|
|
21
|
+
* @param p
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
const searchDialog = (p) => __awaiter(void 0, void 0, void 0, function* () {
|
|
25
|
+
const placeholderText = p.placeholderText || '';
|
|
26
|
+
const closeText = p.closeText || 'CLOSE';
|
|
27
|
+
return new Promise((res) => {
|
|
28
|
+
const wrapper = document.body.appendChild(document.createElement('div'));
|
|
29
|
+
react_dom_1.default.render(react_1.default.createElement(SearchModal_1.SearchModal, Object.assign({}, p, { placeholderText: placeholderText, closeText: closeText, res: (r) => res(r), wrapper: wrapper })), wrapper);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
exports.searchDialog = searchDialog;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface ISearchDialog<T> {
|
|
3
|
+
placeholderText?: string;
|
|
4
|
+
closeText?: string;
|
|
5
|
+
/**
|
|
6
|
+
* method run to render each filtered item
|
|
7
|
+
*/
|
|
8
|
+
renderItem: (searchText: string, item: T) => JSX.Element | string;
|
|
9
|
+
/**
|
|
10
|
+
* all potential items
|
|
11
|
+
*/
|
|
12
|
+
displayItems: T[];
|
|
13
|
+
/**
|
|
14
|
+
* run to filter items by search text
|
|
15
|
+
*/
|
|
16
|
+
willDisplayItem: (searchText: string, item: T) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* get unique render key
|
|
19
|
+
*/
|
|
20
|
+
getKeyF: (i: T) => string;
|
|
21
|
+
}
|
|
22
|
+
export declare type TSearchModalRes<T> = undefined | {
|
|
23
|
+
foundItem: T;
|
|
24
|
+
searchText: string;
|
|
25
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import { StyledComponent } from 'styled-components';
|
|
3
3
|
export declare const ValueReadonly: StyledComponent<"div", any, {}, never>;
|
|
4
|
-
export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, placeholder, className, singleLine, noGrow, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo, }: {
|
|
4
|
+
export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, placeholder, className, singleLine, noGrow, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo, onEscape, }: {
|
|
5
5
|
/**
|
|
6
6
|
* forces single row input style. will also enable 'Enter' to auto submit
|
|
7
7
|
*/
|
|
@@ -42,4 +42,8 @@ export declare const TextEdit: ({ defaultValue, defaultEditing, disableEdit, pla
|
|
|
42
42
|
* if true, will add undo button after changes. if false, will submit after every keypress. default true
|
|
43
43
|
*/
|
|
44
44
|
allowUndo?: boolean | undefined;
|
|
45
|
+
/**
|
|
46
|
+
* will call on user pressed escape
|
|
47
|
+
*/
|
|
48
|
+
onEscape?: (() => void) | undefined;
|
|
45
49
|
}) => JSX.Element;
|
|
@@ -73,7 +73,7 @@ const Icon = styled_components_1.default.div `
|
|
|
73
73
|
filter: saturate(3);
|
|
74
74
|
}
|
|
75
75
|
`;
|
|
76
|
-
const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, placeholder, className, singleLine = false, noGrow = false, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo = true, }) => {
|
|
76
|
+
const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, placeholder, className, singleLine = false, noGrow = false, attributes, leftContent, onSubmit, onEditingChange, onClickOutsideWithNoValue, onClickNotEditing, allowUndo = true, onEscape, }) => {
|
|
77
77
|
const ref = (0, react_1.useRef)(null);
|
|
78
78
|
const taref = (0, react_1.useRef)(null);
|
|
79
79
|
const [value, setValue] = (0, react_1.useState)(defaultValue);
|
|
@@ -134,10 +134,14 @@ const TextEdit = ({ defaultValue = '', defaultEditing, disableEdit = false, plac
|
|
|
134
134
|
if (!allowUndo) {
|
|
135
135
|
onSubmit(v.currentTarget.value, false);
|
|
136
136
|
}
|
|
137
|
-
}, placeholder: placeholder, rows: singleLine ? 1 : undefined, onKeyDown: (e) =>
|
|
138
|
-
e.code.endsWith('Enter')
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
}, placeholder: placeholder, rows: singleLine ? 1 : undefined, onKeyDown: (e) => {
|
|
138
|
+
if (singleLine && e.code.endsWith('Enter')) {
|
|
139
|
+
onSubmit(value, true);
|
|
140
|
+
}
|
|
141
|
+
if (onEscape && e.code.endsWith('Escape')) {
|
|
142
|
+
onEscape();
|
|
143
|
+
}
|
|
144
|
+
} }),
|
|
141
145
|
allowUndo && (react_1.default.createElement(Right, null,
|
|
142
146
|
valueChange && (react_1.default.createElement(Icon, { style: common_1.iconLeft, onClick: () => valueChange && onSubmit(value, false) },
|
|
143
147
|
react_1.default.createElement(images_1.SaveIcon, null))),
|
|
@@ -3,4 +3,13 @@ export interface IScroll {
|
|
|
3
3
|
x: number;
|
|
4
4
|
scrolled: boolean;
|
|
5
5
|
}
|
|
6
|
-
export declare function useOnScroll(
|
|
6
|
+
export declare function useOnScroll({ onScroll, element, }?: {
|
|
7
|
+
/**
|
|
8
|
+
* defaults to window
|
|
9
|
+
*/
|
|
10
|
+
element?: Element;
|
|
11
|
+
/**
|
|
12
|
+
* if provided will call on move
|
|
13
|
+
*/
|
|
14
|
+
onScroll?: (e: Event, st: IScroll) => void;
|
|
15
|
+
}): IScroll;
|
|
@@ -14,20 +14,24 @@ function debounce(callback, time, ...args) {
|
|
|
14
14
|
}, time);
|
|
15
15
|
};
|
|
16
16
|
}
|
|
17
|
-
function useOnScroll() {
|
|
17
|
+
function useOnScroll({ onScroll, element, } = {}) {
|
|
18
18
|
const [state, setState] = (0, react_1.useState)({ scrolled: false, x: 0, y: 0 });
|
|
19
19
|
(0, react_1.useEffect)(() => {
|
|
20
|
-
const listener = () => {
|
|
21
|
-
|
|
22
|
-
const
|
|
20
|
+
const listener = (e) => {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const y = (_a = element === null || element === void 0 ? void 0 : element.scrollTop) !== null && _a !== void 0 ? _a : window.scrollY;
|
|
23
|
+
const x = (_b = element === null || element === void 0 ? void 0 : element.scrollLeft) !== null && _b !== void 0 ? _b : window.scrollX;
|
|
23
24
|
const r = { y, x, scrolled: !!y || !!x };
|
|
24
25
|
setState(r);
|
|
26
|
+
onScroll === null || onScroll === void 0 ? void 0 : onScroll(e, r);
|
|
25
27
|
};
|
|
26
|
-
document.addEventListener(`scroll`, debounce(listener, 10)
|
|
28
|
+
document.addEventListener(`scroll`, (e) => debounce(() => listener(e), 10), {
|
|
29
|
+
passive: true,
|
|
30
|
+
});
|
|
27
31
|
return () => {
|
|
28
32
|
document.removeEventListener(`scroll`, listener);
|
|
29
33
|
};
|
|
30
|
-
}, []);
|
|
34
|
+
}, [element, onScroll]);
|
|
31
35
|
return state;
|
|
32
36
|
}
|
|
33
37
|
exports.useOnScroll = useOnScroll;
|