carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 1.37 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:!0});var t=require("react"),e=require("../flat-table-row/__internal__/flat-table-row.context.js"),i=require("./strict-flat-table.context.js");exports.default=n=>{const{getTabStopElementId:o}=i.useStrictFlatTableContext(),[a,s]=t.useState(-1),{expandable:l,firstCellId:r,firstColumnExpandable:c,leftPositions:d,rightPositions:f,onClick:u,onKeyDown:g,highlighted:b,selected:m}=t.useContext(e.default),p=d[n],x=f[n],h=void 0!==p||void 0!==x,v=n===r,y=l&&v&&c;return t.useEffect((()=>{const t=setTimeout((()=>{s(y&&o()===n?0:-1)}),0);return()=>{clearTimeout(t)}}),[o,y,n]),{expandable:l,leftPosition:p,rightPosition:x,makeCellSticky:h,onClick:u,onKeyDown:g,isFirstCell:v,isExpandableCell:y,tabIndex:a,isInHighlightedRow:b,isInSelectedRow:m,bringToFront:(t,e)=>{if(!t||!t.nativeEvent||"function"!=typeof t.nativeEvent.composedPath)return;const{nativeEvent:i}=t,n=i.composedPath(),o=n.find((t=>t instanceof HTMLElement&&"TBODY"===t.tagName));if(!o)return;const a=Array.from(o.querySelectorAll("th, td")).filter((t=>"left"===t.getAttribute("data-sticky-align")||"right"===t.getAttribute("data-sticky-align")||t.classList.contains("isSticky")));a.map((t=>(t.classList.remove("bringToFront"),t)));const s=n.find((t=>t instanceof HTMLElement&&t.tagName===e)),l=a.indexOf(s);-1!==l&&a[l].classList.add("bringToFront")}}};