@sproutsocial/seeds-react-popout 2.4.6 → 2.4.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.
@@ -0,0 +1,78 @@
1
+ // src/v2/Popout.tsx
2
+ import * as React from "react";
3
+ import { motion } from "motion/react";
4
+ import * as Popover from "@radix-ui/react-popover";
5
+ import { MOTION_DURATION_FAST } from "@sproutsocial/seeds-motion/unitless";
6
+ import styled from "styled-components";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ var defaultAnimationConfig = {
9
+ initial: { opacity: 0 },
10
+ animate: { opacity: 1 },
11
+ exit: { opacity: 0 },
12
+ transition: {
13
+ ease: "circOut",
14
+ type: "tween",
15
+ duration: process.env.NODE_ENV === "test" ? 0 : MOTION_DURATION_FAST
16
+ }
17
+ };
18
+ var StyledMotionDiv = styled(motion.div)`
19
+ background-color: ${({ theme }) => theme.colors.container.background.base};
20
+ border: ${({ theme }) => theme.borders[500]};
21
+ border-color: ${({ theme }) => theme.colors.container.border.base};
22
+ border-radius: ${({ theme }) => theme.radii[500]};
23
+ box-shadow: ${({ theme }) => theme.shadows.medium};
24
+ padding: ${({ theme }) => theme.space[400]};
25
+ `;
26
+ function Popout({
27
+ children,
28
+ content,
29
+ open,
30
+ defaultOpen,
31
+ onOpenChange,
32
+ animationConfig = defaultAnimationConfig,
33
+ side = "bottom",
34
+ sideOffset = 8,
35
+ align = "center",
36
+ alignOffset = 0,
37
+ onOpenAutoFocus,
38
+ onEscapeKeyDown,
39
+ onCloseAutoFocus,
40
+ ...rest
41
+ }) {
42
+ const [isOpen, setIsOpen] = React.useState(defaultOpen ?? false);
43
+ const handleOpenChange = React.useCallback(
44
+ (newOpen) => {
45
+ setIsOpen(newOpen);
46
+ onOpenChange?.(newOpen);
47
+ },
48
+ [onOpenChange]
49
+ );
50
+ const isControlled = open !== void 0;
51
+ const popoverOpen = isControlled ? open : isOpen;
52
+ const popoverOnOpenChange = isControlled ? onOpenChange : handleOpenChange;
53
+ const radixRef = React.useRef(null);
54
+ return /* @__PURE__ */ jsxs(Popover.Root, { open: popoverOpen, onOpenChange: popoverOnOpenChange, children: [
55
+ /* @__PURE__ */ jsx(Popover.Trigger, { ref: radixRef, asChild: true, children }),
56
+ /* @__PURE__ */ jsx(Popover.Portal, { children: /* @__PURE__ */ jsx(
57
+ Popover.Content,
58
+ {
59
+ side,
60
+ sideOffset,
61
+ align,
62
+ alignOffset,
63
+ onOpenAutoFocus,
64
+ onEscapeKeyDown,
65
+ onCloseAutoFocus,
66
+ children: /* @__PURE__ */ jsx(StyledMotionDiv, { ...animationConfig, ...rest, children: content })
67
+ }
68
+ ) })
69
+ ] });
70
+ }
71
+
72
+ // src/v2/PopoutTypes.ts
73
+ import "react";
74
+
75
+ export {
76
+ Popout
77
+ };
78
+ //# sourceMappingURL=chunk-KPXAE7KF.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/v2/Popout.tsx","../../src/v2/PopoutTypes.ts"],"sourcesContent":["import * as React from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport * as Popover from \"@radix-ui/react-popover\";\nimport { MOTION_DURATION_FAST } from \"@sproutsocial/seeds-motion/unitless\";\nimport type { TypePopoutProps } from \"./PopoutTypes\";\nimport styled from \"styled-components\";\n\nconst defaultAnimationConfig = {\n initial: { opacity: 0 },\n animate: { opacity: 1 },\n exit: { opacity: 0 },\n transition: {\n ease: \"circOut\",\n type: \"tween\",\n duration: process.env.NODE_ENV === \"test\" ? 0 : MOTION_DURATION_FAST,\n },\n};\n\nconst StyledMotionDiv = styled(motion.div)`\n background-color: ${({ theme }) => theme.colors.container.background.base};\n border: ${({ theme }) => theme.borders[500]};\n border-color: ${({ theme }) => theme.colors.container.border.base};\n border-radius: ${({ theme }) => theme.radii[500]};\n box-shadow: ${({ theme }) => theme.shadows.medium};\n padding: ${({ theme }) => theme.space[400]};\n`;\n\nexport function Popout({\n children,\n content,\n open,\n defaultOpen,\n onOpenChange,\n animationConfig = defaultAnimationConfig,\n side = \"bottom\",\n sideOffset = 8,\n align = \"center\",\n alignOffset = 0,\n onOpenAutoFocus,\n onEscapeKeyDown,\n onCloseAutoFocus,\n ...rest\n}: TypePopoutProps) {\n const [isOpen, setIsOpen] = React.useState(defaultOpen ?? false);\n\n const handleOpenChange = React.useCallback(\n (newOpen: boolean) => {\n setIsOpen(newOpen);\n onOpenChange?.(newOpen);\n },\n [onOpenChange]\n );\n\n // Use controlled state if open prop is provided\n const isControlled = open !== undefined;\n const popoverOpen = isControlled ? open : isOpen;\n const popoverOnOpenChange = isControlled ? onOpenChange : handleOpenChange;\n\n // Handle ref forwarding for components that use innerRef instead of ref\n // (e.g., seeds-react-button)\n // Radix UI's asChild passes ref, but Button uses innerRef\n const radixRef = React.useRef<HTMLButtonElement | null>(null);\n\n return (\n <Popover.Root open={popoverOpen} onOpenChange={popoverOnOpenChange}>\n <Popover.Trigger ref={radixRef} asChild>\n {children}\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Content\n side={side}\n sideOffset={sideOffset}\n align={align}\n alignOffset={alignOffset}\n onOpenAutoFocus={onOpenAutoFocus}\n onEscapeKeyDown={onEscapeKeyDown}\n onCloseAutoFocus={onCloseAutoFocus}\n >\n <StyledMotionDiv {...animationConfig} {...rest}>\n {content}\n </StyledMotionDiv>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from \"react\";\nimport type {\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n TypeStyledComponentsCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\nimport type { HTMLMotionProps } from \"motion/react\";\n\nexport interface TypePopoutProps\n extends TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n Omit<\n React.ComponentPropsWithoutRef<\"div\">,\n \"color\" | \"children\" | \"content\"\n > {\n /**\n * The content that the popout should be attached to (renders in Popover.Trigger)\n */\n children: React.ReactElement<any>;\n\n /**\n * The content to be shown in the popout (renders in Popover.Content)\n */\n content: React.ReactNode;\n\n /**\n * Whether the popout is open (controlled)\n */\n open?: boolean;\n\n /**\n * Default open state (uncontrolled)\n */\n defaultOpen?: boolean;\n\n /**\n * Callback fired when the open state changes\n */\n onOpenChange?: (open: boolean) => void;\n\n /**\n * Used to override the default Popout animations.\n * Any props that are valid for use on a Motion div can be passed here as an object.\n * See https://motion.dev/docs/react-motion-component#props\n */\n animationConfig?: Omit<HTMLMotionProps<\"div\">, \"children\">;\n\n /**\n * The preferred side of the trigger to render against when open.\n * @default \"bottom\"\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n\n /**\n * The distance in pixels from the trigger.\n * @default 8\n */\n sideOffset?: number;\n\n /**\n * The preferred alignment against the trigger.\n * @default \"center\"\n */\n align?: \"start\" | \"center\" | \"end\";\n\n /**\n * An offset in pixels from the \"start\" or \"end\" alignment options.\n * @default 0\n */\n alignOffset?: number;\n\n /**\n * Event handler called when the popout content tries to auto-focus on open.\n * Can be used to prevent the default auto-focus behavior or customize it.\n * If not provided, defaults to allowing auto-focus on the content.\n */\n onOpenAutoFocus?: (event: Event) => void;\n\n /**\n * Event handler called when the Escape key is pressed while the popout is open.\n * Can be used to prevent the default close behavior or customize it.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void;\n\n /**\n * Event handler called when the popout tries to return focus to the trigger on close.\n * Can be used to prevent the default focus return behavior or customize it.\n */\n onCloseAutoFocus?: (event: Event) => void;\n}\n"],"mappings":";AAAA,YAAY,WAAW;AACvB,SAA0B,cAAc;AACxC,YAAY,aAAa;AACzB,SAAS,4BAA4B;AAErC,OAAO,YAAY;AA2Df,SACE,KADF;AAzDJ,IAAM,yBAAyB;AAAA,EAC7B,SAAS,EAAE,SAAS,EAAE;AAAA,EACtB,SAAS,EAAE,SAAS,EAAE;AAAA,EACtB,MAAM,EAAE,SAAS,EAAE;AAAA,EACnB,YAAY;AAAA,IACV,MAAM;AA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QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEA,8BAAC,mBAAiB,GAAG,iBAAkB,GAAG,MACvC,mBACH;AAAA;AAAA,IACF,GACF;AAAA,KACF;AAEJ;;;ACpFA,OAAuB;","names":[]}
package/dist/esm/index.js CHANGED
@@ -1,3 +1,7 @@
1
+ import {
2
+ Popout
3
+ } from "./chunk-KPXAE7KF.js";
4
+
1
5
  // src/Popout.tsx
2
6
  import * as React from "react";
3
7
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
@@ -33,7 +37,7 @@ var defaultAnimationConfig = {
33
37
  duration: process.env.NODE_ENV === "test" ? 0 : MOTION_DURATION_FAST
34
38
  }
35
39
  };
36
- function Popout({
40
+ function Popout2({
37
41
  isOpen,
38
42
  setIsOpen,
39
43
  content,
@@ -259,16 +263,17 @@ var PopoutContent = ({ children, ...rest }) => /* @__PURE__ */ jsx(
259
263
  }
260
264
  );
261
265
  PopoutContent.displayName = "Popout.Content";
262
- Popout.Content = PopoutContent;
263
- var Popout_default = Popout;
266
+ Popout2.Content = PopoutContent;
267
+ var Popout_default = Popout2;
264
268
 
265
269
  // src/PopoutTypes.ts
266
270
  import "react";
267
271
 
268
272
  // src/index.ts
269
- var index_default = Popout_default;
273
+ var src_default = Popout_default;
270
274
  export {
271
275
  Popout_default as Popout,
272
- index_default as default
276
+ Popout as PopoutV2,
277
+ src_default as default
273
278
  };
274
279
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/Popout.tsx","../../src/styles.ts","../../src/PopoutTypes.ts","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport FocusLock from \"react-focus-lock\";\nimport { Popper } from \"react-popper\";\nimport { MOTION_DURATION_FAST } from \"@sproutsocial/seeds-motion/unitless\";\nimport { useMutationObserver } from \"@sproutsocial/seeds-react-hooks\";\nimport Portal from \"@sproutsocial/seeds-react-portal\";\nimport Box, { type TypeBoxProps } from \"@sproutsocial/seeds-react-box\";\nimport { TargetWrapper } from \"./styles\";\nimport type { TypePopoutProps } from \"./PopoutTypes\";\n\nconst doesRefContainEventTarget = (\n ref: React.MutableRefObject<HTMLDivElement | undefined>,\n event: MouseEvent\n) => {\n return (\n ref.current &&\n event.target instanceof Node &&\n ref.current.contains(event.target)\n );\n};\n\nconst defaultAnimationConfig = {\n initial: { opacity: 0 },\n animate: { opacity: 1 },\n exit: { opacity: 0 },\n transition: {\n ease: \"circOut\",\n type: \"tween\",\n duration: process.env.NODE_ENV === \"test\" ? 0 : MOTION_DURATION_FAST,\n },\n};\n\nexport function Popout({\n isOpen,\n setIsOpen,\n content,\n children,\n placement = \"auto\",\n lockPlacement = false,\n fullWidth = false,\n zIndex = 7,\n focusOnContent = true,\n onOpen,\n onClose,\n qa = {},\n popperProps: { modifiers: popperModifiers, ...restPopperProps } = {},\n animationConfig = defaultAnimationConfig,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n scheduleUpdateRef = () => {},\n appendToBody = true,\n focusLockProps = {},\n color,\n \"aria-haspopup\": ariaHasPopup,\n disableWrapperAria = false,\n id,\n ...rest\n}: TypePopoutProps) {\n const PopoutComponentWrapper = appendToBody ? Portal : React.Fragment;\n const [isInternalShown, setIsInternalShown] = useState<boolean>(false);\n const [lockedPlacement, setLockedPlacement] = useState<\n typeof placement | undefined\n >();\n const isControlled = typeof isOpen === \"boolean\";\n const isShown = isControlled ? isOpen : isInternalShown;\n const setIsShown = useMemo(\n () => (isControlled && setIsOpen ? setIsOpen : setIsInternalShown),\n [isControlled, setIsOpen]\n );\n\n const targetRef = useRef<HTMLElement | any>();\n const popoutRef = useRef<HTMLDivElement>();\n\n // This callback will automatically trigger a recalculation of the popout position if the content is changed\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const scheduleUpdateCallback = useRef(() => {});\n\n useMutationObserver(\n popoutRef.current ?? null,\n {\n childList: true,\n characterData: true,\n subtree: true,\n },\n scheduleUpdateCallback.current\n );\n\n const {\n autoFocus = true,\n returnFocus = true,\n ...restFocusLockProps\n } = focusLockProps;\n\n const isInvalidContent = content === null || content === undefined;\n\n // Callbacks for showing, hiding, and toggling visibility of the popout\n // (Not used when isOpen is passed explicitly)\n const show = useCallback(() => setIsShown(true), [setIsShown]);\n const hide = useCallback(() => setIsShown(false), [setIsShown]);\n const toggle = useCallback(() => setIsShown(!isShown), [isShown, setIsShown]);\n\n useEffect(() => {\n const documentBody = document.body;\n\n if (isShown && documentBody) {\n // Callback passed to a click handler attached to document.body,\n // allowing user to close the popout by clicking outside\n const bodyClick = (e: MouseEvent): void => {\n if (\n doesRefContainEventTarget(targetRef, e) ||\n doesRefContainEventTarget(popoutRef, e)\n ) {\n return;\n }\n\n setIsShown(false, e);\n };\n\n // Callback for allowing user to close by keying \"esc\"\n const onEsc = (e: KeyboardEvent): void => {\n // older browsers use \"Esc\"\n if ([\"Escape\", \"Esc\"].includes(e.key)) {\n // stop propagation to avoid interacting with other components when popout is shown\n // ie if we have a popout shown in a modal and hit esc, we don't want to close both the popout and modal\n e.stopPropagation();\n setIsShown(false, e);\n }\n };\n\n documentBody.addEventListener(\"click\", bodyClick, { capture: true });\n documentBody.addEventListener(\"keydown\", onEsc, { capture: true });\n return () => {\n documentBody.removeEventListener(\"click\", bodyClick, { capture: true });\n documentBody.removeEventListener(\"keydown\", onEsc, { capture: true });\n };\n }\n }, [isShown, setIsShown]);\n\n const callbackStateRef = useRef({ calledFor: isShown });\n useEffect(() => {\n if (callbackStateRef.current.calledFor === isShown) {\n return;\n }\n\n callbackStateRef.current.calledFor = isShown;\n if (isShown) {\n onOpen?.();\n } else {\n onClose?.();\n }\n }, [isShown, onOpen, onClose]);\n\n // WAI-Aria properties for the popout trigger, disabled if necessary\n const ariaProps = useMemo(\n () =>\n disableWrapperAria\n ? {}\n : {\n \"aria-expanded\": isShown,\n \"aria-haspopup\": ariaHasPopup ? ariaHasPopup : true,\n },\n [isShown, ariaHasPopup, disableWrapperAria]\n );\n\n // In cases where a controlled popout is used (e.g. props.isOpen is true), we need\n // to wait for the targetRef to receive a value before rendering the popout. Otherwise,\n // the Popout component renders, but doesn't know how to position itself due the\n // `refereElement` property being undefined.\n const [shouldRenderPopout, setShouldRenderPopout] = useState<boolean>( // Only trigger this shouldRenderPopout logic when using a controlled component.\n // The reason for that is because controlled components may render the popout\n // immediately before the targetRef has a value set to it.\n !isControlled\n );\n\n // Reset the locked placement when the popout is closed\n useEffect(() => {\n if (!isShown && lockedPlacement) {\n setLockedPlacement(undefined);\n }\n }, [isShown, lockedPlacement]);\n\n const childrenRef = (el: React.ElementRef<any> | HTMLElement) => {\n targetRef.current = el;\n\n if (targetRef.current) {\n setShouldRenderPopout(true);\n }\n };\n\n return (\n <React.Fragment>\n {typeof children === \"function\" ? (\n children({\n ref: childrenRef,\n toggle,\n show,\n hide,\n ariaProps,\n })\n ) : (\n <TargetWrapper {...qa} id={id} {...rest} ref={childrenRef}>\n {React.cloneElement(children, {\n ...ariaProps,\n ...(!isControlled\n ? {\n onClick: toggle,\n }\n : undefined),\n })}\n </TargetWrapper>\n )}\n {shouldRenderPopout && !isInvalidContent && (\n <AnimatePresence>\n {isShown && (\n <PopoutComponentWrapper>\n <Popper\n referenceElement={targetRef.current}\n placement={\n lockPlacement && lockedPlacement ? lockedPlacement : placement\n }\n modifiers={{\n preventOverflow: {\n boundariesElement: \"viewport\",\n },\n // Disable flip after locking when lockPlacement is true\n flip: { enabled: !(lockPlacement && lockedPlacement) },\n ...popperModifiers,\n }}\n {...restPopperProps}\n >\n {({\n ref,\n style,\n placement: actualPlacement,\n outOfBoundaries,\n scheduleUpdate,\n }) => {\n // HACK: We use setTimeout to defer locking the placement until after render,\n // because Popper v1 only exposes the computed placement in the render prop,\n // and React does not allow setState during render.\n if (lockPlacement && !lockedPlacement && actualPlacement) {\n setTimeout(() => {\n // Check again before setting to avoid a race condition\n if (\n lockPlacement &&\n !lockedPlacement &&\n actualPlacement\n ) {\n setLockedPlacement(actualPlacement);\n }\n }, 0);\n }\n\n const interceptRef = (el: HTMLDivElement | undefined) => {\n popoutRef.current = el;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n ref(el);\n };\n\n scheduleUpdateCallback.current = scheduleUpdate;\n scheduleUpdateRef(scheduleUpdate);\n\n return (\n <div\n ref={interceptRef}\n style={{\n ...style,\n zIndex,\n width:\n fullWidth && targetRef.current\n ? targetRef.current.offsetWidth\n : \"initial\",\n }}\n data-placement={actualPlacement}\n data-qa-popout=\"\"\n data-qa-popout-isopen={isOpen === true}\n // TODO: fix this type since `color` should be valid here. TS can't resolve the correct type.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n color={color}\n {...rest}\n >\n {!outOfBoundaries && (\n <motion.div\n {...animationConfig}\n // pass the placement in the custom prop so it can be used in the animation\n custom={{\n placement: actualPlacement,\n ...animationConfig.custom,\n }}\n >\n <FocusLock\n autoFocus={autoFocus}\n returnFocus={returnFocus}\n disabled={!focusOnContent}\n {...restFocusLockProps}\n >\n {typeof content === \"function\" &&\n content({\n hide,\n actualPlacement,\n })}\n {typeof content !== \"function\" && content}\n </FocusLock>\n </motion.div>\n )}\n </div>\n );\n }}\n </Popper>\n </PopoutComponentWrapper>\n )}\n </AnimatePresence>\n )}\n </React.Fragment>\n );\n}\n\nconst PopoutContent = ({ children, ...rest }: TypeBoxProps) => (\n <Box\n bg=\"container.background.base\"\n color=\"text.body\"\n border={500}\n borderColor=\"container.border.base\"\n borderRadius=\"outer\"\n boxShadow=\"medium\"\n p={400}\n m={300}\n {...rest}\n >\n {children}\n </Box>\n);\n\nPopoutContent.displayName = \"Popout.Content\";\nPopout.Content = PopoutContent;\n\nexport default Popout;\n","import styled from \"styled-components\";\nimport { COMMON, LAYOUT } from \"@sproutsocial/seeds-react-system-props\";\n\nexport const TargetWrapper = styled.div`\n display: inline-block;\n ${COMMON}\n ${LAYOUT}\n`;\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from \"react\";\nimport type { PopperProps } from \"react-popper\";\nimport type {\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n TypeStyledComponentsCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\nimport type { HTMLMotionProps } from \"motion/react\";\n\nexport type EnumPlacements = Exclude<PopperProps[\"placement\"], undefined>;\n\nexport interface TypeFocusLockProps {\n disabled?: boolean;\n returnFocus?:\n | boolean\n | FocusOptions\n | ((returnTo: Element) => boolean | FocusOptions);\n persistentFocus?: boolean;\n autoFocus?: boolean;\n crossFrame?: boolean;\n noFocusGuards?: boolean | \"tail\";\n group?: string;\n className?: string;\n onActivation?: (node: HTMLElement) => void;\n onDeactivation?: (node: HTMLElement) => void;\n as?: TypeStyledComponentsCommonProps[\"as\"];\n lockProps?: any;\n ref?: any;\n whiteList?: (activeElement: HTMLElement) => boolean;\n shards?: Array<any>;\n children?: React.ReactNode;\n}\n\nexport interface TypePopoutProps\n extends TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n Omit<\n React.ComponentPropsWithoutRef<\"div\">,\n \"color\" | \"children\" | \"content\"\n > {\n /**\n * Whether Popout should automatically add aria-attributes to its wrapped elements\n */\n disableWrapperAria?: boolean;\n /**\n * Is the popout open? This prop is optional. By using it, you will lose some automatic handling of the logic for opening and closing the popout.\n */\n isOpen?: boolean;\n\n /**\n * If you use the isOpen prop you will need to pass a handler to change the state of the popout\n */\n setIsOpen?: (isOpen: boolean, event?: MouseEvent | KeyboardEvent) => void;\n\n /**\n * The content to be shown in the popout. If there is no content, just the children are rendered\n */\n content:\n | (React.ReactElement<any> | null | undefined)\n | (\n | ((opts: {\n hide: () => void;\n actualPlacement: EnumPlacements;\n }) => React.ReactElement<any>)\n | null\n | undefined\n );\n\n /**\n * The content that the popout should be attached to\n */\n children:\n | React.ReactElement<any>\n | ((opts: {\n ref: (arg0: React.ElementRef<any> | HTMLElement) => void;\n toggle: () => void;\n show: () => void;\n hide: () => void;\n ariaProps: Record<string, any>;\n }) => React.ReactNode);\n\n /** How the popped-out content should be placed, in relationship to the children */\n placement?: EnumPlacements;\n\n /**\n * Should the popout be locked in place? This will prevent it from moving when the user scrolls or if the height of the popout changes.\n * This is useful for modals and other places where you want the popout to stay in place\n * after it has been opened but want to use an auto placement strategy.\n */\n lockPlacement?: boolean;\n\n /**\n * Should the popped-out content inherit its width from the children?\n * This is useful for typeaheads and other places where a popout needs to match the width of a given element.\n */\n fullWidth?: boolean;\n\n /**\n * When the popout has opened, should we focus on its content?\n * Focus will be brought inside by looking for elements with [autofocus] first, [tabindex] second and buttons/links/other natively-focusable elements last.\n * Upon closing the popout, focus will be returned to the popout's target.\n * If nothing within your popout's content is focusable, this prop will do nothing.\n */\n focusOnContent?: boolean;\n qa?: Record<string, string>;\n zIndex?: number;\n /** Used to override the default Popout animations.\n * Any props that are valid for use on a Motion div can be passed here as an object.\n * See https://motion.dev/docs/react-motion-component#props */\n animationConfig?: Omit<HTMLMotionProps<\"div\">, \"children\">;\n\n /**\n * Override react-popper per the API documentation here: https://github.com/FezVrasta/react-popper#api-documentation\n */\n popperProps?: Partial<PopperProps>;\n onClose?: () => void;\n onOpen?: () => void;\n\n /**\n * An optional callback to receive the scheduleUpdate function.\n * Use the function to recalculate the popout position in relation to the contents.\n */\n scheduleUpdateRef?: (arg0: () => void) => void;\n\n /**\n * Mount the popout at the bottom of the DOM (using React.Portal) instead of inside the current DOM tree\n */\n appendToBody?: boolean;\n\n /**\n * Override `FocusLock` props, see the API documentation for more details: https://github.com/theKashey/react-focus-lock#api\n */\n focusLockProps?: TypeFocusLockProps;\n}\n","import Popout from \"./Popout\";\n\nexport default Popout;\nexport { Popout };\nexport * from \"./PopoutTypes\";\n"],"mappings":";AAAA,YAAY,WAAW;AACvB,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAClE,SAAS,iBAAiB,cAAc;AACxC,OAAO,eAAe;AACtB,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sBACV,GAAG;AAAA,sBAEH;AAAA,+BAAO,YAAY,cAClB,QAAQ;AAAA,0BACN;AAAA,0BACA;AAAA,wBACF,CAAC;AAAA,wBACF,OAAO,YAAY,cAAc;AAAA;AAAA;AAAA,kBACpC;AAAA;AAAA,cACF;AAAA;AAAA,UAEJ;AAAA,QAEJ;AAAA;AAAA,IACF,GACF,GAEJ;AAAA,KAEJ;AAEJ;AAEA,IAAM,gBAAgB,CAAC,EAAE,UAAU,GAAG,KAAK,MACzC;AAAA,EAAC;AAAA;AAAA,IACC,IAAG;AAAA,IACH,OAAM;AAAA,IACN,QAAQ;AAAA,IACR,aAAY;AAAA,IACZ,cAAa;AAAA,IACb,WAAU;AAAA,IACV,GAAG;AAAA,IACH,GAAG;AAAA,IACF,GAAG;AAAA,IAEH;AAAA;AACH;AAGF,cAAc,cAAc;AAC5B,OAAO,UAAU;AAEjB,IAAO,iBAAQ;;;AElVf,OAAuB;;;ACCvB,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../../src/Popout.tsx","../../src/styles.ts","../../src/PopoutTypes.ts","../../src/index.ts"],"sourcesContent":["import * as React from \"react\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport FocusLock from \"react-focus-lock\";\nimport { Popper } from \"react-popper\";\nimport { MOTION_DURATION_FAST } from \"@sproutsocial/seeds-motion/unitless\";\nimport { useMutationObserver } from \"@sproutsocial/seeds-react-hooks\";\nimport Portal from \"@sproutsocial/seeds-react-portal\";\nimport Box, { type TypeBoxProps } from \"@sproutsocial/seeds-react-box\";\nimport { TargetWrapper } from \"./styles\";\nimport type { TypePopoutProps } from \"./PopoutTypes\";\n\nconst doesRefContainEventTarget = (\n ref: React.MutableRefObject<HTMLDivElement | undefined>,\n event: MouseEvent\n) => {\n return (\n ref.current &&\n event.target instanceof Node &&\n ref.current.contains(event.target)\n );\n};\n\nconst defaultAnimationConfig = {\n initial: { opacity: 0 },\n animate: { opacity: 1 },\n exit: { opacity: 0 },\n transition: {\n ease: \"circOut\",\n type: \"tween\",\n duration: process.env.NODE_ENV === \"test\" ? 0 : MOTION_DURATION_FAST,\n },\n};\n\nexport function Popout({\n isOpen,\n setIsOpen,\n content,\n children,\n placement = \"auto\",\n lockPlacement = false,\n fullWidth = false,\n zIndex = 7,\n focusOnContent = true,\n onOpen,\n onClose,\n qa = {},\n popperProps: { modifiers: popperModifiers, ...restPopperProps } = {},\n animationConfig = defaultAnimationConfig,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n scheduleUpdateRef = () => {},\n appendToBody = true,\n focusLockProps = {},\n color,\n \"aria-haspopup\": ariaHasPopup,\n disableWrapperAria = false,\n id,\n ...rest\n}: TypePopoutProps) {\n const PopoutComponentWrapper = appendToBody ? Portal : React.Fragment;\n const [isInternalShown, setIsInternalShown] = useState<boolean>(false);\n const [lockedPlacement, setLockedPlacement] = useState<\n typeof placement | undefined\n >();\n const isControlled = typeof isOpen === \"boolean\";\n const isShown = isControlled ? isOpen : isInternalShown;\n const setIsShown = useMemo(\n () => (isControlled && setIsOpen ? setIsOpen : setIsInternalShown),\n [isControlled, setIsOpen]\n );\n\n const targetRef = useRef<HTMLElement | any>();\n const popoutRef = useRef<HTMLDivElement>();\n\n // This callback will automatically trigger a recalculation of the popout position if the content is changed\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const scheduleUpdateCallback = useRef(() => {});\n\n useMutationObserver(\n popoutRef.current ?? null,\n {\n childList: true,\n characterData: true,\n subtree: true,\n },\n scheduleUpdateCallback.current\n );\n\n const {\n autoFocus = true,\n returnFocus = true,\n ...restFocusLockProps\n } = focusLockProps;\n\n const isInvalidContent = content === null || content === undefined;\n\n // Callbacks for showing, hiding, and toggling visibility of the popout\n // (Not used when isOpen is passed explicitly)\n const show = useCallback(() => setIsShown(true), [setIsShown]);\n const hide = useCallback(() => setIsShown(false), [setIsShown]);\n const toggle = useCallback(() => setIsShown(!isShown), [isShown, setIsShown]);\n\n useEffect(() => {\n const documentBody = document.body;\n\n if (isShown && documentBody) {\n // Callback passed to a click handler attached to document.body,\n // allowing user to close the popout by clicking outside\n const bodyClick = (e: MouseEvent): void => {\n if (\n doesRefContainEventTarget(targetRef, e) ||\n doesRefContainEventTarget(popoutRef, e)\n ) {\n return;\n }\n\n setIsShown(false, e);\n };\n\n // Callback for allowing user to close by keying \"esc\"\n const onEsc = (e: KeyboardEvent): void => {\n // older browsers use \"Esc\"\n if ([\"Escape\", \"Esc\"].includes(e.key)) {\n // stop propagation to avoid interacting with other components when popout is shown\n // ie if we have a popout shown in a modal and hit esc, we don't want to close both the popout and modal\n e.stopPropagation();\n setIsShown(false, e);\n }\n };\n\n documentBody.addEventListener(\"click\", bodyClick, { capture: true });\n documentBody.addEventListener(\"keydown\", onEsc, { capture: true });\n return () => {\n documentBody.removeEventListener(\"click\", bodyClick, { capture: true });\n documentBody.removeEventListener(\"keydown\", onEsc, { capture: true });\n };\n }\n }, [isShown, setIsShown]);\n\n const callbackStateRef = useRef({ calledFor: isShown });\n useEffect(() => {\n if (callbackStateRef.current.calledFor === isShown) {\n return;\n }\n\n callbackStateRef.current.calledFor = isShown;\n if (isShown) {\n onOpen?.();\n } else {\n onClose?.();\n }\n }, [isShown, onOpen, onClose]);\n\n // WAI-Aria properties for the popout trigger, disabled if necessary\n const ariaProps = useMemo(\n () =>\n disableWrapperAria\n ? {}\n : {\n \"aria-expanded\": isShown,\n \"aria-haspopup\": ariaHasPopup ? ariaHasPopup : true,\n },\n [isShown, ariaHasPopup, disableWrapperAria]\n );\n\n // In cases where a controlled popout is used (e.g. props.isOpen is true), we need\n // to wait for the targetRef to receive a value before rendering the popout. Otherwise,\n // the Popout component renders, but doesn't know how to position itself due the\n // `refereElement` property being undefined.\n const [shouldRenderPopout, setShouldRenderPopout] = useState<boolean>( // Only trigger this shouldRenderPopout logic when using a controlled component.\n // The reason for that is because controlled components may render the popout\n // immediately before the targetRef has a value set to it.\n !isControlled\n );\n\n // Reset the locked placement when the popout is closed\n useEffect(() => {\n if (!isShown && lockedPlacement) {\n setLockedPlacement(undefined);\n }\n }, [isShown, lockedPlacement]);\n\n const childrenRef = (el: React.ElementRef<any> | HTMLElement) => {\n targetRef.current = el;\n\n if (targetRef.current) {\n setShouldRenderPopout(true);\n }\n };\n\n return (\n <React.Fragment>\n {typeof children === \"function\" ? (\n children({\n ref: childrenRef,\n toggle,\n show,\n hide,\n ariaProps,\n })\n ) : (\n <TargetWrapper {...qa} id={id} {...rest} ref={childrenRef}>\n {React.cloneElement(children, {\n ...ariaProps,\n ...(!isControlled\n ? {\n onClick: toggle,\n }\n : undefined),\n })}\n </TargetWrapper>\n )}\n {shouldRenderPopout && !isInvalidContent && (\n <AnimatePresence>\n {isShown && (\n <PopoutComponentWrapper>\n <Popper\n referenceElement={targetRef.current}\n placement={\n lockPlacement && lockedPlacement ? lockedPlacement : placement\n }\n modifiers={{\n preventOverflow: {\n boundariesElement: \"viewport\",\n },\n // Disable flip after locking when lockPlacement is true\n flip: { enabled: !(lockPlacement && lockedPlacement) },\n ...popperModifiers,\n }}\n {...restPopperProps}\n >\n {({\n ref,\n style,\n placement: actualPlacement,\n outOfBoundaries,\n scheduleUpdate,\n }) => {\n // HACK: We use setTimeout to defer locking the placement until after render,\n // because Popper v1 only exposes the computed placement in the render prop,\n // and React does not allow setState during render.\n if (lockPlacement && !lockedPlacement && actualPlacement) {\n setTimeout(() => {\n // Check again before setting to avoid a race condition\n if (\n lockPlacement &&\n !lockedPlacement &&\n actualPlacement\n ) {\n setLockedPlacement(actualPlacement);\n }\n }, 0);\n }\n\n const interceptRef = (el: HTMLDivElement | undefined) => {\n popoutRef.current = el;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n ref(el);\n };\n\n scheduleUpdateCallback.current = scheduleUpdate;\n scheduleUpdateRef(scheduleUpdate);\n\n return (\n <div\n ref={interceptRef}\n style={{\n ...style,\n zIndex,\n width:\n fullWidth && targetRef.current\n ? targetRef.current.offsetWidth\n : \"initial\",\n }}\n data-placement={actualPlacement}\n data-qa-popout=\"\"\n data-qa-popout-isopen={isOpen === true}\n // TODO: fix this type since `color` should be valid here. TS can't resolve the correct type.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n color={color}\n {...rest}\n >\n {!outOfBoundaries && (\n <motion.div\n {...animationConfig}\n // pass the placement in the custom prop so it can be used in the animation\n custom={{\n placement: actualPlacement,\n ...animationConfig.custom,\n }}\n >\n <FocusLock\n autoFocus={autoFocus}\n returnFocus={returnFocus}\n disabled={!focusOnContent}\n {...restFocusLockProps}\n >\n {typeof content === \"function\" &&\n content({\n hide,\n actualPlacement,\n })}\n {typeof content !== \"function\" && content}\n </FocusLock>\n </motion.div>\n )}\n </div>\n );\n }}\n </Popper>\n </PopoutComponentWrapper>\n )}\n </AnimatePresence>\n )}\n </React.Fragment>\n );\n}\n\nconst PopoutContent = ({ children, ...rest }: TypeBoxProps) => (\n <Box\n bg=\"container.background.base\"\n color=\"text.body\"\n border={500}\n borderColor=\"container.border.base\"\n borderRadius=\"outer\"\n boxShadow=\"medium\"\n p={400}\n m={300}\n {...rest}\n >\n {children}\n </Box>\n);\n\nPopoutContent.displayName = \"Popout.Content\";\nPopout.Content = PopoutContent;\n\nexport default Popout;\n","import styled from \"styled-components\";\nimport { COMMON, LAYOUT } from \"@sproutsocial/seeds-react-system-props\";\n\nexport const TargetWrapper = styled.div`\n display: inline-block;\n ${COMMON}\n ${LAYOUT}\n`;\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from \"react\";\nimport type { PopperProps } from \"react-popper\";\nimport type {\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n TypeStyledComponentsCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\nimport type { HTMLMotionProps } from \"motion/react\";\n\nexport type EnumPlacements = Exclude<PopperProps[\"placement\"], undefined>;\n\nexport interface TypeFocusLockProps {\n disabled?: boolean;\n returnFocus?:\n | boolean\n | FocusOptions\n | ((returnTo: Element) => boolean | FocusOptions);\n persistentFocus?: boolean;\n autoFocus?: boolean;\n crossFrame?: boolean;\n noFocusGuards?: boolean | \"tail\";\n group?: string;\n className?: string;\n onActivation?: (node: HTMLElement) => void;\n onDeactivation?: (node: HTMLElement) => void;\n as?: TypeStyledComponentsCommonProps[\"as\"];\n lockProps?: any;\n ref?: any;\n whiteList?: (activeElement: HTMLElement) => boolean;\n shards?: Array<any>;\n children?: React.ReactNode;\n}\n\nexport interface TypePopoutProps\n extends TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n Omit<\n React.ComponentPropsWithoutRef<\"div\">,\n \"color\" | \"children\" | \"content\"\n > {\n /**\n * Whether Popout should automatically add aria-attributes to its wrapped elements\n */\n disableWrapperAria?: boolean;\n /**\n * Is the popout open? This prop is optional. By using it, you will lose some automatic handling of the logic for opening and closing the popout.\n */\n isOpen?: boolean;\n\n /**\n * If you use the isOpen prop you will need to pass a handler to change the state of the popout\n */\n setIsOpen?: (isOpen: boolean, event?: MouseEvent | KeyboardEvent) => void;\n\n /**\n * The content to be shown in the popout. If there is no content, just the children are rendered\n */\n content:\n | (React.ReactElement<any> | null | undefined)\n | (\n | ((opts: {\n hide: () => void;\n actualPlacement: EnumPlacements;\n }) => React.ReactElement<any>)\n | null\n | undefined\n );\n\n /**\n * The content that the popout should be attached to\n */\n children:\n | React.ReactElement<any>\n | ((opts: {\n ref: (arg0: React.ElementRef<any> | HTMLElement) => void;\n toggle: () => void;\n show: () => void;\n hide: () => void;\n ariaProps: Record<string, any>;\n }) => React.ReactNode);\n\n /** How the popped-out content should be placed, in relationship to the children */\n placement?: EnumPlacements;\n\n /**\n * Should the popout be locked in place? This will prevent it from moving when the user scrolls or if the height of the popout changes.\n * This is useful for modals and other places where you want the popout to stay in place\n * after it has been opened but want to use an auto placement strategy.\n */\n lockPlacement?: boolean;\n\n /**\n * Should the popped-out content inherit its width from the children?\n * This is useful for typeaheads and other places where a popout needs to match the width of a given element.\n */\n fullWidth?: boolean;\n\n /**\n * When the popout has opened, should we focus on its content?\n * Focus will be brought inside by looking for elements with [autofocus] first, [tabindex] second and buttons/links/other natively-focusable elements last.\n * Upon closing the popout, focus will be returned to the popout's target.\n * If nothing within your popout's content is focusable, this prop will do nothing.\n */\n focusOnContent?: boolean;\n qa?: Record<string, string>;\n zIndex?: number;\n /** Used to override the default Popout animations.\n * Any props that are valid for use on a Motion div can be passed here as an object.\n * See https://motion.dev/docs/react-motion-component#props */\n animationConfig?: Omit<HTMLMotionProps<\"div\">, \"children\">;\n\n /**\n * Override react-popper per the API documentation here: https://github.com/FezVrasta/react-popper#api-documentation\n */\n popperProps?: Partial<PopperProps>;\n onClose?: () => void;\n onOpen?: () => void;\n\n /**\n * An optional callback to receive the scheduleUpdate function.\n * Use the function to recalculate the popout position in relation to the contents.\n */\n scheduleUpdateRef?: (arg0: () => void) => void;\n\n /**\n * Mount the popout at the bottom of the DOM (using React.Portal) instead of inside the current DOM tree\n */\n appendToBody?: boolean;\n\n /**\n * Override `FocusLock` props, see the API documentation for more details: https://github.com/theKashey/react-focus-lock#api\n */\n focusLockProps?: TypeFocusLockProps;\n}\n","import Popout from \"./Popout\";\n\nexport default Popout;\nexport { Popout };\nexport * from \"./PopoutTypes\";\nexport { Popout as PopoutV2 } from \"./v2\";\nexport type { TypePopoutProps as TypePopoutV2Props } from \"./v2/PopoutTypes\";\n"],"mappings":";;;;;AAAA,YAAY,WAAW;AACvB,SAAS,aAAa,WAAW,SAAS,QAAQ,gBAAgB;AAClE,SAAS,iBAAiB,cAAc;AACxC,OAAO,eAAe;AACtB,SAAS,cAAc;AACvB,SAAS,4BAA4B;AACrC,SAAS,2BAA2B;AACpC,OAAO,YAAY;AACnB,OAAO,SAAgC;;;ACRvC,OAAO,YAAY;AACnB,SAAS,QAAQ,cAAc;AAExB,IAAM,gBAAgB,OAAO;AAAA;AAAA,IAEhC,MAAM;AAAA,IACN,MAAM;AAAA;;;ADmMF,cA4F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GAEJ;AAAA,KAEJ;AAEJ;AAEA,IAAM,gBAAgB,CAAC,EAAE,UAAU,GAAG,KAAK,MACzC;AAAA,EAAC;AAAA;AAAA,IACC,IAAG;AAAA,IACH,OAAM;AAAA,IACN,QAAQ;AAAA,IACR,aAAY;AAAA,IACZ,cAAa;AAAA,IACb,WAAU;AAAA,IACV,GAAG;AAAA,IACH,GAAG;AAAA,IACF,GAAG;AAAA,IAEH;AAAA;AACH;AAGF,cAAc,cAAc;AAC5BA,QAAO,UAAU;AAEjB,IAAO,iBAAQA;;;AElVf,OAAuB;;;ACCvB,IAAO,cAAQ;","names":["Popout"]}
@@ -0,0 +1,7 @@
1
+ import {
2
+ Popout
3
+ } from "../chunk-KPXAE7KF.js";
4
+ export {
5
+ Popout
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/dist/index.d.mts CHANGED
@@ -4,6 +4,7 @@ import * as React from 'react';
4
4
  import { PopperProps } from 'react-popper';
5
5
  import { TypeStyledComponentsCommonProps, TypeSystemCommonProps, TypeSystemLayoutProps } from '@sproutsocial/seeds-react-system-props';
6
6
  import { HTMLMotionProps } from 'motion/react';
7
+ export { Popout as PopoutV2, TypePopoutProps as TypePopoutV2Props } from './v2/index.mjs';
7
8
 
8
9
  type EnumPlacements = Exclude<PopperProps["placement"], undefined>;
9
10
  interface TypeFocusLockProps {
package/dist/index.d.ts CHANGED
@@ -4,6 +4,7 @@ import * as React from 'react';
4
4
  import { PopperProps } from 'react-popper';
5
5
  import { TypeStyledComponentsCommonProps, TypeSystemCommonProps, TypeSystemLayoutProps } from '@sproutsocial/seeds-react-system-props';
6
6
  import { HTMLMotionProps } from 'motion/react';
7
+ export { Popout as PopoutV2, TypePopoutProps as TypePopoutV2Props } from './v2/index.js';
7
8
 
8
9
  type EnumPlacements = Exclude<PopperProps["placement"], undefined>;
9
10
  interface TypeFocusLockProps {
package/dist/index.js CHANGED
@@ -28,12 +28,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
33
  Popout: () => Popout_default,
34
- default: () => index_default
34
+ PopoutV2: () => Popout2,
35
+ default: () => src_default
35
36
  });
36
- module.exports = __toCommonJS(index_exports);
37
+ module.exports = __toCommonJS(src_exports);
37
38
 
38
39
  // src/Popout.tsx
39
40
  var React = __toESM(require("react"));
@@ -302,10 +303,85 @@ var Popout_default = Popout;
302
303
  // src/PopoutTypes.ts
303
304
  var React2 = require("react");
304
305
 
306
+ // src/v2/Popout.tsx
307
+ var React3 = __toESM(require("react"));
308
+ var import_react3 = require("motion/react");
309
+ var Popover = __toESM(require("@radix-ui/react-popover"));
310
+ var import_unitless2 = require("@sproutsocial/seeds-motion/unitless");
311
+ var import_styled_components2 = __toESM(require("styled-components"));
312
+ var import_jsx_runtime2 = require("react/jsx-runtime");
313
+ var defaultAnimationConfig2 = {
314
+ initial: { opacity: 0 },
315
+ animate: { opacity: 1 },
316
+ exit: { opacity: 0 },
317
+ transition: {
318
+ ease: "circOut",
319
+ type: "tween",
320
+ duration: process.env.NODE_ENV === "test" ? 0 : import_unitless2.MOTION_DURATION_FAST
321
+ }
322
+ };
323
+ var StyledMotionDiv = (0, import_styled_components2.default)(import_react3.motion.div)`
324
+ background-color: ${({ theme }) => theme.colors.container.background.base};
325
+ border: ${({ theme }) => theme.borders[500]};
326
+ border-color: ${({ theme }) => theme.colors.container.border.base};
327
+ border-radius: ${({ theme }) => theme.radii[500]};
328
+ box-shadow: ${({ theme }) => theme.shadows.medium};
329
+ padding: ${({ theme }) => theme.space[400]};
330
+ `;
331
+ function Popout2({
332
+ children,
333
+ content,
334
+ open,
335
+ defaultOpen,
336
+ onOpenChange,
337
+ animationConfig = defaultAnimationConfig2,
338
+ side = "bottom",
339
+ sideOffset = 8,
340
+ align = "center",
341
+ alignOffset = 0,
342
+ onOpenAutoFocus,
343
+ onEscapeKeyDown,
344
+ onCloseAutoFocus,
345
+ ...rest
346
+ }) {
347
+ const [isOpen, setIsOpen] = React3.useState(defaultOpen ?? false);
348
+ const handleOpenChange = React3.useCallback(
349
+ (newOpen) => {
350
+ setIsOpen(newOpen);
351
+ onOpenChange?.(newOpen);
352
+ },
353
+ [onOpenChange]
354
+ );
355
+ const isControlled = open !== void 0;
356
+ const popoverOpen = isControlled ? open : isOpen;
357
+ const popoverOnOpenChange = isControlled ? onOpenChange : handleOpenChange;
358
+ const radixRef = React3.useRef(null);
359
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Popover.Root, { open: popoverOpen, onOpenChange: popoverOnOpenChange, children: [
360
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Popover.Trigger, { ref: radixRef, asChild: true, children }),
361
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Popover.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
362
+ Popover.Content,
363
+ {
364
+ side,
365
+ sideOffset,
366
+ align,
367
+ alignOffset,
368
+ onOpenAutoFocus,
369
+ onEscapeKeyDown,
370
+ onCloseAutoFocus,
371
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(StyledMotionDiv, { ...animationConfig, ...rest, children: content })
372
+ }
373
+ ) })
374
+ ] });
375
+ }
376
+
377
+ // src/v2/PopoutTypes.ts
378
+ var React4 = require("react");
379
+
305
380
  // src/index.ts
306
- var index_default = Popout_default;
381
+ var src_default = Popout_default;
307
382
  // Annotate the CommonJS export names for ESM import in node:
308
383
  0 && (module.exports = {
309
- Popout
384
+ Popout,
385
+ PopoutV2
310
386
  });
311
387
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/Popout.tsx","../src/styles.ts","../src/PopoutTypes.ts"],"sourcesContent":["import Popout from \"./Popout\";\n\nexport default Popout;\nexport { Popout };\nexport * from \"./PopoutTypes\";\n","import * as React from \"react\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport FocusLock from \"react-focus-lock\";\nimport { Popper } from \"react-popper\";\nimport { MOTION_DURATION_FAST } from \"@sproutsocial/seeds-motion/unitless\";\nimport { useMutationObserver } from \"@sproutsocial/seeds-react-hooks\";\nimport Portal from \"@sproutsocial/seeds-react-portal\";\nimport Box, { type TypeBoxProps } from \"@sproutsocial/seeds-react-box\";\nimport { TargetWrapper } from \"./styles\";\nimport type { TypePopoutProps } from \"./PopoutTypes\";\n\nconst doesRefContainEventTarget = (\n ref: React.MutableRefObject<HTMLDivElement | undefined>,\n event: MouseEvent\n) => {\n return (\n ref.current &&\n event.target instanceof Node &&\n ref.current.contains(event.target)\n );\n};\n\nconst defaultAnimationConfig = {\n initial: { opacity: 0 },\n animate: { opacity: 1 },\n exit: { opacity: 0 },\n transition: {\n ease: \"circOut\",\n type: \"tween\",\n duration: process.env.NODE_ENV === \"test\" ? 0 : MOTION_DURATION_FAST,\n },\n};\n\nexport function Popout({\n isOpen,\n setIsOpen,\n content,\n children,\n placement = \"auto\",\n lockPlacement = false,\n fullWidth = false,\n zIndex = 7,\n focusOnContent = true,\n onOpen,\n onClose,\n qa = {},\n popperProps: { modifiers: popperModifiers, ...restPopperProps } = {},\n animationConfig = defaultAnimationConfig,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n scheduleUpdateRef = () => {},\n appendToBody = true,\n focusLockProps = {},\n color,\n \"aria-haspopup\": ariaHasPopup,\n disableWrapperAria = false,\n id,\n ...rest\n}: TypePopoutProps) {\n const PopoutComponentWrapper = appendToBody ? Portal : React.Fragment;\n const [isInternalShown, setIsInternalShown] = useState<boolean>(false);\n const [lockedPlacement, setLockedPlacement] = useState<\n typeof placement | undefined\n >();\n const isControlled = typeof isOpen === \"boolean\";\n const isShown = isControlled ? isOpen : isInternalShown;\n const setIsShown = useMemo(\n () => (isControlled && setIsOpen ? setIsOpen : setIsInternalShown),\n [isControlled, setIsOpen]\n );\n\n const targetRef = useRef<HTMLElement | any>();\n const popoutRef = useRef<HTMLDivElement>();\n\n // This callback will automatically trigger a recalculation of the popout position if the content is changed\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const scheduleUpdateCallback = useRef(() => {});\n\n useMutationObserver(\n popoutRef.current ?? null,\n {\n childList: true,\n characterData: true,\n subtree: true,\n },\n scheduleUpdateCallback.current\n );\n\n const {\n autoFocus = true,\n returnFocus = true,\n ...restFocusLockProps\n } = focusLockProps;\n\n const isInvalidContent = content === null || content === undefined;\n\n // Callbacks for showing, hiding, and toggling visibility of the popout\n // (Not used when isOpen is passed explicitly)\n const show = useCallback(() => setIsShown(true), [setIsShown]);\n const hide = useCallback(() => setIsShown(false), [setIsShown]);\n const toggle = useCallback(() => setIsShown(!isShown), [isShown, setIsShown]);\n\n useEffect(() => {\n const documentBody = document.body;\n\n if (isShown && documentBody) {\n // Callback passed to a click handler attached to document.body,\n // allowing user to close the popout by clicking outside\n const bodyClick = (e: MouseEvent): void => {\n if (\n doesRefContainEventTarget(targetRef, e) ||\n doesRefContainEventTarget(popoutRef, e)\n ) {\n return;\n }\n\n setIsShown(false, e);\n };\n\n // Callback for allowing user to close by keying \"esc\"\n const onEsc = (e: KeyboardEvent): void => {\n // older browsers use \"Esc\"\n if ([\"Escape\", \"Esc\"].includes(e.key)) {\n // stop propagation to avoid interacting with other components when popout is shown\n // ie if we have a popout shown in a modal and hit esc, we don't want to close both the popout and modal\n e.stopPropagation();\n setIsShown(false, e);\n }\n };\n\n documentBody.addEventListener(\"click\", bodyClick, { capture: true });\n documentBody.addEventListener(\"keydown\", onEsc, { capture: true });\n return () => {\n documentBody.removeEventListener(\"click\", bodyClick, { capture: true });\n documentBody.removeEventListener(\"keydown\", onEsc, { capture: true });\n };\n }\n }, [isShown, setIsShown]);\n\n const callbackStateRef = useRef({ calledFor: isShown });\n useEffect(() => {\n if (callbackStateRef.current.calledFor === isShown) {\n return;\n }\n\n callbackStateRef.current.calledFor = isShown;\n if (isShown) {\n onOpen?.();\n } else {\n onClose?.();\n }\n }, [isShown, onOpen, onClose]);\n\n // WAI-Aria properties for the popout trigger, disabled if necessary\n const ariaProps = useMemo(\n () =>\n disableWrapperAria\n ? {}\n : {\n \"aria-expanded\": isShown,\n \"aria-haspopup\": ariaHasPopup ? ariaHasPopup : true,\n },\n [isShown, ariaHasPopup, disableWrapperAria]\n );\n\n // In cases where a controlled popout is used (e.g. props.isOpen is true), we need\n // to wait for the targetRef to receive a value before rendering the popout. Otherwise,\n // the Popout component renders, but doesn't know how to position itself due the\n // `refereElement` property being undefined.\n const [shouldRenderPopout, setShouldRenderPopout] = useState<boolean>( // Only trigger this shouldRenderPopout logic when using a controlled component.\n // The reason for that is because controlled components may render the popout\n // immediately before the targetRef has a value set to it.\n !isControlled\n );\n\n // Reset the locked placement when the popout is closed\n useEffect(() => {\n if (!isShown && lockedPlacement) {\n setLockedPlacement(undefined);\n }\n }, [isShown, lockedPlacement]);\n\n const childrenRef = (el: React.ElementRef<any> | HTMLElement) => {\n targetRef.current = el;\n\n if (targetRef.current) {\n setShouldRenderPopout(true);\n }\n };\n\n return (\n <React.Fragment>\n {typeof children === \"function\" ? (\n children({\n ref: childrenRef,\n toggle,\n show,\n hide,\n ariaProps,\n })\n ) : (\n <TargetWrapper {...qa} id={id} {...rest} ref={childrenRef}>\n {React.cloneElement(children, {\n ...ariaProps,\n ...(!isControlled\n ? {\n onClick: toggle,\n }\n : undefined),\n })}\n </TargetWrapper>\n )}\n {shouldRenderPopout && !isInvalidContent && (\n <AnimatePresence>\n {isShown && (\n <PopoutComponentWrapper>\n <Popper\n referenceElement={targetRef.current}\n placement={\n lockPlacement && lockedPlacement ? lockedPlacement : placement\n }\n modifiers={{\n preventOverflow: {\n boundariesElement: \"viewport\",\n },\n // Disable flip after locking when lockPlacement is true\n flip: { enabled: !(lockPlacement && lockedPlacement) },\n ...popperModifiers,\n }}\n {...restPopperProps}\n >\n {({\n ref,\n style,\n placement: actualPlacement,\n outOfBoundaries,\n scheduleUpdate,\n }) => {\n // HACK: We use setTimeout to defer locking the placement until after render,\n // because Popper v1 only exposes the computed placement in the render prop,\n // and React does not allow setState during render.\n if (lockPlacement && !lockedPlacement && actualPlacement) {\n setTimeout(() => {\n // Check again before setting to avoid a race condition\n if (\n lockPlacement &&\n !lockedPlacement &&\n actualPlacement\n ) {\n setLockedPlacement(actualPlacement);\n }\n }, 0);\n }\n\n const interceptRef = (el: HTMLDivElement | undefined) => {\n popoutRef.current = el;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n ref(el);\n };\n\n scheduleUpdateCallback.current = scheduleUpdate;\n scheduleUpdateRef(scheduleUpdate);\n\n return (\n <div\n ref={interceptRef}\n style={{\n ...style,\n zIndex,\n width:\n fullWidth && targetRef.current\n ? targetRef.current.offsetWidth\n : \"initial\",\n }}\n data-placement={actualPlacement}\n data-qa-popout=\"\"\n data-qa-popout-isopen={isOpen === true}\n // TODO: fix this type since `color` should be valid here. TS can't resolve the correct type.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n color={color}\n {...rest}\n >\n {!outOfBoundaries && (\n <motion.div\n {...animationConfig}\n // pass the placement in the custom prop so it can be used in the animation\n custom={{\n placement: actualPlacement,\n ...animationConfig.custom,\n }}\n >\n <FocusLock\n autoFocus={autoFocus}\n returnFocus={returnFocus}\n disabled={!focusOnContent}\n {...restFocusLockProps}\n >\n {typeof content === \"function\" &&\n content({\n hide,\n actualPlacement,\n })}\n {typeof content !== \"function\" && content}\n </FocusLock>\n </motion.div>\n )}\n </div>\n );\n }}\n </Popper>\n </PopoutComponentWrapper>\n )}\n </AnimatePresence>\n )}\n </React.Fragment>\n );\n}\n\nconst PopoutContent = ({ children, ...rest }: TypeBoxProps) => (\n <Box\n bg=\"container.background.base\"\n color=\"text.body\"\n border={500}\n borderColor=\"container.border.base\"\n borderRadius=\"outer\"\n boxShadow=\"medium\"\n p={400}\n m={300}\n {...rest}\n >\n {children}\n </Box>\n);\n\nPopoutContent.displayName = \"Popout.Content\";\nPopout.Content = PopoutContent;\n\nexport default Popout;\n","import styled from \"styled-components\";\nimport { COMMON, LAYOUT } from \"@sproutsocial/seeds-react-system-props\";\n\nexport const TargetWrapper = styled.div`\n display: inline-block;\n ${COMMON}\n ${LAYOUT}\n`;\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from \"react\";\nimport type { PopperProps } from \"react-popper\";\nimport type {\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n TypeStyledComponentsCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\nimport type { HTMLMotionProps } from \"motion/react\";\n\nexport type EnumPlacements = Exclude<PopperProps[\"placement\"], undefined>;\n\nexport interface TypeFocusLockProps {\n disabled?: boolean;\n returnFocus?:\n | boolean\n | FocusOptions\n | ((returnTo: Element) => boolean | FocusOptions);\n persistentFocus?: boolean;\n autoFocus?: boolean;\n crossFrame?: boolean;\n noFocusGuards?: boolean | \"tail\";\n group?: string;\n className?: string;\n onActivation?: (node: HTMLElement) => void;\n onDeactivation?: (node: HTMLElement) => void;\n as?: TypeStyledComponentsCommonProps[\"as\"];\n lockProps?: any;\n ref?: any;\n whiteList?: (activeElement: HTMLElement) => boolean;\n shards?: Array<any>;\n children?: React.ReactNode;\n}\n\nexport interface TypePopoutProps\n extends TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n Omit<\n React.ComponentPropsWithoutRef<\"div\">,\n \"color\" | \"children\" | \"content\"\n > {\n /**\n * Whether Popout should automatically add aria-attributes to its wrapped elements\n */\n disableWrapperAria?: boolean;\n /**\n * Is the popout open? This prop is optional. By using it, you will lose some automatic handling of the logic for opening and closing the popout.\n */\n isOpen?: boolean;\n\n /**\n * If you use the isOpen prop you will need to pass a handler to change the state of the popout\n */\n setIsOpen?: (isOpen: boolean, event?: MouseEvent | KeyboardEvent) => void;\n\n /**\n * The content to be shown in the popout. If there is no content, just the children are rendered\n */\n content:\n | (React.ReactElement<any> | null | undefined)\n | (\n | ((opts: {\n hide: () => void;\n actualPlacement: EnumPlacements;\n }) => React.ReactElement<any>)\n | null\n | undefined\n );\n\n /**\n * The content that the popout should be attached to\n */\n children:\n | React.ReactElement<any>\n | ((opts: {\n ref: (arg0: React.ElementRef<any> | HTMLElement) => void;\n toggle: () => void;\n show: () => void;\n hide: () => void;\n ariaProps: Record<string, any>;\n }) => React.ReactNode);\n\n /** How the popped-out content should be placed, in relationship to the children */\n placement?: EnumPlacements;\n\n /**\n * Should the popout be locked in place? This will prevent it from moving when the user scrolls or if the height of the popout changes.\n * This is useful for modals and other places where you want the popout to stay in place\n * after it has been opened but want to use an auto placement strategy.\n */\n lockPlacement?: boolean;\n\n /**\n * Should the popped-out content inherit its width from the children?\n * This is useful for typeaheads and other places where a popout needs to match the width of a given element.\n */\n fullWidth?: boolean;\n\n /**\n * When the popout has opened, should we focus on its content?\n * Focus will be brought inside by looking for elements with [autofocus] first, [tabindex] second and buttons/links/other natively-focusable elements last.\n * Upon closing the popout, focus will be returned to the popout's target.\n * If nothing within your popout's content is focusable, this prop will do nothing.\n */\n focusOnContent?: boolean;\n qa?: Record<string, string>;\n zIndex?: number;\n /** Used to override the default Popout animations.\n * Any props that are valid for use on a Motion div can be passed here as an object.\n * See https://motion.dev/docs/react-motion-component#props */\n animationConfig?: Omit<HTMLMotionProps<\"div\">, \"children\">;\n\n /**\n * Override react-popper per the API documentation here: https://github.com/FezVrasta/react-popper#api-documentation\n */\n popperProps?: Partial<PopperProps>;\n onClose?: () => void;\n onOpen?: () => void;\n\n /**\n * An optional callback to receive the scheduleUpdate function.\n * Use the function to recalculate the popout position in relation to the contents.\n */\n scheduleUpdateRef?: (arg0: () => void) => void;\n\n /**\n * Mount the popout at the bottom of the DOM (using React.Portal) instead of inside the current DOM tree\n */\n appendToBody?: boolean;\n\n /**\n * Override `FocusLock` props, see the API documentation for more details: https://github.com/theKashey/react-focus-lock#api\n */\n focusLockProps?: TypeFocusLockProps;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,mBAAkE;AAClE,IAAAA,gBAAwC;AACxC,8BAAsB;AACtB,0BAAuB;AACvB,sBAAqC;AACrC,+BAAoC;AACpC,gCAAmB;AACnB,6BAAuC;;;ACRvC,+BAAmB;AACnB,sCAA+B;AAExB,IAAM,gBAAgB,yBAAAC,QAAO;AAAA;AAAA,IAEhC,sCAAM;AAAA,IACN,sCAAM;AAAA;;;ADmMF;AA7LR,IAAM,4BAA4B,CAChC,KACA,UACG;AACH,SACE,IAAI,WACJ,MAAM,kBAAkB,QACxB,IAAI,QAAQ,SAAS,MAAM,MAAM;AAErC;AAEA,IAAM,yBAAyB;AAAA,EAC7B,SAAS,EAAE,SAAS,EAAE;AAAA,EACtB,SAAS,EAAE,SAAS,EAAE;AAAA,EACtB,MAAM,EAAE,SAAS,EAAE;AAAA,EACnB,YAAY;AAAA,IACV,MAAM;AAAA,IACN,MAAM;AAAA,IACN,UAAU,QAAQ,IAAI,aAAa,SAAS,IAAI;AAAA,EAClD;AACF;AAEO,SAAS,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EACA,KAAK,CAAC;AAAA,EACN,aAAa,EAAE,WAAW,iBAAiB,GAAG,gBAAgB,IAAI,CAAC;AAAA,EACnE,kBAAkB;AAAA;AAAA,EAElB,oBAAoB,MAAM;AAAA,EAAC;AAAA,EAC3B,eAAe;AAAA,EACf,iBAAiB,CAAC;AAAA,EAClB;AAAA,EACA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IlC;AAAA,cACC,GAAG;AAAA,cAEH,WAAC,mBACA;AAAA,gBAAC,qBAAO;AAAA,gBAAP;AAAA,kBACE,GAAG;AAAA,kBAEJ,QAAQ;AAAA,oBACN,WAAW;AAAA,oBACX,GAAG,gBAAgB;AAAA,kBACrB;AAAA,kBAEA;AAAA,oBAAC,wBAAAC;AAAA,oBAAA;AAAA,sBACC;AAAA,sBACA;AAAA,sBACA,UAAU,CAAC;AAAA,sBACV,GAAG;AAAA,sBAEH;AAAA,+BAAO,YAAY,cAClB,QAAQ;AAAA,0BACN;AAAA,0BACA;AAAA,wBACF,CAAC;AAAA,wBACF,OAAO,YAAY,cAAc;AAAA;AAAA;AAAA,kBACpC;AAAA;AAAA,cACF;AAAA;AAAA,UAEJ;AAAA,QAEJ;AAAA;AAAA,IACF,GACF,GAEJ;AAAA,KAEJ;AAEJ;AAEA,IAAM,gBAAgB,CAAC,EAAE,UAAU,GAAG,KAAK,MACzC;AAAA,EAAC,uBAAAC;AAAA,EAAA;AAAA,IACC,IAAG;AAAA,IACH,OAAM;AAAA,IACN,QAAQ;AAAA,IACR,aAAY;AAAA,IACZ,cAAa;AAAA,IACb,WAAU;AAAA,IACV,GAAG;AAAA,IACH,GAAG;AAAA,IACF,GAAG;AAAA,IAEH;AAAA;AACH;AAGF,cAAc,cAAc;AAC5B,OAAO,UAAU;AAEjB,IAAO,iBAAQ;;;AElVf,IAAAC,SAAuB;;;AHCvB,IAAO,gBAAQ;","names":["import_react","styled","Portal","FocusLock","Box","React"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/Popout.tsx","../src/styles.ts","../src/PopoutTypes.ts","../src/v2/Popout.tsx","../src/v2/PopoutTypes.ts"],"sourcesContent":["import Popout from \"./Popout\";\n\nexport default Popout;\nexport { Popout };\nexport * from \"./PopoutTypes\";\nexport { Popout as PopoutV2 } from \"./v2\";\nexport type { TypePopoutProps as TypePopoutV2Props } from \"./v2/PopoutTypes\";\n","import * as React from \"react\";\nimport { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport FocusLock from \"react-focus-lock\";\nimport { Popper } from \"react-popper\";\nimport { MOTION_DURATION_FAST } from \"@sproutsocial/seeds-motion/unitless\";\nimport { useMutationObserver } from \"@sproutsocial/seeds-react-hooks\";\nimport Portal from \"@sproutsocial/seeds-react-portal\";\nimport Box, { type TypeBoxProps } from \"@sproutsocial/seeds-react-box\";\nimport { TargetWrapper } from \"./styles\";\nimport type { TypePopoutProps } from \"./PopoutTypes\";\n\nconst doesRefContainEventTarget = (\n ref: React.MutableRefObject<HTMLDivElement | undefined>,\n event: MouseEvent\n) => {\n return (\n ref.current &&\n event.target instanceof Node &&\n ref.current.contains(event.target)\n );\n};\n\nconst defaultAnimationConfig = {\n initial: { opacity: 0 },\n animate: { opacity: 1 },\n exit: { opacity: 0 },\n transition: {\n ease: \"circOut\",\n type: \"tween\",\n duration: process.env.NODE_ENV === \"test\" ? 0 : MOTION_DURATION_FAST,\n },\n};\n\nexport function Popout({\n isOpen,\n setIsOpen,\n content,\n children,\n placement = \"auto\",\n lockPlacement = false,\n fullWidth = false,\n zIndex = 7,\n focusOnContent = true,\n onOpen,\n onClose,\n qa = {},\n popperProps: { modifiers: popperModifiers, ...restPopperProps } = {},\n animationConfig = defaultAnimationConfig,\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n scheduleUpdateRef = () => {},\n appendToBody = true,\n focusLockProps = {},\n color,\n \"aria-haspopup\": ariaHasPopup,\n disableWrapperAria = false,\n id,\n ...rest\n}: TypePopoutProps) {\n const PopoutComponentWrapper = appendToBody ? Portal : React.Fragment;\n const [isInternalShown, setIsInternalShown] = useState<boolean>(false);\n const [lockedPlacement, setLockedPlacement] = useState<\n typeof placement | undefined\n >();\n const isControlled = typeof isOpen === \"boolean\";\n const isShown = isControlled ? isOpen : isInternalShown;\n const setIsShown = useMemo(\n () => (isControlled && setIsOpen ? setIsOpen : setIsInternalShown),\n [isControlled, setIsOpen]\n );\n\n const targetRef = useRef<HTMLElement | any>();\n const popoutRef = useRef<HTMLDivElement>();\n\n // This callback will automatically trigger a recalculation of the popout position if the content is changed\n // eslint-disable-next-line @typescript-eslint/no-empty-function\n const scheduleUpdateCallback = useRef(() => {});\n\n useMutationObserver(\n popoutRef.current ?? null,\n {\n childList: true,\n characterData: true,\n subtree: true,\n },\n scheduleUpdateCallback.current\n );\n\n const {\n autoFocus = true,\n returnFocus = true,\n ...restFocusLockProps\n } = focusLockProps;\n\n const isInvalidContent = content === null || content === undefined;\n\n // Callbacks for showing, hiding, and toggling visibility of the popout\n // (Not used when isOpen is passed explicitly)\n const show = useCallback(() => setIsShown(true), [setIsShown]);\n const hide = useCallback(() => setIsShown(false), [setIsShown]);\n const toggle = useCallback(() => setIsShown(!isShown), [isShown, setIsShown]);\n\n useEffect(() => {\n const documentBody = document.body;\n\n if (isShown && documentBody) {\n // Callback passed to a click handler attached to document.body,\n // allowing user to close the popout by clicking outside\n const bodyClick = (e: MouseEvent): void => {\n if (\n doesRefContainEventTarget(targetRef, e) ||\n doesRefContainEventTarget(popoutRef, e)\n ) {\n return;\n }\n\n setIsShown(false, e);\n };\n\n // Callback for allowing user to close by keying \"esc\"\n const onEsc = (e: KeyboardEvent): void => {\n // older browsers use \"Esc\"\n if ([\"Escape\", \"Esc\"].includes(e.key)) {\n // stop propagation to avoid interacting with other components when popout is shown\n // ie if we have a popout shown in a modal and hit esc, we don't want to close both the popout and modal\n e.stopPropagation();\n setIsShown(false, e);\n }\n };\n\n documentBody.addEventListener(\"click\", bodyClick, { capture: true });\n documentBody.addEventListener(\"keydown\", onEsc, { capture: true });\n return () => {\n documentBody.removeEventListener(\"click\", bodyClick, { capture: true });\n documentBody.removeEventListener(\"keydown\", onEsc, { capture: true });\n };\n }\n }, [isShown, setIsShown]);\n\n const callbackStateRef = useRef({ calledFor: isShown });\n useEffect(() => {\n if (callbackStateRef.current.calledFor === isShown) {\n return;\n }\n\n callbackStateRef.current.calledFor = isShown;\n if (isShown) {\n onOpen?.();\n } else {\n onClose?.();\n }\n }, [isShown, onOpen, onClose]);\n\n // WAI-Aria properties for the popout trigger, disabled if necessary\n const ariaProps = useMemo(\n () =>\n disableWrapperAria\n ? {}\n : {\n \"aria-expanded\": isShown,\n \"aria-haspopup\": ariaHasPopup ? ariaHasPopup : true,\n },\n [isShown, ariaHasPopup, disableWrapperAria]\n );\n\n // In cases where a controlled popout is used (e.g. props.isOpen is true), we need\n // to wait for the targetRef to receive a value before rendering the popout. Otherwise,\n // the Popout component renders, but doesn't know how to position itself due the\n // `refereElement` property being undefined.\n const [shouldRenderPopout, setShouldRenderPopout] = useState<boolean>( // Only trigger this shouldRenderPopout logic when using a controlled component.\n // The reason for that is because controlled components may render the popout\n // immediately before the targetRef has a value set to it.\n !isControlled\n );\n\n // Reset the locked placement when the popout is closed\n useEffect(() => {\n if (!isShown && lockedPlacement) {\n setLockedPlacement(undefined);\n }\n }, [isShown, lockedPlacement]);\n\n const childrenRef = (el: React.ElementRef<any> | HTMLElement) => {\n targetRef.current = el;\n\n if (targetRef.current) {\n setShouldRenderPopout(true);\n }\n };\n\n return (\n <React.Fragment>\n {typeof children === \"function\" ? (\n children({\n ref: childrenRef,\n toggle,\n show,\n hide,\n ariaProps,\n })\n ) : (\n <TargetWrapper {...qa} id={id} {...rest} ref={childrenRef}>\n {React.cloneElement(children, {\n ...ariaProps,\n ...(!isControlled\n ? {\n onClick: toggle,\n }\n : undefined),\n })}\n </TargetWrapper>\n )}\n {shouldRenderPopout && !isInvalidContent && (\n <AnimatePresence>\n {isShown && (\n <PopoutComponentWrapper>\n <Popper\n referenceElement={targetRef.current}\n placement={\n lockPlacement && lockedPlacement ? lockedPlacement : placement\n }\n modifiers={{\n preventOverflow: {\n boundariesElement: \"viewport\",\n },\n // Disable flip after locking when lockPlacement is true\n flip: { enabled: !(lockPlacement && lockedPlacement) },\n ...popperModifiers,\n }}\n {...restPopperProps}\n >\n {({\n ref,\n style,\n placement: actualPlacement,\n outOfBoundaries,\n scheduleUpdate,\n }) => {\n // HACK: We use setTimeout to defer locking the placement until after render,\n // because Popper v1 only exposes the computed placement in the render prop,\n // and React does not allow setState during render.\n if (lockPlacement && !lockedPlacement && actualPlacement) {\n setTimeout(() => {\n // Check again before setting to avoid a race condition\n if (\n lockPlacement &&\n !lockedPlacement &&\n actualPlacement\n ) {\n setLockedPlacement(actualPlacement);\n }\n }, 0);\n }\n\n const interceptRef = (el: HTMLDivElement | undefined) => {\n popoutRef.current = el;\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n ref(el);\n };\n\n scheduleUpdateCallback.current = scheduleUpdate;\n scheduleUpdateRef(scheduleUpdate);\n\n return (\n <div\n ref={interceptRef}\n style={{\n ...style,\n zIndex,\n width:\n fullWidth && targetRef.current\n ? targetRef.current.offsetWidth\n : \"initial\",\n }}\n data-placement={actualPlacement}\n data-qa-popout=\"\"\n data-qa-popout-isopen={isOpen === true}\n // TODO: fix this type since `color` should be valid here. TS can't resolve the correct type.\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n color={color}\n {...rest}\n >\n {!outOfBoundaries && (\n <motion.div\n {...animationConfig}\n // pass the placement in the custom prop so it can be used in the animation\n custom={{\n placement: actualPlacement,\n ...animationConfig.custom,\n }}\n >\n <FocusLock\n autoFocus={autoFocus}\n returnFocus={returnFocus}\n disabled={!focusOnContent}\n {...restFocusLockProps}\n >\n {typeof content === \"function\" &&\n content({\n hide,\n actualPlacement,\n })}\n {typeof content !== \"function\" && content}\n </FocusLock>\n </motion.div>\n )}\n </div>\n );\n }}\n </Popper>\n </PopoutComponentWrapper>\n )}\n </AnimatePresence>\n )}\n </React.Fragment>\n );\n}\n\nconst PopoutContent = ({ children, ...rest }: TypeBoxProps) => (\n <Box\n bg=\"container.background.base\"\n color=\"text.body\"\n border={500}\n borderColor=\"container.border.base\"\n borderRadius=\"outer\"\n boxShadow=\"medium\"\n p={400}\n m={300}\n {...rest}\n >\n {children}\n </Box>\n);\n\nPopoutContent.displayName = \"Popout.Content\";\nPopout.Content = PopoutContent;\n\nexport default Popout;\n","import styled from \"styled-components\";\nimport { COMMON, LAYOUT } from \"@sproutsocial/seeds-react-system-props\";\n\nexport const TargetWrapper = styled.div`\n display: inline-block;\n ${COMMON}\n ${LAYOUT}\n`;\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from \"react\";\nimport type { PopperProps } from \"react-popper\";\nimport type {\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n TypeStyledComponentsCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\nimport type { HTMLMotionProps } from \"motion/react\";\n\nexport type EnumPlacements = Exclude<PopperProps[\"placement\"], undefined>;\n\nexport interface TypeFocusLockProps {\n disabled?: boolean;\n returnFocus?:\n | boolean\n | FocusOptions\n | ((returnTo: Element) => boolean | FocusOptions);\n persistentFocus?: boolean;\n autoFocus?: boolean;\n crossFrame?: boolean;\n noFocusGuards?: boolean | \"tail\";\n group?: string;\n className?: string;\n onActivation?: (node: HTMLElement) => void;\n onDeactivation?: (node: HTMLElement) => void;\n as?: TypeStyledComponentsCommonProps[\"as\"];\n lockProps?: any;\n ref?: any;\n whiteList?: (activeElement: HTMLElement) => boolean;\n shards?: Array<any>;\n children?: React.ReactNode;\n}\n\nexport interface TypePopoutProps\n extends TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n Omit<\n React.ComponentPropsWithoutRef<\"div\">,\n \"color\" | \"children\" | \"content\"\n > {\n /**\n * Whether Popout should automatically add aria-attributes to its wrapped elements\n */\n disableWrapperAria?: boolean;\n /**\n * Is the popout open? This prop is optional. By using it, you will lose some automatic handling of the logic for opening and closing the popout.\n */\n isOpen?: boolean;\n\n /**\n * If you use the isOpen prop you will need to pass a handler to change the state of the popout\n */\n setIsOpen?: (isOpen: boolean, event?: MouseEvent | KeyboardEvent) => void;\n\n /**\n * The content to be shown in the popout. If there is no content, just the children are rendered\n */\n content:\n | (React.ReactElement<any> | null | undefined)\n | (\n | ((opts: {\n hide: () => void;\n actualPlacement: EnumPlacements;\n }) => React.ReactElement<any>)\n | null\n | undefined\n );\n\n /**\n * The content that the popout should be attached to\n */\n children:\n | React.ReactElement<any>\n | ((opts: {\n ref: (arg0: React.ElementRef<any> | HTMLElement) => void;\n toggle: () => void;\n show: () => void;\n hide: () => void;\n ariaProps: Record<string, any>;\n }) => React.ReactNode);\n\n /** How the popped-out content should be placed, in relationship to the children */\n placement?: EnumPlacements;\n\n /**\n * Should the popout be locked in place? This will prevent it from moving when the user scrolls or if the height of the popout changes.\n * This is useful for modals and other places where you want the popout to stay in place\n * after it has been opened but want to use an auto placement strategy.\n */\n lockPlacement?: boolean;\n\n /**\n * Should the popped-out content inherit its width from the children?\n * This is useful for typeaheads and other places where a popout needs to match the width of a given element.\n */\n fullWidth?: boolean;\n\n /**\n * When the popout has opened, should we focus on its content?\n * Focus will be brought inside by looking for elements with [autofocus] first, [tabindex] second and buttons/links/other natively-focusable elements last.\n * Upon closing the popout, focus will be returned to the popout's target.\n * If nothing within your popout's content is focusable, this prop will do nothing.\n */\n focusOnContent?: boolean;\n qa?: Record<string, string>;\n zIndex?: number;\n /** Used to override the default Popout animations.\n * Any props that are valid for use on a Motion div can be passed here as an object.\n * See https://motion.dev/docs/react-motion-component#props */\n animationConfig?: Omit<HTMLMotionProps<\"div\">, \"children\">;\n\n /**\n * Override react-popper per the API documentation here: https://github.com/FezVrasta/react-popper#api-documentation\n */\n popperProps?: Partial<PopperProps>;\n onClose?: () => void;\n onOpen?: () => void;\n\n /**\n * An optional callback to receive the scheduleUpdate function.\n * Use the function to recalculate the popout position in relation to the contents.\n */\n scheduleUpdateRef?: (arg0: () => void) => void;\n\n /**\n * Mount the popout at the bottom of the DOM (using React.Portal) instead of inside the current DOM tree\n */\n appendToBody?: boolean;\n\n /**\n * Override `FocusLock` props, see the API documentation for more details: https://github.com/theKashey/react-focus-lock#api\n */\n focusLockProps?: TypeFocusLockProps;\n}\n","import * as React from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport * as Popover from \"@radix-ui/react-popover\";\nimport { MOTION_DURATION_FAST } from \"@sproutsocial/seeds-motion/unitless\";\nimport type { TypePopoutProps } from \"./PopoutTypes\";\nimport styled from \"styled-components\";\n\nconst defaultAnimationConfig = {\n initial: { opacity: 0 },\n animate: { opacity: 1 },\n exit: { opacity: 0 },\n transition: {\n ease: \"circOut\",\n type: \"tween\",\n duration: process.env.NODE_ENV === \"test\" ? 0 : MOTION_DURATION_FAST,\n },\n};\n\nconst StyledMotionDiv = styled(motion.div)`\n background-color: ${({ theme }) => theme.colors.container.background.base};\n border: ${({ theme }) => theme.borders[500]};\n border-color: ${({ theme }) => theme.colors.container.border.base};\n border-radius: ${({ theme }) => theme.radii[500]};\n box-shadow: ${({ theme }) => theme.shadows.medium};\n padding: ${({ theme }) => theme.space[400]};\n`;\n\nexport function Popout({\n children,\n content,\n open,\n defaultOpen,\n onOpenChange,\n animationConfig = defaultAnimationConfig,\n side = \"bottom\",\n sideOffset = 8,\n align = \"center\",\n alignOffset = 0,\n onOpenAutoFocus,\n onEscapeKeyDown,\n onCloseAutoFocus,\n ...rest\n}: TypePopoutProps) {\n const [isOpen, setIsOpen] = React.useState(defaultOpen ?? false);\n\n const handleOpenChange = React.useCallback(\n (newOpen: boolean) => {\n setIsOpen(newOpen);\n onOpenChange?.(newOpen);\n },\n [onOpenChange]\n );\n\n // Use controlled state if open prop is provided\n const isControlled = open !== undefined;\n const popoverOpen = isControlled ? open : isOpen;\n const popoverOnOpenChange = isControlled ? onOpenChange : handleOpenChange;\n\n // Handle ref forwarding for components that use innerRef instead of ref\n // (e.g., seeds-react-button)\n // Radix UI's asChild passes ref, but Button uses innerRef\n const radixRef = React.useRef<HTMLButtonElement | null>(null);\n\n return (\n <Popover.Root open={popoverOpen} onOpenChange={popoverOnOpenChange}>\n <Popover.Trigger ref={radixRef} asChild>\n {children}\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Content\n side={side}\n sideOffset={sideOffset}\n align={align}\n alignOffset={alignOffset}\n onOpenAutoFocus={onOpenAutoFocus}\n onEscapeKeyDown={onEscapeKeyDown}\n onCloseAutoFocus={onCloseAutoFocus}\n >\n <StyledMotionDiv {...animationConfig} {...rest}>\n {content}\n </StyledMotionDiv>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from \"react\";\nimport type {\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n TypeStyledComponentsCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\nimport type { HTMLMotionProps } from \"motion/react\";\n\nexport interface TypePopoutProps\n extends TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n Omit<\n React.ComponentPropsWithoutRef<\"div\">,\n \"color\" | \"children\" | \"content\"\n > {\n /**\n * The content that the popout should be attached to (renders in Popover.Trigger)\n */\n children: React.ReactElement<any>;\n\n /**\n * The content to be shown in the popout (renders in Popover.Content)\n */\n content: React.ReactNode;\n\n /**\n * Whether the popout is open (controlled)\n */\n open?: boolean;\n\n /**\n * Default open state (uncontrolled)\n */\n defaultOpen?: boolean;\n\n /**\n * Callback fired when the open state changes\n */\n onOpenChange?: (open: boolean) => void;\n\n /**\n * Used to override the default Popout animations.\n * Any props that are valid for use on a Motion div can be passed here as an object.\n * See https://motion.dev/docs/react-motion-component#props\n */\n animationConfig?: Omit<HTMLMotionProps<\"div\">, \"children\">;\n\n /**\n * The preferred side of the trigger to render against when open.\n * @default \"bottom\"\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n\n /**\n * The distance in pixels from the trigger.\n * @default 8\n */\n sideOffset?: number;\n\n /**\n * The preferred alignment against the trigger.\n * @default \"center\"\n */\n align?: \"start\" | \"center\" | \"end\";\n\n /**\n * An offset in pixels from the \"start\" or \"end\" alignment options.\n * @default 0\n */\n alignOffset?: number;\n\n /**\n * Event handler called when the popout content tries to auto-focus on open.\n * Can be used to prevent the default auto-focus behavior or customize it.\n * If not provided, defaults to allowing auto-focus on the content.\n */\n onOpenAutoFocus?: (event: Event) => void;\n\n /**\n * Event handler called when the Escape key is pressed while the popout is open.\n * Can be used to prevent the default close behavior or customize it.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void;\n\n /**\n * Event handler called when the popout tries to return focus to the trigger on close.\n * Can be used to prevent the default focus return behavior or customize it.\n */\n onCloseAutoFocus?: (event: Event) => void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA,kBAAAA;AAAA,EAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,mBAAkE;AAClE,IAAAC,gBAAwC;AACxC,8BAAsB;AACtB,0BAAuB;AACvB,sBAAqC;AACrC,+BAAoC;AACpC,gCAAmB;AACnB,6BAAuC;;;ACRvC,+BAAmB;AACnB,sCAA+B;AAExB,IAAM,gBAAgB,yBAAAC,QAAO;AAAA;AAAA,IAEhC,sCAAM;AAAA,IACN,sCAAM;AAAA;;;ADmMF;AA7LR,IAAM,4BAA4B,CAChC,KACA,UACG;AACH,SACE,IAAI,WACJ,MAAM,kBAAkB,QACxB,IAAI,QAAQ,SAAS,MAAM,MAAM;AAErC;AAEA,IAAM,yBAAyB;AAAA,EAC7B,SAAS,EAAE,SAAS,EAAE;AAAA,EACtB,SAAS,EAAE,SAAS,EAAE;AAAA,EACtB,MAAM,EAAE,SAAS,EAAE;AAAA,EACnB,YAAY;AAAA,IACV,MAAM;AAAA,IACN,MAAM;AAAA,IACN,UAAU,QAAQ,IAAI,aAAa,SAAS,IAAI;AAAA,EAClD;AACF;AAEO,SAAS,OAAO;AAAA,EACrB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,YAAY;AAAA,EACZ,SAAS;AAAA,EACT,iBAAiB;AAAA,EACjB;AAAA,EACA;AAAA,EAC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MAAM,aAAa,cAAc,qBAC7C;AAAA,iDAAS,iBAAR,EAAgB,KAAK,UAAU,SAAO,MACpC,UACH;AAAA,IACA,6CAAS,gBAAR,EACC;AAAA,MAAS;AAAA,MAAR;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QAEA,uDAAC,mBAAiB,GAAG,iBAAkB,GAAG,MACvC,mBACH;AAAA;AAAA,IACF,GACF;AAAA,KACF;AAEJ;;;ACpFA,IAAAG,SAAuB;;;ALCvB,IAAO,cAAQ;","names":["Popout","import_react","styled","Portal","FocusLock","Box","React","React","import_react","import_unitless","import_styled_components","import_jsx_runtime","defaultAnimationConfig","styled","Popout","React"]}
@@ -0,0 +1,73 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { TypeStyledComponentsCommonProps, TypeSystemCommonProps, TypeSystemLayoutProps } from '@sproutsocial/seeds-react-system-props';
4
+ import { HTMLMotionProps } from 'motion/react';
5
+
6
+ interface TypePopoutProps extends TypeStyledComponentsCommonProps, TypeSystemCommonProps, TypeSystemLayoutProps, Omit<React.ComponentPropsWithoutRef<"div">, "color" | "children" | "content"> {
7
+ /**
8
+ * The content that the popout should be attached to (renders in Popover.Trigger)
9
+ */
10
+ children: React.ReactElement<any>;
11
+ /**
12
+ * The content to be shown in the popout (renders in Popover.Content)
13
+ */
14
+ content: React.ReactNode;
15
+ /**
16
+ * Whether the popout is open (controlled)
17
+ */
18
+ open?: boolean;
19
+ /**
20
+ * Default open state (uncontrolled)
21
+ */
22
+ defaultOpen?: boolean;
23
+ /**
24
+ * Callback fired when the open state changes
25
+ */
26
+ onOpenChange?: (open: boolean) => void;
27
+ /**
28
+ * Used to override the default Popout animations.
29
+ * Any props that are valid for use on a Motion div can be passed here as an object.
30
+ * See https://motion.dev/docs/react-motion-component#props
31
+ */
32
+ animationConfig?: Omit<HTMLMotionProps<"div">, "children">;
33
+ /**
34
+ * The preferred side of the trigger to render against when open.
35
+ * @default "bottom"
36
+ */
37
+ side?: "top" | "right" | "bottom" | "left";
38
+ /**
39
+ * The distance in pixels from the trigger.
40
+ * @default 8
41
+ */
42
+ sideOffset?: number;
43
+ /**
44
+ * The preferred alignment against the trigger.
45
+ * @default "center"
46
+ */
47
+ align?: "start" | "center" | "end";
48
+ /**
49
+ * An offset in pixels from the "start" or "end" alignment options.
50
+ * @default 0
51
+ */
52
+ alignOffset?: number;
53
+ /**
54
+ * Event handler called when the popout content tries to auto-focus on open.
55
+ * Can be used to prevent the default auto-focus behavior or customize it.
56
+ * If not provided, defaults to allowing auto-focus on the content.
57
+ */
58
+ onOpenAutoFocus?: (event: Event) => void;
59
+ /**
60
+ * Event handler called when the Escape key is pressed while the popout is open.
61
+ * Can be used to prevent the default close behavior or customize it.
62
+ */
63
+ onEscapeKeyDown?: (event: KeyboardEvent) => void;
64
+ /**
65
+ * Event handler called when the popout tries to return focus to the trigger on close.
66
+ * Can be used to prevent the default focus return behavior or customize it.
67
+ */
68
+ onCloseAutoFocus?: (event: Event) => void;
69
+ }
70
+
71
+ declare function Popout({ children, content, open, defaultOpen, onOpenChange, animationConfig, side, sideOffset, align, alignOffset, onOpenAutoFocus, onEscapeKeyDown, onCloseAutoFocus, ...rest }: TypePopoutProps): react_jsx_runtime.JSX.Element;
72
+
73
+ export { Popout, type TypePopoutProps };
@@ -0,0 +1,73 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React from 'react';
3
+ import { TypeStyledComponentsCommonProps, TypeSystemCommonProps, TypeSystemLayoutProps } from '@sproutsocial/seeds-react-system-props';
4
+ import { HTMLMotionProps } from 'motion/react';
5
+
6
+ interface TypePopoutProps extends TypeStyledComponentsCommonProps, TypeSystemCommonProps, TypeSystemLayoutProps, Omit<React.ComponentPropsWithoutRef<"div">, "color" | "children" | "content"> {
7
+ /**
8
+ * The content that the popout should be attached to (renders in Popover.Trigger)
9
+ */
10
+ children: React.ReactElement<any>;
11
+ /**
12
+ * The content to be shown in the popout (renders in Popover.Content)
13
+ */
14
+ content: React.ReactNode;
15
+ /**
16
+ * Whether the popout is open (controlled)
17
+ */
18
+ open?: boolean;
19
+ /**
20
+ * Default open state (uncontrolled)
21
+ */
22
+ defaultOpen?: boolean;
23
+ /**
24
+ * Callback fired when the open state changes
25
+ */
26
+ onOpenChange?: (open: boolean) => void;
27
+ /**
28
+ * Used to override the default Popout animations.
29
+ * Any props that are valid for use on a Motion div can be passed here as an object.
30
+ * See https://motion.dev/docs/react-motion-component#props
31
+ */
32
+ animationConfig?: Omit<HTMLMotionProps<"div">, "children">;
33
+ /**
34
+ * The preferred side of the trigger to render against when open.
35
+ * @default "bottom"
36
+ */
37
+ side?: "top" | "right" | "bottom" | "left";
38
+ /**
39
+ * The distance in pixels from the trigger.
40
+ * @default 8
41
+ */
42
+ sideOffset?: number;
43
+ /**
44
+ * The preferred alignment against the trigger.
45
+ * @default "center"
46
+ */
47
+ align?: "start" | "center" | "end";
48
+ /**
49
+ * An offset in pixels from the "start" or "end" alignment options.
50
+ * @default 0
51
+ */
52
+ alignOffset?: number;
53
+ /**
54
+ * Event handler called when the popout content tries to auto-focus on open.
55
+ * Can be used to prevent the default auto-focus behavior or customize it.
56
+ * If not provided, defaults to allowing auto-focus on the content.
57
+ */
58
+ onOpenAutoFocus?: (event: Event) => void;
59
+ /**
60
+ * Event handler called when the Escape key is pressed while the popout is open.
61
+ * Can be used to prevent the default close behavior or customize it.
62
+ */
63
+ onEscapeKeyDown?: (event: KeyboardEvent) => void;
64
+ /**
65
+ * Event handler called when the popout tries to return focus to the trigger on close.
66
+ * Can be used to prevent the default focus return behavior or customize it.
67
+ */
68
+ onCloseAutoFocus?: (event: Event) => void;
69
+ }
70
+
71
+ declare function Popout({ children, content, open, defaultOpen, onOpenChange, animationConfig, side, sideOffset, align, alignOffset, onOpenAutoFocus, onEscapeKeyDown, onCloseAutoFocus, ...rest }: TypePopoutProps): react_jsx_runtime.JSX.Element;
72
+
73
+ export { Popout, type TypePopoutProps };
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/v2/index.ts
31
+ var v2_exports = {};
32
+ __export(v2_exports, {
33
+ Popout: () => Popout
34
+ });
35
+ module.exports = __toCommonJS(v2_exports);
36
+
37
+ // src/v2/Popout.tsx
38
+ var React = __toESM(require("react"));
39
+ var import_react = require("motion/react");
40
+ var Popover = __toESM(require("@radix-ui/react-popover"));
41
+ var import_unitless = require("@sproutsocial/seeds-motion/unitless");
42
+ var import_styled_components = __toESM(require("styled-components"));
43
+ var import_jsx_runtime = require("react/jsx-runtime");
44
+ var defaultAnimationConfig = {
45
+ initial: { opacity: 0 },
46
+ animate: { opacity: 1 },
47
+ exit: { opacity: 0 },
48
+ transition: {
49
+ ease: "circOut",
50
+ type: "tween",
51
+ duration: process.env.NODE_ENV === "test" ? 0 : import_unitless.MOTION_DURATION_FAST
52
+ }
53
+ };
54
+ var StyledMotionDiv = (0, import_styled_components.default)(import_react.motion.div)`
55
+ background-color: ${({ theme }) => theme.colors.container.background.base};
56
+ border: ${({ theme }) => theme.borders[500]};
57
+ border-color: ${({ theme }) => theme.colors.container.border.base};
58
+ border-radius: ${({ theme }) => theme.radii[500]};
59
+ box-shadow: ${({ theme }) => theme.shadows.medium};
60
+ padding: ${({ theme }) => theme.space[400]};
61
+ `;
62
+ function Popout({
63
+ children,
64
+ content,
65
+ open,
66
+ defaultOpen,
67
+ onOpenChange,
68
+ animationConfig = defaultAnimationConfig,
69
+ side = "bottom",
70
+ sideOffset = 8,
71
+ align = "center",
72
+ alignOffset = 0,
73
+ onOpenAutoFocus,
74
+ onEscapeKeyDown,
75
+ onCloseAutoFocus,
76
+ ...rest
77
+ }) {
78
+ const [isOpen, setIsOpen] = React.useState(defaultOpen ?? false);
79
+ const handleOpenChange = React.useCallback(
80
+ (newOpen) => {
81
+ setIsOpen(newOpen);
82
+ onOpenChange?.(newOpen);
83
+ },
84
+ [onOpenChange]
85
+ );
86
+ const isControlled = open !== void 0;
87
+ const popoverOpen = isControlled ? open : isOpen;
88
+ const popoverOnOpenChange = isControlled ? onOpenChange : handleOpenChange;
89
+ const radixRef = React.useRef(null);
90
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Popover.Root, { open: popoverOpen, onOpenChange: popoverOnOpenChange, children: [
91
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Popover.Trigger, { ref: radixRef, asChild: true, children }),
92
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Popover.Portal, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
93
+ Popover.Content,
94
+ {
95
+ side,
96
+ sideOffset,
97
+ align,
98
+ alignOffset,
99
+ onOpenAutoFocus,
100
+ onEscapeKeyDown,
101
+ onCloseAutoFocus,
102
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StyledMotionDiv, { ...animationConfig, ...rest, children: content })
103
+ }
104
+ ) })
105
+ ] });
106
+ }
107
+
108
+ // src/v2/PopoutTypes.ts
109
+ var React2 = require("react");
110
+ // Annotate the CommonJS export names for ESM import in node:
111
+ 0 && (module.exports = {
112
+ Popout
113
+ });
114
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/v2/index.ts","../../src/v2/Popout.tsx","../../src/v2/PopoutTypes.ts"],"sourcesContent":["export * from \"./Popout\";\nexport * from \"./PopoutTypes\";\n","import * as React from \"react\";\nimport { AnimatePresence, motion } from \"motion/react\";\nimport * as Popover from \"@radix-ui/react-popover\";\nimport { MOTION_DURATION_FAST } from \"@sproutsocial/seeds-motion/unitless\";\nimport type { TypePopoutProps } from \"./PopoutTypes\";\nimport styled from \"styled-components\";\n\nconst defaultAnimationConfig = {\n initial: { opacity: 0 },\n animate: { opacity: 1 },\n exit: { opacity: 0 },\n transition: {\n ease: \"circOut\",\n type: \"tween\",\n duration: process.env.NODE_ENV === \"test\" ? 0 : MOTION_DURATION_FAST,\n },\n};\n\nconst StyledMotionDiv = styled(motion.div)`\n background-color: ${({ theme }) => theme.colors.container.background.base};\n border: ${({ theme }) => theme.borders[500]};\n border-color: ${({ theme }) => theme.colors.container.border.base};\n border-radius: ${({ theme }) => theme.radii[500]};\n box-shadow: ${({ theme }) => theme.shadows.medium};\n padding: ${({ theme }) => theme.space[400]};\n`;\n\nexport function Popout({\n children,\n content,\n open,\n defaultOpen,\n onOpenChange,\n animationConfig = defaultAnimationConfig,\n side = \"bottom\",\n sideOffset = 8,\n align = \"center\",\n alignOffset = 0,\n onOpenAutoFocus,\n onEscapeKeyDown,\n onCloseAutoFocus,\n ...rest\n}: TypePopoutProps) {\n const [isOpen, setIsOpen] = React.useState(defaultOpen ?? false);\n\n const handleOpenChange = React.useCallback(\n (newOpen: boolean) => {\n setIsOpen(newOpen);\n onOpenChange?.(newOpen);\n },\n [onOpenChange]\n );\n\n // Use controlled state if open prop is provided\n const isControlled = open !== undefined;\n const popoverOpen = isControlled ? open : isOpen;\n const popoverOnOpenChange = isControlled ? onOpenChange : handleOpenChange;\n\n // Handle ref forwarding for components that use innerRef instead of ref\n // (e.g., seeds-react-button)\n // Radix UI's asChild passes ref, but Button uses innerRef\n const radixRef = React.useRef<HTMLButtonElement | null>(null);\n\n return (\n <Popover.Root open={popoverOpen} onOpenChange={popoverOnOpenChange}>\n <Popover.Trigger ref={radixRef} asChild>\n {children}\n </Popover.Trigger>\n <Popover.Portal>\n <Popover.Content\n side={side}\n sideOffset={sideOffset}\n align={align}\n alignOffset={alignOffset}\n onOpenAutoFocus={onOpenAutoFocus}\n onEscapeKeyDown={onEscapeKeyDown}\n onCloseAutoFocus={onCloseAutoFocus}\n >\n <StyledMotionDiv {...animationConfig} {...rest}>\n {content}\n </StyledMotionDiv>\n </Popover.Content>\n </Popover.Portal>\n </Popover.Root>\n );\n}\n","/* eslint-disable @typescript-eslint/no-explicit-any */\nimport * as React from \"react\";\nimport type {\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n TypeStyledComponentsCommonProps,\n} from \"@sproutsocial/seeds-react-system-props\";\nimport type { HTMLMotionProps } from \"motion/react\";\n\nexport interface TypePopoutProps\n extends TypeStyledComponentsCommonProps,\n TypeSystemCommonProps,\n TypeSystemLayoutProps,\n Omit<\n React.ComponentPropsWithoutRef<\"div\">,\n \"color\" | \"children\" | \"content\"\n > {\n /**\n * The content that the popout should be attached to (renders in Popover.Trigger)\n */\n children: React.ReactElement<any>;\n\n /**\n * The content to be shown in the popout (renders in Popover.Content)\n */\n content: React.ReactNode;\n\n /**\n * Whether the popout is open (controlled)\n */\n open?: boolean;\n\n /**\n * Default open state (uncontrolled)\n */\n defaultOpen?: boolean;\n\n /**\n * Callback fired when the open state changes\n */\n onOpenChange?: (open: boolean) => void;\n\n /**\n * Used to override the default Popout animations.\n * Any props that are valid for use on a Motion div can be passed here as an object.\n * See https://motion.dev/docs/react-motion-component#props\n */\n animationConfig?: Omit<HTMLMotionProps<\"div\">, \"children\">;\n\n /**\n * The preferred side of the trigger to render against when open.\n * @default \"bottom\"\n */\n side?: \"top\" | \"right\" | \"bottom\" | \"left\";\n\n /**\n * The distance in pixels from the trigger.\n * @default 8\n */\n sideOffset?: number;\n\n /**\n * The preferred alignment against the trigger.\n * @default \"center\"\n */\n align?: \"start\" | \"center\" | \"end\";\n\n /**\n * An offset in pixels from the \"start\" or \"end\" alignment options.\n * @default 0\n */\n alignOffset?: number;\n\n /**\n * Event handler called when the popout content tries to auto-focus on open.\n * Can be used to prevent the default auto-focus behavior or customize it.\n * If not provided, defaults to allowing auto-focus on the content.\n */\n onOpenAutoFocus?: (event: Event) => void;\n\n /**\n * Event handler called when the Escape key is pressed while the popout is open.\n * Can be used to prevent the default close behavior or customize it.\n */\n onEscapeKeyDown?: (event: KeyboardEvent) => void;\n\n /**\n * Event handler called when the popout tries to return focus to the trigger on close.\n * Can be used to prevent the default focus return behavior or customize it.\n */\n onCloseAutoFocus?: (event: Event) => void;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,mBAAwC;AACxC,cAAyB;AACzB,sBAAqC;AAErC,+BAAmB;AA2Df;AAzDJ,IAAM,yBAAyB;AAAA,EAC7B,SAAS,EAAE,SAAS,EAAE;AAAA,EACtB,SAAS,EAAE,SAAS,EAAE;AAAA,EACtB,MAAM,EAAE,SAAS,EAAE;AAAA,EACnB,YAAY;AAAA,IACV,MAAM;AAAA,IACN,MAAM;AAAA,IACN,UAAU,QAAQ,IAAI,aAAa,SAAS,IAAI;AAAA,EAClD;AACF;AAEA,IAAM,sBAAkB,yBAAAA,SAAO,oBAAO,GAAG;AAAA,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,GACF;AAAA,KACF;AAEJ;;;ACpFA,IAAAC,SAAuB;","names":["styled","React"]}
package/package.json CHANGED
@@ -1,12 +1,24 @@
1
1
  {
2
2
  "name": "@sproutsocial/seeds-react-popout",
3
- "version": "2.4.6",
3
+ "version": "2.4.7",
4
4
  "description": "Seeds React Popout",
5
5
  "author": "Sprout Social, Inc.",
6
6
  "license": "MIT",
7
7
  "main": "dist/index.js",
8
8
  "module": "dist/esm/index.js",
9
9
  "types": "dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/esm/index.js",
14
+ "require": "./dist/index.js"
15
+ },
16
+ "./v2": {
17
+ "types": "./dist/v2/index.d.ts",
18
+ "import": "./dist/esm/v2/index.js",
19
+ "require": "./dist/v2/index.js"
20
+ }
21
+ },
10
22
  "files": [
11
23
  "dist"
12
24
  ],
@@ -21,6 +33,7 @@
21
33
  "test:watch": "jest --watch --coverage=false"
22
34
  },
23
35
  "dependencies": {
36
+ "@radix-ui/react-popover": "^1.1.2",
24
37
  "@sproutsocial/seeds-motion": "^1.8.1",
25
38
  "@sproutsocial/seeds-react-box": "^1.1.5",
26
39
  "@sproutsocial/seeds-react-button": "^1.3.1",
@@ -34,6 +47,10 @@
34
47
  "devDependencies": {
35
48
  "@sproutsocial/eslint-config-seeds": "*",
36
49
  "@sproutsocial/seeds-tsconfig": "*",
50
+ "@sproutsocial/seeds-react-drawer": "*",
51
+ "@sproutsocial/seeds-react-input": "*",
52
+ "@sproutsocial/seeds-react-loader": "*",
53
+ "@sproutsocial/seeds-react-modal": "*",
37
54
  "@sproutsocial/seeds-react-testing-library": "*",
38
55
  "@sproutsocial/seeds-testing": "*",
39
56
  "@types/react": "^18.0.0",