carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 3.67 kB
JavaScript
import{jsxs as t,jsx as e}from"react/jsx-runtime";import r,{forwardRef as o,useRef as n,useContext as i,useImperativeHandle as l}from"react";import{offset as a,flip as s}from"@floating-ui/dom";import c from"../../hooks/__internal__/useClickAwayListener/useClickAwayListener.js";import u from"../split-button/__internal__/split-button.context.js";import{StyledMultiActionButton as p,StyledButtonChildrenContainer as d}from"./multi-action-button.style.js";import f from"../button/button.component.js";import m from"../../__internal__/popover/popover.component.js";import"../../style/utils/filter-styled-system-padding-props.js";import b from"../../style/utils/filter-styled-system-margin-props.js";import y from"../../style/utils/filter-out-styled-system-spacing-props.js";import g from"../../hooks/__internal__/useChildButtons/useChildButtons.js";import j from"../../hooks/__internal__/useAdaptiveSidebarModalFocus/useAdaptiveSidebarModalFocus.js";import O from"../flat-table/__internal__/flat-table.context.js";import h from"../../__internal__/utils/helpers/guid/index.js";function _(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function w(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{},o=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(o=o.concat(Object.getOwnPropertySymbols(r).filter((function(t){return Object.getOwnPropertyDescriptor(r,t).enumerable})))),o.forEach((function(e){_(t,e,r[e])}))}return t}function v(t,e){return e=null!=e?e:{},Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(e)):function(t){var e=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e.push.apply(e,r)}return e}(Object(e)).forEach((function(r){Object.defineProperty(t,r,Object.getOwnPropertyDescriptor(e,r))})),t}const P=o(((o,_)=>{var{align:P="left",position:x="left",disabled:k,buttonType:S,size:B,children:C,text:T,subtext:D,width:A,onClick:z,"data-element":E,"data-role":F}=o,I=function(t,e){if(null==t)return{};var r,o,n=function(t,e){if(null==t)return{};var r,o,n={},i=Object.keys(t);for(o=0;o<i.length;o++)r=i[o],e.indexOf(r)>=0||(n[r]=t[r]);return n}(t,e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);for(o=0;o<i.length;o++)r=i[o],e.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(t,r)&&(n[r]=t[r])}return n}(o,["align","position","disabled","buttonType","size","children","text","subtext","width","onClick","data-element","data-role"]);const M=n(null),{isInFlatTable:K}=i(O),L=n(h());l(_,(()=>({focusMainButton(){var t;null===(t=M.current)||void 0===t||t.focus({preventScroll:!0})}})),[]);const{showAdditionalButtons:N,showButtons:U,hideButtons:V,buttonNode:q,handleToggleButtonKeyDown:G,wrapperProps:H,contextValue:J}=g(M),Q=c(V);j((()=>V()));const R=w({disabled:k,displayed:N,onTouchStart:U,onKeyDown:G,onClick:t=>{N?V():U(),Q(),z&&z(t)},buttonType:S,size:B,subtext:D},y(I)),W=b(I);return t(p,v(w({ref:q,"data-component":"multi-action-button","data-element":E,"data-role":F,displayed:N,width:A},W),{children:[e(f,v(w({"aria-expanded":N,"aria-controls":L.current,"data-element":"toggle-button"},R),{ref:M,iconPosition:"after",iconType:"dropdown",children:T}),"toggle-button"),N&&e(m,{disableBackgroundUI:K,disablePortal:!0,placement:"left"===x?"bottom-start":"bottom-end",reference:q,popoverStrategy:"fixed",middleware:[a(6),s({fallbackStrategy:"initialPlacement"})],children:e(d,v(w({id:L.current},H),{align:P,children:e(u.Provider,{value:J,children:r.Children.map(C,(t=>e("li",{children:t})))})}))})]}))}));export{P as MultiActionButton,P as default};