@adamjanicki/ui-extended 1.1.3 → 1.1.4
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.d.ts +2 -2
- package/components/Autocomplete.js +12 -15
- package/components/Popover.js +4 -3
- package/components/Tooltip.d.ts +3 -3
- package/components/Tooltip.js +4 -3
- package/package.json +4 -3
- package/style.css +21 -21
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import Popover from "./Popover";
|
|
3
3
|
import { IconInput } from "@adamjanicki/ui";
|
|
4
|
-
|
|
4
|
+
type Props<T> = {
|
|
5
5
|
/**
|
|
6
6
|
* The value of the input field
|
|
7
7
|
*/
|
|
@@ -94,6 +94,6 @@ interface Props<T> {
|
|
|
94
94
|
* @default false
|
|
95
95
|
*/
|
|
96
96
|
remainOpenOnSelectOrEnter?: boolean;
|
|
97
|
-
}
|
|
97
|
+
};
|
|
98
98
|
declare const Autocomplete: <T>(props: Props<T>) => import("react/jsx-runtime").JSX.Element;
|
|
99
99
|
export default Autocomplete;
|
|
@@ -20,13 +20,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
}
|
|
21
21
|
return t;
|
|
22
22
|
};
|
|
23
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
23
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
24
24
|
import React from "react";
|
|
25
25
|
import Popover from "./Popover";
|
|
26
|
-
import ClickOutside from "@adamjanicki/ui
|
|
27
|
-
import { IconInput } from "@adamjanicki/ui";
|
|
26
|
+
import { Box, ClickOutside, IconInput } from "@adamjanicki/ui";
|
|
28
27
|
import { classNames } from "@adamjanicki/ui/functions";
|
|
29
|
-
var defaultRenderOption = function (option) { return (_jsx(
|
|
28
|
+
var defaultRenderOption = function (option) { return (_jsx(Box, { className: "aui-pa-m", children: "".concat(option) })); };
|
|
30
29
|
var Autocomplete = function (props) {
|
|
31
30
|
var _a, _b;
|
|
32
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"]);
|
|
@@ -66,12 +65,7 @@ var Autocomplete = function (props) {
|
|
|
66
65
|
if (!remainOpenOnSelectOrEnter)
|
|
67
66
|
closeMenu();
|
|
68
67
|
};
|
|
69
|
-
var closeMenu = function () {
|
|
70
|
-
var _a;
|
|
71
|
-
setOn(undefined);
|
|
72
|
-
setOpen(false);
|
|
73
|
-
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
74
|
-
};
|
|
68
|
+
var closeMenu = function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur(); };
|
|
75
69
|
var openMenu = function () { return setOpen(true); };
|
|
76
70
|
var handleKeys = function (_a) {
|
|
77
71
|
var _b;
|
|
@@ -121,7 +115,7 @@ var Autocomplete = function (props) {
|
|
|
121
115
|
filteredOptions.length;
|
|
122
116
|
var next = ((on !== null && on !== void 0 ? on : -1) + filteredOptions.length + 1) % filteredOptions.length;
|
|
123
117
|
var popoverOpen = open && (filteredOptions.length > 0 || value.length > 0);
|
|
124
|
-
return (_jsx(ClickOutside, { onClickOutside: closeMenu, children: _jsxs(
|
|
118
|
+
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) {
|
|
125
119
|
setOn(undefined);
|
|
126
120
|
onInputChange(e);
|
|
127
121
|
if (e.target.value) {
|
|
@@ -132,11 +126,14 @@ var Autocomplete = function (props) {
|
|
|
132
126
|
else {
|
|
133
127
|
focusInput();
|
|
134
128
|
}
|
|
129
|
+
}, onBlur: function () {
|
|
130
|
+
setOn(undefined);
|
|
131
|
+
setOpen(false);
|
|
135
132
|
}, onClick: function () {
|
|
136
133
|
if (!open) {
|
|
137
134
|
openMenu();
|
|
138
135
|
}
|
|
139
|
-
}, ref: inputRef, autoComplete: "off" }) })), _jsxs(Popover, __assign({}, popoverProps, { open: popoverOpen, triggerRef: inputContainerRef, style: __assign(__assign({ zIndex: 100 }, ((popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.style) || {})), { padding: 0, margin: 0, width: (_b = (_a = inputContainerRef.current) === null || _a === void 0 ? void 0 : _a.offsetWidth) !== null && _b !== void 0 ? _b : 0 }), className: classNames("
|
|
136
|
+
}, ref: inputRef, autoComplete: "off" }) })), _jsxs(Popover, __assign({}, popoverProps, { open: popoverOpen, triggerRef: inputContainerRef, style: __assign(__assign({ zIndex: 100 }, ((popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.style) || {})), { padding: 0, margin: 0, 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-m aui-ma-none", listProps.className), children: filteredOptions.length
|
|
140
137
|
? filteredOptions.map(function (option, index) {
|
|
141
138
|
var group = groupMap.get(index);
|
|
142
139
|
var ref = index === on
|
|
@@ -146,11 +143,11 @@ var Autocomplete = function (props) {
|
|
|
146
143
|
: index === next
|
|
147
144
|
? nextRef
|
|
148
145
|
: undefined;
|
|
149
|
-
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("
|
|
150
|
-
? "
|
|
146
|
+
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
|
|
147
|
+
? "aui-autocomplete-on-option"
|
|
151
148
|
: undefined, listItemProps.className), onClick: function () { return handleChange(option); }, children: renderOption(option) }))] }, index));
|
|
152
149
|
})
|
|
153
150
|
: !freeSolo &&
|
|
154
|
-
(noOptionsNode || defaultRenderOption("No results found")) })), footer && (_jsx(
|
|
151
|
+
(noOptionsNode || defaultRenderOption("No results found")) })), footer && (_jsx(Box, { onClick: closeOnFooterClick ? closeMenu : undefined, children: _jsx(_Fragment, { children: footer }) }))] }))] })) }));
|
|
155
152
|
};
|
|
156
153
|
export default Autocomplete;
|
package/components/Popover.js
CHANGED
|
@@ -9,7 +9,8 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { Box } from "@adamjanicki/ui";
|
|
13
14
|
import { useFloating, autoUpdate, offset, useDismiss, useTransitionStyles, } from "@floating-ui/react";
|
|
14
15
|
var Popover = function (props) {
|
|
15
16
|
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, className = props.className, children = props.children, onClose = props.onClose, _c = props.returnFocusOnEscape, returnFocusOnEscape = _c === void 0 ? false : _c;
|
|
@@ -32,9 +33,9 @@ var Popover = function (props) {
|
|
|
32
33
|
middleware: middleware,
|
|
33
34
|
}), floatingStyles = _d.floatingStyles, context = _d.context, refs = _d.refs;
|
|
34
35
|
var _e = useTransitionStyles(context, {
|
|
35
|
-
duration: { open: 0, close: 250 }, // default
|
|
36
|
+
duration: { open: 0, close: 250 }, // default aui-transition value
|
|
36
37
|
}), isMounted = _e.isMounted, transitionStyles = _e.styles;
|
|
37
38
|
useDismiss(context);
|
|
38
|
-
return isMounted ? (_jsx(
|
|
39
|
+
return isMounted ? (_jsx(Box, { ref: refs.setFloating, style: __assign(__assign(__assign({}, (style || {})), floatingStyles), transitionStyles), className: className, children: _jsx(_Fragment, { children: children }) })) : null;
|
|
39
40
|
};
|
|
40
41
|
export default Popover;
|
package/components/Tooltip.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { type Placement } from "@floating-ui/react";
|
|
3
|
-
type Props = {
|
|
3
|
+
type Props<T extends React.ElementType> = {
|
|
4
4
|
/**
|
|
5
5
|
* Children to render inside the tooltip container.
|
|
6
6
|
*/
|
|
@@ -9,7 +9,7 @@ type Props = {
|
|
|
9
9
|
* The element to attach the tooltip to.
|
|
10
10
|
* **IMPORTANT**: This must be able to hold a ref.
|
|
11
11
|
*/
|
|
12
|
-
children: React.ReactElement
|
|
12
|
+
children: React.ReactElement<React.ComponentPropsWithRef<T>>;
|
|
13
13
|
/**
|
|
14
14
|
* The placement of the popover relative to the trigger element.
|
|
15
15
|
* @default "bottom"
|
|
@@ -38,5 +38,5 @@ type Props = {
|
|
|
38
38
|
*/
|
|
39
39
|
disabled?: boolean;
|
|
40
40
|
};
|
|
41
|
-
declare const Tooltip: (props: Props) => import("react/jsx-runtime").JSX.Element;
|
|
41
|
+
declare const Tooltip: <T extends React.ElementType>(props: Props<T>) => import("react/jsx-runtime").JSX.Element;
|
|
42
42
|
export default Tooltip;
|
package/components/Tooltip.js
CHANGED
|
@@ -9,8 +9,9 @@ var __assign = (this && this.__assign) || function () {
|
|
|
9
9
|
};
|
|
10
10
|
return __assign.apply(this, arguments);
|
|
11
11
|
};
|
|
12
|
-
import {
|
|
12
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { cloneElement, useState } from "react";
|
|
14
|
+
import { Box } from "@adamjanicki/ui";
|
|
14
15
|
import { useFloating, useHover, useInteractions, flip, safePolygon, autoUpdate, offset, useTransitionStyles, } from "@floating-ui/react";
|
|
15
16
|
var Tooltip = function (props) {
|
|
16
17
|
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, className = props.className, _c = props.disableFlip, disableFlip = _c === void 0 ? false : _c, _d = props.disabled, disabled = _d === void 0 ? false : _d;
|
|
@@ -31,11 +32,11 @@ var Tooltip = function (props) {
|
|
|
31
32
|
mouseOnly: true,
|
|
32
33
|
});
|
|
33
34
|
var _g = useTransitionStyles(context, {
|
|
34
|
-
duration: 250, // default
|
|
35
|
+
duration: 250, // default aui-transition value
|
|
35
36
|
}), isMounted = _g.isMounted, transitionStyles = _g.styles;
|
|
36
37
|
var _h = useInteractions([hover]), getReferenceProps = _h.getReferenceProps, getFloatingProps = _h.getFloatingProps;
|
|
37
38
|
if (disabled)
|
|
38
39
|
return children;
|
|
39
|
-
return (_jsxs(_Fragment, { children: [cloneElement(children, __assign({ ref: refs.setReference }, getReferenceProps())), isMounted && (_jsx(
|
|
40
|
+
return (_jsxs(_Fragment, { children: [cloneElement(children, __assign({ ref: refs.setReference }, getReferenceProps())), isMounted && (_jsx(Box, __assign({ ref: refs.setFloating, style: __assign(__assign(__assign({}, style), floatingStyles), transitionStyles) }, getFloatingProps(), { className: className, children: _jsx(_Fragment, { children: content }) })))] }));
|
|
40
41
|
};
|
|
41
42
|
export default Tooltip;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamjanicki/ui-extended",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4",
|
|
4
4
|
"description": "More advanced UI components and hooks for React in TypeScript",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -14,14 +14,15 @@
|
|
|
14
14
|
"clean": "./clean.sh",
|
|
15
15
|
"lint": "eslint src --max-warnings=0",
|
|
16
16
|
"build": "npm run clean && npm run lint && tsc; cp src/style.css ./style.css",
|
|
17
|
-
"prepare": "npm run build"
|
|
17
|
+
"prepare": "npm run build",
|
|
18
|
+
"dryrun": "npm publish --dry-run"
|
|
18
19
|
},
|
|
19
20
|
"peerDependencies": {
|
|
20
21
|
"react": ">=18",
|
|
21
22
|
"react-dom": ">=18"
|
|
22
23
|
},
|
|
23
24
|
"dependencies": {
|
|
24
|
-
"@adamjanicki/ui": "^1.5.
|
|
25
|
+
"@adamjanicki/ui": "^1.5.8",
|
|
25
26
|
"@floating-ui/react": "^0.26.17"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
package/style.css
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
|
+
:root {
|
|
2
|
+
--aui-autocomplete-popover-box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
|
|
3
|
+
--aui-autocomplete-highlighted: #eee;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
[data-theme="dark"] {
|
|
7
|
+
--aui-autocomplete-highlighted: var(--aui-darkest-gray);
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
@media (hover: hover) {
|
|
2
|
-
.
|
|
3
|
-
.
|
|
4
|
-
background-color:
|
|
5
|
-
}
|
|
6
|
-
[data-theme="dark"] .ajui-autocomplete-on-option,
|
|
7
|
-
[data-theme="dark"] .ajui-autocomplete-option:hover {
|
|
8
|
-
background-color: var(--ajui-darkest-gray);
|
|
11
|
+
.aui-autocomplete-on-option,
|
|
12
|
+
.aui-autocomplete-option:hover {
|
|
13
|
+
background-color: var(--aui-autocomplete-highlighted);
|
|
9
14
|
}
|
|
10
15
|
}
|
|
11
16
|
|
|
12
|
-
.
|
|
13
|
-
background-color: var(--
|
|
14
|
-
font-size: 1rem;
|
|
17
|
+
.aui-autocomplete-popover {
|
|
18
|
+
background-color: var(--aui-default-background);
|
|
15
19
|
font-weight: 400;
|
|
16
|
-
|
|
20
|
+
box-shadow: 0 0 0 1px var(--aui-default-border) inset,
|
|
21
|
+
var(--aui-container-box-shadow);
|
|
17
22
|
overflow: hidden;
|
|
18
|
-
border-radius: var(--
|
|
23
|
+
border-radius: var(--aui-rounded-radius);
|
|
19
24
|
}
|
|
20
25
|
|
|
21
|
-
.
|
|
26
|
+
.aui-autocomplete-ul {
|
|
22
27
|
overflow: scroll;
|
|
23
28
|
max-height: 300px;
|
|
24
29
|
display: flex;
|
|
25
30
|
flex-direction: column;
|
|
26
|
-
|
|
27
|
-
margin: 0;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
.ajui-autocomplete-default-rendering {
|
|
31
|
-
padding: 0.5rem 1rem;
|
|
31
|
+
outline: none;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
.
|
|
34
|
+
.aui-autocomplete-li {
|
|
35
35
|
display: flex;
|
|
36
36
|
cursor: pointer;
|
|
37
|
-
border-radius: var(--
|
|
37
|
+
border-radius: var(--aui-rounded-radius);
|
|
38
38
|
}
|