@khanacademy/wonder-blocks-modal 8.10.6 → 9.0.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/.turbo/turbo-build$colon$css.log +1 -1
- package/CHANGELOG.md +129 -0
- package/dist/components/modal-header.d.ts +5 -0
- package/dist/es/index.css +618 -0
- package/dist/es/index.css.map +1 -0
- package/dist/es/index.js +50 -24
- package/dist/index.css +618 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +53 -27
- package/dist/util/small-screen-styles.d.ts +44 -0
- package/package.json +19 -12
package/dist/es/index.js
CHANGED
|
@@ -1,65 +1,91 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { View, Id, useDirectionDetection } from '@khanacademy/wonder-blocks-core';
|
|
4
|
-
import { StyleSheet } from 'aphrodite';
|
|
5
|
-
import { border, sizing, mapValuesToCssVars, semanticColor, breakpoint } from '@khanacademy/wonder-blocks-tokens';
|
|
6
4
|
import { attachAnnouncerToModal, detachAnnouncerFromModal } from '@khanacademy/wonder-blocks-announcer';
|
|
5
|
+
import { border, sizing, mapValuesToCssVars, breakpoint, semanticColor } from '@khanacademy/wonder-blocks-tokens';
|
|
7
6
|
import { Heading, BodyText } from '@khanacademy/wonder-blocks-typography';
|
|
8
7
|
import * as ReactDOM from 'react-dom';
|
|
9
8
|
import { withActionScheduler, SchedulePolicy, ClearPolicy } from '@khanacademy/wonder-blocks-timing';
|
|
10
|
-
import { focusStyles } from '@khanacademy/wonder-blocks-styles';
|
|
11
9
|
import xIcon from '@phosphor-icons/core/bold/x-bold.svg';
|
|
12
10
|
import IconButton from '@khanacademy/wonder-blocks-icon-button';
|
|
13
11
|
import { useWonderBlocksI18n } from '@khanacademy/wonder-blocks-config';
|
|
14
12
|
|
|
15
13
|
function useModalAnnouncer(forwardedRef){const internalRef=React.useRef(null);React.useEffect(()=>{const el=internalRef.current;if(!el){return}attachAnnouncerToModal(el);return ()=>{detachAnnouncerFromModal(el);}},[]);const ariaModalRef=React.useCallback(node=>{internalRef.current=node;if(typeof forwardedRef==="function"){forwardedRef(node);}else if(forwardedRef){forwardedRef.current=node;}},[]);return {ariaModalRef}}
|
|
16
14
|
|
|
15
|
+
const theme$1={root:{border:{radius:border.radius.radius_040}},dialog:{layout:{padding:sizing.size_160},shadow:{default:"none"}},header:{layout:{padding:{block:sizing.size_240,inline:{default:sizing.size_320,small:sizing.size_160}},gap:{default:sizing.size_080,title:{default:sizing.size_160,small:sizing.size_320}}}},panel:{layout:{gap:{default:sizing.size_320,small:sizing.size_160}}},footer:{layout:{padding:{inline:sizing.size_160,block:sizing.size_080}}},closeButton:{layout:{gapRight:sizing.size_080,gapTop:sizing.size_080}}};var themeDefault = theme$1;
|
|
16
|
+
|
|
17
|
+
var theme = mapValuesToCssVars(themeDefault,"--wb-c-modal-");
|
|
18
|
+
|
|
17
19
|
const ModalLauncherPortalAttributeName="data-modal-launcher-portal";const height={smMin:500};const width={mid:767};const modalMediaQuery={midOrSmaller:`@media screen and (max-width: ${width.mid}px) /* breakpoint.mediaQuery.midOrSmaller */`,midOrLarger:`@media screen and (min-width: ${width.mid}px) /* breakpoint.mediaQuery.midOrLarger */`,smMinOrSmallerHeight:`@media screen and (max-height:${height.smMin}px)`};
|
|
18
20
|
|
|
19
|
-
const
|
|
21
|
+
const wrapperSmallScreenStyles={[modalMediaQuery.smMinOrSmallerHeight]:{overflow:"auto"},[modalMediaQuery.midOrSmaller]:{flexDirection:"column"}};const onePaneDialogSmallScreenStyles={[modalMediaQuery.smMinOrSmallerHeight]:{overflow:"auto"},[modalMediaQuery.midOrSmaller]:{flexDirection:"column",width:"100%",height:"100%",overflow:"hidden"}};const panelSmallScreenStyles={[modalMediaQuery.smMinOrSmallerHeight]:{overflow:"auto"}};const contentSmallScreenStyles={[modalMediaQuery.midOrSmaller]:{paddingInline:theme.panel.layout.gap.small}};const contentSmallHeightStyles={[modalMediaQuery.smMinOrSmallerHeight]:{flex:"unset",minBlockSize:"unset",overflow:"unset"}};const drawerSmallScreenStyles={[breakpoint.mediaQuery.smOrSmaller]:{minInlineSize:"unset",maxInlineSize:"unset"}};const drawerBlockEndSmallScreenStyles={[breakpoint.mediaQuery.smOrSmaller]:{minInlineSize:"unset",maxInlineSize:"unset",height:"auto"}};
|
|
22
|
+
|
|
23
|
+
var modules_802b32ef={"root":"wb-modal-dialog-root-0c114631","paddingLayer":"wb-modal-dialog-paddingLayer-0c114631","wrapper":"wb-modal-dialog-wrapper-0c114631","dialog":"wb-modal-dialog-dialog-0c114631","above":"wb-modal-dialog-above-0c114631","below":"wb-modal-dialog-below-0c114631"};
|
|
24
|
+
|
|
25
|
+
const ModalDialog=React.forwardRef(function ModalDialog(props,ref){const{above,below,role="dialog",style,children,testId,"aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,"aria-describedby":ariaDescribedBy}=props;const{ariaModalRef}=useModalAnnouncer(ref);return jsx(View,{style:[modules_802b32ef.root,modules_802b32ef.paddingLayer],"data-modal-padding-layer":true,children:jsxs(View,{style:[modules_802b32ef.wrapper,wrapperSmallScreenStyles,style],children:[below&&jsx(View,{style:modules_802b32ef.below,children:below}),jsx(View,{role:role,"aria-modal":"true","aria-label":ariaLabel,"aria-labelledby":ariaLabelledBy,"aria-describedby":ariaDescribedBy,ref:ariaModalRef,style:modules_802b32ef.dialog,testId:testId,children:children}),above&&jsx(View,{style:modules_802b32ef.above,children:above})]})})});ModalDialog.displayName="ModalDialog";var ModalDialog$1 = ModalDialog;
|
|
20
26
|
|
|
21
|
-
var
|
|
27
|
+
var modules_6a3864ff={"root":"wb-modal-footer-root-9e947823","footer":"wb-modal-footer-footer-9e947823"};var styles$2 = modules_6a3864ff;
|
|
22
28
|
|
|
23
|
-
|
|
29
|
+
function ModalFooter({children}){return jsx(View,{style:[styles$2.root,styles$2.footer],children:children})}ModalFooter.__IS_MODAL_FOOTER__=true;ModalFooter.isComponentOf=instance=>{return instance&&instance.type&&instance.type.__IS_MODAL_FOOTER__};
|
|
24
30
|
|
|
25
|
-
|
|
31
|
+
var modules_0db31a3e={"root":"wb-modal-header-root-861865df","header":"wb-modal-header-header-861865df","breadcrumbs":"wb-modal-header-breadcrumbs-861865df","title":"wb-modal-header-title-861865df","subtitle":"wb-modal-header-subtitle-861865df"};var styles$1 = modules_0db31a3e;
|
|
26
32
|
|
|
27
|
-
function ModalHeader(props){const{breadcrumbs=undefined,subtitle=undefined,testId,title,titleId}=props;if(subtitle&&breadcrumbs){throw new Error("'subtitle' and 'breadcrumbs' can't be used together")}return jsxs(View,{style:[styles$
|
|
33
|
+
function ModalHeader(props){const{breadcrumbs=undefined,subtitle=undefined,testId,title,titleId}=props;if(subtitle&&breadcrumbs){throw new Error("'subtitle' and 'breadcrumbs' can't be used together")}return jsxs(View,{style:[styles$1.root,styles$1.header],testId:testId,children:[breadcrumbs&&jsx(View,{style:styles$1.breadcrumbs,children:breadcrumbs}),jsx(Heading,{size:"large",tag:"h2",style:styles$1.title,id:titleId,testId:testId&&`${testId}-title`,children:title}),subtitle&&jsx(BodyText,{size:"small",style:styles$1.subtitle,testId:testId&&`${testId}-subtitle`,children:subtitle})]})}
|
|
28
34
|
|
|
29
|
-
const FOCUSABLE_ELEMENTS$1='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';const FocusTrap=({children,style})=>{const modalRootRef=React.useRef(null);const tryToFocus=React.useCallback(node=>{if(node instanceof HTMLElement){try{node.focus();}catch(e){}return document.activeElement===node}},[]);const focusElementIn=React.useCallback(isLast=>{if(!modalRootRef.current){return}const modalRootAsHtmlEl=modalRootRef.current;const focusableNodes=Array.from(modalRootAsHtmlEl.querySelectorAll(FOCUSABLE_ELEMENTS$1)).filter(element=>{const style=window.getComputedStyle(element);return style.display!=="none"&&style.visibility!=="hidden"});const nodeIndex=!isLast?focusableNodes.length-1:0;const focusableNode=focusableNodes[nodeIndex];tryToFocus(focusableNode);},[tryToFocus]);const handleFocusMoveToLast=React.useCallback(()=>{focusElementIn(false);},[focusElementIn]);const handleFocusMoveToFirst=React.useCallback(()=>{focusElementIn(true);},[focusElementIn]);const getModalRoot=React.useCallback(node=>{if(!node){return}const modalRoot=ReactDOM.findDOMNode(node);if(!modalRoot){throw new Error("Assertion error: modal root should exist after mount")}modalRootRef.current=modalRoot;},[]);return jsxs(React.Fragment,{children:[jsx("div",{tabIndex:0,className:"modal-focus-trap-first",onFocus:handleFocusMoveToLast,style:{position:"fixed"}}),jsx(View,{style:style,ref:getModalRoot,children:children}),jsx("div",{tabIndex:0,className:"modal-focus-trap-last",onFocus:handleFocusMoveToFirst,style:{position:"fixed"}})]})};
|
|
35
|
+
const FOCUSABLE_ELEMENTS$1='button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])';const FocusTrap=({children,style})=>{const modalRootRef=React.useRef(null);const tryToFocus=React.useCallback(node=>{if(node instanceof HTMLElement){try{node.focus();}catch(e){}return document.activeElement===node}},[]);const focusElementIn=React.useCallback(isLast=>{if(!modalRootRef.current){return}const modalRootAsHtmlEl=modalRootRef.current;const focusableNodes=Array.from(modalRootAsHtmlEl.querySelectorAll(FOCUSABLE_ELEMENTS$1)).filter(element=>{const style=window.getComputedStyle(element);return style.display!=="none"&&style.visibility!=="hidden"});const nodeIndex=!isLast?focusableNodes.length-1:0;const focusableNode=focusableNodes[nodeIndex];tryToFocus(focusableNode);},[tryToFocus]);const handleFocusMoveToLast=React.useCallback(()=>{focusElementIn(false);},[focusElementIn]);const handleFocusMoveToFirst=React.useCallback(()=>{focusElementIn(true);},[focusElementIn]);const getModalRoot=React.useCallback(node=>{if(!node){return}const modalRoot=ReactDOM.findDOMNode(node);if(!modalRoot){throw new Error("Assertion error: modal root should exist after mount")}modalRootRef.current=modalRoot;},[]);return jsxs(React.Fragment,{children:[jsx("div",{tabIndex:0,className:"modal-focus-trap-first",onFocus:handleFocusMoveToLast,style:{position:"fixed"}}),jsx(View,{style:style,ref:getModalRoot,children:children}),jsx("div",{tabIndex:0,className:"modal-focus-trap-last",onFocus:handleFocusMoveToFirst,style:{position:"fixed"}})]})};var FocusTrap$1 = FocusTrap;
|
|
30
36
|
|
|
31
37
|
const FOCUSABLE_ELEMENTS="a[href], details, input, textarea, select, button";function findFocusableNodes(root){return Array.from(root.querySelectorAll(FOCUSABLE_ELEMENTS))}
|
|
32
38
|
|
|
33
|
-
|
|
39
|
+
var modules_02ebbaa2={"root":"wb-modal-backdrop-root-26b9a9a8","modalPositioner":"wb-modal-backdrop-modalPositioner-26b9a9a8"};
|
|
40
|
+
|
|
41
|
+
const getInitialFocusElement=(node,initialFocusId)=>{if(!initialFocusId){return null}return ReactDOM.findDOMNode(node.querySelector(`#${initialFocusId}`))};const getFirstFocusableElement=node=>{const focusableElements=findFocusableNodes(node);if(!focusableElements){return null}return focusableElements[0]};const getDialogElement=node=>{const dialogElement=ReactDOM.findDOMNode(node.querySelector('[role="dialog"]'));dialogElement?.setAttribute("tabindex","-1");return dialogElement};const ModalBackdrop=({children,initialFocusId,onCloseModal,testId,style})=>{const backdropRef=React.useRef(null);const[mousePressedOutside,setMousePressedOutside]=React.useState(false);React.useEffect(()=>{const node=ReactDOM.findDOMNode(backdropRef.current);if(!node){return}const firstFocusableElement=getInitialFocusElement(node,initialFocusId)||getFirstFocusableElement(node)||getDialogElement(node);setTimeout(()=>{firstFocusableElement?.focus();},0);},[initialFocusId]);const handleMouseDown=React.useCallback(e=>{const target=e.target;const isBackdropClick=e.target===e.currentTarget;const isPaddingLayerClick=target?.hasAttribute?.("data-modal-padding-layer");setMousePressedOutside(isBackdropClick||isPaddingLayerClick);},[]);const handleMouseUp=React.useCallback(e=>{const target=e.target;const isBackdropClick=e.target===e.currentTarget;const isPaddingLayerClick=target?.hasAttribute?.("data-modal-padding-layer");if((isBackdropClick||isPaddingLayerClick)&&mousePressedOutside){onCloseModal();}setMousePressedOutside(false);},[mousePressedOutside,onCloseModal]);const backdropProps={[ModalLauncherPortalAttributeName]:true};return jsx(View,{ref:backdropRef,style:[modules_02ebbaa2.root,modules_02ebbaa2.modalPositioner,style],onMouseDown:handleMouseDown,onMouseUp:handleMouseUp,testId:testId,...backdropProps,children:children})};var ModalBackdrop$1 = ModalBackdrop;
|
|
42
|
+
|
|
43
|
+
const needsHackyMobileSafariScrollDisabler=(()=>{if(typeof window==="undefined"){return false}const userAgent=window.navigator.userAgent;return userAgent.indexOf("iPad")>-1||userAgent.indexOf("iPhone")>-1})();let numModalsOpened=0;let oldOverflow;let oldPosition;let oldScrollY;let oldWidth;let oldTop;const ScrollDisabler=_props=>{React.useEffect(()=>{if(numModalsOpened===0){const body=document.body;if(!body){throw new Error("couldn't find document.body")}oldOverflow=body.style.overflow;oldScrollY=window.scrollY;if(needsHackyMobileSafariScrollDisabler){oldPosition=body.style.position;oldWidth=body.style.width;oldTop=body.style.top;}body.style.overflow="hidden";if(needsHackyMobileSafariScrollDisabler){body.style.position="fixed";body.style.width="100%";body.style.top=`${-oldScrollY}px`;}}numModalsOpened++;return ()=>{numModalsOpened--;if(numModalsOpened===0){const body=document.body;if(!body){throw new Error("couldn't find document.body")}body.style.overflow=oldOverflow;if(needsHackyMobileSafariScrollDisabler){body.style.position=oldPosition;body.style.width=oldWidth;body.style.top=oldTop;}if(typeof window!=="undefined"&&window.scrollTo){window.scrollTo(0,oldScrollY);}}}},[]);return null};var ScrollDisabler$1 = ScrollDisabler;
|
|
44
|
+
|
|
45
|
+
const defaultContext={closeModal:undefined};const ModalContext=React.createContext(defaultContext);ModalContext.displayName="ModalContext";var ModalContext$1 = ModalContext;
|
|
34
46
|
|
|
35
|
-
|
|
47
|
+
var modules_5a43fb8b={"root":"wb-modal-launcher-root-8b1f173e","container":"wb-modal-launcher-container-8b1f173e"};
|
|
36
48
|
|
|
37
|
-
const
|
|
49
|
+
const ModalLauncher=props=>{const{backdropDismissEnabled=true,children,closedFocusId,initialFocusId,modal,onClose,opened:controlledOpened,schedule,styles:stylesProp,testId}=props;const lastElementFocusedOutsideModalRef=React.useRef(null);const[opened,setOpened]=React.useState(false);const isOpened=typeof controlledOpened==="boolean"?controlledOpened:opened;React.useEffect(()=>{if(typeof controlledOpened==="boolean"&&children){console.warn("'children' and 'opened' can't be used together");}if(typeof controlledOpened==="boolean"&&!onClose){console.warn("'onClose' should be used with 'opened'");}if(typeof controlledOpened!=="boolean"&&!children){console.warn("either 'children' or 'opened' must be set");}},[controlledOpened,children,onClose]);const saveLastElementFocused=React.useCallback(()=>{lastElementFocusedOutsideModalRef.current=document.activeElement;},[]);React.useEffect(()=>{if(!opened&&controlledOpened){saveLastElementFocused();}},[controlledOpened,opened,saveLastElementFocused]);const openModal=React.useCallback(()=>{saveLastElementFocused();setOpened(true);},[saveLastElementFocused]);const returnFocus=React.useCallback(()=>{if(closedFocusId){const focusElement=ReactDOM.findDOMNode(document.getElementById(closedFocusId));if(focusElement){schedule.animationFrame(()=>focusElement.focus(),{schedulePolicy:SchedulePolicy.Immediately,clearPolicy:ClearPolicy.Resolve});return}}const lastElement=lastElementFocusedOutsideModalRef.current;if(lastElement!=null){schedule.animationFrame(()=>{lastElement.focus();});}},[closedFocusId,schedule]);const handleCloseModal=React.useCallback(()=>{setOpened(false);onClose?.();returnFocus();},[onClose,returnFocus]);const renderModal=React.useCallback(()=>{if(typeof modal==="function"){return modal({closeModal:handleCloseModal})}else {return modal}},[modal,handleCloseModal]);const renderedChildren=children?children({openModal}):null;const{body}=document;if(!body){return null}return jsxs(ModalContext$1.Provider,{value:{closeModal:handleCloseModal},children:[renderedChildren,isOpened&&ReactDOM.createPortal(jsx(FocusTrap$1,{style:[modules_5a43fb8b.root,modules_5a43fb8b.container],children:jsx(ModalBackdrop$1,{initialFocusId:initialFocusId,testId:testId,style:stylesProp?.backdrop,onCloseModal:backdropDismissEnabled?handleCloseModal:()=>{},children:renderModal()})}),body),isOpened&&jsx(ModalLauncherKeypressListener,{onClose:handleCloseModal}),isOpened&&jsx(ScrollDisabler$1,{})]})};const ModalLauncherKeypressListener=({onClose})=>{const handleKeyup=React.useCallback(e=>{if(e.key==="Escape"){e.preventDefault();e.stopPropagation();onClose();}},[onClose]);React.useEffect(()=>{window.addEventListener("keyup",handleKeyup);return ()=>{window.removeEventListener("keyup",handleKeyup);}},[handleKeyup]);return null};var modalLauncher = withActionScheduler(ModalLauncher);
|
|
38
50
|
|
|
39
|
-
|
|
51
|
+
var modules_8ad27c48={"root":"wb-modal-content-root-71497938","wrapper":"wb-modal-content-wrapper-71497938","scrollOverflow":"wb-modal-content-scrollOverflow-71497938","content":"wb-modal-content-content-71497938","wrapperSmallHeight":"wb-modal-content-wrapperSmallHeight-71497938"};
|
|
40
52
|
|
|
41
|
-
function ModalContent(props){const{scrollOverflow,style,children,applySmallHeightStyles=true}=props;return jsx(View,{style:[
|
|
53
|
+
function ModalContent(props){const{scrollOverflow,style,children,applySmallHeightStyles=true}=props;return jsx(View,{style:[modules_8ad27c48.root,modules_8ad27c48.wrapper,scrollOverflow&&modules_8ad27c48.scrollOverflow,applySmallHeightStyles&&modules_8ad27c48.wrapperSmallHeight],children:jsx(View,{style:[modules_8ad27c48.content,contentSmallScreenStyles,applySmallHeightStyles&&contentSmallHeightStyles,style],children:children})})}ModalContent.__IS_MODAL_CONTENT__=true;ModalContent.isComponentOf=instance=>{return instance&&instance.type&&instance.type.__IS_MODAL_CONTENT__};ModalContent.defaultProps={scrollOverflow:true,applySmallHeightStyles:true};
|
|
42
54
|
|
|
43
|
-
const CloseButton=({onClick,style,testId})=>{const{strings}=useWonderBlocksI18n();return jsx(ModalContext.Consumer,{children:({closeModal})=>{if(closeModal&&onClick){throw new Error("You've specified 'onClose' on a modal when using ModalLauncher. Please specify 'onClose' on the ModalLauncher instead")}return jsx(IconButton,{icon:xIcon,"aria-label":strings.iconAltCloseModal,onClick:onClick||closeModal,kind:"tertiary",actionType:"neutral",style:style,testId:testId})}})};
|
|
55
|
+
const CloseButton=({onClick,style,testId})=>{const{strings}=useWonderBlocksI18n();return jsx(ModalContext$1.Consumer,{children:({closeModal})=>{if(closeModal&&onClick){throw new Error("You've specified 'onClose' on a modal when using ModalLauncher. Please specify 'onClose' on the ModalLauncher instead")}return jsx(IconButton,{icon:xIcon,"aria-label":strings.iconAltCloseModal,onClick:onClick||closeModal,kind:"tertiary",actionType:"neutral",style:style,testId:testId})}})};var CloseButton$1 = CloseButton;
|
|
44
56
|
|
|
45
|
-
|
|
57
|
+
var modules_2c25c143={"root":"wb-modal-panel-root-77565dcb","wrapper":"wb-modal-panel-wrapper-77565dcb","hasFooter":"wb-modal-panel-hasFooter-77565dcb","closeButton":"wb-modal-panel-closeButton-77565dcb"};var styles = modules_2c25c143;
|
|
46
58
|
|
|
47
|
-
|
|
59
|
+
function ModalPanel({closeButtonVisible=true,scrollOverflow=true,content,footer,header,onClose,style,testId}){const renderMainContent=React.useCallback(()=>{const mainContent=ModalContent.isComponentOf(content)?content:jsx(ModalContent,{children:content});if(!mainContent){return mainContent}return React.cloneElement(mainContent,{scrollOverflow,style:[!!footer&&styles.hasFooter,mainContent.props.style]})},[content,footer,scrollOverflow]);const mainContent=renderMainContent();return jsxs(View,{style:[styles.root,styles.wrapper,panelSmallScreenStyles,style],testId:testId&&`${testId}-panel`,children:[closeButtonVisible&&jsx(CloseButton$1,{onClick:onClose,style:[styles.closeButton],testId:testId&&`${testId}-close`}),header,mainContent,!footer||ModalFooter.isComponentOf(footer)?footer:jsx(ModalFooter,{children:footer})]})}ModalPanel.defaultProps={closeButtonVisible:true,scrollOverflow:true};
|
|
48
60
|
|
|
49
|
-
|
|
61
|
+
var modules_feb951a9={"onePaneDialog":"wb-one-pane-dialog-onePaneDialog-a4d4f705"};
|
|
50
62
|
|
|
51
|
-
const
|
|
63
|
+
const renderHeader=(props,uniqueId)=>{const{title,breadcrumbs=undefined,subtitle=undefined,testId}=props;if(breadcrumbs){return jsx(ModalHeader,{title:title,breadcrumbs:breadcrumbs,titleId:uniqueId,testId:testId&&`${testId}-header`})}else if(subtitle){return jsx(ModalHeader,{title:title,subtitle:subtitle,titleId:uniqueId,testId:testId&&`${testId}-header`})}else {return jsx(ModalHeader,{title:title,titleId:uniqueId,testId:testId&&`${testId}-header`})}};const OnePaneDialog=props=>{const{onClose,footer,content,above,below,style,closeButtonVisible=true,testId,titleId,role,"aria-describedby":ariaDescribedBy}=props;return jsx(Id,{id:titleId,children:uniqueId=>jsx(ModalDialog$1,{style:[modules_feb951a9.onePaneDialog,onePaneDialogSmallScreenStyles,style],above:above,below:below,testId:testId,"aria-labelledby":uniqueId,"aria-describedby":ariaDescribedBy,role:role,children:jsx(ModalPanel,{onClose:onClose,header:renderHeader(props,uniqueId),content:content,footer:footer,closeButtonVisible:closeButtonVisible,testId:testId})})})};var OnePaneDialog$1 = OnePaneDialog;
|
|
64
|
+
|
|
65
|
+
var modules_0f19b942={"root":"wb-flexible-panel-root-caa0bc2b","wrapper":"wb-flexible-panel-wrapper-caa0bc2b","closeButton":"wb-flexible-panel-closeButton-caa0bc2b"};var componentStyles = modules_0f19b942;
|
|
66
|
+
|
|
67
|
+
function FlexiblePanel({closeButtonVisible=true,content,title,onClose,styles,testId}){const panelRef=React.useRef(null);const renderMainContent=React.useCallback(()=>{const contentNode=typeof content==="function"?content({title}):jsxs(Fragment,{children:[title,content]});const mainContent=ModalContent.isComponentOf(contentNode)?contentNode:jsx(ModalContent,{style:styles?.content,applySmallHeightStyles:false,children:contentNode});if(!mainContent){return mainContent}return React.cloneElement(mainContent,{applySmallHeightStyles:false,style:[mainContent.props.style]})},[title,content,styles?.content]);const mainContent=renderMainContent();const defaultBackgroundStyle={backgroundColor:semanticColor.core.background.base.default};return jsxs(View,{style:[componentStyles.root,componentStyles.wrapper,defaultBackgroundStyle,styles?.panel],testId:testId&&`${testId}-panel`,ref:panelRef,children:[closeButtonVisible&&jsx(CloseButton$1,{onClick:onClose,style:[componentStyles.closeButton,styles?.closeButton],testId:testId&&`${testId}-close`}),mainContent]})}FlexiblePanel.defaultProps={closeButtonVisible:true};
|
|
68
|
+
|
|
69
|
+
var modules_67358578={"root":"wb-flexible-dialog-root-77f9ee79","flexibleRoot":"wb-flexible-dialog-flexibleRoot-77f9ee79"};
|
|
70
|
+
|
|
71
|
+
const FlexibleDialog=React.forwardRef(function FlexibleDialog(props,ref){const{onClose,title,content,styles,closeButtonVisible=true,testId,titleId,role="dialog",...accessibilityProps}=props;const uniqueId=React.useId();const headingId=titleId??uniqueId;const{ariaModalRef}=useModalAnnouncer(ref);const renderedTitle=title==null?null:typeof title==="string"?jsx(Heading,{id:headingId,children:title}):React.cloneElement(title,{id:headingId});return jsx(View,{style:[modules_67358578.root,modules_67358578.flexibleRoot,styles?.root],children:jsx(View,{role:role,"aria-modal":"true","aria-label":accessibilityProps["aria-label"],"aria-labelledby":headingId,"aria-describedby":accessibilityProps["aria-describedby"],ref:ariaModalRef,testId:testId,style:styles?.dialog,children:jsx(FlexiblePanel,{styles:{panel:styles?.panel,content:styles?.content,closeButton:styles?.closeButton},onClose:onClose,title:renderedTitle,content:content,closeButtonVisible:closeButtonVisible,testId:testId})})})});var FlexibleDialog$1 = FlexibleDialog;
|
|
52
72
|
|
|
53
73
|
const DRAWER_ENTER_DURATION_MS=300;const DRAWER_EXIT_DURATION_MS=150;const DRAWER_ENTER_EASING="cubic-bezier(0.05, 0.7, 0.1, 1)";const DRAWER_EXIT_EASING="cubic-bezier(0.3, 0, 0.8, 0.15)";const DRAWER_SLIDE_OFFSET="42%";
|
|
54
74
|
|
|
55
|
-
const DEFAULT_DRAWER_ANIMATED=true;const DEFAULT_DRAWER_BACKDROP_DISMISS_ENABLED=true;const DEFAULT_DRAWER_IS_EXITING=false;const defaultDrawerContextValue={animated:DEFAULT_DRAWER_ANIMATED,isExiting:DEFAULT_DRAWER_IS_EXITING};const DrawerContext=React.createContext(defaultDrawerContextValue);const useDrawerContext=()=>{return React.useContext(DrawerContext)};
|
|
75
|
+
const DEFAULT_DRAWER_TIMING_DURATION_MS=DRAWER_ENTER_DURATION_MS;const DEFAULT_DRAWER_ANIMATED=true;const DEFAULT_DRAWER_BACKDROP_DISMISS_ENABLED=true;const DEFAULT_DRAWER_IS_EXITING=false;const defaultDrawerContextValue={animated:DEFAULT_DRAWER_ANIMATED,isExiting:DEFAULT_DRAWER_IS_EXITING};const DrawerContext=React.createContext(defaultDrawerContextValue);const useDrawerContext=()=>{return React.useContext(DrawerContext)};
|
|
56
76
|
|
|
57
|
-
|
|
77
|
+
var modules_86e0fdaa={"root":"wb-drawer-backdrop-root-be242eab","backdrop-fade-in":"wb-drawer-backdrop-backdrop-fade-in-be242eab","backdrop-fade-out":"wb-drawer-backdrop-backdrop-fade-out-be242eab","drawerPositioner":"wb-drawer-backdrop-drawerPositioner-be242eab","inlineStart":"wb-drawer-backdrop-inlineStart-be242eab","inlineEnd":"wb-drawer-backdrop-inlineEnd-be242eab","blockEnd":"wb-drawer-backdrop-blockEnd-be242eab","fadeIn":"wb-drawer-backdrop-fadeIn-be242eab","fadeOut":"wb-drawer-backdrop-fadeOut-be242eab"};
|
|
58
78
|
|
|
59
|
-
const
|
|
79
|
+
const DrawerBackdrop=({children,testId,initialFocusId,onCloseModal,style})=>{const{alignment,animated,timingDuration,isExiting}=useDrawerContext();const[mousePressedOutside,setMousePressedOutside]=React.useState(false);const backdropRef=React.useRef(null);const computedTimingDuration=animated?timingDuration??DRAWER_ENTER_DURATION_MS:0;const fadeStyle=isExiting?modules_86e0fdaa.fadeOut:modules_86e0fdaa.fadeIn;const fadeDurationOverride=timingDuration!=null?{animationDuration:`${timingDuration}ms`}:undefined;const getInitialFocusElement=React.useCallback(container=>{if(!initialFocusId){return null}return container.querySelector(`#${initialFocusId}`)},[initialFocusId]);const getFirstFocusableElement=React.useCallback(container=>{const focusableElements=findFocusableNodes(container);if(!focusableElements){return null}return focusableElements[0]},[]);const getDialogElement=React.useCallback(container=>{const dialogElement=container.querySelector('[role="dialog"]');if(dialogElement){dialogElement.tabIndex=-1;}return dialogElement},[]);React.useEffect(()=>{const container=backdropRef.current;if(!container){return}const firstFocusableElement=getInitialFocusElement(container)||getFirstFocusableElement(container)||getDialogElement(container);if(firstFocusableElement){setTimeout(()=>{firstFocusableElement.focus();},computedTimingDuration);}},[getInitialFocusElement,getFirstFocusableElement,getDialogElement,computedTimingDuration]);const handleMouseDown=e=>{if(e.target===e.currentTarget){setMousePressedOutside(true);}};const handleMouseUp=e=>{if(e.target===e.currentTarget&&mousePressedOutside){onCloseModal();}setMousePressedOutside(false);};const backdropProps={[ModalLauncherPortalAttributeName]:true};return jsx(View,{ref:backdropRef,style:[modules_86e0fdaa.root,modules_86e0fdaa.drawerPositioner,alignment&&modules_86e0fdaa[alignment],animated&&fadeStyle,animated&&fadeDurationOverride,style].filter(Boolean),onMouseDown:handleMouseDown,onMouseUp:handleMouseUp,testId:testId,...backdropProps,children:children})};var DrawerBackdrop$1 = DrawerBackdrop;
|
|
60
80
|
|
|
61
|
-
const
|
|
81
|
+
DEFAULT_DRAWER_TIMING_DURATION_MS;const defaultProps={backdropDismissEnabled:DEFAULT_DRAWER_BACKDROP_DISMISS_ENABLED};const DrawerLauncher=props=>{const{modal,backdropDismissEnabled=defaultProps.backdropDismissEnabled,initialFocusId,closedFocusId,testId,opened:controlledOpened,onClose,children,schedule,alignment,styles,animated=DEFAULT_DRAWER_ANIMATED,timingDuration,easing}=props;const easingEnter=easing?.enter;const easingExit=easing?.exit;const[uncontrolledOpened,setUncontrolledOpened]=React.useState(false);const[isExiting,setIsExiting]=React.useState(false);const lastElementFocusedOutsideModalRef=React.useRef(null);const opened=typeof controlledOpened==="boolean"?controlledOpened:uncontrolledOpened;const saveLastElementFocused=React.useCallback(()=>{lastElementFocusedOutsideModalRef.current=document.activeElement;},[]);React.useEffect(()=>{if(controlledOpened&&!prevControlledOpened.current){saveLastElementFocused();}prevControlledOpened.current=controlledOpened;},[controlledOpened,saveLastElementFocused]);const prevControlledOpened=React.useRef(controlledOpened);const returnFocus=React.useCallback(()=>{const focusElement=closedFocusId?document.getElementById(closedFocusId):null;schedule.animationFrame(()=>{if(focusElement){focusElement.focus();}else if(lastElementFocusedOutsideModalRef.current){lastElementFocusedOutsideModalRef.current.focus();}});},[closedFocusId,schedule]);const handleCloseModal=React.useCallback(()=>{if(animated){setIsExiting(true);setTimeout(()=>{setIsExiting(false);if(typeof controlledOpened==="boolean"){onClose?.();}else {setUncontrolledOpened(false);onClose?.();}returnFocus();},timingDuration??DRAWER_EXIT_DURATION_MS);}else {if(typeof controlledOpened==="boolean"){onClose?.();}else {setUncontrolledOpened(false);onClose?.();}returnFocus();}},[controlledOpened,onClose,returnFocus,animated,timingDuration]);const openModal=React.useCallback(()=>{saveLastElementFocused();setUncontrolledOpened(true);},[saveLastElementFocused]);const drawerDialogProps=React.useMemo(()=>({alignment,animated,isExiting,timingDuration,easing:{enter:easingEnter,exit:easingExit}}),[alignment,animated,isExiting,timingDuration,easingEnter,easingExit]);const renderModal=React.useCallback(()=>{if(typeof modal==="function"){const renderedModal=modal({closeModal:handleCloseModal});if(!renderedModal){return null}return renderedModal}if(!modal){return null}return modal},[modal,handleCloseModal]);const renderedChildren=children?children({openModal}):null;const body=document.body;if(!body){return null}return jsxs(ModalContext$1.Provider,{value:{closeModal:handleCloseModal},children:[renderedChildren,opened&&!isExiting||opened&&isExiting&&animated?ReactDOM.createPortal(jsx(DrawerContext.Provider,{value:drawerDialogProps,children:jsx(FocusTrap$1,{style:styles?.container,children:jsx(DrawerBackdrop$1,{initialFocusId:initialFocusId,testId:testId,style:styles?.backdrop,onCloseModal:backdropDismissEnabled?handleCloseModal:()=>{},children:renderModal()})})}),body):null,opened&&!isExiting&&jsxs(Fragment,{children:[jsx(DrawerLauncherKeypressListener,{onClose:handleCloseModal}),jsx(ScrollDisabler$1,{})]})]})};function DrawerLauncherKeypressListener({onClose}){React.useEffect(()=>{const handleKeyup=e=>{if(e.key==="Escape"){e.preventDefault();e.stopPropagation();onClose();}};window.addEventListener("keyup",handleKeyup);return ()=>window.removeEventListener("keyup",handleKeyup)},[onClose]);return null}DrawerLauncher.displayName="DrawerLauncher";var drawerLauncher = withActionScheduler(DrawerLauncher);
|
|
82
|
+
|
|
83
|
+
var modules_8866c729={"root":"wb-drawer-dialog-root-e8a53d57","drawerRoot":"wb-drawer-dialog-drawerRoot-e8a53d57","blockEnd":"wb-drawer-dialog-blockEnd-e8a53d57","dialogDefault":"wb-drawer-dialog-dialogDefault-e8a53d57","dialogBlockEnd":"wb-drawer-dialog-dialogBlockEnd-e8a53d57"};
|
|
84
|
+
|
|
85
|
+
const DrawerDialog=React.forwardRef(function DrawerDialog(props,ref){const contextProps=useDrawerContext();const alignment=contextProps.alignment??"inlineEnd";const animated=contextProps.animated??DEFAULT_DRAWER_ANIMATED;const isExiting=contextProps.isExiting??DEFAULT_DRAWER_IS_EXITING;const timingDuration=contextProps.timingDuration;const easing=contextProps.easing;const{styles}=props;const direction=useDirectionDetection();const isRtl=direction==="rtl";const phase=isExiting?"exit":"enter";const defaultAnimationStyle=DEFAULT_ANIMATION_STYLES[alignment][isRtl?"rtl":"ltr"][phase];const phaseEasing=easing?.[phase];const animationStyle=!animated?undefined:timingDuration===undefined&&phaseEasing===undefined?defaultAnimationStyle:{...defaultAnimationStyle,...timingDuration!==undefined&&{animationDuration:`${timingDuration}ms`},...phaseEasing!==undefined&&{animationTimingFunction:phaseEasing}};return jsx(FlexibleDialog$1,{...props,ref:ref,styles:{root:[modules_8866c729.root,modules_8866c729.drawerRoot,alignmentStyles[alignment],animationStyle,alignment==="blockEnd"?drawerBlockEndSmallScreenStyles:drawerSmallScreenStyles,styles?.root].filter(Boolean),dialog:[alignment==="blockEnd"?modules_8866c729.dialogBlockEnd:modules_8866c729.dialogDefault,styles?.dialog].filter(Boolean),panel:styles?.panel,content:styles?.content,closeButton:styles?.closeButton}})});const alignmentStyles={inlineStart:undefined,inlineEnd:undefined,blockEnd:modules_8866c729.blockEnd};const REST_TRANSFORM="translate3d(0, 0, 0)";const getTransformValue=(isRtl,alignment,offset)=>{if(alignment==="blockEnd"){return `translate3d(0, ${offset}, 0)`}const isNegative=isRtl?alignment==="inlineEnd":alignment==="inlineStart";const signedOffset=isNegative?`calc(-1 * ${offset})`:offset;return `translate3d(${signedOffset}, 0, 0)`};const createKeyframes=(isRtl,alignment)=>({slideIn:{"0%":{transform:getTransformValue(isRtl,alignment,DRAWER_SLIDE_OFFSET),opacity:0},"100%":{transform:REST_TRANSFORM,opacity:1}},slideOut:{"0%":{transform:REST_TRANSFORM,opacity:1},"100%":{transform:getTransformValue(isRtl,alignment,DRAWER_SLIDE_OFFSET),opacity:0}}});const buildDefaultStyle=(isExiting,alignmentKeyframes)=>({animationName:isExiting?alignmentKeyframes.slideOut:alignmentKeyframes.slideIn,animationDuration:`${isExiting?DRAWER_EXIT_DURATION_MS:DRAWER_ENTER_DURATION_MS}ms`,animationTimingFunction:isExiting?DRAWER_EXIT_EASING:DRAWER_ENTER_EASING,animationFillMode:isExiting?"forwards":"backwards"});const buildDirectionStyles=alignment=>{const ltrKeyframes=createKeyframes(false,alignment);const rtlKeyframes=alignment==="blockEnd"?ltrKeyframes:createKeyframes(true,alignment);return {ltr:{enter:buildDefaultStyle(false,ltrKeyframes),exit:buildDefaultStyle(true,ltrKeyframes)},rtl:{enter:buildDefaultStyle(false,rtlKeyframes),exit:buildDefaultStyle(true,rtlKeyframes)}}};const DEFAULT_ANIMATION_STYLES={inlineStart:buildDirectionStyles("inlineStart"),inlineEnd:buildDirectionStyles("inlineEnd"),blockEnd:buildDirectionStyles("blockEnd")};DrawerDialog.displayName="DrawerDialog";var DrawerDialog$1 = DrawerDialog;
|
|
62
86
|
|
|
63
87
|
function maybeGetNextAncestorModalLauncherPortal(element){let candidateElement=element&&element.parentElement;while(candidateElement&&!candidateElement.hasAttribute(ModalLauncherPortalAttributeName)){candidateElement=candidateElement.parentElement;}return candidateElement}function maybeGetPortalMountedModalHostElement(element){return maybeGetNextAncestorModalLauncherPortal(element)}
|
|
64
88
|
|
|
65
|
-
export { DrawerDialog, drawerLauncher as DrawerLauncher, FlexibleDialog, ModalDialog, ModalFooter, ModalHeader, modalLauncher as ModalLauncher, ModalPanel, OnePaneDialog, maybeGetPortalMountedModalHostElement };
|
|
89
|
+
export { DrawerDialog$1 as DrawerDialog, drawerLauncher as DrawerLauncher, FlexibleDialog$1 as FlexibleDialog, ModalDialog$1 as ModalDialog, ModalFooter, ModalHeader, modalLauncher as ModalLauncher, ModalPanel, OnePaneDialog$1 as OnePaneDialog, maybeGetPortalMountedModalHostElement };
|
|
90
|
+
|
|
91
|
+
import "./index.css";
|