@adamjanicki/ui-extended 1.1.1 → 1.1.3
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/README.md +0 -6
- package/components/Autocomplete.d.ts +6 -5
- package/components/Autocomplete.js +17 -18
- package/components/Popover.d.ts +2 -2
- package/components/Tooltip.d.ts +1 -1
- package/package.json +9 -21
- package/style.css +1 -1
package/README.md
CHANGED
|
@@ -8,12 +8,6 @@
|
|
|
8
8
|
npm install @adamjanicki/ui-extended
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## Usage
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
// Add here
|
|
15
|
-
```
|
|
16
|
-
|
|
17
11
|
## Importing CSS
|
|
18
12
|
|
|
19
13
|
Unfortunately, there was no great way to handle CSS. I often hate how large libraries make it extremely difficult to override CSS without using `!important`, or using inline styles. So, I've decided to just import the CSS directly into your project. Here's an example of how to do it:
|
|
@@ -60,10 +60,6 @@ interface Props<T> {
|
|
|
60
60
|
* Allow free text input
|
|
61
61
|
*/
|
|
62
62
|
freeSolo?: boolean;
|
|
63
|
-
/**
|
|
64
|
-
* Focus on the input field after selecting an option
|
|
65
|
-
*/
|
|
66
|
-
focusOnSelect?: boolean;
|
|
67
63
|
/**
|
|
68
64
|
* Props for the input field
|
|
69
65
|
*/
|
|
@@ -93,6 +89,11 @@ interface Props<T> {
|
|
|
93
89
|
* A callback to be called when the user hits the enter key while no option is selected
|
|
94
90
|
*/
|
|
95
91
|
onUnselectedEnter?: () => void;
|
|
92
|
+
/**
|
|
93
|
+
* Whether or not to leave the popover open after a selection occurs
|
|
94
|
+
* @default false
|
|
95
|
+
*/
|
|
96
|
+
remainOpenOnSelectOrEnter?: boolean;
|
|
96
97
|
}
|
|
97
|
-
declare const Autocomplete: <T>(props: Props<T>) => JSX.Element;
|
|
98
|
+
declare const Autocomplete: <T>(props: Props<T>) => import("react/jsx-runtime").JSX.Element;
|
|
98
99
|
export default Autocomplete;
|
|
@@ -29,7 +29,7 @@ import { classNames } from "@adamjanicki/ui/functions";
|
|
|
29
29
|
var defaultRenderOption = function (option) { return (_jsx("div", { className: "ajui-autocomplete-default-rendering", children: "".concat(option) })); };
|
|
30
30
|
var Autocomplete = function (props) {
|
|
31
31
|
var _a, _b;
|
|
32
|
-
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,
|
|
32
|
+
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"]);
|
|
33
33
|
var inputContainerRef = React.useRef(null);
|
|
34
34
|
var inputRef = React.useRef(null);
|
|
35
35
|
var onRef = React.useRef(null);
|
|
@@ -60,22 +60,21 @@ var Autocomplete = function (props) {
|
|
|
60
60
|
if (freeSolo && value.length > 0 && filteredOptions.length === 0) {
|
|
61
61
|
filteredOptions.push(value);
|
|
62
62
|
}
|
|
63
|
+
var focusInput = function () { var _a; return (_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.focus(); };
|
|
63
64
|
var handleChange = function (v) {
|
|
64
65
|
onSelect(v);
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
if (!focusOnSelect)
|
|
68
|
-
return current === null || current === void 0 ? void 0 : current.focus();
|
|
66
|
+
if (!remainOpenOnSelectOrEnter)
|
|
67
|
+
closeMenu();
|
|
69
68
|
};
|
|
70
69
|
var closeMenu = function () {
|
|
70
|
+
var _a;
|
|
71
71
|
setOn(undefined);
|
|
72
72
|
setOpen(false);
|
|
73
|
+
(_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.blur();
|
|
73
74
|
};
|
|
74
|
-
var openMenu = function () {
|
|
75
|
-
setOpen(true);
|
|
76
|
-
};
|
|
75
|
+
var openMenu = function () { return setOpen(true); };
|
|
77
76
|
var handleKeys = function (_a) {
|
|
78
|
-
var _b
|
|
77
|
+
var _b;
|
|
79
78
|
var code = _a.code;
|
|
80
79
|
if (code === "Escape") {
|
|
81
80
|
closeMenu();
|
|
@@ -90,14 +89,11 @@ var Autocomplete = function (props) {
|
|
|
90
89
|
if (child && child.nodeName === "A")
|
|
91
90
|
(_b = child.click) === null || _b === void 0 ? void 0 : _b.call(child);
|
|
92
91
|
current.click();
|
|
93
|
-
if (!focusOnSelect)
|
|
94
|
-
return (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.blur();
|
|
95
92
|
}
|
|
96
93
|
else if (onUnselectedEnter) {
|
|
97
94
|
onUnselectedEnter();
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
return (_d = inputRef.current) === null || _d === void 0 ? void 0 : _d.blur();
|
|
95
|
+
if (!remainOpenOnSelectOrEnter)
|
|
96
|
+
closeMenu();
|
|
101
97
|
}
|
|
102
98
|
}
|
|
103
99
|
if (modulo > 0 && code === "ArrowDown") {
|
|
@@ -129,14 +125,17 @@ var Autocomplete = function (props) {
|
|
|
129
125
|
setOn(undefined);
|
|
130
126
|
onInputChange(e);
|
|
131
127
|
if (e.target.value) {
|
|
132
|
-
!open
|
|
128
|
+
if (!open) {
|
|
129
|
+
openMenu();
|
|
130
|
+
}
|
|
133
131
|
}
|
|
134
132
|
else {
|
|
135
|
-
|
|
136
|
-
current && current.focus();
|
|
133
|
+
focusInput();
|
|
137
134
|
}
|
|
138
135
|
}, onClick: function () {
|
|
139
|
-
!open
|
|
136
|
+
if (!open) {
|
|
137
|
+
openMenu();
|
|
138
|
+
}
|
|
140
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("ajui-autocomplete-popover", popoverProps === null || popoverProps === void 0 ? void 0 : popoverProps.className), children: [_jsx("ul", __assign({}, listProps, { className: classNames("ajui-autocomplete-ul", listProps.className), children: filteredOptions.length
|
|
141
140
|
? filteredOptions.map(function (option, index) {
|
|
142
141
|
var group = groupMap.get(index);
|
package/components/Popover.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ type Props = {
|
|
|
8
8
|
/**
|
|
9
9
|
* The trigger ref for the element to position the popover over.
|
|
10
10
|
*/
|
|
11
|
-
triggerRef: React.RefObject<HTMLElement>;
|
|
11
|
+
triggerRef: React.RefObject<HTMLElement | null>;
|
|
12
12
|
/**
|
|
13
13
|
* Whether the popover is open.
|
|
14
14
|
*/
|
|
@@ -42,5 +42,5 @@ type Props = {
|
|
|
42
42
|
*/
|
|
43
43
|
returnFocusOnEscape?: boolean;
|
|
44
44
|
};
|
|
45
|
-
declare const Popover: (props: Props) => JSX.Element | null;
|
|
45
|
+
declare const Popover: (props: Props) => import("react/jsx-runtime").JSX.Element | null;
|
|
46
46
|
export default Popover;
|
package/components/Tooltip.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adamjanicki/ui-extended",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3",
|
|
4
4
|
"description": "More advanced UI components and hooks for React in TypeScript",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"types": "./index.d.ts",
|
|
@@ -11,34 +11,22 @@
|
|
|
11
11
|
"url": "git+https://github.com/adamjanicki2/ui-extended.git"
|
|
12
12
|
},
|
|
13
13
|
"scripts": {
|
|
14
|
-
"build": "tsc; cp src/style.css ./style.css",
|
|
15
14
|
"clean": "./clean.sh",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"prepare": "npm run
|
|
15
|
+
"lint": "eslint src --max-warnings=0",
|
|
16
|
+
"build": "npm run clean && npm run lint && tsc; cp src/style.css ./style.css",
|
|
17
|
+
"prepare": "npm run build"
|
|
19
18
|
},
|
|
20
19
|
"peerDependencies": {
|
|
21
20
|
"react": ">=18",
|
|
22
21
|
"react-dom": ">=18"
|
|
23
22
|
},
|
|
24
23
|
"dependencies": {
|
|
25
|
-
"@adamjanicki/ui": "
|
|
26
|
-
"@floating-ui/react": "
|
|
24
|
+
"@adamjanicki/ui": "^1.5.5",
|
|
25
|
+
"@floating-ui/react": "^0.26.17"
|
|
27
26
|
},
|
|
28
27
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"
|
|
32
|
-
"eslint-config-prettier": "^9.0.0",
|
|
33
|
-
"eslint-plugin-react": "^7.33.2",
|
|
34
|
-
"eslint-plugin-react-hooks": "^4.6.0",
|
|
35
|
-
"nodemon": "^3.1.4",
|
|
36
|
-
"typescript": "^5.2.2"
|
|
37
|
-
},
|
|
38
|
-
"eslintConfig": {
|
|
39
|
-
"extends": [
|
|
40
|
-
"react-app",
|
|
41
|
-
"react-app/jest"
|
|
42
|
-
]
|
|
28
|
+
"@types/react": "^19.1.9",
|
|
29
|
+
"@types/react-dom": "^19.1.7",
|
|
30
|
+
"typescript": "^5.9.2"
|
|
43
31
|
}
|
|
44
32
|
}
|
package/style.css
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
@media (hover: hover) {
|
|
2
2
|
.ajui-autocomplete-on-option,
|
|
3
3
|
.ajui-autocomplete-option:hover {
|
|
4
|
-
background-color:
|
|
4
|
+
background-color: #eee;
|
|
5
5
|
}
|
|
6
6
|
[data-theme="dark"] .ajui-autocomplete-on-option,
|
|
7
7
|
[data-theme="dark"] .ajui-autocomplete-option:hover {
|