@adamjanicki/ui-extended 1.0.5 → 1.0.7

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.
@@ -84,6 +84,11 @@ interface Props<T> {
84
84
  * Footer node to render at the bottom of the popover
85
85
  */
86
86
  footer?: React.ReactNode;
87
+ /**
88
+ * Close the popover when the footer is clicked
89
+ * @default true
90
+ */
91
+ closeOnFooterClick?: boolean;
87
92
  /**
88
93
  * A callback to be called when the user hits the enter key while no option is selected
89
94
  */
@@ -29,14 +29,14 @@ import { classNames } from "@adamjanicki/ui/utils/util";
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, _g = props.focusOnSelect, focusOnSelect = _g === void 0 ? true : _g, value = props.value, onInputChange = props.onInputChange, onSelect = props.onSelect, popoverProps = props.popoverProps, footer = props.footer, _h = props.listItemProps, listItemProps = _h === void 0 ? {} : _h, _j = props.listProps, listProps = _j === void 0 ? {} : _j, onUnselectedEnter = props.onUnselectedEnter, rest = __rest(props, ["options", "renderOption", "filterOption", "groupBy", "renderGroup", "noOptionsNode", "InputProps", "freeSolo", "focusOnSelect", "value", "onInputChange", "onSelect", "popoverProps", "footer", "listItemProps", "listProps", "onUnselectedEnter"]);
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, _g = props.focusOnSelect, focusOnSelect = _g === void 0 ? true : _g, value = props.value, onInputChange = props.onInputChange, onSelect = props.onSelect, popoverProps = props.popoverProps, footer = props.footer, _h = props.listItemProps, listItemProps = _h === void 0 ? {} : _h, _j = props.listProps, listProps = _j === void 0 ? {} : _j, onUnselectedEnter = props.onUnselectedEnter, _k = props.closeOnFooterClick, closeOnFooterClick = _k === void 0 ? true : _k, rest = __rest(props, ["options", "renderOption", "filterOption", "groupBy", "renderGroup", "noOptionsNode", "InputProps", "freeSolo", "focusOnSelect", "value", "onInputChange", "onSelect", "popoverProps", "footer", "listItemProps", "listProps", "onUnselectedEnter", "closeOnFooterClick"]);
33
33
  var inputContainerRef = React.useRef(null);
34
34
  var inputRef = React.useRef(null);
35
35
  var onRef = React.useRef(null);
36
36
  var nextRef = React.useRef(null);
37
37
  var prevRef = React.useRef(null);
38
- var _k = React.useState(), on = _k[0], setOn = _k[1];
39
- var _l = React.useState(false), open = _l[0], setOpen = _l[1];
38
+ var _l = React.useState(), on = _l[0], setOn = _l[1];
39
+ var _m = React.useState(false), open = _m[0], setOpen = _m[1];
40
40
  var filteredOptions = options.filter(filterOption);
41
41
  var groupMap = new Map();
42
42
  if (groupBy) {
@@ -152,6 +152,6 @@ var Autocomplete = function (props) {
152
152
  : undefined, listItemProps.className), onClick: function () { return handleChange(option); }, children: renderOption(option) }))] }, index));
153
153
  })
154
154
  : !freeSolo &&
155
- (noOptionsNode || defaultRenderOption("No results found")) })), footer] }))] })) }));
155
+ (noOptionsNode || defaultRenderOption("No results found")) })), footer && (_jsx("div", { onClick: closeOnFooterClick ? closeMenu : undefined, children: footer }))] }))] })) }));
156
156
  };
157
157
  export default Autocomplete;
@@ -10,7 +10,7 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
- import { useFloating, autoUpdate, offset, useDismiss, } from "@floating-ui/react";
13
+ import { useFloating, autoUpdate, offset, useDismiss, useTransitionStyles, } from "@floating-ui/react";
14
14
  var Popover = function (props) {
15
15
  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 ? true : _c;
16
16
  var handleOnClose = function () {
@@ -31,9 +31,10 @@ var Popover = function (props) {
31
31
  whileElementsMounted: autoUpdate,
32
32
  middleware: middleware,
33
33
  }), floatingStyles = _d.floatingStyles, context = _d.context, refs = _d.refs;
34
+ var _e = useTransitionStyles(context, {
35
+ duration: { open: 0, close: 250 }, // default ajui-transition value
36
+ }), isMounted = _e.isMounted, transitionStyles = _e.styles;
34
37
  useDismiss(context);
35
- if (!open)
36
- return null;
37
- return (_jsx("div", { ref: refs.setFloating, style: __assign(__assign(__assign({}, (style || {})), floatingStyles), { outline: "none" }), className: className, children: children }));
38
+ return isMounted ? (_jsx("div", { ref: refs.setFloating, style: __assign(__assign(__assign(__assign({}, (style || {})), floatingStyles), transitionStyles), { outline: "none" }), className: className, children: children })) : null;
38
39
  };
39
40
  export default Popover;
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { cloneElement, useState } from "react";
14
- import { useFloating, useHover, useInteractions, flip, safePolygon, autoUpdate, offset, } from "@floating-ui/react";
14
+ import { useFloating, useHover, useInteractions, flip, safePolygon, autoUpdate, offset, useTransitionStyles, } from "@floating-ui/react";
15
15
  var Tooltip = function (props) {
16
16
  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;
17
17
  var _d = useState(false), open = _d[0], setOpen = _d[1];
@@ -27,11 +27,13 @@ var Tooltip = function (props) {
27
27
  placement: placement,
28
28
  }), refs = _e.refs, floatingStyles = _e.floatingStyles, context = _e.context;
29
29
  var hover = useHover(context, {
30
- delay: { open: 200, close: 100 },
31
30
  handleClose: safePolygon(),
32
31
  mouseOnly: true,
33
32
  });
34
- var _f = useInteractions([hover]), getReferenceProps = _f.getReferenceProps, getFloatingProps = _f.getFloatingProps;
35
- return (_jsxs(_Fragment, { children: [cloneElement(children, __assign({ ref: refs.setReference }, getReferenceProps())), open && (_jsx("div", __assign({ ref: refs.setFloating, style: __assign(__assign({}, (style || {})), floatingStyles) }, getFloatingProps(), { className: className, children: content })))] }));
33
+ var _f = useTransitionStyles(context, {
34
+ duration: 250, // default ajui-transition value
35
+ }), isMounted = _f.isMounted, transitionStyles = _f.styles;
36
+ var _g = useInteractions([hover]), getReferenceProps = _g.getReferenceProps, getFloatingProps = _g.getFloatingProps;
37
+ 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 })))] }));
36
38
  };
37
39
  export default Tooltip;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui-extended",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "More advanced UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
package/style.css CHANGED
@@ -23,7 +23,7 @@
23
23
  max-height: 300px;
24
24
  display: flex;
25
25
  flex-direction: column;
26
- padding: 0.25rem;
26
+ padding: 0.5rem;
27
27
  margin: 0;
28
28
  }
29
29
 
package/utils/types.d.ts DELETED
@@ -1,8 +0,0 @@
1
- /**
2
- * The type of corner to display, controlling the border radius property.
3
- */
4
- export type CornerType = "pill" | "rounded" | "sharp";
5
- /**
6
- * The type of message associated with a piece of content.
7
- */
8
- export type ContentType = "success" | "warning" | "error" | "info" | "static";
package/utils/types.js DELETED
@@ -1 +0,0 @@
1
- export {};