@adamjanicki/ui-extended 1.0.7 → 1.0.9

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.
@@ -38,6 +38,7 @@ type Props = {
38
38
  /**
39
39
  * Whether to return focus to the trigger element when the popover is closed
40
40
  * by pressing the escape key.
41
+ * @default false
41
42
  */
42
43
  returnFocusOnEscape?: boolean;
43
44
  };
@@ -12,7 +12,7 @@ var __assign = (this && this.__assign) || function () {
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { useFloating, autoUpdate, offset, useDismiss, useTransitionStyles, } from "@floating-ui/react";
14
14
  var Popover = function (props) {
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;
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 ? false : _c;
16
16
  var handleOnClose = function () {
17
17
  var _a, _b;
18
18
  if (!returnFocusOnEscape)
@@ -31,6 +31,11 @@ type Props = {
31
31
  * Whether to disable the flip behavior of the tooltip.
32
32
  */
33
33
  disableFlip?: boolean;
34
+ /**
35
+ * Whether the tooltip is disabled. If true, will not show the tooltip.
36
+ * @default false
37
+ */
38
+ disabled?: boolean;
34
39
  };
35
40
  declare const Tooltip: (props: Props) => JSX.Element;
36
41
  export default Tooltip;
@@ -13,27 +13,29 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
13
13
  import { cloneElement, useState } from "react";
14
14
  import { useFloating, useHover, useInteractions, flip, safePolygon, autoUpdate, offset, useTransitionStyles, } from "@floating-ui/react";
15
15
  var Tooltip = function (props) {
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
- var _d = useState(false), open = _d[0], setOpen = _d[1];
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, _d = props.disabled, disabled = _d === void 0 ? false : _d;
17
+ var _e = useState(false), open = _e[0], setOpen = _e[1];
18
18
  var middleware = [offset(placementOffset)];
19
19
  if (!disableFlip) {
20
20
  middleware.push(flip());
21
21
  }
22
- var _e = useFloating({
22
+ var _f = useFloating({
23
23
  open: open,
24
24
  onOpenChange: setOpen,
25
25
  middleware: middleware,
26
26
  whileElementsMounted: autoUpdate,
27
27
  placement: placement,
28
- }), refs = _e.refs, floatingStyles = _e.floatingStyles, context = _e.context;
28
+ }), refs = _f.refs, floatingStyles = _f.floatingStyles, context = _f.context;
29
29
  var hover = useHover(context, {
30
30
  handleClose: safePolygon(),
31
31
  mouseOnly: true,
32
32
  });
33
- var _f = useTransitionStyles(context, {
33
+ var _g = useTransitionStyles(context, {
34
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;
35
+ }), isMounted = _g.isMounted, transitionStyles = _g.styles;
36
+ var _h = useInteractions([hover]), getReferenceProps = _h.getReferenceProps, getFloatingProps = _h.getFloatingProps;
37
+ if (disabled)
38
+ return children;
37
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 })))] }));
38
40
  };
39
41
  export default Tooltip;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adamjanicki/ui-extended",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "More advanced UI components and hooks for React in TypeScript",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",