@adamjanicki/ui-extended 1.1.2 → 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/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:
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import Popover from "./Popover";
3
3
  import { IconInput } from "@adamjanicki/ui";
4
- interface Props<T> {
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
- }
98
- declare const Autocomplete: <T>(props: Props<T>) => JSX.Element;
97
+ };
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/components/ClickOutside";
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("div", { className: "ajui-autocomplete-default-rendering", children: "".concat(option) })); };
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,18 +115,25 @@ 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("div", __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) {
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) {
128
- !open && openMenu();
122
+ if (!open) {
123
+ openMenu();
124
+ }
129
125
  }
130
126
  else {
131
127
  focusInput();
132
128
  }
129
+ }, onBlur: function () {
130
+ setOn(undefined);
131
+ setOpen(false);
133
132
  }, onClick: function () {
134
- !open && openMenu();
135
- }, 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
133
+ if (!open) {
134
+ openMenu();
135
+ }
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
136
137
  ? filteredOptions.map(function (option, index) {
137
138
  var group = groupMap.get(index);
138
139
  var ref = index === on
@@ -142,11 +143,11 @@ var Autocomplete = function (props) {
142
143
  : index === next
143
144
  ? nextRef
144
145
  : undefined;
145
- 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("ajui-autocomplete-li", on === index
146
- ? "ajui-autocomplete-on-option"
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"
147
148
  : undefined, listItemProps.className), onClick: function () { return handleChange(option); }, children: renderOption(option) }))] }, index));
148
149
  })
149
150
  : !freeSolo &&
150
- (noOptionsNode || defaultRenderOption("No results found")) })), footer && (_jsx("div", { onClick: closeOnFooterClick ? closeMenu : undefined, children: footer }))] }))] })) }));
151
+ (noOptionsNode || defaultRenderOption("No results found")) })), footer && (_jsx(Box, { onClick: closeOnFooterClick ? closeMenu : undefined, children: _jsx(_Fragment, { children: footer }) }))] }))] })) }));
151
152
  };
152
153
  export default Autocomplete;
@@ -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;
@@ -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 ajui-transition value
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("div", { ref: refs.setFloating, style: __assign(__assign(__assign(__assign({}, (style || {})), floatingStyles), transitionStyles), { outline: "none" }), className: className, children: children })) : null;
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;
@@ -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) => JSX.Element;
41
+ declare const Tooltip: <T extends React.ElementType>(props: Props<T>) => import("react/jsx-runtime").JSX.Element;
42
42
  export default Tooltip;
@@ -9,8 +9,9 @@ var __assign = (this && this.__assign) || function () {
9
9
  };
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
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 ajui-transition value
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("div", __assign({ ref: refs.setFloating, style: __assign(__assign(__assign({}, (style || {})), floatingStyles), transitionStyles) }, getFloatingProps(), { className: className, children: content })))] }));
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.2",
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",
@@ -11,34 +11,23 @@
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
- "dev": "nodemon --watch src --ext ts,tsx,css --exec \"npm run build\"",
17
- "lint": "eslint --ext .ts,.tsx src",
18
- "prepare": "npm run lint; npm run build"
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",
18
+ "dryrun": "npm publish --dry-run"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "react": ">=18",
22
22
  "react-dom": ">=18"
23
23
  },
24
24
  "dependencies": {
25
- "@adamjanicki/ui": ">=1.3.6",
26
- "@floating-ui/react": ">=0.26.17"
25
+ "@adamjanicki/ui": "^1.5.8",
26
+ "@floating-ui/react": "^0.26.17"
27
27
  },
28
28
  "devDependencies": {
29
- "@typescript-eslint/eslint-plugin": "^6.11.0",
30
- "@typescript-eslint/parser": "^6.11.0",
31
- "eslint": "^8.53.0",
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
- ]
29
+ "@types/react": "^19.1.9",
30
+ "@types/react-dom": "^19.1.7",
31
+ "typescript": "^5.9.2"
43
32
  }
44
33
  }
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
- .ajui-autocomplete-on-option,
3
- .ajui-autocomplete-option:hover {
4
- background-color: var(--ajui-light-gray);
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
- .ajui-autocomplete-popover {
13
- background-color: var(--ajui-default-background);
14
- font-size: 1rem;
17
+ .aui-autocomplete-popover {
18
+ background-color: var(--aui-default-background);
15
19
  font-weight: 400;
16
- border: 1px solid var(--ajui-default-border);
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(--ajui-rounded-radius);
23
+ border-radius: var(--aui-rounded-radius);
19
24
  }
20
25
 
21
- .ajui-autocomplete-ul {
26
+ .aui-autocomplete-ul {
22
27
  overflow: scroll;
23
28
  max-height: 300px;
24
29
  display: flex;
25
30
  flex-direction: column;
26
- padding: 0.5rem;
27
- margin: 0;
28
- }
29
-
30
- .ajui-autocomplete-default-rendering {
31
- padding: 0.5rem 1rem;
31
+ outline: none;
32
32
  }
33
33
 
34
- .ajui-autocomplete-li {
34
+ .aui-autocomplete-li {
35
35
  display: flex;
36
36
  cursor: pointer;
37
- border-radius: var(--ajui-rounded-radius);
37
+ border-radius: var(--aui-rounded-radius);
38
38
  }