@chayns-components/core 5.0.0-beta.1195 → 5.0.0-beta.1196

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.
@@ -14,17 +14,18 @@ var _container = require("../../hooks/container");
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
15
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
16
  const DropdownBodyWrapper = ({
17
- direction = _dropdown.DropdownDirection.BOTTOM_RIGHT,
17
+ anchorElement,
18
+ bodyWidth,
18
19
  children,
19
20
  container: containerProp,
20
- shouldShowDropdown,
21
- anchorElement,
22
21
  contentHeight = 0,
22
+ direction = _dropdown.DropdownDirection.BOTTOM_RIGHT,
23
23
  maxHeight = 300,
24
+ minBodyWidth = 0,
24
25
  onClose,
26
+ onOutsideClick,
25
27
  onMeasure,
26
- minBodyWidth = 0,
27
- bodyWidth
28
+ shouldShowDropdown
28
29
  }) => {
29
30
  const isInChaynsWalletRef = (0, _react.useRef)(false);
30
31
  const [measuredContentHeight, setMeasuredContentHeight] = (0, _react.useState)(0);
@@ -58,11 +59,16 @@ const DropdownBodyWrapper = ({
58
59
  * This function closes the body
59
60
  */
60
61
  const handleClick = (0, _react.useCallback)(event => {
61
- if (!shouldPreventClickRef.current && !anchorElement.contains(event.target) && ref.current && !ref.current.contains(event.target)) {
62
- handleClose();
62
+ if (ref.current && shouldShowDropdown && !anchorElement.contains(event.target) && !ref.current.contains(event.target)) {
63
+ event.preventDefault();
64
+ event.stopPropagation();
65
+ const shouldPreventCloseOnClick = (onOutsideClick === null || onOutsideClick === void 0 ? void 0 : onOutsideClick()) ?? false;
66
+ if (!shouldPreventClickRef.current && !shouldPreventCloseOnClick) {
67
+ handleClose();
68
+ }
63
69
  }
64
70
  shouldPreventClickRef.current = false;
65
- }, [anchorElement, handleClose]);
71
+ }, [anchorElement, handleClose, onOutsideClick, shouldShowDropdown]);
66
72
  const handleContentMeasure = (0, _react.useCallback)(measurements => {
67
73
  // Measurements are only needed if the content is shown in the chayns wallet. To prevent
68
74
  // unnecessary renders, we only set the height if the content is shown in the wallet.
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownBodyWrapper.js","names":["_react","_interopRequireWildcard","require","_DropdownBodyWrapper","_reactDom","_dropdown","_DelayedDropdownContent","_interopRequireDefault","_dropdown2","_container","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","DropdownBodyWrapper","direction","DropdownDirection","BOTTOM_RIGHT","children","container","containerProp","shouldShowDropdown","anchorElement","contentHeight","maxHeight","onClose","onMeasure","minBodyWidth","bodyWidth","isInChaynsWalletRef","useRef","measuredContentHeight","setMeasuredContentHeight","useState","portal","setPortal","ref","shouldPreventClickRef","touchTimeoutRef","undefined","useContainer","transform","width","coordinates","useDropdown","handleClose","useCallback","handleClick","event","current","contains","target","handleContentMeasure","measurements","height","handleTouchEnd","clearTimeout","handleTouchStart","window","setTimeout","useDropdownListener","onClick","onTouchEnd","onTouchStart","useEffect","isBottomDirection","BOTTOM","BOTTOM_LEFT","includes","reservationWrapperElement","closest","ContainerAnchor","RESERVATION_WRAPPER","availableHeight","innerHeight","getBoundingClientRect","bottom","additionalNeededSpace","style","marginBottom","createPortal","createElement","shouldShowContent","StyledDropdownBodyWrapperContent","$width","$minWidth","$maxHeight","$direction","StyledDropdownBodyWrapper","displayName","_default","exports"],"sources":["../../../../src/components/dropdown-body-wrapper/DropdownBodyWrapper.tsx"],"sourcesContent":["import React, { FC, ReactNode, ReactPortal, useCallback, useEffect, useRef, useState } from 'react';\nimport {\n StyledDropdownBodyWrapper,\n StyledDropdownBodyWrapperContent,\n} from './DropdownBodyWrapper.styles';\nimport { createPortal } from 'react-dom';\nimport { DropdownDirection, DropdownMeasurements } from '../../types/dropdown';\nimport DelayedDropdownContent, {\n DelayedDropdownContentProps,\n} from './delayed-dropdown-content/DelayedDropdownContent';\nimport { useDropdown, useDropdownListener } from '../../hooks/dropdown';\nimport { ContainerAnchor, useContainer } from '../../hooks/container';\n\ninterface DropdownBodyWrapperProps {\n /**\n * The anchor element of the dropdown.\n */\n anchorElement: Element;\n /**\n * The width of the Body.\n */\n bodyWidth?: number;\n /**\n * The content of the dropdown body.\n */\n children: ReactNode;\n /**\n * The element where the content should be rendered via React Portal.\n */\n container?: Element;\n /**\n * The height of the content\n */\n contentHeight?: number;\n /**\n * The direction of the dropdown.\n */\n direction?: DropdownDirection;\n /**\n * The max height of the dropdown.\n */\n maxHeight?: number;\n /**\n * The minimum width of the body.\n */\n minBodyWidth?: number;\n /**\n * Function to be executed when the body is closed.\n */\n onClose?: VoidFunction;\n /**\n * Function to be executed when the content is measured.\n */\n onMeasure?: DelayedDropdownContentProps['onMeasure'];\n /**\n * Whether the dropdown should be visible.\n */\n shouldShowDropdown: boolean;\n}\n\nconst DropdownBodyWrapper: FC<DropdownBodyWrapperProps> = ({\n direction = DropdownDirection.BOTTOM_RIGHT,\n children,\n container: containerProp,\n shouldShowDropdown,\n anchorElement,\n contentHeight = 0,\n maxHeight = 300,\n onClose,\n onMeasure,\n minBodyWidth = 0,\n bodyWidth,\n}) => {\n const isInChaynsWalletRef = useRef(false);\n\n const [measuredContentHeight, setMeasuredContentHeight] = useState<number>(0);\n const [portal, setPortal] = useState<ReactPortal>();\n\n const ref = useRef<HTMLDivElement>(null);\n const shouldPreventClickRef = useRef<boolean>(false);\n const touchTimeoutRef = useRef<number | undefined>(undefined);\n\n const container = useContainer({ anchorElement, container: containerProp });\n\n const { transform, width, coordinates } = useDropdown({\n direction,\n bodyWidth,\n contentHeight,\n container,\n anchorElement,\n shouldShowDropdown,\n });\n\n const handleClose = useCallback(() => {\n if (typeof onClose === 'function') {\n onClose();\n }\n }, [onClose]);\n\n /**\n * This function closes the body\n */\n const handleClick = useCallback(\n (event: MouseEvent) => {\n if (\n !shouldPreventClickRef.current &&\n !anchorElement.contains(event.target as Node) &&\n ref.current &&\n !ref.current.contains(event.target as Node)\n ) {\n handleClose();\n }\n\n shouldPreventClickRef.current = false;\n },\n [anchorElement, handleClose],\n );\n\n const handleContentMeasure = useCallback(\n (measurements: DropdownMeasurements) => {\n // Measurements are only needed if the content is shown in the chayns wallet. To prevent\n // unnecessary renders, we only set the height if the content is shown in the wallet.\n if (isInChaynsWalletRef.current) {\n setMeasuredContentHeight(measurements.height);\n }\n\n if (typeof onMeasure === 'function') {\n onMeasure(measurements);\n }\n },\n [onMeasure],\n );\n\n const handleTouchEnd = useCallback(() => {\n clearTimeout(touchTimeoutRef.current);\n }, []);\n\n const handleTouchStart = useCallback(() => {\n touchTimeoutRef.current = window.setTimeout(() => {\n shouldPreventClickRef.current = true;\n }, 500);\n }, []);\n\n /**\n * This hook listens for clicks\n */\n useDropdownListener({\n onClick: handleClick,\n onClose: handleClose,\n onTouchEnd: handleTouchEnd,\n onTouchStart: handleTouchStart,\n });\n\n useEffect(() => {\n const isBottomDirection = [\n DropdownDirection.BOTTOM,\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.BOTTOM_RIGHT,\n ].includes(direction);\n\n const reservationWrapperElement = anchorElement.closest<HTMLDivElement>(\n ContainerAnchor.RESERVATION_WRAPPER,\n );\n\n isInChaynsWalletRef.current =\n !!(reservationWrapperElement && reservationWrapperElement.contains(anchorElement)) ||\n true;\n\n // This effect checks if additional space is needed to show dropdown content in chayns cards.\n if (\n isBottomDirection &&\n isInChaynsWalletRef.current &&\n measuredContentHeight > 0 &&\n reservationWrapperElement &&\n shouldShowDropdown\n ) {\n const availableHeight =\n window.innerHeight - anchorElement.getBoundingClientRect().bottom;\n\n // If the content height is greater than the available height, we need to add additional space.\n // This is to ensure that the dropdown content is fully visible. The 16 pixels are a buffer for shadows.\n const additionalNeededSpace = measuredContentHeight + 16 - availableHeight;\n\n if (additionalNeededSpace > 0) {\n // Add margin bottom to the reservation wrapper to ensure the dropdown content is fully visible.\n reservationWrapperElement.style.marginBottom = `${additionalNeededSpace}px`;\n } else {\n // Reset the margin bottom if no additional space is needed.\n reservationWrapperElement.style.marginBottom = '0px';\n }\n }\n\n if (isInChaynsWalletRef.current && reservationWrapperElement && !shouldShowDropdown) {\n // Reset the margin bottom when the dropdown is closed.\n reservationWrapperElement.style.marginBottom = '0px';\n }\n\n return () => {\n if (reservationWrapperElement) {\n reservationWrapperElement.style.marginBottom = '0px';\n }\n };\n }, [anchorElement, direction, measuredContentHeight, shouldShowDropdown]);\n\n useEffect(() => {\n if (!container) return;\n\n setPortal(() =>\n createPortal(\n <DelayedDropdownContent\n coordinates={coordinates}\n onMeasure={handleContentMeasure}\n shouldShowContent={shouldShowDropdown}\n transform={transform}\n >\n <StyledDropdownBodyWrapperContent\n $width={width}\n $minWidth={minBodyWidth}\n $maxHeight={maxHeight}\n $direction={direction}\n ref={ref}\n >\n {children}\n </StyledDropdownBodyWrapperContent>\n </DelayedDropdownContent>,\n container,\n ),\n );\n }, [\n children,\n container,\n coordinates,\n direction,\n handleContentMeasure,\n maxHeight,\n minBodyWidth,\n shouldShowDropdown,\n transform,\n width,\n ]);\n\n return <StyledDropdownBodyWrapper>{portal}</StyledDropdownBodyWrapper>;\n};\n\nDropdownBodyWrapper.displayName = 'DropdownBodyWrapper';\n\nexport default DropdownBodyWrapper;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAIA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,SAA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aAAA,CAAC1F,uBAAA,CAAAM,OAAsB;MACnB8C,WAAW,EAAEA,WAAY;MACzBjB,SAAS,EAAE0B,oBAAqB;MAChC8B,iBAAiB,EAAE7D,kBAAmB;MACtCoB,SAAS,EAAEA;IAAU,gBAErBxD,MAAA,CAAAY,OAAA,CAAAoF,aAAA,CAAC7F,oBAAA,CAAA+F,gCAAgC;MAC7BC,MAAM,EAAE1C,KAAM;MACd2C,SAAS,EAAE1D,YAAa;MACxB2D,UAAU,EAAE9D,SAAU;MACtB+D,UAAU,EAAExE,SAAU;MACtBqB,GAAG,EAAEA;IAAI,GAERlB,QAC6B,CACd,CAAC,EACzBC,SACJ,CACJ,CAAC;EACL,CAAC,EAAE,CACCD,QAAQ,EACRC,SAAS,EACTwB,WAAW,EACX5B,SAAS,EACTqC,oBAAoB,EACpB5B,SAAS,EACTG,YAAY,EACZN,kBAAkB,EAClBoB,SAAS,EACTC,KAAK,CACR,CAAC;EAEF,oBAAOzD,MAAA,CAAAY,OAAA,CAAAoF,aAAA,CAAC7F,oBAAA,CAAAoG,yBAAyB,QAAEtD,MAAkC,CAAC;AAC1E,CAAC;AAEDpB,mBAAmB,CAAC2E,WAAW,GAAG,qBAAqB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAA9F,OAAA,GAEzCiB,mBAAmB","ignoreList":[]}
1
+ {"version":3,"file":"DropdownBodyWrapper.js","names":["_react","_interopRequireWildcard","require","_DropdownBodyWrapper","_reactDom","_dropdown","_DelayedDropdownContent","_interopRequireDefault","_dropdown2","_container","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","DropdownBodyWrapper","anchorElement","bodyWidth","children","container","containerProp","contentHeight","direction","DropdownDirection","BOTTOM_RIGHT","maxHeight","minBodyWidth","onClose","onOutsideClick","onMeasure","shouldShowDropdown","isInChaynsWalletRef","useRef","measuredContentHeight","setMeasuredContentHeight","useState","portal","setPortal","ref","shouldPreventClickRef","touchTimeoutRef","undefined","useContainer","transform","width","coordinates","useDropdown","handleClose","useCallback","handleClick","event","current","contains","target","preventDefault","stopPropagation","shouldPreventCloseOnClick","handleContentMeasure","measurements","height","handleTouchEnd","clearTimeout","handleTouchStart","window","setTimeout","useDropdownListener","onClick","onTouchEnd","onTouchStart","useEffect","isBottomDirection","BOTTOM","BOTTOM_LEFT","includes","reservationWrapperElement","closest","ContainerAnchor","RESERVATION_WRAPPER","availableHeight","innerHeight","getBoundingClientRect","bottom","additionalNeededSpace","style","marginBottom","createPortal","createElement","shouldShowContent","StyledDropdownBodyWrapperContent","$width","$minWidth","$maxHeight","$direction","StyledDropdownBodyWrapper","displayName","_default","exports"],"sources":["../../../../src/components/dropdown-body-wrapper/DropdownBodyWrapper.tsx"],"sourcesContent":["import React, { FC, ReactNode, ReactPortal, useCallback, useEffect, useRef, useState } from 'react';\nimport {\n StyledDropdownBodyWrapper,\n StyledDropdownBodyWrapperContent,\n} from './DropdownBodyWrapper.styles';\nimport { createPortal } from 'react-dom';\nimport { DropdownDirection, DropdownMeasurements } from '../../types/dropdown';\nimport DelayedDropdownContent, {\n DelayedDropdownContentProps,\n} from './delayed-dropdown-content/DelayedDropdownContent';\nimport { useDropdown, useDropdownListener } from '../../hooks/dropdown';\nimport { ContainerAnchor, useContainer } from '../../hooks/container';\n\ninterface DropdownBodyWrapperProps {\n /**\n * The anchor element of the dropdown.\n */\n anchorElement: Element;\n /**\n * The width of the Body.\n */\n bodyWidth?: number;\n /**\n * The content of the dropdown body.\n */\n children: ReactNode;\n /**\n * The element where the content should be rendered via React Portal.\n */\n container?: Element;\n /**\n * The height of the content\n */\n contentHeight?: number;\n /**\n * The direction of the dropdown.\n */\n direction?: DropdownDirection;\n /**\n * The max height of the dropdown.\n */\n maxHeight?: number;\n /**\n * The minimum width of the body.\n */\n minBodyWidth?: number;\n /**\n * Function to be executed when the body is closed.\n */\n onClose?: VoidFunction;\n /**\n * Function to be executed when the user clicks outside the dropdown.\n * If the function returns `true`, the dropdown will not be closed.\n */\n onOutsideClick?: () => boolean | void;\n /**\n * Function to be executed when the content is measured.\n */\n onMeasure?: DelayedDropdownContentProps['onMeasure'];\n /**\n * Whether the dropdown should be visible.\n */\n shouldShowDropdown: boolean;\n}\n\nconst DropdownBodyWrapper: FC<DropdownBodyWrapperProps> = ({\n anchorElement,\n bodyWidth,\n children,\n container: containerProp,\n contentHeight = 0,\n direction = DropdownDirection.BOTTOM_RIGHT,\n maxHeight = 300,\n minBodyWidth = 0,\n onClose,\n onOutsideClick,\n onMeasure,\n shouldShowDropdown,\n}) => {\n const isInChaynsWalletRef = useRef(false);\n\n const [measuredContentHeight, setMeasuredContentHeight] = useState<number>(0);\n const [portal, setPortal] = useState<ReactPortal>();\n\n const ref = useRef<HTMLDivElement>(null);\n const shouldPreventClickRef = useRef<boolean>(false);\n const touchTimeoutRef = useRef<number | undefined>(undefined);\n\n const container = useContainer({ anchorElement, container: containerProp });\n\n const { transform, width, coordinates } = useDropdown({\n direction,\n bodyWidth,\n contentHeight,\n container,\n anchorElement,\n shouldShowDropdown,\n });\n\n const handleClose = useCallback(() => {\n if (typeof onClose === 'function') {\n onClose();\n }\n }, [onClose]);\n\n /**\n * This function closes the body\n */\n const handleClick = useCallback(\n (event: MouseEvent) => {\n if (\n ref.current &&\n shouldShowDropdown &&\n !anchorElement.contains(event.target as Node) &&\n !ref.current.contains(event.target as Node)\n ) {\n event.preventDefault();\n event.stopPropagation();\n\n const shouldPreventCloseOnClick = onOutsideClick?.() ?? false;\n\n if (!shouldPreventClickRef.current && !shouldPreventCloseOnClick) {\n handleClose();\n }\n }\n\n shouldPreventClickRef.current = false;\n },\n [anchorElement, handleClose, onOutsideClick, shouldShowDropdown],\n );\n\n const handleContentMeasure = useCallback(\n (measurements: DropdownMeasurements) => {\n // Measurements are only needed if the content is shown in the chayns wallet. To prevent\n // unnecessary renders, we only set the height if the content is shown in the wallet.\n if (isInChaynsWalletRef.current) {\n setMeasuredContentHeight(measurements.height);\n }\n\n if (typeof onMeasure === 'function') {\n onMeasure(measurements);\n }\n },\n [onMeasure],\n );\n\n const handleTouchEnd = useCallback(() => {\n clearTimeout(touchTimeoutRef.current);\n }, []);\n\n const handleTouchStart = useCallback(() => {\n touchTimeoutRef.current = window.setTimeout(() => {\n shouldPreventClickRef.current = true;\n }, 500);\n }, []);\n\n /**\n * This hook listens for clicks\n */\n useDropdownListener({\n onClick: handleClick,\n onClose: handleClose,\n onTouchEnd: handleTouchEnd,\n onTouchStart: handleTouchStart,\n });\n\n useEffect(() => {\n const isBottomDirection = [\n DropdownDirection.BOTTOM,\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.BOTTOM_RIGHT,\n ].includes(direction);\n\n const reservationWrapperElement = anchorElement.closest<HTMLDivElement>(\n ContainerAnchor.RESERVATION_WRAPPER,\n );\n\n isInChaynsWalletRef.current =\n !!(reservationWrapperElement && reservationWrapperElement.contains(anchorElement)) ||\n true;\n\n // This effect checks if additional space is needed to show dropdown content in chayns cards.\n if (\n isBottomDirection &&\n isInChaynsWalletRef.current &&\n measuredContentHeight > 0 &&\n reservationWrapperElement &&\n shouldShowDropdown\n ) {\n const availableHeight =\n window.innerHeight - anchorElement.getBoundingClientRect().bottom;\n\n // If the content height is greater than the available height, we need to add additional space.\n // This is to ensure that the dropdown content is fully visible. The 16 pixels are a buffer for shadows.\n const additionalNeededSpace = measuredContentHeight + 16 - availableHeight;\n\n if (additionalNeededSpace > 0) {\n // Add margin bottom to the reservation wrapper to ensure the dropdown content is fully visible.\n reservationWrapperElement.style.marginBottom = `${additionalNeededSpace}px`;\n } else {\n // Reset the margin bottom if no additional space is needed.\n reservationWrapperElement.style.marginBottom = '0px';\n }\n }\n\n if (isInChaynsWalletRef.current && reservationWrapperElement && !shouldShowDropdown) {\n // Reset the margin bottom when the dropdown is closed.\n reservationWrapperElement.style.marginBottom = '0px';\n }\n\n return () => {\n if (reservationWrapperElement) {\n reservationWrapperElement.style.marginBottom = '0px';\n }\n };\n }, [anchorElement, direction, measuredContentHeight, shouldShowDropdown]);\n\n useEffect(() => {\n if (!container) return;\n\n setPortal(() =>\n createPortal(\n <DelayedDropdownContent\n coordinates={coordinates}\n onMeasure={handleContentMeasure}\n shouldShowContent={shouldShowDropdown}\n transform={transform}\n >\n <StyledDropdownBodyWrapperContent\n $width={width}\n $minWidth={minBodyWidth}\n $maxHeight={maxHeight}\n $direction={direction}\n ref={ref}\n >\n {children}\n </StyledDropdownBodyWrapperContent>\n </DelayedDropdownContent>,\n container,\n ),\n );\n }, [\n children,\n container,\n coordinates,\n direction,\n handleContentMeasure,\n maxHeight,\n minBodyWidth,\n shouldShowDropdown,\n transform,\n width,\n ]);\n\n return <StyledDropdownBodyWrapper>{portal}</StyledDropdownBodyWrapper>;\n};\n\nDropdownBodyWrapper.displayName = 'DropdownBodyWrapper';\n\nexport default DropdownBodyWrapper;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,oBAAA,GAAAD,OAAA;AAIA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,uBAAA,GAAAC,sBAAA,CAAAL,OAAA;AAGA,IAAAM,UAAA,GAAAN,OAAA;AACA,IAAAO,UAAA,GAAAP,OAAA;AAAsE,SAAAK,uBAAAG,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAb,uBAAA,YAAAA,CAAAS,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAAC,UAAA,SAAAD,CAAA,MAAAO,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAR,OAAA,EAAAF,CAAA,iBAAAA,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;MACxBiE,UAAU,EAAElE,SAAU;MACtBmE,UAAU,EAAEtE,SAAU;MACtBgB,GAAG,EAAEA;IAAI,GAERpB,QAC6B,CACd,CAAC,EACzBC,SACJ,CACJ,CAAC;EACL,CAAC,EAAE,CACCD,QAAQ,EACRC,SAAS,EACT0B,WAAW,EACXvB,SAAS,EACTmC,oBAAoB,EACpBhC,SAAS,EACTC,YAAY,EACZI,kBAAkB,EAClBa,SAAS,EACTC,KAAK,CACR,CAAC;EAEF,oBAAO1D,MAAA,CAAAY,OAAA,CAAAwF,aAAA,CAACjG,oBAAA,CAAAwG,yBAAyB,QAAEzD,MAAkC,CAAC;AAC1E,CAAC;AAEDrB,mBAAmB,CAAC+E,WAAW,GAAG,qBAAqB;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAlG,OAAA,GAEzCiB,mBAAmB","ignoreList":[]}
@@ -14,19 +14,22 @@ var _AreaContextProvider = require("../area-provider/AreaContextProvider");
14
14
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
15
15
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
16
16
  const TagInput = /*#__PURE__*/(0, _react.forwardRef)(({
17
- placeholder,
18
- tags,
19
- onRemove,
20
- onChange,
21
- onAdd,
22
17
  leftElement,
18
+ onAdd,
19
+ onBlur,
20
+ onChange,
21
+ onFocus,
22
+ onRemove,
23
+ placeholder,
23
24
  shouldAllowMultiple = true,
24
- shouldPreventEnter
25
+ shouldPreventEnter,
26
+ tags
25
27
  }, ref) => {
26
28
  const [internalTags, setInternalTags] = (0, _react.useState)();
27
29
  const [currentValue, setCurrentValue] = (0, _react.useState)('');
28
30
  const [selectedId, setSelectedId] = (0, _react.useState)();
29
31
  const areaProvider = (0, _react.useContext)(_AreaContextProvider.AreaContext);
32
+ const inputRef = (0, _react.useRef)(null);
30
33
  const theme = (0, _styledComponents.useTheme)();
31
34
  (0, _react.useEffect)(() => {
32
35
  if (tags) {
@@ -38,6 +41,10 @@ const TagInput = /*#__PURE__*/(0, _react.forwardRef)(({
38
41
  };
39
42
  const shouldChangeColor = (0, _react.useMemo)(() => areaProvider.shouldChangeColor ?? false, [areaProvider.shouldChangeColor]);
40
43
  (0, _react.useImperativeHandle)(ref, () => ({
44
+ blur: () => {
45
+ var _inputRef$current;
46
+ return (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.blur();
47
+ },
41
48
  getUnsavedTagText: currentValue !== '' ? currentValue : undefined,
42
49
  resetValue: handleResetValue
43
50
  }), [currentValue]);
@@ -135,11 +142,14 @@ const TagInput = /*#__PURE__*/(0, _react.forwardRef)(({
135
142
  return (0, _react.useMemo)(() => /*#__PURE__*/_react.default.createElement(_TagInput.StyledTagInput, {
136
143
  $shouldChangeColor: shouldChangeColor
137
144
  }, leftElement && /*#__PURE__*/_react.default.createElement(_TagInput.StyledTagInputIconWrapper, null, leftElement), content, shouldShowInput && /*#__PURE__*/_react.default.createElement(_TagInput.StyledTagInputTagInput, {
138
- placeholder: tags && tags.length > 0 ? undefined : placeholder,
139
- onKeyDown: handleKeyDown,
145
+ onBlur: onBlur,
140
146
  onChange: handleChange,
147
+ onFocus: onFocus,
148
+ onKeyDown: handleKeyDown,
149
+ placeholder: tags && tags.length > 0 ? undefined : placeholder,
150
+ ref: inputRef,
141
151
  value: currentValue
142
- })), [content, currentValue, handleChange, handleKeyDown, leftElement, placeholder, shouldChangeColor, shouldShowInput, tags]);
152
+ })), [content, currentValue, handleChange, handleKeyDown, leftElement, onBlur, onFocus, placeholder, shouldChangeColor, shouldShowInput, tags]);
143
153
  });
144
154
  var _default = exports.default = TagInput;
145
155
  //# sourceMappingURL=TagInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TagInput.js","names":["_react","_interopRequireWildcard","require","_styledComponents","_uuid","_Badge","_interopRequireDefault","_Icon","_TagInput","_AreaContextProvider","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TagInput","forwardRef","placeholder","tags","onRemove","onChange","onAdd","leftElement","shouldAllowMultiple","shouldPreventEnter","ref","internalTags","setInternalTags","useState","currentValue","setCurrentValue","selectedId","setSelectedId","areaProvider","useContext","AreaContext","theme","useTheme","useEffect","slice","handleResetValue","shouldChangeColor","useMemo","useImperativeHandle","getUnsavedTagText","undefined","resetValue","handleKeyDown","useCallback","event","key","prevValue","prevTags","length","newTag","id","uuidv4","text","_internalTags","newSelectedId","prevState","_prevState","removedId","updatedTags","filter","tag","handleChange","target","value","handleIconClick","content","items","forEach","rightElement","push","createElement","backgroundColor","StyledTagInputTagWrapper","StyledTagInputTagWrapperText","icons","onClick","preventDefault","stopPropagation","shouldShowInput","StyledTagInput","$shouldChangeColor","StyledTagInputIconWrapper","StyledTagInputTagInput","onKeyDown","_default","exports"],"sources":["../../../../src/components/tag-input/TagInput.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useState,\n type ChangeEvent,\n type KeyboardEvent,\n type ReactElement,\n useImperativeHandle,\n useContext,\n ChangeEventHandler,\n ReactNode,\n} from 'react';\nimport { useTheme } from 'styled-components';\nimport { v4 as uuidv4 } from 'uuid';\nimport type { Tag } from '../../types/tagInput';\nimport Badge from '../badge/Badge';\nimport Icon from '../icon/Icon';\nimport {\n StyledTagInput,\n StyledTagInputIconWrapper,\n StyledTagInputTagInput,\n StyledTagInputTagWrapper,\n StyledTagInputTagWrapperText,\n} from './TagInput.styles';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport type { Theme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport type TagInputProps = {\n /**\n * An element that should be displayed on the left side of the input.\n */\n leftElement?: ReactNode;\n /**\n * Function to be executed when a tag is added.\n */\n onAdd?: (tag: Tag) => void;\n /**\n * Function to be executed when the value of the input is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when a tag is removed.\n */\n onRemove?: (id: string) => void;\n /**\n * The placeholder that should be displayed.\n */\n placeholder?: string;\n /**\n * The tags that should be displayed.\n */\n tags?: Tag[];\n /**\n * Whether multiple tags should be allowed.\n */\n shouldAllowMultiple?: boolean;\n /**\n * Whether the enter key should be prevented.\n */\n shouldPreventEnter?: boolean;\n};\n\nexport type TagInputRef = {\n getUnsavedTagText: Tag['text'] | undefined;\n resetValue: () => void;\n};\n\nconst TagInput = forwardRef<TagInputRef, TagInputProps>(\n (\n {\n placeholder,\n tags,\n onRemove,\n onChange,\n onAdd,\n leftElement,\n shouldAllowMultiple = true,\n shouldPreventEnter,\n },\n ref,\n ) => {\n const [internalTags, setInternalTags] = useState<Tag[]>();\n const [currentValue, setCurrentValue] = useState('');\n const [selectedId, setSelectedId] = useState<Tag['id']>();\n\n const areaProvider = useContext(AreaContext);\n\n const theme = useTheme() as Theme;\n\n useEffect(() => {\n if (tags) {\n setInternalTags(shouldAllowMultiple ? tags : tags.slice(0, 1));\n }\n }, [shouldAllowMultiple, tags]);\n\n const handleResetValue = () => {\n setCurrentValue('');\n };\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n getUnsavedTagText: currentValue !== '' ? currentValue : undefined,\n resetValue: handleResetValue,\n }),\n [currentValue],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent) => {\n if (event.key === 'Enter' && !shouldPreventEnter) {\n setCurrentValue((prevValue) => {\n if (!prevValue) {\n return '';\n }\n\n setInternalTags((prevTags) => {\n if (!shouldAllowMultiple && (prevTags?.length ?? 0) > 0)\n return prevTags;\n\n const newTag = { id: uuidv4(), text: prevValue };\n\n if (typeof onAdd === 'function') {\n onAdd(newTag);\n }\n\n return prevTags ? [...prevTags, newTag] : [newTag];\n });\n\n return '';\n });\n }\n\n if (event.key === 'Backspace' && currentValue === '') {\n if (!selectedId) {\n if (!internalTags) {\n return;\n }\n\n const newSelectedId = internalTags[internalTags.length - 1]?.id;\n\n setSelectedId(newSelectedId);\n\n return;\n }\n\n setInternalTags((prevState) => {\n if (!prevState) {\n return prevState;\n }\n\n const removedId = prevState[prevState.length - 1]?.id;\n\n if (!removedId) {\n return prevState;\n }\n\n const updatedTags = (prevState ?? []).filter((tag) => tag.id !== removedId);\n\n if (typeof onRemove === 'function') {\n onRemove(removedId);\n }\n\n setSelectedId(undefined);\n\n return updatedTags;\n });\n }\n },\n [\n currentValue,\n internalTags,\n onAdd,\n onRemove,\n selectedId,\n shouldAllowMultiple,\n shouldPreventEnter,\n ],\n );\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setCurrentValue(event.target.value);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n\n if (event.target.value !== '') {\n setSelectedId(undefined);\n }\n },\n [onChange],\n );\n\n const handleIconClick = useCallback(\n (id: string) => {\n setInternalTags((prevState) => {\n const updatedTags = (prevState ?? []).filter((tag) => tag.id !== id);\n\n if (typeof onRemove === 'function') {\n onRemove(id);\n }\n\n return updatedTags;\n });\n },\n [onRemove],\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n if (!internalTags) {\n return items;\n }\n\n internalTags.forEach(({ text, id, rightElement }) => {\n items.push(\n <Badge\n key={`tag-input-${id}`}\n backgroundColor={\n id === selectedId ? ((theme['206'] as string) ?? undefined) : undefined\n }\n >\n <StyledTagInputTagWrapper>\n <StyledTagInputTagWrapperText>{text}</StyledTagInputTagWrapperText>\n {rightElement}\n <Icon\n icons={['ts-wrong']}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n\n handleIconClick(id);\n }}\n />\n </StyledTagInputTagWrapper>\n </Badge>,\n );\n });\n\n return items;\n }, [handleIconClick, internalTags, selectedId, theme]);\n\n const shouldShowInput = useMemo(\n () => shouldAllowMultiple || (internalTags?.length ?? 0) < 1,\n [internalTags?.length, shouldAllowMultiple],\n );\n\n return useMemo(\n () => (\n <StyledTagInput $shouldChangeColor={shouldChangeColor}>\n {leftElement && (\n <StyledTagInputIconWrapper>{leftElement}</StyledTagInputIconWrapper>\n )}\n {content}\n {shouldShowInput && (\n <StyledTagInputTagInput\n placeholder={tags && tags.length > 0 ? undefined : placeholder}\n onKeyDown={handleKeyDown}\n onChange={handleChange}\n value={currentValue}\n />\n )}\n </StyledTagInput>\n ),\n [\n content,\n currentValue,\n handleChange,\n handleKeyDown,\n leftElement,\n placeholder,\n shouldChangeColor,\n shouldShowInput,\n tags,\n ],\n );\n },\n);\n\nexport default TagInput;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAcA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AAEA,IAAAG,MAAA,GAAAC,sBAAA,CAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAD,sBAAA,CAAAJ,OAAA;AACA,IAAAM,SAAA,GAAAN,OAAA;AAOA,IAAAO,oBAAA,GAAAP,OAAA;AAAmE,SAAAI,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,SAAAT,wBAAAS,CAAA,EAAAG,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAb,uBAAA,YAAAA,CAAAS,CAAA,EAAAG,CAAA,SAAAA,CAAA,IAAAH,CAAA,IAAAA,CAAA,CAAA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,CAAC,GAAGR,SAAS,GAAG5B,WAAY;IAC/DuE,SAAS,EAAEzC,aAAc;IACzB3B,QAAQ,EAAE8C,YAAa;IACvBE,KAAK,EAAEvC;EAAa,CACvB,CAEO,CACnB,EACD,CACIyC,OAAO,EACPzC,YAAY,EACZqC,YAAY,EACZnB,aAAa,EACbzB,WAAW,EACXL,WAAW,EACXwB,iBAAiB,EACjB0C,eAAe,EACfjE,IAAI,CAEZ,CAAC;AACL,CACJ,CAAC;AAAC,IAAAuE,QAAA,GAAAC,OAAA,CAAA5F,OAAA,GAEaiB,QAAQ","ignoreList":[]}
1
+ {"version":3,"file":"TagInput.js","names":["_react","_interopRequireWildcard","require","_styledComponents","_uuid","_Badge","_interopRequireDefault","_Icon","_TagInput","_AreaContextProvider","e","__esModule","default","t","WeakMap","r","n","o","i","f","__proto__","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","TagInput","forwardRef","leftElement","onAdd","onBlur","onChange","onFocus","onRemove","placeholder","shouldAllowMultiple","shouldPreventEnter","tags","ref","internalTags","setInternalTags","useState","currentValue","setCurrentValue","selectedId","setSelectedId","areaProvider","useContext","AreaContext","inputRef","useRef","theme","useTheme","useEffect","slice","handleResetValue","shouldChangeColor","useMemo","useImperativeHandle","blur","_inputRef$current","current","getUnsavedTagText","undefined","resetValue","handleKeyDown","useCallback","event","key","prevValue","prevTags","length","newTag","id","uuidv4","text","_internalTags","newSelectedId","prevState","_prevState","removedId","updatedTags","filter","tag","handleChange","target","value","handleIconClick","content","items","forEach","rightElement","push","createElement","backgroundColor","StyledTagInputTagWrapper","StyledTagInputTagWrapperText","icons","onClick","preventDefault","stopPropagation","shouldShowInput","StyledTagInput","$shouldChangeColor","StyledTagInputIconWrapper","StyledTagInputTagInput","onKeyDown","_default","exports"],"sources":["../../../../src/components/tag-input/TagInput.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useState,\n type ChangeEvent,\n type KeyboardEvent,\n type ReactElement,\n useImperativeHandle,\n useContext,\n ChangeEventHandler,\n ReactNode,\n FocusEventHandler,\n useRef,\n} from 'react';\nimport { useTheme } from 'styled-components';\nimport { v4 as uuidv4 } from 'uuid';\nimport type { Tag } from '../../types/tagInput';\nimport Badge from '../badge/Badge';\nimport Icon from '../icon/Icon';\nimport {\n StyledTagInput,\n StyledTagInputIconWrapper,\n StyledTagInputTagInput,\n StyledTagInputTagWrapper,\n StyledTagInputTagWrapperText,\n} from './TagInput.styles';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport type { Theme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport type TagInputProps = {\n /**\n * An element that should be displayed on the left side of the input.\n */\n leftElement?: ReactNode;\n /**\n * Function to be executed when a tag is added.\n */\n onAdd?: (tag: Tag) => void;\n /**\n * Function to be executed when the input is blurred.\n */\n onBlur?: FocusEventHandler;\n /**\n * Function to be executed when the value of the input is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when the input is focused.\n */\n onFocus?: FocusEventHandler;\n /**\n * Function to be executed when a tag is removed.\n */\n onRemove?: (id: string) => void;\n /**\n * The placeholder that should be displayed.\n */\n placeholder?: string;\n /**\n * Whether multiple tags should be allowed.\n */\n shouldAllowMultiple?: boolean;\n /**\n * Whether the enter key should be prevented.\n */\n shouldPreventEnter?: boolean;\n /**\n * The tags that should be displayed.\n */\n tags?: Tag[];\n};\n\nexport type TagInputRef = {\n blur: () => void;\n getUnsavedTagText: Tag['text'] | undefined;\n resetValue: () => void;\n};\n\nconst TagInput = forwardRef<TagInputRef, TagInputProps>(\n (\n {\n leftElement,\n onAdd,\n onBlur,\n onChange,\n onFocus,\n onRemove,\n placeholder,\n shouldAllowMultiple = true,\n shouldPreventEnter,\n tags,\n },\n ref,\n ) => {\n const [internalTags, setInternalTags] = useState<Tag[]>();\n const [currentValue, setCurrentValue] = useState('');\n const [selectedId, setSelectedId] = useState<Tag['id']>();\n\n const areaProvider = useContext(AreaContext);\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n const theme = useTheme() as Theme;\n\n useEffect(() => {\n if (tags) {\n setInternalTags(shouldAllowMultiple ? tags : tags.slice(0, 1));\n }\n }, [shouldAllowMultiple, tags]);\n\n const handleResetValue = () => {\n setCurrentValue('');\n };\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n blur: () => inputRef.current?.blur(),\n getUnsavedTagText: currentValue !== '' ? currentValue : undefined,\n resetValue: handleResetValue,\n }),\n [currentValue],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent) => {\n if (event.key === 'Enter' && !shouldPreventEnter) {\n setCurrentValue((prevValue) => {\n if (!prevValue) {\n return '';\n }\n\n setInternalTags((prevTags) => {\n if (!shouldAllowMultiple && (prevTags?.length ?? 0) > 0)\n return prevTags;\n\n const newTag = { id: uuidv4(), text: prevValue };\n\n if (typeof onAdd === 'function') {\n onAdd(newTag);\n }\n\n return prevTags ? [...prevTags, newTag] : [newTag];\n });\n\n return '';\n });\n }\n\n if (event.key === 'Backspace' && currentValue === '') {\n if (!selectedId) {\n if (!internalTags) {\n return;\n }\n\n const newSelectedId = internalTags[internalTags.length - 1]?.id;\n\n setSelectedId(newSelectedId);\n\n return;\n }\n\n setInternalTags((prevState) => {\n if (!prevState) {\n return prevState;\n }\n\n const removedId = prevState[prevState.length - 1]?.id;\n\n if (!removedId) {\n return prevState;\n }\n\n const updatedTags = (prevState ?? []).filter((tag) => tag.id !== removedId);\n\n if (typeof onRemove === 'function') {\n onRemove(removedId);\n }\n\n setSelectedId(undefined);\n\n return updatedTags;\n });\n }\n },\n [\n currentValue,\n internalTags,\n onAdd,\n onRemove,\n selectedId,\n shouldAllowMultiple,\n shouldPreventEnter,\n ],\n );\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setCurrentValue(event.target.value);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n\n if (event.target.value !== '') {\n setSelectedId(undefined);\n }\n },\n [onChange],\n );\n\n const handleIconClick = useCallback(\n (id: string) => {\n setInternalTags((prevState) => {\n const updatedTags = (prevState ?? []).filter((tag) => tag.id !== id);\n\n if (typeof onRemove === 'function') {\n onRemove(id);\n }\n\n return updatedTags;\n });\n },\n [onRemove],\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n if (!internalTags) {\n return items;\n }\n\n internalTags.forEach(({ text, id, rightElement }) => {\n items.push(\n <Badge\n key={`tag-input-${id}`}\n backgroundColor={\n id === selectedId ? ((theme['206'] as string) ?? undefined) : undefined\n }\n >\n <StyledTagInputTagWrapper>\n <StyledTagInputTagWrapperText>{text}</StyledTagInputTagWrapperText>\n {rightElement}\n <Icon\n icons={['ts-wrong']}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n\n handleIconClick(id);\n }}\n />\n </StyledTagInputTagWrapper>\n </Badge>,\n );\n });\n\n return items;\n }, [handleIconClick, internalTags, selectedId, theme]);\n\n const shouldShowInput = useMemo(\n () => shouldAllowMultiple || (internalTags?.length ?? 0) < 1,\n [internalTags?.length, shouldAllowMultiple],\n );\n\n return useMemo(\n () => (\n <StyledTagInput $shouldChangeColor={shouldChangeColor}>\n {leftElement && (\n <StyledTagInputIconWrapper>{leftElement}</StyledTagInputIconWrapper>\n )}\n {content}\n {shouldShowInput && (\n <StyledTagInputTagInput\n onBlur={onBlur}\n onChange={handleChange}\n onFocus={onFocus}\n onKeyDown={handleKeyDown}\n placeholder={tags && tags.length > 0 ? undefined : placeholder}\n ref={inputRef}\n value={currentValue}\n />\n )}\n </StyledTagInput>\n ),\n [\n content,\n currentValue,\n handleChange,\n handleKeyDown,\n leftElement,\n onBlur,\n onFocus,\n placeholder,\n shouldChangeColor,\n shouldShowInput,\n tags,\n ],\n );\n },\n);\n\nexport default TagInput;\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CA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A,GAEaiB,QAAQ","ignoreList":[]}
@@ -14,15 +14,15 @@ const useDropdownListener = ({
14
14
  onTouchStart
15
15
  }) => {
16
16
  (0, _react.useEffect)(() => {
17
- document.addEventListener('click', onClick);
18
- document.addEventListener('touchend', onTouchEnd);
19
- document.addEventListener('touchstart', onTouchStart);
20
- window.addEventListener('blur', () => onClose());
17
+ document.addEventListener('click', onClick, true);
18
+ document.addEventListener('touchend', onTouchEnd, true);
19
+ document.addEventListener('touchstart', onTouchStart, true);
20
+ window.addEventListener('blur', () => onClose(), true);
21
21
  return () => {
22
- document.removeEventListener('click', onClick);
23
- document.removeEventListener('touchend', onTouchEnd);
24
- document.removeEventListener('touchstart', onTouchStart);
25
- window.addEventListener('blur', () => onClose());
22
+ document.removeEventListener('click', onClick, true);
23
+ document.removeEventListener('touchend', onTouchEnd, true);
24
+ document.removeEventListener('touchstart', onTouchStart, true);
25
+ window.addEventListener('blur', () => onClose(), true);
26
26
  };
27
27
  }, [onClick, onClose, onTouchEnd, onTouchStart]);
28
28
  };
@@ -1 +1 @@
1
- {"version":3,"file":"dropdown.js","names":["_react","require","_dropdown","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useDropdownListener","onClick","onClose","onTouchEnd","onTouchStart","document","addEventListener","removeEventListener","exports","useDropdownAlignment","direction","shouldUseTopAlignment","anchorElement","bodyWidth","translateX","setTranslateX","useState","translateY","setTranslateY","DropdownDirection","BOTTOM_LEFT","TOP_LEFT","LEFT","includes","difference","clientWidth","useTopAlignment","TOP","TOP_RIGHT","useMemo","x","y","useDropdownPosition","container","contentHeight","shouldShowDropdown","coordinates","setCoordinates","setShouldUseTopAlignment","calculateCoordinates","useCallback","left","anchorLeft","top","anchorTop","height","anchorHeight","getBoundingClientRect","scrollLeft","scrollTop","hasBottomAlignment","BOTTOM","BOTTOM_RIGHT","handleResize","setTimeout","useDropdown","transform","width"],"sources":["../../../src/hooks/dropdown.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';\nimport { DropdownCoordinates, DropdownDirection } from '../types/dropdown';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\ninterface UseDropdownListenerOptions {\n onClick: (event: MouseEvent) => void;\n onClose: () => void;\n onTouchEnd: (event: TouchEvent) => void;\n onTouchStart: (event: TouchEvent) => void;\n}\n\nexport const useDropdownListener = ({\n onClick,\n onClose,\n onTouchEnd,\n onTouchStart,\n}: UseDropdownListenerOptions) => {\n useEffect(() => {\n document.addEventListener('click', onClick);\n document.addEventListener('touchend', onTouchEnd);\n document.addEventListener('touchstart', onTouchStart);\n\n window.addEventListener('blur', () => onClose());\n\n return () => {\n document.removeEventListener('click', onClick);\n document.removeEventListener('touchend', onTouchEnd);\n document.removeEventListener('touchstart', onTouchStart);\n\n window.addEventListener('blur', () => onClose());\n };\n }, [onClick, onClose, onTouchEnd, onTouchStart]);\n};\n\ninterface UseDropdownAlignmentOptions {\n direction: DropdownDirection;\n shouldUseTopAlignment: boolean;\n bodyWidth?: number;\n anchorElement: Element;\n}\n\nexport const useDropdownAlignment = ({\n direction,\n shouldUseTopAlignment,\n anchorElement,\n bodyWidth,\n}: UseDropdownAlignmentOptions) => {\n const [translateX, setTranslateX] = useState<string>('0px');\n const [translateY, setTranslateY] = useState<string>('0px');\n\n useEffect(() => {\n if (\n [\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.LEFT,\n ].includes(direction) &&\n typeof bodyWidth === 'number'\n ) {\n const difference = anchorElement.clientWidth - bodyWidth;\n\n setTranslateX(`${difference}px`);\n } else {\n setTranslateX('0px');\n }\n }, [anchorElement.clientWidth, bodyWidth, direction]);\n\n useEffect(() => {\n const useTopAlignment =\n shouldUseTopAlignment ||\n [\n DropdownDirection.TOP,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.TOP_RIGHT,\n ].includes(direction);\n\n if (useTopAlignment) {\n setTranslateY('-100%');\n } else {\n setTranslateY('0px');\n }\n }, [direction, shouldUseTopAlignment]);\n\n return useMemo(() => ({ x: translateX, y: translateY }), [translateX, translateY]);\n};\n\ninterface UseDropdownPositionOptions {\n anchorElement: Element;\n container?: Element;\n contentHeight?: number;\n direction: DropdownDirection;\n shouldShowDropdown: boolean;\n}\n\nexport const useDropdownPosition = ({\n anchorElement,\n container,\n contentHeight = 0,\n direction,\n shouldShowDropdown,\n}: UseDropdownPositionOptions) => {\n const [coordinates, setCoordinates] = useState<DropdownCoordinates>({ x: 0, y: 0 });\n const [shouldUseTopAlignment, setShouldUseTopAlignment] = useState(false);\n\n const calculateCoordinates = useCallback(() => {\n if (container) {\n const {\n left: anchorLeft,\n top: anchorTop,\n height: anchorHeight,\n } = anchorElement.getBoundingClientRect();\n\n const { left, top, height } = container.getBoundingClientRect();\n\n const x = anchorLeft - left + container.scrollLeft;\n const y = anchorTop - top + container.scrollTop;\n\n let useTopAlignment = [\n DropdownDirection.TOP,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.TOP_RIGHT,\n ].includes(direction);\n\n const hasBottomAlignment = [\n DropdownDirection.BOTTOM,\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.BOTTOM_RIGHT,\n ].includes(direction);\n\n if (!hasBottomAlignment && y + anchorHeight + contentHeight > height) {\n useTopAlignment = true;\n\n setShouldUseTopAlignment(true);\n } else {\n setShouldUseTopAlignment(false);\n }\n\n setCoordinates({ x, y: useTopAlignment ? y : y + anchorHeight });\n }\n }, [anchorElement, container, contentHeight, direction]);\n\n useIsomorphicLayoutEffect(() => {\n const handleResize = () => {\n calculateCoordinates();\n\n setTimeout(calculateCoordinates, 300);\n };\n\n handleResize();\n\n if (shouldShowDropdown) {\n window.addEventListener('resize', handleResize);\n }\n\n return () => {\n window.removeEventListener('resize', handleResize);\n };\n }, [calculateCoordinates, shouldShowDropdown]);\n\n return useMemo(\n () => ({ shouldUseTopAlignment, coordinates }),\n [coordinates, shouldUseTopAlignment],\n );\n};\n\ninterface UseDropdownOptions {\n anchorElement: Element;\n bodyWidth?: number;\n container?: Element;\n contentHeight?: number;\n direction: DropdownDirection;\n shouldShowDropdown: boolean;\n}\n\nexport const useDropdown = ({\n anchorElement,\n bodyWidth,\n container,\n contentHeight,\n direction,\n shouldShowDropdown,\n}: UseDropdownOptions) => {\n const { shouldUseTopAlignment, coordinates } = useDropdownPosition({\n anchorElement,\n container,\n contentHeight,\n direction,\n shouldShowDropdown,\n });\n\n const transform = useDropdownAlignment({\n shouldUseTopAlignment,\n bodyWidth,\n anchorElement,\n direction,\n });\n\n const width = anchorElement.clientWidth;\n\n return useMemo(() => ({ coordinates, transform, width }), [coordinates, transform, width]);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAEA,MAAME,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGC,sBAAe,GAAGC,gBAAS;AAStF,MAAMC,mBAAmB,GAAGA,CAAC;EAChCC,OAAO;EACPC,OAAO;EACPC,UAAU;EACVC;AACwB,CAAC,KAAK;EAC9B,IAAAL,gBAAS,EAAC,MAAM;IACZM,QAAQ,CAACC,gBAAgB,CAAC,OAAO,EAAEL,OAAO,CAAC;IAC3CI,QAAQ,CAACC,gBAAgB,CAAC,UAAU,EAAEH,UAAU,CAAC;IACjDE,QAAQ,CAACC,gBAAgB,CAAC,YAAY,EAAEF,YAAY,CAAC;IAErDP,MAAM,CAACS,gBAAgB,CAAC,MAAM,EAAE,MAAMJ,OAAO,CAAC,CAAC,CAAC;IAEhD,OAAO,MAAM;MACTG,QAAQ,CAACE,mBAAmB,CAAC,OAAO,EAAEN,OAAO,CAAC;MAC9CI,QAAQ,CAACE,mBAAmB,CAAC,UAAU,EAAEJ,UAAU,CAAC;MACpDE,QAAQ,CAACE,mBAAmB,CAAC,YAAY,EAAEH,YAAY,CAAC;MAExDP,MAAM,CAACS,gBAAgB,CAAC,MAAM,EAAE,MAAMJ,OAAO,CAAC,C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AACgB,CAAC,KAAK;EACtB,MAAM;IAAExB,qBAAqB;IAAEyB;EAAY,CAAC,GAAGJ,mBAAmB,CAAC;IAC/DpB,aAAa;IACbqB,SAAS;IACTC,aAAa;IACbxB,SAAS;IACTyB;EACJ,CAAC,CAAC;EAEF,MAAMqB,SAAS,GAAG/C,oBAAoB,CAAC;IACnCE,qBAAqB;IACrBE,SAAS;IACTD,aAAa;IACbF;EACJ,CAAC,CAAC;EAEF,MAAM+C,KAAK,GAAG7C,aAAa,CAACa,WAAW;EAEvC,OAAO,IAAAI,cAAO,EAAC,OAAO;IAAEO,WAAW;IAAEoB,SAAS;IAAEC;EAAM,CAAC,CAAC,EAAE,CAACrB,WAAW,EAAEoB,SAAS,EAAEC,KAAK,CAAC,CAAC;AAC9F,CAAC;AAACjD,OAAA,CAAA+C,WAAA,GAAAA,WAAA","ignoreList":[]}
1
+ {"version":3,"file":"dropdown.js","names":["_react","require","_dropdown","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","useDropdownListener","onClick","onClose","onTouchEnd","onTouchStart","document","addEventListener","removeEventListener","exports","useDropdownAlignment","direction","shouldUseTopAlignment","anchorElement","bodyWidth","translateX","setTranslateX","useState","translateY","setTranslateY","DropdownDirection","BOTTOM_LEFT","TOP_LEFT","LEFT","includes","difference","clientWidth","useTopAlignment","TOP","TOP_RIGHT","useMemo","x","y","useDropdownPosition","container","contentHeight","shouldShowDropdown","coordinates","setCoordinates","setShouldUseTopAlignment","calculateCoordinates","useCallback","left","anchorLeft","top","anchorTop","height","anchorHeight","getBoundingClientRect","scrollLeft","scrollTop","hasBottomAlignment","BOTTOM","BOTTOM_RIGHT","handleResize","setTimeout","useDropdown","transform","width"],"sources":["../../../src/hooks/dropdown.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';\nimport { DropdownCoordinates, DropdownDirection } from '../types/dropdown';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\ninterface UseDropdownListenerOptions {\n onClick: (event: MouseEvent) => void;\n onClose: () => void;\n onTouchEnd: (event: TouchEvent) => void;\n onTouchStart: (event: TouchEvent) => void;\n}\n\nexport const useDropdownListener = ({\n onClick,\n onClose,\n onTouchEnd,\n onTouchStart,\n}: UseDropdownListenerOptions) => {\n useEffect(() => {\n document.addEventListener('click', onClick, true);\n document.addEventListener('touchend', onTouchEnd, true);\n document.addEventListener('touchstart', onTouchStart, true);\n\n window.addEventListener('blur', () => onClose(), true);\n\n return () => {\n document.removeEventListener('click', onClick, true);\n document.removeEventListener('touchend', onTouchEnd, true);\n document.removeEventListener('touchstart', onTouchStart, true);\n\n window.addEventListener('blur', () => onClose(), true);\n };\n }, [onClick, onClose, onTouchEnd, onTouchStart]);\n};\n\ninterface UseDropdownAlignmentOptions {\n direction: DropdownDirection;\n shouldUseTopAlignment: boolean;\n bodyWidth?: number;\n anchorElement: Element;\n}\n\nexport const useDropdownAlignment = ({\n direction,\n shouldUseTopAlignment,\n anchorElement,\n bodyWidth,\n}: UseDropdownAlignmentOptions) => {\n const [translateX, setTranslateX] = useState<string>('0px');\n const [translateY, setTranslateY] = useState<string>('0px');\n\n useEffect(() => {\n if (\n [\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.LEFT,\n ].includes(direction) &&\n typeof bodyWidth === 'number'\n ) {\n const difference = anchorElement.clientWidth - bodyWidth;\n\n setTranslateX(`${difference}px`);\n } else {\n setTranslateX('0px');\n }\n }, [anchorElement.clientWidth, bodyWidth, direction]);\n\n useEffect(() => {\n const useTopAlignment =\n shouldUseTopAlignment ||\n [\n DropdownDirection.TOP,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.TOP_RIGHT,\n ].includes(direction);\n\n if (useTopAlignment) {\n setTranslateY('-100%');\n } else {\n setTranslateY('0px');\n }\n }, [direction, shouldUseTopAlignment]);\n\n return useMemo(() => ({ x: translateX, y: translateY }), [translateX, translateY]);\n};\n\ninterface UseDropdownPositionOptions {\n anchorElement: Element;\n container?: Element;\n contentHeight?: number;\n direction: DropdownDirection;\n shouldShowDropdown: boolean;\n}\n\nexport const useDropdownPosition = ({\n anchorElement,\n container,\n contentHeight = 0,\n direction,\n shouldShowDropdown,\n}: UseDropdownPositionOptions) => {\n const [coordinates, setCoordinates] = useState<DropdownCoordinates>({ x: 0, y: 0 });\n const [shouldUseTopAlignment, setShouldUseTopAlignment] = useState(false);\n\n const calculateCoordinates = useCallback(() => {\n if (container) {\n const {\n left: anchorLeft,\n top: anchorTop,\n height: anchorHeight,\n } = anchorElement.getBoundingClientRect();\n\n const { left, top, height } = container.getBoundingClientRect();\n\n const x = anchorLeft - left + container.scrollLeft;\n const y = anchorTop - top + container.scrollTop;\n\n let useTopAlignment = [\n DropdownDirection.TOP,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.TOP_RIGHT,\n ].includes(direction);\n\n const hasBottomAlignment = [\n DropdownDirection.BOTTOM,\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.BOTTOM_RIGHT,\n ].includes(direction);\n\n if (!hasBottomAlignment && y + anchorHeight + contentHeight > height) {\n useTopAlignment = true;\n\n setShouldUseTopAlignment(true);\n } else {\n setShouldUseTopAlignment(false);\n }\n\n setCoordinates({ x, y: useTopAlignment ? y : y + anchorHeight });\n }\n }, [anchorElement, container, contentHeight, direction]);\n\n useIsomorphicLayoutEffect(() => {\n const handleResize = () => {\n calculateCoordinates();\n\n setTimeout(calculateCoordinates, 300);\n };\n\n handleResize();\n\n if (shouldShowDropdown) {\n window.addEventListener('resize', handleResize);\n }\n\n return () => {\n window.removeEventListener('resize', handleResize);\n };\n }, [calculateCoordinates, shouldShowDropdown]);\n\n return useMemo(\n () => ({ shouldUseTopAlignment, coordinates }),\n [coordinates, shouldUseTopAlignment],\n );\n};\n\ninterface UseDropdownOptions {\n anchorElement: Element;\n bodyWidth?: number;\n container?: Element;\n contentHeight?: number;\n direction: DropdownDirection;\n shouldShowDropdown: boolean;\n}\n\nexport const useDropdown = ({\n anchorElement,\n bodyWidth,\n container,\n contentHeight,\n direction,\n shouldShowDropdown,\n}: UseDropdownOptions) => {\n const { shouldUseTopAlignment, coordinates } = useDropdownPosition({\n anchorElement,\n container,\n contentHeight,\n direction,\n shouldShowDropdown,\n });\n\n const transform = useDropdownAlignment({\n shouldUseTopAlignment,\n bodyWidth,\n anchorElement,\n direction,\n });\n\n const width = anchorElement.clientWidth;\n\n return useMemo(() => ({ coordinates, transform, width }), [coordinates, transform, width]);\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAEA,MAAME,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGC,sBAAe,GAAGC,gBAAS;AAStF,MAAMC,mBAAmB,GAAGA,CAAC;EAChCC,OAAO;EACPC,OAAO;EACPC,UAAU;EACVC;AACwB,CAAC,KAAK;EAC9B,IAAAL,gBAAS,EAAC,MAAM;IACZM,QAAQ,CAACC,gBAAgB,CAAC,OAAO,EAAEL,OAAO,EAAE,IAAI,CAAC;IACjDI,QAAQ,CAACC,gBAAgB,CAAC,UAAU,EAAEH,UAAU,EAAE,IAAI,CAAC;IACvDE,QAAQ,CAACC,gBAAgB,CAAC,YAAY,EAAEF,YAAY,EAAE,IAAI,CAAC;IAE3DP,MAAM,CAACS,gBAAgB,CAAC,MAAM,EAAE,MAAMJ,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC;IAEtD,OAAO,MAAM;MACTG,QAAQ,CAACE,mBAAmB,CAAC,OAAO,EAAEN,OAAO,EAAE,IAAI,CAAC;MACpDI,QAAQ,CAACE,mBAAmB,CAAC,UAAU,EAAEJ,UAAU,EAAE,IAAI,CAAC;MAC1DE,QAAQ,CAACE,mBAAmB,CAAC,YAAY,EAAEH,YAAY,EAAE,IAAI,CAAC;MAE9DP,MAAM,CAACS,gBAAgB,CAAC,MAAM,EAAE,MAAMJ,OAAO,CAAC,CAAC,EA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ACTyB;AACgB,CAAC,KAAK;EACtB,MAAM;IAAExB,qBAAqB;IAAEyB;EAAY,CAAC,GAAGJ,mBAAmB,CAAC;IAC/DpB,aAAa;IACbqB,SAAS;IACTC,aAAa;IACbxB,SAAS;IACTyB;EACJ,CAAC,CAAC;EAEF,MAAMqB,SAAS,GAAG/C,oBAAoB,CAAC;IACnCE,qBAAqB;IACrBE,SAAS;IACTD,aAAa;IACbF;EACJ,CAAC,CAAC;EAEF,MAAM+C,KAAK,GAAG7C,aAAa,CAACa,WAAW;EAEvC,OAAO,IAAAI,cAAO,EAAC,OAAO;IAAEO,WAAW;IAAEoB,SAAS;IAAEC;EAAM,CAAC,CAAC,EAAE,CAACrB,WAAW,EAAEoB,SAAS,EAAEC,KAAK,CAAC,CAAC;AAC9F,CAAC;AAACjD,OAAA,CAAA+C,WAAA,GAAAA,WAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["_Accordion","_interopRequireDefault","require","_AccordionContent","_AccordionGroup","_AccordionIntro","_AccordionItem","_AmountControl","_VerificationBadge","_AreaContextProvider","_interopRequireWildcard","_Badge","_Button","_Checkbox","_ColorSchemeProvider","_badge","_container","_dropdown","_element","_ref","_FileList","_FileSelect","_DropdownBodyWrapper","_ComboBox","_ContentCard","_HighlightSlider","_ContextMenu","_ExpandableContent","_FileInput","_FilterButton","_FilterButtons","_GridImage","_GroupedImage","_Icon","_Input","_List","_ListItemContent","_ListItem","_MentionFinder","_NumberInput","_PageProvider","_Popup","_PopupContent","_ProgressBar","_popup","_RadioButtonGroup","_RadioButton","_ScrollView","_SearchBox","_SearchInput","_SelectButton","_SetupWizardItem","_SetupWizard","_SharingBar","_Signature","_SliderButton","_Slider","_SmallWaitCursor","_TagInput","_TextArea","_Tooltip","_Truncation","_mentionFinder","_contentCard","_contextMenu","_file","_filterButtons","_truncation","_environment","_fileDialog","_isTobitEmployee","_pageProvider","_uploadFile","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as Accordion } from './components/accordion/Accordion';\nexport { default as AccordionContent } from './components/accordion/accordion-content/AccordionContent';\nexport { default as AccordionGroup } from './components/accordion/accordion-group/AccordionGroup';\nexport { default as AccordionIntro } from './components/accordion/accordion-intro/AccordionIntro';\nexport { default as AccordionItem } from './components/accordion/accordion-item/AccordionItem';\nexport { default as AmountControl } from './components/amount-control/AmountControl';\nexport { default as VerificationBadge } from './components/verification-badge/VerificationBadge';\nexport {\n AreaContext,\n default as AreaProvider,\n} from './components/area-provider/AreaContextProvider';\nexport { default as Badge } from './components/badge/Badge';\nexport { default as Button } from './components/button/Button';\nexport { default as Checkbox } from './components/checkbox/Checkbox';\nexport {\n default as ColorSchemeProvider,\n useColorScheme,\n} from './components/color-scheme-provider/ColorSchemeProvider';\nexport { BadgeSize, BadgeDesign } from './types/badge';\nexport type {\n ColorSchemeContextProps,\n WithTheme,\n} from './components/color-scheme-provider/ColorSchemeProvider';\nexport { useContainer, ContainerAnchor } from './hooks/container';\nexport { DropdownDirection, type DropdownCoordinates } from './types/dropdown';\nexport { useIsMeasuredClone } from './hooks/element';\nexport { useCombinedRefs } from './hooks/ref';\nexport {\n default as FileList,\n type IFileItem as FileListItem,\n} from './components/file-list/FileList';\nexport { default as FileSelect } from './components/file-select/FileSelect';\nexport { default as DropdownBodyWrapper } from './components/dropdown-body-wrapper/DropdownBodyWrapper';\nexport {\n default as ComboBox,\n type ComboBoxTextStyles,\n type IComboBoxItem as ComboBoxItem,\n type IComboBoxItems as ComboBoxItems,\n} from './components/combobox/ComboBox';\nexport { default as ContentCard } from './components/content-card/ContentCard';\nexport { default as HighlightSLider } from './components/highlight-slider/HighlightSlider';\nexport type { HighlightSliderItemColors as HighlightSliderColors } from './components/highlight-slider/highlight-slider-item/HighlightSliderItem';\nexport {\n default as ContextMenu,\n type ContextMenuCoordinates,\n type ContextMenuItem,\n type ContextMenuRef,\n} from './components/context-menu/ContextMenu';\nexport { default as ExpandableContent } from './components/expandable-content/ExpandableContent';\nexport { default as FileInput, type FileInputRef } from './components/file-input/FileInput';\nexport { default as FilterButton } from './components/filter-buttons/filter-button/FilterButton';\nexport { default as FilterButtons } from './components/filter-buttons/FilterButtons';\nexport { default as GridImage } from './components/grid-image/GridImage';\nexport { default as GroupedImage } from './components/grouped-image/GroupedImage';\nexport { default as Icon } from './components/icon/Icon';\nexport { default as Input, InputSize } from './components/input/Input';\nexport { default as List } from './components/list/List';\nexport { default as ListItemContent } from './components/list/list-item/list-item-content/ListItemContent';\nexport {\n default as ListItem,\n type ListItemElements,\n type ListItemProps,\n} from './components/list/list-item/ListItem';\nexport { default as MentionFinder } from './components/mention-finder/MentionFinder';\nexport type { MentionMember } from './components/mention-finder/MentionFinder';\nexport { default as NumberInput } from './components/number-input/NumberInput';\nexport { default as PageProvider } from './components/page-provider/PageProvider';\nexport { default as Popup } from './components/popup/Popup';\nexport { default as PopupContent } from './components/popup/popup-content/PopupContent';\nexport { default as ProgressBar } from './components/progress-bar/ProgressBar';\nexport { PopupAlignment } from './types/popup';\nexport {\n default as RadioButtonGroup,\n type RadioButtonGroupRef,\n} from './components/radio-button/radio-button-group/RadioButtonGroup';\nexport { default as RadioButton } from './components/radio-button/RadioButton';\nexport { default as ScrollView } from './components/scroll-view/ScrollView';\nexport { default as SearchBox } from './components/search-box/SearchBox';\nexport { default as SearchInput } from './components/search-input/SearchInput';\nexport { default as SelectButton } from './components/select-button/SelectButton';\nexport { default as SetupWizardItem } from './components/setup-wizard/setup-wizard-item/SetupWizardItem';\nexport { default as SetupWizard } from './components/setup-wizard/SetupWizard';\nexport type { SetupWizardRef } from './components/setup-wizard/SetupWizard';\nexport { default as SharingBar } from './components/sharing-bar/SharingBar';\nexport { default as Signature } from './components/signature/Signature';\nexport type { SignatureRef } from './components/signature/Signature';\nexport { default as SliderButton } from './components/slider-button/SliderButton';\nexport { default as Slider } from './components/slider/Slider';\nexport {\n default as SmallWaitCursor,\n SmallWaitCursorSize,\n SmallWaitCursorSpeed,\n} from './components/small-wait-cursor/SmallWaitCursor';\nexport { default as TagInput } from './components/tag-input/TagInput';\nexport { default as TextArea } from './components/text-area/TextArea';\nexport { default as Tooltip } from './components/tooltip/Tooltip';\nexport { default as Truncation } from './components/truncation/Truncation';\nexport { MentionFinderPopupAlignment } from './constants/mentionFinder';\nexport { useElementSize } from './hooks/element';\nexport type { BrowserName } from './types/chayns';\nexport { ContentCardType } from './types/contentCard';\nexport { ContextMenuAlignment } from './types/contextMenu';\nexport type { FileItem, Image, InternalFileItem, Meta, Video } from './types/file';\nexport { isValidFileType } from './utils/file';\nexport type { FileInputFileItem } from './types/fileInput';\nexport { FilterButtonItemShape, FilterButtonSize } from './types/filterButtons';\nexport type { IFilterButtonItem as FilterButtonItem } from './types/filterButtons';\nexport type { IListItemRightElements } from './types/list';\nexport type { PopupRef } from './types/popup';\nexport type { RadioButtonItem } from './types/radioButton';\nexport type {\n ISearchBoxItem as SearchBoxItem,\n ISearchBoxItems as SearchBoxItems,\n} from './types/searchBox';\nexport type { SelectButtonItem } from './types/selectButton';\nexport type { SliderButtonItem } from './types/slider-button';\nexport { ClampPosition } from './types/truncation';\nexport { getIsTouch } from './utils/environment';\nexport { filterFilesByMimeType, getFileAsArrayBuffer, selectFiles } from './utils/fileDialog';\nexport { isTobitEmployee } from './utils/isTobitEmployee';\nexport { getUsableHeight } from './utils/pageProvider';\nexport { uploadFile } from './utils/uploadFile';\nexport type { Theme } from './components/color-scheme-provider/ColorSchemeProvider';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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K,UAAA,SAAAL,CAAA,MAAAM,CAAA,EAAAC,CAAA,EAAAC,CAAA,KAAAC,SAAA,QAAAC,OAAA,EAAAV,CAAA,iBAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,SAAAQ,CAAA,MAAAF,CAAA,GAAAL,CAAA,GAAAG,CAAA,GAAAD,CAAA,QAAAG,CAAA,CAAAK,GAAA,CAAAX,CAAA,UAAAM,CAAA,CAAAM,GAAA,CAAAZ,CAAA,GAAAM,CAAA,CAAAO,GAAA,CAAAb,CAAA,EAAAQ,CAAA,gBAAAP,CAAA,IAAAD,CAAA,gBAAAC,CAAA,OAAAa,cAAA,CAAAC,IAAA,CAAAf,CAAA,EAAAC,CAAA,OAAAM,CAAA,IAAAD,CAAA,GAAAU,MAAA,CAAAC,cAAA,KAAAD,MAAA,CAAAE,wBAAA,CAAAlB,CAAA,EAAAC,CAAA,OAAAM,CAAA,CAAAK,GAAA,IAAAL,CAAA,CAAAM,GAAA,IAAAP,CAAA,CAAAE,CAAA,EAAAP,CAAA,EAAAM,CAAA,IAAAC,CAAA,CAAAP,CAAA,IAAAD,CAAA,CAAAC,CAAA,WAAAO,CAAA,KAAAR,CAAA,EAAAC,CAAA;AAAA,SAAAzE,uBAAAwE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAK,UAAA,GAAAL,CAAA,KAAAU,OAAA,EAAAV,CAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["_Accordion","_interopRequireDefault","require","_AccordionContent","_AccordionGroup","_AccordionIntro","_AccordionItem","_AmountControl","_VerificationBadge","_AreaContextProvider","_interopRequireWildcard","_Badge","_Button","_Checkbox","_ColorSchemeProvider","_badge","_container","_dropdown","_element","_ref","_FileList","_FileSelect","_DropdownBodyWrapper","_ComboBox","_ContentCard","_HighlightSlider","_ContextMenu","_ExpandableContent","_FileInput","_FilterButton","_FilterButtons","_GridImage","_GroupedImage","_Icon","_Input","_List","_ListItemContent","_ListItem","_MentionFinder","_NumberInput","_PageProvider","_Popup","_PopupContent","_ProgressBar","_popup","_RadioButtonGroup","_RadioButton","_ScrollView","_SearchBox","_SearchInput","_SelectButton","_SetupWizardItem","_SetupWizard","_SharingBar","_Signature","_SliderButton","_Slider","_SmallWaitCursor","_TagInput","_TextArea","_Tooltip","_Truncation","_mentionFinder","_contentCard","_contextMenu","_file","_filterButtons","_truncation","_environment","_fileDialog","_isTobitEmployee","_pageProvider","_uploadFile","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as Accordion } from './components/accordion/Accordion';\nexport { default as AccordionContent } from './components/accordion/accordion-content/AccordionContent';\nexport { default as AccordionGroup } from './components/accordion/accordion-group/AccordionGroup';\nexport { default as AccordionIntro } from './components/accordion/accordion-intro/AccordionIntro';\nexport { default as AccordionItem } from './components/accordion/accordion-item/AccordionItem';\nexport { default as AmountControl } from './components/amount-control/AmountControl';\nexport { default as VerificationBadge } from './components/verification-badge/VerificationBadge';\nexport {\n AreaContext,\n default as AreaProvider,\n} from './components/area-provider/AreaContextProvider';\nexport { default as Badge } from './components/badge/Badge';\nexport { default as Button } from './components/button/Button';\nexport { default as Checkbox } from './components/checkbox/Checkbox';\nexport {\n default as ColorSchemeProvider,\n useColorScheme,\n} from './components/color-scheme-provider/ColorSchemeProvider';\nexport { BadgeSize, BadgeDesign } from './types/badge';\nexport type {\n ColorSchemeContextProps,\n WithTheme,\n} from './components/color-scheme-provider/ColorSchemeProvider';\nexport { useContainer, ContainerAnchor } from './hooks/container';\nexport { DropdownDirection, type DropdownCoordinates } from './types/dropdown';\nexport { useIsMeasuredClone } from './hooks/element';\nexport { useCombinedRefs } from './hooks/ref';\nexport {\n default as FileList,\n type IFileItem as FileListItem,\n} from './components/file-list/FileList';\nexport { default as FileSelect } from './components/file-select/FileSelect';\nexport { default as DropdownBodyWrapper } from './components/dropdown-body-wrapper/DropdownBodyWrapper';\nexport {\n default as ComboBox,\n type ComboBoxTextStyles,\n type IComboBoxItem as ComboBoxItem,\n type IComboBoxItems as ComboBoxItems,\n} from './components/combobox/ComboBox';\nexport { default as ContentCard } from './components/content-card/ContentCard';\nexport { default as HighlightSLider } from './components/highlight-slider/HighlightSlider';\nexport type { HighlightSliderItemColors as HighlightSliderColors } from './components/highlight-slider/highlight-slider-item/HighlightSliderItem';\nexport {\n default as ContextMenu,\n type ContextMenuCoordinates,\n type ContextMenuItem,\n type ContextMenuRef,\n} from './components/context-menu/ContextMenu';\nexport { default as ExpandableContent } from './components/expandable-content/ExpandableContent';\nexport { default as FileInput, type FileInputRef } from './components/file-input/FileInput';\nexport { default as FilterButton } from './components/filter-buttons/filter-button/FilterButton';\nexport { default as FilterButtons } from './components/filter-buttons/FilterButtons';\nexport { default as GridImage } from './components/grid-image/GridImage';\nexport { default as GroupedImage } from './components/grouped-image/GroupedImage';\nexport { default as Icon } from './components/icon/Icon';\nexport { default as Input, InputSize } from './components/input/Input';\nexport { default as List } from './components/list/List';\nexport { default as ListItemContent } from './components/list/list-item/list-item-content/ListItemContent';\nexport {\n default as ListItem,\n type ListItemElements,\n type ListItemProps,\n} from './components/list/list-item/ListItem';\nexport { default as MentionFinder } from './components/mention-finder/MentionFinder';\nexport type { MentionMember } from './components/mention-finder/MentionFinder';\nexport { default as NumberInput } from './components/number-input/NumberInput';\nexport { default as PageProvider } from './components/page-provider/PageProvider';\nexport { default as Popup } from './components/popup/Popup';\nexport { default as PopupContent } from './components/popup/popup-content/PopupContent';\nexport { default as ProgressBar } from './components/progress-bar/ProgressBar';\nexport { PopupAlignment } from './types/popup';\nexport {\n default as RadioButtonGroup,\n type RadioButtonGroupRef,\n} from './components/radio-button/radio-button-group/RadioButtonGroup';\nexport { default as RadioButton } from './components/radio-button/RadioButton';\nexport { default as ScrollView } from './components/scroll-view/ScrollView';\nexport { default as SearchBox } from './components/search-box/SearchBox';\nexport { default as SearchInput } from './components/search-input/SearchInput';\nexport { default as SelectButton } from './components/select-button/SelectButton';\nexport { default as SetupWizardItem } from './components/setup-wizard/setup-wizard-item/SetupWizardItem';\nexport { default as SetupWizard } from './components/setup-wizard/SetupWizard';\nexport type { SetupWizardRef } from './components/setup-wizard/SetupWizard';\nexport { default as SharingBar } from './components/sharing-bar/SharingBar';\nexport { default as Signature } from './components/signature/Signature';\nexport type { SignatureRef } from './components/signature/Signature';\nexport { default as SliderButton } from './components/slider-button/SliderButton';\nexport { default as Slider } from './components/slider/Slider';\nexport {\n default as SmallWaitCursor,\n SmallWaitCursorSize,\n SmallWaitCursorSpeed,\n} from './components/small-wait-cursor/SmallWaitCursor';\nexport type { Tag } from './types/tagInput';\nexport { default as TagInput } from './components/tag-input/TagInput';\nexport type { TagInputRef } from './components/tag-input/TagInput';\nexport { default as TextArea } from './components/text-area/TextArea';\nexport { default as Tooltip } from './components/tooltip/Tooltip';\nexport { default as Truncation } from './components/truncation/Truncation';\nexport { MentionFinderPopupAlignment } from './constants/mentionFinder';\nexport { useElementSize } from './hooks/element';\nexport type { BrowserName } from './types/chayns';\nexport { ContentCardType } from './types/contentCard';\nexport { ContextMenuAlignment } from './types/contextMenu';\nexport type { FileItem, Image, InternalFileItem, Meta, Video } from './types/file';\nexport { isValidFileType } from './utils/file';\nexport type { FileInputFileItem } from './types/fileInput';\nexport { FilterButtonItemShape, FilterButtonSize } from './types/filterButtons';\nexport type { IFilterButtonItem as FilterButtonItem } from './types/filterButtons';\nexport type { IListItemRightElements } from './types/list';\nexport type { PopupRef } from './types/popup';\nexport type { RadioButtonItem } from './types/radioButton';\nexport type {\n ISearchBoxItem as SearchBoxItem,\n ISearchBoxItems as SearchBoxItems,\n} from './types/searchBox';\nexport type { SelectButtonItem } from './types/selectButton';\nexport type { SliderButtonItem } from './types/slider-button';\nexport { ClampPosition } from './types/truncation';\nexport { getIsTouch } from './utils/environment';\nexport { filterFilesByMimeType, getFileAsArrayBuffer, selectFiles } from './utils/fileDialog';\nexport { isTobitEmployee } from './utils/isTobitEmployee';\nexport { getUsableHeight } from './utils/pageProvider';\nexport { uploadFile } from './utils/uploadFile';\nexport type { Theme } from './components/color-scheme-provider/ColorSchemeProvider';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,eAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,eAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,cAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,cAAA,GAAAN,sBAAA,CAAAC,OAAA;AACA,IAAAM,kBAAA,GAAAP,sBAAA,CAAAC,OAAA;AACA,IAAAO,oBAAA,GAAAC,uBAAA,CAAAR,OAAA;AAIA,IAAAS,MAAA,GAAAV,sBAAA,CAAAC,OAAA;AACA,IAAAU,OAAA,GAAAX,sBAAA,CAAAC,OAAA;AACA,IAAAW,SAAA,GAAAZ,sBA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[]}
@@ -6,17 +6,18 @@ import DelayedDropdownContent from './delayed-dropdown-content/DelayedDropdownCo
6
6
  import { useDropdown, useDropdownListener } from '../../hooks/dropdown';
7
7
  import { ContainerAnchor, useContainer } from '../../hooks/container';
8
8
  const DropdownBodyWrapper = ({
9
- direction = DropdownDirection.BOTTOM_RIGHT,
9
+ anchorElement,
10
+ bodyWidth,
10
11
  children,
11
12
  container: containerProp,
12
- shouldShowDropdown,
13
- anchorElement,
14
13
  contentHeight = 0,
14
+ direction = DropdownDirection.BOTTOM_RIGHT,
15
15
  maxHeight = 300,
16
+ minBodyWidth = 0,
16
17
  onClose,
18
+ onOutsideClick,
17
19
  onMeasure,
18
- minBodyWidth = 0,
19
- bodyWidth
20
+ shouldShowDropdown
20
21
  }) => {
21
22
  const isInChaynsWalletRef = useRef(false);
22
23
  const [measuredContentHeight, setMeasuredContentHeight] = useState(0);
@@ -50,11 +51,16 @@ const DropdownBodyWrapper = ({
50
51
  * This function closes the body
51
52
  */
52
53
  const handleClick = useCallback(event => {
53
- if (!shouldPreventClickRef.current && !anchorElement.contains(event.target) && ref.current && !ref.current.contains(event.target)) {
54
- handleClose();
54
+ if (ref.current && shouldShowDropdown && !anchorElement.contains(event.target) && !ref.current.contains(event.target)) {
55
+ event.preventDefault();
56
+ event.stopPropagation();
57
+ const shouldPreventCloseOnClick = onOutsideClick?.() ?? false;
58
+ if (!shouldPreventClickRef.current && !shouldPreventCloseOnClick) {
59
+ handleClose();
60
+ }
55
61
  }
56
62
  shouldPreventClickRef.current = false;
57
- }, [anchorElement, handleClose]);
63
+ }, [anchorElement, handleClose, onOutsideClick, shouldShowDropdown]);
58
64
  const handleContentMeasure = useCallback(measurements => {
59
65
  // Measurements are only needed if the content is shown in the chayns wallet. To prevent
60
66
  // unnecessary renders, we only set the height if the content is shown in the wallet.
@@ -1 +1 @@
1
- {"version":3,"file":"DropdownBodyWrapper.js","names":["React","useCallback","useEffect","useRef","useState","StyledDropdownBodyWrapper","StyledDropdownBodyWrapperContent","createPortal","DropdownDirection","DelayedDropdownContent","useDropdown","useDropdownListener","ContainerAnchor","useContainer","DropdownBodyWrapper","direction","BOTTOM_RIGHT","children","container","containerProp","shouldShowDropdown","anchorElement","contentHeight","maxHeight","onClose","onMeasure","minBodyWidth","bodyWidth","isInChaynsWalletRef","measuredContentHeight","setMeasuredContentHeight","portal","setPortal","ref","shouldPreventClickRef","touchTimeoutRef","undefined","transform","width","coordinates","handleClose","handleClick","event","current","contains","target","handleContentMeasure","measurements","height","handleTouchEnd","clearTimeout","handleTouchStart","window","setTimeout","onClick","onTouchEnd","onTouchStart","isBottomDirection","BOTTOM","BOTTOM_LEFT","includes","reservationWrapperElement","closest","RESERVATION_WRAPPER","availableHeight","innerHeight","getBoundingClientRect","bottom","additionalNeededSpace","style","marginBottom","createElement","shouldShowContent","$width","$minWidth","$maxHeight","$direction","displayName"],"sources":["../../../../src/components/dropdown-body-wrapper/DropdownBodyWrapper.tsx"],"sourcesContent":["import React, { FC, ReactNode, ReactPortal, useCallback, useEffect, useRef, useState } from 'react';\nimport {\n StyledDropdownBodyWrapper,\n StyledDropdownBodyWrapperContent,\n} from './DropdownBodyWrapper.styles';\nimport { createPortal } from 'react-dom';\nimport { DropdownDirection, DropdownMeasurements } from '../../types/dropdown';\nimport DelayedDropdownContent, {\n DelayedDropdownContentProps,\n} from './delayed-dropdown-content/DelayedDropdownContent';\nimport { useDropdown, useDropdownListener } from '../../hooks/dropdown';\nimport { ContainerAnchor, useContainer } from '../../hooks/container';\n\ninterface DropdownBodyWrapperProps {\n /**\n * The anchor element of the dropdown.\n */\n anchorElement: Element;\n /**\n * The width of the Body.\n */\n bodyWidth?: number;\n /**\n * The content of the dropdown body.\n */\n children: ReactNode;\n /**\n * The element where the content should be rendered via React Portal.\n */\n container?: Element;\n /**\n * The height of the content\n */\n contentHeight?: number;\n /**\n * The direction of the dropdown.\n */\n direction?: DropdownDirection;\n /**\n * The max height of the dropdown.\n */\n maxHeight?: number;\n /**\n * The minimum width of the body.\n */\n minBodyWidth?: number;\n /**\n * Function to be executed when the body is closed.\n */\n onClose?: VoidFunction;\n /**\n * Function to be executed when the content is measured.\n */\n onMeasure?: DelayedDropdownContentProps['onMeasure'];\n /**\n * Whether the dropdown should be visible.\n */\n shouldShowDropdown: boolean;\n}\n\nconst DropdownBodyWrapper: FC<DropdownBodyWrapperProps> = ({\n direction = DropdownDirection.BOTTOM_RIGHT,\n children,\n container: containerProp,\n shouldShowDropdown,\n anchorElement,\n contentHeight = 0,\n maxHeight = 300,\n onClose,\n onMeasure,\n minBodyWidth = 0,\n bodyWidth,\n}) => {\n const isInChaynsWalletRef = useRef(false);\n\n const [measuredContentHeight, setMeasuredContentHeight] = useState<number>(0);\n const [portal, setPortal] = useState<ReactPortal>();\n\n const ref = useRef<HTMLDivElement>(null);\n const shouldPreventClickRef = useRef<boolean>(false);\n const touchTimeoutRef = useRef<number | undefined>(undefined);\n\n const container = useContainer({ anchorElement, container: containerProp });\n\n const { transform, width, coordinates } = useDropdown({\n direction,\n bodyWidth,\n contentHeight,\n container,\n anchorElement,\n shouldShowDropdown,\n });\n\n const handleClose = useCallback(() => {\n if (typeof onClose === 'function') {\n onClose();\n }\n }, [onClose]);\n\n /**\n * This function closes the body\n */\n const handleClick = useCallback(\n (event: MouseEvent) => {\n if (\n !shouldPreventClickRef.current &&\n !anchorElement.contains(event.target as Node) &&\n ref.current &&\n !ref.current.contains(event.target as Node)\n ) {\n handleClose();\n }\n\n shouldPreventClickRef.current = false;\n },\n [anchorElement, handleClose],\n );\n\n const handleContentMeasure = useCallback(\n (measurements: DropdownMeasurements) => {\n // Measurements are only needed if the content is shown in the chayns wallet. To prevent\n // unnecessary renders, we only set the height if the content is shown in the wallet.\n if (isInChaynsWalletRef.current) {\n setMeasuredContentHeight(measurements.height);\n }\n\n if (typeof onMeasure === 'function') {\n onMeasure(measurements);\n }\n },\n [onMeasure],\n );\n\n const handleTouchEnd = useCallback(() => {\n clearTimeout(touchTimeoutRef.current);\n }, []);\n\n const handleTouchStart = useCallback(() => {\n touchTimeoutRef.current = window.setTimeout(() => {\n shouldPreventClickRef.current = true;\n }, 500);\n }, []);\n\n /**\n * This hook listens for clicks\n */\n useDropdownListener({\n onClick: handleClick,\n onClose: handleClose,\n onTouchEnd: handleTouchEnd,\n onTouchStart: handleTouchStart,\n });\n\n useEffect(() => {\n const isBottomDirection = [\n DropdownDirection.BOTTOM,\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.BOTTOM_RIGHT,\n ].includes(direction);\n\n const reservationWrapperElement = anchorElement.closest<HTMLDivElement>(\n ContainerAnchor.RESERVATION_WRAPPER,\n );\n\n isInChaynsWalletRef.current =\n !!(reservationWrapperElement && reservationWrapperElement.contains(anchorElement)) ||\n true;\n\n // This effect checks if additional space is needed to show dropdown content in chayns cards.\n if (\n isBottomDirection &&\n isInChaynsWalletRef.current &&\n measuredContentHeight > 0 &&\n reservationWrapperElement &&\n shouldShowDropdown\n ) {\n const availableHeight =\n window.innerHeight - anchorElement.getBoundingClientRect().bottom;\n\n // If the content height is greater than the available height, we need to add additional space.\n // This is to ensure that the dropdown content is fully visible. The 16 pixels are a buffer for shadows.\n const additionalNeededSpace = measuredContentHeight + 16 - availableHeight;\n\n if (additionalNeededSpace > 0) {\n // Add margin bottom to the reservation wrapper to ensure the dropdown content is fully visible.\n reservationWrapperElement.style.marginBottom = `${additionalNeededSpace}px`;\n } else {\n // Reset the margin bottom if no additional space is needed.\n reservationWrapperElement.style.marginBottom = '0px';\n }\n }\n\n if (isInChaynsWalletRef.current && reservationWrapperElement && !shouldShowDropdown) {\n // Reset the margin bottom when the dropdown is closed.\n reservationWrapperElement.style.marginBottom = '0px';\n }\n\n return () => {\n if (reservationWrapperElement) {\n reservationWrapperElement.style.marginBottom = '0px';\n }\n };\n }, [anchorElement, direction, measuredContentHeight, shouldShowDropdown]);\n\n useEffect(() => {\n if (!container) return;\n\n setPortal(() =>\n createPortal(\n <DelayedDropdownContent\n coordinates={coordinates}\n onMeasure={handleContentMeasure}\n shouldShowContent={shouldShowDropdown}\n transform={transform}\n >\n <StyledDropdownBodyWrapperContent\n $width={width}\n $minWidth={minBodyWidth}\n $maxHeight={maxHeight}\n $direction={direction}\n ref={ref}\n >\n {children}\n </StyledDropdownBodyWrapperContent>\n </DelayedDropdownContent>,\n container,\n ),\n );\n }, [\n children,\n container,\n coordinates,\n direction,\n handleContentMeasure,\n maxHeight,\n minBodyWidth,\n shouldShowDropdown,\n transform,\n width,\n ]);\n\n return <StyledDropdownBodyWrapper>{portal}</StyledDropdownBodyWrapper>;\n};\n\nDropdownBodyWrapper.displayName = 'DropdownBodyWrapper';\n\nexport default DropdownBodyWrapper;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAgCC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACnG,SACIC,yBAAyB,EACzBC,gCAAgC,QAC7B,8BAA8B;AACrC,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,iBAAiB,QAA8B,sBAAsB;AAC9E,OAAOC,sBAAsB,MAEtB,mDAAmD;AAC1D,SAASC,WAAW,EAAEC,mBAAmB,QAAQ,sBAAsB;AACvE,SAASC,eAAe,EAAEC,YAAY,QAAQ,uBAAuB;AAiDrE,MAAMC,mBAAiD,GAAGA,CAAC;EACvDC,SAAS,GAAGP,iBAAiB,CAACQ,YAAY;EAC1CC,QAAQ;EACRC,SAAS,EAAEC,aAAa;EACxBC,kBAAkB;EAClBC,aAAa;EACbC,aAAa,GAAG,CAAC;EACjBC,SAAS,GAAG,GAAG;EACfC,OAAO;EACPC,SAAS;EACTC,YAAY,GAAG,CAAC;EAChBC;AACJ,CAAC,KAAK;EACF,MAAMC,mBAAmB,GAAGzB,MAAM,CAAC,KAAK,CAAC;EAEzC,MAAM,CAAC0B,qBAAqB,EAAEC,wBAAwB,CAAC,GAAG1B,QAAQ,CAAS,CAAC,CAAC;EAC7E,MAAM,CAAC2B,MAAM,EAAEC,SAAS,CAAC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,SAAS,EACTC,KAAK,CACR,CAAC;EAEF,oBAAOtC,KAAA,CAAAuE,aAAA,CAAClE,yBAAyB,QAAE0B,MAAkC,CAAC;AAC1E,CAAC;AAEDjB,mBAAmB,CAAC+D,WAAW,GAAG,qBAAqB;AAEvD,eAAe/D,mBAAmB","ignoreList":[]}
1
+ {"version":3,"file":"DropdownBodyWrapper.js","names":["React","useCallback","useEffect","useRef","useState","StyledDropdownBodyWrapper","StyledDropdownBodyWrapperContent","createPortal","DropdownDirection","DelayedDropdownContent","useDropdown","useDropdownListener","ContainerAnchor","useContainer","DropdownBodyWrapper","anchorElement","bodyWidth","children","container","containerProp","contentHeight","direction","BOTTOM_RIGHT","maxHeight","minBodyWidth","onClose","onOutsideClick","onMeasure","shouldShowDropdown","isInChaynsWalletRef","measuredContentHeight","setMeasuredContentHeight","portal","setPortal","ref","shouldPreventClickRef","touchTimeoutRef","undefined","transform","width","coordinates","handleClose","handleClick","event","current","contains","target","preventDefault","stopPropagation","shouldPreventCloseOnClick","handleContentMeasure","measurements","height","handleTouchEnd","clearTimeout","handleTouchStart","window","setTimeout","onClick","onTouchEnd","onTouchStart","isBottomDirection","BOTTOM","BOTTOM_LEFT","includes","reservationWrapperElement","closest","RESERVATION_WRAPPER","availableHeight","innerHeight","getBoundingClientRect","bottom","additionalNeededSpace","style","marginBottom","createElement","shouldShowContent","$width","$minWidth","$maxHeight","$direction","displayName"],"sources":["../../../../src/components/dropdown-body-wrapper/DropdownBodyWrapper.tsx"],"sourcesContent":["import React, { FC, ReactNode, ReactPortal, useCallback, useEffect, useRef, useState } from 'react';\nimport {\n StyledDropdownBodyWrapper,\n StyledDropdownBodyWrapperContent,\n} from './DropdownBodyWrapper.styles';\nimport { createPortal } from 'react-dom';\nimport { DropdownDirection, DropdownMeasurements } from '../../types/dropdown';\nimport DelayedDropdownContent, {\n DelayedDropdownContentProps,\n} from './delayed-dropdown-content/DelayedDropdownContent';\nimport { useDropdown, useDropdownListener } from '../../hooks/dropdown';\nimport { ContainerAnchor, useContainer } from '../../hooks/container';\n\ninterface DropdownBodyWrapperProps {\n /**\n * The anchor element of the dropdown.\n */\n anchorElement: Element;\n /**\n * The width of the Body.\n */\n bodyWidth?: number;\n /**\n * The content of the dropdown body.\n */\n children: ReactNode;\n /**\n * The element where the content should be rendered via React Portal.\n */\n container?: Element;\n /**\n * The height of the content\n */\n contentHeight?: number;\n /**\n * The direction of the dropdown.\n */\n direction?: DropdownDirection;\n /**\n * The max height of the dropdown.\n */\n maxHeight?: number;\n /**\n * The minimum width of the body.\n */\n minBodyWidth?: number;\n /**\n * Function to be executed when the body is closed.\n */\n onClose?: VoidFunction;\n /**\n * Function to be executed when the user clicks outside the dropdown.\n * If the function returns `true`, the dropdown will not be closed.\n */\n onOutsideClick?: () => boolean | void;\n /**\n * Function to be executed when the content is measured.\n */\n onMeasure?: DelayedDropdownContentProps['onMeasure'];\n /**\n * Whether the dropdown should be visible.\n */\n shouldShowDropdown: boolean;\n}\n\nconst DropdownBodyWrapper: FC<DropdownBodyWrapperProps> = ({\n anchorElement,\n bodyWidth,\n children,\n container: containerProp,\n contentHeight = 0,\n direction = DropdownDirection.BOTTOM_RIGHT,\n maxHeight = 300,\n minBodyWidth = 0,\n onClose,\n onOutsideClick,\n onMeasure,\n shouldShowDropdown,\n}) => {\n const isInChaynsWalletRef = useRef(false);\n\n const [measuredContentHeight, setMeasuredContentHeight] = useState<number>(0);\n const [portal, setPortal] = useState<ReactPortal>();\n\n const ref = useRef<HTMLDivElement>(null);\n const shouldPreventClickRef = useRef<boolean>(false);\n const touchTimeoutRef = useRef<number | undefined>(undefined);\n\n const container = useContainer({ anchorElement, container: containerProp });\n\n const { transform, width, coordinates } = useDropdown({\n direction,\n bodyWidth,\n contentHeight,\n container,\n anchorElement,\n shouldShowDropdown,\n });\n\n const handleClose = useCallback(() => {\n if (typeof onClose === 'function') {\n onClose();\n }\n }, [onClose]);\n\n /**\n * This function closes the body\n */\n const handleClick = useCallback(\n (event: MouseEvent) => {\n if (\n ref.current &&\n shouldShowDropdown &&\n !anchorElement.contains(event.target as Node) &&\n !ref.current.contains(event.target as Node)\n ) {\n event.preventDefault();\n event.stopPropagation();\n\n const shouldPreventCloseOnClick = onOutsideClick?.() ?? false;\n\n if (!shouldPreventClickRef.current && !shouldPreventCloseOnClick) {\n handleClose();\n }\n }\n\n shouldPreventClickRef.current = false;\n },\n [anchorElement, handleClose, onOutsideClick, shouldShowDropdown],\n );\n\n const handleContentMeasure = useCallback(\n (measurements: DropdownMeasurements) => {\n // Measurements are only needed if the content is shown in the chayns wallet. To prevent\n // unnecessary renders, we only set the height if the content is shown in the wallet.\n if (isInChaynsWalletRef.current) {\n setMeasuredContentHeight(measurements.height);\n }\n\n if (typeof onMeasure === 'function') {\n onMeasure(measurements);\n }\n },\n [onMeasure],\n );\n\n const handleTouchEnd = useCallback(() => {\n clearTimeout(touchTimeoutRef.current);\n }, []);\n\n const handleTouchStart = useCallback(() => {\n touchTimeoutRef.current = window.setTimeout(() => {\n shouldPreventClickRef.current = true;\n }, 500);\n }, []);\n\n /**\n * This hook listens for clicks\n */\n useDropdownListener({\n onClick: handleClick,\n onClose: handleClose,\n onTouchEnd: handleTouchEnd,\n onTouchStart: handleTouchStart,\n });\n\n useEffect(() => {\n const isBottomDirection = [\n DropdownDirection.BOTTOM,\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.BOTTOM_RIGHT,\n ].includes(direction);\n\n const reservationWrapperElement = anchorElement.closest<HTMLDivElement>(\n ContainerAnchor.RESERVATION_WRAPPER,\n );\n\n isInChaynsWalletRef.current =\n !!(reservationWrapperElement && reservationWrapperElement.contains(anchorElement)) ||\n true;\n\n // This effect checks if additional space is needed to show dropdown content in chayns cards.\n if (\n isBottomDirection &&\n isInChaynsWalletRef.current &&\n measuredContentHeight > 0 &&\n reservationWrapperElement &&\n shouldShowDropdown\n ) {\n const availableHeight =\n window.innerHeight - anchorElement.getBoundingClientRect().bottom;\n\n // If the content height is greater than the available height, we need to add additional space.\n // This is to ensure that the dropdown content is fully visible. The 16 pixels are a buffer for shadows.\n const additionalNeededSpace = measuredContentHeight + 16 - availableHeight;\n\n if (additionalNeededSpace > 0) {\n // Add margin bottom to the reservation wrapper to ensure the dropdown content is fully visible.\n reservationWrapperElement.style.marginBottom = `${additionalNeededSpace}px`;\n } else {\n // Reset the margin bottom if no additional space is needed.\n reservationWrapperElement.style.marginBottom = '0px';\n }\n }\n\n if (isInChaynsWalletRef.current && reservationWrapperElement && !shouldShowDropdown) {\n // Reset the margin bottom when the dropdown is closed.\n reservationWrapperElement.style.marginBottom = '0px';\n }\n\n return () => {\n if (reservationWrapperElement) {\n reservationWrapperElement.style.marginBottom = '0px';\n }\n };\n }, [anchorElement, direction, measuredContentHeight, shouldShowDropdown]);\n\n useEffect(() => {\n if (!container) return;\n\n setPortal(() =>\n createPortal(\n <DelayedDropdownContent\n coordinates={coordinates}\n onMeasure={handleContentMeasure}\n shouldShowContent={shouldShowDropdown}\n transform={transform}\n >\n <StyledDropdownBodyWrapperContent\n $width={width}\n $minWidth={minBodyWidth}\n $maxHeight={maxHeight}\n $direction={direction}\n ref={ref}\n >\n {children}\n </StyledDropdownBodyWrapperContent>\n </DelayedDropdownContent>,\n container,\n ),\n );\n }, [\n children,\n container,\n coordinates,\n direction,\n handleContentMeasure,\n maxHeight,\n minBodyWidth,\n shouldShowDropdown,\n transform,\n width,\n ]);\n\n return <StyledDropdownBodyWrapper>{portal}</StyledDropdownBodyWrapper>;\n};\n\nDropdownBodyWrapper.displayName = 'DropdownBodyWrapper';\n\nexport default DropdownBodyWrapper;\n"],"mappings":"AAAA,OAAOA,KAAK,IAAgCC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AACnG,SACIC,yBAAyB,EACzBC,gCAAgC,QAC7B,8BAA8B;AACrC,SAASC,YAAY,QAAQ,WAAW;AACxC,SAASC,iBAAiB,QAA8B,sBAAsB;AAC9E,OAAOC,sBAAsB,MAEtB,mD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E;QAC3BA,yBAAyB,CAACQ,KAAK,CAACC,YAAY,GAAG,KAAK;MACxD;IACJ,CAAC;EACL,CAAC,EAAE,CAAC3D,aAAa,EAAEM,SAAS,EAAES,qBAAqB,EAAEF,kBAAkB,CAAC,CAAC;EAEzE1B,SAAS,CAAC,MAAM;IACZ,IAAI,CAACgB,SAAS,EAAE;IAEhBe,SAAS,CAAC,mBACN1B,YAAY,cACRP,KAAA,CAAA2E,aAAA,CAAClE,sBAAsB;MACnB+B,WAAW,EAAEA,WAAY;MACzBb,SAAS,EAAEuB,oBAAqB;MAChC0B,iBAAiB,EAAEhD,kBAAmB;MACtCU,SAAS,EAAEA;IAAU,gBAErBtC,KAAA,CAAA2E,aAAA,CAACrE,gCAAgC;MAC7BuE,MAAM,EAAEtC,KAAM;MACduC,SAAS,EAAEtD,YAAa;MACxBuD,UAAU,EAAExD,SAAU;MACtByD,UAAU,EAAE3D,SAAU;MACtBa,GAAG,EAAEA;IAAI,GAERjB,QAC6B,CACd,CAAC,EACzBC,SACJ,CACJ,CAAC;EACL,CAAC,EAAE,CACCD,QAAQ,EACRC,SAAS,EACTsB,WAAW,EACXnB,SAAS,EACT6B,oBAAoB,EACpB3B,SAAS,EACTC,YAAY,EACZI,kBAAkB,EAClBU,SAAS,EACTC,KAAK,CACR,CAAC;EAEF,oBAAOvC,KAAA,CAAA2E,aAAA,CAACtE,yBAAyB,QAAE2B,MAAkC,CAAC;AAC1E,CAAC;AAEDlB,mBAAmB,CAACmE,WAAW,GAAG,qBAAqB;AAEvD,eAAenE,mBAAmB","ignoreList":[]}
@@ -1,4 +1,4 @@
1
- import React, { forwardRef, useCallback, useEffect, useMemo, useState, useImperativeHandle, useContext } from 'react';
1
+ import React, { forwardRef, useCallback, useEffect, useMemo, useState, useImperativeHandle, useContext, useRef } from 'react';
2
2
  import { useTheme } from 'styled-components';
3
3
  import { v4 as uuidv4 } from 'uuid';
4
4
  import Badge from '../badge/Badge';
@@ -6,19 +6,22 @@ import Icon from '../icon/Icon';
6
6
  import { StyledTagInput, StyledTagInputIconWrapper, StyledTagInputTagInput, StyledTagInputTagWrapper, StyledTagInputTagWrapperText } from './TagInput.styles';
7
7
  import { AreaContext } from '../area-provider/AreaContextProvider';
8
8
  const TagInput = /*#__PURE__*/forwardRef(({
9
- placeholder,
10
- tags,
11
- onRemove,
12
- onChange,
13
- onAdd,
14
9
  leftElement,
10
+ onAdd,
11
+ onBlur,
12
+ onChange,
13
+ onFocus,
14
+ onRemove,
15
+ placeholder,
15
16
  shouldAllowMultiple = true,
16
- shouldPreventEnter
17
+ shouldPreventEnter,
18
+ tags
17
19
  }, ref) => {
18
20
  const [internalTags, setInternalTags] = useState();
19
21
  const [currentValue, setCurrentValue] = useState('');
20
22
  const [selectedId, setSelectedId] = useState();
21
23
  const areaProvider = useContext(AreaContext);
24
+ const inputRef = useRef(null);
22
25
  const theme = useTheme();
23
26
  useEffect(() => {
24
27
  if (tags) {
@@ -30,6 +33,7 @@ const TagInput = /*#__PURE__*/forwardRef(({
30
33
  };
31
34
  const shouldChangeColor = useMemo(() => areaProvider.shouldChangeColor ?? false, [areaProvider.shouldChangeColor]);
32
35
  useImperativeHandle(ref, () => ({
36
+ blur: () => inputRef.current?.blur(),
33
37
  getUnsavedTagText: currentValue !== '' ? currentValue : undefined,
34
38
  resetValue: handleResetValue
35
39
  }), [currentValue]);
@@ -125,11 +129,14 @@ const TagInput = /*#__PURE__*/forwardRef(({
125
129
  return useMemo(() => /*#__PURE__*/React.createElement(StyledTagInput, {
126
130
  $shouldChangeColor: shouldChangeColor
127
131
  }, leftElement && /*#__PURE__*/React.createElement(StyledTagInputIconWrapper, null, leftElement), content, shouldShowInput && /*#__PURE__*/React.createElement(StyledTagInputTagInput, {
128
- placeholder: tags && tags.length > 0 ? undefined : placeholder,
129
- onKeyDown: handleKeyDown,
132
+ onBlur: onBlur,
130
133
  onChange: handleChange,
134
+ onFocus: onFocus,
135
+ onKeyDown: handleKeyDown,
136
+ placeholder: tags && tags.length > 0 ? undefined : placeholder,
137
+ ref: inputRef,
131
138
  value: currentValue
132
- })), [content, currentValue, handleChange, handleKeyDown, leftElement, placeholder, shouldChangeColor, shouldShowInput, tags]);
139
+ })), [content, currentValue, handleChange, handleKeyDown, leftElement, onBlur, onFocus, placeholder, shouldChangeColor, shouldShowInput, tags]);
133
140
  });
134
141
  export default TagInput;
135
142
  //# sourceMappingURL=TagInput.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TagInput.js","names":["React","forwardRef","useCallback","useEffect","useMemo","useState","useImperativeHandle","useContext","useTheme","v4","uuidv4","Badge","Icon","StyledTagInput","StyledTagInputIconWrapper","StyledTagInputTagInput","StyledTagInputTagWrapper","StyledTagInputTagWrapperText","AreaContext","TagInput","placeholder","tags","onRemove","onChange","onAdd","leftElement","shouldAllowMultiple","shouldPreventEnter","ref","internalTags","setInternalTags","currentValue","setCurrentValue","selectedId","setSelectedId","areaProvider","theme","slice","handleResetValue","shouldChangeColor","getUnsavedTagText","undefined","resetValue","handleKeyDown","event","key","prevValue","prevTags","length","newTag","id","text","newSelectedId","prevState","removedId","updatedTags","filter","tag","handleChange","target","value","handleIconClick","content","items","forEach","rightElement","push","createElement","backgroundColor","icons","onClick","preventDefault","stopPropagation","shouldShowInput","$shouldChangeColor","onKeyDown"],"sources":["../../../../src/components/tag-input/TagInput.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useState,\n type ChangeEvent,\n type KeyboardEvent,\n type ReactElement,\n useImperativeHandle,\n useContext,\n ChangeEventHandler,\n ReactNode,\n} from 'react';\nimport { useTheme } from 'styled-components';\nimport { v4 as uuidv4 } from 'uuid';\nimport type { Tag } from '../../types/tagInput';\nimport Badge from '../badge/Badge';\nimport Icon from '../icon/Icon';\nimport {\n StyledTagInput,\n StyledTagInputIconWrapper,\n StyledTagInputTagInput,\n StyledTagInputTagWrapper,\n StyledTagInputTagWrapperText,\n} from './TagInput.styles';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport type { Theme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport type TagInputProps = {\n /**\n * An element that should be displayed on the left side of the input.\n */\n leftElement?: ReactNode;\n /**\n * Function to be executed when a tag is added.\n */\n onAdd?: (tag: Tag) => void;\n /**\n * Function to be executed when the value of the input is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when a tag is removed.\n */\n onRemove?: (id: string) => void;\n /**\n * The placeholder that should be displayed.\n */\n placeholder?: string;\n /**\n * The tags that should be displayed.\n */\n tags?: Tag[];\n /**\n * Whether multiple tags should be allowed.\n */\n shouldAllowMultiple?: boolean;\n /**\n * Whether the enter key should be prevented.\n */\n shouldPreventEnter?: boolean;\n};\n\nexport type TagInputRef = {\n getUnsavedTagText: Tag['text'] | undefined;\n resetValue: () => void;\n};\n\nconst TagInput = forwardRef<TagInputRef, TagInputProps>(\n (\n {\n placeholder,\n tags,\n onRemove,\n onChange,\n onAdd,\n leftElement,\n shouldAllowMultiple = true,\n shouldPreventEnter,\n },\n ref,\n ) => {\n const [internalTags, setInternalTags] = useState<Tag[]>();\n const [currentValue, setCurrentValue] = useState('');\n const [selectedId, setSelectedId] = useState<Tag['id']>();\n\n const areaProvider = useContext(AreaContext);\n\n const theme = useTheme() as Theme;\n\n useEffect(() => {\n if (tags) {\n setInternalTags(shouldAllowMultiple ? tags : tags.slice(0, 1));\n }\n }, [shouldAllowMultiple, tags]);\n\n const handleResetValue = () => {\n setCurrentValue('');\n };\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n getUnsavedTagText: currentValue !== '' ? currentValue : undefined,\n resetValue: handleResetValue,\n }),\n [currentValue],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent) => {\n if (event.key === 'Enter' && !shouldPreventEnter) {\n setCurrentValue((prevValue) => {\n if (!prevValue) {\n return '';\n }\n\n setInternalTags((prevTags) => {\n if (!shouldAllowMultiple && (prevTags?.length ?? 0) > 0)\n return prevTags;\n\n const newTag = { id: uuidv4(), text: prevValue };\n\n if (typeof onAdd === 'function') {\n onAdd(newTag);\n }\n\n return prevTags ? [...prevTags, newTag] : [newTag];\n });\n\n return '';\n });\n }\n\n if (event.key === 'Backspace' && currentValue === '') {\n if (!selectedId) {\n if (!internalTags) {\n return;\n }\n\n const newSelectedId = internalTags[internalTags.length - 1]?.id;\n\n setSelectedId(newSelectedId);\n\n return;\n }\n\n setInternalTags((prevState) => {\n if (!prevState) {\n return prevState;\n }\n\n const removedId = prevState[prevState.length - 1]?.id;\n\n if (!removedId) {\n return prevState;\n }\n\n const updatedTags = (prevState ?? []).filter((tag) => tag.id !== removedId);\n\n if (typeof onRemove === 'function') {\n onRemove(removedId);\n }\n\n setSelectedId(undefined);\n\n return updatedTags;\n });\n }\n },\n [\n currentValue,\n internalTags,\n onAdd,\n onRemove,\n selectedId,\n shouldAllowMultiple,\n shouldPreventEnter,\n ],\n );\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setCurrentValue(event.target.value);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n\n if (event.target.value !== '') {\n setSelectedId(undefined);\n }\n },\n [onChange],\n );\n\n const handleIconClick = useCallback(\n (id: string) => {\n setInternalTags((prevState) => {\n const updatedTags = (prevState ?? []).filter((tag) => tag.id !== id);\n\n if (typeof onRemove === 'function') {\n onRemove(id);\n }\n\n return updatedTags;\n });\n },\n [onRemove],\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n if (!internalTags) {\n return items;\n }\n\n internalTags.forEach(({ text, id, rightElement }) => {\n items.push(\n <Badge\n key={`tag-input-${id}`}\n backgroundColor={\n id === selectedId ? ((theme['206'] as string) ?? undefined) : undefined\n }\n >\n <StyledTagInputTagWrapper>\n <StyledTagInputTagWrapperText>{text}</StyledTagInputTagWrapperText>\n {rightElement}\n <Icon\n icons={['ts-wrong']}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n\n handleIconClick(id);\n }}\n />\n </StyledTagInputTagWrapper>\n </Badge>,\n );\n });\n\n return items;\n }, [handleIconClick, internalTags, selectedId, theme]);\n\n const shouldShowInput = useMemo(\n () => shouldAllowMultiple || (internalTags?.length ?? 0) < 1,\n [internalTags?.length, shouldAllowMultiple],\n );\n\n return useMemo(\n () => (\n <StyledTagInput $shouldChangeColor={shouldChangeColor}>\n {leftElement && (\n <StyledTagInputIconWrapper>{leftElement}</StyledTagInputIconWrapper>\n )}\n {content}\n {shouldShowInput && (\n <StyledTagInputTagInput\n placeholder={tags && tags.length > 0 ? undefined : placeholder}\n onKeyDown={handleKeyDown}\n onChange={handleChange}\n value={currentValue}\n />\n )}\n </StyledTagInput>\n ),\n [\n content,\n currentValue,\n handleChange,\n handleKeyDown,\n leftElement,\n placeholder,\n shouldChangeColor,\n shouldShowInput,\n tags,\n ],\n );\n },\n);\n\nexport default TagInput;\n"],"mappings":"AAAA,OAAOA,KAAK,IACRC,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,QAAQ,EAIRC,mBAAmB,EACnBC,UAAU,QAGP,OAAO;AACd,SAASC,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AAEnC,OAAOC,KAAK,MAAM,gBAAgB;AAClC,OAAOC,IAAI,MAAM,cAAc;AAC/B,SACIC,cAAc,EACdC,yBAAyB,EACzBC,sBAAsB,EACtBC,wBAAwB,EACxBC,4BAA4B,QACzB,mBAAmB;AAC1B,SAASC,WAAW,QAAQ,sCAAsC;AA2ClE,MAAMC,QAAQ,gBAAGlB,UAAU,CACvB,CACI;EACImB,WAAW;EACXC,IAAI;EACJC,QAAQ;EACRC,QAAQ;EACRC,KAAK;EACLC,WAAW;EACXC,mBAAmB,GAAG,IAAI;EAC1BC;AACJ,CAAC,EACDC,GAAG,KACF;EACD,MAAM,CAACC,YAAY,EAAEC,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IAAI,CAEZ,CAAC;AACL,CACJ,CAAC;AAED,eAAeF,QAAQ","ignoreList":[]}
1
+ {"version":3,"file":"TagInput.js","names":["React","forwardRef","useCallback","useEffect","useMemo","useState","useImperativeHandle","useContext","useRef","useTheme","v4","uuidv4","Badge","Icon","StyledTagInput","StyledTagInputIconWrapper","StyledTagInputTagInput","StyledTagInputTagWrapper","StyledTagInputTagWrapperText","AreaContext","TagInput","leftElement","onAdd","onBlur","onChange","onFocus","onRemove","placeholder","shouldAllowMultiple","shouldPreventEnter","tags","ref","internalTags","setInternalTags","currentValue","setCurrentValue","selectedId","setSelectedId","areaProvider","inputRef","theme","slice","handleResetValue","shouldChangeColor","blur","current","getUnsavedTagText","undefined","resetValue","handleKeyDown","event","key","prevValue","prevTags","length","newTag","id","text","newSelectedId","prevState","removedId","updatedTags","filter","tag","handleChange","target","value","handleIconClick","content","items","forEach","rightElement","push","createElement","backgroundColor","icons","onClick","preventDefault","stopPropagation","shouldShowInput","$shouldChangeColor","onKeyDown"],"sources":["../../../../src/components/tag-input/TagInput.tsx"],"sourcesContent":["import React, {\n forwardRef,\n useCallback,\n useEffect,\n useMemo,\n useState,\n type ChangeEvent,\n type KeyboardEvent,\n type ReactElement,\n useImperativeHandle,\n useContext,\n ChangeEventHandler,\n ReactNode,\n FocusEventHandler,\n useRef,\n} from 'react';\nimport { useTheme } from 'styled-components';\nimport { v4 as uuidv4 } from 'uuid';\nimport type { Tag } from '../../types/tagInput';\nimport Badge from '../badge/Badge';\nimport Icon from '../icon/Icon';\nimport {\n StyledTagInput,\n StyledTagInputIconWrapper,\n StyledTagInputTagInput,\n StyledTagInputTagWrapper,\n StyledTagInputTagWrapperText,\n} from './TagInput.styles';\nimport { AreaContext } from '../area-provider/AreaContextProvider';\nimport type { Theme } from '../color-scheme-provider/ColorSchemeProvider';\n\nexport type TagInputProps = {\n /**\n * An element that should be displayed on the left side of the input.\n */\n leftElement?: ReactNode;\n /**\n * Function to be executed when a tag is added.\n */\n onAdd?: (tag: Tag) => void;\n /**\n * Function to be executed when the input is blurred.\n */\n onBlur?: FocusEventHandler;\n /**\n * Function to be executed when the value of the input is changed.\n */\n onChange?: ChangeEventHandler<HTMLInputElement>;\n /**\n * Function to be executed when the input is focused.\n */\n onFocus?: FocusEventHandler;\n /**\n * Function to be executed when a tag is removed.\n */\n onRemove?: (id: string) => void;\n /**\n * The placeholder that should be displayed.\n */\n placeholder?: string;\n /**\n * Whether multiple tags should be allowed.\n */\n shouldAllowMultiple?: boolean;\n /**\n * Whether the enter key should be prevented.\n */\n shouldPreventEnter?: boolean;\n /**\n * The tags that should be displayed.\n */\n tags?: Tag[];\n};\n\nexport type TagInputRef = {\n blur: () => void;\n getUnsavedTagText: Tag['text'] | undefined;\n resetValue: () => void;\n};\n\nconst TagInput = forwardRef<TagInputRef, TagInputProps>(\n (\n {\n leftElement,\n onAdd,\n onBlur,\n onChange,\n onFocus,\n onRemove,\n placeholder,\n shouldAllowMultiple = true,\n shouldPreventEnter,\n tags,\n },\n ref,\n ) => {\n const [internalTags, setInternalTags] = useState<Tag[]>();\n const [currentValue, setCurrentValue] = useState('');\n const [selectedId, setSelectedId] = useState<Tag['id']>();\n\n const areaProvider = useContext(AreaContext);\n\n const inputRef = useRef<HTMLInputElement | null>(null);\n\n const theme = useTheme() as Theme;\n\n useEffect(() => {\n if (tags) {\n setInternalTags(shouldAllowMultiple ? tags : tags.slice(0, 1));\n }\n }, [shouldAllowMultiple, tags]);\n\n const handleResetValue = () => {\n setCurrentValue('');\n };\n\n const shouldChangeColor = useMemo(\n () => areaProvider.shouldChangeColor ?? false,\n [areaProvider.shouldChangeColor],\n );\n\n useImperativeHandle(\n ref,\n () => ({\n blur: () => inputRef.current?.blur(),\n getUnsavedTagText: currentValue !== '' ? currentValue : undefined,\n resetValue: handleResetValue,\n }),\n [currentValue],\n );\n\n const handleKeyDown = useCallback(\n (event: KeyboardEvent) => {\n if (event.key === 'Enter' && !shouldPreventEnter) {\n setCurrentValue((prevValue) => {\n if (!prevValue) {\n return '';\n }\n\n setInternalTags((prevTags) => {\n if (!shouldAllowMultiple && (prevTags?.length ?? 0) > 0)\n return prevTags;\n\n const newTag = { id: uuidv4(), text: prevValue };\n\n if (typeof onAdd === 'function') {\n onAdd(newTag);\n }\n\n return prevTags ? [...prevTags, newTag] : [newTag];\n });\n\n return '';\n });\n }\n\n if (event.key === 'Backspace' && currentValue === '') {\n if (!selectedId) {\n if (!internalTags) {\n return;\n }\n\n const newSelectedId = internalTags[internalTags.length - 1]?.id;\n\n setSelectedId(newSelectedId);\n\n return;\n }\n\n setInternalTags((prevState) => {\n if (!prevState) {\n return prevState;\n }\n\n const removedId = prevState[prevState.length - 1]?.id;\n\n if (!removedId) {\n return prevState;\n }\n\n const updatedTags = (prevState ?? []).filter((tag) => tag.id !== removedId);\n\n if (typeof onRemove === 'function') {\n onRemove(removedId);\n }\n\n setSelectedId(undefined);\n\n return updatedTags;\n });\n }\n },\n [\n currentValue,\n internalTags,\n onAdd,\n onRemove,\n selectedId,\n shouldAllowMultiple,\n shouldPreventEnter,\n ],\n );\n\n const handleChange = useCallback(\n (event: ChangeEvent<HTMLInputElement>) => {\n setCurrentValue(event.target.value);\n\n if (typeof onChange === 'function') {\n onChange(event);\n }\n\n if (event.target.value !== '') {\n setSelectedId(undefined);\n }\n },\n [onChange],\n );\n\n const handleIconClick = useCallback(\n (id: string) => {\n setInternalTags((prevState) => {\n const updatedTags = (prevState ?? []).filter((tag) => tag.id !== id);\n\n if (typeof onRemove === 'function') {\n onRemove(id);\n }\n\n return updatedTags;\n });\n },\n [onRemove],\n );\n\n const content = useMemo(() => {\n const items: ReactElement[] = [];\n\n if (!internalTags) {\n return items;\n }\n\n internalTags.forEach(({ text, id, rightElement }) => {\n items.push(\n <Badge\n key={`tag-input-${id}`}\n backgroundColor={\n id === selectedId ? ((theme['206'] as string) ?? undefined) : undefined\n }\n >\n <StyledTagInputTagWrapper>\n <StyledTagInputTagWrapperText>{text}</StyledTagInputTagWrapperText>\n {rightElement}\n <Icon\n icons={['ts-wrong']}\n onClick={(event) => {\n event.preventDefault();\n event.stopPropagation();\n\n handleIconClick(id);\n }}\n />\n </StyledTagInputTagWrapper>\n </Badge>,\n );\n });\n\n return items;\n }, [handleIconClick, internalTags, selectedId, theme]);\n\n const shouldShowInput = useMemo(\n () => shouldAllowMultiple || (internalTags?.length ?? 0) < 1,\n [internalTags?.length, shouldAllowMultiple],\n );\n\n return useMemo(\n () => (\n <StyledTagInput $shouldChangeColor={shouldChangeColor}>\n {leftElement && (\n <StyledTagInputIconWrapper>{leftElement}</StyledTagInputIconWrapper>\n )}\n {content}\n {shouldShowInput && (\n <StyledTagInputTagInput\n onBlur={onBlur}\n onChange={handleChange}\n onFocus={onFocus}\n onKeyDown={handleKeyDown}\n placeholder={tags && tags.length > 0 ? undefined : placeholder}\n ref={inputRef}\n value={currentValue}\n />\n )}\n </StyledTagInput>\n ),\n [\n content,\n currentValue,\n handleChange,\n handleKeyDown,\n leftElement,\n onBlur,\n onFocus,\n placeholder,\n shouldChangeColor,\n shouldShowInput,\n tags,\n ],\n );\n },\n);\n\nexport default TagInput;\n"],"mappings":"AAAA,OAAOA,KAAK,IACRC,UAAU,EACVC,WAAW,EACXC,SAAS,EACTC,OAAO,EACPC,QAAQ,EAIRC,mBAAmB,EACnBC,UAAU,EAIVC,MAAM,QACH,OAAO;AACd,SAASC,QAAQ,QAAQ,mBAAmB;AAC5C,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AAEnC,OAAOC,KAAK,MAAM,gBAAgB;AAClC,OAAOC,IAAI,MAAM,cAAc;AAC/B,SACIC,cAAc,EACdC,yBAAyB,EACzBC,sBAAsB,EACtBC,wBAAwB,EACxBC,4BAA4B,QACzB,mBAAmB;AAC1B,SAASC,WAAW,QAAQ,sCAAsC;AAoDlE,MAAMC,QAAQ,gBAAGnB,UAAU,CACvB,CACI;EACIoB,WAAW;EACXC,KAAK;EACLC,MAAM;EACNC,QAAQ;EACRC,OAAO;EACPC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Aa;IACvBvC,OAAO,EAAEA,OAAQ;IACjBwD,SAAS,EAAEhC,aAAc;IACzBtB,WAAW,EAAEG,IAAI,IAAIA,IAAI,CAACwB,MAAM,GAAG,CAAC,GAAGP,SAAS,GAAGpB,WAAY;IAC/DI,GAAG,EAAEQ,QAAS;IACd2B,KAAK,EAAEhC;EAAa,CACvB,CAEO,CACnB,EACD,CACIkC,OAAO,EACPlC,YAAY,EACZ8B,YAAY,EACZf,aAAa,EACb5B,WAAW,EACXE,MAAM,EACNE,OAAO,EACPE,WAAW,EACXgB,iBAAiB,EACjBoC,eAAe,EACfjD,IAAI,CAEZ,CAAC;AACL,CACJ,CAAC;AAED,eAAeV,QAAQ","ignoreList":[]}
@@ -8,15 +8,15 @@ export const useDropdownListener = ({
8
8
  onTouchStart
9
9
  }) => {
10
10
  useEffect(() => {
11
- document.addEventListener('click', onClick);
12
- document.addEventListener('touchend', onTouchEnd);
13
- document.addEventListener('touchstart', onTouchStart);
14
- window.addEventListener('blur', () => onClose());
11
+ document.addEventListener('click', onClick, true);
12
+ document.addEventListener('touchend', onTouchEnd, true);
13
+ document.addEventListener('touchstart', onTouchStart, true);
14
+ window.addEventListener('blur', () => onClose(), true);
15
15
  return () => {
16
- document.removeEventListener('click', onClick);
17
- document.removeEventListener('touchend', onTouchEnd);
18
- document.removeEventListener('touchstart', onTouchStart);
19
- window.addEventListener('blur', () => onClose());
16
+ document.removeEventListener('click', onClick, true);
17
+ document.removeEventListener('touchend', onTouchEnd, true);
18
+ document.removeEventListener('touchstart', onTouchStart, true);
19
+ window.addEventListener('blur', () => onClose(), true);
20
20
  };
21
21
  }, [onClick, onClose, onTouchEnd, onTouchStart]);
22
22
  };
@@ -1 +1 @@
1
- {"version":3,"file":"dropdown.js","names":["useCallback","useEffect","useLayoutEffect","useMemo","useState","DropdownDirection","useIsomorphicLayoutEffect","window","useDropdownListener","onClick","onClose","onTouchEnd","onTouchStart","document","addEventListener","removeEventListener","useDropdownAlignment","direction","shouldUseTopAlignment","anchorElement","bodyWidth","translateX","setTranslateX","translateY","setTranslateY","BOTTOM_LEFT","TOP_LEFT","LEFT","includes","difference","clientWidth","useTopAlignment","TOP","TOP_RIGHT","x","y","useDropdownPosition","container","contentHeight","shouldShowDropdown","coordinates","setCoordinates","setShouldUseTopAlignment","calculateCoordinates","left","anchorLeft","top","anchorTop","height","anchorHeight","getBoundingClientRect","scrollLeft","scrollTop","hasBottomAlignment","BOTTOM","BOTTOM_RIGHT","handleResize","setTimeout","useDropdown","transform","width"],"sources":["../../../src/hooks/dropdown.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';\nimport { DropdownCoordinates, DropdownDirection } from '../types/dropdown';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\ninterface UseDropdownListenerOptions {\n onClick: (event: MouseEvent) => void;\n onClose: () => void;\n onTouchEnd: (event: TouchEvent) => void;\n onTouchStart: (event: TouchEvent) => void;\n}\n\nexport const useDropdownListener = ({\n onClick,\n onClose,\n onTouchEnd,\n onTouchStart,\n}: UseDropdownListenerOptions) => {\n useEffect(() => {\n document.addEventListener('click', onClick);\n document.addEventListener('touchend', onTouchEnd);\n document.addEventListener('touchstart', onTouchStart);\n\n window.addEventListener('blur', () => onClose());\n\n return () => {\n document.removeEventListener('click', onClick);\n document.removeEventListener('touchend', onTouchEnd);\n document.removeEventListener('touchstart', onTouchStart);\n\n window.addEventListener('blur', () => onClose());\n };\n }, [onClick, onClose, onTouchEnd, onTouchStart]);\n};\n\ninterface UseDropdownAlignmentOptions {\n direction: DropdownDirection;\n shouldUseTopAlignment: boolean;\n bodyWidth?: number;\n anchorElement: Element;\n}\n\nexport const useDropdownAlignment = ({\n direction,\n shouldUseTopAlignment,\n anchorElement,\n bodyWidth,\n}: UseDropdownAlignmentOptions) => {\n const [translateX, setTranslateX] = useState<string>('0px');\n const [translateY, setTranslateY] = useState<string>('0px');\n\n useEffect(() => {\n if (\n [\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.LEFT,\n ].includes(direction) &&\n typeof bodyWidth === 'number'\n ) {\n const difference = anchorElement.clientWidth - bodyWidth;\n\n setTranslateX(`${difference}px`);\n } else {\n setTranslateX('0px');\n }\n }, [anchorElement.clientWidth, bodyWidth, direction]);\n\n useEffect(() => {\n const useTopAlignment =\n shouldUseTopAlignment ||\n [\n DropdownDirection.TOP,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.TOP_RIGHT,\n ].includes(direction);\n\n if (useTopAlignment) {\n setTranslateY('-100%');\n } else {\n setTranslateY('0px');\n }\n }, [direction, shouldUseTopAlignment]);\n\n return useMemo(() => ({ x: translateX, y: translateY }), [translateX, translateY]);\n};\n\ninterface UseDropdownPositionOptions {\n anchorElement: Element;\n container?: Element;\n contentHeight?: number;\n direction: DropdownDirection;\n shouldShowDropdown: boolean;\n}\n\nexport const useDropdownPosition = ({\n anchorElement,\n container,\n contentHeight = 0,\n direction,\n shouldShowDropdown,\n}: UseDropdownPositionOptions) => {\n const [coordinates, setCoordinates] = useState<DropdownCoordinates>({ x: 0, y: 0 });\n const [shouldUseTopAlignment, setShouldUseTopAlignment] = useState(false);\n\n const calculateCoordinates = useCallback(() => {\n if (container) {\n const {\n left: anchorLeft,\n top: anchorTop,\n height: anchorHeight,\n } = anchorElement.getBoundingClientRect();\n\n const { left, top, height } = container.getBoundingClientRect();\n\n const x = anchorLeft - left + container.scrollLeft;\n const y = anchorTop - top + container.scrollTop;\n\n let useTopAlignment = [\n DropdownDirection.TOP,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.TOP_RIGHT,\n ].includes(direction);\n\n const hasBottomAlignment = [\n DropdownDirection.BOTTOM,\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.BOTTOM_RIGHT,\n ].includes(direction);\n\n if (!hasBottomAlignment && y + anchorHeight + contentHeight > height) {\n useTopAlignment = true;\n\n setShouldUseTopAlignment(true);\n } else {\n setShouldUseTopAlignment(false);\n }\n\n setCoordinates({ x, y: useTopAlignment ? y : y + anchorHeight });\n }\n }, [anchorElement, container, contentHeight, direction]);\n\n useIsomorphicLayoutEffect(() => {\n const handleResize = () => {\n calculateCoordinates();\n\n setTimeout(calculateCoordinates, 300);\n };\n\n handleResize();\n\n if (shouldShowDropdown) {\n window.addEventListener('resize', handleResize);\n }\n\n return () => {\n window.removeEventListener('resize', handleResize);\n };\n }, [calculateCoordinates, shouldShowDropdown]);\n\n return useMemo(\n () => ({ shouldUseTopAlignment, coordinates }),\n [coordinates, shouldUseTopAlignment],\n );\n};\n\ninterface UseDropdownOptions {\n anchorElement: Element;\n bodyWidth?: number;\n container?: Element;\n contentHeight?: number;\n direction: DropdownDirection;\n shouldShowDropdown: boolean;\n}\n\nexport const useDropdown = ({\n anchorElement,\n bodyWidth,\n container,\n contentHeight,\n direction,\n shouldShowDropdown,\n}: UseDropdownOptions) => {\n const { shouldUseTopAlignment, coordinates } = useDropdownPosition({\n anchorElement,\n container,\n contentHeight,\n direction,\n shouldShowDropdown,\n });\n\n const transform = useDropdownAlignment({\n shouldUseTopAlignment,\n bodyWidth,\n anchorElement,\n direction,\n });\n\n const width = anchorElement.clientWidth;\n\n return useMemo(() => ({ coordinates, transform, width }), [coordinates, transform, width]);\n};\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAClF,SAA8BC,iBAAiB,QAAQ,mBAAmB;AAE1E,MAAMC,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGL,eAAe,GAAGD,SAAS;AAS7F,OAAO,MAAMO,mBAAmB,GAAGA,CAAC;EAChCC,OAAO;EACPC,OAAO;EACPC,UAAU;EACVC;AACwB,CAAC,KAAK;EAC9BX,SAAS,CAAC,MAAM;IACZY,QAAQ,CAACC,gBAAgB,CAAC,OAAO,EAAEL,OAAO,CAAC;IAC3CI,QAAQ,CAACC,gBAA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L,CAAC,EAAE,CAACb,oBAAoB,EAAEJ,kBAAkB,CAAC,CAAC;EAE9C,OAAOpC,OAAO,CACV,OAAO;IAAEe,qBAAqB;IAAEsB;EAAY,CAAC,CAAC,EAC9C,CAACA,WAAW,EAAEtB,qBAAqB,CACvC,CAAC;AACL,CAAC;AAWD,OAAO,MAAMwC,WAAW,GAAGA,CAAC;EACxBvC,aAAa;EACbC,SAAS;EACTiB,SAAS;EACTC,aAAa;EACbrB,SAAS;EACTsB;AACgB,CAAC,KAAK;EACtB,MAAM;IAAErB,qBAAqB;IAAEsB;EAAY,CAAC,GAAGJ,mBAAmB,CAAC;IAC/DjB,aAAa;IACbkB,SAAS;IACTC,aAAa;IACbrB,SAAS;IACTsB;EACJ,CAAC,CAAC;EAEF,MAAMoB,SAAS,GAAG3C,oBAAoB,CAAC;IACnCE,qBAAqB;IACrBE,SAAS;IACTD,aAAa;IACbF;EACJ,CAAC,CAAC;EAEF,MAAM2C,KAAK,GAAGzC,aAAa,CAACW,WAAW;EAEvC,OAAO3B,OAAO,CAAC,OAAO;IAAEqC,WAAW;IAAEmB,SAAS;IAAEC;EAAM,CAAC,CAAC,EAAE,CAACpB,WAAW,EAAEmB,SAAS,EAAEC,KAAK,CAAC,CAAC;AAC9F,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"dropdown.js","names":["useCallback","useEffect","useLayoutEffect","useMemo","useState","DropdownDirection","useIsomorphicLayoutEffect","window","useDropdownListener","onClick","onClose","onTouchEnd","onTouchStart","document","addEventListener","removeEventListener","useDropdownAlignment","direction","shouldUseTopAlignment","anchorElement","bodyWidth","translateX","setTranslateX","translateY","setTranslateY","BOTTOM_LEFT","TOP_LEFT","LEFT","includes","difference","clientWidth","useTopAlignment","TOP","TOP_RIGHT","x","y","useDropdownPosition","container","contentHeight","shouldShowDropdown","coordinates","setCoordinates","setShouldUseTopAlignment","calculateCoordinates","left","anchorLeft","top","anchorTop","height","anchorHeight","getBoundingClientRect","scrollLeft","scrollTop","hasBottomAlignment","BOTTOM","BOTTOM_RIGHT","handleResize","setTimeout","useDropdown","transform","width"],"sources":["../../../src/hooks/dropdown.ts"],"sourcesContent":["import { useCallback, useEffect, useLayoutEffect, useMemo, useState } from 'react';\nimport { DropdownCoordinates, DropdownDirection } from '../types/dropdown';\n\nconst useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\ninterface UseDropdownListenerOptions {\n onClick: (event: MouseEvent) => void;\n onClose: () => void;\n onTouchEnd: (event: TouchEvent) => void;\n onTouchStart: (event: TouchEvent) => void;\n}\n\nexport const useDropdownListener = ({\n onClick,\n onClose,\n onTouchEnd,\n onTouchStart,\n}: UseDropdownListenerOptions) => {\n useEffect(() => {\n document.addEventListener('click', onClick, true);\n document.addEventListener('touchend', onTouchEnd, true);\n document.addEventListener('touchstart', onTouchStart, true);\n\n window.addEventListener('blur', () => onClose(), true);\n\n return () => {\n document.removeEventListener('click', onClick, true);\n document.removeEventListener('touchend', onTouchEnd, true);\n document.removeEventListener('touchstart', onTouchStart, true);\n\n window.addEventListener('blur', () => onClose(), true);\n };\n }, [onClick, onClose, onTouchEnd, onTouchStart]);\n};\n\ninterface UseDropdownAlignmentOptions {\n direction: DropdownDirection;\n shouldUseTopAlignment: boolean;\n bodyWidth?: number;\n anchorElement: Element;\n}\n\nexport const useDropdownAlignment = ({\n direction,\n shouldUseTopAlignment,\n anchorElement,\n bodyWidth,\n}: UseDropdownAlignmentOptions) => {\n const [translateX, setTranslateX] = useState<string>('0px');\n const [translateY, setTranslateY] = useState<string>('0px');\n\n useEffect(() => {\n if (\n [\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.LEFT,\n ].includes(direction) &&\n typeof bodyWidth === 'number'\n ) {\n const difference = anchorElement.clientWidth - bodyWidth;\n\n setTranslateX(`${difference}px`);\n } else {\n setTranslateX('0px');\n }\n }, [anchorElement.clientWidth, bodyWidth, direction]);\n\n useEffect(() => {\n const useTopAlignment =\n shouldUseTopAlignment ||\n [\n DropdownDirection.TOP,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.TOP_RIGHT,\n ].includes(direction);\n\n if (useTopAlignment) {\n setTranslateY('-100%');\n } else {\n setTranslateY('0px');\n }\n }, [direction, shouldUseTopAlignment]);\n\n return useMemo(() => ({ x: translateX, y: translateY }), [translateX, translateY]);\n};\n\ninterface UseDropdownPositionOptions {\n anchorElement: Element;\n container?: Element;\n contentHeight?: number;\n direction: DropdownDirection;\n shouldShowDropdown: boolean;\n}\n\nexport const useDropdownPosition = ({\n anchorElement,\n container,\n contentHeight = 0,\n direction,\n shouldShowDropdown,\n}: UseDropdownPositionOptions) => {\n const [coordinates, setCoordinates] = useState<DropdownCoordinates>({ x: 0, y: 0 });\n const [shouldUseTopAlignment, setShouldUseTopAlignment] = useState(false);\n\n const calculateCoordinates = useCallback(() => {\n if (container) {\n const {\n left: anchorLeft,\n top: anchorTop,\n height: anchorHeight,\n } = anchorElement.getBoundingClientRect();\n\n const { left, top, height } = container.getBoundingClientRect();\n\n const x = anchorLeft - left + container.scrollLeft;\n const y = anchorTop - top + container.scrollTop;\n\n let useTopAlignment = [\n DropdownDirection.TOP,\n DropdownDirection.TOP_LEFT,\n DropdownDirection.TOP_RIGHT,\n ].includes(direction);\n\n const hasBottomAlignment = [\n DropdownDirection.BOTTOM,\n DropdownDirection.BOTTOM_LEFT,\n DropdownDirection.BOTTOM_RIGHT,\n ].includes(direction);\n\n if (!hasBottomAlignment && y + anchorHeight + contentHeight > height) {\n useTopAlignment = true;\n\n setShouldUseTopAlignment(true);\n } else {\n setShouldUseTopAlignment(false);\n }\n\n setCoordinates({ x, y: useTopAlignment ? y : y + anchorHeight });\n }\n }, [anchorElement, container, contentHeight, direction]);\n\n useIsomorphicLayoutEffect(() => {\n const handleResize = () => {\n calculateCoordinates();\n\n setTimeout(calculateCoordinates, 300);\n };\n\n handleResize();\n\n if (shouldShowDropdown) {\n window.addEventListener('resize', handleResize);\n }\n\n return () => {\n window.removeEventListener('resize', handleResize);\n };\n }, [calculateCoordinates, shouldShowDropdown]);\n\n return useMemo(\n () => ({ shouldUseTopAlignment, coordinates }),\n [coordinates, shouldUseTopAlignment],\n );\n};\n\ninterface UseDropdownOptions {\n anchorElement: Element;\n bodyWidth?: number;\n container?: Element;\n contentHeight?: number;\n direction: DropdownDirection;\n shouldShowDropdown: boolean;\n}\n\nexport const useDropdown = ({\n anchorElement,\n bodyWidth,\n container,\n contentHeight,\n direction,\n shouldShowDropdown,\n}: UseDropdownOptions) => {\n const { shouldUseTopAlignment, coordinates } = useDropdownPosition({\n anchorElement,\n container,\n contentHeight,\n direction,\n shouldShowDropdown,\n });\n\n const transform = useDropdownAlignment({\n shouldUseTopAlignment,\n bodyWidth,\n anchorElement,\n direction,\n });\n\n const width = anchorElement.clientWidth;\n\n return useMemo(() => ({ coordinates, transform, width }), [coordinates, transform, width]);\n};\n"],"mappings":"AAAA,SAASA,WAAW,EAAEC,SAAS,EAAEC,eAAe,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAClF,SAA8BC,iBAAiB,QAAQ,mBAAmB;AAE1E,MAAMC,yBAAyB,GAAG,OAAOC,MAAM,KAAK,WAAW,GAAGL,eAAe,GAAGD,SAAS;AAS7F,OAAO,MAAMO,mBAAmB,GAAGA,CAAC;EAChCC,OAAO;EACPC,OAAO;EACPC,UAAU;EACVC;AACwB,CAAC,KAAK;EAC9BX,SAAS,CAAC,MAAM;IACZY,QAAQ,CAACC,gBAAgB,CAAC,OAAO,EAAEL,OAAO,EAAE,IAAI,CAAC;IACjDI,QAAQ,CAACC,gBAAgB,CAAC,UAAU,EAAEH,UAAU,EAAE,IAAI,CAAC;IACvDE,QAAQ,CAACC,gBAAgB,CAAC,YAAY,EAAEF,YAAY,EAAE,IAAI,CAAC;IAE3DL,MAAM,CAACO,gBAAgB,CAAC,MAAM,EAAE,MAAMJ,OAAO,CAAC,CAAC,EAAE,IAAI,CAAC;IAEtD,OAAO,MAA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CAACA,WAAW,EAAEtB,qBAAqB,CACvC,CAAC;AACL,CAAC;AAWD,OAAO,MAAMwC,WAAW,GAAGA,CAAC;EACxBvC,aAAa;EACbC,SAAS;EACTiB,SAAS;EACTC,aAAa;EACbrB,SAAS;EACTsB;AACgB,CAAC,KAAK;EACtB,MAAM;IAAErB,qBAAqB;IAAEsB;EAAY,CAAC,GAAGJ,mBAAmB,CAAC;IAC/DjB,aAAa;IACbkB,SAAS;IACTC,aAAa;IACbrB,SAAS;IACTsB;EACJ,CAAC,CAAC;EAEF,MAAMoB,SAAS,GAAG3C,oBAAoB,CAAC;IACnCE,qBAAqB;IACrBE,SAAS;IACTD,aAAa;IACbF;EACJ,CAAC,CAAC;EAEF,MAAM2C,KAAK,GAAGzC,aAAa,CAACW,WAAW;EAEvC,OAAO3B,OAAO,CAAC,OAAO;IAAEqC,WAAW;IAAEmB,SAAS;IAAEC;EAAM,CAAC,CAAC,EAAE,CAACpB,WAAW,EAAEmB,SAAS,EAAEC,KAAK,CAAC,CAAC;AAC9F,CAAC","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["default","Accordion","AccordionContent","AccordionGroup","AccordionIntro","AccordionItem","AmountControl","VerificationBadge","AreaContext","AreaProvider","Badge","Button","Checkbox","ColorSchemeProvider","useColorScheme","BadgeSize","BadgeDesign","useContainer","ContainerAnchor","DropdownDirection","useIsMeasuredClone","useCombinedRefs","FileList","FileSelect","DropdownBodyWrapper","ComboBox","ContentCard","HighlightSLider","ContextMenu","ExpandableContent","FileInput","FilterButton","FilterButtons","GridImage","GroupedImage","Icon","Input","InputSize","List","ListItemContent","ListItem","MentionFinder","NumberInput","PageProvider","Popup","PopupContent","ProgressBar","PopupAlignment","RadioButtonGroup","RadioButton","ScrollView","SearchBox","SearchInput","SelectButton","SetupWizardItem","SetupWizard","SharingBar","Signature","SliderButton","Slider","SmallWaitCursor","SmallWaitCursorSize","SmallWaitCursorSpeed","TagInput","TextArea","Tooltip","Truncation","MentionFinderPopupAlignment","useElementSize","ContentCardType","ContextMenuAlignment","isValidFileType","FilterButtonItemShape","FilterButtonSize","ClampPosition","getIsTouch","filterFilesByMimeType","getFileAsArrayBuffer","selectFiles","isTobitEmployee","getUsableHeight","uploadFile"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as Accordion } from './components/accordion/Accordion';\nexport { default as AccordionContent } from './components/accordion/accordion-content/AccordionContent';\nexport { default as AccordionGroup } from './components/accordion/accordion-group/AccordionGroup';\nexport { default as AccordionIntro } from './components/accordion/accordion-intro/AccordionIntro';\nexport { default as AccordionItem } from './components/accordion/accordion-item/AccordionItem';\nexport { default as AmountControl } from './components/amount-control/AmountControl';\nexport { default as VerificationBadge } from './components/verification-badge/VerificationBadge';\nexport {\n AreaContext,\n default as AreaProvider,\n} from './components/area-provider/AreaContextProvider';\nexport { default as Badge } from './components/badge/Badge';\nexport { default as Button } from './components/button/Button';\nexport { default as Checkbox } from './components/checkbox/Checkbox';\nexport {\n default as ColorSchemeProvider,\n useColorScheme,\n} from './components/color-scheme-provider/ColorSchemeProvider';\nexport { BadgeSize, BadgeDesign } from './types/badge';\nexport type {\n ColorSchemeContextProps,\n WithTheme,\n} from './components/color-scheme-provider/ColorSchemeProvider';\nexport { useContainer, ContainerAnchor } from './hooks/container';\nexport { DropdownDirection, type DropdownCoordinates } from './types/dropdown';\nexport { useIsMeasuredClone } from './hooks/element';\nexport { useCombinedRefs } from './hooks/ref';\nexport {\n default as FileList,\n type IFileItem as FileListItem,\n} from './components/file-list/FileList';\nexport { default as FileSelect } from './components/file-select/FileSelect';\nexport { default as DropdownBodyWrapper } from './components/dropdown-body-wrapper/DropdownBodyWrapper';\nexport {\n default as ComboBox,\n type ComboBoxTextStyles,\n type IComboBoxItem as ComboBoxItem,\n type IComboBoxItems as ComboBoxItems,\n} from './components/combobox/ComboBox';\nexport { default as ContentCard } from './components/content-card/ContentCard';\nexport { default as HighlightSLider } from './components/highlight-slider/HighlightSlider';\nexport type { HighlightSliderItemColors as HighlightSliderColors } from './components/highlight-slider/highlight-slider-item/HighlightSliderItem';\nexport {\n default as ContextMenu,\n type ContextMenuCoordinates,\n type ContextMenuItem,\n type ContextMenuRef,\n} from './components/context-menu/ContextMenu';\nexport { default as ExpandableContent } from './components/expandable-content/ExpandableContent';\nexport { default as FileInput, type FileInputRef } from './components/file-input/FileInput';\nexport { default as FilterButton } from './components/filter-buttons/filter-button/FilterButton';\nexport { default as FilterButtons } from './components/filter-buttons/FilterButtons';\nexport { default as GridImage } from './components/grid-image/GridImage';\nexport { default as GroupedImage } from './components/grouped-image/GroupedImage';\nexport { default as Icon } from './components/icon/Icon';\nexport { default as Input, InputSize } from './components/input/Input';\nexport { default as List } from './components/list/List';\nexport { default as ListItemContent } from './components/list/list-item/list-item-content/ListItemContent';\nexport {\n default as ListItem,\n type ListItemElements,\n type ListItemProps,\n} from './components/list/list-item/ListItem';\nexport { default as MentionFinder } from './components/mention-finder/MentionFinder';\nexport type { MentionMember } from './components/mention-finder/MentionFinder';\nexport { default as NumberInput } from './components/number-input/NumberInput';\nexport { default as PageProvider } from './components/page-provider/PageProvider';\nexport { default as Popup } from './components/popup/Popup';\nexport { default as PopupContent } from './components/popup/popup-content/PopupContent';\nexport { default as ProgressBar } from './components/progress-bar/ProgressBar';\nexport { PopupAlignment } from './types/popup';\nexport {\n default as RadioButtonGroup,\n type RadioButtonGroupRef,\n} from './components/radio-button/radio-button-group/RadioButtonGroup';\nexport { default as RadioButton } from './components/radio-button/RadioButton';\nexport { default as ScrollView } from './components/scroll-view/ScrollView';\nexport { default as SearchBox } from './components/search-box/SearchBox';\nexport { default as SearchInput } from './components/search-input/SearchInput';\nexport { default as SelectButton } from './components/select-button/SelectButton';\nexport { default as SetupWizardItem } from './components/setup-wizard/setup-wizard-item/SetupWizardItem';\nexport { default as SetupWizard } from './components/setup-wizard/SetupWizard';\nexport type { SetupWizardRef } from './components/setup-wizard/SetupWizard';\nexport { default as SharingBar } from './components/sharing-bar/SharingBar';\nexport { default as Signature } from './components/signature/Signature';\nexport type { SignatureRef } from './components/signature/Signature';\nexport { default as SliderButton } from './components/slider-button/SliderButton';\nexport { default as Slider } from './components/slider/Slider';\nexport {\n default as SmallWaitCursor,\n SmallWaitCursorSize,\n SmallWaitCursorSpeed,\n} from './components/small-wait-cursor/SmallWaitCursor';\nexport { default as TagInput } from './components/tag-input/TagInput';\nexport { default as TextArea } from './components/text-area/TextArea';\nexport { default as Tooltip } from './components/tooltip/Tooltip';\nexport { default as Truncation } from './components/truncation/Truncation';\nexport { MentionFinderPopupAlignment } from './constants/mentionFinder';\nexport { useElementSize } from './hooks/element';\nexport type { BrowserName } from './types/chayns';\nexport { ContentCardType } from './types/contentCard';\nexport { ContextMenuAlignment } from './types/contextMenu';\nexport type { FileItem, Image, InternalFileItem, Meta, Video } from './types/file';\nexport { isValidFileType } from './utils/file';\nexport type { FileInputFileItem } from './types/fileInput';\nexport { FilterButtonItemShape, FilterButtonSize } from './types/filterButtons';\nexport type { IFilterButtonItem as FilterButtonItem } from './types/filterButtons';\nexport type { IListItemRightElements } from './types/list';\nexport type { PopupRef } from './types/popup';\nexport type { RadioButtonItem } from './types/radioButton';\nexport type {\n ISearchBoxItem as SearchBoxItem,\n ISearchBoxItems as SearchBoxItems,\n} from './types/searchBox';\nexport type { SelectButtonItem } from './types/selectButton';\nexport type { SliderButtonItem } from './types/slider-button';\nexport { ClampPosition } from './types/truncation';\nexport { getIsTouch } from './utils/environment';\nexport { filterFilesByMimeType, getFileAsArrayBuffer, selectFiles } from './utils/fileDialog';\nexport { isTobitEmployee } from './utils/isTobitEmployee';\nexport { getUsableHeight } from './utils/pageProvider';\nexport { uploadFile } from './utils/uploadFile';\nexport type { Theme } from './components/color-scheme-provider/ColorSchemeProvider';\n"],"mappings":"AAAA;;AAEA,SAASA,OAAO,IAAIC,SAAS,QAAQ,kCAAkC;AACvE,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,2DAA2D;AACv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,SAASzD,OAAO,IAAI0D,YAAY,QAAQ,yCAAyC;AACjF,SAAS1D,OAAO,IAAI2D,MAAM,QAAQ,4BAA4B;AAC9D,SACI3D,OAAO,IAAI4D,eAAe,EAC1BC,mBAAmB,EACnBC,oBAAoB,QACjB,gDAAgD;AACvD,SAAS9D,OAAO,IAAI+D,QAAQ,QAAQ,iCAAiC;AACrE,SAAS/D,OAAO,IAAIgE,QAAQ,QAAQ,iCAAiC;AACrE,SAAShE,OAAO,IAAIiE,OAAO,QAAQ,8BAA8B;AACjE,SAASjE,OAAO,IAAIkE,UAAU,QAAQ,oCAAoC;AAC1E,SAASC,2BAA2B,QAAQ,2BAA2B;AACvE,SAASC,cAAc,QAAQ,iBAAiB;AAEhD,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,oBAAoB,QAAQ,qBAAqB;AAE1D,SAASC,eAAe,QAAQ,cAAc;AAE9C,SAASC,qBAAqB,EAAEC,gBAAgB,QAAQ,uBAAuB;AAW/E,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,qBAAqB,EAAEC,oBAAoB,EAAEC,WAAW,QAAQ,oBAAoB;AAC7F,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,UAAU,QAAQ,oBAAoB","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["default","Accordion","AccordionContent","AccordionGroup","AccordionIntro","AccordionItem","AmountControl","VerificationBadge","AreaContext","AreaProvider","Badge","Button","Checkbox","ColorSchemeProvider","useColorScheme","BadgeSize","BadgeDesign","useContainer","ContainerAnchor","DropdownDirection","useIsMeasuredClone","useCombinedRefs","FileList","FileSelect","DropdownBodyWrapper","ComboBox","ContentCard","HighlightSLider","ContextMenu","ExpandableContent","FileInput","FilterButton","FilterButtons","GridImage","GroupedImage","Icon","Input","InputSize","List","ListItemContent","ListItem","MentionFinder","NumberInput","PageProvider","Popup","PopupContent","ProgressBar","PopupAlignment","RadioButtonGroup","RadioButton","ScrollView","SearchBox","SearchInput","SelectButton","SetupWizardItem","SetupWizard","SharingBar","Signature","SliderButton","Slider","SmallWaitCursor","SmallWaitCursorSize","SmallWaitCursorSpeed","TagInput","TextArea","Tooltip","Truncation","MentionFinderPopupAlignment","useElementSize","ContentCardType","ContextMenuAlignment","isValidFileType","FilterButtonItemShape","FilterButtonSize","ClampPosition","getIsTouch","filterFilesByMimeType","getFileAsArrayBuffer","selectFiles","isTobitEmployee","getUsableHeight","uploadFile"],"sources":["../../src/index.ts"],"sourcesContent":["// noinspection JSUnusedGlobalSymbols\n\nexport { default as Accordion } from './components/accordion/Accordion';\nexport { default as AccordionContent } from './components/accordion/accordion-content/AccordionContent';\nexport { default as AccordionGroup } from './components/accordion/accordion-group/AccordionGroup';\nexport { default as AccordionIntro } from './components/accordion/accordion-intro/AccordionIntro';\nexport { default as AccordionItem } from './components/accordion/accordion-item/AccordionItem';\nexport { default as AmountControl } from './components/amount-control/AmountControl';\nexport { default as VerificationBadge } from './components/verification-badge/VerificationBadge';\nexport {\n AreaContext,\n default as AreaProvider,\n} from './components/area-provider/AreaContextProvider';\nexport { default as Badge } from './components/badge/Badge';\nexport { default as Button } from './components/button/Button';\nexport { default as Checkbox } from './components/checkbox/Checkbox';\nexport {\n default as ColorSchemeProvider,\n useColorScheme,\n} from './components/color-scheme-provider/ColorSchemeProvider';\nexport { BadgeSize, BadgeDesign } from './types/badge';\nexport type {\n ColorSchemeContextProps,\n WithTheme,\n} from './components/color-scheme-provider/ColorSchemeProvider';\nexport { useContainer, ContainerAnchor } from './hooks/container';\nexport { DropdownDirection, type DropdownCoordinates } from './types/dropdown';\nexport { useIsMeasuredClone } from './hooks/element';\nexport { useCombinedRefs } from './hooks/ref';\nexport {\n default as FileList,\n type IFileItem as FileListItem,\n} from './components/file-list/FileList';\nexport { default as FileSelect } from './components/file-select/FileSelect';\nexport { default as DropdownBodyWrapper } from './components/dropdown-body-wrapper/DropdownBodyWrapper';\nexport {\n default as ComboBox,\n type ComboBoxTextStyles,\n type IComboBoxItem as ComboBoxItem,\n type IComboBoxItems as ComboBoxItems,\n} from './components/combobox/ComboBox';\nexport { default as ContentCard } from './components/content-card/ContentCard';\nexport { default as HighlightSLider } from './components/highlight-slider/HighlightSlider';\nexport type { HighlightSliderItemColors as HighlightSliderColors } from './components/highlight-slider/highlight-slider-item/HighlightSliderItem';\nexport {\n default as ContextMenu,\n type ContextMenuCoordinates,\n type ContextMenuItem,\n type ContextMenuRef,\n} from './components/context-menu/ContextMenu';\nexport { default as ExpandableContent } from './components/expandable-content/ExpandableContent';\nexport { default as FileInput, type FileInputRef } from './components/file-input/FileInput';\nexport { default as FilterButton } from './components/filter-buttons/filter-button/FilterButton';\nexport { default as FilterButtons } from './components/filter-buttons/FilterButtons';\nexport { default as GridImage } from './components/grid-image/GridImage';\nexport { default as GroupedImage } from './components/grouped-image/GroupedImage';\nexport { default as Icon } from './components/icon/Icon';\nexport { default as Input, InputSize } from './components/input/Input';\nexport { default as List } from './components/list/List';\nexport { default as ListItemContent } from './components/list/list-item/list-item-content/ListItemContent';\nexport {\n default as ListItem,\n type ListItemElements,\n type ListItemProps,\n} from './components/list/list-item/ListItem';\nexport { default as MentionFinder } from './components/mention-finder/MentionFinder';\nexport type { MentionMember } from './components/mention-finder/MentionFinder';\nexport { default as NumberInput } from './components/number-input/NumberInput';\nexport { default as PageProvider } from './components/page-provider/PageProvider';\nexport { default as Popup } from './components/popup/Popup';\nexport { default as PopupContent } from './components/popup/popup-content/PopupContent';\nexport { default as ProgressBar } from './components/progress-bar/ProgressBar';\nexport { PopupAlignment } from './types/popup';\nexport {\n default as RadioButtonGroup,\n type RadioButtonGroupRef,\n} from './components/radio-button/radio-button-group/RadioButtonGroup';\nexport { default as RadioButton } from './components/radio-button/RadioButton';\nexport { default as ScrollView } from './components/scroll-view/ScrollView';\nexport { default as SearchBox } from './components/search-box/SearchBox';\nexport { default as SearchInput } from './components/search-input/SearchInput';\nexport { default as SelectButton } from './components/select-button/SelectButton';\nexport { default as SetupWizardItem } from './components/setup-wizard/setup-wizard-item/SetupWizardItem';\nexport { default as SetupWizard } from './components/setup-wizard/SetupWizard';\nexport type { SetupWizardRef } from './components/setup-wizard/SetupWizard';\nexport { default as SharingBar } from './components/sharing-bar/SharingBar';\nexport { default as Signature } from './components/signature/Signature';\nexport type { SignatureRef } from './components/signature/Signature';\nexport { default as SliderButton } from './components/slider-button/SliderButton';\nexport { default as Slider } from './components/slider/Slider';\nexport {\n default as SmallWaitCursor,\n SmallWaitCursorSize,\n SmallWaitCursorSpeed,\n} from './components/small-wait-cursor/SmallWaitCursor';\nexport type { Tag } from './types/tagInput';\nexport { default as TagInput } from './components/tag-input/TagInput';\nexport type { TagInputRef } from './components/tag-input/TagInput';\nexport { default as TextArea } from './components/text-area/TextArea';\nexport { default as Tooltip } from './components/tooltip/Tooltip';\nexport { default as Truncation } from './components/truncation/Truncation';\nexport { MentionFinderPopupAlignment } from './constants/mentionFinder';\nexport { useElementSize } from './hooks/element';\nexport type { BrowserName } from './types/chayns';\nexport { ContentCardType } from './types/contentCard';\nexport { ContextMenuAlignment } from './types/contextMenu';\nexport type { FileItem, Image, InternalFileItem, Meta, Video } from './types/file';\nexport { isValidFileType } from './utils/file';\nexport type { FileInputFileItem } from './types/fileInput';\nexport { FilterButtonItemShape, FilterButtonSize } from './types/filterButtons';\nexport type { IFilterButtonItem as FilterButtonItem } from './types/filterButtons';\nexport type { IListItemRightElements } from './types/list';\nexport type { PopupRef } from './types/popup';\nexport type { RadioButtonItem } from './types/radioButton';\nexport type {\n ISearchBoxItem as SearchBoxItem,\n ISearchBoxItems as SearchBoxItems,\n} from './types/searchBox';\nexport type { SelectButtonItem } from './types/selectButton';\nexport type { SliderButtonItem } from './types/slider-button';\nexport { ClampPosition } from './types/truncation';\nexport { getIsTouch } from './utils/environment';\nexport { filterFilesByMimeType, getFileAsArrayBuffer, selectFiles } from './utils/fileDialog';\nexport { isTobitEmployee } from './utils/isTobitEmployee';\nexport { getUsableHeight } from './utils/pageProvider';\nexport { uploadFile } from './utils/uploadFile';\nexport type { Theme } from './components/color-scheme-provider/ColorSchemeProvider';\n"],"mappings":"AAAA;;AAEA,SAASA,OAAO,IAAIC,SAAS,QAAQ,kCAAkC;AACvE,SAASD,OAAO,IAAIE,gBAAgB,QAAQ,2DAA2D;AACvG,SAASF,OAAO,IAAIG,cAAc,QAAQ,uDAAuD;AACjG,SAASH,OAAO,IAAII,cAAc,QAAQ,uDAAuD;AACjG,SAASJ,OAAO,IAAIK,aAAa,QAAQ,qDAAqD;AAC9F,SAASL,OAAO,IAAIM,aAAa,QAAQ,2CAA2C;AACpF,SAASN,OAAO,IAAIO,iBAAiB,QAAQ,mDAAmD;AAChG,SACIC,WAAW,EACXR,OAAO,IAAIS,YAAY,QACpB,gDAAgD;AACvD,SAAST,OAAO,IAAIU,KAAK,QAAQ,0BAA0B;AAC3D,SAASV,OAAO,IAAIW,MAAM,QAAQ,4BAA4B;AAC9D,SAASX,OAAO,IAAIY,QAAQ,QAAQ,gCAAgC;AACpE,SACIZ,OAAO,IAAIa,mBAAmB,EAC9BC,cAAc,QACX,wDAAwD;AAC/D,SAASC,SAAS,EAAEC,WAAW,QAAQ,eAAe;AAKtD,SAASC,YAAY,EAAEC,eAAe,QAAQ,mBAAmB;AACjE,SAASC,iBAAiB,QAAkC,kBAAkB;AAC9E,SAASC,kBAAkB,QAAQ,iBAAiB;AACpD,SAASC,eAAe,QAAQ,aAAa;AAC7C,SACIrB,OAAO,IAAIsB,QAAQ,QAEhB,iCAAiC;AACxC,SAAStB,OAAO,IAAIuB,UAAU,QAAQ,qCAAqC;AAC3E,SAASvB,OAAO,IAAIwB,mBAAmB,QAAQ,wDAAwD;AACvG,SACIxB,OAAO,IAAIyB,QAAQ,QAIhB,gCAAgC;AACvC,SAASzB,OAAO,IAAI0B,WAAW,QAAQ,uCAAuC;AAC9E,SAAS1B,OAAO,IAAI2B,eAAe,QAAQ,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,IAAIqD,YAAY,QAAQ,yCAAyC;AACjF,SAASrD,OAAO,IAAIsD,eAAe,QAAQ,6DAA6D;AACxG,SAAStD,OAAO,IAAIuD,WAAW,QAAQ,uCAAuC;AAE9E,SAASvD,OAAO,IAAIwD,UAAU,QAAQ,qCAAqC;AAC3E,SAASxD,OAAO,IAAIyD,SAAS,QAAQ,kCAAkC;AAEvE,SAASzD,OAAO,IAAI0D,YAAY,QAAQ,yCAAyC;AACjF,SAAS1D,OAAO,IAAI2D,MAAM,QAAQ,4BAA4B;AAC9D,SACI3D,OAAO,IAAI4D,eAAe,EAC1BC,mBAAmB,EACnBC,oBAAoB,QACjB,gDAAgD;AAEvD,SAAS9D,OAAO,IAAI+D,QAAQ,QAAQ,iCAAiC;AAErE,SAAS/D,OAAO,IAAIgE,QAAQ,QAAQ,iCAAiC;AACrE,SAAShE,OAAO,IAAIiE,OAAO,QAAQ,8BAA8B;AACjE,SAASjE,OAAO,IAAIkE,UAAU,QAAQ,oCAAoC;AAC1E,SAASC,2BAA2B,QAAQ,2BAA2B;AACvE,SAASC,cAAc,QAAQ,iBAAiB;AAEhD,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,oBAAoB,QAAQ,qBAAqB;AAE1D,SAASC,eAAe,QAAQ,cAAc;AAE9C,SAASC,qBAAqB,EAAEC,gBAAgB,QAAQ,uBAAuB;AAW/E,SAASC,aAAa,QAAQ,oBAAoB;AAClD,SAASC,UAAU,QAAQ,qBAAqB;AAChD,SAASC,qBAAqB,EAAEC,oBAAoB,EAAEC,WAAW,QAAQ,oBAAoB;AAC7F,SAASC,eAAe,QAAQ,yBAAyB;AACzD,SAASC,eAAe,QAAQ,sBAAsB;AACtD,SAASC,UAAU,QAAQ,oBAAoB","ignoreList":[]}
@@ -38,6 +38,11 @@ interface DropdownBodyWrapperProps {
38
38
  * Function to be executed when the body is closed.
39
39
  */
40
40
  onClose?: VoidFunction;
41
+ /**
42
+ * Function to be executed when the user clicks outside the dropdown.
43
+ * If the function returns `true`, the dropdown will not be closed.
44
+ */
45
+ onOutsideClick?: () => boolean | void;
41
46
  /**
42
47
  * Function to be executed when the content is measured.
43
48
  */
@@ -1,4 +1,4 @@
1
- import React, { ChangeEventHandler, ReactNode } from 'react';
1
+ import React, { ChangeEventHandler, ReactNode, FocusEventHandler } from 'react';
2
2
  import type { Tag } from '../../types/tagInput';
3
3
  export type TagInputProps = {
4
4
  /**
@@ -9,10 +9,18 @@ export type TagInputProps = {
9
9
  * Function to be executed when a tag is added.
10
10
  */
11
11
  onAdd?: (tag: Tag) => void;
12
+ /**
13
+ * Function to be executed when the input is blurred.
14
+ */
15
+ onBlur?: FocusEventHandler;
12
16
  /**
13
17
  * Function to be executed when the value of the input is changed.
14
18
  */
15
19
  onChange?: ChangeEventHandler<HTMLInputElement>;
20
+ /**
21
+ * Function to be executed when the input is focused.
22
+ */
23
+ onFocus?: FocusEventHandler;
16
24
  /**
17
25
  * Function to be executed when a tag is removed.
18
26
  */
@@ -21,10 +29,6 @@ export type TagInputProps = {
21
29
  * The placeholder that should be displayed.
22
30
  */
23
31
  placeholder?: string;
24
- /**
25
- * The tags that should be displayed.
26
- */
27
- tags?: Tag[];
28
32
  /**
29
33
  * Whether multiple tags should be allowed.
30
34
  */
@@ -33,8 +37,13 @@ export type TagInputProps = {
33
37
  * Whether the enter key should be prevented.
34
38
  */
35
39
  shouldPreventEnter?: boolean;
40
+ /**
41
+ * The tags that should be displayed.
42
+ */
43
+ tags?: Tag[];
36
44
  };
37
45
  export type TagInputRef = {
46
+ blur: () => void;
38
47
  getUnsavedTagText: Tag['text'] | undefined;
39
48
  resetValue: () => void;
40
49
  };
@@ -58,7 +58,9 @@ export type { SignatureRef } from './components/signature/Signature';
58
58
  export { default as SliderButton } from './components/slider-button/SliderButton';
59
59
  export { default as Slider } from './components/slider/Slider';
60
60
  export { default as SmallWaitCursor, SmallWaitCursorSize, SmallWaitCursorSpeed, } from './components/small-wait-cursor/SmallWaitCursor';
61
+ export type { Tag } from './types/tagInput';
61
62
  export { default as TagInput } from './components/tag-input/TagInput';
63
+ export type { TagInputRef } from './components/tag-input/TagInput';
62
64
  export { default as TextArea } from './components/text-area/TextArea';
63
65
  export { default as Tooltip } from './components/tooltip/Tooltip';
64
66
  export { default as Truncation } from './components/truncation/Truncation';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chayns-components/core",
3
- "version": "5.0.0-beta.1195",
3
+ "version": "5.0.0-beta.1196",
4
4
  "description": "A set of beautiful React components for developing your own applications with chayns.",
5
5
  "sideEffects": false,
6
6
  "browserslist": [
@@ -85,5 +85,5 @@
85
85
  "publishConfig": {
86
86
  "access": "public"
87
87
  },
88
- "gitHead": "c62c6834ff9c8086205486d255fa16c22e19ccbf"
88
+ "gitHead": "26edacf32936f754675f4cea418ed994a54a6551"
89
89
  }