@algolia/satellite 1.0.0-beta.156 → 1.0.0-beta.158

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.
Files changed (86) hide show
  1. package/cjs/Avatars/UserAvatar.d.ts +7 -3
  2. package/cjs/Avatars/UserAvatar.js +28 -28
  3. package/cjs/Badge/Badge.d.ts +2 -2
  4. package/cjs/Badge/Badge.js +7 -6
  5. package/cjs/Banners/Alert/Alert.js +1 -1
  6. package/cjs/Button/Button.d.ts +3 -5
  7. package/cjs/Button/Button.js +8 -51
  8. package/cjs/Button/Button.tailwind.js +0 -2
  9. package/cjs/Button/IconButton.d.ts +3 -15
  10. package/cjs/Button/IconButton.js +8 -62
  11. package/cjs/Button/PolymorphicButton.d.ts +11 -0
  12. package/cjs/Button/PolymorphicButton.js +76 -0
  13. package/cjs/Button/PolymorphicIconButton.d.ts +24 -0
  14. package/cjs/Button/PolymorphicIconButton.js +84 -0
  15. package/cjs/Button/index.d.ts +1 -1
  16. package/cjs/Button/index.js +16 -12
  17. package/cjs/Button/types.d.ts +11 -6
  18. package/cjs/Button/types.js +3 -1
  19. package/cjs/Dropdown/DropdownButton.d.ts +3 -3
  20. package/cjs/Dropdown/DropdownButton.js +5 -2
  21. package/cjs/FlexGrid/FlexGrid.js +1 -1
  22. package/cjs/Link/ButtonLink.d.ts +5 -3
  23. package/cjs/Link/ButtonLink.js +9 -6
  24. package/cjs/Link/IconButtonLink.d.ts +5 -4
  25. package/cjs/Link/IconButtonLink.js +8 -5
  26. package/cjs/Medallion/Medallion.js +1 -1
  27. package/cjs/Modal/Modal.d.ts +35 -11
  28. package/cjs/Modal/Modal.js +131 -95
  29. package/cjs/Modal/Modal.tailwind.js +7 -0
  30. package/cjs/RangeSlider/RangeSlider.js +1 -1
  31. package/cjs/Satellite/Satellite.d.ts +2 -1
  32. package/cjs/Satellite/Satellite.js +26 -2
  33. package/cjs/Satellite/locale.d.ts +2 -0
  34. package/cjs/Tables/DataTable/DataTable.js +12 -12
  35. package/cjs/Tag/Tag.d.ts +26 -6
  36. package/cjs/Tag/Tag.js +51 -19
  37. package/cjs/Tag/Tag.tailwind.js +17 -1
  38. package/cjs/Tooltip/Tooltip.tailwind.js +2 -1
  39. package/cjs/styles/colors.d.ts +18 -0
  40. package/cjs/styles/colors.js +33 -15
  41. package/cjs/types.d.ts +9 -0
  42. package/cjs/utils/isCssPropertySupported.d.ts +1 -1
  43. package/esm/Avatars/UserAvatar.d.ts +7 -3
  44. package/esm/Avatars/UserAvatar.js +28 -28
  45. package/esm/Badge/Badge.d.ts +2 -2
  46. package/esm/Badge/Badge.js +7 -6
  47. package/esm/Banners/Alert/Alert.js +1 -1
  48. package/esm/Button/Button.d.ts +3 -5
  49. package/esm/Button/Button.js +8 -52
  50. package/esm/Button/Button.tailwind.js +0 -2
  51. package/esm/Button/IconButton.d.ts +3 -15
  52. package/esm/Button/IconButton.js +8 -64
  53. package/esm/Button/PolymorphicButton.d.ts +11 -0
  54. package/esm/Button/PolymorphicButton.js +66 -0
  55. package/esm/Button/PolymorphicIconButton.d.ts +24 -0
  56. package/esm/Button/PolymorphicIconButton.js +78 -0
  57. package/esm/Button/index.d.ts +1 -1
  58. package/esm/Button/index.js +1 -1
  59. package/esm/Button/types.d.ts +11 -6
  60. package/esm/Button/types.js +3 -1
  61. package/esm/Dropdown/DropdownButton.d.ts +3 -3
  62. package/esm/Dropdown/DropdownButton.js +5 -2
  63. package/esm/Link/ButtonLink.d.ts +5 -3
  64. package/esm/Link/ButtonLink.js +9 -6
  65. package/esm/Link/IconButtonLink.d.ts +5 -4
  66. package/esm/Link/IconButtonLink.js +8 -5
  67. package/esm/Medallion/Medallion.js +1 -1
  68. package/esm/Modal/Modal.d.ts +35 -11
  69. package/esm/Modal/Modal.js +129 -96
  70. package/esm/Modal/Modal.tailwind.js +7 -0
  71. package/esm/RangeSlider/RangeSlider.js +2 -0
  72. package/esm/Satellite/Satellite.d.ts +2 -1
  73. package/esm/Satellite/Satellite.js +24 -1
  74. package/esm/Satellite/locale.d.ts +2 -0
  75. package/esm/Tables/DataTable/DataTable.js +12 -12
  76. package/esm/Tag/Tag.d.ts +26 -6
  77. package/esm/Tag/Tag.js +52 -20
  78. package/esm/Tag/Tag.tailwind.js +17 -1
  79. package/esm/Tooltip/Tooltip.tailwind.js +2 -1
  80. package/esm/styles/colors.d.ts +18 -0
  81. package/esm/styles/colors.js +33 -15
  82. package/esm/types.d.ts +9 -0
  83. package/esm/utils/isCssPropertySupported.d.ts +1 -1
  84. package/package.json +8 -4
  85. package/satellite.min.css +1 -1
  86. package/scss/colors.scss +27 -10
@@ -1,3 +1,5 @@
1
1
  export function isButtonType(props) {
2
2
  return props && (!props.as || props.as === "button");
3
- }
3
+ }
4
+
5
+ // Polymorphic Helpers lifted from https://blog.logrocket.com/build-strongly-typed-polymorphic-components-react-typescript/
@@ -1,11 +1,11 @@
1
- import type { FunctionComponent, ReactNode } from "react";
1
+ import { ReactNode } from "react";
2
2
  import { ButtonProps } from "../Button";
3
3
  import { RenderTargetParams } from "./Dropdown";
4
- export interface DropdownButtonProps extends Omit<ButtonProps<"button">, "title" | "endIcon"> {
4
+ export interface DropdownButtonProps extends Omit<ButtonProps, "title" | "endIcon"> {
5
5
  /** Descriptive title for `Dropdown` */
6
6
  title: ReactNode;
7
7
  renderFooter?: (args: RenderTargetParams) => ReactNode;
8
8
  children: ReactNode;
9
9
  }
10
- export declare const DropdownButton: FunctionComponent<DropdownButtonProps>;
10
+ export declare const DropdownButton: import("react").ForwardRefExoticComponent<DropdownButtonProps & import("react").RefAttributes<HTMLButtonElement & HTMLAnchorElement>>;
11
11
  export default DropdownButton;
@@ -3,11 +3,12 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  var _excluded = ["children", "title", "renderFooter"];
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+ import { forwardRef } from "react";
6
7
  import { ChevronDown } from "react-feather";
7
8
  import Button from "../Button";
8
9
  import Dropdown from "./Dropdown";
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
10
- export var DropdownButton = function DropdownButton(_ref) {
11
+ export var DropdownButton = /*#__PURE__*/forwardRef(function (_ref, ref) {
11
12
  var children = _ref.children,
12
13
  title = _ref.title,
13
14
  renderFooter = _ref.renderFooter,
@@ -25,6 +26,7 @@ export var DropdownButton = function DropdownButton(_ref) {
25
26
  return /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread({}, buttonProps), {}, {
26
27
  onClick: handleClick,
27
28
  endIcon: ChevronDown,
29
+ ref: ref,
28
30
  children: title
29
31
  }));
30
32
  };
@@ -33,5 +35,6 @@ export var DropdownButton = function DropdownButton(_ref) {
33
35
  renderFooter: renderFooter,
34
36
  children: children
35
37
  });
36
- };
38
+ });
39
+ DropdownButton.displayName = "DropdownButton";
37
40
  export default DropdownButton;
@@ -1,7 +1,9 @@
1
1
  /// <reference types="react" />
2
- import type { ButtonBaseProps, ExtractProps } from "../Button/types";
3
- export declare type ButtonLinkProps = ButtonBaseProps & ExtractProps<"a"> & {
2
+ import { type PolymorphicButtonProps } from "../Button/PolymorphicButton";
3
+ export declare type ButtonLinkProps = Omit<PolymorphicButtonProps<"a">, "as" | "ref"> & {
4
4
  href: string;
5
5
  };
6
- export declare const ButtonLink: ({ endIcon: EndIcon, href, onClick, ...props }: ButtonLinkProps) => JSX.Element;
6
+ export declare const ButtonLink: import("react").ForwardRefExoticComponent<Omit<PolymorphicButtonProps<"a">, "ref" | "as"> & {
7
+ href: string;
8
+ } & import("react").RefAttributes<HTMLAnchorElement>>;
7
9
  export default ButtonLink;
@@ -3,11 +3,12 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  var _excluded = ["endIcon", "href", "onClick"];
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
+ import { forwardRef } from "react";
6
7
  import { ExternalLink } from "react-feather";
7
- import Button from "../Button/Button";
8
+ import { PolymorphicButton } from "../Button/PolymorphicButton";
8
9
  import useLinkProps from "../utils/useLinkProps";
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
10
- export var ButtonLink = function ButtonLink(_ref) {
11
+ export var ButtonLink = /*#__PURE__*/forwardRef(function (_ref, ref) {
11
12
  var EndIcon = _ref.endIcon,
12
13
  href = _ref.href,
13
14
  onClick = _ref.onClick,
@@ -19,9 +20,11 @@ export var ButtonLink = function ButtonLink(_ref) {
19
20
  if (linkProps.target === "_blank" && EndIcon === undefined) {
20
21
  EndIcon = ExternalLink;
21
22
  }
22
- return /*#__PURE__*/_jsx(Button, _objectSpread(_objectSpread(_objectSpread({}, props), linkProps), {}, {
23
- endIcon: EndIcon,
24
- as: "a"
23
+ return /*#__PURE__*/_jsx(PolymorphicButton, _objectSpread(_objectSpread(_objectSpread({}, props), linkProps), {}, {
24
+ ref: ref,
25
+ as: "a",
26
+ endIcon: EndIcon
25
27
  }));
26
- };
28
+ });
29
+ ButtonLink.displayName = "ButtonLink";
27
30
  export default ButtonLink;
@@ -1,8 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { IconButtonBaseProps } from "../Button/IconButton";
3
- import type { ExtractProps } from "../Button/types";
4
- export declare type IconButtonLinkProps = IconButtonBaseProps & ExtractProps<"a"> & {
2
+ import { type PolymorphicIconButtonProps } from "../Button/PolymorphicIconButton";
3
+ export declare type IconButtonLinkProps = Omit<PolymorphicIconButtonProps<"a">, "as" | "ref"> & {
5
4
  href: string;
6
5
  };
7
- export declare const IconButtonLink: ({ href, onClick, ...props }: IconButtonLinkProps) => JSX.Element;
6
+ export declare const IconButtonLink: import("react").ForwardRefExoticComponent<Omit<PolymorphicIconButtonProps<"a">, "ref" | "as"> & {
7
+ href: string;
8
+ } & import("react").RefAttributes<HTMLAnchorElement>>;
8
9
  export default IconButtonLink;
@@ -3,10 +3,11 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  var _excluded = ["href", "onClick"];
4
4
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
5
5
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
6
- import IconButton from "../Button/IconButton";
6
+ import { forwardRef } from "react";
7
+ import { PolymorphicIconButton } from "../Button/PolymorphicIconButton";
7
8
  import useLinkProps from "../utils/useLinkProps";
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
- export var IconButtonLink = function IconButtonLink(_ref) {
10
+ export var IconButtonLink = /*#__PURE__*/forwardRef(function (_ref, ref) {
10
11
  var href = _ref.href,
11
12
  onClick = _ref.onClick,
12
13
  props = _objectWithoutProperties(_ref, _excluded);
@@ -14,8 +15,10 @@ export var IconButtonLink = function IconButtonLink(_ref) {
14
15
  href: href,
15
16
  onClick: onClick
16
17
  }));
17
- return /*#__PURE__*/_jsx(IconButton, _objectSpread(_objectSpread(_objectSpread({}, props), linkProps), {}, {
18
- as: "a"
18
+ return /*#__PURE__*/_jsx(PolymorphicIconButton, _objectSpread(_objectSpread(_objectSpread({}, props), linkProps), {}, {
19
+ as: "a",
20
+ ref: ref
19
21
  }));
20
- };
22
+ });
23
+ IconButtonLink.displayName = "IconButtonLink";
21
24
  export default IconButtonLink;
@@ -8,7 +8,7 @@ var VARIANT_CLASSNAMES = {
8
8
  pink: stl(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["medallion-pink text-pink-600"]))),
9
9
  accent: stl(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["medallion-accent text-accent-600"]))),
10
10
  blue: stl(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["medallion-blue text-blue-600"]))),
11
- green: stl(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["medallion-green text-green-700"]))),
11
+ green: stl(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["medallion-green text-green-600"]))),
12
12
  orange: stl(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["medallion-orange text-orange-600"]))),
13
13
  red: stl(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["medallion-red text-red-600"]))),
14
14
  // eslint-disable-next-line @algolia/satellite/prefer-accent -- here we're definitely refering to the color itself
@@ -1,30 +1,54 @@
1
1
  import type { ReactNode } from "react";
2
+ import type { XOR } from "../types";
2
3
  export declare type ModalSizeVariant = "medium" | "large";
3
4
  export declare type ModalLocale = {
4
5
  dismissText?: string;
6
+ modalTitle?: string;
5
7
  };
6
- export interface ModalProps {
7
- open?: boolean;
8
- /** Descriptive title for `Modal` */
8
+ interface ModalControlledProps {
9
+ /** Define whether the modal is open or closed. */
10
+ open: boolean;
11
+ /** The element that should receive focus once the `Modal` is closed. */
12
+ autoFocusOnCloseElement?: HTMLElement | null;
13
+ }
14
+ interface ModalUncontrolledProps {
15
+ /** Button which should trigger the modal */
16
+ triggerButton: ReactNode;
17
+ }
18
+ export declare type ModalProps = XOR<ModalControlledProps, ModalUncontrolledProps> & {
19
+ /** Descriptive title for `Modal`. */
9
20
  title?: ReactNode;
10
21
  /** @ignore */
11
22
  className?: string;
12
- /** Should the content take up full full width of the `Modal`. */
23
+ /** Define whether the content should take up the full width of the `Modal`. */
13
24
  fullBleed?: boolean;
14
- /** Define whether or not the modal should animate on show and hide */
25
+ /** Define whether or not the modal should animate on show and hide. */
15
26
  animate?: boolean;
27
+ /** Define the size of the `Modal`. */
16
28
  size?: ModalSizeVariant;
17
- /** Define whether or not the dismiss button should be hidden */
29
+ /** Define whether or not the dismiss button should be hidden. */
18
30
  hideCloseIcon?: boolean;
19
- /** Define whether or not the modal should be vertically aligned */
31
+ /** Define whether or not the modal should be vertically aligned. */
20
32
  centerY?: boolean;
21
- /** Function triggered when the dismiss button is clicked */
33
+ /**
34
+ * Function triggered when the modal is dismissed.
35
+ * This function is called when the user clicks the close button,
36
+ * clicks outside the modal or presses the escape key.
37
+ */
22
38
  onDismiss?: () => void;
23
- children: ReactNode;
39
+ /** The locale for the `Modal`. */
24
40
  locale?: ModalLocale;
25
- }
41
+ /**
42
+ * The element that should receive focus once the `Modal` is opened.
43
+ * If `undefined` or `null` is passed, the first focusable element will be focused.
44
+ * If `false`, no element will be focused.
45
+ */
46
+ autoFocusOnOpenElement?: HTMLElement | null | false;
47
+ children: ReactNode;
48
+ };
26
49
  export declare const Modal: {
27
- ({ title, className, children, open, fullBleed, onDismiss, animate, hideCloseIcon, size, centerY, locale: propsLocale, }: ModalProps): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;
50
+ ({ title, className, children, open, onDismiss, fullBleed, animate, hideCloseIcon, size, centerY, autoFocusOnOpenElement, autoFocusOnCloseElement, triggerButton, locale: propsLocale, }: ModalProps): JSX.Element;
28
51
  Footer: import("react").FunctionComponent<import("./components/ModalFooter").ModalFooterProps>;
52
+ Section: ({ children, className, fullBleed }: import("./components/ModalSection").ModalSectionProps) => JSX.Element;
29
53
  };
30
54
  export default Modal;
@@ -1,38 +1,36 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
3
  import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
4
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11;
4
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16;
5
5
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
6
6
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
7
+ import * as Dialog from "@radix-ui/react-dialog";
7
8
  import cx from "clsx";
8
- import { useEffect, useMemo, useRef, useState } from "react";
9
+ import { Fragment, useEffect, useRef, useState } from "react";
9
10
  import { X } from "react-feather";
10
11
  import { CSSTransition } from "react-transition-group";
11
- import useKeyPressEvent from "react-use/lib/useKeyPressEvent";
12
- import useLockBodyScroll from "react-use/lib/useLockBodyScroll";
13
12
  import { IconButton } from "../Button";
14
13
  import Card from "../Card";
15
14
  import { useCreatePortal, useLocale } from "../Satellite";
16
15
  import stl from "../styles/helpers/satellitePrefixer";
17
- import uniqueId from "../utils/uniqueId";
18
16
  import ModalFooter from "./components/ModalFooter";
17
+ import ModalSection from "./components/ModalSection";
19
18
  import { jsx as _jsx } from "react/jsx-runtime";
20
19
  import { Fragment as _Fragment } from "react/jsx-runtime";
21
20
  import { jsxs as _jsxs } from "react/jsx-runtime";
22
21
  var DEFAULT_MODAL_LOCALE = {
23
- dismissText: "Dismiss"
22
+ dismissText: "Dismiss",
23
+ modalTitle: "Modal"
24
24
  };
25
+ var MODAL_ANIMATION_OUT_DELAY = 200;
25
26
  var ModalAnimation = function ModalAnimation(props) {
26
- return (
27
- /*#__PURE__*/
27
+ return /*#__PURE__*/_jsx(CSSTransition, _objectSpread(_objectSpread({}, props), {}, {
28
28
  /* eslint-disable-next-line @algolia/satellite/invalid-classnames */
29
- _jsx(CSSTransition, _objectSpread(_objectSpread({}, props), {}, {
30
- classNames: stl(_templateObject || (_templateObject = _taggedTemplateLiteral(["satellite-modal"]))),
31
- timeout: 200,
32
- appear: true,
33
- unmountOnExit: true
34
- }))
35
- );
29
+ classNames: stl(_templateObject || (_templateObject = _taggedTemplateLiteral(["satellite-modal"]))),
30
+ timeout: MODAL_ANIMATION_OUT_DELAY,
31
+ appear: true,
32
+ unmountOnExit: true
33
+ }));
36
34
  };
37
35
  var ModalNoAnimation = function ModalNoAnimation(props) {
38
36
  return props["in"] ? /*#__PURE__*/_jsx(_Fragment, {
@@ -48,11 +46,10 @@ export var Modal = function Modal(_ref) {
48
46
  className = _ref.className,
49
47
  children = _ref.children,
50
48
  _ref$open = _ref.open,
51
- open = _ref$open === void 0 ? true : _ref$open,
49
+ open = _ref$open === void 0 ? false : _ref$open,
50
+ onDismiss = _ref.onDismiss,
52
51
  _ref$fullBleed = _ref.fullBleed,
53
52
  fullBleed = _ref$fullBleed === void 0 ? false : _ref$fullBleed,
54
- _ref$onDismiss = _ref.onDismiss,
55
- onDismiss = _ref$onDismiss === void 0 ? function () {} : _ref$onDismiss,
56
53
  _ref$animate = _ref.animate,
57
54
  animate = _ref$animate === void 0 ? true : _ref$animate,
58
55
  _ref$hideCloseIcon = _ref.hideCloseIcon,
@@ -61,91 +58,127 @@ export var Modal = function Modal(_ref) {
61
58
  size = _ref$size === void 0 ? "medium" : _ref$size,
62
59
  _ref$centerY = _ref.centerY,
63
60
  centerY = _ref$centerY === void 0 ? false : _ref$centerY,
61
+ autoFocusOnOpenElement = _ref.autoFocusOnOpenElement,
62
+ autoFocusOnCloseElement = _ref.autoFocusOnCloseElement,
63
+ triggerButton = _ref.triggerButton,
64
64
  propsLocale = _ref.locale;
65
- var createPortal = useCreatePortal();
66
65
  var contextLocale = useLocale("modal");
67
66
  var locale = _objectSpread(_objectSpread(_objectSpread({}, DEFAULT_MODAL_LOCALE), contextLocale), propsLocale);
68
- var _useState = useState(null),
69
- _useState2 = _slicedToArray(_useState, 2),
70
- modalWrapperRef = _useState2[0],
71
- setModalWrapperRef = _useState2[1];
72
- var dialogRef = useRef(null);
73
- var mouseDownTargetRef = useRef(null);
67
+ var createPortal = useCreatePortal();
74
68
  var ModalContainer = animate ? ModalAnimation : ModalNoAnimation;
75
- var modalTitleId = useMemo(function () {
76
- return uniqueId("modal-title");
77
- }, []);
78
- useLockBodyScroll(open);
79
- useKeyPressEvent("Escape", function () {
80
- if (open) onDismiss();
81
- });
69
+ var _useState = useState(open),
70
+ _useState2 = _slicedToArray(_useState, 2),
71
+ isOpen = _useState2[0],
72
+ setIsOpen = _useState2[1];
73
+ var _useState3 = useState(open),
74
+ _useState4 = _slicedToArray(_useState3, 2),
75
+ isOpenAnimated = _useState4[0],
76
+ setIsOpenAnimated = _useState4[1];
77
+ var openTimeoutId = useRef();
78
+ var onOpenChangeTimeoutId = useRef();
79
+ var isControlled = triggerButton === undefined;
82
80
  useEffect(function () {
83
- if (!modalWrapperRef) return;
84
- var onMouseUp = function onMouseUp(evt) {
85
- if (evt.target === mouseDownTargetRef.current && dialogRef.current && !dialogRef.current.contains(evt.target)) {
86
- onDismiss();
81
+ clearTimeout(openTimeoutId.current);
82
+ setIsOpenAnimated(open);
83
+ if (animate && !open) {
84
+ openTimeoutId.current = setTimeout(function () {
85
+ return setIsOpen(open);
86
+ }, MODAL_ANIMATION_OUT_DELAY);
87
+ } else {
88
+ setIsOpen(open);
89
+ }
90
+ }, [open, animate]);
91
+ if (typeof document === "undefined") return /*#__PURE__*/_jsx(Fragment, {});
92
+ return /*#__PURE__*/_jsxs(Dialog.Root, {
93
+ open: isOpen,
94
+ onOpenChange: function onOpenChange(open) {
95
+ clearTimeout(onOpenChangeTimeoutId.current);
96
+ setIsOpenAnimated(open);
97
+ var cb = function cb() {
98
+ setIsOpen(open);
99
+ if (!open) onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
100
+ };
101
+ if (animate) {
102
+ onOpenChangeTimeoutId.current = setTimeout(cb, MODAL_ANIMATION_OUT_DELAY);
103
+ } else {
104
+ cb();
87
105
  }
88
- mouseDownTargetRef.current = null;
89
- };
90
- var onMouseDown = function onMouseDown(evt) {
91
- return mouseDownTargetRef.current = evt.target;
92
- };
93
-
94
- /**
95
- * We use native event handlers to avoid React event bubbling behaviour with element rendered in a portal.
96
- * (otherwise, the modal gets dismissed when clicking on an AutoComplete menu item)
97
- */
98
- modalWrapperRef.addEventListener("mouseup", onMouseUp);
99
- modalWrapperRef.addEventListener("mousedown", onMouseDown);
100
- return function () {
101
- modalWrapperRef.removeEventListener("mouseup", onMouseUp);
102
- modalWrapperRef.removeEventListener("mousedown", onMouseDown);
103
- };
104
- }, [modalWrapperRef, onDismiss]);
105
- var modalAccessibilityProps = _objectSpread({
106
- role: "dialog"
107
- }, title ? {
108
- "aria-labelledby": modalTitleId
109
- } : {
110
- "aria-label": "Modal"
111
- });
112
- return createPortal( /*#__PURE__*/_jsx(ModalContainer, {
113
- "in": open,
114
- children: /*#__PURE__*/_jsxs("div", {
115
- children: [/*#__PURE__*/_jsx("div", {
116
- className: cx(stl(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["bg-grey-900/30 z-modalOverlay inset-x-0 inset-y-0 fixed w-full h-full"]))))
117
- }), /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
118
- className: cx(stl(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["modal-container inset-x-0 inset-y-0 fixed w-full h-full p-4 overflow-x-hidden overflow-y-auto"]))), centerY && stl(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["flex items-center"])))),
119
- ref: setModalWrapperRef
120
- }, modalAccessibilityProps), {}, {
121
- children: /*#__PURE__*/_jsxs(Card, {
122
- ref: dialogRef,
123
- as: "section",
124
- elevation: "500",
125
- className: cx(stl(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["my-6 mx-auto"]))), SIZE_CLASSNAMES[size], className),
126
- fullBleed: true,
127
- "aria-label": title || "Modal",
128
- children: [/*#__PURE__*/_jsxs("header", {
129
- className: stl(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n px-8 min-h-14\n flex items-center justify-between space-x-2\n ", "\n ", "\n "])), title ? "border-b border-grey-100" : "justify-end", !title && hideCloseIcon && "hidden"),
130
- children: [!!title && /*#__PURE__*/_jsx("h2", {
131
- id: modalTitleId,
132
- className: stl(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["flex-1 display-heading truncate"]))),
133
- children: title
134
- }), !hideCloseIcon && /*#__PURE__*/_jsx(IconButton, {
135
- icon: X,
136
- title: locale.dismissText,
137
- variant: "subtle",
138
- onClick: onDismiss,
139
- className: stl(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["shrink-0 -mr-2"])))
140
- })]
141
- }), /*#__PURE__*/_jsx("div", {
142
- className: fullBleed ? undefined : stl(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["p-10"]))),
143
- children: children
144
- })]
106
+ },
107
+ modal: true,
108
+ children: [!isControlled && /*#__PURE__*/_jsx(Dialog.Trigger, {
109
+ asChild: true,
110
+ children: triggerButton
111
+ }), createPortal( /*#__PURE__*/_jsx(Dialog.Overlay, {
112
+ className: stl(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["bg-grey-900/30 z-modalOverlay inset-0 fixed w-full h-full flex items-start justify-center overflow-x-hidden overflow-y-auto px-4 py-10"]))),
113
+ children: /*#__PURE__*/_jsx(Dialog.Content, {
114
+ className: cx(stl(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["modal-content"]))), SIZE_CLASSNAMES[size], !isOpen && stl(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["hidden"]))), centerY && stl(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["flex m-auto"])))),
115
+ onOpenAutoFocus: function onOpenAutoFocus(e) {
116
+ if (autoFocusOnOpenElement === false) {
117
+ e.preventDefault();
118
+ } else if (autoFocusOnOpenElement instanceof HTMLElement) {
119
+ e.preventDefault();
120
+ autoFocusOnOpenElement.focus();
121
+ }
122
+ },
123
+ onCloseAutoFocus: function onCloseAutoFocus(e) {
124
+ if (autoFocusOnCloseElement instanceof HTMLElement) {
125
+ e.preventDefault();
126
+ autoFocusOnCloseElement.focus();
127
+ }
128
+ },
129
+ onEscapeKeyDown: function onEscapeKeyDown(e) {
130
+ if (isControlled) {
131
+ e.preventDefault();
132
+ onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
133
+ }
134
+ },
135
+ onInteractOutside: function onInteractOutside(e) {
136
+ if (isControlled) {
137
+ e.preventDefault();
138
+ onDismiss === null || onDismiss === void 0 ? void 0 : onDismiss();
139
+ }
140
+ },
141
+ "aria-label": !title ? locale.modalTitle : undefined,
142
+ "aria-describedby": undefined,
143
+ children: /*#__PURE__*/_jsx(ModalContainer, {
144
+ "in": animate ? isOpenAnimated : isOpen,
145
+ children: /*#__PURE__*/_jsx("div", {
146
+ children: /*#__PURE__*/_jsx("div", {
147
+ className: stl(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["modal-container"]))),
148
+ children: /*#__PURE__*/_jsxs(Card, {
149
+ as: "div",
150
+ elevation: "500",
151
+ className: cx(stl(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["relative"]))), className),
152
+ fullBleed: true,
153
+ children: [/*#__PURE__*/_jsx("header", {
154
+ className: cx(stl(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["min-h-14 flex items-center justify-between space-x-2"]))), title ? stl(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["border-b border-grey-100 pl-8 pr-16"]))) : stl(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["justify-end px-8"]))), !title && hideCloseIcon && stl(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["hidden"])))),
155
+ children: !!title && /*#__PURE__*/_jsx(Dialog.Title, {
156
+ className: stl(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["flex-1 display-heading truncate"]))),
157
+ children: title
158
+ })
159
+ }), /*#__PURE__*/_jsx("div", {
160
+ className: cx(!fullBleed && stl(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["p-10"])))),
161
+ children: children
162
+ }), !hideCloseIcon && /*#__PURE__*/_jsx("div", {
163
+ className: stl(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["-mr-2 absolute top-3 right-8"]))),
164
+ children: /*#__PURE__*/_jsx(Dialog.Close, {
165
+ asChild: true,
166
+ children: /*#__PURE__*/_jsx(IconButton, {
167
+ icon: X,
168
+ title: locale.dismissText,
169
+ variant: "subtle",
170
+ showTooltip: false
171
+ })
172
+ })
173
+ })]
174
+ })
175
+ })
176
+ })
145
177
  })
146
- }))]
147
- })
148
- }));
178
+ })
179
+ }))]
180
+ });
149
181
  };
150
182
  Modal.Footer = ModalFooter;
183
+ Modal.Section = ModalSection;
151
184
  export default Modal;
@@ -10,6 +10,13 @@ var modalPlugin = plugin(function (_ref) {
10
10
  ".modal-container": {
11
11
  zIndex: theme("zIndex.modal")
12
12
  },
13
+ ".modal-content": {
14
+ borderRadius: "8px",
15
+ width: "100%",
16
+ "&:focus": {
17
+ outline: "none"
18
+ }
19
+ },
13
20
  // Sizes
14
21
  ".modal-dialog-medium": {
15
22
  maxWidth: "640px"
@@ -9,6 +9,8 @@ import { SliderRange, Root as SliderRoot, SliderThumb, SliderTrack } from "@radi
9
9
  import cx from "clsx";
10
10
  import colors from "../styles/colors";
11
11
  import stl from "../styles/helpers/satellitePrefixer";
12
+
13
+ // Prevents unwanted number narrowing
12
14
  import { jsx as _jsx } from "react/jsx-runtime";
13
15
  import { jsxs as _jsxs } from "react/jsx-runtime";
14
16
  var TRACK_SHADOWS_CLASSNAME = stl(_templateObject || (_templateObject = _taggedTemplateLiteral(["shadow-[inset_0_1px_3px_0_rgb(0_0_0_/_10%),0_0.5px_0_0_rgb(255_255_255_/_5%)]"])));
@@ -1,4 +1,4 @@
1
- import type { FunctionComponent, ReactNode } from "react";
1
+ import { type FunctionComponent, type ReactNode } from "react";
2
2
  import type { ComponentsLocales } from "./locale";
3
3
  import type { SatelliteRouter } from "./SatelliteRouter";
4
4
  export interface SatelliteProps {
@@ -7,5 +7,6 @@ export interface SatelliteProps {
7
7
  portalTarget?: HTMLElement;
8
8
  children: ReactNode;
9
9
  }
10
+ export declare const DEFAULT_PORTAL_TARGET_ID = "satellite-portal";
10
11
  export declare const Satellite: FunctionComponent<SatelliteProps>;
11
12
  export default Satellite;
@@ -1,12 +1,35 @@
1
+ import { useEffect } from "react";
1
2
  import SatelliteContext from "./SatelliteContext";
2
3
  import { router as defaultRouter } from "./SatelliteRouter";
3
4
  import { jsx as _jsx } from "react/jsx-runtime";
5
+ export var DEFAULT_PORTAL_TARGET_ID = "satellite-portal";
6
+ var portalElement;
7
+ var getPortalElement = function getPortalElement() {
8
+ if (typeof document === "undefined") return;
9
+ if (!portalElement) {
10
+ var element = document.createElement("div");
11
+ element.setAttribute("id", DEFAULT_PORTAL_TARGET_ID);
12
+ document.body.appendChild(element);
13
+ portalElement = element;
14
+ }
15
+ return portalElement;
16
+ };
4
17
  export var Satellite = function Satellite(_ref) {
5
18
  var _ref$router = _ref.router,
6
19
  router = _ref$router === void 0 ? defaultRouter : _ref$router,
7
20
  locales = _ref.locales,
8
- portalTarget = _ref.portalTarget,
21
+ _ref$portalTarget = _ref.portalTarget,
22
+ portalTarget = _ref$portalTarget === void 0 ? getPortalElement() : _ref$portalTarget,
9
23
  children = _ref.children;
24
+ useEffect(function () {
25
+ if (!portalTarget) return;
26
+ if (portalTarget === document.body) {
27
+ console.warn("Avoid using the document body as a portal target.");
28
+ }
29
+
30
+ // Radix adds pointer-events: none; on the body for its modal, so we need to reenable it for other portaled elements (tooltips, menus, autocomplete)
31
+ portalTarget.style.pointerEvents = "auto";
32
+ }, [portalTarget]);
10
33
  return /*#__PURE__*/_jsx(SatelliteContext.Provider, {
11
34
  value: {
12
35
  router: router,
@@ -1,5 +1,6 @@
1
1
  import type { AnnouncementBadgeLocale } from "../AnnouncementBadge";
2
2
  import type { AutoCompleteLocale } from "../AutoComplete";
3
+ import type { UserAvatarLocale } from "../Avatars/UserAvatar";
3
4
  import type { DatePickerLocale } from "../DatePicker/types";
4
5
  import type { DropzoneLocale } from "../Dropzone";
5
6
  import type { FlagLocale } from "../Flag";
@@ -25,5 +26,6 @@ export declare type ComponentsLocales = {
25
26
  pagination?: PaginationLocale;
26
27
  sidebar?: SidebarLocale;
27
28
  tag?: TagLocale;
29
+ userAvatar?: UserAvatarLocale;
28
30
  };
29
31
  export declare const useLocale: <ComponentKey extends keyof ComponentsLocales>(componentKey: ComponentKey) => ComponentsLocales[ComponentKey];