@vibe/core 3.53.1-alpha-685df.0 → 3.53.1
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/dist/components/Toast/Toast.d.ts +2 -2
- package/dist/icons/dist/react/DropdownChevronDown.js +1 -1
- package/dist/icons/dist/react/DropdownChevronDown.js.map +1 -1
- package/dist/icons/dist/react/DropdownChevronUp.js +1 -1
- package/dist/icons/dist/react/DropdownChevronUp.js.map +1 -1
- package/dist/metadata.json +30 -16
- package/dist/mocked_classnames/components/Toast/Toast.d.ts +2 -2
- package/dist/mocked_classnames/icons/dist/react/DropdownChevronDown.js +1 -1
- package/dist/mocked_classnames/icons/dist/react/DropdownChevronDown.js.map +1 -1
- package/dist/mocked_classnames/icons/dist/react/DropdownChevronUp.js +1 -1
- package/dist/mocked_classnames/icons/dist/react/DropdownChevronUp.js.map +1 -1
- package/dist/mocked_classnames/src/components/AlertBanner/AlertBannerButton/AlertBannerButton.js +1 -1
- package/dist/mocked_classnames/src/components/AlertBanner/AlertBannerButton/AlertBannerButton.js.map +1 -1
- package/dist/mocked_classnames/src/components/Button/Button.js +1 -1
- package/dist/mocked_classnames/src/components/Button/Button.js.map +1 -1
- package/dist/mocked_classnames/src/components/Counter/Counter.js +1 -1
- package/dist/mocked_classnames/src/components/Counter/Counter.js.map +1 -1
- package/dist/mocked_classnames/src/components/Dialog/DialogContent/DialogContent.js +1 -1
- package/dist/mocked_classnames/src/components/Dialog/DialogContent/DialogContent.js.map +1 -1
- package/dist/mocked_classnames/src/components/SplitButton/SplitButton.js +1 -1
- package/dist/mocked_classnames/src/components/SplitButton/SplitButton.js.map +1 -1
- package/dist/mocked_classnames/src/components/Toast/Toast.js +1 -1
- package/dist/mocked_classnames/src/components/Toast/Toast.js.map +1 -1
- package/dist/mocked_classnames/src/components/Toast/ToastButton/ToastButton.js +1 -1
- package/dist/mocked_classnames/src/components/Toast/ToastButton/ToastButton.js.map +1 -1
- package/dist/src/components/AlertBanner/AlertBannerButton/AlertBannerButton.js +1 -1
- package/dist/src/components/AlertBanner/AlertBannerButton/AlertBannerButton.js.map +1 -1
- package/dist/src/components/Button/Button.js +1 -1
- package/dist/src/components/Button/Button.js.map +1 -1
- package/dist/src/components/Counter/Counter.js +1 -1
- package/dist/src/components/Counter/Counter.js.map +1 -1
- package/dist/src/components/Dialog/DialogContent/DialogContent.js +1 -1
- package/dist/src/components/Dialog/DialogContent/DialogContent.js.map +1 -1
- package/dist/src/components/SplitButton/SplitButton.js +1 -1
- package/dist/src/components/SplitButton/SplitButton.js.map +1 -1
- package/dist/src/components/Toast/Toast.js +1 -1
- package/dist/src/components/Toast/Toast.js.map +1 -1
- package/dist/src/components/Toast/ToastButton/ToastButton.js +1 -1
- package/dist/src/components/Toast/ToastButton/ToastButton.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DialogContent.js","sources":["../../../../../src/components/Dialog/DialogContent/DialogContent.tsx"],"sourcesContent":["import React, { cloneElement, CSSProperties, forwardRef, ReactElement, useCallback, useEffect, useRef } from \"react\";\nimport cx from \"classnames\";\nimport { camelCase } from \"lodash-es\";\nimport { CSSTransition } from \"react-transition-group\";\nimport { CSSTransitionProps } from \"react-transition-group/CSSTransition\";\nimport useClickOutside from \"../../../hooks/useClickOutside\";\nimport { chainFunctions, NOOP } from \"../../../utils/function-utils\";\nimport useKeyEvent from \"../../../hooks/useKeyEvent\";\nimport { VibeComponentProps } from \"../../../types\";\nimport { keyCodes } from \"../../../constants\";\nimport { DialogAnimationType, DialogTriggerEvent } from \"../Dialog.types\";\nimport * as PopperJS from \"@popperjs/core\";\nimport { getStyle } from \"../../../helpers/typesciptCssModulesHelper\";\nimport styles from \"./DialogContent.module.scss\";\nimport useDisableScroll from \"../../../hooks/useDisableScroll\";\n\nconst EMPTY_OBJECT = {};\nconst ESCAPE_KEYS = [keyCodes.ESCAPE];\n\nexport interface DialogContentProps extends VibeComponentProps {\n /**\n * The content inside the dialog.\n */\n children?: ReactElement | ReactElement[];\n /**\n * The placement of the dialog relative to the reference element.\n */\n position?: PopperJS.Placement;\n /**\n * Class name applied to the dialog wrapper.\n */\n wrapperClassName?: string;\n /**\n * If true, the dialog is open.\n */\n isOpen?: boolean;\n // TODO: [breaking] use type\n /**\n * The starting edge of the dialog.\n */\n startingEdge?: any;\n /**\n * The animation type used for showing/hiding the dialog.\n */\n animationType?: DialogAnimationType;\n /**\n * Callback fired when the Escape key is pressed.\n */\n onEsc?: (event: React.KeyboardEvent) => void;\n /**\n * Callback fired when the mouse enters the dialog.\n */\n onMouseEnter?: (event: React.MouseEvent) => void;\n /**\n * Callback fired when the mouse leaves the dialog.\n */\n onMouseLeave?: (event: React.MouseEvent) => void;\n /**\n * Callback fired when clicking outside the dialog.\n */\n onClickOutside?: (event: React.MouseEvent, hideShowEvent: DialogTriggerEvent) => void;\n /**\n * Callback fired when clicking inside the dialog.\n */\n onClick?: (event: React.MouseEvent) => void;\n /**\n * Delay before showing the dialog.\n */\n showDelay?: number;\n /**\n * Inline styles applied to the dialog.\n */\n styleObject?: CSSProperties;\n /**\n * If true, hides the reference element when the dialog is shown.\n */\n isReferenceHidden?: boolean;\n /**\n * If true, applies tooltip arrow to the dialog.\n */\n hasTooltip?: boolean;\n /**\n * The CSS selector of the container where the dialog should be rendered.\n */\n containerSelector?: string;\n /**\n * If true, disables scrolling in the container when the dialog is open.\n */\n disableContainerScroll?: boolean | string;\n /**\n * Callback fired when the context menu (right-click) event occurs outside the dialog.\n */\n onContextMenu?: (e: React.MouseEvent) => void;\n}\n\nconst DialogContent = forwardRef(\n (\n {\n onEsc = NOOP,\n children,\n position,\n wrapperClassName,\n isOpen = false,\n startingEdge,\n animationType = \"expand\",\n onMouseEnter = NOOP,\n onMouseLeave = NOOP,\n onClickOutside = NOOP,\n onClick = NOOP,\n onContextMenu = NOOP,\n showDelay,\n styleObject = EMPTY_OBJECT,\n isReferenceHidden,\n hasTooltip = false,\n containerSelector,\n disableContainerScroll = false,\n \"data-testid\": dataTestId\n }: DialogContentProps,\n forwardRef: React.ForwardedRef<HTMLElement>\n ) => {\n const ref = useRef<HTMLDivElement>(null);\n const onOutSideClick = useCallback(\n (event: React.MouseEvent) => {\n if (isOpen) {\n return onClickOutside(event, \"clickoutside\");\n }\n },\n [isOpen, onClickOutside]\n );\n const overrideOnContextMenu = useCallback(\n (event: React.MouseEvent) => {\n if (isOpen) {\n onContextMenu(event);\n }\n },\n [isOpen, onContextMenu]\n );\n useKeyEvent({ keys: ESCAPE_KEYS, callback: onEsc });\n useClickOutside({ callback: onOutSideClick, ref });\n useClickOutside({ eventName: \"contextmenu\", callback: overrideOnContextMenu, ref });\n const selectorToDisable = typeof disableContainerScroll === \"string\" ? disableContainerScroll : containerSelector;\n const { disableScroll, enableScroll } = useDisableScroll(selectorToDisable);\n\n useEffect(() => {\n if (disableContainerScroll) {\n if (isOpen) {\n disableScroll();\n } else {\n enableScroll();\n }\n }\n }, [disableContainerScroll, disableScroll, enableScroll, isOpen]);\n\n const transitionOptions: Partial<CSSTransitionProps> = { classNames: undefined };\n\n switch (animationType) {\n case \"expand\":\n transitionOptions.classNames = {\n appear: styles.expandAppear,\n appearActive: styles.expandAppearActive,\n exit: styles.expandExit\n };\n break;\n case \"opacity-and-slide\":\n transitionOptions.classNames = {\n appear: styles.opacitySlideAppear,\n appearActive: styles.opacitySlideAppearActive\n };\n break;\n }\n return (\n <span\n // don't remove old classname - override from Monolith\n className={cx(\"monday-style-dialog-content-wrapper\", styles.contentWrapper, wrapperClassName)}\n ref={forwardRef}\n data-testid={dataTestId}\n style={styleObject}\n onClickCapture={onClick}\n data-popper-reference-hidden={isReferenceHidden}\n >\n <CSSTransition\n classNames={transitionOptions.classNames}\n nodeRef={ref}\n in={isOpen}\n appear={!!animationType}\n timeout={showDelay}\n >\n <div\n className={cx(styles.contentComponent, getStyle(styles, camelCase(position)), {\n [getStyle(styles, camelCase(\"edge-\" + startingEdge))]: startingEdge,\n [styles.hasTooltip]: hasTooltip\n })}\n ref={ref}\n >\n {React.Children.toArray(children).map((child: ReactElement) => {\n return cloneElement(child, {\n onMouseEnter: chainFunctions([child.props.onMouseEnter, onMouseEnter]),\n onMouseLeave: chainFunctions([child.props.onMouseLeave, onMouseLeave])\n });\n })}\n </div>\n </CSSTransition>\n </span>\n );\n }\n);\n\nexport default DialogContent;\n"],"names":["EMPTY_OBJECT","ESCAPE_KEYS","keyCodes","ESCAPE","DialogContent","forwardRef","_ref","_ref$onEsc","onEsc","NOOP","children","position","wrapperClassName","_ref$isOpen","isOpen","startingEdge","_ref$animationType","animationType","_ref$onMouseEnter","onMouseEnter","_ref$onMouseLeave","onMouseLeave","_ref$onClickOutside","onClickOutside","_ref$onClick","onClick","_ref$onContextMenu","onContextMenu","showDelay","_ref$styleObject","styleObject","isReferenceHidden","_ref$hasTooltip","hasTooltip","containerSelector","_ref$disableContainer","disableContainerScroll","dataTestId","ref","useRef","onOutSideClick","useCallback","event","overrideOnContextMenu","useKeyEvent","keys","callback","useClickOutside","eventName","_useDisableScroll","useDisableScroll","disableScroll","enableScroll","useEffect","transitionOptions","classNames","undefined","appear","styles","expandAppear","appearActive","expandAppearActive","exit","expandExit","opacitySlideAppear","opacitySlideAppearActive","React","createElement","className","cx","contentWrapper","style","onClickCapture","CSSTransition","nodeRef","in","timeout","contentComponent","getStyle","camelCase","_defineProperty","Children","toArray","map","child","cloneElement","chainFunctions","props"],"mappings":"ivBAgBA,IAAMA,EAAe,CAAA,EACfC,EAAc,CAACC,EAASC,QA8ExBC,EAAgBC,GACpB,SAAAC,EAsBED,GACE,IAAAE,EAAAD,EArBAE,MAAAA,OAAQC,IAAHF,EAAGE,EAAIF,EACZG,EAAQJ,EAARI,SACAC,EAAQL,EAARK,SACAC,EAAgBN,EAAhBM,iBAAgBC,EAAAP,EAChBQ,OAAAA,OAAS,IAAHD,GAAQA,EACdE,EAAYT,EAAZS,aAAYC,EAAAV,EACZW,cAAAA,OAAgB,IAAHD,EAA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,EAAOG,mBACrBC,KAAMJ,EAAOK,YAEf,MACF,IAAK,oBACHT,GAAkBC,WAAa,CAC7BE,OAAQC,EAAOM,mBACfJ,aAAcF,EAAOO,0BAI3B,OACEC,EAAAC,cAAA,OAAA,CAEEC,UAAWC,EAAG,sCAAuCX,EAAOY,eAAgB1D,GAC5E0B,IAAKjC,EAAU,cACFgC,EACbkC,MAAOzC,EACP0C,eAAgB/C,EAAO,+BACOM,GAE9BmC,EAACC,cAAAM,EACC,CAAAlB,WAAYD,GAAkBC,WAC9BmB,QAASpC,EACTqC,GAAI7D,EACJ2C,SAAUxC,EACV2D,QAAShD,GAETsC,EAAAC,cAAA,MAAA,CACEC,UAAWC,EAAGX,EAAOmB,iBAAkBC,EAASpB,EAAQqB,EAAUpE,IAAUqE,EAAAA,EACzEF,GAAAA,EAASpB,EAAQqB,EAAU,QAAUhE,IAAiBA,GACtD2C,EAAOzB,WAAaA,IAEvBK,IAAKA,GAEJ4B,EAAMe,SAASC,QAAQxE,GAAUyE,KAAI,SAACC,GACrC,OAAOC,EAAaD,EAAO,CACzBjE,aAAcmE,EAAe,CAACF,EAAMG,MAAMpE,aAAcA,IACxDE,aAAciE,EAAe,CAACF,EAAMG,MAAMlE,aAAcA,WAOtE"}
|
|
1
|
+
{"version":3,"file":"DialogContent.js","sources":["../../../../../src/components/Dialog/DialogContent/DialogContent.tsx"],"sourcesContent":["import React, { cloneElement, CSSProperties, forwardRef, ReactElement, useCallback, useEffect, useRef } from \"react\";\nimport cx from \"classnames\";\nimport { camelCase } from \"lodash-es\";\nimport { CSSTransition } from \"react-transition-group\";\nimport { CSSTransitionProps } from \"react-transition-group/CSSTransition\";\nimport useClickOutside from \"../../../hooks/useClickOutside\";\nimport { chainFunctions, NOOP } from \"../../../utils/function-utils\";\nimport useKeyEvent from \"../../../hooks/useKeyEvent\";\nimport { VibeComponentProps } from \"../../../types\";\nimport { keyCodes } from \"../../../constants\";\nimport { DialogAnimationType, DialogTriggerEvent } from \"../Dialog.types\";\nimport * as PopperJS from \"@popperjs/core\";\nimport { getStyle } from \"../../../helpers/typesciptCssModulesHelper\";\nimport styles from \"./DialogContent.module.scss\";\nimport useDisableScroll from \"../../../hooks/useDisableScroll\";\n\nconst EMPTY_OBJECT = {};\nconst ESCAPE_KEYS = [keyCodes.ESCAPE];\n\nexport interface DialogContentProps extends VibeComponentProps {\n /**\n * The content inside the dialog.\n */\n children?: ReactElement | ReactElement[];\n /**\n * The placement of the dialog relative to the reference element.\n */\n position?: PopperJS.Placement;\n /**\n * Class name applied to the dialog wrapper.\n */\n wrapperClassName?: string;\n /**\n * If true, the dialog is open.\n */\n isOpen?: boolean;\n // TODO: [breaking] use type\n /**\n * The starting edge of the dialog.\n */\n startingEdge?: any;\n /**\n * The animation type used for showing/hiding the dialog.\n */\n animationType?: DialogAnimationType;\n /**\n * Callback fired when the Escape key is pressed.\n */\n onEsc?: (event: React.KeyboardEvent) => void;\n /**\n * Callback fired when the mouse enters the dialog.\n */\n onMouseEnter?: (event: React.MouseEvent) => void;\n /**\n * Callback fired when the mouse leaves the dialog.\n */\n onMouseLeave?: (event: React.MouseEvent) => void;\n /**\n * Callback fired when clicking outside the dialog.\n */\n onClickOutside?: (event: React.MouseEvent, hideShowEvent: DialogTriggerEvent) => void;\n /**\n * Callback fired when clicking inside the dialog.\n */\n onClick?: (event: React.MouseEvent) => void;\n /**\n * Delay before showing the dialog.\n */\n showDelay?: number;\n /**\n * Inline styles applied to the dialog.\n */\n styleObject?: CSSProperties;\n /**\n * If true, hides the reference element when the dialog is shown.\n */\n isReferenceHidden?: boolean;\n /**\n * If true, applies tooltip arrow to the dialog.\n */\n hasTooltip?: boolean;\n /**\n * The CSS selector of the container where the dialog should be rendered.\n */\n containerSelector?: string;\n /**\n * If true, disables scrolling in the container when the dialog is open.\n */\n disableContainerScroll?: boolean | string;\n /**\n * Callback fired when the context menu (right-click) event occurs outside the dialog.\n */\n onContextMenu?: (e: React.MouseEvent) => void;\n}\n\nconst DialogContent = forwardRef(\n (\n {\n onEsc = NOOP,\n children,\n position,\n wrapperClassName,\n isOpen = false,\n startingEdge,\n animationType = \"expand\",\n onMouseEnter = NOOP,\n onMouseLeave = NOOP,\n onClickOutside = NOOP,\n onClick = NOOP,\n onContextMenu = NOOP,\n showDelay,\n styleObject = EMPTY_OBJECT,\n isReferenceHidden,\n hasTooltip = false,\n containerSelector,\n disableContainerScroll = false,\n \"data-testid\": dataTestId\n }: DialogContentProps,\n forwardRef: React.ForwardedRef<HTMLElement>\n ) => {\n const ref = useRef(null);\n const onOutSideClick = useCallback(\n (event: React.MouseEvent) => {\n if (isOpen) {\n return onClickOutside(event, \"clickoutside\");\n }\n },\n [isOpen, onClickOutside]\n );\n const overrideOnContextMenu = useCallback(\n (event: React.MouseEvent) => {\n if (isOpen) {\n onContextMenu(event);\n }\n },\n [isOpen, onContextMenu]\n );\n useKeyEvent({ keys: ESCAPE_KEYS, callback: onEsc });\n useClickOutside({ callback: onOutSideClick, ref });\n useClickOutside({ eventName: \"contextmenu\", callback: overrideOnContextMenu, ref });\n const selectorToDisable = typeof disableContainerScroll === \"string\" ? disableContainerScroll : containerSelector;\n const { disableScroll, enableScroll } = useDisableScroll(selectorToDisable);\n\n useEffect(() => {\n if (disableContainerScroll) {\n if (isOpen) {\n disableScroll();\n } else {\n enableScroll();\n }\n }\n }, [disableContainerScroll, disableScroll, enableScroll, isOpen]);\n\n const transitionOptions: Partial<CSSTransitionProps> = { classNames: undefined };\n\n switch (animationType) {\n case \"expand\":\n transitionOptions.classNames = {\n appear: styles.expandAppear,\n appearActive: styles.expandAppearActive,\n exit: styles.expandExit\n };\n break;\n case \"opacity-and-slide\":\n transitionOptions.classNames = {\n appear: styles.opacitySlideAppear,\n appearActive: styles.opacitySlideAppearActive\n };\n break;\n }\n return (\n <span\n // don't remove old classname - override from Monolith\n className={cx(\"monday-style-dialog-content-wrapper\", styles.contentWrapper, wrapperClassName)}\n ref={forwardRef}\n data-testid={dataTestId}\n style={styleObject}\n onClickCapture={onClick}\n data-popper-reference-hidden={isReferenceHidden}\n >\n <CSSTransition {...transitionOptions} in={isOpen} appear={!!animationType} timeout={showDelay}>\n <div\n className={cx(styles.contentComponent, getStyle(styles, camelCase(position)), {\n [getStyle(styles, camelCase(\"edge-\" + startingEdge))]: startingEdge,\n [styles.hasTooltip]: hasTooltip\n })}\n ref={ref}\n >\n {React.Children.toArray(children).map((child: ReactElement) => {\n return cloneElement(child, {\n onMouseEnter: chainFunctions([child.props.onMouseEnter, onMouseEnter]),\n onMouseLeave: chainFunctions([child.props.onMouseLeave, onMouseLeave])\n });\n })}\n </div>\n </CSSTransition>\n </span>\n );\n }\n);\n\nexport default DialogContent;\n"],"names":["EMPTY_OBJECT","ESCAPE_KEYS","keyCodes","ESCAPE","DialogContent","forwardRef","_ref","_ref$onEsc","onEsc","NOOP","children","position","wrapperClassName","_ref$isOpen","isOpen","startingEdge","_ref$animationType","animationType","_ref$onMouseEnter","onMouseEnter","_ref$onMouseLeave","onMouseLeave","_ref$onClickOutside","onClickOutside","_ref$onClick","onClick","_ref$onContextMenu","onContextMenu","showDelay","_ref$styleObject","styleObject","isReferenceHidden","_ref$hasTooltip","hasTooltip","containerSelector","_ref$disableContainer","disableContainerScroll","dataTestId","ref","useRef","onOutSideClick","useCallback","event","overrideOnContextMenu","useKeyEvent","keys","callback","useClickOutside","eventName","_useDisableScroll","useDisableScroll","disableScroll","enableScroll","useEffect","transitionOptions","classNames","undefined","appear","styles","expandAppear","appearActive","expandAppearActive","exit","expandExit","opacitySlideAppear","opacitySlideAppearActive","React","createElement","className","cx","contentWrapper","style","onClickCapture","CSSTransition","Object","assign","in","timeout","contentComponent","getStyle","camelCase","_defineProperty","Children","toArray","map","child","cloneElement","chainFunctions","props"],"mappings":"ivBAgBA,IAAMA,EAAe,CAAA,EACfC,EAAc,CAACC,EAASC,QA8ExBC,EAAgBC,GACpB,SAAAC,EAsBED,GACE,IAAAE,EAAAD,EArBAE,MAAAA,OAAQC,IAAHF,EAAGE,E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,IACEtB,EACFqC,KAEAC,KAGL,GAAE,CAAChB,EAAwBe,GAAeC,GAActC,IAEzD,IAAMwC,GAAiD,CAAEC,gBAAYC,GAErE,OAAQvC,GACN,IAAK,SACHqC,GAAkBC,WAAa,CAC7BE,OAAQC,EAAOC,aACfC,aAAcF,EAAOG,mBACrBC,KAAMJ,EAAOK,YAEf,MACF,IAAK,oBACHT,GAAkBC,WAAa,CAC7BE,OAAQC,EAAOM,mBACfJ,aAAcF,EAAOO,0BAI3B,OACEC,EAAAC,cAAA,OAAA,CAEEC,UAAWC,EAAG,sCAAuCX,EAAOY,eAAgB1D,GAC5E0B,IAAKjC,EAAU,cACFgC,EACbkC,MAAOzC,EACP0C,eAAgB/C,EAAO,+BACOM,GAE9BmC,EAAAC,cAACM,EAAkBC,OAAAC,OAAA,CAAA,EAAArB,GAAmB,CAAAsB,GAAI9D,EAAQ2C,SAAUxC,EAAe4D,QAASjD,IAClFsC,EAAAC,cAAA,MAAA,CACEC,UAAWC,EAAGX,EAAOoB,iBAAkBC,EAASrB,EAAQsB,EAAUrE,IAAUsE,EAAAA,EACzEF,GAAAA,EAASrB,EAAQsB,EAAU,QAAUjE,IAAiBA,GACtD2C,EAAOzB,WAAaA,IAEvBK,IAAKA,GAEJ4B,EAAMgB,SAASC,QAAQzE,GAAU0E,KAAI,SAACC,GACrC,OAAOC,EAAaD,EAAO,CACzBlE,aAAcoE,EAAe,CAACF,EAAMG,MAAMrE,aAAcA,IACxDE,aAAckE,EAAe,CAACF,EAAMG,MAAMnE,aAAcA,WAOtE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{slicedToArray as o,defineProperty as e,toConsumableArray as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{__rest as i}from"../../../_virtual/_tslib.js";import{camelCase as n}from"lodash-es";import{getStyle as a}from"../../helpers/typesciptCssModulesHelper.js";import{getTestId as r,ComponentDefaultTestId as s}from"../../tests/testIds.js";import l from"classnames";import d,{useState as c,useRef as m,useCallback as u,useMemo as
|
|
1
|
+
import{slicedToArray as o,defineProperty as e,toConsumableArray as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{__rest as i}from"../../../_virtual/_tslib.js";import{camelCase as n}from"lodash-es";import{getStyle as a}from"../../helpers/typesciptCssModulesHelper.js";import{getTestId as r,ComponentDefaultTestId as s}from"../../tests/testIds.js";import l from"classnames";import d,{useState as c,useRef as m,useCallback as u,useMemo as g}from"react";import{SplitButtonSecondaryContentPosition as p,ENTER_KEYS as f,DEFAULT_DIALOG_SHOW_TRIGGER as D,DEFAULT_DIALOG_HIDE_TRIGGER as v,DIALOG_MOVE_BY as y,SECONDARY_BUTTON_ARIA_LABEL as C,SECONDARY_BUTTON_WRAPPER_CLASSNAME as T}from"./SplitButtonConstants.js";import{withStaticPropsWithoutForwardRef as S}from"../../types/withStaticProps.js";import"../../utils/colors-vars-map.js";import{HideShowEvent as N,AnimationType as b}from"../Dialog/DialogConstants.js";import{NOOP as h}from"../../utils/function-utils.js";import{isInsideClass as k}from"../../utils/dom-utils.js";import P from"../../hooks/useKeyEvent/index.js";import j from"../../hooks/useEventListener/index.js";import I from"../Button/Button.js";import B from"../Dialog/Dialog.js";import O from"../DialogContentContainer/DialogContentContainer.js";import E from"./SplitButton.module.scss.js";import{ComponentVibeId as _}from"../../tests/constants.js";import z from"../../../icons/dist/react/DropdownChevronDown.js";var w=function(p){var S=p.secondaryDialogContent,w=p.onSecondaryDialogDidShow,L=void 0===w?h:w,A=p.onSecondaryDialogDidHide,x=void 0===A?h:A,R=p.shouldCloseOnClickInsideDialog,H=p.zIndex,U=void 0===H?null:H,M=p.secondaryDialogClassName,F=p.secondaryDialogPosition,K=void 0===F?"bottom-start":F,W=p.dialogContainerSelector,Y=p.dialogPaddingSize,V=void 0===Y?"medium":Y,X=p.disabled,q=p.loading,G=p.kind,J=p.color,Q=p.className,Z=p.leftIcon,$=p.rightIcon,oo=p.onClick,eo=p.children,to=p.marginLeft,io=p.marginRight,no=p.active,ao=p.id,ro=p["data-testid"],so=i(p,["secondaryDialogContent","onSecondaryDialogDidShow","onSecondaryDialogDidHide","shouldCloseOnClickInsideDialog","zIndex","secondaryDialogClassName","secondaryDialogPosition","dialogContainerSelector","dialogPaddingSize","disabled","success","loading","kind","color","className","leftIcon","rightIcon","onClick","children","marginLeft","marginRight","active","id","data-testid"]),lo=c(!1),co=o(lo,2),mo=co[0],uo=co[1],go=c(!1),po=o(go,2),fo=po[0],Do=po[1],vo=c(!1),yo=o(vo,2),Co=yo[0],To=yo[1],So=m(null),No=m(null),bo=u((function(){return Do(!0)}),[Do]),ho=u((function(){return Do(!1)}),[Do]),ko=u((function(o){return!X&&!k(o.target,T)}),[X]),Po=u((function(o){ko(o)&&To(!0)}),[To,ko]),jo=u((function(){return To(!1)}),[To]),Io=u((function(o){ko(o)&&To(!0)}),[To,ko]),Bo=u((function(){uo(!0),L()}),[uo,L]),Oo=u((function(o,e){uo(!1),x(),"esckey"===e&&No.current.focus()}),[uo,x]);j({eventName:"mouseenter",callback:bo,ref:So}),j({eventName:"mouseleave",callback:ho,ref:So}),j({eventName:"mousedown",callback:Po,ref:So}),j({eventName:"mouseup",callback:jo,ref:So}),j({eventName:"transitionend",callback:jo,ref:So}),P({keys:f,ref:So,callback:Io});var Eo=g((function(){return l(E.button,a(E,n("kind-"+G)),a(E,n("color-"+J)),e(e(e(e(e({},E.mainActive,no),E.active,Co),E.splitContentOpen,mo),E.hovered,fo),E.disabled,X),Q)}),[Q,G,J,no,Co,mo,fo,X]),_o=g((function(){return X?[]:D}),[X]),zo=g((function(){return R?[].concat(t(v),[N.CONTENT_CLICK]):v}),[R]),wo=u((function(){var o="function"==typeof S?S():S;return d.createElement(O,{type:O.types.POPOVER,size:V},o)}),[S,V]),Lo=g((function(){return"bottom"===K?"":"bottom-start"===K?"bottom":"top"}),[K]);return d.createElement("div",{className:Eo,ref:So,id:ao,"data-testid":ro||r(s.SPLIT_BUTTON,ao),"data-vibe":_.SPLIT_BUTTON},d.createElement(I,Object.assign({},so,{preventClickAnimation:!0,leftIcon:Z,rightIcon:$,rightFlat:!0,color:J,kind:G,active:no,onClick:oo,className:E.mainButton,marginLeft:to,onFocus:bo,onBlur:ho,disabled:X,loading:q,"data-testid":r(s.SPLIT_BUTTON_PRIMARY_BUTTON,ao)}),eo),d.createElement("div",{className:E.secondaryButtonWrapper},d.createElement(B,{wrapperClassName:M,zIndex:U,content:wo,position:K,containerSelector:W,startingEdge:Lo,animationType:b.EXPAND,moveBy:y,onDialogDidShow:Bo,onDialogDidHide:Oo,showTrigger:_o,hideTrigger:zo},d.createElement(I,Object.assign({},so,{ref:No,preventClickAnimation:!0,leftFlat:!0,noSidePadding:!0,color:J,kind:G,className:E.secondaryButton,active:mo,marginRight:io,onFocus:bo,onBlur:ho,disabled:X,ariaLabel:C,ariaHasPopup:!0,ariaExpanded:mo,"data-testid":r(s.SPLIT_BUTTON_SECONDARY_BUTTON,ao)}),d.createElement("div",{className:E.secondaryButtonIconWrapper},d.createElement(z,{"aria-hidden":"true"}))))))};w.defaultProps=Object.assign(Object.assign({},I.defaultProps),{onSecondaryDialogDidShow:h,onSecondaryDialogDidHide:h,zIndex:null,secondaryDialogClassName:"",secondaryDialogPosition:p.BOTTOM_START,dialogPaddingSize:O.sizes.MEDIUM});var L=S(w,{secondaryPositions:p,secondaryDialogPositions:p,sizes:I.sizes,colors:I.colors,kinds:I.kinds,inputTags:I.inputTags,dialogPaddingSizes:O.sizes});export{L as default};
|
|
2
2
|
//# sourceMappingURL=SplitButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SplitButton.js","sources":["../../../../src/components/SplitButton/SplitButton.tsx"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\nimport { camelCase } from \"lodash-es\";\nimport { getStyle } from \"../../helpers/typesciptCssModulesHelper\";\nimport { ComponentDefaultTestId, getTestId } from \"../../tests/test-ids-utils\";\nimport cx from \"classnames\";\n// Libraries import\nimport React, { ReactElement, useCallback, useMemo, useRef, useState } from \"react\";\n// Constants import\nimport {\n DEFAULT_DIALOG_HIDE_TRIGGER,\n DEFAULT_DIALOG_SHOW_TRIGGER,\n DIALOG_MOVE_BY,\n ENTER_KEYS,\n SECONDARY_BUTTON_ARIA_LABEL,\n SECONDARY_BUTTON_WRAPPER_CLASSNAME,\n SplitButtonSecondaryContentPosition,\n SplitButtonSecondaryContentPositionType\n} from \"./SplitButtonConstants\";\nimport { withStaticPropsWithoutForwardRef } from \"../../types\";\nimport { AnimationType, DialogPosition, HideShowEvent } from \"../Dialog/DialogConstants\";\n// Utils import\nimport { NOOP } from \"../../utils/function-utils\";\nimport { isInsideClass } from \"../../utils/dom-utils\";\n// Hooks import\nimport useKeyEvent from \"../../hooks/useKeyEvent\";\nimport useEventListener from \"../../hooks/useEventListener\";\n// Components import\nimport Button, { ButtonProps } from \"../Button/Button\";\nimport Dialog, { DialogEvent } from \"../Dialog/Dialog\";\nimport { DropdownChevronDown } from \"@vibe/icons\";\nimport DialogContentContainer from \"../DialogContentContainer/DialogContentContainer\";\nimport styles from \"./SplitButton.module.scss\";\nimport { DialogSize, DialogTriggerEvent } from \"../Dialog\";\nimport { ComponentVibeId } from \"../../tests/constants\";\n\nexport interface SplitButtonProps extends ButtonProps {\n /**\n * The element or renderer that is displayed inside the dialog opened by clicking the secondary button.\n */\n secondaryDialogContent?: ReactElement | (() => string | ReactElement);\n /**\n * Callback fired when the secondary dialog is shown.\n */\n onSecondaryDialogDidShow?: () => void;\n /**\n * Callback fired when the secondary dialog is hidden.\n */\n onSecondaryDialogDidHide?: () => void;\n /**\n * The z-index applied to the secondary dialog.\n */\n zIndex?: number;\n /**\n * Class name applied to the wrapper of the secondary dialog.\n */\n secondaryDialogClassName?: string;\n /**\n * The position of the secondary dialog.\n */\n secondaryDialogPosition?: SplitButtonSecondaryContentPositionType;\n /**\n * The padding size inside the secondary dialog.\n */\n dialogPaddingSize?: DialogSize;\n /**\n * The CSS selector of the container where the dialog should be rendered.\n */\n dialogContainerSelector?: string;\n /**\n * If true, clicking inside the dialog will close it.\n */\n shouldCloseOnClickInsideDialog?: boolean;\n}\n\nconst SplitButton = ({\n secondaryDialogContent,\n onSecondaryDialogDidShow = NOOP,\n onSecondaryDialogDidHide = NOOP,\n shouldCloseOnClickInsideDialog,\n zIndex = null,\n secondaryDialogClassName = \"\",\n secondaryDialogPosition = \"bottom-start\",\n dialogContainerSelector,\n dialogPaddingSize = \"medium\",\n disabled,\n // success mode not working right now, need to fix it in different pr\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n success,\n loading,\n kind = \"primary\",\n color = \"primary\",\n className,\n leftIcon,\n rightIcon,\n onClick,\n children,\n marginLeft,\n marginRight,\n active,\n id,\n \"data-testid\": dataTestId,\n ...buttonProps\n}: SplitButtonProps) => {\n // State //\n const [isDialogOpen, setDialogOpen] = useState(false);\n const [isHovered, setIsHover] = useState(false);\n const [isActive, setIsActive] = useState(false);\n\n // Refs //\n const ref = useRef(null);\n const secondaryButtonRef = useRef(null);\n\n // Callbacks //\n const setHovered = useCallback(() => setIsHover(true), [setIsHover]);\n const setNotHovered = useCallback(() => setIsHover(false), [setIsHover]);\n\n const shouldSetActive = useCallback(\n (e: React.KeyboardEvent<HTMLElement>) => {\n if (disabled) return false;\n return !isInsideClass(e.target as HTMLElement, SECONDARY_BUTTON_WRAPPER_CLASSNAME);\n },\n [disabled]\n );\n\n const setActive = useCallback(\n (e: React.KeyboardEvent<HTMLElement>) => {\n if (!shouldSetActive(e)) return;\n setIsActive(true);\n },\n [setIsActive, shouldSetActive]\n );\n const setNotActive = useCallback(() => setIsActive(false), [setIsActive]);\n const setActiveOnEnter = useCallback(\n (e: React.KeyboardEvent<HTMLElement>) => {\n if (!shouldSetActive(e)) return;\n setIsActive(true);\n },\n [setIsActive, shouldSetActive]\n );\n\n const showDialog = useCallback(() => {\n setDialogOpen(true);\n onSecondaryDialogDidShow();\n }, [setDialogOpen, onSecondaryDialogDidShow]);\n\n const hideDialog = useCallback(\n (_: DialogEvent, eventName: DialogTriggerEvent) => {\n setDialogOpen(false);\n onSecondaryDialogDidHide();\n if (eventName === \"esckey\") {\n secondaryButtonRef.current.focus();\n }\n },\n [setDialogOpen, onSecondaryDialogDidHide]\n );\n\n // Event listeners //\n\n // Used to set both buttons as hovered no matter what button was hovered\n useEventListener({ eventName: \"mouseenter\", callback: setHovered, ref });\n useEventListener({ eventName: \"mouseleave\", callback: setNotHovered, ref });\n\n useEventListener({ eventName: \"mousedown\", callback: setActive, ref });\n useEventListener({ eventName: \"mouseup\", callback: setNotActive, ref });\n\n // Used to finish active transition if clicked on enter\n useEventListener({ eventName: \"transitionend\", callback: setNotActive, ref });\n\n // Key events\n useKeyEvent({ keys: ENTER_KEYS, ref, callback: setActiveOnEnter });\n\n const classNames = useMemo(\n () =>\n cx(\n styles.button,\n getStyle(styles, camelCase(\"kind-\" + kind)),\n getStyle(styles, camelCase(\"color-\" + color)),\n {\n [styles.mainActive]: active,\n [styles.active]: isActive,\n [styles.splitContentOpen]: isDialogOpen,\n [styles.hovered]: isHovered,\n [styles.disabled]: disabled\n },\n className\n ),\n [className, kind, color, active, isActive, isDialogOpen, isHovered, disabled]\n );\n\n const dialogShowTrigger = useMemo(() => (disabled ? [] : DEFAULT_DIALOG_SHOW_TRIGGER), [disabled]);\n\n const dialogHideTrigger = useMemo(() => {\n if (shouldCloseOnClickInsideDialog) return [...DEFAULT_DIALOG_HIDE_TRIGGER, HideShowEvent.CONTENT_CLICK];\n return DEFAULT_DIALOG_HIDE_TRIGGER;\n }, [shouldCloseOnClickInsideDialog]);\n\n const actionsContent = useCallback(() => {\n const content = typeof secondaryDialogContent === \"function\" ? secondaryDialogContent() : secondaryDialogContent;\n return (\n <DialogContentContainer type={DialogContentContainer.types.POPOVER} size={dialogPaddingSize}>\n {content}\n </DialogContentContainer>\n );\n }, [secondaryDialogContent, dialogPaddingSize]);\n\n const animationEdgePosition = useMemo(() => {\n if (secondaryDialogPosition === \"bottom\") {\n return \"\";\n }\n if (secondaryDialogPosition === \"bottom-start\") {\n return \"bottom\";\n }\n\n return \"top\";\n }, [secondaryDialogPosition]);\n\n return (\n <div\n className={classNames}\n ref={ref}\n id={id}\n data-testid={dataTestId || getTestId(ComponentDefaultTestId.SPLIT_BUTTON, id)}\n data-vibe={ComponentVibeId.SPLIT_BUTTON}\n >\n <Button\n {\n ...buttonProps /* We are enriching button with other props so we must use spreading */\n }\n preventClickAnimation\n leftIcon={leftIcon}\n rightIcon={rightIcon}\n rightFlat\n color={color}\n kind={kind}\n active={active}\n onClick={onClick}\n className={styles.mainButton}\n marginLeft={marginLeft}\n onFocus={setHovered}\n onBlur={setNotHovered}\n disabled={disabled}\n loading={loading}\n data-testid={getTestId(ComponentDefaultTestId.SPLIT_BUTTON_PRIMARY_BUTTON, id)}\n >\n {children}\n </Button>\n <div className={styles.secondaryButtonWrapper}>\n <Dialog\n wrapperClassName={secondaryDialogClassName}\n zIndex={zIndex}\n content={actionsContent}\n position={secondaryDialogPosition as DialogPosition}\n containerSelector={dialogContainerSelector}\n startingEdge={animationEdgePosition}\n animationType={AnimationType.EXPAND}\n moveBy={DIALOG_MOVE_BY}\n onDialogDidShow={showDialog}\n onDialogDidHide={hideDialog}\n showTrigger={dialogShowTrigger}\n hideTrigger={dialogHideTrigger}\n >\n <Button\n {...buttonProps}\n ref={secondaryButtonRef}\n preventClickAnimation\n leftFlat\n noSidePadding\n color={color}\n kind={kind}\n className={styles.secondaryButton}\n active={isDialogOpen}\n marginRight={marginRight}\n onFocus={setHovered}\n onBlur={setNotHovered}\n disabled={disabled}\n ariaLabel={SECONDARY_BUTTON_ARIA_LABEL}\n ariaHasPopup\n ariaExpanded={isDialogOpen}\n data-testid={getTestId(ComponentDefaultTestId.SPLIT_BUTTON_SECONDARY_BUTTON, id)}\n >\n <div className={styles.secondaryButtonIconWrapper}>\n <DropdownChevronDown aria-hidden=\"true\" />\n </div>\n </Button>\n </Dialog>\n </div>\n </div>\n );\n};\n\ninterface SplitButtonStaticProps {\n secondaryPositions: typeof SplitButtonSecondaryContentPosition;\n secondaryDialogPositions: typeof SplitButtonSecondaryContentPosition;\n sizes: typeof Button.sizes;\n colors: typeof Button.colors;\n kinds: typeof Button.kinds;\n inputTags: typeof Button.inputTags;\n dialogPaddingSizes: typeof DialogContentContainer.sizes;\n}\n\nexport default withStaticPropsWithoutForwardRef<SplitButtonProps, SplitButtonStaticProps>(SplitButton, {\n secondaryPositions: SplitButtonSecondaryContentPosition,\n secondaryDialogPositions: SplitButtonSecondaryContentPosition,\n sizes: Button.sizes,\n colors: Button.colors,\n kinds: Button.kinds,\n inputTags: Button.inputTags,\n dialogPaddingSizes: DialogContentContainer.sizes\n});\n"],"names":["withStaticPropsWithoutForwardRef","_a","secondaryDialogContent","_a$onSecondaryDialogD","onSecondaryDialogDidShow","NOOP","_a$onSecondaryDialogD2","onSecondaryDialogDidHide","shouldCloseOnClickInsideDialog","_a$zIndex","zIndex","_a$secondaryDialogCla","secondaryDialogClassName","_a$secondaryDialogPos","secondaryDialogPosition","dialogContainerSelector","_a$dialogPaddingSize","dialogPaddingSize","disabled","loading","_a$kind","kind","_a$color","color","className","leftIcon","rightIcon","onClick","children","marginLeft","marginRight","active","id","dataTestId","buttonProps","__rest","_useState","useState","_useState2","_slicedToArray","isDialogOpen","setDialogOpen","_useState3","_useState4","isHovered","setIsHover","_useState5","_useState6","isActive","setIsActive","ref","useRef","secondaryButtonRef","setHovered","useCallback","setNotHovered","shouldSetActive","e","isInsideClass","target","SECONDARY_BUTTON_WRAPPER_CLASSNAME","setActive","setNotActive","setActiveOnEnter","showDialog","hideDialog","_","eventName","current","focus","useEventListener","callback","useKeyEvent","keys","ENTER_KEYS","classNames","useMemo","cx","styles","button","getStyle","camelCase","_defineProperty","mainActive","splitContentOpen","hovered","dialogShowTrigger","DEFAULT_DIALOG_SHOW_TRIGGER","dialogHideTrigger","concat","_toConsumableArray","DEFAULT_DIALOG_HIDE_TRIGGER","HideShowEvent","CONTENT_CLICK","actionsContent","content","React","createElement","DialogContentContainer","type","types","POPOVER","size","animationEdgePosition","getTestId","ComponentDefaultTestId","SPLIT_BUTTON","ComponentVibeId","Button","Object","assign","preventClickAnimation","rightFlat","mainButton","onFocus","onBlur","SPLIT_BUTTON_PRIMARY_BUTTON","secondaryButtonWrapper","Dialog","wrapperClassName","position","containerSelector","startingEdge","animationType","AnimationType","EXPAND","moveBy","DIALOG_MOVE_BY","onDialogDidShow","onDialogDidHide","showTrigger","hideTrigger","leftFlat","noSidePadding","secondaryButton","ariaLabel","SECONDARY_BUTTON_ARIA_LABEL","ariaHasPopup","ariaExpanded","SPLIT_BUTTON_SECONDARY_BUTTON","secondaryButtonIconWrapper","DropdownChevronDown","secondaryPositions","SplitButtonSecondaryContentPosition","secondaryDialogPositions","sizes","colors","kinds","inputTags","dialogPaddingSizes"],"mappings":"65CA0EA,IAkOeA,EAAAA,GAlOK,SAACC,GAAA,IACnBC,EAyByBD,EAzBzBC,uBAAsBC,EAyBGF,EAxBzBG,yBAAAA,OAA2BC,IAAHF,EAAGE,EAAIF,EAAAG,EAwBNL,EAvBzBM,yBAAAA,OAA2BF,IAAHC,EAAGD,EAAIC,EAC/BE,EAsByBP,EAtBzBO,+BAA8BC,EAsBLR,EArBzBS,OAAAA,OAAS,IAAHD,EAAG,KAAIA,EAAAE,EAqBYV,EApBzBW,yBAAAA,OAA2B,IAAHD,EAAG,GAAEA,EAAAE,EAoBJZ,EAnBzBa,wBAAAA,OAA0B,IAAHD,EAAG,eAAcA,EACxCE,EAkByBd,EAlBzBc,wBAAuBC,EAkBEf,EAjBzBgB,kBAAAA,OAAoB,IAAHD,EAAG,SAAQA,EAC5BE,EAgByBjB,EAhBzBiB,SAIAC,EAYyBlB,EAZzBkB,QAAOC,EAYkBnB,EAXzBoB,KAAAA,OAAO,IAAHD,EAAG,UAASA,EAAAE,EAWSrB,EAVzBsB,MAAAA,OAAQ,IAAHD,EAAG,UAASA,EACjBE,GASyBvB,EATzBuB,UACAC,GAQyBxB,EARzBwB,S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
{"version":3,"file":"SplitButton.js","sources":["../../../../src/components/SplitButton/SplitButton.tsx"],"sourcesContent":["/* eslint-disable react/jsx-props-no-spreading */\nimport { camelCase } from \"lodash-es\";\nimport { getStyle } from \"../../helpers/typesciptCssModulesHelper\";\nimport { ComponentDefaultTestId, getTestId } from \"../../tests/test-ids-utils\";\nimport cx from \"classnames\";\n// Libraries import\nimport React, { ReactElement, useCallback, useMemo, useRef, useState } from \"react\";\n// Constants import\nimport {\n DEFAULT_DIALOG_HIDE_TRIGGER,\n DEFAULT_DIALOG_SHOW_TRIGGER,\n DIALOG_MOVE_BY,\n ENTER_KEYS,\n SECONDARY_BUTTON_ARIA_LABEL,\n SECONDARY_BUTTON_WRAPPER_CLASSNAME,\n SplitButtonSecondaryContentPosition,\n SplitButtonSecondaryContentPositionType\n} from \"./SplitButtonConstants\";\nimport { withStaticPropsWithoutForwardRef } from \"../../types\";\nimport { AnimationType, DialogPosition, HideShowEvent } from \"../Dialog/DialogConstants\";\n// Utils import\nimport { NOOP } from \"../../utils/function-utils\";\nimport { isInsideClass } from \"../../utils/dom-utils\";\n// Hooks import\nimport useKeyEvent from \"../../hooks/useKeyEvent\";\nimport useEventListener from \"../../hooks/useEventListener\";\n// Components import\nimport Button, { ButtonProps } from \"../Button/Button\";\nimport Dialog, { DialogEvent } from \"../Dialog/Dialog\";\nimport { DropdownChevronDown } from \"@vibe/icons\";\nimport DialogContentContainer from \"../DialogContentContainer/DialogContentContainer\";\nimport styles from \"./SplitButton.module.scss\";\nimport { DialogSize, DialogTriggerEvent } from \"../Dialog\";\nimport { ComponentVibeId } from \"../../tests/constants\";\n\nexport interface SplitButtonProps extends ButtonProps {\n /**\n * The element or renderer that is displayed inside the dialog opened by clicking the secondary button.\n */\n secondaryDialogContent?: ReactElement | (() => string | ReactElement);\n /**\n * Callback fired when the secondary dialog is shown.\n */\n onSecondaryDialogDidShow?: () => void;\n /**\n * Callback fired when the secondary dialog is hidden.\n */\n onSecondaryDialogDidHide?: () => void;\n /**\n * The z-index applied to the secondary dialog.\n */\n zIndex?: number;\n /**\n * Class name applied to the wrapper of the secondary dialog.\n */\n secondaryDialogClassName?: string;\n /**\n * The position of the secondary dialog.\n */\n secondaryDialogPosition?: SplitButtonSecondaryContentPositionType;\n /**\n * The padding size inside the secondary dialog.\n */\n dialogPaddingSize?: DialogSize;\n /**\n * The CSS selector of the container where the dialog should be rendered.\n */\n dialogContainerSelector?: string;\n /**\n * If true, clicking inside the dialog will close it.\n */\n shouldCloseOnClickInsideDialog?: boolean;\n}\n\nconst SplitButton = ({\n secondaryDialogContent,\n onSecondaryDialogDidShow = NOOP,\n onSecondaryDialogDidHide = NOOP,\n shouldCloseOnClickInsideDialog,\n zIndex = null,\n secondaryDialogClassName,\n secondaryDialogPosition = \"bottom-start\",\n dialogContainerSelector,\n dialogPaddingSize = \"medium\",\n disabled,\n // success mode not working right now, need to fix it in different pr\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n success,\n loading,\n kind,\n color,\n className,\n leftIcon,\n rightIcon,\n onClick,\n children,\n marginLeft,\n marginRight,\n active,\n id,\n \"data-testid\": dataTestId,\n ...buttonProps\n}: SplitButtonProps) => {\n // State //\n const [isDialogOpen, setDialogOpen] = useState(false);\n const [isHovered, setIsHover] = useState(false);\n const [isActive, setIsActive] = useState(false);\n\n // Refs //\n const ref = useRef(null);\n const secondaryButtonRef = useRef(null);\n\n // Callbacks //\n const setHovered = useCallback(() => setIsHover(true), [setIsHover]);\n const setNotHovered = useCallback(() => setIsHover(false), [setIsHover]);\n\n const shouldSetActive = useCallback(\n (e: React.KeyboardEvent<HTMLElement>) => {\n if (disabled) return false;\n return !isInsideClass(e.target as HTMLElement, SECONDARY_BUTTON_WRAPPER_CLASSNAME);\n },\n [disabled]\n );\n\n const setActive = useCallback(\n (e: React.KeyboardEvent<HTMLElement>) => {\n if (!shouldSetActive(e)) return;\n setIsActive(true);\n },\n [setIsActive, shouldSetActive]\n );\n const setNotActive = useCallback(() => setIsActive(false), [setIsActive]);\n const setActiveOnEnter = useCallback(\n (e: React.KeyboardEvent<HTMLElement>) => {\n if (!shouldSetActive(e)) return;\n setIsActive(true);\n },\n [setIsActive, shouldSetActive]\n );\n\n const showDialog = useCallback(() => {\n setDialogOpen(true);\n onSecondaryDialogDidShow();\n }, [setDialogOpen, onSecondaryDialogDidShow]);\n\n const hideDialog = useCallback(\n (_: DialogEvent, eventName: DialogTriggerEvent) => {\n setDialogOpen(false);\n onSecondaryDialogDidHide();\n if (eventName === \"esckey\") {\n secondaryButtonRef.current.focus();\n }\n },\n [setDialogOpen, onSecondaryDialogDidHide]\n );\n\n // Event listeners //\n\n // Used to set both buttons as hovered no matter what button was hovered\n useEventListener({ eventName: \"mouseenter\", callback: setHovered, ref });\n useEventListener({ eventName: \"mouseleave\", callback: setNotHovered, ref });\n\n useEventListener({ eventName: \"mousedown\", callback: setActive, ref });\n useEventListener({ eventName: \"mouseup\", callback: setNotActive, ref });\n\n // Used to finish active transition if clicked on enter\n useEventListener({ eventName: \"transitionend\", callback: setNotActive, ref });\n\n // Key events\n useKeyEvent({ keys: ENTER_KEYS, ref, callback: setActiveOnEnter });\n\n const classNames = useMemo(\n () =>\n cx(\n styles.button,\n getStyle(styles, camelCase(\"kind-\" + kind)),\n getStyle(styles, camelCase(\"color-\" + color)),\n {\n [styles.mainActive]: active,\n [styles.active]: isActive,\n [styles.splitContentOpen]: isDialogOpen,\n [styles.hovered]: isHovered,\n [styles.disabled]: disabled\n },\n className\n ),\n [className, kind, color, active, isActive, isDialogOpen, isHovered, disabled]\n );\n\n const dialogShowTrigger = useMemo(() => (disabled ? [] : DEFAULT_DIALOG_SHOW_TRIGGER), [disabled]);\n\n const dialogHideTrigger = useMemo(() => {\n if (shouldCloseOnClickInsideDialog) return [...DEFAULT_DIALOG_HIDE_TRIGGER, HideShowEvent.CONTENT_CLICK];\n return DEFAULT_DIALOG_HIDE_TRIGGER;\n }, [shouldCloseOnClickInsideDialog]);\n\n const actionsContent = useCallback(() => {\n const content = typeof secondaryDialogContent === \"function\" ? secondaryDialogContent() : secondaryDialogContent;\n return (\n <DialogContentContainer type={DialogContentContainer.types.POPOVER} size={dialogPaddingSize}>\n {content}\n </DialogContentContainer>\n );\n }, [secondaryDialogContent, dialogPaddingSize]);\n\n const animationEdgePosition = useMemo(() => {\n if (secondaryDialogPosition === \"bottom\") {\n return \"\";\n }\n if (secondaryDialogPosition === \"bottom-start\") {\n return \"bottom\";\n }\n\n return \"top\";\n }, [secondaryDialogPosition]);\n\n return (\n <div\n className={classNames}\n ref={ref}\n id={id}\n data-testid={dataTestId || getTestId(ComponentDefaultTestId.SPLIT_BUTTON, id)}\n data-vibe={ComponentVibeId.SPLIT_BUTTON}\n >\n <Button\n {\n ...buttonProps /* We are enriching button with other props so we must use spreading */\n }\n preventClickAnimation\n leftIcon={leftIcon}\n rightIcon={rightIcon}\n rightFlat\n color={color}\n kind={kind}\n active={active}\n onClick={onClick}\n className={styles.mainButton}\n marginLeft={marginLeft}\n onFocus={setHovered}\n onBlur={setNotHovered}\n disabled={disabled}\n loading={loading}\n data-testid={getTestId(ComponentDefaultTestId.SPLIT_BUTTON_PRIMARY_BUTTON, id)}\n >\n {children}\n </Button>\n <div className={styles.secondaryButtonWrapper}>\n <Dialog\n wrapperClassName={secondaryDialogClassName}\n zIndex={zIndex}\n content={actionsContent}\n position={secondaryDialogPosition as DialogPosition}\n containerSelector={dialogContainerSelector}\n startingEdge={animationEdgePosition}\n animationType={AnimationType.EXPAND}\n moveBy={DIALOG_MOVE_BY}\n onDialogDidShow={showDialog}\n onDialogDidHide={hideDialog}\n showTrigger={dialogShowTrigger}\n hideTrigger={dialogHideTrigger}\n >\n <Button\n {...buttonProps}\n ref={secondaryButtonRef}\n preventClickAnimation\n leftFlat\n noSidePadding\n color={color}\n kind={kind}\n className={styles.secondaryButton}\n active={isDialogOpen}\n marginRight={marginRight}\n onFocus={setHovered}\n onBlur={setNotHovered}\n disabled={disabled}\n ariaLabel={SECONDARY_BUTTON_ARIA_LABEL}\n ariaHasPopup\n ariaExpanded={isDialogOpen}\n data-testid={getTestId(ComponentDefaultTestId.SPLIT_BUTTON_SECONDARY_BUTTON, id)}\n >\n <div className={styles.secondaryButtonIconWrapper}>\n <DropdownChevronDown aria-hidden=\"true\" />\n </div>\n </Button>\n </Dialog>\n </div>\n </div>\n );\n};\n\nSplitButton.defaultProps = {\n ...Button.defaultProps,\n onSecondaryDialogDidShow: NOOP,\n onSecondaryDialogDidHide: NOOP,\n zIndex: null,\n secondaryDialogClassName: \"\",\n secondaryDialogPosition: SplitButtonSecondaryContentPosition.BOTTOM_START,\n dialogPaddingSize: DialogContentContainer.sizes.MEDIUM\n};\n\ninterface SplitButtonStaticProps {\n secondaryPositions: typeof SplitButtonSecondaryContentPosition;\n secondaryDialogPositions: typeof SplitButtonSecondaryContentPosition;\n sizes: typeof Button.sizes;\n colors: typeof Button.colors;\n kinds: typeof Button.kinds;\n inputTags: typeof Button.inputTags;\n dialogPaddingSizes: typeof DialogContentContainer.sizes;\n}\n\nexport default withStaticPropsWithoutForwardRef<SplitButtonProps, SplitButtonStaticProps>(SplitButton, {\n secondaryPositions: SplitButtonSecondaryContentPosition,\n secondaryDialogPositions: SplitButtonSecondaryContentPosition,\n sizes: Button.sizes,\n colors: Button.colors,\n kinds: Button.kinds,\n inputTags: Button.inputTags,\n dialogPaddingSizes: DialogContentContainer.sizes\n});\n"],"names":["SplitButton","_a","secondaryDialogContent","_a$onSecondaryDialogD","onSecondaryDialogDidShow","NOOP","_a$onSecondaryDialogD2","onSecondaryDialogDidHide","shouldCloseOnClickInsideDialog","_a$zIndex","zIndex","secondaryDialogClassName","_a$secondaryDialogPos","secondaryDialogPosition","dialogContainerSelector","_a$dialogPaddingSize","dialogPaddingSize","disabled","loading","kind","color","className","leftIcon","rightIcon","onClick","children","marginLeft","marginRight","active","id","dataTestId","buttonProps","__rest","_useState","useState","_useState2","_slicedToArray","isDialogOpen","setDialogOpen","_useState3","_useState4","isHovered","setIsHover","_useState5","_useState6","isActive","setIsActive","ref","useRef","secondaryButtonRef","setHovered","useCallback","setNotHovered","shouldSetActive","e","isInsideClass","target","SECONDARY_BUTTON_WRAPPER_CLASSNAME","setActive","setNotActive","setActiveOnEnter","showDialog","hideDialog","_","eventName","current","focus","useEventListener","callback","useKeyEvent","keys","ENTER_KEYS","classNames","useMemo","cx","styles","button","getStyle","camelCase","_defineProperty","mainActive","splitContentOpen","hovered","dialogShowTrigger","DEFAULT_DIALOG_SHOW_TRIGGER","dialogHideTrigger","concat","_toConsumableArray","DEFAULT_DIALOG_HIDE_TRIGGER","HideShowEvent","CONTENT_CLICK","actionsContent","content","React","createElement","DialogContentContainer","type","types","POPOVER","size","animationEdgePosition","getTestId","ComponentDefaultTestId","SPLIT_BUTTON","ComponentVibeId","Button","Object","assign","preventClickAnimation","rightFlat","mainButton","onFocus","onBlur","SPLIT_BUTTON_PRIMARY_BUTTON","secondaryButtonWrapper","Dialog","wrapperClassName","position","containerSelector","startingEdge","animationType","AnimationType","EXPAND","moveBy","DIALOG_MOVE_BY","onDialogDidShow","onDialogDidHide","showTrigger","hideTrigger","leftFlat","noSidePadding","secondaryButton","ariaLabel","SECONDARY_BUTTON_ARIA_LABEL","ariaHasPopup","ariaExpanded","SPLIT_BUTTON_SECONDARY_BUTTON","secondaryButtonIconWrapper","DropdownChevronDown","defaultProps","SplitButtonSecondaryContentPosition","BOTTOM_START","sizes","MEDIUM","withStaticPropsWithoutForwardRef","secondaryPositions","secondaryDialogPositions","colors","kinds","inputTags","dialogPaddingSizes"],"mappings":"65CA0EA,IAAMA,EAAc,SAACC,GAAA,IACnBC,EA2BiBD,EA3BjBC,uBAAsBC,EA2BLF,EA1BjBG,yBAAAA,OAA2BC,IAAHF,EAAGE,EAAIF,EAAAG,EA0BdL,EAzBjBM,yBAAAA,OAA2BF,IAAHC,EAAGD,EAAIC,EAC/BE,EAwBiBP,EAxBjBO,+BAA8BC,EAwBbR,EAvBjBS,OAAAA,OAAS,IAAHD,EAAG,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ACA,EAAAC,aAAclG,GAAY,cACbgE,EAAUC,EAAuBkC,8BAA+B3G,MAE7EgE,EAAAC,cAAA,MAAA,CAAKzE,UAAWsD,EAAO8D,4BACrB5C,EAACC,cAAA4C,EAAgC,CAAA,cAAA,aAO/C,EAEA1I,EAAY2I,aAAYjC,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EACnBF,EAAOkC,cACV,CAAAvI,yBAA0BC,EAC1BE,yBAA0BF,EAC1BK,OAAQ,KACRC,yBAA0B,GAC1BE,wBAAyB+H,EAAoCC,aAC7D7H,kBAAmB+E,EAAuB+C,MAAMC,SAalD,IAAeC,EAAAA,EAA2EhJ,EAAa,CACrGiJ,mBAAoBL,EACpBM,yBAA0BN,EAC1BE,MAAOrC,EAAOqC,MACdK,OAAQ1C,EAAO0C,OACfC,MAAO3C,EAAO2C,MACdC,UAAW5C,EAAO4C,UAClBC,mBAAoBvD,EAAuB+C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{__rest as e}from"../../../_virtual/_tslib.js";import{camelCase as o}from"lodash-es";import{getTestId as
|
|
1
|
+
import{defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{__rest as e}from"../../../_virtual/_tslib.js";import{camelCase as o}from"lodash-es";import{getTestId as r,ComponentDefaultTestId as i}from"../../tests/testIds.js";import n from"classnames";import s,{useRef as a,useMemo as l,useCallback as c,useEffect as m}from"react";import{CSSTransition as u}from"react-transition-group";import p from"../Text/Text.js";import d from"../Loader/Loader.js";import f from"../Flex/Flex.js";import v from"./ToastLink/ToastLink.js";import T from"./ToastButton/ToastButton.js";import{ToastType as j,ToastActionType as y}from"./ToastConstants.js";import{getIcon as h}from"./ToastHelpers.js";import{NOOP as g}from"../../utils/function-utils.js";import{getStyle as x}from"../../helpers/typesciptCssModulesHelper.js";import{withStaticPropsWithoutForwardRef as E}from"../../types/withStaticProps.js";import"../../utils/colors-vars-map.js";import N from"./Toast.module.scss.js";import C from"../IconButton/IconButton.js";import b from"../../hooks/usePrevious/index.js";import k from"../../../icons/dist/react/CloseSmall.js";var B=E((function(j){var y=j.open,E=void 0!==y&&y,B=j.loading,L=void 0!==B&&B,O=j.autoHideDuration,A=void 0===O?null:O,w=j.type,S=void 0===w?"normal":w,_=j.icon,H=j.hideIcon,I=void 0!==H&&H,P=j.action,z=j.actions,F=j.children,D=j.closeable,M=void 0===D||D,U=j.onClose,q=void 0===U?g:U,G=j.className,J=j.id,K=j.closeButtonAriaLabel,Q=void 0===K?"Close":K,R=j["data-testid"],V=a(null),W=b(null==z?void 0:z.length),X=l((function(){return z?z.filter((function(t){return"link"===t.type})).map((function(t){var o=e(t,["type"]);return s.createElement(v,Object.assign({key:o.href,className:N.actionLink},o))})):null}),[z]),Y=l((function(){return void 0!==W&&(null==z?void 0:z.length)!==W}),[z,W]),Z=l((function(){return z?z.filter((function(t){return"button"===t.type})).map((function(o,r){var i=o.content,a=e(o,["type","content"]);return s.createElement(T,Object.assign({key:"alert-button-".concat(r),className:n(N.actionButton,t({},N.withTransition,Y))},a),i)})):null}),[z,Y]),$=l((function(){return n(N.toast,x(N,o("type-"+S)),G)}),[S,G]),tt=c((function(){q&&q()}),[q]),et=a(),ot=c((function(t){q&&null!=t&&(clearTimeout(et.current),et.current=setTimeout((function(){tt()}),t))}),[tt,q]);m((function(){return E&&A>0&&ot(A),function(){clearTimeout(et.current)}}),[E,A,ot]);var rt=!I&&h(S,_),it=c((function(t){var e=t.style.width;t.style.width="auto";var o=getComputedStyle(t).width;t.style.width=e,t.style.width=o}),[]);return m((function(){V.current&&it(V.current)}),[F,it]),s.createElement(u,{in:E,classNames:{enterActive:N.enterActive,exitActive:N.exitActive},timeout:400,unmountOnExit:!0},s.createElement(p,{id:J,"data-testid":R||r(i.TOAST,J),type:"text2",element:"div",color:"fixedLight",className:$,role:"alert","aria-live":"polite",ref:V},rt&&s.createElement("div",{className:n(N.icon)},rt),s.createElement(f,{align:"center",gap:"large",className:N.content},s.createElement(f,{gap:"medium","data-testid":r(i.TOAST_CONTENT),className:N.textContent},s.createElement("span",null,F),X),(Z||P)&&(Z||P),L&&s.createElement(d,{size:"xs"})),M&&s.createElement(C,{className:n(N.closeButton),onClick:tt,size:"small",kind:"tertiary",color:"fixed-light",ariaLabel:Q,"data-testid":r(i.TOAST_CLOSE_BUTTON),icon:k,hideTooltip:!0})))}),{types:j,actionTypes:y});export{B as default};
|
|
2
2
|
//# sourceMappingURL=Toast.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Toast.js","sources":["../../../../src/components/Toast/Toast.tsx"],"sourcesContent":["import { camelCase } from \"lodash-es\";\nimport { ComponentDefaultTestId, getTestId } from \"../../tests/test-ids-utils\";\nimport cx from \"classnames\";\nimport React, { ReactElement, useCallback, useEffect, useMemo, useRef, type JSX } from \"react\";\nimport { CSSTransition } from \"react-transition-group\";\nimport { IconSubComponentProps } from \"../Icon/Icon\";\nimport Text from \"../Text/Text\";\nimport Loader from \"../Loader/Loader\";\nimport Flex from \"../Flex/Flex\";\nimport { CloseSmall } from \"@vibe/icons\";\nimport ToastLink from \"./ToastLink/ToastLink\";\nimport ToastButton from \"./ToastButton/ToastButton\";\nimport { ToastActionType as ToastActionTypeEnum, ToastType as ToastTypeEnum } from \"./ToastConstants\";\nimport { ToastType, ToastAction } from \"./Toast.types\";\nimport { getIcon } from \"./ToastHelpers\";\nimport { NOOP } from \"../../utils/function-utils\";\nimport { getStyle } from \"../../helpers/typesciptCssModulesHelper\";\nimport { VibeComponentProps, withStaticPropsWithoutForwardRef } from \"../../types\";\nimport styles from \"./Toast.module.scss\";\nimport IconButton from \"../IconButton/IconButton\";\nimport usePrevious from \"../../hooks/usePrevious\";\n\nexport interface ToastProps extends VibeComponentProps {\n /**\n * The actions available in the toast.\n */\n actions?: ToastAction[];\n /**\n * If true, the toast is open (visible).\n */\n open?: boolean;\n /**\n * If true, displays a loading indicator inside the toast.\n */\n loading?: boolean;\n /**\n * The type of toast.\n */\n type?: ToastType;\n /**\n * The icon displayed in the toast.\n */\n icon?: string | React.FC<IconSubComponentProps> | null;\n /**\n * If true, hides the toast icon.\n */\n hideIcon?: boolean;\n /**\n * The action element displayed in the toast.\n */\n action?: JSX.Element;\n /**\n * If false, hides the close button.\n */\n closeable?: boolean;\n /**\n * Callback fired when the toast is closed.\n */\n onClose?: () => void;\n /**\n * The number of milliseconds before the toast automatically closes.\n * (0 or null disables auto-close behavior).\n */\n autoHideDuration?: number;\n /**\n * The content displayed inside the toast.\n */\n children?: ReactElement<any> | ReactElement<any>[] | string;\n /**\n * The aria-label for the close button.\n */\n closeButtonAriaLabel?: string;\n}\n\nconst Toast = ({\n open = false,\n loading = false,\n autoHideDuration = null,\n type = \"normal\",\n icon,\n hideIcon = false,\n action: deprecatedAction,\n actions,\n children,\n closeable = true,\n onClose = NOOP,\n className,\n id,\n closeButtonAriaLabel = \"Close\",\n \"data-testid\": dataTestId\n}: ToastProps) => {\n const ref = useRef(null);\n const nodeRef = useRef<HTMLDivElement>(null);\n const prevActions = usePrevious(actions?.length);\n const toastLinks = useMemo(() => {\n return actions\n ? actions\n .filter(action => action.type === \"link\")\n .map(({ type: _type, ...otherProps }) => (\n <ToastLink key={otherProps.href} className={styles.actionLink} {...otherProps} />\n ))\n : null;\n }, [actions]);\n\n const shouldShowButtonTransition = useMemo(() => {\n return prevActions !== undefined && actions?.length !== prevActions;\n }, [actions, prevActions]);\n\n const toastButtons: JSX.Element[] | null = useMemo(() => {\n return actions\n ? actions\n .filter(action => action.type === \"button\")\n .map(({ type: _type, content, ...otherProps }, index) => (\n <ToastButton\n key={`alert-button-${index}`}\n className={cx(styles.actionButton, { [styles.withTransition]: shouldShowButtonTransition })}\n {...otherProps}\n >\n {content}\n </ToastButton>\n ))\n : null;\n }, [actions, shouldShowButtonTransition]);\n\n const classNames = useMemo(\n () => cx(styles.toast, getStyle(styles, camelCase(\"type-\" + type)), className),\n [type, className]\n );\n\n const handleClose = useCallback(() => {\n if (onClose) {\n onClose();\n }\n }, [onClose]);\n\n /* Timer */\n const timerAutoHide = useRef<NodeJS.Timeout>(undefined);\n const setAutoHideTimer = useCallback(\n (duration: number) => {\n if (!onClose || duration == null) {\n return;\n }\n\n clearTimeout(timerAutoHide.current);\n timerAutoHide.current = setTimeout(() => {\n handleClose();\n }, duration);\n },\n [handleClose, onClose]\n );\n\n useEffect(() => {\n if (open && autoHideDuration > 0) {\n setAutoHideTimer(autoHideDuration);\n }\n\n return () => {\n clearTimeout(timerAutoHide.current);\n };\n }, [open, autoHideDuration, setAutoHideTimer]);\n\n const iconElement = !hideIcon && getIcon(type, icon);\n\n // https://n12v.com/css-transition-to-from-auto/\n const recalculateElementWidth = useCallback((element: HTMLElement) => {\n const prevWidth = element.style.width;\n element.style.width = \"auto\";\n const endWidth = getComputedStyle(element).width;\n element.style.width = prevWidth;\n element.offsetWidth; // force repaint\n element.style.width = endWidth;\n }, []);\n\n useEffect(() => {\n if (ref.current) {\n recalculateElementWidth(ref.current);\n }\n }, [children, recalculateElementWidth]);\n\n return (\n <CSSTransition\n in={open}\n nodeRef={nodeRef}\n classNames={{ enterActive: styles.enterActive, exitActive: styles.exitActive }}\n timeout={400}\n unmountOnExit\n >\n <Text\n ref={nodeRef}\n id={id}\n data-testid={dataTestId || getTestId(ComponentDefaultTestId.TOAST, id)}\n type=\"text2\"\n element=\"div\"\n color=\"fixedLight\"\n className={classNames}\n role=\"alert\"\n aria-live=\"polite\"\n >\n {iconElement && <div className={cx(styles.icon)}>{iconElement}</div>}\n <Flex align=\"center\" gap=\"large\" className={styles.content}>\n <Flex\n gap=\"medium\"\n data-testid={getTestId(ComponentDefaultTestId.TOAST_CONTENT)}\n className={styles.textContent}\n >\n <span>{children}</span>\n {toastLinks}\n </Flex>\n {(toastButtons || deprecatedAction) && (toastButtons || deprecatedAction)}\n {loading && <Loader size=\"xs\" />}\n </Flex>\n {closeable && (\n <IconButton\n className={cx(styles.closeButton)}\n onClick={handleClose}\n size=\"small\"\n kind=\"tertiary\"\n color=\"fixed-light\"\n ariaLabel={closeButtonAriaLabel}\n data-testid={getTestId(ComponentDefaultTestId.TOAST_CLOSE_BUTTON)}\n icon={CloseSmall}\n hideTooltip\n />\n )}\n </Text>\n </CSSTransition>\n );\n};\n\ninterface ToastStaticProps {\n types: typeof ToastTypeEnum;\n actionTypes: typeof ToastActionTypeEnum;\n}\n\nexport default withStaticPropsWithoutForwardRef<ToastProps, ToastStaticProps>(Toast, {\n types: ToastTypeEnum,\n actionTypes: ToastActionTypeEnum\n});\n"],"names":["withStaticPropsWithoutForwardRef","_ref","_ref$open","open","_ref$loading","loading","_ref$autoHideDuration","autoHideDuration","_ref$type","type","icon","_ref$hideIcon","hideIcon","deprecatedAction","action","actions","children","_ref$closeable","closeable","_ref$onClose","onClose","NOOP","className","id","_ref$closeButtonAriaL","closeButtonAriaLabel","dataTestId","ref","useRef","nodeRef","prevActions","usePrevious","length","toastLinks","useMemo","filter","map","_a","otherProps","__rest","React","createElement","ToastLink","key","href","styles","actionLink","shouldShowButtonTransition","undefined","toastButtons","index","content","ToastButton","Object","assign","concat","cx","actionButton","_defineProperty","withTransition","classNames","toast","getStyle","camelCase","handleClose","useCallback","timerAutoHide","setAutoHideTimer","duration","clearTimeout","current","setTimeout","useEffect","iconElement","getIcon","recalculateElementWidth","element","prevWidth","style","width","endWidth","getComputedStyle","CSSTransition","in","enterActive","exitActive","timeout","unmountOnExit","Text","getTestId","ComponentDefaultTestId","TOAST","color","role","Flex","align","gap","TOAST_CONTENT","textContent","Loader","size","IconButton","closeButton","onClick","kind","ariaLabel","TOAST_CLOSE_BUTTON","CloseSmall","hideTooltip","types","ToastTypeEnum","actionTypes","ToastActionTypeEnum"],"mappings":"4mCA0EA,IAgKeA,EAAAA,GAhKD,SAAHC,GAgBM,IAAAC,EAAAD,EAffE,KAAAA,OAAO,IAAHD,GAAQA,EAAAE,EAAAH,EACZI,QAAAA,OAAU,IAAHD,GAAQA,EAAAE,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KAAK,oBACK,UAETpB,IAAejC,EAAAC,cAAA,MAAA,CAAKnB,UAAWkC,EAAGX,EAAOnC,OAAQ+D,IAClDjC,EAAAC,cAACqD,EAAI,CAACC,MAAM,SAASC,IAAI,QAAQ1E,UAAWuB,EAAOM,SACjDX,EAAAC,cAACqD,EACC,CAAAE,IAAI,uBACSP,EAAUC,EAAuBO,eAC9C3E,UAAWuB,EAAOqD,aAElB1D,EAAAC,cAAA,OAAA,KAAOzB,GACNiB,IAEDgB,GAAgBpC,KAAsBoC,GAAgBpC,GACvDR,GAAWmC,gBAAC2D,EAAM,CAACC,KAAK,QAE1BlF,GACCsB,EAACC,cAAA4D,GACC/E,UAAWkC,EAAGX,EAAOyD,aACrBC,QAASvC,GACToC,KAAK,QACLI,KAAK,WACLZ,MAAM,cACNa,UAAWhF,EACE,cAAAgE,EAAUC,EAAuBgB,oBAC9ChG,KAAMiG,EACNC,kBAMZ,GAOqF,CACnFC,MAAOC,EACPC,YAAaC"}
|
|
1
|
+
{"version":3,"file":"Toast.js","sources":["../../../../src/components/Toast/Toast.tsx"],"sourcesContent":["import { camelCase } from \"lodash-es\";\nimport { ComponentDefaultTestId, getTestId } from \"../../tests/test-ids-utils\";\nimport cx from \"classnames\";\nimport React, { ReactElement, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { CSSTransition } from \"react-transition-group\";\nimport { IconSubComponentProps } from \"../Icon/Icon\";\nimport Text from \"../Text/Text\";\nimport Loader from \"../Loader/Loader\";\nimport Flex from \"../Flex/Flex\";\nimport { CloseSmall } from \"@vibe/icons\";\nimport ToastLink from \"./ToastLink/ToastLink\";\nimport ToastButton from \"./ToastButton/ToastButton\";\nimport { ToastActionType as ToastActionTypeEnum, ToastType as ToastTypeEnum } from \"./ToastConstants\";\nimport { ToastType, ToastAction } from \"./Toast.types\";\nimport { getIcon } from \"./ToastHelpers\";\nimport { NOOP } from \"../../utils/function-utils\";\nimport { getStyle } from \"../../helpers/typesciptCssModulesHelper\";\nimport { VibeComponentProps, withStaticPropsWithoutForwardRef } from \"../../types\";\nimport styles from \"./Toast.module.scss\";\nimport IconButton from \"../IconButton/IconButton\";\nimport usePrevious from \"../../hooks/usePrevious\";\n\nexport interface ToastProps extends VibeComponentProps {\n /**\n * The actions available in the toast.\n */\n actions?: ToastAction[];\n /**\n * If true, the toast is open (visible).\n */\n open?: boolean;\n /**\n * If true, displays a loading indicator inside the toast.\n */\n loading?: boolean;\n /**\n * The type of toast.\n */\n type?: ToastType;\n /**\n * The icon displayed in the toast.\n */\n icon?: string | React.FC<IconSubComponentProps> | null;\n /**\n * If true, hides the toast icon.\n */\n hideIcon?: boolean;\n /**\n * The action element displayed in the toast.\n */\n action?: JSX.Element;\n /**\n * If false, hides the close button.\n */\n closeable?: boolean;\n /**\n * Callback fired when the toast is closed.\n */\n onClose?: () => void;\n /**\n * The number of milliseconds before the toast automatically closes.\n * (0 or null disables auto-close behavior).\n */\n autoHideDuration?: number;\n /**\n * The content displayed inside the toast.\n */\n children?: ReactElement | ReactElement[] | string;\n /**\n * The aria-label for the close button.\n */\n closeButtonAriaLabel?: string;\n}\n\nconst Toast = ({\n open = false,\n loading = false,\n autoHideDuration = null,\n type = \"normal\",\n icon,\n hideIcon = false,\n action: deprecatedAction,\n actions,\n children,\n closeable = true,\n onClose = NOOP,\n className,\n id,\n closeButtonAriaLabel = \"Close\",\n \"data-testid\": dataTestId\n}: ToastProps) => {\n const ref = useRef(null);\n const prevActions = usePrevious(actions?.length);\n const toastLinks = useMemo(() => {\n return actions\n ? actions\n .filter(action => action.type === \"link\")\n .map(({ type: _type, ...otherProps }) => (\n <ToastLink key={otherProps.href} className={styles.actionLink} {...otherProps} />\n ))\n : null;\n }, [actions]);\n\n const shouldShowButtonTransition = useMemo(() => {\n return prevActions !== undefined && actions?.length !== prevActions;\n }, [actions, prevActions]);\n\n const toastButtons: JSX.Element[] | null = useMemo(() => {\n return actions\n ? actions\n .filter(action => action.type === \"button\")\n .map(({ type: _type, content, ...otherProps }, index) => (\n <ToastButton\n key={`alert-button-${index}`}\n className={cx(styles.actionButton, { [styles.withTransition]: shouldShowButtonTransition })}\n {...otherProps}\n >\n {content}\n </ToastButton>\n ))\n : null;\n }, [actions, shouldShowButtonTransition]);\n\n const classNames = useMemo(\n () => cx(styles.toast, getStyle(styles, camelCase(\"type-\" + type)), className),\n [type, className]\n );\n\n const handleClose = useCallback(() => {\n if (onClose) {\n onClose();\n }\n }, [onClose]);\n\n /* Timer */\n const timerAutoHide = useRef<NodeJS.Timeout>();\n const setAutoHideTimer = useCallback(\n (duration: number) => {\n if (!onClose || duration == null) {\n return;\n }\n\n clearTimeout(timerAutoHide.current);\n timerAutoHide.current = setTimeout(() => {\n handleClose();\n }, duration);\n },\n [handleClose, onClose]\n );\n\n useEffect(() => {\n if (open && autoHideDuration > 0) {\n setAutoHideTimer(autoHideDuration);\n }\n\n return () => {\n clearTimeout(timerAutoHide.current);\n };\n }, [open, autoHideDuration, setAutoHideTimer]);\n\n const iconElement = !hideIcon && getIcon(type, icon);\n\n // https://n12v.com/css-transition-to-from-auto/\n const recalculateElementWidth = useCallback((element: HTMLElement) => {\n const prevWidth = element.style.width;\n element.style.width = \"auto\";\n const endWidth = getComputedStyle(element).width;\n element.style.width = prevWidth;\n element.offsetWidth; // force repaint\n element.style.width = endWidth;\n }, []);\n\n useEffect(() => {\n if (ref.current) {\n recalculateElementWidth(ref.current);\n }\n }, [children, recalculateElementWidth]);\n\n return (\n <CSSTransition\n in={open}\n classNames={{ enterActive: styles.enterActive, exitActive: styles.exitActive }}\n timeout={400}\n unmountOnExit\n >\n <Text\n id={id}\n data-testid={dataTestId || getTestId(ComponentDefaultTestId.TOAST, id)}\n type=\"text2\"\n element=\"div\"\n color=\"fixedLight\"\n className={classNames}\n role=\"alert\"\n aria-live=\"polite\"\n ref={ref}\n >\n {iconElement && <div className={cx(styles.icon)}>{iconElement}</div>}\n <Flex align=\"center\" gap=\"large\" className={styles.content}>\n <Flex\n gap=\"medium\"\n data-testid={getTestId(ComponentDefaultTestId.TOAST_CONTENT)}\n className={styles.textContent}\n >\n <span>{children}</span>\n {toastLinks}\n </Flex>\n {(toastButtons || deprecatedAction) && (toastButtons || deprecatedAction)}\n {loading && <Loader size=\"xs\" />}\n </Flex>\n {closeable && (\n <IconButton\n className={cx(styles.closeButton)}\n onClick={handleClose}\n size=\"small\"\n kind=\"tertiary\"\n color=\"fixed-light\"\n ariaLabel={closeButtonAriaLabel}\n data-testid={getTestId(ComponentDefaultTestId.TOAST_CLOSE_BUTTON)}\n icon={CloseSmall}\n hideTooltip\n />\n )}\n </Text>\n </CSSTransition>\n );\n};\n\ninterface ToastStaticProps {\n types: typeof ToastTypeEnum;\n actionTypes: typeof ToastActionTypeEnum;\n}\n\nexport default withStaticPropsWithoutForwardRef<ToastProps, ToastStaticProps>(Toast, {\n types: ToastTypeEnum,\n actionTypes: ToastActionTypeEnum\n});\n"],"names":["withStaticPropsWithoutForwardRef","_ref","_ref$open","open","_ref$loading","loading","_ref$autoHideDuration","autoHideDuration","_ref$type","type","icon","_ref$hideIcon","hideIcon","deprecatedAction","action","actions","children","_ref$closeable","closeable","_ref$onClose","onClose","NOOP","className","id","_ref$closeButtonAriaL","closeButtonAriaLabel","dataTestId","ref","useRef","prevActions","usePrevious","length","toastLinks","useMemo","filter","map","_a","otherProps","__rest","React","createElement","ToastLink","key","href","styles","actionLink","shouldShowButtonTransition","undefined","toastButtons","index","content","ToastButton","Object","assign","concat","cx","actionButton","_defineProperty","withTransition","classNames","toast","getStyle","camelCase","handleClose","useCallback","timerAutoHide","setAutoHideTimer","duration","clearTimeout","current","setTimeout","useEffect","iconElement","getIcon","recalculateElementWidth","element","prevWidth","style","width","endWidth","getComputedStyle","CSSTransition","in","enterActive","exitActive","timeout","unmountOnExit","Text","getTestId","ComponentDefaultTestId","TOAST","color","role","Flex","align","gap","TOAST_CONTENT","textContent","Loader","size","IconButton","closeButton","onClick","kind","ariaLabel","TOAST_CLOSE_BUTTON","CloseSmall","hideTooltip","types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AAC+C,EACC,CAAAhE,GAAIA,EAAE,cACOG,GAAc8D,EAAUC,EAAuBC,MAAOnE,GACnEd,KAAK,QACLkE,QAAQ,MACRgB,MAAM,aACNrE,UAAWqC,EACXiC,KAAK,QAAO,YACF,SACVjE,IAAKA,GAEJ6C,IAAejC,EAAAC,cAAA,MAAA,CAAKlB,UAAWiC,EAAGX,EAAOlC,OAAQ8D,IAClDjC,EAAAC,cAACqD,EAAI,CAACC,MAAM,SAASC,IAAI,QAAQzE,UAAWsB,EAAOM,SACjDX,EAAAC,cAACqD,EACC,CAAAE,IAAI,uBACSP,EAAUC,EAAuBO,eAC9C1E,UAAWsB,EAAOqD,aAElB1D,EAAAC,cAAA,OAAA,KAAOxB,GACNgB,IAEDgB,GAAgBnC,KAAsBmC,GAAgBnC,GACvDR,GAAWkC,gBAAC2D,EAAM,CAACC,KAAK,QAE1BjF,GACCqB,EAACC,cAAA4D,GACC9E,UAAWiC,EAAGX,EAAOyD,aACrBC,QAASvC,GACToC,KAAK,QACLI,KAAK,WACLZ,MAAM,cACNa,UAAW/E,EACE,cAAA+D,EAAUC,EAAuBgB,oBAC9C/F,KAAMgG,EACNC,kBAMZ,GAOqF,CACnFC,MAAOC,EACPC,YAAaC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__rest as t}from"../../../../_virtual/_tslib.js";import s from"../../Button/Button.js";import a from"react";import{ComponentDefaultTestId as e}from"../../../tests/constants.js";import{getTestId as
|
|
1
|
+
import{__rest as t}from"../../../../_virtual/_tslib.js";import s from"../../Button/Button.js";import a from"react";import{ComponentDefaultTestId as e}from"../../../tests/constants.js";import{getTestId as i}from"../../../tests/testIds.js";var r=function(r){var o=r.className,m=r.id,d=r["data-testid"],n=t(r,["className","id","data-testid"]),c=Object.assign(Object.assign(Object.assign({},s.defaultProps),{kind:"secondary",marginLeft:!1}),n);return a.createElement(s,Object.assign({},c,{id:m,"data-testid":d||i(e.TOAST_BUTTON,m),className:o,size:"small",color:"fixed-light"}))};export{r as default};
|
|
2
2
|
//# sourceMappingURL=ToastButton.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToastButton.js","sources":["../../../../../src/components/Toast/ToastButton/ToastButton.tsx"],"sourcesContent":["import Button, { ButtonProps } from \"../../Button/Button\";\nimport React, { FC } from \"react\";\nimport { ComponentDefaultTestId } from \"../../../tests/constants\";\nimport { getTestId } from \"../../../tests/test-ids-utils\";\n\nexport type ToastButtonProps = ButtonProps;\n\nconst ToastButton: FC<ToastButtonProps> = ({\n className,\n id,\n \"data-testid\": dataTestId,\n ...buttonProps\n}: ToastButtonProps) => {\n return (\n <Button\n {...
|
|
1
|
+
{"version":3,"file":"ToastButton.js","sources":["../../../../../src/components/Toast/ToastButton/ToastButton.tsx"],"sourcesContent":["import Button, { ButtonProps } from \"../../Button/Button\";\nimport React, { FC } from \"react\";\nimport { ComponentDefaultTestId } from \"../../../tests/constants\";\nimport { getTestId } from \"../../../tests/test-ids-utils\";\nimport { ButtonType } from \"../../Button\";\n\nexport type ToastButtonProps = ButtonProps;\n\nconst ToastButton: FC<ToastButtonProps> = ({\n className,\n id,\n \"data-testid\": dataTestId,\n ...buttonProps\n}: ToastButtonProps) => {\n const overrideButtonProps = {\n ...Button.defaultProps,\n kind: \"secondary\" as ButtonType,\n marginLeft: false,\n ...buttonProps\n };\n\n return (\n <Button\n {...overrideButtonProps}\n id={id}\n data-testid={dataTestId || getTestId(ComponentDefaultTestId.TOAST_BUTTON, id)}\n className={className}\n size=\"small\"\n color=\"fixed-light\"\n />\n );\n};\n\nexport default ToastButton;\n"],"names":["ToastButton","_a","className","id","dataTestId","buttonProps","__rest","overrideButtonProps","Object","assign","Button","defaultProps","kind","marginLeft","React","createElement","getTestId","ComponentDefaultTestId","TOAST_BUTTON","size","color"],"mappings":"8OAQA,IAAMA,EAAoC,SAACC,GAAA,IACzCC,EAEyBD,EAFzBC,UACAC,EACyBF,EADzBE,GACeC,EAAUH,EAAzB,eACGI,EAJsCC,EAAAL,EAAA,CAAA,YAAA,KAAA,gBAMnCM,EACDC,OAAAC,OAAAD,OAAAC,OAAAD,OAAAC,OAAA,CAAA,EAAAC,EAAOC,eACVC,KAAM,YACNC,YAAY,IACTR,GAGL,OACES,EAAAC,cAACL,EAAMF,OAAAC,OAAA,CAAA,EACDF,EACJ,CAAAJ,GAAIA,gBACSC,GAAcY,EAAUC,EAAuBC,aAAcf,GAC1ED,UAAWA,EACXiB,KAAK,QACLC,MAAM,gBAGZ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibe/core",
|
|
3
|
-
"version": "3.53.1
|
|
3
|
+
"version": "3.53.1",
|
|
4
4
|
"description": "Official monday.com UI resources for application development in React.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
},
|
|
89
89
|
"dependencies": {
|
|
90
90
|
"@popperjs/core": "2.11.6",
|
|
91
|
-
"@vibe/icons": "1.
|
|
91
|
+
"@vibe/icons": "1.9.0",
|
|
92
92
|
"a11y-dialog": "^7.5.2",
|
|
93
93
|
"body-scroll-lock": "^4.0.0-beta.0",
|
|
94
94
|
"browserslist-config-monday": "1.0.6",
|
|
@@ -288,5 +288,5 @@
|
|
|
288
288
|
"gzip": true
|
|
289
289
|
}
|
|
290
290
|
],
|
|
291
|
-
"gitHead": "
|
|
291
|
+
"gitHead": "25d1384f53b489059eb1dc9710a3d964165efc42"
|
|
292
292
|
}
|