@adamjanicki/ui-extended 1.1.7 → 1.1.8
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/components/Autocomplete.js +19 -34
- package/components/Popover.d.ts +4 -14
- package/components/Popover.js +20 -4
- package/components/Tooltip.d.ts +5 -11
- package/components/Tooltip.js +20 -4
- package/index.d.ts +3 -2
- package/index.js +3 -2
- package/package.json +2 -2
- package/style.css +10 -5
|
@@ -25,15 +25,13 @@ import React from "react";
|
|
|
25
25
|
import Popover from "./Popover";
|
|
26
26
|
import { Box, ClickOutside, IconInput } from "@adamjanicki/ui";
|
|
27
27
|
import { classNames } from "@adamjanicki/ui/functions";
|
|
28
|
-
var defaultRenderOption = function (option) { return (_jsx(Box, {
|
|
28
|
+
var defaultRenderOption = function (option) { return (_jsx(Box, { layout: { padding: "s" }, children: "".concat(option) })); };
|
|
29
29
|
var Autocomplete = function (props) {
|
|
30
30
|
var _a, _b;
|
|
31
31
|
var options = props.options, _c = props.renderOption, renderOption = _c === void 0 ? defaultRenderOption : _c, _d = props.filterOption, filterOption = _d === void 0 ? function () { return true; } : _d, groupBy = props.groupBy, renderGroup = props.renderGroup, noOptionsNode = props.noOptionsNode, _e = props.InputProps, InputProps = _e === void 0 ? {} : _e, _f = props.freeSolo, freeSolo = _f === void 0 ? false : _f, value = props.value, onInputChange = props.onInputChange, onSelect = props.onSelect, popoverProps = props.popoverProps, footer = props.footer, _g = props.listItemProps, listItemProps = _g === void 0 ? {} : _g, _h = props.listProps, listProps = _h === void 0 ? {} : _h, onUnselectedEnter = props.onUnselectedEnter, _j = props.closeOnFooterClick, closeOnFooterClick = _j === void 0 ? true : _j, _k = props.remainOpenOnSelectOrEnter, remainOpenOnSelectOrEnter = _k === void 0 ? false : _k, rest = __rest(props, ["options", "renderOption", "filterOption", "groupBy", "renderGroup", "noOptionsNode", "InputProps", "freeSolo", "value", "onInputChange", "onSelect", "popoverProps", "footer", "listItemProps", "listProps", "onUnselectedEnter", "closeOnFooterClick", "remainOpenOnSelectOrEnter"]);
|
|
32
32
|
var inputContainerRef = React.useRef(null);
|
|
33
33
|
var inputRef = React.useRef(null);
|
|
34
34
|
var onRef = React.useRef(null);
|
|
35
|
-
var nextRef = React.useRef(null);
|
|
36
|
-
var prevRef = React.useRef(null);
|
|
37
35
|
var _l = React.useState(), on = _l[0], setOn = _l[1];
|
|
38
36
|
var _m = React.useState(false), open = _m[0], setOpen = _m[1];
|
|
39
37
|
var filteredOptions = options.filter(filterOption);
|
|
@@ -79,9 +77,12 @@ var Autocomplete = function (props) {
|
|
|
79
77
|
closeMenu();
|
|
80
78
|
}
|
|
81
79
|
var modulo = filteredOptions.length;
|
|
80
|
+
if (modulo <= 0) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
82
83
|
if (code === "Enter") {
|
|
83
84
|
var current = onRef.current;
|
|
84
|
-
if (
|
|
85
|
+
if (current) {
|
|
85
86
|
// Horrible heuristic to handle links
|
|
86
87
|
// It's terrible, but efficient
|
|
87
88
|
var child = current.firstChild;
|
|
@@ -95,30 +96,20 @@ var Autocomplete = function (props) {
|
|
|
95
96
|
closeMenu();
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
setOn(newOn);
|
|
101
|
-
if (nextRef.current) {
|
|
102
|
-
nextRef.current.scrollIntoView({
|
|
103
|
-
block: "nearest",
|
|
104
|
-
behavior: "smooth",
|
|
105
|
-
});
|
|
106
|
-
}
|
|
99
|
+
if (code === "ArrowDown") {
|
|
100
|
+
setOn(function (on) { return ((on !== null && on !== void 0 ? on : -1) + 1) % modulo; });
|
|
107
101
|
}
|
|
108
|
-
else if (
|
|
109
|
-
|
|
110
|
-
setOn(newOn);
|
|
111
|
-
if (prevRef.current) {
|
|
112
|
-
prevRef.current.scrollIntoView({
|
|
113
|
-
block: "nearest",
|
|
114
|
-
behavior: "smooth",
|
|
115
|
-
});
|
|
116
|
-
}
|
|
102
|
+
else if (code === "ArrowUp") {
|
|
103
|
+
setOn(function (on) { return ((on !== null && on !== void 0 ? on : 0) - 1 + modulo) % modulo; });
|
|
117
104
|
}
|
|
118
105
|
};
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
106
|
+
React.useEffect(function () {
|
|
107
|
+
var _a;
|
|
108
|
+
(_a = onRef.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView({
|
|
109
|
+
block: "nearest",
|
|
110
|
+
behavior: "smooth",
|
|
111
|
+
});
|
|
112
|
+
}, [on]);
|
|
122
113
|
var popoverOpen = open && (filteredOptions.length > 0 || value.length > 0);
|
|
123
114
|
return (_jsx(ClickOutside, { onClickOutside: closeMenu, children: _jsxs(Box, __assign({}, rest, { onKeyUp: function (e) { return handleKeys(e); }, children: [_jsx(IconInput, __assign({}, InputProps, { ref: inputContainerRef, inputProps: __assign(__assign({}, (InputProps.inputProps || {})), { value: value, onChange: function (e) {
|
|
124
115
|
setOn(undefined);
|
|
@@ -135,21 +126,15 @@ var Autocomplete = function (props) {
|
|
|
135
126
|
if (!open) {
|
|
136
127
|
openMenu();
|
|
137
128
|
}
|
|
138
|
-
}, ref: inputRef, autoComplete: "off" }) })), _jsxs(Popover, __assign({}, popoverProps, { open: popoverOpen, triggerRef: inputContainerRef,
|
|
129
|
+
}, ref: inputRef, autoComplete: "off" }) })), _jsxs(Popover, __assign({}, popoverProps, { open: popoverOpen, triggerRef: inputContainerRef, layout: { padding: "none", margin: "none" }, style: __assign(__assign({}, popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.style), { width: (_b = (_a = inputContainerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) !== null && _b !== void 0 ? _b : 0 }), className: classNames("aui-autocomplete-popover", popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.className), children: [_jsx("ul", __assign({}, listProps, { className: classNames("aui-autocomplete-ul aui-pa-s aui-ma-none", listProps.className), children: filteredOptions.length
|
|
139
130
|
? filteredOptions.map(function (option, index) {
|
|
140
131
|
var group = groupMap.get(index);
|
|
141
|
-
var ref = index === on
|
|
142
|
-
? onRef
|
|
143
|
-
: index === prev
|
|
144
|
-
? prevRef
|
|
145
|
-
: index === next
|
|
146
|
-
? nextRef
|
|
147
|
-
: undefined;
|
|
132
|
+
var ref = index === on ? onRef : undefined;
|
|
148
133
|
return (_jsxs(React.Fragment, { children: [group && ((renderGroup === null || renderGroup === void 0 ? void 0 : renderGroup(group)) || group), _jsx("li", __assign({}, listItemProps, { ref: ref, onMouseEnter: function () { return setOn(index); }, className: classNames("aui-autocomplete-li", on === index
|
|
149
134
|
? "aui-autocomplete-on-option"
|
|
150
135
|
: undefined, listItemProps.className), onClick: function () { return handleChange(option); }, children: renderOption(option) }))] }, index));
|
|
151
136
|
})
|
|
152
137
|
: !freeSolo &&
|
|
153
|
-
(noOptionsNode || defaultRenderOption("No results found")) })), footer && (_jsx(Box, { onClick: closeOnFooterClick ? closeMenu : undefined, children: _jsx(_Fragment, { children: footer }) }))] }))] })) }));
|
|
138
|
+
(noOptionsNode || defaultRenderOption("No results found")) })), !!footer && (_jsx(Box, { onClick: closeOnFooterClick ? closeMenu : undefined, children: _jsx(_Fragment, { children: footer }) }))] }))] })) }));
|
|
154
139
|
};
|
|
155
140
|
export default Autocomplete;
|
package/components/Popover.d.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { BoxProps } from "@adamjanicki/ui/components/Box/Box";
|
|
2
3
|
import { type Placement } from "@floating-ui/react";
|
|
3
|
-
type Props = {
|
|
4
|
-
/**
|
|
5
|
-
* Children to render inside the popover.
|
|
6
|
-
*/
|
|
7
|
-
children: React.ReactNode | React.ReactNode[];
|
|
4
|
+
type Props = BoxProps & {
|
|
8
5
|
/**
|
|
9
6
|
* The trigger ref for the element to position the popover over.
|
|
10
7
|
*/
|
|
@@ -18,14 +15,6 @@ type Props = {
|
|
|
18
15
|
* @default "bottom"
|
|
19
16
|
*/
|
|
20
17
|
placement?: Placement;
|
|
21
|
-
/**
|
|
22
|
-
* Additional styles to apply to the popover container.
|
|
23
|
-
*/
|
|
24
|
-
style?: React.CSSProperties;
|
|
25
|
-
/**
|
|
26
|
-
* Additional classes to apply to the popover container.
|
|
27
|
-
*/
|
|
28
|
-
className?: string;
|
|
29
18
|
/**
|
|
30
19
|
* The offset of the popover relative to the trigger element.
|
|
31
20
|
* @default 0
|
|
@@ -42,5 +31,6 @@ type Props = {
|
|
|
42
31
|
*/
|
|
43
32
|
returnFocusOnEscape?: boolean;
|
|
44
33
|
};
|
|
45
|
-
declare const
|
|
34
|
+
export declare const UnstyledPopover: (props: Props) => import("react/jsx-runtime").JSX.Element | null;
|
|
35
|
+
declare const Popover: ({ className, layout, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
46
36
|
export default Popover;
|
package/components/Popover.js
CHANGED
|
@@ -9,11 +9,23 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
12
23
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
-
import
|
|
24
|
+
import Box from "@adamjanicki/ui/components/Box/Box";
|
|
14
25
|
import { useFloating, autoUpdate, offset, useDismiss, useTransitionStyles, } from "@floating-ui/react";
|
|
15
|
-
|
|
16
|
-
|
|
26
|
+
import { classNames } from "@adamjanicki/ui";
|
|
27
|
+
export var UnstyledPopover = function (props) {
|
|
28
|
+
var triggerRef = props.triggerRef, open = props.open, _a = props.placement, placement = _a === void 0 ? "bottom" : _a, style = props.style, _b = props.offset, placementOffset = _b === void 0 ? 0 : _b, children = props.children, onClose = props.onClose, _c = props.returnFocusOnEscape, returnFocusOnEscape = _c === void 0 ? false : _c, rest = __rest(props, ["triggerRef", "open", "placement", "style", "offset", "children", "onClose", "returnFocusOnEscape"]);
|
|
17
29
|
var handleOnClose = function () {
|
|
18
30
|
var _a, _b;
|
|
19
31
|
if (!returnFocusOnEscape)
|
|
@@ -36,6 +48,10 @@ var Popover = function (props) {
|
|
|
36
48
|
duration: { open: 0, close: 250 }, // default aui-transition value
|
|
37
49
|
}), isMounted = _e.isMounted, transitionStyles = _e.styles;
|
|
38
50
|
useDismiss(context);
|
|
39
|
-
return isMounted ? (_jsx(Box, { ref: refs.setFloating, style: __assign(__assign(__assign({},
|
|
51
|
+
return isMounted ? (_jsx(Box, __assign({ ref: refs.setFloating, style: __assign(__assign(__assign({}, floatingStyles), transitionStyles), style) }, rest, { children: _jsx(_Fragment, { children: children }) }))) : null;
|
|
52
|
+
};
|
|
53
|
+
var Popover = function (_a) {
|
|
54
|
+
var className = _a.className, layout = _a.layout, rest = __rest(_a, ["className", "layout"]);
|
|
55
|
+
return (_jsx(UnstyledPopover, __assign({ className: classNames("aui-popover", className), layout: __assign({ padding: "s" }, layout) }, rest)));
|
|
40
56
|
};
|
|
41
57
|
export default Popover;
|
package/components/Tooltip.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { BoxProps } from "@adamjanicki/ui/components/Box/Box";
|
|
2
3
|
import { type Placement } from "@floating-ui/react";
|
|
3
|
-
type Props<
|
|
4
|
+
type Props = Omit<BoxProps, "children" | "onMouseEnter" | "onMouseLeave"> & {
|
|
4
5
|
/**
|
|
5
6
|
* Children to render inside the tooltip container.
|
|
6
7
|
*/
|
|
@@ -9,20 +10,12 @@ type Props<T extends React.ElementType> = {
|
|
|
9
10
|
* The element to attach the tooltip to.
|
|
10
11
|
* **IMPORTANT**: This must be able to hold a ref.
|
|
11
12
|
*/
|
|
12
|
-
children: React.ReactElement<
|
|
13
|
+
children: React.ReactElement<any>;
|
|
13
14
|
/**
|
|
14
15
|
* The placement of the popover relative to the trigger element.
|
|
15
16
|
* @default "bottom"
|
|
16
17
|
*/
|
|
17
18
|
placement?: Placement;
|
|
18
|
-
/**
|
|
19
|
-
* Additional styles to apply to the tooltip container.
|
|
20
|
-
*/
|
|
21
|
-
style?: React.CSSProperties;
|
|
22
|
-
/**
|
|
23
|
-
* Additional classes to apply to the tooltip container.
|
|
24
|
-
*/
|
|
25
|
-
className?: string;
|
|
26
19
|
/**
|
|
27
20
|
* The offset of the popover relative to the trigger element.
|
|
28
21
|
* @default 0
|
|
@@ -38,5 +31,6 @@ type Props<T extends React.ElementType> = {
|
|
|
38
31
|
*/
|
|
39
32
|
disabled?: boolean;
|
|
40
33
|
};
|
|
41
|
-
declare const
|
|
34
|
+
export declare const UnstyledTooltip: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
35
|
+
export declare const Tooltip: ({ className, layout, ...rest }: Props) => import("react/jsx-runtime").JSX.Element;
|
|
42
36
|
export default Tooltip;
|
package/components/Tooltip.js
CHANGED
|
@@ -9,12 +9,24 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
+
var t = {};
|
|
14
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
+
t[p] = s[p];
|
|
16
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
+
t[p[i]] = s[p[i]];
|
|
20
|
+
}
|
|
21
|
+
return t;
|
|
22
|
+
};
|
|
12
23
|
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
24
|
import { cloneElement, useState } from "react";
|
|
14
|
-
import
|
|
25
|
+
import Box from "@adamjanicki/ui/components/Box/Box";
|
|
15
26
|
import { useFloating, useHover, useInteractions, flip, safePolygon, autoUpdate, offset, useTransitionStyles, } from "@floating-ui/react";
|
|
16
|
-
|
|
17
|
-
|
|
27
|
+
import { classNames } from "@adamjanicki/ui";
|
|
28
|
+
export var UnstyledTooltip = function (props) {
|
|
29
|
+
var children = props.children, content = props.tooltipContent, _a = props.placement, placement = _a === void 0 ? "bottom" : _a, style = props.style, _b = props.offset, placementOffset = _b === void 0 ? 0 : _b, _c = props.disableFlip, disableFlip = _c === void 0 ? false : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d, rest = __rest(props, ["children", "tooltipContent", "placement", "style", "offset", "disableFlip", "disabled"]);
|
|
18
30
|
var _e = useState(false), open = _e[0], setOpen = _e[1];
|
|
19
31
|
var middleware = [offset(placementOffset)];
|
|
20
32
|
if (!disableFlip) {
|
|
@@ -38,6 +50,10 @@ var Tooltip = function (props) {
|
|
|
38
50
|
if (disabled)
|
|
39
51
|
return children;
|
|
40
52
|
var _j = getFloatingProps(), onMouseEnter = _j.onMouseEnter, onMouseLeave = _j.onMouseLeave;
|
|
41
|
-
return (_jsxs(_Fragment, { children: [cloneElement(children, __assign({ ref: refs.setReference }, getReferenceProps())), isMounted && (_jsx(Box, __assign({ ref: refs.setFloating, style: __assign(__assign(__assign({},
|
|
53
|
+
return (_jsxs(_Fragment, { children: [cloneElement(children, __assign({ ref: refs.setReference }, getReferenceProps())), isMounted && (_jsx(Box, __assign({ ref: refs.setFloating, style: __assign(__assign(__assign({}, floatingStyles), transitionStyles), style) }, { onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, rest, { children: _jsx(_Fragment, { children: content }) })))] }));
|
|
54
|
+
};
|
|
55
|
+
export var Tooltip = function (_a) {
|
|
56
|
+
var className = _a.className, layout = _a.layout, rest = __rest(_a, ["className", "layout"]);
|
|
57
|
+
return (_jsx(UnstyledTooltip, __assign({ className: classNames("aui-tooltip", className), layout: __assign({ padding: "s" }, layout) }, rest)));
|
|
42
58
|
};
|
|
43
59
|
export default Tooltip;
|
package/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import Tooltip, { UnstyledTooltip } from "./components/Tooltip";
|
|
2
|
+
import Popover, { UnstyledPopover } from "./components/Popover";
|
|
3
|
+
export { Tooltip, UnstyledTooltip, Popover, UnstyledPopover };
|
|
3
4
|
export { default as Autocomplete } from "./components/Autocomplete";
|
package/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Components
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import Tooltip, { UnstyledTooltip } from "./components/Tooltip";
|
|
3
|
+
import Popover, { UnstyledPopover } from "./components/Popover";
|
|
4
|
+
export { Tooltip, UnstyledTooltip, Popover, UnstyledPopover };
|
|
4
5
|
export { default as Autocomplete } from "./components/Autocomplete";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamjanicki/ui-extended",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.8",
|
|
4
4
|
"description": "More advanced UI components and hooks for React in TypeScript",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"react-dom": ">=18"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@adamjanicki/ui": "^1.6.
|
|
25
|
+
"@adamjanicki/ui": "^1.6.3",
|
|
26
26
|
"@floating-ui/react": "^0.26.17"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
package/style.css
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
:root {
|
|
2
|
-
--aui-autocomplete-popover-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
3
2
|
--aui-autocomplete-highlighted: #eee;
|
|
4
3
|
}
|
|
5
4
|
|
|
@@ -15,12 +14,9 @@
|
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
.aui-autocomplete-popover {
|
|
18
|
-
background-color: var(--aui-default-background);
|
|
19
17
|
font-weight: 400;
|
|
20
|
-
box-shadow: 0 0 0 1px var(--aui-default-border) inset,
|
|
21
|
-
var(--aui-container-box-shadow);
|
|
22
18
|
overflow: hidden;
|
|
23
|
-
|
|
19
|
+
padding: 0;
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
.aui-autocomplete-ul {
|
|
@@ -36,3 +32,12 @@
|
|
|
36
32
|
cursor: pointer;
|
|
37
33
|
border-radius: var(--aui-rounded-radius);
|
|
38
34
|
}
|
|
35
|
+
|
|
36
|
+
.aui-tooltip,
|
|
37
|
+
.aui-popover {
|
|
38
|
+
background-color: var(--aui-default-background);
|
|
39
|
+
border: 1px solid var(--aui-default-border);
|
|
40
|
+
box-shadow: var(--aui-floating-box-shadow);
|
|
41
|
+
border-radius: var(--aui-rounded-radius);
|
|
42
|
+
z-index: 1000;
|
|
43
|
+
}
|