@instincthub/react-ui 0.1.56 → 0.1.58

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.
@@ -169,36 +169,37 @@
169
169
  transition: transform 0.2s ease;
170
170
  }
171
171
 
172
- .ihub-action-dropdown-container:has(.ihub-action-dropdown-menu)
173
- .ihub-action-dropdown-icon {
172
+ .ihub-action-with-dropdown[aria-expanded="true"] .ihub-action-dropdown-icon {
174
173
  transform: rotate(180deg);
175
174
  }
176
175
 
176
+ /* Fixed, not absolute: the menu is portalled to <body> and positioned from
177
+ the trigger's bounding box, so no scrolling ancestor can clip it. The
178
+ coordinates are set inline by the component. */
177
179
  .ihub-action-dropdown-menu {
178
- position: absolute;
179
- top: calc(100% + 8px);
180
+ position: fixed;
180
181
  min-width: 160px;
181
182
  background: var(--White);
182
183
  border-radius: 5px;
183
184
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
184
185
  border: var(--borderDefault);
185
186
  z-index: 20;
186
- overflow: hidden;
187
- max-height: 300px;
187
+ /* max-height is set inline from the space the chosen side actually has, so
188
+ a long list scrolls in here instead of running off the viewport. The
189
+ scroll is contained: chaining it to the page would move the trigger out
190
+ from under the menu. */
191
+ overflow-x: hidden;
188
192
  overflow-y: auto;
193
+ overscroll-behavior: contain;
189
194
  }
190
195
 
191
- .ihub-action-dropdown-left {
192
- left: 0;
193
- }
194
-
195
- .ihub-action-dropdown-right {
196
- right: 0;
197
- }
198
-
196
+ /* Alignment is resolved in JS when the menu is positioned; these remain only
197
+ so existing markup keeps a stable hook. */
198
+ .ihub-action-dropdown-left,
199
+ .ihub-action-dropdown-right,
199
200
  .ihub-action-dropdown-center {
200
- left: 50%;
201
- transform: translateX(-50%);
201
+ right: auto;
202
+ transform: none;
202
203
  }
203
204
 
204
205
  .ihub-action-dropdown-item {
@@ -1,2 +1,2 @@
1
- import{slicedToArray as i}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as n,Fragment as o,jsx as e}from"react/jsx-runtime";import t from"react";import a from"next/link";var r=function(r){var c=r.label,d=r.onClick,l=r.href,s=r.variant,u=void 0===s?"primary":s,h=r.size,m=void 0===h?"medium":h,f=r.fullWidth,p=void 0!==f&&f,b=r.disabled,v=void 0!==b&&b,w=r.iconBefore,k=r.iconAfter,N=r.className,g=void 0===N?"":N,C=r.target,y=r.type,B=void 0===y?"button":y,L=r.animated,j=void 0!==L&&L,x=r.dropdown,P=void 0!==x&&x,E=r.dropdownItems,A=void 0===E?[]:E,W=r.dropdownPosition,_=void 0===W?"right":W,z=t.useState(!1),D=i(z,2),H=D[0],I=D[1],M=t.useRef(null);t.useEffect(function(){var i=function(i){M.current&&!M.current.contains(i.target)&&I(!1)};return H&&document.addEventListener("mousedown",i),function(){document.removeEventListener("mousedown",i)}},[H]);var R=["ihub-action","ihub-action-".concat(u),"ihub-action-".concat(m),p?"ihub-action-full-width":"",v?"ihub-action-disabled":"",j?"ihub-action-animated":"",P?"ihub-action-with-dropdown":"",g].filter(Boolean).join(" "),S=n(o,{children:[w&&e("span",{className:"ihub-action-icon-before",children:w}),e("span",{className:"ihub-action-label",children:c}),P&&e("span",{className:"ihub-action-dropdown-icon",children:e("svg",{width:"12",height:"7",viewBox:"0 0 12 7",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:"primary"===u?{color:"#fff"}:{},children:e("path",{d:"M1 1L6 6L11 1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),!P&&k&&e("span",{className:"ihub-action-icon-after",children:k})]}),T=H&&P&&A.length>0&&e("div",{className:"ihub-action-dropdown-menu ihub-action-dropdown-".concat(_),onClick:function(i){return i.stopPropagation()},children:A.map(function(i,t){var r=["ihub-action-dropdown-item",i.disabled?"ihub-action-dropdown-item-disabled":"",i.className||""].filter(Boolean).join(" "),c=n(o,{children:[i.iconBefore&&e("span",{className:"ihub-action-dropdown-item-icon",children:i.iconBefore}),e("span",{className:"ihub-action-dropdown-item-label",children:i.label})]});return i.href&&!i.disabled?e(a,{href:i.href,className:r,onClick:function(){i.onClick&&i.onClick(),I(!1)},children:c},t):e("button",{className:r,onClick:function(){!i.disabled&&i.onClick&&(i.onClick(),I(!1))},disabled:i.disabled,type:"button",children:c},t)})});return function(i){return P?n("div",{className:"ihub-action-dropdown-container",ref:M,children:[i,T]}):i}(!l||v||P?e("button",{type:B,className:R,onClick:P?function(i){P&&(i.preventDefault(),i.stopPropagation(),I(function(i){return!i}))}:d,disabled:v,children:S}):e(a,{href:l,className:R,target:C,onClick:d,children:S}))};export{r as default};
1
+ import{slicedToArray as n,objectSpread2 as i}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as e,Fragment as t,jsx as o}from"react/jsx-runtime";import r from"react";import{createPortal as a}from"react-dom";import d from"next/link";var c=function(c){var l=c.label,s=c.onClick,u=c.href,h=c.variant,m=void 0===h?"primary":h,f=c.size,p=void 0===f?"medium":f,b=c.fullWidth,v=void 0!==b&&b,w=c.disabled,g=void 0!==w&&w,k=c.iconBefore,N=c.iconAfter,x=c.className,C=void 0===x?"":x,y=c.target,L=c.type,B=void 0===L?"button":L,M=c.animated,E=void 0!==M&&M,H=c.dropdown,j=void 0!==H&&H,P=c.dropdownItems,W=void 0===P?[]:P,z=c.dropdownPosition,R=void 0===z?"right":z,S=r.useState(!1),A=n(S,2),_=A[0],D=A[1],I=r.useRef(null),T=r.useRef(null),q=r.useState({top:0,left:0,maxHeight:0}),F=n(q,2),G=F[0],J=F[1],K=r.useCallback(function(){var n=I.current;if(!n)return!1;var i=n.getBoundingClientRect();if(i.bottom<0||i.top>window.innerHeight||i.right<0||i.left>window.innerWidth)return!1;var e=Math.min(40*W.length+8,300),t=Math.max(i.width,160),o=window.innerHeight-i.bottom-8-8,r=i.top-8-8,a=o<Math.min(e,120)&&r>o,d=Math.max(120,a?r:o),c=Math.min(e,d),l=i.left;return"right"===R?l=i.right-t:"center"===R&&(l=i.left+i.width/2-t/2),J({top:a?i.top-c-8:i.bottom+8,left:Math.max(8,Math.min(l,window.innerWidth-t-8)),maxHeight:c}),!0},[W.length,R]);r.useEffect(function(){if(_){var n=function(n){var i,e,t=n.target;null!==(i=I.current)&&void 0!==i&&i.contains(t)||null!==(e=T.current)&&void 0!==e&&e.contains(t)||D(!1)},i=function(n){var i,e=n.target;e&&null!==(i=T.current)&&void 0!==i&&i.contains(e)||K()||D(!1)},e=function(){K()||D(!1)};return document.addEventListener("mousedown",n),window.addEventListener("scroll",i,!0),window.addEventListener("resize",e),function(){document.removeEventListener("mousedown",n),window.removeEventListener("scroll",i,!0),window.removeEventListener("resize",e)}}},[_,K]);var O=["ihub-action","ihub-action-".concat(m),"ihub-action-".concat(p),v?"ihub-action-full-width":"",g?"ihub-action-disabled":"",E?"ihub-action-animated":"",j?"ihub-action-with-dropdown":"",C].filter(Boolean).join(" "),Q=e(t,{children:[k&&o("span",{className:"ihub-action-icon-before",children:k}),o("span",{className:"ihub-action-label",children:l}),j&&o("span",{className:"ihub-action-dropdown-icon",children:o("svg",{width:"12",height:"7",viewBox:"0 0 12 7",fill:"none",xmlns:"http://www.w3.org/2000/svg",style:"primary"===m?{color:"#fff"}:{},children:o("path",{d:"M1 1L6 6L11 1",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})}),!j&&N&&o("span",{className:"ihub-action-icon-after",children:N})]}),U=_&&j&&W.length>0&&o("div",{ref:T,className:"ihub-action-dropdown-menu ihub-action-dropdown-".concat(R),style:{top:G.top,left:G.left,maxHeight:G.maxHeight||void 0},onClick:function(n){return n.stopPropagation()},children:W.map(function(n,i){var r=["ihub-action-dropdown-item",n.disabled?"ihub-action-dropdown-item-disabled":"",n.className||""].filter(Boolean).join(" "),a=e(t,{children:[n.iconBefore&&o("span",{className:"ihub-action-dropdown-item-icon",children:n.iconBefore}),o("span",{className:"ihub-action-dropdown-item-label",children:n.label})]});return n.href&&!n.disabled?o(d,{href:n.href,className:r,onClick:function(){n.onClick&&n.onClick(),D(!1)},children:a},i):o("button",{className:r,onClick:function(){!n.disabled&&n.onClick&&(n.onClick(),D(!1))},disabled:n.disabled,type:"button",children:a},i)})});return function(n){return j?e("div",{className:"ihub-action-dropdown-container",ref:I,children:[n,U&&"undefined"!=typeof document&&a(U,document.body)]}):n}(!u||g||j?o("button",i(i({type:B,className:O,onClick:j?function(n){if(j){if(n.preventDefault(),n.stopPropagation(),_)return void D(!1);K()&&D(!0)}}:s,disabled:g},j?{"aria-haspopup":"menu","aria-expanded":_}:{}),{},{children:Q})):o(d,{href:u,className:O,target:y,onClick:s,children:Q}))};export{c as default};
2
2
  //# sourceMappingURL=Action.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Action.js","sources":["../../../../src/components/ui/Action.tsx"],"sourcesContent":["import React from \"react\";\nimport Link from \"next/link\";\n\n/**\n * Defines the structure of a dropdown item\n */\nexport interface ActionDropdownItem {\n /** Text label to display for the dropdown item */\n label: string | React.ReactNode;\n /** Click handler function */\n onClick?: () => void;\n /** Link destination if the dropdown item is a link */\n href?: string;\n /** Icon to display before the label */\n iconBefore?: React.ReactNode;\n /** Whether the item is disabled */\n disabled?: boolean;\n /** Optional additional class names */\n className?: string;\n}\n\n/**\n * ActionProps interface defines all possible props for the Action component\n */\ninterface ActionProps {\n /** Text label to display in the action element */\n label: string | React.ReactNode;\n /** Click handler function */\n onClick?: () => void;\n /** Link destination if the action is a link */\n href?: string;\n /** Visual style variant */\n variant?: \"primary\" | \"secondary\" | \"outline\" | \"danger\" | \"text\";\n /** Size variation */\n size?: \"small\" | \"medium\" | \"large\";\n /** Whether the action should take up full width of container */\n fullWidth?: boolean;\n /** Whether the action is disabled */\n disabled?: boolean;\n /** Icon to display before the label */\n iconBefore?: React.ReactNode;\n /** Icon to display after the label */\n iconAfter?: React.ReactNode;\n /** Optional additional class names */\n className?: string;\n /** Target attribute for links */\n target?: \"_blank\" | \"_self\" | \"_parent\" | \"_top\";\n /** Type attribute for buttons */\n type?: \"button\" | \"submit\" | \"reset\";\n /** Whether to add animation effect */\n animated?: boolean;\n /** Whether to show a dropdown menu */\n dropdown?: boolean;\n /** Items to display in the dropdown menu */\n dropdownItems?: ActionDropdownItem[];\n /** Position of the dropdown menu */\n dropdownPosition?: \"left\" | \"right\" | \"center\";\n}\n\n/**\n * Action component\n * A versatile Action component that can be rendered as a button or link\n * with various styles, sizes, icon options, and dropdown functionality\n * @example\n * <Action\n * label=\"Click Me\"\n * onClick={() => alert('Action clicked!')}\n * variant=\"primary\"\n * size=\"medium\"\n * fullWidth={false}\n * disabled={false}\n * iconBefore={<Icon />}\n * />\n */\nconst Action: React.FC<ActionProps> = ({\n label,\n onClick,\n href,\n variant = \"primary\",\n size = \"medium\",\n fullWidth = false,\n disabled = false,\n iconBefore,\n iconAfter,\n className = \"\",\n target,\n type = \"button\",\n animated = false,\n dropdown = false,\n dropdownItems = [],\n dropdownPosition = \"right\",\n}) => {\n // State to manage dropdown visibility\n const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);\n const dropdownRef = React.useRef<HTMLDivElement>(null);\n\n // Handle opening/closing the dropdown\n const toggleDropdown = (e: React.MouseEvent) => {\n if (dropdown) {\n e.preventDefault();\n e.stopPropagation();\n setIsDropdownOpen((prev) => !prev);\n }\n };\n\n // Close dropdown when clicking outside\n React.useEffect(() => {\n const handleClickOutside = (event: MouseEvent) => {\n if (\n dropdownRef.current &&\n !dropdownRef.current.contains(event.target as Node)\n ) {\n setIsDropdownOpen(false);\n }\n };\n\n if (isDropdownOpen) {\n document.addEventListener(\"mousedown\", handleClickOutside);\n }\n\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n };\n }, [isDropdownOpen]);\n\n // Construct class names based on props\n const baseClasses = [\n \"ihub-action\",\n `ihub-action-${variant}`,\n `ihub-action-${size}`,\n fullWidth ? \"ihub-action-full-width\" : \"\",\n disabled ? \"ihub-action-disabled\" : \"\",\n animated ? \"ihub-action-animated\" : \"\",\n dropdown ? \"ihub-action-with-dropdown\" : \"\",\n className,\n ]\n .filter(Boolean)\n .join(\" \");\n\n // Common content for both button and link\n const content = (\n <>\n {iconBefore && (\n <span className=\"ihub-action-icon-before\">{iconBefore}</span>\n )}\n <span className=\"ihub-action-label\">{label}</span>\n {dropdown && (\n <span className=\"ihub-action-dropdown-icon\">\n <svg\n width=\"12\"\n height=\"7\"\n viewBox=\"0 0 12 7\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n style={variant === \"primary\" ? { color: \"#fff\" } : {}}\n >\n <path\n d=\"M1 1L6 6L11 1\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n </span>\n )}\n {!dropdown && iconAfter && (\n <span className=\"ihub-action-icon-after\">{iconAfter}</span>\n )}\n </>\n );\n\n // Dropdown menu\n const dropdownMenu = isDropdownOpen &&\n dropdown &&\n dropdownItems.length > 0 && (\n <div\n className={`ihub-action-dropdown-menu ihub-action-dropdown-${dropdownPosition}`}\n onClick={(e) => e.stopPropagation()}\n >\n {dropdownItems.map((item, index) => {\n const itemClasses = [\n \"ihub-action-dropdown-item\",\n item.disabled ? \"ihub-action-dropdown-item-disabled\" : \"\",\n item.className || \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n const itemContent = (\n <>\n {item.iconBefore && (\n <span className=\"ihub-action-dropdown-item-icon\">\n {item.iconBefore}\n </span>\n )}\n <span className=\"ihub-action-dropdown-item-label\">\n {item.label}\n </span>\n </>\n );\n\n if (item.href && !item.disabled) {\n return (\n <Link\n key={index}\n href={item.href}\n className={itemClasses}\n onClick={() => {\n if (item.onClick) item.onClick();\n setIsDropdownOpen(false);\n }}\n >\n {itemContent}\n </Link>\n );\n }\n\n return (\n <button\n key={index}\n className={itemClasses}\n onClick={() => {\n if (!item.disabled && item.onClick) {\n item.onClick();\n setIsDropdownOpen(false);\n }\n }}\n disabled={item.disabled}\n type=\"button\"\n >\n {itemContent}\n </button>\n );\n })}\n </div>\n );\n\n // Wrapper to contain both the action and dropdown\n const renderWithDropdown = (actionElement: React.ReactElement) => {\n if (!dropdown) return actionElement;\n\n return (\n <div className=\"ihub-action-dropdown-container\" ref={dropdownRef}>\n {actionElement}\n {dropdownMenu}\n </div>\n );\n };\n\n // Render the appropriate element\n const actionElement =\n href && !disabled && !dropdown ? (\n <Link\n href={href}\n className={baseClasses}\n target={target}\n onClick={onClick}\n >\n {content}\n </Link>\n ) : (\n <button\n type={type}\n className={baseClasses}\n onClick={dropdown ? toggleDropdown : onClick}\n disabled={disabled}\n >\n {content}\n </button>\n );\n\n return renderWithDropdown(actionElement);\n};\n\nexport default Action;\n"],"names":["Action","_ref","label","onClick","href","_ref$variant","variant","_ref$size","size","_ref$fullWidth","fullWidth","_ref$disabled","disabled","iconBefore","iconAfter","_ref$className","className","target","_ref$type","type","_ref$animated","animated","_ref$dropdown","dropdown","_ref$dropdownItems","dropdownItems","_ref$dropdownPosition","dropdownPosition","_React$useState","React","useState","_React$useState2","_slicedToArray","isDropdownOpen","setIsDropdownOpen","dropdownRef","useRef","useEffect","handleClickOutside","event","current","contains","document","addEventListener","removeEventListener","baseClasses","concat","filter","Boolean","join","content","_jsxs","_Fragment","children","_jsx","width","height","viewBox","fill","xmlns","style","color","d","stroke","strokeWidth","strokeLinecap","strokeLinejoin","dropdownMenu","length","e","stopPropagation","map","item","index","itemClasses","itemContent","Link","actionElement","ref","renderWithDropdown","preventDefault","prev"],"mappings":"6LA0EA,IAAMA,EAAgC,SAA1BC,GAiBP,IAhBHC,EAAKD,EAALC,MACAC,EAAOF,EAAPE,QACAC,EAAIH,EAAJG,KAAIC,EAAAJ,EACJK,QAAAA,OAAU,IAAHD,EAAG,UAASA,EAAAE,EAAAN,EACnBO,KAAAA,OAAO,IAAHD,EAAG,SAAQA,EAAAE,EAAAR,EACfS,UAAAA,OAAY,IAAHD,GAAQA,EAAAE,EAAAV,EACjBW,SAAAA,OAAW,IAAHD,GAAQA,EAChBE,EAAUZ,EAAVY,WACAC,EAASb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C,GAAI,OAAMA,MAoKU9E,EACrCS,SAAUA,EAAQyC,SAEjBH,IAfHI,EAACsB,EACC,CAAAxE,KAAMA,EACNY,UAAW6B,EACX5B,OAAQA,EACRd,QAASA,EAERkD,SAAAH,IAcT"}
1
+ {"version":3,"file":"Action.js","sources":["../../../../src/components/ui/Action.tsx"],"sourcesContent":["import React from \"react\";\nimport { createPortal } from \"react-dom\";\nimport Link from \"next/link\";\n\n/** Menu geometry. Item height is approximate — it only sizes the menu before\n * it renders; the inline max-height is what actually bounds it. */\nconst ITEM_HEIGHT = 40;\nconst MENU_PADDING = 8;\nconst MENU_GAP = 8;\nconst VIEWPORT_MARGIN = 8;\nconst MIN_MENU_WIDTH = 160;\nconst MAX_MENU_HEIGHT = 300;\nconst MIN_USABLE_HEIGHT = 120;\n\n/**\n * Defines the structure of a dropdown item\n */\nexport interface ActionDropdownItem {\n /** Text label to display for the dropdown item */\n label: string | React.ReactNode;\n /** Click handler function */\n onClick?: () => void;\n /** Link destination if the dropdown item is a link */\n href?: string;\n /** Icon to display before the label */\n iconBefore?: React.ReactNode;\n /** Whether the item is disabled */\n disabled?: boolean;\n /** Optional additional class names */\n className?: string;\n}\n\n/**\n * ActionProps interface defines all possible props for the Action component\n */\ninterface ActionProps {\n /** Text label to display in the action element */\n label: string | React.ReactNode;\n /** Click handler function */\n onClick?: () => void;\n /** Link destination if the action is a link */\n href?: string;\n /** Visual style variant */\n variant?: \"primary\" | \"secondary\" | \"outline\" | \"danger\" | \"text\";\n /** Size variation */\n size?: \"small\" | \"medium\" | \"large\";\n /** Whether the action should take up full width of container */\n fullWidth?: boolean;\n /** Whether the action is disabled */\n disabled?: boolean;\n /** Icon to display before the label */\n iconBefore?: React.ReactNode;\n /** Icon to display after the label */\n iconAfter?: React.ReactNode;\n /** Optional additional class names */\n className?: string;\n /** Target attribute for links */\n target?: \"_blank\" | \"_self\" | \"_parent\" | \"_top\";\n /** Type attribute for buttons */\n type?: \"button\" | \"submit\" | \"reset\";\n /** Whether to add animation effect */\n animated?: boolean;\n /** Whether to show a dropdown menu */\n dropdown?: boolean;\n /** Items to display in the dropdown menu */\n dropdownItems?: ActionDropdownItem[];\n /** Position of the dropdown menu */\n dropdownPosition?: \"left\" | \"right\" | \"center\";\n}\n\n/**\n * Action component\n * A versatile Action component that can be rendered as a button or link\n * with various styles, sizes, icon options, and dropdown functionality\n * @example\n * <Action\n * label=\"Click Me\"\n * onClick={() => alert('Action clicked!')}\n * variant=\"primary\"\n * size=\"medium\"\n * fullWidth={false}\n * disabled={false}\n * iconBefore={<Icon />}\n * />\n */\nconst Action: React.FC<ActionProps> = ({\n label,\n onClick,\n href,\n variant = \"primary\",\n size = \"medium\",\n fullWidth = false,\n disabled = false,\n iconBefore,\n iconAfter,\n className = \"\",\n target,\n type = \"button\",\n animated = false,\n dropdown = false,\n dropdownItems = [],\n dropdownPosition = \"right\",\n}) => {\n // State to manage dropdown visibility\n const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);\n const dropdownRef = React.useRef<HTMLDivElement>(null);\n const menuRef = React.useRef<HTMLDivElement>(null);\n const [menuPosition, setMenuPosition] = React.useState<{\n top: number;\n left: number;\n maxHeight: number;\n }>({ top: 0, left: 0, maxHeight: 0 });\n\n /**\n * Positions the menu from the trigger's bounding box.\n *\n * The menu is rendered into `document.body` rather than beside the trigger,\n * because an absolutely-positioned menu is clipped by any scrolling ancestor\n * — and the most common host for this component is a table row inside\n * `IHubTableServer`'s `.ihub-scroll-container` (`overflow: auto`), which is\n * only as tall as its rows. On a long table the menu had room and looked\n * fine; on a one-row table it was cut to a sliver. Filtering a table down to\n * a single result is exactly when someone reaches for that row's actions, so\n * the broken case was the common one.\n *\n * Flips above the trigger when there is not enough room below, and clamps to\n * the viewport horizontally.\n */\n const positionMenu = React.useCallback(() => {\n const trigger = dropdownRef.current;\n if (!trigger) return false;\n\n const rect = trigger.getBoundingClientRect();\n\n // Scrolled out of view — including horizontally, since a table scrolls\n // sideways. Nothing to pin the menu to.\n if (\n rect.bottom < 0 ||\n rect.top > window.innerHeight ||\n rect.right < 0 ||\n rect.left > window.innerWidth\n ) {\n return false;\n }\n\n const desiredHeight = Math.min(\n dropdownItems.length * ITEM_HEIGHT + MENU_PADDING,\n MAX_MENU_HEIGHT\n );\n const menuWidth = Math.max(rect.width, MIN_MENU_WIDTH);\n const spaceBelow =\n window.innerHeight - rect.bottom - MENU_GAP - VIEWPORT_MARGIN;\n const spaceAbove = rect.top - MENU_GAP - VIEWPORT_MARGIN;\n\n // Prefer below; flip only when below cannot show a usable amount and above\n // is genuinely roomier.\n const openUpward =\n spaceBelow < Math.min(desiredHeight, MIN_USABLE_HEIGHT) &&\n spaceAbove > spaceBelow;\n\n const available = Math.max(\n MIN_USABLE_HEIGHT,\n openUpward ? spaceAbove : spaceBelow\n );\n const maxHeight = Math.min(desiredHeight, available);\n\n let left = rect.left;\n if (dropdownPosition === \"right\") left = rect.right - menuWidth;\n else if (dropdownPosition === \"center\")\n left = rect.left + rect.width / 2 - menuWidth / 2;\n\n setMenuPosition({\n top: openUpward ? rect.top - maxHeight - MENU_GAP : rect.bottom + MENU_GAP,\n left: Math.max(\n VIEWPORT_MARGIN,\n Math.min(left, window.innerWidth - menuWidth - VIEWPORT_MARGIN)\n ),\n maxHeight,\n });\n return true;\n }, [dropdownItems.length, dropdownPosition]);\n\n // Handle opening/closing the dropdown\n const toggleDropdown = (e: React.MouseEvent) => {\n if (dropdown) {\n e.preventDefault();\n e.stopPropagation();\n if (isDropdownOpen) {\n setIsDropdownOpen(false);\n return;\n }\n // Only open once we know where to put it; otherwise an off-screen\n // trigger would drop the menu in the top-left corner.\n if (positionMenu()) setIsDropdownOpen(true);\n }\n };\n\n // Close dropdown when clicking outside\n React.useEffect(() => {\n if (!isDropdownOpen) return;\n\n // Both refs are checked: the menu now lives outside the trigger's subtree,\n // so testing only the container would close it on its own menu items.\n const handleClickOutside = (event: MouseEvent) => {\n const target = event.target as Node;\n if (\n dropdownRef.current?.contains(target) ||\n menuRef.current?.contains(target)\n ) {\n return;\n }\n setIsDropdownOpen(false);\n };\n\n // Fixed coordinates go stale as soon as anything scrolls, so the menu is\n // repositioned to stay pinned to its trigger. It is NOT closed: the menu\n // caps its own height and scrolls internally, and closing here also fired\n // for scrolls originating INSIDE the menu — which made a list long enough\n // to need scrolling impossible to scroll. Capture phase, because a table's\n // own scroll container never bubbles to window.\n const handleScroll = (event: Event) => {\n const target = event.target as Node | null;\n if (target && menuRef.current?.contains(target)) return;\n if (!positionMenu()) setIsDropdownOpen(false);\n };\n\n const handleResize = () => {\n if (!positionMenu()) setIsDropdownOpen(false);\n };\n\n document.addEventListener(\"mousedown\", handleClickOutside);\n window.addEventListener(\"scroll\", handleScroll, true);\n window.addEventListener(\"resize\", handleResize);\n\n return () => {\n document.removeEventListener(\"mousedown\", handleClickOutside);\n window.removeEventListener(\"scroll\", handleScroll, true);\n window.removeEventListener(\"resize\", handleResize);\n };\n }, [isDropdownOpen, positionMenu]);\n\n // Construct class names based on props\n const baseClasses = [\n \"ihub-action\",\n `ihub-action-${variant}`,\n `ihub-action-${size}`,\n fullWidth ? \"ihub-action-full-width\" : \"\",\n disabled ? \"ihub-action-disabled\" : \"\",\n animated ? \"ihub-action-animated\" : \"\",\n dropdown ? \"ihub-action-with-dropdown\" : \"\",\n className,\n ]\n .filter(Boolean)\n .join(\" \");\n\n // Common content for both button and link\n const content = (\n <>\n {iconBefore && (\n <span className=\"ihub-action-icon-before\">{iconBefore}</span>\n )}\n <span className=\"ihub-action-label\">{label}</span>\n {dropdown && (\n <span className=\"ihub-action-dropdown-icon\">\n <svg\n width=\"12\"\n height=\"7\"\n viewBox=\"0 0 12 7\"\n fill=\"none\"\n xmlns=\"http://www.w3.org/2000/svg\"\n style={variant === \"primary\" ? { color: \"#fff\" } : {}}\n >\n <path\n d=\"M1 1L6 6L11 1\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n />\n </svg>\n </span>\n )}\n {!dropdown && iconAfter && (\n <span className=\"ihub-action-icon-after\">{iconAfter}</span>\n )}\n </>\n );\n\n // Dropdown menu\n const dropdownMenu = isDropdownOpen &&\n dropdown &&\n dropdownItems.length > 0 && (\n <div\n ref={menuRef}\n className={`ihub-action-dropdown-menu ihub-action-dropdown-${dropdownPosition}`}\n style={{\n top: menuPosition.top,\n left: menuPosition.left,\n maxHeight: menuPosition.maxHeight || undefined,\n }}\n onClick={(e) => e.stopPropagation()}\n >\n {dropdownItems.map((item, index) => {\n const itemClasses = [\n \"ihub-action-dropdown-item\",\n item.disabled ? \"ihub-action-dropdown-item-disabled\" : \"\",\n item.className || \"\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n const itemContent = (\n <>\n {item.iconBefore && (\n <span className=\"ihub-action-dropdown-item-icon\">\n {item.iconBefore}\n </span>\n )}\n <span className=\"ihub-action-dropdown-item-label\">\n {item.label}\n </span>\n </>\n );\n\n if (item.href && !item.disabled) {\n return (\n <Link\n key={index}\n href={item.href}\n className={itemClasses}\n onClick={() => {\n if (item.onClick) item.onClick();\n setIsDropdownOpen(false);\n }}\n >\n {itemContent}\n </Link>\n );\n }\n\n return (\n <button\n key={index}\n className={itemClasses}\n onClick={() => {\n if (!item.disabled && item.onClick) {\n item.onClick();\n setIsDropdownOpen(false);\n }\n }}\n disabled={item.disabled}\n type=\"button\"\n >\n {itemContent}\n </button>\n );\n })}\n </div>\n );\n\n // Wrapper to contain both the action and dropdown\n const renderWithDropdown = (actionElement: React.ReactElement) => {\n if (!dropdown) return actionElement;\n\n return (\n <div className=\"ihub-action-dropdown-container\" ref={dropdownRef}>\n {actionElement}\n {dropdownMenu &&\n typeof document !== \"undefined\" &&\n createPortal(dropdownMenu, document.body)}\n </div>\n );\n };\n\n // Render the appropriate element\n const actionElement =\n href && !disabled && !dropdown ? (\n <Link\n href={href}\n className={baseClasses}\n target={target}\n onClick={onClick}\n >\n {content}\n </Link>\n ) : (\n <button\n type={type}\n className={baseClasses}\n onClick={dropdown ? toggleDropdown : onClick}\n disabled={disabled}\n {...(dropdown\n ? { \"aria-haspopup\": \"menu\" as const, \"aria-expanded\": isDropdownOpen }\n : {})}\n >\n {content}\n </button>\n );\n\n return renderWithDropdown(actionElement);\n};\n\nexport default Action;\n"],"names":["Action","_ref","label","onClick","href","_ref$variant","variant","_ref$size","size","_ref$fullWidth","fullWidth","_ref$disabled","disabled","iconBefore","iconAfter","_ref$className","className","target","_ref$type","type","_ref$animated","animated","_ref$dropdown","dropdown","_ref$dropdownItems","dropdownItems","_ref$dropdownPosition","dropdownPosition","_React$useState","React","useState","_React$useState2","_slicedToArray","isDropdownOpen","setIsDropdownOpen","dropdownRef","useRef","menuRef","_React$useState3","top","left","maxHeight","_React$useState4","menuPosition","setMenuPosition","positionMenu","useCallback","trigger","current","rect","getBoundingClientRect","bottom","window","innerHeight","right","innerWidth","desiredHeight","Math","min","length","menuWidth","max","width","spaceBelow","spaceAbove","openUpward","available","useEffect","handleClickOutside","event","_dropdownRef$current","_menuRef$current","contains","handleScroll","_menuRef$current2","handleResize","document","addEventListener","removeEventListener","baseClasses","concat","filter","Boolean","join","content","_jsxs","_Fragment","children","_jsx","height","viewBox","fill","xmlns","style","color","d","stroke","strokeWidth","strokeLinecap","strokeLinejoin","dropdownMenu","ref","undefined","e","stopPropagation","map","item","index","itemClasses","itemContent","Link","actionElement","createPortal","body","renderWithDropdown","_objectSpread","preventDefault"],"mappings":"yPAMA,IA+EMA,EAAgC,SAA1BC,GAiBP,IAhBHC,EAAKD,EAALC,MACAC,EAAOF,EAAPE,QACAC,EAAIH,EAAJG,KAAIC,EAAAJ,EACJK,QAAAA,OAAU,IAAHD,EAAG,UAASA,EAAAE,EAAAN,EACnBO,KAAAA,OAAO,IAAHD,EAAG,SAAQA,EAAAE,EAAAR,EACfS,UAAAA,OAAY,IAAHD,GAAQA,EAAAE,EAAAV,EACjBW,SAAAA,OAAW,IAAHD,GAAQA,EAChBE,EAAUZ,EAAVY,WACAC,EAASb,EAATa,U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