@via-profit/ui-kit 0.1.0-rc.57 → 0.1.0-rc.59
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/Autocomplete/AutocompleteContainer.js +45 -23
- package/ClickOutside/index.d.ts +1 -0
- package/ClickOutside/index.js +4 -3
- package/Menu/MenuContainer.d.ts +4 -0
- package/Menu/MenuContainer.js +1 -0
- package/Surface/SurfaceFooter.d.ts +8 -0
- package/Surface/SurfaceFooter.js +31 -0
- package/Surface/index.d.ts +13 -0
- package/Surface/index.js +7 -3
- package/package.json +1 -1
|
@@ -44,6 +44,7 @@ const Button_1 = __importDefault(require("../Button"));
|
|
|
44
44
|
const Spinner_1 = __importDefault(require("../LoadingIndicator/Spinner"));
|
|
45
45
|
const context_1 = __importStar(require("./context"));
|
|
46
46
|
const IconClear_1 = __importDefault(require("./IconClear"));
|
|
47
|
+
const ClickOutside_1 = require("../ClickOutside");
|
|
47
48
|
const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
48
49
|
const { items, value, multiple, isOpen = false, isLoading = false, clearIfNotSelected = true, anchorPos = 'auto-start-end', requiredAsterisk, startIcon, fullWidth, placeholder, label, error, errorText, inputRef, filterItems, children, onChange, selectedItemToString, onInputChange, getOptionSelected, onRequestOpen = () => undefined, onRequestClose = () => undefined, overrides } = props, nativeInputProps = __rest(props, ["items", "value", "multiple", "isOpen", "isLoading", "clearIfNotSelected", "anchorPos", "requiredAsterisk", "startIcon", "fullWidth", "placeholder", "label", "error", "errorText", "inputRef", "filterItems", "children", "onChange", "selectedItemToString", "onInputChange", "getOptionSelected", "onRequestOpen", "onRequestClose", "overrides"]);
|
|
49
50
|
const menuRef = react_1.default.useRef(null);
|
|
@@ -155,6 +156,27 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
155
156
|
react_1.default.useEffect(() => {
|
|
156
157
|
dispatch((0, context_1.actionSetPartial)({ currentOpen: isOpen, currentLoading: isLoading, filteredItems: items }));
|
|
157
158
|
}, [isOpen, isLoading, items, dispatch]);
|
|
159
|
+
react_1.default.useEffect(() => {
|
|
160
|
+
const mouseDownEvent = (event) => {
|
|
161
|
+
var _a;
|
|
162
|
+
let parentElem = event.target;
|
|
163
|
+
let needToClose = true;
|
|
164
|
+
while (parentElem && 'parentNode' in parentElem) {
|
|
165
|
+
if (parentElem === anchorElement || parentElem === ((_a = menuRef.current) === null || _a === void 0 ? void 0 : _a.getListElement())) {
|
|
166
|
+
needToClose = false;
|
|
167
|
+
break;
|
|
168
|
+
}
|
|
169
|
+
parentElem = parentElem.parentNode;
|
|
170
|
+
}
|
|
171
|
+
if (needToClose) {
|
|
172
|
+
onRequestClose(event);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
window.document.addEventListener(ClickOutside_1.mouseEventMap.onMouseDown, mouseDownEvent);
|
|
176
|
+
return () => {
|
|
177
|
+
window.document.removeEventListener(ClickOutside_1.mouseEventMap.onMouseDown, mouseDownEvent);
|
|
178
|
+
};
|
|
179
|
+
}, [onRequestClose, anchorElement]);
|
|
158
180
|
return (react_1.default.createElement("div", null,
|
|
159
181
|
react_1.default.useMemo(() => (react_1.default.createElement(overridesMap.TextField, Object.assign({ placeholder: placeholder, label: label, error: error, requiredAsterisk: requiredAsterisk, errorText: errorText, fullWidth: fullWidth, startIcon: startIcon, isLoading: currentLoading, endIcon: react_1.default.createElement(Button_1.default, { iconOnly: true, type: "button", onClick: () => (currentLoading ? 'undefined' : clear()) }, currentLoading ? react_1.default.createElement(Spinner_1.default, null) : react_1.default.createElement(IconClear_1.default, null)) }, nativeInputProps, { onKeyDown: event => {
|
|
160
182
|
inputKeydownEvent(event);
|
|
@@ -175,15 +197,6 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
175
197
|
}
|
|
176
198
|
}, value: inputValue, onBlur: event => {
|
|
177
199
|
isFocusedRef.current = false;
|
|
178
|
-
if (clearIfNotSelected) {
|
|
179
|
-
dispatch((0, context_1.actionSetPartial)({
|
|
180
|
-
inputValue: multiple
|
|
181
|
-
? ''
|
|
182
|
-
: value !== null
|
|
183
|
-
? selectedItemToString(value)
|
|
184
|
-
: '',
|
|
185
|
-
}));
|
|
186
|
-
}
|
|
187
200
|
if (typeof nativeInputProps.onBlur === 'function') {
|
|
188
201
|
nativeInputProps.onBlur(event);
|
|
189
202
|
}
|
|
@@ -230,36 +243,45 @@ const Autocomplete = react_1.default.forwardRef((props, ref) => {
|
|
|
230
243
|
anchorElement,
|
|
231
244
|
dispatch,
|
|
232
245
|
inputRef,
|
|
233
|
-
clearIfNotSelected,
|
|
234
|
-
multiple,
|
|
235
246
|
nativeInputProps,
|
|
236
|
-
value,
|
|
237
|
-
selectedItemToString,
|
|
238
247
|
onRequestOpen,
|
|
239
248
|
onInputChange,
|
|
240
249
|
filterItems,
|
|
241
250
|
items,
|
|
242
251
|
]),
|
|
243
|
-
react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, anchorPos: anchorPos, multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen && filteredItems.length > 0, autofocus: false, anchorElement: anchorElement, closeOutsideClick:
|
|
252
|
+
react_1.default.useMemo(() => (react_1.default.createElement(Menu_1.default, { ref: menuRef, anchorPos: anchorPos, multiple: multiple, items: filteredItems, value: currentValue, isOpen: currentOpen && filteredItems.length > 0, autofocus: false, anchorElement: anchorElement, closeOutsideClick: false, getOptionSelected: getOptionSelected, onSelectItem: item => {
|
|
244
253
|
if (typeof onChange === 'function') {
|
|
245
254
|
onChange(item);
|
|
246
255
|
}
|
|
247
256
|
}, closeOnSelect: multiple ? false : true, onRequestClose: evt => {
|
|
257
|
+
if (clearIfNotSelected) {
|
|
258
|
+
dispatch((0, context_1.actionSetPartial)({
|
|
259
|
+
inputValue: multiple
|
|
260
|
+
? ''
|
|
261
|
+
: value !== null
|
|
262
|
+
? selectedItemToString(value)
|
|
263
|
+
: '',
|
|
264
|
+
}));
|
|
265
|
+
}
|
|
248
266
|
if ((evt === null || evt === void 0 ? void 0 : evt.target) !== anchorElement) {
|
|
249
267
|
onRequestClose(evt);
|
|
250
268
|
}
|
|
251
269
|
} }, ({ index, item }, itemProps) => children({ index, item: item, inputValue }, itemProps))), [
|
|
252
|
-
anchorElement,
|
|
253
|
-
currentOpen,
|
|
254
|
-
currentValue,
|
|
255
|
-
filteredItems,
|
|
256
|
-
inputValue,
|
|
257
|
-
multiple,
|
|
258
270
|
anchorPos,
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
271
|
+
multiple,
|
|
272
|
+
filteredItems,
|
|
273
|
+
currentValue,
|
|
274
|
+
currentOpen,
|
|
275
|
+
anchorElement,
|
|
262
276
|
getOptionSelected,
|
|
277
|
+
onChange,
|
|
278
|
+
clearIfNotSelected,
|
|
279
|
+
dispatch,
|
|
280
|
+
value,
|
|
281
|
+
selectedItemToString,
|
|
282
|
+
onRequestClose,
|
|
283
|
+
children,
|
|
284
|
+
inputValue,
|
|
263
285
|
])));
|
|
264
286
|
});
|
|
265
287
|
Autocomplete.displayName = 'Autocomplete';
|
package/ClickOutside/index.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export interface ClickOutsideProps {
|
|
|
17
17
|
readonly mouseEvent?: OutsideMouseEventName | false;
|
|
18
18
|
}
|
|
19
19
|
type OutsideMouseEventName = 'onClick' | 'onMouseDown' | 'onMouseUp';
|
|
20
|
+
export declare const mouseEventMap: Record<OutsideMouseEventName, 'click' | 'mousedown' | 'mouseup'>;
|
|
20
21
|
export type OnOutsideClick = (event?: React.MouseEvent<HTMLElement> | MouseEvent) => void;
|
|
21
22
|
declare const ClickOutside: React.FC<ClickOutsideProps>;
|
|
22
23
|
export default ClickOutside;
|
package/ClickOutside/index.js
CHANGED
|
@@ -3,8 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mouseEventMap = void 0;
|
|
6
7
|
const react_1 = __importDefault(require("react"));
|
|
7
|
-
|
|
8
|
+
exports.mouseEventMap = {
|
|
8
9
|
onClick: 'click',
|
|
9
10
|
onMouseDown: 'mousedown',
|
|
10
11
|
onMouseUp: 'mouseup',
|
|
@@ -28,11 +29,11 @@ const ClickOutside = props => {
|
|
|
28
29
|
}
|
|
29
30
|
};
|
|
30
31
|
if (mouseEvent) {
|
|
31
|
-
window.document.addEventListener(mouseEventMap[mouseEvent], mouseDownEvent);
|
|
32
|
+
window.document.addEventListener(exports.mouseEventMap[mouseEvent], mouseDownEvent);
|
|
32
33
|
}
|
|
33
34
|
return () => {
|
|
34
35
|
if (mouseEvent) {
|
|
35
|
-
window.document.removeEventListener(mouseEventMap[mouseEvent], mouseDownEvent);
|
|
36
|
+
window.document.removeEventListener(exports.mouseEventMap[mouseEvent], mouseDownEvent);
|
|
36
37
|
}
|
|
37
38
|
};
|
|
38
39
|
}, [onOutsideClick, mouseEvent]);
|
package/Menu/MenuContainer.d.ts
CHANGED
|
@@ -185,6 +185,10 @@ export type MenuRef = {
|
|
|
185
185
|
* Select highlighted item in list
|
|
186
186
|
*/
|
|
187
187
|
selectHightlightedItem: () => void;
|
|
188
|
+
/**
|
|
189
|
+
* Returns the list HTML container
|
|
190
|
+
*/
|
|
191
|
+
getListElement: () => HTMLDivElement | null;
|
|
188
192
|
};
|
|
189
193
|
export type Value<T, Multiple> = Multiple extends undefined | undefined ? T | null : readonly T[];
|
|
190
194
|
export type GetOptionSelected<T> = (payload: {
|
package/Menu/MenuContainer.js
CHANGED
|
@@ -188,6 +188,7 @@ const MenuContainer = react_1.default.forwardRef((props, ref) => {
|
|
|
188
188
|
scrollToFirstSelected: () => scrollToFirstSelected(),
|
|
189
189
|
selectHightlightedItem: () => selectHightlightedItem(),
|
|
190
190
|
selectItem: (idx) => selectItem(idx),
|
|
191
|
+
getListElement: () => menuListRef.current,
|
|
191
192
|
}), [
|
|
192
193
|
scrollToIndex,
|
|
193
194
|
highlightIndex,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export type SurfaceFooterProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
3
|
+
readonly noPadding?: boolean;
|
|
4
|
+
};
|
|
5
|
+
declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
|
|
6
|
+
readonly noPadding?: boolean | undefined;
|
|
7
|
+
} & React.RefAttributes<HTMLDivElement>>;
|
|
8
|
+
export default _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
const react_1 = __importDefault(require("react"));
|
|
18
|
+
const styled_1 = __importDefault(require("@emotion/styled"));
|
|
19
|
+
const StyledFooter = styled_1.default.div `
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
justify-content: flex-end;
|
|
23
|
+
padding: 1rem;
|
|
24
|
+
border-bottom-left-radius: inherit;
|
|
25
|
+
border-bottom-right-radius: inherit;
|
|
26
|
+
`;
|
|
27
|
+
const SurfaceFooter = (props, ref) => {
|
|
28
|
+
const { children } = props, nativeProps = __rest(props, ["children"]);
|
|
29
|
+
return (react_1.default.createElement(StyledFooter, Object.assign({}, nativeProps, { ref: ref }), children));
|
|
30
|
+
};
|
|
31
|
+
exports.default = react_1.default.forwardRef(SurfaceFooter);
|
package/Surface/index.d.ts
CHANGED
|
@@ -3,12 +3,17 @@ import { SurfaceContainerProps } from './SurfaceContainer';
|
|
|
3
3
|
import { SurfaceHeaderProps } from './SurfaceHeader';
|
|
4
4
|
import { SurfaceSubheaderProps } from './SurfaceSubheader';
|
|
5
5
|
import { SurfaceContentProps } from './SurfaceContent';
|
|
6
|
+
import { SurfaceFooterProps } from './SurfaceFooter';
|
|
6
7
|
export type SurfaceProps = React.HTMLAttributes<HTMLDivElement> & {
|
|
7
8
|
readonly children: React.ReactNode | React.ReactNode[];
|
|
8
9
|
/**
|
|
9
10
|
* Header content
|
|
10
11
|
*/
|
|
11
12
|
readonly header?: JSX.Element | string;
|
|
13
|
+
/**
|
|
14
|
+
* Footer content
|
|
15
|
+
*/
|
|
16
|
+
readonly footer?: JSX.Element | string;
|
|
12
17
|
/**
|
|
13
18
|
* Subheader content
|
|
14
19
|
*/
|
|
@@ -39,6 +44,10 @@ export interface SurfaceOverrides {
|
|
|
39
44
|
* Surface content component
|
|
40
45
|
*/
|
|
41
46
|
readonly Content?: React.ForwardRefExoticComponent<SurfaceContentProps & React.RefAttributes<HTMLDivElement>>;
|
|
47
|
+
/**
|
|
48
|
+
* Surface footer component
|
|
49
|
+
*/
|
|
50
|
+
readonly Footer?: React.ForwardRefExoticComponent<SurfaceFooterProps & React.RefAttributes<HTMLDivElement>>;
|
|
42
51
|
}
|
|
43
52
|
declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
|
|
44
53
|
readonly children: React.ReactNode | React.ReactNode[];
|
|
@@ -46,6 +55,10 @@ declare const _default: React.ForwardRefExoticComponent<React.HTMLAttributes<HTM
|
|
|
46
55
|
* Header content
|
|
47
56
|
*/
|
|
48
57
|
readonly header?: string | JSX.Element | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Footer content
|
|
60
|
+
*/
|
|
61
|
+
readonly footer?: string | JSX.Element | undefined;
|
|
49
62
|
/**
|
|
50
63
|
* Subheader content
|
|
51
64
|
*/
|
package/Surface/index.js
CHANGED
|
@@ -42,20 +42,24 @@ const SurfaceContainer_1 = __importDefault(require("./SurfaceContainer"));
|
|
|
42
42
|
const SurfaceHeader_1 = __importDefault(require("./SurfaceHeader"));
|
|
43
43
|
const SurfaceSubheader_1 = __importDefault(require("./SurfaceSubheader"));
|
|
44
44
|
const SurfaceContent_1 = __importDefault(require("./SurfaceContent"));
|
|
45
|
+
const SurfaceFooter_1 = __importDefault(require("./SurfaceFooter"));
|
|
45
46
|
const Surface = (props, ref) => {
|
|
46
|
-
const { children, header, subheader, inline, overrides } = props, nativeProps = __rest(props, ["children", "header", "subheader", "inline", "overrides"]);
|
|
47
|
+
const { children, header, subheader, footer, inline, overrides } = props, nativeProps = __rest(props, ["children", "header", "subheader", "footer", "inline", "overrides"]);
|
|
48
|
+
const hasFooter = typeof footer !== 'undefined' && footer !== null;
|
|
47
49
|
const hasHeader = typeof header !== 'undefined' && header !== null;
|
|
48
50
|
const hasSubheader = typeof subheader !== 'undefined' && subheader !== null;
|
|
49
51
|
const overridesMap = React.useMemo(() => (Object.assign({ Container: SurfaceContainer_1.default,
|
|
50
52
|
Header: SurfaceHeader_1.default,
|
|
51
53
|
Subheader: SurfaceSubheader_1.default,
|
|
52
|
-
Content: SurfaceContent_1.default
|
|
54
|
+
Content: SurfaceContent_1.default,
|
|
55
|
+
Footer: SurfaceFooter_1.default }, overrides)), [overrides]);
|
|
53
56
|
if (!hasHeader && hasSubheader) {
|
|
54
57
|
console.warn(`[@via-profit/ui-kit] Surface component. If you use a subheader, then you should add a header`);
|
|
55
58
|
}
|
|
56
59
|
return (React.createElement(overridesMap.Container, Object.assign({}, nativeProps, { inline: inline, ref: ref }),
|
|
57
60
|
hasHeader && React.createElement(overridesMap.Header, null, header),
|
|
58
61
|
hasSubheader && React.createElement(overridesMap.Subheader, null, subheader),
|
|
59
|
-
React.createElement(overridesMap.Content, null, children)
|
|
62
|
+
React.createElement(overridesMap.Content, null, children),
|
|
63
|
+
hasFooter && React.createElement(overridesMap.Footer, null, footer)));
|
|
60
64
|
};
|
|
61
65
|
exports.default = React.forwardRef(Surface);
|