carbon-react
Version:
A library of reusable React components for easily building user interfaces.
2 lines (1 loc) • 2.81 kB
JavaScript
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useRef as r,useCallback as n}from"react";import o from"../../icon/icon.component.js";import{StyledFlatTableRowHeader as i,StyledFlatTableRowHeaderContent as l}from"./flat-table-row-header.style.js";import a from"../../../__internal__/utils/helpers/guid/index.js";import c from"../../../__internal__/utils/helpers/tags/tags.js";import p from"../__internal__/use-table-cell.js";function s(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{},n=Object.keys(r);"function"==typeof Object.getOwnPropertySymbols&&(n=n.concat(Object.getOwnPropertySymbols(r).filter((function(e){return Object.getOwnPropertyDescriptor(r,e).enumerable})))),n.forEach((function(t){s(e,t,r[t])}))}return e}function b(e,t){return t=null!=t?t:{},Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):function(e){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t.push.apply(t,r)}return t}(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))})),e}const d=s=>{var{align:d="left",children:u,width:y,py:m,px:g,truncate:O,title:h,stickyAlignment:w="left",colspan:j,rowspan:P,id:x}=s,v=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(s,["align","children","width","py","px","truncate","title","stickyAlignment","colspan","rowspan","id"]);const _=r(x||a()),{leftPosition:k,rightPosition:S,expandable:D,onClick:I,onKeyDown:C,isFirstCell:E,isExpandableCell:F,tabIndex:A,isInHighlightedRow:H,isInSelectedRow:N,bringToFront:R}=p(_.current),T=n((e=>{F&&I&&I(e)}),[F,I]),K=n((e=>{F&&C&&C(e)}),[F,C]);return e(i,b(f(b(f({leftPosition:"left"===w?k||0:void 0,rightPosition:"right"===w?S||0:void 0,align:d,width:y,py:m||"10px",px:g||3,onClick:T,tabIndex:F?A:void 0,onKeyDown:K,truncate:O,expandable:D,stickyAlignment:w},void 0!==j&&{colSpan:Number(j)},void 0!==P&&{rowSpan:Number(P)}),{"data-selected":N&&F,"data-highlighted":H&&F,onFocus:e=>{R(e,"TH")}}),v,c("flat-table-row-header",f({"data-element":"flat-table-row-header"},v))),{id:_.current,children:t(l,{title:O&&!h&&"string"==typeof u?u:h,expandable:D,"data-role":"flat-table-row-header-content",children:[D&&E&&e(o,{type:"chevron_down_thick",mr:"8px"}),u]})}))};d.displayName="FlatTableRowHeader";export{d as FlatTableRowHeader,d as default};