@contentful/f36-popover 4.17.0 → 4.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/dist/{types.d.ts → index.d.ts} +18 -13
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +11 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +7 -7
- package/dist/main.js +0 -234
- package/dist/main.js.map +0 -1
- package/dist/module.js +0 -225
- package/dist/module.js.map +0 -1
- package/dist/types.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { ExpandProps,
|
|
3
|
-
import { Placement } from
|
|
4
|
-
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ExpandProps, PropsWithHTMLElement, CommonProps } from '@contentful/f36-core';
|
|
3
|
+
import { Placement } from '@popperjs/core';
|
|
4
|
+
import * as _emotion_core from '@emotion/core';
|
|
5
|
+
|
|
6
|
+
interface PopoverProps {
|
|
5
7
|
children: React.ReactNode;
|
|
6
8
|
/**
|
|
7
9
|
* Boolean to determine if the Popover should be the same width as
|
|
@@ -89,19 +91,21 @@ export interface PopoverProps {
|
|
|
89
91
|
*/
|
|
90
92
|
renderOnlyWhenOpen?: boolean;
|
|
91
93
|
}
|
|
92
|
-
declare function
|
|
94
|
+
declare function Popover$1(props: ExpandProps<PopoverProps>): JSX.Element;
|
|
95
|
+
|
|
93
96
|
interface PopoverContentInternalProps extends CommonProps {
|
|
94
97
|
children?: React.ReactNode;
|
|
95
98
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
+
declare type PopoverContentProps = PropsWithHTMLElement<PopoverContentInternalProps, 'div'>;
|
|
100
|
+
declare const PopoverContent: React.ForwardRefExoticComponent<Omit<Omit<Pick<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "key" | keyof React.HTMLAttributes<HTMLDivElement>>, never>, keyof PopoverContentInternalProps> & PopoverContentInternalProps & React.RefAttributes<unknown>>;
|
|
101
|
+
|
|
102
|
+
interface PopoverTriggerProps {
|
|
99
103
|
children: React.ReactNode;
|
|
100
104
|
}
|
|
101
105
|
/**
|
|
102
106
|
* PopoverTrigger opens the popover. It must be an interactive element.
|
|
103
107
|
*/
|
|
104
|
-
|
|
108
|
+
declare const PopoverTrigger: (props: PopoverTriggerProps) => React.DetailedReactHTMLElement<{
|
|
105
109
|
'aria-haspopup': any;
|
|
106
110
|
accept?: string;
|
|
107
111
|
acceptCharset?: string;
|
|
@@ -463,14 +467,15 @@ export const PopoverTrigger: (props: PopoverTriggerProps) => React.DetailedReact
|
|
|
463
467
|
onAnimationIterationCapture?: React.AnimationEventHandler<HTMLElement>;
|
|
464
468
|
onTransitionEnd?: React.TransitionEventHandler<HTMLElement>;
|
|
465
469
|
onTransitionEndCapture?: React.TransitionEventHandler<HTMLElement>;
|
|
466
|
-
css?:
|
|
470
|
+
css?: _emotion_core.InterpolationWithTheme<any>;
|
|
467
471
|
ref?: React.LegacyRef<HTMLElement>;
|
|
468
472
|
key?: React.Key;
|
|
469
473
|
}, HTMLElement>;
|
|
470
|
-
|
|
474
|
+
|
|
475
|
+
declare type CompoundPopover = typeof Popover$1 & {
|
|
471
476
|
Content: typeof PopoverContent;
|
|
472
477
|
Trigger: typeof PopoverTrigger;
|
|
473
478
|
};
|
|
474
|
-
|
|
479
|
+
declare const Popover: CompoundPopover;
|
|
475
480
|
|
|
476
|
-
|
|
481
|
+
export { Popover, PopoverContent, PopoverContentProps, PopoverProps, PopoverTrigger, PopoverTriggerProps };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var O = require('react');
|
|
6
|
+
var f36Core = require('@contentful/f36-core');
|
|
7
|
+
var reactPopper = require('react-popper');
|
|
8
|
+
var emotion = require('emotion');
|
|
9
|
+
var f36Utils = require('@contentful/f36-utils');
|
|
10
|
+
var f = require('@contentful/f36-tokens');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var O__default = /*#__PURE__*/_interopDefaultLegacy(O);
|
|
15
|
+
var f__default = /*#__PURE__*/_interopDefaultLegacy(f);
|
|
16
|
+
|
|
17
|
+
var ee=Object.defineProperty,oe=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var D=(e,r,o)=>r in e?ee(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,i=(e,r)=>{for(var o in r||(r={}))I.call(r,o)&&D(e,o,r[o]);if(y)for(var o of y(r))B.call(r,o)&&D(e,o,r[o]);return e},P=(e,r)=>oe(e,re(r));var F=(e,r)=>{var o={};for(var t in e)I.call(e,t)&&r.indexOf(t)<0&&(o[t]=e[t]);if(e!=null&&y)for(var t of y(e))r.indexOf(t)<0&&B.call(e,t)&&(o[t]=e[t]);return o};var N=(e,r,o)=>new Promise((t,u)=>{var m=p=>{try{a(o.next(p));}catch(n){u(n);}},d=p=>{try{a(o.throw(p));}catch(n){u(n);}},a=p=>p.done?t(p.value):Promise.resolve(p.value).then(m,d);a((o=o.apply(e,r)).next());});var A=O__default["default"].createContext(void 0),T=()=>{let e=O__default["default"].useContext(A);if(e===void 0)throw new Error("usePopoverContext must be used within a PopoverContextProvider");return e},K=A.Provider;function q(e){let{children:r,isOpen:o,placement:t="bottom-start",isFullWidth:u=!1,isAutoalignmentEnabled:m=!0,usePortal:d=!0,closeOnBlur:a=!0,closeOnEsc:p=!0,onClose:n,autoFocus:h=!0,id:C,offset:g=[1,4],renderOnlyWhenOpen:v=!0}=e,[s,J]=O.useState(null),[l,Q]=O.useState(null),{attributes:L,update:E,styles:W}=reactPopper.usePopper(s,l,{placement:t,modifiers:[{name:"offset",options:{offset:g}},P(i({},ae),{enabled:u}),{name:"preventOverflow",enabled:m,options:{mainAxis:!0}},{name:"flip",enabled:m}]});O.useEffect(()=>{o&&h&&l&&l.focus({preventScroll:!0});},[o,l]),O.useEffect(()=>{(()=>N(this,null,function*(){o&&E&&(yield E());}))();},[o,E]);let U=f36Core.useId(void 0,"popover-content"),M=C||U,S=O.useCallback(()=>{n==null||n(),setTimeout(()=>s==null?void 0:s.focus({preventScroll:!0}),0);},[n,s]),X=O.useMemo(()=>({isOpen:Boolean(o),usePortal:d,renderOnlyWhenOpen:v,getTriggerProps:(c=null)=>({ref:f36Core.mergeRefs(J,c),["aria-expanded"]:Boolean(o),["aria-controls"]:M}),getPopoverProps:(c={},Y=null)=>P(i({},L.popper),{style:i(i({},c.style||{}),W.popper),ref:f36Core.mergeRefs(Q,Y),id:M,onBlur:x=>{if(c.onBlur&&c.onBlur(x),!a)return;let b=x.relatedTarget,Z=l===b||(l==null?void 0:l.contains(b)),_=s===b||(s==null?void 0:s.contains(b));Z||_||n==null||n();},onKeyDown:x=>{c.onKeyDown&&c.onKeyDown(x),p&&x.key==="Escape"&&S();}})}),[o,v,L,W,d,M,p,a,l,s,S,n]);return O__default["default"].createElement(K,{value:X},r)}var ae={name:"sameWidth",enabled:!0,phase:"beforeWrite",requires:["computeStyles"],fn:({state:e})=>{e.styles.popper.width=`${e.rects.reference.width}px`;},effect:({state:e})=>()=>{let r=e.elements.reference;e.elements.popper.style.width=`${r.offsetWidth}px`;}};var G=e=>({container:emotion.css({display:e?"initial":"none",background:f__default["default"].colorWhite,border:0,borderRadius:f__default["default"].borderRadiusMedium,boxShadow:f__default["default"].boxShadowDefault,zIndex:f__default["default"].zIndexDropdown,"&:focus":{boxShadow:f__default["default"].glowPrimary,outline:"none"},"&:focus:not(:focus-visible)":{boxShadow:f__default["default"].boxShadowDefault}})});var Pe=(e,r)=>{let v=e,{children:o,className:t,testId:u="cf-ui-popover-content",role:m="dialog"}=v,d=F(v,["children","className","testId","role"]),{isOpen:a,renderOnlyWhenOpen:p,getPopoverProps:n,usePortal:h}=T(),C=G(a),g=O__default["default"].createElement("div",P(i(i({},d),n(d,r)),{className:emotion.cx(C.container,t),"data-test-id":u,tabIndex:-1,role:m,"data-position-absolute":!0}),o);return p&&!a?null:h?O__default["default"].createElement(f36Utils.Portal,null,g):g},w=O__default["default"].forwardRef(Pe);var R=e=>{var t;let r=O__default["default"].Children.only(e.children),{getTriggerProps:o}=T();return O__default["default"].cloneElement(r,P(i({},o(r.ref)),{"aria-haspopup":(t=r.props["aria-haspopup"])!=null?t:"dialog"}))};var H=q;H.Content=w;H.Trigger=R;
|
|
18
|
+
|
|
19
|
+
exports.Popover = H;
|
|
20
|
+
exports.PopoverContent = w;
|
|
21
|
+
exports.PopoverTrigger = R;
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Popover.tsx","../src/PopoverContext.ts","../src/PopoverContent/PopoverContent.tsx","../src/PopoverContent/PopoverContent.styles.ts","../src/PopoverTrigger/PopoverTrigger.tsx","../src/CompoundPopover.tsx"],"names":["React","useMemo","useState","useEffect","useCallback","useId","mergeRefs","PopoverContext","usePopoverContext","context","PopoverContextProvider","usePopper","Popover","props","children","isOpen","placement","isFullWidth","isAutoalignmentEnabled","usePortal","closeOnBlur","closeOnEsc","onClose","autoFocus","id","offset","renderOnlyWhenOpen","triggerElement","setTriggerElement","popoverElement","setPopoverElement","popperAttributes","update","popperStyles","__spreadProps","__spreadValues","sameWidth","__async","popoverGeneratedId","popoverId","closeAndFocusTrigger","contextValue","_ref","_props","event","relatedTarget","targetIsPopover","targetIsTrigger","state","reference","cx","Portal","css","tokens","getPopoverContentStyles","_PopoverContent","ref","_a","className","testId","role","otherProps","__objRest","getPopoverProps","styles","content","PopoverContent","PopoverTrigger","child","getTriggerProps"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zC,eAAcC,EACd,SAAU,GACV,KAAMC,EAGN,yBAAsB,KAErB9C,CACH,EAGF,OAAIY,GAAsB,CAACX,EAClB,KAGFI,EAAYnB,EAAA,cAACmD,GAAA,KAAQc,CAAQ,EAAYA,CAClD,EAEaC,EAAiBlE,EAAM,WAAWuD,EAAe,EExD9D,OAAOvD,MAAW,QAUX,IAAMmE,EAAkBtD,GAA+B,CAV9D,IAAA4C,EAWE,IAAMW,EAAQpE,EAAM,SAAS,KAAKa,EAAM,QAAQ,EAC1C,CAAE,gBAAAwD,CAAgB,EAAI7D,EAAkB,EAE9C,OAAOR,EAAM,aAAaoE,EAAOlC,EAAAC,EAAA,GAC5BkC,EAAgBD,EAAM,GAAG,GADG,CAE/B,iBAAiBX,EAAAW,EAAM,MAAM,mBAAZ,KAAAX,EAAgC,QACnD,EAAC,CACH,ECTO,IAAM7C,EAAUA,EACvBA,EAAQ,QAAUsD,EAClBtD,EAAQ,QAAUuD","sourcesContent":["import React, { useMemo, useState, useEffect, useCallback } from 'react';\nimport { useId, mergeRefs, type ExpandProps } from '@contentful/f36-core';\nimport type { Placement, Modifier } from '@popperjs/core';\nimport { PopoverContextProvider, PopoverContextType } from './PopoverContext';\nimport { usePopper } from 'react-popper';\n\nexport interface PopoverProps {\n children: React.ReactNode;\n\n /**\n * Boolean to determine if the Popover should be the same width as\n * the trigger element\n *\n * @default false\n */\n isFullWidth?: boolean;\n\n /**\n * Boolean to control whether or not the Popover is open\n *\n * @default false\n */\n isOpen?: boolean;\n\n /**\n * Callback fired when the popover closes\n */\n onClose?: () => void;\n\n /**\n * Determines the preferred position of the Popover. This position is not\n * guaranteed, as the Popover might be moved to fit the viewport\n *\n * @default bottom-start\n */\n placement?: Placement;\n\n /**\n * Boolean to control if popover is allowed to change its placement automatically\n * based on available space in the viewport.\n *\n * For example:\n * If you set placement prop to bottom, but there isn't enough space to position the popover in that direction,\n * it will change the popper placement to top. As soon as enough space is detected, the placement will be reverted to the defined one.\n *\n * If you want the popover to strictly follow the placement prop you should set this prop to false.\n *\n * @default true\n */\n isAutoalignmentEnabled?: boolean;\n\n /**\n * Boolean to control whether or not to render the Popover in a React Portal.\n * Rendering content inside a Portal allows the Popover to escape the bounds\n * of its parent while still being positioned correctly. Using a Portal is\n * necessary if an ancestor of the Popover hides overflow.\n *\n * @default true\n */\n usePortal?: boolean;\n\n /**\n * If true, the popover will close when you blur out it by clicking outside or tabbing out\n *\n * @default true\n */\n closeOnBlur?: boolean;\n\n /**\n * If true, the popover will close when you hit the Esc key\n *\n * @default true\n */\n closeOnEsc?: boolean;\n\n /**\n * If true, the popover will be focused after opening\n *\n * @default true\n */\n autoFocus?: boolean;\n\n /**\n * Popover id. Will be used as an `id` attribute on popover\n * and as `aria-controls` attribute on trigger\n *\n * @default true\n */\n id?: string;\n\n /**\n * The `X-axis` and `Y-axis` offset to position popper element\n * from its trigger element. `[X, Y]`\n *\n * @default [1, 4]\n */\n offset?: [number, number];\n\n /**\n * Defines if popover should be rendered in the DOM only when it's open\n * or all the time (after the component has been mounted)\n *\n * @default true\n */\n renderOnlyWhenOpen?: boolean;\n}\n\nexport function Popover(props: ExpandProps<PopoverProps>) {\n const {\n children,\n isOpen,\n placement = 'bottom-start',\n isFullWidth = false,\n isAutoalignmentEnabled = true,\n usePortal = true,\n closeOnBlur = true,\n closeOnEsc = true,\n onClose,\n autoFocus = true,\n id,\n offset = [1, 4],\n renderOnlyWhenOpen = true,\n } = props;\n\n const [triggerElement, setTriggerElement] = useState<HTMLElement | null>(\n null,\n );\n const [popoverElement, setPopoverElement] = useState<HTMLElement | null>(\n null,\n );\n\n const {\n attributes: popperAttributes,\n update,\n styles: popperStyles,\n } = usePopper(triggerElement, popoverElement, {\n placement,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset,\n },\n },\n {\n ...sameWidth,\n enabled: isFullWidth,\n },\n {\n name: 'preventOverflow',\n enabled: isAutoalignmentEnabled,\n options: {\n mainAxis: true,\n },\n },\n {\n name: 'flip',\n enabled: isAutoalignmentEnabled,\n },\n ],\n });\n\n useEffect(() => {\n if (isOpen && autoFocus && popoverElement) {\n popoverElement.focus({ preventScroll: true });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen, popoverElement]);\n\n useEffect(() => {\n const updatePosition = async () => {\n if (isOpen && update) {\n await update();\n }\n };\n updatePosition();\n }, [isOpen, update]);\n\n const popoverGeneratedId = useId(undefined, 'popover-content');\n const popoverId = id || popoverGeneratedId;\n\n const closeAndFocusTrigger = useCallback(() => {\n onClose?.();\n\n // setTimeout trick to make it work with focus-lock\n setTimeout(() => triggerElement?.focus({ preventScroll: true }), 0);\n }, [onClose, triggerElement]);\n\n const contextValue: PopoverContextType = useMemo(\n () => ({\n isOpen: Boolean(isOpen),\n usePortal,\n renderOnlyWhenOpen,\n getTriggerProps: (_ref = null) => ({\n ref: mergeRefs(setTriggerElement, _ref),\n ['aria-expanded']: Boolean(isOpen),\n ['aria-controls']: popoverId,\n }),\n getPopoverProps: (_props = {}, _ref = null) => ({\n ...popperAttributes.popper,\n style: {\n ...(_props.style || {}),\n ...popperStyles.popper,\n },\n ref: mergeRefs(setPopoverElement, _ref),\n id: popoverId,\n onBlur: (event: React.FocusEvent<HTMLDivElement>) => {\n if (_props.onBlur) {\n _props.onBlur(event);\n }\n\n if (!closeOnBlur) {\n return;\n }\n\n const relatedTarget = event.relatedTarget as Node;\n\n const targetIsPopover =\n popoverElement === relatedTarget ||\n popoverElement?.contains(relatedTarget);\n const targetIsTrigger =\n triggerElement === relatedTarget ||\n triggerElement?.contains(relatedTarget);\n\n if (targetIsPopover || targetIsTrigger) {\n return;\n }\n\n onClose?.();\n },\n onKeyDown: (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (_props.onKeyDown) {\n _props.onKeyDown(event);\n }\n\n if (closeOnEsc && event.key === 'Escape') {\n closeAndFocusTrigger();\n }\n },\n }),\n }),\n [\n isOpen,\n renderOnlyWhenOpen,\n popperAttributes,\n popperStyles,\n usePortal,\n popoverId,\n closeOnEsc,\n closeOnBlur,\n popoverElement,\n triggerElement,\n closeAndFocusTrigger,\n onClose,\n ],\n );\n\n return (\n <PopoverContextProvider value={contextValue}>\n {children}\n </PopoverContextProvider>\n );\n}\n\n/**\n * Sets the popover width to the size of the trigger element.\n */\nconst sameWidth: Modifier<'sameWidth', any> = {\n name: 'sameWidth',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles'],\n fn: ({ state }) => {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n effect:\n ({ state }) =>\n () => {\n const reference = state.elements.reference as HTMLElement;\n state.elements.popper.style.width = `${reference.offsetWidth}px`;\n },\n};\n","import React, { HTMLProps } from 'react';\n\nexport type PopoverContextType = {\n isOpen: boolean;\n usePortal: boolean;\n renderOnlyWhenOpen: boolean;\n getPopoverProps: (\n _props: HTMLProps<HTMLDivElement>,\n _ref: React.Ref<HTMLDivElement>,\n ) => HTMLProps<HTMLDivElement>;\n getTriggerProps: (_ref: React.Ref<HTMLElement>) => HTMLProps<HTMLElement>;\n};\n\nconst PopoverContext = React.createContext<PopoverContextType | undefined>(\n undefined,\n);\n\nexport const usePopoverContext = () => {\n const context = React.useContext(PopoverContext);\n\n if (context === undefined) {\n throw new Error(\n 'usePopoverContext must be used within a PopoverContextProvider',\n );\n }\n\n return context;\n};\n\nexport const PopoverContextProvider = PopoverContext.Provider;\n","import React from 'react';\nimport { cx } from 'emotion';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\nimport { usePopoverContext } from '../PopoverContext';\nimport { Portal } from '@contentful/f36-utils';\nimport { getPopoverContentStyles } from './PopoverContent.styles';\n\ninterface PopoverContentInternalProps extends CommonProps {\n children?: React.ReactNode;\n}\n\nexport type PopoverContentProps = PropsWithHTMLElement<\n PopoverContentInternalProps,\n 'div'\n>;\n\nconst _PopoverContent = (props: ExpandProps<PopoverContentProps>, ref) => {\n const {\n children,\n className,\n testId = 'cf-ui-popover-content',\n role = 'dialog',\n ...otherProps\n } = props;\n const { isOpen, renderOnlyWhenOpen, getPopoverProps, usePortal } =\n usePopoverContext();\n\n const styles = getPopoverContentStyles(isOpen);\n\n const content = (\n <div\n {...otherProps}\n {...getPopoverProps(otherProps, ref)}\n className={cx(styles.container, className)}\n data-test-id={testId}\n tabIndex={-1}\n role={role}\n // specific attribute to mark that this element is absolute positioned\n // for internal contentful apps usage\n data-position-absolute\n >\n {children}\n </div>\n );\n\n if (renderOnlyWhenOpen && !isOpen) {\n return null;\n }\n\n return usePortal ? <Portal>{content}</Portal> : content;\n};\n\nexport const PopoverContent = React.forwardRef(_PopoverContent);\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getPopoverContentStyles = (isOpen: boolean) => ({\n container: css({\n display: isOpen ? 'initial' : 'none',\n background: tokens.colorWhite,\n border: 0,\n borderRadius: tokens.borderRadiusMedium,\n boxShadow: tokens.boxShadowDefault,\n zIndex: tokens.zIndexDropdown,\n '&:focus': {\n boxShadow: tokens.glowPrimary,\n outline: 'none',\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: tokens.boxShadowDefault,\n },\n }),\n});\n","import React from 'react';\nimport { usePopoverContext } from '../PopoverContext';\n\nexport interface PopoverTriggerProps {\n children: React.ReactNode;\n}\n\n/**\n * PopoverTrigger opens the popover. It must be an interactive element.\n */\nexport const PopoverTrigger = (props: PopoverTriggerProps) => {\n const child = React.Children.only(props.children) as any;\n const { getTriggerProps } = usePopoverContext();\n\n return React.cloneElement(child, {\n ...getTriggerProps(child.ref),\n 'aria-haspopup': child.props['aria-haspopup'] ?? 'dialog',\n });\n};\n","import { Popover as OriginalPopover } from './Popover';\nimport { PopoverContent } from './PopoverContent/PopoverContent';\nimport { PopoverTrigger } from './PopoverTrigger/PopoverTrigger';\n\ntype CompoundPopover = typeof OriginalPopover & {\n Content: typeof PopoverContent;\n Trigger: typeof PopoverTrigger;\n};\n\nexport const Popover = OriginalPopover as CompoundPopover;\nPopover.Content = PopoverContent;\nPopover.Trigger = PopoverTrigger;\n"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import O, { useState, useEffect, useCallback, useMemo } from 'react';
|
|
2
|
+
import { useId, mergeRefs } from '@contentful/f36-core';
|
|
3
|
+
import { usePopper } from 'react-popper';
|
|
4
|
+
import { cx, css } from 'emotion';
|
|
5
|
+
import { Portal } from '@contentful/f36-utils';
|
|
6
|
+
import f from '@contentful/f36-tokens';
|
|
7
|
+
|
|
8
|
+
var ee=Object.defineProperty,oe=Object.defineProperties;var re=Object.getOwnPropertyDescriptors;var y=Object.getOwnPropertySymbols;var I=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;var D=(e,r,o)=>r in e?ee(e,r,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[r]=o,i=(e,r)=>{for(var o in r||(r={}))I.call(r,o)&&D(e,o,r[o]);if(y)for(var o of y(r))B.call(r,o)&&D(e,o,r[o]);return e},P=(e,r)=>oe(e,re(r));var F=(e,r)=>{var o={};for(var t in e)I.call(e,t)&&r.indexOf(t)<0&&(o[t]=e[t]);if(e!=null&&y)for(var t of y(e))r.indexOf(t)<0&&B.call(e,t)&&(o[t]=e[t]);return o};var N=(e,r,o)=>new Promise((t,u)=>{var m=p=>{try{a(o.next(p));}catch(n){u(n);}},d=p=>{try{a(o.throw(p));}catch(n){u(n);}},a=p=>p.done?t(p.value):Promise.resolve(p.value).then(m,d);a((o=o.apply(e,r)).next());});var A=O.createContext(void 0),T=()=>{let e=O.useContext(A);if(e===void 0)throw new Error("usePopoverContext must be used within a PopoverContextProvider");return e},K=A.Provider;function q(e){let{children:r,isOpen:o,placement:t="bottom-start",isFullWidth:u=!1,isAutoalignmentEnabled:m=!0,usePortal:d=!0,closeOnBlur:a=!0,closeOnEsc:p=!0,onClose:n,autoFocus:h=!0,id:C,offset:g=[1,4],renderOnlyWhenOpen:v=!0}=e,[s,J]=useState(null),[l,Q]=useState(null),{attributes:L,update:E,styles:W}=usePopper(s,l,{placement:t,modifiers:[{name:"offset",options:{offset:g}},P(i({},ae),{enabled:u}),{name:"preventOverflow",enabled:m,options:{mainAxis:!0}},{name:"flip",enabled:m}]});useEffect(()=>{o&&h&&l&&l.focus({preventScroll:!0});},[o,l]),useEffect(()=>{(()=>N(this,null,function*(){o&&E&&(yield E());}))();},[o,E]);let U=useId(void 0,"popover-content"),M=C||U,S=useCallback(()=>{n==null||n(),setTimeout(()=>s==null?void 0:s.focus({preventScroll:!0}),0);},[n,s]),X=useMemo(()=>({isOpen:Boolean(o),usePortal:d,renderOnlyWhenOpen:v,getTriggerProps:(c=null)=>({ref:mergeRefs(J,c),["aria-expanded"]:Boolean(o),["aria-controls"]:M}),getPopoverProps:(c={},Y=null)=>P(i({},L.popper),{style:i(i({},c.style||{}),W.popper),ref:mergeRefs(Q,Y),id:M,onBlur:x=>{if(c.onBlur&&c.onBlur(x),!a)return;let b=x.relatedTarget,Z=l===b||(l==null?void 0:l.contains(b)),_=s===b||(s==null?void 0:s.contains(b));Z||_||n==null||n();},onKeyDown:x=>{c.onKeyDown&&c.onKeyDown(x),p&&x.key==="Escape"&&S();}})}),[o,v,L,W,d,M,p,a,l,s,S,n]);return O.createElement(K,{value:X},r)}var ae={name:"sameWidth",enabled:!0,phase:"beforeWrite",requires:["computeStyles"],fn:({state:e})=>{e.styles.popper.width=`${e.rects.reference.width}px`;},effect:({state:e})=>()=>{let r=e.elements.reference;e.elements.popper.style.width=`${r.offsetWidth}px`;}};var G=e=>({container:css({display:e?"initial":"none",background:f.colorWhite,border:0,borderRadius:f.borderRadiusMedium,boxShadow:f.boxShadowDefault,zIndex:f.zIndexDropdown,"&:focus":{boxShadow:f.glowPrimary,outline:"none"},"&:focus:not(:focus-visible)":{boxShadow:f.boxShadowDefault}})});var Pe=(e,r)=>{let v=e,{children:o,className:t,testId:u="cf-ui-popover-content",role:m="dialog"}=v,d=F(v,["children","className","testId","role"]),{isOpen:a,renderOnlyWhenOpen:p,getPopoverProps:n,usePortal:h}=T(),C=G(a),g=O.createElement("div",P(i(i({},d),n(d,r)),{className:cx(C.container,t),"data-test-id":u,tabIndex:-1,role:m,"data-position-absolute":!0}),o);return p&&!a?null:h?O.createElement(Portal,null,g):g},w=O.forwardRef(Pe);var R=e=>{var t;let r=O.Children.only(e.children),{getTriggerProps:o}=T();return O.cloneElement(r,P(i({},o(r.ref)),{"aria-haspopup":(t=r.props["aria-haspopup"])!=null?t:"dialog"}))};var H=q;H.Content=w;H.Trigger=R;
|
|
9
|
+
|
|
10
|
+
export { H as Popover, w as PopoverContent, R as PopoverTrigger };
|
|
11
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Popover.tsx","../src/PopoverContext.ts","../src/PopoverContent/PopoverContent.tsx","../src/PopoverContent/PopoverContent.styles.ts","../src/PopoverTrigger/PopoverTrigger.tsx","../src/CompoundPopover.tsx"],"names":["React","useMemo","useState","useEffect","useCallback","useId","mergeRefs","PopoverContext","usePopoverContext","context","PopoverContextProvider","usePopper","Popover","props","children","isOpen","placement","isFullWidth","isAutoalignmentEnabled","usePortal","closeOnBlur","closeOnEsc","onClose","autoFocus","id","offset","renderOnlyWhenOpen","triggerElement","setTriggerElement","popoverElement","setPopoverElement","popperAttributes","update","popperStyles","__spreadProps","__spreadValues","sameWidth","__async","popoverGeneratedId","popoverId","closeAndFocusTrigger","contextValue","_ref","_props","event","relatedTarget","targetIsPopover","targetIsTrigger","state","reference","cx","Portal","css","tokens","getPopoverContentStyles","_PopoverContent","ref","_a","className","testId","role","otherProps","__objRest","getPopoverProps","styles","content","PopoverContent","PopoverTrigger","child","getTriggerProps"],"mappings":"kyBAAA,OAAOA,IAAS,WAAAC,GAAS,YAAAC,EAAU,aAAAC,EAAW,eAAAC,OAAmB,QACjE,OAAS,SAAAC,GAAO,aAAAC,MAAmC,uBCDnD,OAAON,MAA0B,QAajC,IAAMO,EAAiBP,EAAM,cAC3B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WAAWuD,EAAe,EExD9D,OAAOvD,MAAW,QAUX,IAAMmE,EAAkBtD,GAA+B,CAV9D,IAAA4C,EAWE,IAAMW,EAAQpE,EAAM,SAAS,KAAKa,EAAM,QAAQ,EAC1C,CAAE,gBAAAwD,CAAgB,EAAI7D,EAAkB,EAE9C,OAAOR,EAAM,aAAaoE,EAAOlC,EAAAC,EAAA,GAC5BkC,EAAgBD,EAAM,GAAG,GADG,CAE/B,iBAAiBX,EAAAW,EAAM,MAAM,mBAAZ,KAAAX,EAAgC,QACnD,EAAC,CACH,ECTO,IAAM7C,EAAUA,EACvBA,EAAQ,QAAUsD,EAClBtD,EAAQ,QAAUuD","sourcesContent":["import React, { useMemo, useState, useEffect, useCallback } from 'react';\nimport { useId, mergeRefs, type ExpandProps } from '@contentful/f36-core';\nimport type { Placement, Modifier } from '@popperjs/core';\nimport { PopoverContextProvider, PopoverContextType } from './PopoverContext';\nimport { usePopper } from 'react-popper';\n\nexport interface PopoverProps {\n children: React.ReactNode;\n\n /**\n * Boolean to determine if the Popover should be the same width as\n * the trigger element\n *\n * @default false\n */\n isFullWidth?: boolean;\n\n /**\n * Boolean to control whether or not the Popover is open\n *\n * @default false\n */\n isOpen?: boolean;\n\n /**\n * Callback fired when the popover closes\n */\n onClose?: () => void;\n\n /**\n * Determines the preferred position of the Popover. This position is not\n * guaranteed, as the Popover might be moved to fit the viewport\n *\n * @default bottom-start\n */\n placement?: Placement;\n\n /**\n * Boolean to control if popover is allowed to change its placement automatically\n * based on available space in the viewport.\n *\n * For example:\n * If you set placement prop to bottom, but there isn't enough space to position the popover in that direction,\n * it will change the popper placement to top. As soon as enough space is detected, the placement will be reverted to the defined one.\n *\n * If you want the popover to strictly follow the placement prop you should set this prop to false.\n *\n * @default true\n */\n isAutoalignmentEnabled?: boolean;\n\n /**\n * Boolean to control whether or not to render the Popover in a React Portal.\n * Rendering content inside a Portal allows the Popover to escape the bounds\n * of its parent while still being positioned correctly. Using a Portal is\n * necessary if an ancestor of the Popover hides overflow.\n *\n * @default true\n */\n usePortal?: boolean;\n\n /**\n * If true, the popover will close when you blur out it by clicking outside or tabbing out\n *\n * @default true\n */\n closeOnBlur?: boolean;\n\n /**\n * If true, the popover will close when you hit the Esc key\n *\n * @default true\n */\n closeOnEsc?: boolean;\n\n /**\n * If true, the popover will be focused after opening\n *\n * @default true\n */\n autoFocus?: boolean;\n\n /**\n * Popover id. Will be used as an `id` attribute on popover\n * and as `aria-controls` attribute on trigger\n *\n * @default true\n */\n id?: string;\n\n /**\n * The `X-axis` and `Y-axis` offset to position popper element\n * from its trigger element. `[X, Y]`\n *\n * @default [1, 4]\n */\n offset?: [number, number];\n\n /**\n * Defines if popover should be rendered in the DOM only when it's open\n * or all the time (after the component has been mounted)\n *\n * @default true\n */\n renderOnlyWhenOpen?: boolean;\n}\n\nexport function Popover(props: ExpandProps<PopoverProps>) {\n const {\n children,\n isOpen,\n placement = 'bottom-start',\n isFullWidth = false,\n isAutoalignmentEnabled = true,\n usePortal = true,\n closeOnBlur = true,\n closeOnEsc = true,\n onClose,\n autoFocus = true,\n id,\n offset = [1, 4],\n renderOnlyWhenOpen = true,\n } = props;\n\n const [triggerElement, setTriggerElement] = useState<HTMLElement | null>(\n null,\n );\n const [popoverElement, setPopoverElement] = useState<HTMLElement | null>(\n null,\n );\n\n const {\n attributes: popperAttributes,\n update,\n styles: popperStyles,\n } = usePopper(triggerElement, popoverElement, {\n placement,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset,\n },\n },\n {\n ...sameWidth,\n enabled: isFullWidth,\n },\n {\n name: 'preventOverflow',\n enabled: isAutoalignmentEnabled,\n options: {\n mainAxis: true,\n },\n },\n {\n name: 'flip',\n enabled: isAutoalignmentEnabled,\n },\n ],\n });\n\n useEffect(() => {\n if (isOpen && autoFocus && popoverElement) {\n popoverElement.focus({ preventScroll: true });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen, popoverElement]);\n\n useEffect(() => {\n const updatePosition = async () => {\n if (isOpen && update) {\n await update();\n }\n };\n updatePosition();\n }, [isOpen, update]);\n\n const popoverGeneratedId = useId(undefined, 'popover-content');\n const popoverId = id || popoverGeneratedId;\n\n const closeAndFocusTrigger = useCallback(() => {\n onClose?.();\n\n // setTimeout trick to make it work with focus-lock\n setTimeout(() => triggerElement?.focus({ preventScroll: true }), 0);\n }, [onClose, triggerElement]);\n\n const contextValue: PopoverContextType = useMemo(\n () => ({\n isOpen: Boolean(isOpen),\n usePortal,\n renderOnlyWhenOpen,\n getTriggerProps: (_ref = null) => ({\n ref: mergeRefs(setTriggerElement, _ref),\n ['aria-expanded']: Boolean(isOpen),\n ['aria-controls']: popoverId,\n }),\n getPopoverProps: (_props = {}, _ref = null) => ({\n ...popperAttributes.popper,\n style: {\n ...(_props.style || {}),\n ...popperStyles.popper,\n },\n ref: mergeRefs(setPopoverElement, _ref),\n id: popoverId,\n onBlur: (event: React.FocusEvent<HTMLDivElement>) => {\n if (_props.onBlur) {\n _props.onBlur(event);\n }\n\n if (!closeOnBlur) {\n return;\n }\n\n const relatedTarget = event.relatedTarget as Node;\n\n const targetIsPopover =\n popoverElement === relatedTarget ||\n popoverElement?.contains(relatedTarget);\n const targetIsTrigger =\n triggerElement === relatedTarget ||\n triggerElement?.contains(relatedTarget);\n\n if (targetIsPopover || targetIsTrigger) {\n return;\n }\n\n onClose?.();\n },\n onKeyDown: (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (_props.onKeyDown) {\n _props.onKeyDown(event);\n }\n\n if (closeOnEsc && event.key === 'Escape') {\n closeAndFocusTrigger();\n }\n },\n }),\n }),\n [\n isOpen,\n renderOnlyWhenOpen,\n popperAttributes,\n popperStyles,\n usePortal,\n popoverId,\n closeOnEsc,\n closeOnBlur,\n popoverElement,\n triggerElement,\n closeAndFocusTrigger,\n onClose,\n ],\n );\n\n return (\n <PopoverContextProvider value={contextValue}>\n {children}\n </PopoverContextProvider>\n );\n}\n\n/**\n * Sets the popover width to the size of the trigger element.\n */\nconst sameWidth: Modifier<'sameWidth', any> = {\n name: 'sameWidth',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles'],\n fn: ({ state }) => {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n effect:\n ({ state }) =>\n () => {\n const reference = state.elements.reference as HTMLElement;\n state.elements.popper.style.width = `${reference.offsetWidth}px`;\n },\n};\n","import React, { HTMLProps } from 'react';\n\nexport type PopoverContextType = {\n isOpen: boolean;\n usePortal: boolean;\n renderOnlyWhenOpen: boolean;\n getPopoverProps: (\n _props: HTMLProps<HTMLDivElement>,\n _ref: React.Ref<HTMLDivElement>,\n ) => HTMLProps<HTMLDivElement>;\n getTriggerProps: (_ref: React.Ref<HTMLElement>) => HTMLProps<HTMLElement>;\n};\n\nconst PopoverContext = React.createContext<PopoverContextType | undefined>(\n undefined,\n);\n\nexport const usePopoverContext = () => {\n const context = React.useContext(PopoverContext);\n\n if (context === undefined) {\n throw new Error(\n 'usePopoverContext must be used within a PopoverContextProvider',\n );\n }\n\n return context;\n};\n\nexport const PopoverContextProvider = PopoverContext.Provider;\n","import React from 'react';\nimport { cx } from 'emotion';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\nimport { usePopoverContext } from '../PopoverContext';\nimport { Portal } from '@contentful/f36-utils';\nimport { getPopoverContentStyles } from './PopoverContent.styles';\n\ninterface PopoverContentInternalProps extends CommonProps {\n children?: React.ReactNode;\n}\n\nexport type PopoverContentProps = PropsWithHTMLElement<\n PopoverContentInternalProps,\n 'div'\n>;\n\nconst _PopoverContent = (props: ExpandProps<PopoverContentProps>, ref) => {\n const {\n children,\n className,\n testId = 'cf-ui-popover-content',\n role = 'dialog',\n ...otherProps\n } = props;\n const { isOpen, renderOnlyWhenOpen, getPopoverProps, usePortal } =\n usePopoverContext();\n\n const styles = getPopoverContentStyles(isOpen);\n\n const content = (\n <div\n {...otherProps}\n {...getPopoverProps(otherProps, ref)}\n className={cx(styles.container, className)}\n data-test-id={testId}\n tabIndex={-1}\n role={role}\n // specific attribute to mark that this element is absolute positioned\n // for internal contentful apps usage\n data-position-absolute\n >\n {children}\n </div>\n );\n\n if (renderOnlyWhenOpen && !isOpen) {\n return null;\n }\n\n return usePortal ? <Portal>{content}</Portal> : content;\n};\n\nexport const PopoverContent = React.forwardRef(_PopoverContent);\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getPopoverContentStyles = (isOpen: boolean) => ({\n container: css({\n display: isOpen ? 'initial' : 'none',\n background: tokens.colorWhite,\n border: 0,\n borderRadius: tokens.borderRadiusMedium,\n boxShadow: tokens.boxShadowDefault,\n zIndex: tokens.zIndexDropdown,\n '&:focus': {\n boxShadow: tokens.glowPrimary,\n outline: 'none',\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: tokens.boxShadowDefault,\n },\n }),\n});\n","import React from 'react';\nimport { usePopoverContext } from '../PopoverContext';\n\nexport interface PopoverTriggerProps {\n children: React.ReactNode;\n}\n\n/**\n * PopoverTrigger opens the popover. It must be an interactive element.\n */\nexport const PopoverTrigger = (props: PopoverTriggerProps) => {\n const child = React.Children.only(props.children) as any;\n const { getTriggerProps } = usePopoverContext();\n\n return React.cloneElement(child, {\n ...getTriggerProps(child.ref),\n 'aria-haspopup': child.props['aria-haspopup'] ?? 'dialog',\n });\n};\n","import { Popover as OriginalPopover } from './Popover';\nimport { PopoverContent } from './PopoverContent/PopoverContent';\nimport { PopoverTrigger } from './PopoverTrigger/PopoverTrigger';\n\ntype CompoundPopover = typeof OriginalPopover & {\n Content: typeof PopoverContent;\n Trigger: typeof PopoverTrigger;\n};\n\nexport const Popover = OriginalPopover as CompoundPopover;\nPopover.Content = PopoverContent;\nPopover.Trigger = PopoverTrigger;\n"]}
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/f36-popover",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.18.0",
|
|
4
4
|
"description": "Forma 36: Popover component",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"build": "
|
|
6
|
+
"build": "tsup"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
9
|
"@babel/runtime": "^7.6.2",
|
|
10
|
-
"@contentful/f36-core": "^4.
|
|
10
|
+
"@contentful/f36-core": "^4.18.0",
|
|
11
11
|
"@contentful/f36-tokens": "^4.0.1",
|
|
12
|
-
"@contentful/f36-utils": "^4.
|
|
12
|
+
"@contentful/f36-utils": "^4.18.0",
|
|
13
13
|
"@popperjs/core": "^2.11.5",
|
|
14
14
|
"emotion": "^10.0.17",
|
|
15
15
|
"react-popper": "^2.3.0"
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"files": [
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
|
-
"main": "dist/
|
|
25
|
-
"module": "dist/
|
|
26
|
-
"types": "dist/
|
|
24
|
+
"main": "dist/index.js",
|
|
25
|
+
"module": "dist/index.mjs",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
27
|
"source": "src/index.ts",
|
|
28
28
|
"sideEffects": false,
|
|
29
29
|
"browserslist": "extends @contentful/browserslist-config",
|
package/dist/main.js
DELETED
|
@@ -1,234 +0,0 @@
|
|
|
1
|
-
var $36WSQ$react = require("react");
|
|
2
|
-
var $36WSQ$contentfulf36core = require("@contentful/f36-core");
|
|
3
|
-
var $36WSQ$reactpopper = require("react-popper");
|
|
4
|
-
var $36WSQ$emotion = require("emotion");
|
|
5
|
-
var $36WSQ$contentfulf36utils = require("@contentful/f36-utils");
|
|
6
|
-
var $36WSQ$contentfulf36tokens = require("@contentful/f36-tokens");
|
|
7
|
-
|
|
8
|
-
function $parcel$export(e, n, v, s) {
|
|
9
|
-
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
10
|
-
}
|
|
11
|
-
function $parcel$interopDefault(a) {
|
|
12
|
-
return a && a.__esModule ? a.default : a;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
$parcel$export(module.exports, "Popover", () => $dd96ee4ab94ee75f$export$5b6b19405a83ff9d);
|
|
16
|
-
$parcel$export(module.exports, "PopoverTrigger", () => $b3e2e9dc1eae953e$export$7dacb05d26466c3);
|
|
17
|
-
$parcel$export(module.exports, "PopoverContent", () => $ec6b27dd96eb674c$export$d7e1f420b25549ff);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const $a5e54ab4533eb4d3$var$PopoverContext = (0, ($parcel$interopDefault($36WSQ$react))).createContext(undefined);
|
|
22
|
-
const $a5e54ab4533eb4d3$export$1468d0761b26e6c8 = ()=>{
|
|
23
|
-
const context = (0, ($parcel$interopDefault($36WSQ$react))).useContext($a5e54ab4533eb4d3$var$PopoverContext);
|
|
24
|
-
if (context === undefined) throw new Error("usePopoverContext must be used within a PopoverContextProvider");
|
|
25
|
-
return context;
|
|
26
|
-
};
|
|
27
|
-
const $a5e54ab4533eb4d3$export$f5300fbf692a63ec = $a5e54ab4533eb4d3$var$PopoverContext.Provider;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
function $ed3840333e471e4e$export$5b6b19405a83ff9d(props) {
|
|
32
|
-
const { children: children , isOpen: isOpen , placement: placement = "bottom-start" , isFullWidth: isFullWidth = false , isAutoalignmentEnabled: isAutoalignmentEnabled = true , usePortal: usePortal = true , closeOnBlur: closeOnBlur = true , closeOnEsc: closeOnEsc = true , onClose: onClose , autoFocus: autoFocus = true , id: id , offset: offset = [
|
|
33
|
-
1,
|
|
34
|
-
4
|
|
35
|
-
] , renderOnlyWhenOpen: renderOnlyWhenOpen = true } = props;
|
|
36
|
-
const [triggerElement, setTriggerElement] = (0, $36WSQ$react.useState)(null);
|
|
37
|
-
const [popoverElement, setPopoverElement] = (0, $36WSQ$react.useState)(null);
|
|
38
|
-
const { attributes: popperAttributes , update: update , styles: popperStyles } = (0, $36WSQ$reactpopper.usePopper)(triggerElement, popoverElement, {
|
|
39
|
-
placement: placement,
|
|
40
|
-
modifiers: [
|
|
41
|
-
{
|
|
42
|
-
name: "offset",
|
|
43
|
-
options: {
|
|
44
|
-
offset: offset
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
{
|
|
48
|
-
...$ed3840333e471e4e$var$sameWidth,
|
|
49
|
-
enabled: isFullWidth
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: "preventOverflow",
|
|
53
|
-
enabled: isAutoalignmentEnabled,
|
|
54
|
-
options: {
|
|
55
|
-
mainAxis: true
|
|
56
|
-
}
|
|
57
|
-
},
|
|
58
|
-
{
|
|
59
|
-
name: "flip",
|
|
60
|
-
enabled: isAutoalignmentEnabled
|
|
61
|
-
}
|
|
62
|
-
]
|
|
63
|
-
});
|
|
64
|
-
(0, $36WSQ$react.useEffect)(()=>{
|
|
65
|
-
if (isOpen && autoFocus && popoverElement) popoverElement.focus({
|
|
66
|
-
preventScroll: true
|
|
67
|
-
});
|
|
68
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
69
|
-
}, [
|
|
70
|
-
isOpen,
|
|
71
|
-
popoverElement
|
|
72
|
-
]);
|
|
73
|
-
(0, $36WSQ$react.useEffect)(()=>{
|
|
74
|
-
const updatePosition = async ()=>{
|
|
75
|
-
if (isOpen && update) await update();
|
|
76
|
-
};
|
|
77
|
-
updatePosition();
|
|
78
|
-
}, [
|
|
79
|
-
isOpen,
|
|
80
|
-
update
|
|
81
|
-
]);
|
|
82
|
-
const popoverGeneratedId = (0, $36WSQ$contentfulf36core.useId)(undefined, "popover-content");
|
|
83
|
-
const popoverId = id || popoverGeneratedId;
|
|
84
|
-
const closeAndFocusTrigger = (0, $36WSQ$react.useCallback)(()=>{
|
|
85
|
-
onClose === null || onClose === void 0 ? void 0 : onClose(); // setTimeout trick to make it work with focus-lock
|
|
86
|
-
setTimeout(()=>{
|
|
87
|
-
return triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.focus({
|
|
88
|
-
preventScroll: true
|
|
89
|
-
});
|
|
90
|
-
}, 0);
|
|
91
|
-
}, [
|
|
92
|
-
onClose,
|
|
93
|
-
triggerElement
|
|
94
|
-
]);
|
|
95
|
-
const contextValue = (0, $36WSQ$react.useMemo)(()=>{
|
|
96
|
-
return {
|
|
97
|
-
isOpen: Boolean(isOpen),
|
|
98
|
-
usePortal: usePortal,
|
|
99
|
-
renderOnlyWhenOpen: renderOnlyWhenOpen,
|
|
100
|
-
getTriggerProps: (_ref = null)=>({
|
|
101
|
-
ref: (0, $36WSQ$contentfulf36core.mergeRefs)(setTriggerElement, _ref),
|
|
102
|
-
["aria-expanded"]: Boolean(isOpen),
|
|
103
|
-
["aria-controls"]: popoverId
|
|
104
|
-
}),
|
|
105
|
-
getPopoverProps: (_props = {}, _ref = null)=>{
|
|
106
|
-
return {
|
|
107
|
-
...popperAttributes.popper,
|
|
108
|
-
style: {
|
|
109
|
-
..._props.style || {},
|
|
110
|
-
...popperStyles.popper
|
|
111
|
-
},
|
|
112
|
-
ref: (0, $36WSQ$contentfulf36core.mergeRefs)(setPopoverElement, _ref),
|
|
113
|
-
id: popoverId,
|
|
114
|
-
onBlur: (event)=>{
|
|
115
|
-
if (_props.onBlur) _props.onBlur(event);
|
|
116
|
-
if (!closeOnBlur) return;
|
|
117
|
-
const relatedTarget = event.relatedTarget;
|
|
118
|
-
const targetIsPopover = popoverElement === relatedTarget || (popoverElement === null || popoverElement === void 0 ? void 0 : popoverElement.contains(relatedTarget));
|
|
119
|
-
const targetIsTrigger = triggerElement === relatedTarget || (triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.contains(relatedTarget));
|
|
120
|
-
if (targetIsPopover || targetIsTrigger) return;
|
|
121
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
122
|
-
},
|
|
123
|
-
onKeyDown: (event)=>{
|
|
124
|
-
if (_props.onKeyDown) _props.onKeyDown(event);
|
|
125
|
-
if (closeOnEsc && event.key === "Escape") closeAndFocusTrigger();
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
}, [
|
|
131
|
-
isOpen,
|
|
132
|
-
renderOnlyWhenOpen,
|
|
133
|
-
popperAttributes,
|
|
134
|
-
popperStyles,
|
|
135
|
-
usePortal,
|
|
136
|
-
popoverId,
|
|
137
|
-
closeOnEsc,
|
|
138
|
-
closeOnBlur,
|
|
139
|
-
popoverElement,
|
|
140
|
-
triggerElement,
|
|
141
|
-
closeAndFocusTrigger,
|
|
142
|
-
onClose
|
|
143
|
-
]);
|
|
144
|
-
return /*#__PURE__*/ (0, ($parcel$interopDefault($36WSQ$react))).createElement((0, $a5e54ab4533eb4d3$export$f5300fbf692a63ec), {
|
|
145
|
-
value: contextValue
|
|
146
|
-
}, children);
|
|
147
|
-
}
|
|
148
|
-
/**
|
|
149
|
-
* Sets the popover width to the size of the trigger element.
|
|
150
|
-
*/ const $ed3840333e471e4e$var$sameWidth = {
|
|
151
|
-
name: "sameWidth",
|
|
152
|
-
enabled: true,
|
|
153
|
-
phase: "beforeWrite",
|
|
154
|
-
requires: [
|
|
155
|
-
"computeStyles"
|
|
156
|
-
],
|
|
157
|
-
fn: ({ state: state })=>{
|
|
158
|
-
state.styles.popper.width = `${state.rects.reference.width}px`;
|
|
159
|
-
},
|
|
160
|
-
effect: ({ state: state })=>()=>{
|
|
161
|
-
const reference = state.elements.reference;
|
|
162
|
-
state.elements.popper.style.width = `${reference.offsetWidth}px`;
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const $ac842fe302ff665f$export$fbd764fe961047f7 = (isOpen)=>({
|
|
174
|
-
container: /*#__PURE__*/ (0, $36WSQ$emotion.css)({
|
|
175
|
-
display: isOpen ? "initial" : "none",
|
|
176
|
-
background: (0, ($parcel$interopDefault($36WSQ$contentfulf36tokens))).colorWhite,
|
|
177
|
-
border: 0,
|
|
178
|
-
borderRadius: (0, ($parcel$interopDefault($36WSQ$contentfulf36tokens))).borderRadiusMedium,
|
|
179
|
-
boxShadow: (0, ($parcel$interopDefault($36WSQ$contentfulf36tokens))).boxShadowDefault,
|
|
180
|
-
zIndex: (0, ($parcel$interopDefault($36WSQ$contentfulf36tokens))).zIndexDropdown,
|
|
181
|
-
"&:focus": {
|
|
182
|
-
boxShadow: (0, ($parcel$interopDefault($36WSQ$contentfulf36tokens))).glowPrimary,
|
|
183
|
-
outline: "none"
|
|
184
|
-
},
|
|
185
|
-
"&:focus:not(:focus-visible)": {
|
|
186
|
-
boxShadow: (0, ($parcel$interopDefault($36WSQ$contentfulf36tokens))).boxShadowDefault
|
|
187
|
-
}
|
|
188
|
-
})
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
const $ec6b27dd96eb674c$var$_PopoverContent = (props, ref)=>{
|
|
193
|
-
const { children: children , className: className , testId: testId = "cf-ui-popover-content" , role: role = "dialog" , ...otherProps } = props;
|
|
194
|
-
const { isOpen: isOpen , renderOnlyWhenOpen: renderOnlyWhenOpen , getPopoverProps: getPopoverProps , usePortal: usePortal } = (0, $a5e54ab4533eb4d3$export$1468d0761b26e6c8)();
|
|
195
|
-
const styles = (0, $ac842fe302ff665f$export$fbd764fe961047f7)(isOpen);
|
|
196
|
-
const content = /*#__PURE__*/ (0, ($parcel$interopDefault($36WSQ$react))).createElement("div", {
|
|
197
|
-
...otherProps,
|
|
198
|
-
...getPopoverProps(otherProps, ref),
|
|
199
|
-
className: (0, $36WSQ$emotion.cx)(styles.container, className),
|
|
200
|
-
"data-test-id": testId,
|
|
201
|
-
tabIndex: -1,
|
|
202
|
-
role: role,
|
|
203
|
-
// for internal contentful apps usage
|
|
204
|
-
"data-position-absolute": true
|
|
205
|
-
}, children);
|
|
206
|
-
if (renderOnlyWhenOpen && !isOpen) return null;
|
|
207
|
-
return usePortal ? /*#__PURE__*/ (0, ($parcel$interopDefault($36WSQ$react))).createElement((0, $36WSQ$contentfulf36utils.Portal), null, content) : content;
|
|
208
|
-
};
|
|
209
|
-
const $ec6b27dd96eb674c$export$d7e1f420b25549ff = /*#__PURE__*/ (0, ($parcel$interopDefault($36WSQ$react))).forwardRef($ec6b27dd96eb674c$var$_PopoverContent);
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
const $b3e2e9dc1eae953e$export$7dacb05d26466c3 = (props)=>{
|
|
215
|
-
const child = (0, ($parcel$interopDefault($36WSQ$react))).Children.only(props.children);
|
|
216
|
-
const { getTriggerProps: getTriggerProps } = (0, $a5e54ab4533eb4d3$export$1468d0761b26e6c8)();
|
|
217
|
-
var ref;
|
|
218
|
-
return /*#__PURE__*/ (0, ($parcel$interopDefault($36WSQ$react))).cloneElement(child, {
|
|
219
|
-
...getTriggerProps(child.ref),
|
|
220
|
-
"aria-haspopup": (ref = child.props["aria-haspopup"]) !== null && ref !== void 0 ? ref : "dialog"
|
|
221
|
-
});
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const $dd96ee4ab94ee75f$export$5b6b19405a83ff9d = (0, $ed3840333e471e4e$export$5b6b19405a83ff9d);
|
|
226
|
-
$dd96ee4ab94ee75f$export$5b6b19405a83ff9d.Content = (0, $ec6b27dd96eb674c$export$d7e1f420b25549ff);
|
|
227
|
-
$dd96ee4ab94ee75f$export$5b6b19405a83ff9d.Trigger = (0, $b3e2e9dc1eae953e$export$7dacb05d26466c3);
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
//# sourceMappingURL=main.js.map
|
package/dist/main.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;AEAA;;ACAA;AAaA,MAAM+F,oCAAc,GAAGrF,CAAAA,GAAAA,sCAAK,CAAA,CAACsF,aAAa,CACxCtC,SADqB,CAAvB,AAAA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AA,GAAAA,sCAAK,CAAA,CAACyH,YAAN,CAAmBH,KAAnB,EAA0B;QAC/B,GAAGhE,eAAe,CAACgE,KAAK,CAAC9D,GAAP,CADa;QAE/B,eAAA,EAAiB8D,CAAAA,GAAA,GAAAA,KAAK,CAAC3F,KAAN,CAAY,eAAZ,CAAA,cAAA2F,GAAA,cAAAA,GAAA,GAAgC,QAAjD;KAFK,CAAP,CAAiC;CAJ5B,AAQN;;;ALTM,MAAMhI,yCAAO,GAAGM,CAAAA,GAAAA,yCAAe,CAAA,AAA/B,AAAP;AACAN,yCAAO,CAACQ,OAAR,GAAkBJ,CAAAA,GAAAA,yCAAlB,CAAA,CAAAJ;AACAA,yCAAO,CAACS,OAAR,GAAkBP,CAAAA,GAAAA,wCAAlB,CAAA,CAAAF;;ADXA","sources":["packages/components/popover/src/index.ts","packages/components/popover/src/CompoundPopover.tsx","packages/components/popover/src/Popover.tsx","packages/components/popover/src/PopoverContext.ts","packages/components/popover/src/PopoverContent/PopoverContent.tsx","packages/components/popover/src/PopoverContent/PopoverContent.styles.ts","packages/components/popover/src/PopoverTrigger/PopoverTrigger.tsx"],"sourcesContent":["export { Popover } from './CompoundPopover';\nexport type { PopoverProps } from './Popover';\nexport { PopoverTrigger } from './PopoverTrigger/PopoverTrigger';\nexport type { PopoverTriggerProps } from './PopoverTrigger/PopoverTrigger';\nexport { PopoverContent } from './PopoverContent/PopoverContent';\nexport type { PopoverContentProps } from './PopoverContent/PopoverContent';\n","import { Popover as OriginalPopover } from './Popover';\nimport { PopoverContent } from './PopoverContent/PopoverContent';\nimport { PopoverTrigger } from './PopoverTrigger/PopoverTrigger';\n\ntype CompoundPopover = typeof OriginalPopover & {\n Content: typeof PopoverContent;\n Trigger: typeof PopoverTrigger;\n};\n\nexport const Popover = OriginalPopover as CompoundPopover;\nPopover.Content = PopoverContent;\nPopover.Trigger = PopoverTrigger;\n","import React, { useMemo, useState, useEffect, useCallback } from 'react';\nimport { useId, mergeRefs, type ExpandProps } from '@contentful/f36-core';\nimport type { Placement, Modifier } from '@popperjs/core';\nimport { PopoverContextProvider, PopoverContextType } from './PopoverContext';\nimport { usePopper } from 'react-popper';\n\nexport interface PopoverProps {\n children: React.ReactNode;\n\n /**\n * Boolean to determine if the Popover should be the same width as\n * the trigger element\n *\n * @default false\n */\n isFullWidth?: boolean;\n\n /**\n * Boolean to control whether or not the Popover is open\n *\n * @default false\n */\n isOpen?: boolean;\n\n /**\n * Callback fired when the popover closes\n */\n onClose?: () => void;\n\n /**\n * Determines the preferred position of the Popover. This position is not\n * guaranteed, as the Popover might be moved to fit the viewport\n *\n * @default bottom-start\n */\n placement?: Placement;\n\n /**\n * Boolean to control if popover is allowed to change its placement automatically\n * based on available space in the viewport.\n *\n * For example:\n * If you set placement prop to bottom, but there isn't enough space to position the popover in that direction,\n * it will change the popper placement to top. As soon as enough space is detected, the placement will be reverted to the defined one.\n *\n * If you want the popover to strictly follow the placement prop you should set this prop to false.\n *\n * @default true\n */\n isAutoalignmentEnabled?: boolean;\n\n /**\n * Boolean to control whether or not to render the Popover in a React Portal.\n * Rendering content inside a Portal allows the Popover to escape the bounds\n * of its parent while still being positioned correctly. Using a Portal is\n * necessary if an ancestor of the Popover hides overflow.\n *\n * @default true\n */\n usePortal?: boolean;\n\n /**\n * If true, the popover will close when you blur out it by clicking outside or tabbing out\n *\n * @default true\n */\n closeOnBlur?: boolean;\n\n /**\n * If true, the popover will close when you hit the Esc key\n *\n * @default true\n */\n closeOnEsc?: boolean;\n\n /**\n * If true, the popover will be focused after opening\n *\n * @default true\n */\n autoFocus?: boolean;\n\n /**\n * Popover id. Will be used as an `id` attribute on popover\n * and as `aria-controls` attribute on trigger\n *\n * @default true\n */\n id?: string;\n\n /**\n * The `X-axis` and `Y-axis` offset to position popper element\n * from its trigger element. `[X, Y]`\n *\n * @default [1, 4]\n */\n offset?: [number, number];\n\n /**\n * Defines if popover should be rendered in the DOM only when it's open\n * or all the time (after the component has been mounted)\n *\n * @default true\n */\n renderOnlyWhenOpen?: boolean;\n}\n\nexport function Popover(props: ExpandProps<PopoverProps>) {\n const {\n children,\n isOpen,\n placement = 'bottom-start',\n isFullWidth = false,\n isAutoalignmentEnabled = true,\n usePortal = true,\n closeOnBlur = true,\n closeOnEsc = true,\n onClose,\n autoFocus = true,\n id,\n offset = [1, 4],\n renderOnlyWhenOpen = true,\n } = props;\n\n const [triggerElement, setTriggerElement] = useState<HTMLElement | null>(\n null,\n );\n const [popoverElement, setPopoverElement] = useState<HTMLElement | null>(\n null,\n );\n\n const {\n attributes: popperAttributes,\n update,\n styles: popperStyles,\n } = usePopper(triggerElement, popoverElement, {\n placement,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset,\n },\n },\n {\n ...sameWidth,\n enabled: isFullWidth,\n },\n {\n name: 'preventOverflow',\n enabled: isAutoalignmentEnabled,\n options: {\n mainAxis: true,\n },\n },\n {\n name: 'flip',\n enabled: isAutoalignmentEnabled,\n },\n ],\n });\n\n useEffect(() => {\n if (isOpen && autoFocus && popoverElement) {\n popoverElement.focus({ preventScroll: true });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen, popoverElement]);\n\n useEffect(() => {\n const updatePosition = async () => {\n if (isOpen && update) {\n await update();\n }\n };\n updatePosition();\n }, [isOpen, update]);\n\n const popoverGeneratedId = useId(undefined, 'popover-content');\n const popoverId = id || popoverGeneratedId;\n\n const closeAndFocusTrigger = useCallback(() => {\n onClose?.();\n\n // setTimeout trick to make it work with focus-lock\n setTimeout(() => triggerElement?.focus({ preventScroll: true }), 0);\n }, [onClose, triggerElement]);\n\n const contextValue: PopoverContextType = useMemo(\n () => ({\n isOpen: Boolean(isOpen),\n usePortal,\n renderOnlyWhenOpen,\n getTriggerProps: (_ref = null) => ({\n ref: mergeRefs(setTriggerElement, _ref),\n ['aria-expanded']: Boolean(isOpen),\n ['aria-controls']: popoverId,\n }),\n getPopoverProps: (_props = {}, _ref = null) => ({\n ...popperAttributes.popper,\n style: {\n ...(_props.style || {}),\n ...popperStyles.popper,\n },\n ref: mergeRefs(setPopoverElement, _ref),\n id: popoverId,\n onBlur: (event: React.FocusEvent<HTMLDivElement>) => {\n if (_props.onBlur) {\n _props.onBlur(event);\n }\n\n if (!closeOnBlur) {\n return;\n }\n\n const relatedTarget = event.relatedTarget as Node;\n\n const targetIsPopover =\n popoverElement === relatedTarget ||\n popoverElement?.contains(relatedTarget);\n const targetIsTrigger =\n triggerElement === relatedTarget ||\n triggerElement?.contains(relatedTarget);\n\n if (targetIsPopover || targetIsTrigger) {\n return;\n }\n\n onClose?.();\n },\n onKeyDown: (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (_props.onKeyDown) {\n _props.onKeyDown(event);\n }\n\n if (closeOnEsc && event.key === 'Escape') {\n closeAndFocusTrigger();\n }\n },\n }),\n }),\n [\n isOpen,\n renderOnlyWhenOpen,\n popperAttributes,\n popperStyles,\n usePortal,\n popoverId,\n closeOnEsc,\n closeOnBlur,\n popoverElement,\n triggerElement,\n closeAndFocusTrigger,\n onClose,\n ],\n );\n\n return (\n <PopoverContextProvider value={contextValue}>\n {children}\n </PopoverContextProvider>\n );\n}\n\n/**\n * Sets the popover width to the size of the trigger element.\n */\nconst sameWidth: Modifier<'sameWidth', any> = {\n name: 'sameWidth',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles'],\n fn: ({ state }) => {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n effect:\n ({ state }) =>\n () => {\n const reference = state.elements.reference as HTMLElement;\n state.elements.popper.style.width = `${reference.offsetWidth}px`;\n },\n};\n","import React, { HTMLProps } from 'react';\n\nexport type PopoverContextType = {\n isOpen: boolean;\n usePortal: boolean;\n renderOnlyWhenOpen: boolean;\n getPopoverProps: (\n _props: HTMLProps<HTMLDivElement>,\n _ref: React.Ref<HTMLDivElement>,\n ) => HTMLProps<HTMLDivElement>;\n getTriggerProps: (_ref: React.Ref<HTMLElement>) => HTMLProps<HTMLElement>;\n};\n\nconst PopoverContext = React.createContext<PopoverContextType | undefined>(\n undefined,\n);\n\nexport const usePopoverContext = () => {\n const context = React.useContext(PopoverContext);\n\n if (context === undefined) {\n throw new Error(\n 'usePopoverContext must be used within a PopoverContextProvider',\n );\n }\n\n return context;\n};\n\nexport const PopoverContextProvider = PopoverContext.Provider;\n","import React from 'react';\nimport { cx } from 'emotion';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\nimport { usePopoverContext } from '../PopoverContext';\nimport { Portal } from '@contentful/f36-utils';\nimport { getPopoverContentStyles } from './PopoverContent.styles';\n\ninterface PopoverContentInternalProps extends CommonProps {\n children?: React.ReactNode;\n}\n\nexport type PopoverContentProps = PropsWithHTMLElement<\n PopoverContentInternalProps,\n 'div'\n>;\n\nconst _PopoverContent = (props: ExpandProps<PopoverContentProps>, ref) => {\n const {\n children,\n className,\n testId = 'cf-ui-popover-content',\n role = 'dialog',\n ...otherProps\n } = props;\n const { isOpen, renderOnlyWhenOpen, getPopoverProps, usePortal } =\n usePopoverContext();\n\n const styles = getPopoverContentStyles(isOpen);\n\n const content = (\n <div\n {...otherProps}\n {...getPopoverProps(otherProps, ref)}\n className={cx(styles.container, className)}\n data-test-id={testId}\n tabIndex={-1}\n role={role}\n // specific attribute to mark that this element is absolute positioned\n // for internal contentful apps usage\n data-position-absolute\n >\n {children}\n </div>\n );\n\n if (renderOnlyWhenOpen && !isOpen) {\n return null;\n }\n\n return usePortal ? <Portal>{content}</Portal> : content;\n};\n\nexport const PopoverContent = React.forwardRef(_PopoverContent);\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getPopoverContentStyles = (isOpen: boolean) => ({\n container: css({\n display: isOpen ? 'initial' : 'none',\n background: tokens.colorWhite,\n border: 0,\n borderRadius: tokens.borderRadiusMedium,\n boxShadow: tokens.boxShadowDefault,\n zIndex: tokens.zIndexDropdown,\n '&:focus': {\n boxShadow: tokens.glowPrimary,\n outline: 'none',\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: tokens.boxShadowDefault,\n },\n }),\n});\n","import React from 'react';\nimport { usePopoverContext } from '../PopoverContext';\n\nexport interface PopoverTriggerProps {\n children: React.ReactNode;\n}\n\n/**\n * PopoverTrigger opens the popover. It must be an interactive element.\n */\nexport const PopoverTrigger = (props: PopoverTriggerProps) => {\n const child = React.Children.only(props.children) as any;\n const { getTriggerProps } = usePopoverContext();\n\n return React.cloneElement(child, {\n ...getTriggerProps(child.ref),\n 'aria-haspopup': child.props['aria-haspopup'] ?? 'dialog',\n });\n};\n"],"names":["Popover","PopoverProps","PopoverTrigger","PopoverTriggerProps","PopoverContent","PopoverContentProps","OriginalPopover","CompoundPopover","Content","Trigger","React","useMemo","useState","useEffect","useCallback","useId","mergeRefs","ExpandProps","Placement","Modifier","PopoverContextProvider","PopoverContextType","usePopper","children","ReactNode","isFullWidth","isOpen","onClose","placement","isAutoalignmentEnabled","usePortal","closeOnBlur","closeOnEsc","autoFocus","id","offset","renderOnlyWhenOpen","props","triggerElement","setTriggerElement","HTMLElement","popoverElement","setPopoverElement","attributes","popperAttributes","update","styles","popperStyles","modifiers","name","options","sameWidth","enabled","mainAxis","focus","preventScroll","updatePosition","popoverGeneratedId","undefined","popoverId","closeAndFocusTrigger","setTimeout","contextValue","Boolean","getTriggerProps","_ref","ref","getPopoverProps","_props","popper","style","onBlur","event","FocusEvent","HTMLDivElement","relatedTarget","Node","targetIsPopover","contains","targetIsTrigger","onKeyDown","KeyboardEvent","key","phase","requires","fn","state","width","rects","reference","effect","elements","offsetWidth","HTMLProps","Ref","PopoverContext","createContext","usePopoverContext","context","useContext","Error","Provider","CommonProps","PropsWithHTMLElement","Portal","getPopoverContentStyles","PopoverContentInternalProps","_PopoverContent","className","testId","role","otherProps","content","container","forwardRef","tokens","display","background","colorWhite","border","borderRadius","borderRadiusMedium","boxShadow","boxShadowDefault","zIndex","zIndexDropdown","glowPrimary","outline","child","Children","only","cloneElement"],"version":3,"file":"main.js.map"}
|
package/dist/module.js
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
import $hYGFM$react, {useState as $hYGFM$useState, useEffect as $hYGFM$useEffect, useCallback as $hYGFM$useCallback, useMemo as $hYGFM$useMemo} from "react";
|
|
2
|
-
import {useId as $hYGFM$useId, mergeRefs as $hYGFM$mergeRefs} from "@contentful/f36-core";
|
|
3
|
-
import {usePopper as $hYGFM$usePopper} from "react-popper";
|
|
4
|
-
import {cx as $hYGFM$cx, css as $hYGFM$css} from "emotion";
|
|
5
|
-
import {Portal as $hYGFM$Portal} from "@contentful/f36-utils";
|
|
6
|
-
import $hYGFM$contentfulf36tokens from "@contentful/f36-tokens";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const $8c1b76e1106abdf5$var$PopoverContext = (0, $hYGFM$react).createContext(undefined);
|
|
12
|
-
const $8c1b76e1106abdf5$export$1468d0761b26e6c8 = ()=>{
|
|
13
|
-
const context = (0, $hYGFM$react).useContext($8c1b76e1106abdf5$var$PopoverContext);
|
|
14
|
-
if (context === undefined) throw new Error("usePopoverContext must be used within a PopoverContextProvider");
|
|
15
|
-
return context;
|
|
16
|
-
};
|
|
17
|
-
const $8c1b76e1106abdf5$export$f5300fbf692a63ec = $8c1b76e1106abdf5$var$PopoverContext.Provider;
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
function $fd548c9231cfa260$export$5b6b19405a83ff9d(props) {
|
|
22
|
-
const { children: children , isOpen: isOpen , placement: placement = "bottom-start" , isFullWidth: isFullWidth = false , isAutoalignmentEnabled: isAutoalignmentEnabled = true , usePortal: usePortal = true , closeOnBlur: closeOnBlur = true , closeOnEsc: closeOnEsc = true , onClose: onClose , autoFocus: autoFocus = true , id: id , offset: offset = [
|
|
23
|
-
1,
|
|
24
|
-
4
|
|
25
|
-
] , renderOnlyWhenOpen: renderOnlyWhenOpen = true } = props;
|
|
26
|
-
const [triggerElement, setTriggerElement] = (0, $hYGFM$useState)(null);
|
|
27
|
-
const [popoverElement, setPopoverElement] = (0, $hYGFM$useState)(null);
|
|
28
|
-
const { attributes: popperAttributes , update: update , styles: popperStyles } = (0, $hYGFM$usePopper)(triggerElement, popoverElement, {
|
|
29
|
-
placement: placement,
|
|
30
|
-
modifiers: [
|
|
31
|
-
{
|
|
32
|
-
name: "offset",
|
|
33
|
-
options: {
|
|
34
|
-
offset: offset
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
...$fd548c9231cfa260$var$sameWidth,
|
|
39
|
-
enabled: isFullWidth
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
name: "preventOverflow",
|
|
43
|
-
enabled: isAutoalignmentEnabled,
|
|
44
|
-
options: {
|
|
45
|
-
mainAxis: true
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
name: "flip",
|
|
50
|
-
enabled: isAutoalignmentEnabled
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
});
|
|
54
|
-
(0, $hYGFM$useEffect)(()=>{
|
|
55
|
-
if (isOpen && autoFocus && popoverElement) popoverElement.focus({
|
|
56
|
-
preventScroll: true
|
|
57
|
-
});
|
|
58
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
59
|
-
}, [
|
|
60
|
-
isOpen,
|
|
61
|
-
popoverElement
|
|
62
|
-
]);
|
|
63
|
-
(0, $hYGFM$useEffect)(()=>{
|
|
64
|
-
const updatePosition = async ()=>{
|
|
65
|
-
if (isOpen && update) await update();
|
|
66
|
-
};
|
|
67
|
-
updatePosition();
|
|
68
|
-
}, [
|
|
69
|
-
isOpen,
|
|
70
|
-
update
|
|
71
|
-
]);
|
|
72
|
-
const popoverGeneratedId = (0, $hYGFM$useId)(undefined, "popover-content");
|
|
73
|
-
const popoverId = id || popoverGeneratedId;
|
|
74
|
-
const closeAndFocusTrigger = (0, $hYGFM$useCallback)(()=>{
|
|
75
|
-
onClose === null || onClose === void 0 ? void 0 : onClose(); // setTimeout trick to make it work with focus-lock
|
|
76
|
-
setTimeout(()=>{
|
|
77
|
-
return triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.focus({
|
|
78
|
-
preventScroll: true
|
|
79
|
-
});
|
|
80
|
-
}, 0);
|
|
81
|
-
}, [
|
|
82
|
-
onClose,
|
|
83
|
-
triggerElement
|
|
84
|
-
]);
|
|
85
|
-
const contextValue = (0, $hYGFM$useMemo)(()=>{
|
|
86
|
-
return {
|
|
87
|
-
isOpen: Boolean(isOpen),
|
|
88
|
-
usePortal: usePortal,
|
|
89
|
-
renderOnlyWhenOpen: renderOnlyWhenOpen,
|
|
90
|
-
getTriggerProps: (_ref = null)=>({
|
|
91
|
-
ref: (0, $hYGFM$mergeRefs)(setTriggerElement, _ref),
|
|
92
|
-
["aria-expanded"]: Boolean(isOpen),
|
|
93
|
-
["aria-controls"]: popoverId
|
|
94
|
-
}),
|
|
95
|
-
getPopoverProps: (_props = {}, _ref = null)=>{
|
|
96
|
-
return {
|
|
97
|
-
...popperAttributes.popper,
|
|
98
|
-
style: {
|
|
99
|
-
..._props.style || {},
|
|
100
|
-
...popperStyles.popper
|
|
101
|
-
},
|
|
102
|
-
ref: (0, $hYGFM$mergeRefs)(setPopoverElement, _ref),
|
|
103
|
-
id: popoverId,
|
|
104
|
-
onBlur: (event)=>{
|
|
105
|
-
if (_props.onBlur) _props.onBlur(event);
|
|
106
|
-
if (!closeOnBlur) return;
|
|
107
|
-
const relatedTarget = event.relatedTarget;
|
|
108
|
-
const targetIsPopover = popoverElement === relatedTarget || (popoverElement === null || popoverElement === void 0 ? void 0 : popoverElement.contains(relatedTarget));
|
|
109
|
-
const targetIsTrigger = triggerElement === relatedTarget || (triggerElement === null || triggerElement === void 0 ? void 0 : triggerElement.contains(relatedTarget));
|
|
110
|
-
if (targetIsPopover || targetIsTrigger) return;
|
|
111
|
-
onClose === null || onClose === void 0 ? void 0 : onClose();
|
|
112
|
-
},
|
|
113
|
-
onKeyDown: (event)=>{
|
|
114
|
-
if (_props.onKeyDown) _props.onKeyDown(event);
|
|
115
|
-
if (closeOnEsc && event.key === "Escape") closeAndFocusTrigger();
|
|
116
|
-
}
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
}, [
|
|
121
|
-
isOpen,
|
|
122
|
-
renderOnlyWhenOpen,
|
|
123
|
-
popperAttributes,
|
|
124
|
-
popperStyles,
|
|
125
|
-
usePortal,
|
|
126
|
-
popoverId,
|
|
127
|
-
closeOnEsc,
|
|
128
|
-
closeOnBlur,
|
|
129
|
-
popoverElement,
|
|
130
|
-
triggerElement,
|
|
131
|
-
closeAndFocusTrigger,
|
|
132
|
-
onClose
|
|
133
|
-
]);
|
|
134
|
-
return /*#__PURE__*/ (0, $hYGFM$react).createElement((0, $8c1b76e1106abdf5$export$f5300fbf692a63ec), {
|
|
135
|
-
value: contextValue
|
|
136
|
-
}, children);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Sets the popover width to the size of the trigger element.
|
|
140
|
-
*/ const $fd548c9231cfa260$var$sameWidth = {
|
|
141
|
-
name: "sameWidth",
|
|
142
|
-
enabled: true,
|
|
143
|
-
phase: "beforeWrite",
|
|
144
|
-
requires: [
|
|
145
|
-
"computeStyles"
|
|
146
|
-
],
|
|
147
|
-
fn: ({ state: state })=>{
|
|
148
|
-
state.styles.popper.width = `${state.rects.reference.width}px`;
|
|
149
|
-
},
|
|
150
|
-
effect: ({ state: state })=>()=>{
|
|
151
|
-
const reference = state.elements.reference;
|
|
152
|
-
state.elements.popper.style.width = `${reference.offsetWidth}px`;
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const $8a165eef2449d46a$export$fbd764fe961047f7 = (isOpen)=>({
|
|
164
|
-
container: /*#__PURE__*/ (0, $hYGFM$css)({
|
|
165
|
-
display: isOpen ? "initial" : "none",
|
|
166
|
-
background: (0, $hYGFM$contentfulf36tokens).colorWhite,
|
|
167
|
-
border: 0,
|
|
168
|
-
borderRadius: (0, $hYGFM$contentfulf36tokens).borderRadiusMedium,
|
|
169
|
-
boxShadow: (0, $hYGFM$contentfulf36tokens).boxShadowDefault,
|
|
170
|
-
zIndex: (0, $hYGFM$contentfulf36tokens).zIndexDropdown,
|
|
171
|
-
"&:focus": {
|
|
172
|
-
boxShadow: (0, $hYGFM$contentfulf36tokens).glowPrimary,
|
|
173
|
-
outline: "none"
|
|
174
|
-
},
|
|
175
|
-
"&:focus:not(:focus-visible)": {
|
|
176
|
-
boxShadow: (0, $hYGFM$contentfulf36tokens).boxShadowDefault
|
|
177
|
-
}
|
|
178
|
-
})
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
const $249e5486684b1d2a$var$_PopoverContent = (props, ref)=>{
|
|
183
|
-
const { children: children , className: className , testId: testId = "cf-ui-popover-content" , role: role = "dialog" , ...otherProps } = props;
|
|
184
|
-
const { isOpen: isOpen , renderOnlyWhenOpen: renderOnlyWhenOpen , getPopoverProps: getPopoverProps , usePortal: usePortal } = (0, $8c1b76e1106abdf5$export$1468d0761b26e6c8)();
|
|
185
|
-
const styles = (0, $8a165eef2449d46a$export$fbd764fe961047f7)(isOpen);
|
|
186
|
-
const content = /*#__PURE__*/ (0, $hYGFM$react).createElement("div", {
|
|
187
|
-
...otherProps,
|
|
188
|
-
...getPopoverProps(otherProps, ref),
|
|
189
|
-
className: (0, $hYGFM$cx)(styles.container, className),
|
|
190
|
-
"data-test-id": testId,
|
|
191
|
-
tabIndex: -1,
|
|
192
|
-
role: role,
|
|
193
|
-
// for internal contentful apps usage
|
|
194
|
-
"data-position-absolute": true
|
|
195
|
-
}, children);
|
|
196
|
-
if (renderOnlyWhenOpen && !isOpen) return null;
|
|
197
|
-
return usePortal ? /*#__PURE__*/ (0, $hYGFM$react).createElement((0, $hYGFM$Portal), null, content) : content;
|
|
198
|
-
};
|
|
199
|
-
const $249e5486684b1d2a$export$d7e1f420b25549ff = /*#__PURE__*/ (0, $hYGFM$react).forwardRef($249e5486684b1d2a$var$_PopoverContent);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
const $2ab55052da688660$export$7dacb05d26466c3 = (props)=>{
|
|
205
|
-
const child = (0, $hYGFM$react).Children.only(props.children);
|
|
206
|
-
const { getTriggerProps: getTriggerProps } = (0, $8c1b76e1106abdf5$export$1468d0761b26e6c8)();
|
|
207
|
-
var ref;
|
|
208
|
-
return /*#__PURE__*/ (0, $hYGFM$react).cloneElement(child, {
|
|
209
|
-
...getTriggerProps(child.ref),
|
|
210
|
-
"aria-haspopup": (ref = child.props["aria-haspopup"]) !== null && ref !== void 0 ? ref : "dialog"
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const $52a0de85cb27ef74$export$5b6b19405a83ff9d = (0, $fd548c9231cfa260$export$5b6b19405a83ff9d);
|
|
216
|
-
$52a0de85cb27ef74$export$5b6b19405a83ff9d.Content = (0, $249e5486684b1d2a$export$d7e1f420b25549ff);
|
|
217
|
-
$52a0de85cb27ef74$export$5b6b19405a83ff9d.Trigger = (0, $2ab55052da688660$export$7dacb05d26466c3);
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
export {$52a0de85cb27ef74$export$5b6b19405a83ff9d as Popover, $2ab55052da688660$export$7dacb05d26466c3 as PopoverTrigger, $249e5486684b1d2a$export$d7e1f420b25549ff as PopoverContent};
|
|
225
|
-
//# sourceMappingURL=module.js.map
|
package/dist/module.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;AEAA;;ACAA;AAaA,MAAM+F,oCAAc,GAAGrF,CAAAA,GAAAA,YAAK,CAAA,CAACsF,aAAa,CACxCtC,SADqB,CAAvB,AA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,YAAK,CAAA,CAACyH,YAAN,CAAmBH,KAAnB,EAA0B;QAC/B,GAAGhE,eAAe,CAACgE,KAAK,CAAC9D,GAAP,CADa;QAE/B,eAAA,EAAiB8D,CAAAA,GAAA,GAAAA,KAAK,CAAC3F,KAAN,CAAY,eAAZ,CAAA,cAAA2F,GAAA,cAAAA,GAAA,GAAgC,QAAjD;KAFK,CAAP,CAAiC;CAJ5B,AAQN;;;ALTM,MAAMhI,yCAAO,GAAGM,CAAAA,GAAAA,yCAAe,CAAA,AAA/B,AAAP;AACAN,yCAAO,CAACQ,OAAR,GAAkBJ,CAAAA,GAAAA,yCAAlB,CAAA,CAAAJ;AACAA,yCAAO,CAACS,OAAR,GAAkBP,CAAAA,GAAAA,wCAAlB,CAAA,CAAAF;;ADXA","sources":["packages/components/popover/src/index.ts","packages/components/popover/src/CompoundPopover.tsx","packages/components/popover/src/Popover.tsx","packages/components/popover/src/PopoverContext.ts","packages/components/popover/src/PopoverContent/PopoverContent.tsx","packages/components/popover/src/PopoverContent/PopoverContent.styles.ts","packages/components/popover/src/PopoverTrigger/PopoverTrigger.tsx"],"sourcesContent":["export { Popover } from './CompoundPopover';\nexport type { PopoverProps } from './Popover';\nexport { PopoverTrigger } from './PopoverTrigger/PopoverTrigger';\nexport type { PopoverTriggerProps } from './PopoverTrigger/PopoverTrigger';\nexport { PopoverContent } from './PopoverContent/PopoverContent';\nexport type { PopoverContentProps } from './PopoverContent/PopoverContent';\n","import { Popover as OriginalPopover } from './Popover';\nimport { PopoverContent } from './PopoverContent/PopoverContent';\nimport { PopoverTrigger } from './PopoverTrigger/PopoverTrigger';\n\ntype CompoundPopover = typeof OriginalPopover & {\n Content: typeof PopoverContent;\n Trigger: typeof PopoverTrigger;\n};\n\nexport const Popover = OriginalPopover as CompoundPopover;\nPopover.Content = PopoverContent;\nPopover.Trigger = PopoverTrigger;\n","import React, { useMemo, useState, useEffect, useCallback } from 'react';\nimport { useId, mergeRefs, type ExpandProps } from '@contentful/f36-core';\nimport type { Placement, Modifier } from '@popperjs/core';\nimport { PopoverContextProvider, PopoverContextType } from './PopoverContext';\nimport { usePopper } from 'react-popper';\n\nexport interface PopoverProps {\n children: React.ReactNode;\n\n /**\n * Boolean to determine if the Popover should be the same width as\n * the trigger element\n *\n * @default false\n */\n isFullWidth?: boolean;\n\n /**\n * Boolean to control whether or not the Popover is open\n *\n * @default false\n */\n isOpen?: boolean;\n\n /**\n * Callback fired when the popover closes\n */\n onClose?: () => void;\n\n /**\n * Determines the preferred position of the Popover. This position is not\n * guaranteed, as the Popover might be moved to fit the viewport\n *\n * @default bottom-start\n */\n placement?: Placement;\n\n /**\n * Boolean to control if popover is allowed to change its placement automatically\n * based on available space in the viewport.\n *\n * For example:\n * If you set placement prop to bottom, but there isn't enough space to position the popover in that direction,\n * it will change the popper placement to top. As soon as enough space is detected, the placement will be reverted to the defined one.\n *\n * If you want the popover to strictly follow the placement prop you should set this prop to false.\n *\n * @default true\n */\n isAutoalignmentEnabled?: boolean;\n\n /**\n * Boolean to control whether or not to render the Popover in a React Portal.\n * Rendering content inside a Portal allows the Popover to escape the bounds\n * of its parent while still being positioned correctly. Using a Portal is\n * necessary if an ancestor of the Popover hides overflow.\n *\n * @default true\n */\n usePortal?: boolean;\n\n /**\n * If true, the popover will close when you blur out it by clicking outside or tabbing out\n *\n * @default true\n */\n closeOnBlur?: boolean;\n\n /**\n * If true, the popover will close when you hit the Esc key\n *\n * @default true\n */\n closeOnEsc?: boolean;\n\n /**\n * If true, the popover will be focused after opening\n *\n * @default true\n */\n autoFocus?: boolean;\n\n /**\n * Popover id. Will be used as an `id` attribute on popover\n * and as `aria-controls` attribute on trigger\n *\n * @default true\n */\n id?: string;\n\n /**\n * The `X-axis` and `Y-axis` offset to position popper element\n * from its trigger element. `[X, Y]`\n *\n * @default [1, 4]\n */\n offset?: [number, number];\n\n /**\n * Defines if popover should be rendered in the DOM only when it's open\n * or all the time (after the component has been mounted)\n *\n * @default true\n */\n renderOnlyWhenOpen?: boolean;\n}\n\nexport function Popover(props: ExpandProps<PopoverProps>) {\n const {\n children,\n isOpen,\n placement = 'bottom-start',\n isFullWidth = false,\n isAutoalignmentEnabled = true,\n usePortal = true,\n closeOnBlur = true,\n closeOnEsc = true,\n onClose,\n autoFocus = true,\n id,\n offset = [1, 4],\n renderOnlyWhenOpen = true,\n } = props;\n\n const [triggerElement, setTriggerElement] = useState<HTMLElement | null>(\n null,\n );\n const [popoverElement, setPopoverElement] = useState<HTMLElement | null>(\n null,\n );\n\n const {\n attributes: popperAttributes,\n update,\n styles: popperStyles,\n } = usePopper(triggerElement, popoverElement, {\n placement,\n modifiers: [\n {\n name: 'offset',\n options: {\n offset,\n },\n },\n {\n ...sameWidth,\n enabled: isFullWidth,\n },\n {\n name: 'preventOverflow',\n enabled: isAutoalignmentEnabled,\n options: {\n mainAxis: true,\n },\n },\n {\n name: 'flip',\n enabled: isAutoalignmentEnabled,\n },\n ],\n });\n\n useEffect(() => {\n if (isOpen && autoFocus && popoverElement) {\n popoverElement.focus({ preventScroll: true });\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [isOpen, popoverElement]);\n\n useEffect(() => {\n const updatePosition = async () => {\n if (isOpen && update) {\n await update();\n }\n };\n updatePosition();\n }, [isOpen, update]);\n\n const popoverGeneratedId = useId(undefined, 'popover-content');\n const popoverId = id || popoverGeneratedId;\n\n const closeAndFocusTrigger = useCallback(() => {\n onClose?.();\n\n // setTimeout trick to make it work with focus-lock\n setTimeout(() => triggerElement?.focus({ preventScroll: true }), 0);\n }, [onClose, triggerElement]);\n\n const contextValue: PopoverContextType = useMemo(\n () => ({\n isOpen: Boolean(isOpen),\n usePortal,\n renderOnlyWhenOpen,\n getTriggerProps: (_ref = null) => ({\n ref: mergeRefs(setTriggerElement, _ref),\n ['aria-expanded']: Boolean(isOpen),\n ['aria-controls']: popoverId,\n }),\n getPopoverProps: (_props = {}, _ref = null) => ({\n ...popperAttributes.popper,\n style: {\n ...(_props.style || {}),\n ...popperStyles.popper,\n },\n ref: mergeRefs(setPopoverElement, _ref),\n id: popoverId,\n onBlur: (event: React.FocusEvent<HTMLDivElement>) => {\n if (_props.onBlur) {\n _props.onBlur(event);\n }\n\n if (!closeOnBlur) {\n return;\n }\n\n const relatedTarget = event.relatedTarget as Node;\n\n const targetIsPopover =\n popoverElement === relatedTarget ||\n popoverElement?.contains(relatedTarget);\n const targetIsTrigger =\n triggerElement === relatedTarget ||\n triggerElement?.contains(relatedTarget);\n\n if (targetIsPopover || targetIsTrigger) {\n return;\n }\n\n onClose?.();\n },\n onKeyDown: (event: React.KeyboardEvent<HTMLDivElement>) => {\n if (_props.onKeyDown) {\n _props.onKeyDown(event);\n }\n\n if (closeOnEsc && event.key === 'Escape') {\n closeAndFocusTrigger();\n }\n },\n }),\n }),\n [\n isOpen,\n renderOnlyWhenOpen,\n popperAttributes,\n popperStyles,\n usePortal,\n popoverId,\n closeOnEsc,\n closeOnBlur,\n popoverElement,\n triggerElement,\n closeAndFocusTrigger,\n onClose,\n ],\n );\n\n return (\n <PopoverContextProvider value={contextValue}>\n {children}\n </PopoverContextProvider>\n );\n}\n\n/**\n * Sets the popover width to the size of the trigger element.\n */\nconst sameWidth: Modifier<'sameWidth', any> = {\n name: 'sameWidth',\n enabled: true,\n phase: 'beforeWrite',\n requires: ['computeStyles'],\n fn: ({ state }) => {\n state.styles.popper.width = `${state.rects.reference.width}px`;\n },\n effect:\n ({ state }) =>\n () => {\n const reference = state.elements.reference as HTMLElement;\n state.elements.popper.style.width = `${reference.offsetWidth}px`;\n },\n};\n","import React, { HTMLProps } from 'react';\n\nexport type PopoverContextType = {\n isOpen: boolean;\n usePortal: boolean;\n renderOnlyWhenOpen: boolean;\n getPopoverProps: (\n _props: HTMLProps<HTMLDivElement>,\n _ref: React.Ref<HTMLDivElement>,\n ) => HTMLProps<HTMLDivElement>;\n getTriggerProps: (_ref: React.Ref<HTMLElement>) => HTMLProps<HTMLElement>;\n};\n\nconst PopoverContext = React.createContext<PopoverContextType | undefined>(\n undefined,\n);\n\nexport const usePopoverContext = () => {\n const context = React.useContext(PopoverContext);\n\n if (context === undefined) {\n throw new Error(\n 'usePopoverContext must be used within a PopoverContextProvider',\n );\n }\n\n return context;\n};\n\nexport const PopoverContextProvider = PopoverContext.Provider;\n","import React from 'react';\nimport { cx } from 'emotion';\nimport type {\n CommonProps,\n PropsWithHTMLElement,\n ExpandProps,\n} from '@contentful/f36-core';\nimport { usePopoverContext } from '../PopoverContext';\nimport { Portal } from '@contentful/f36-utils';\nimport { getPopoverContentStyles } from './PopoverContent.styles';\n\ninterface PopoverContentInternalProps extends CommonProps {\n children?: React.ReactNode;\n}\n\nexport type PopoverContentProps = PropsWithHTMLElement<\n PopoverContentInternalProps,\n 'div'\n>;\n\nconst _PopoverContent = (props: ExpandProps<PopoverContentProps>, ref) => {\n const {\n children,\n className,\n testId = 'cf-ui-popover-content',\n role = 'dialog',\n ...otherProps\n } = props;\n const { isOpen, renderOnlyWhenOpen, getPopoverProps, usePortal } =\n usePopoverContext();\n\n const styles = getPopoverContentStyles(isOpen);\n\n const content = (\n <div\n {...otherProps}\n {...getPopoverProps(otherProps, ref)}\n className={cx(styles.container, className)}\n data-test-id={testId}\n tabIndex={-1}\n role={role}\n // specific attribute to mark that this element is absolute positioned\n // for internal contentful apps usage\n data-position-absolute\n >\n {children}\n </div>\n );\n\n if (renderOnlyWhenOpen && !isOpen) {\n return null;\n }\n\n return usePortal ? <Portal>{content}</Portal> : content;\n};\n\nexport const PopoverContent = React.forwardRef(_PopoverContent);\n","import { css } from 'emotion';\nimport tokens from '@contentful/f36-tokens';\n\nexport const getPopoverContentStyles = (isOpen: boolean) => ({\n container: css({\n display: isOpen ? 'initial' : 'none',\n background: tokens.colorWhite,\n border: 0,\n borderRadius: tokens.borderRadiusMedium,\n boxShadow: tokens.boxShadowDefault,\n zIndex: tokens.zIndexDropdown,\n '&:focus': {\n boxShadow: tokens.glowPrimary,\n outline: 'none',\n },\n '&:focus:not(:focus-visible)': {\n boxShadow: tokens.boxShadowDefault,\n },\n }),\n});\n","import React from 'react';\nimport { usePopoverContext } from '../PopoverContext';\n\nexport interface PopoverTriggerProps {\n children: React.ReactNode;\n}\n\n/**\n * PopoverTrigger opens the popover. It must be an interactive element.\n */\nexport const PopoverTrigger = (props: PopoverTriggerProps) => {\n const child = React.Children.only(props.children) as any;\n const { getTriggerProps } = usePopoverContext();\n\n return React.cloneElement(child, {\n ...getTriggerProps(child.ref),\n 'aria-haspopup': child.props['aria-haspopup'] ?? 'dialog',\n });\n};\n"],"names":["Popover","PopoverProps","PopoverTrigger","PopoverTriggerProps","PopoverContent","PopoverContentProps","OriginalPopover","CompoundPopover","Content","Trigger","React","useMemo","useState","useEffect","useCallback","useId","mergeRefs","ExpandProps","Placement","Modifier","PopoverContextProvider","PopoverContextType","usePopper","children","ReactNode","isFullWidth","isOpen","onClose","placement","isAutoalignmentEnabled","usePortal","closeOnBlur","closeOnEsc","autoFocus","id","offset","renderOnlyWhenOpen","props","triggerElement","setTriggerElement","HTMLElement","popoverElement","setPopoverElement","attributes","popperAttributes","update","styles","popperStyles","modifiers","name","options","sameWidth","enabled","mainAxis","focus","preventScroll","updatePosition","popoverGeneratedId","undefined","popoverId","closeAndFocusTrigger","setTimeout","contextValue","Boolean","getTriggerProps","_ref","ref","getPopoverProps","_props","popper","style","onBlur","event","FocusEvent","HTMLDivElement","relatedTarget","Node","targetIsPopover","contains","targetIsTrigger","onKeyDown","KeyboardEvent","key","phase","requires","fn","state","width","rects","reference","effect","elements","offsetWidth","HTMLProps","Ref","PopoverContext","createContext","usePopoverContext","context","useContext","Error","Provider","CommonProps","PropsWithHTMLElement","Portal","getPopoverContentStyles","PopoverContentInternalProps","_PopoverContent","className","testId","role","otherProps","content","container","forwardRef","tokens","display","background","colorWhite","border","borderRadius","borderRadiusMedium","boxShadow","boxShadowDefault","zIndex","zIndexDropdown","glowPrimary","outline","child","Children","only","cloneElement"],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts.map
DEL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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;eAQxD,CAAC;ACdF,uBAAuB,gBAAsB,GAAG;IAC9C,OAAO,EAAE,qBAAqB,CAAC;IAC/B,OAAO,EAAE,qBAAqB,CAAC;CAChC,CAAC;AAEF,OAAO,MAAM,wBAA4C,CAAC","sources":["packages/components/popover/src/src/PopoverContext.ts","packages/components/popover/src/src/Popover.tsx","packages/components/popover/src/src/PopoverContent/PopoverContent.styles.ts","packages/components/popover/src/src/PopoverContent/PopoverContent.tsx","packages/components/popover/src/src/PopoverTrigger/PopoverTrigger.tsx","packages/components/popover/src/src/CompoundPopover.tsx","packages/components/popover/src/src/index.ts","packages/components/popover/src/index.ts"],"sourcesContent":[null,null,null,null,null,null,null,"export { Popover } from './CompoundPopover';\nexport type { PopoverProps } from './Popover';\nexport { PopoverTrigger } from './PopoverTrigger/PopoverTrigger';\nexport type { PopoverTriggerProps } from './PopoverTrigger/PopoverTrigger';\nexport { PopoverContent } from './PopoverContent/PopoverContent';\nexport type { PopoverContentProps } from './PopoverContent/PopoverContent';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|