@scania/tegel
Version:
Tegel Design System
1 lines • 7.32 kB
JavaScript
import{r as t,c as e,h as s,H as a,a as o}from"./p-9xxNGlso.js";const d=["multiselect","expandableRows","compactDesign","noMinWidth","verticalDividers"],i=class{constructor(a){t(this,a),this.tdsSort=e(this,"tdsSort",7),this.internalSortButtonClicked=e(this,"internalSortButtonClicked",6),this.internalTdsTextAlign=e(this,"internalTdsTextAlign",6),this.internalTdsHover=e(this,"internalTdsHover",6),this.sortable=!1,this.textAlign="left",this.disablePadding=!1,this.tdsAriaLabelSortButton="",this.textAlignState="left",this.sortedByMyKey=!1,this.verticalDividers=!1,this.compactDesign=!1,this.noMinWidth=!1,this.multiselect=!1,this.enableToolbarDesign=!1,this.tableId="",this.expandableRows=!1,this.sortButtonClick=()=>{this.sortingDirection="asc"!==this.sortingDirection&&"desc"!==this.sortingDirection?"asc":"asc"===this.sortingDirection?"desc":"asc",this.sortedByMyKey=!0,this.tdsSort.emit({tableId:this.tableId,columnKey:this.cellKey,sortingDirection:this.sortingDirection}),this.internalSortButtonClicked.emit({tableId:this.tableId,key:this.cellKey})},this.headerCellContent=()=>this.sortable?s("button",{class:"tds-table__header-button",onClick:()=>this.sortButtonClick(),style:{justifyContent:this.textAlignState},"aria-label":this.tdsAriaLabelSortButton},s("span",{class:"tds-table__header-button-text"},this.cellValue,s("slot",null)),void 0===this.sortingDirection&&s("tds-icon",{svgTitle:"sorting",class:"tds-table__header-button-icon",name:"sorting",size:"16px"}),this.sortingDirection&&["asc","desc"].includes(this.sortingDirection)&&s("tds-icon",{svgTitle:"arrow down",class:"tds-table__header-button-icon "+("asc"===this.sortingDirection?"tds-table__header-button-icon--rotate":""),name:"arrow_down",size:"16px"})):s("p",{class:{"tds-table__header-text":!0,"tds-table__header-text-no-padding":this.disablePadding},style:{textAlign:this.textAlignState}},this.cellValue,s("slot",null)),this.onHeadCellHover=t=>{this.internalTdsHover.emit({tableId:this.tableId,key:null!=t?t:""})}}internalTdsPropChangeListener(t){this.tableId===t.detail.tableId&&t.detail.changed.filter((t=>d.includes(t))).forEach((e=>{if(void 0===this[e])throw new Error(`Table prop is not supported: ${e}`);this[e]=t.detail[e]}))}updateOptionsContent(t){const{tableId:e,key:s}=t.detail;this.tableId===e&&this.cellKey!==s&&(this.sortedByMyKey=!1,setTimeout((()=>{this.sortingDirection=void 0}),200))}connectedCallback(){var t;this.tableEl=this.host.closest("tds-table"),this.tableId=null===(t=this.tableEl)||void 0===t?void 0:t.tableId}componentWillLoad(){d.forEach((t=>{var e;this[t]=null===(e=this.tableEl)||void 0===e?void 0:e[t]}))}componentWillRender(){this.textAlignState=["left","start","right","end","center"].includes(this.textAlign)?this.textAlign:"left",this.internalTdsTextAlign.emit([this.tableId,this.cellKey,this.textAlignState]);const t=this.host.closest("tds-table");t&&(this.enableToolbarDesign=t.getElementsByTagName("tds-table-toolbar").length>=1)}getAriaSort(){return"asc"===this.sortingDirection?"ascending":"desc"===this.sortingDirection?"descending":"none"}render(){return s(a,{key:"be64d88104f52df5d328b61a052eb489bcc01b72",class:{"tds-table__header-cell":!0,"tds-table__header-cell--sortable":this.sortable,"tds-table__header-cell--is-sorted":this.sortedByMyKey,"tds-table__header-cell--custom-width":""!==this.customWidth,"tds-table--compact":this.compactDesign,"tds-table--divider":this.verticalDividers,"tds-table--no-min-width":this.noMinWidth,"tds-table--extra-column":this.multiselect||this.expandableRows,"tds-table--toolbar-available":this.enableToolbarDesign,"tds-table--no-padding":this.disablePadding}},s("th",{key:"5ce91b5905d96bf9be4061a2b7a53c1af18fc390",style:{minWidth:this.customWidth},onMouseOver:()=>this.onHeadCellHover(this.cellKey),onFocus:()=>this.onHeadCellHover(this.cellKey),onMouseLeave:()=>this.onHeadCellHover(""),onBlur:()=>this.onHeadCellHover(""),"aria-sort":this.getAriaSort(),colSpan:this.colSpan,rowSpan:this.rowSpan},this.headerCellContent()))}get host(){return o(this)}};i.style=":host{display:contents}:host(.tds-table__header-cell) th{box-sizing:border-box;font:var(--tds-headline-07);letter-spacing:var(--tds-headline-07-ls);text-align:left;color:var(--tds-table-color);background-color:var(--tds-table-header-background);border-bottom:1px solid var(--tds-table-header-background-hover);padding:0;height:48px;min-width:192px;box-sizing:border-box;vertical-align:middle;overflow:hidden;transition:background-color 200ms ease}:host(.tds-table__header-cell) th *{box-sizing:border-box}:host(.tds-table__header-cell) th .tds-table__header-text{padding:8px 16px;margin:0}:host(.tds-table__header-cell) th .tds-table__header-text-no-padding{padding:0}:host(.tds-table__header-cell) th:hover{background-color:var(--tds-table-header-background-hover)}:host(.tds-table__header-cell--sortable) th .tds-table__header-button{display:flex;align-items:center;gap:8px;justify-content:start;flex-direction:row;width:100%;height:100%;padding:0 16px;background-color:transparent;border:none;cursor:pointer;transition:background-color 200ms ease}:host(.tds-table__header-cell--sortable) th .tds-table__header-button:focus{outline:2px solid var(--tds-table-header-btn-focus);outline-offset:-2px}:host(.tds-table__header-cell--sortable) th .tds-table__header-button:focus .tds-table__header-button-icon{opacity:1}:host(.tds-table__header-cell--sortable) th .tds-table__header-button .tds-table__header-button-text{font:var(--tds-headline-07);letter-spacing:var(--tds-headline-07-ls);text-align:left;color:var(--tds-table-header-btn-color)}:host(.tds-table__header-cell--sortable) th .tds-table__header-button .tds-table__header-button-icon{flex:0 0 16px;height:16px;width:16px;opacity:0;transform-origin:center;transition:opacity 200ms ease-in, transform 200ms ease;color:var(--tds-table-color)}:host(.tds-table__header-cell--sortable) th .tds-table__header-button:hover .tds-table__header-button-icon{opacity:1}:host(.tds-table__header-cell--is-sorted) th .tds-table__header-button{background-color:var(--tds-table-header-btn-background)}:host(.tds-table__header-cell--is-sorted) th .tds-table__header-button:hover{background-color:var(--tds-table-header-btn-background-hover)}:host(.tds-table__header-cell--is-sorted) th .tds-table__header-button .tds-table__header-button-icon{opacity:1}:host(.tds-table__header-cell--is-sorted) th .tds-table__header-button .tds-table__header-button-icon--rotate{transform:rotate(180deg)}:host(.tds-table--compact) th{height:33px}:host(.tds-table--divider) th{border-right:1px solid var(--tds-table-divider)}:host(.tds-table--divider:last-of-type) th{border-right:none}:host(.tds-table--no-min-width) th{min-width:unset}:host(.tds-table--no-padding) th{height:unset}:host(.tds-table__header-cell:first-of-type) th{border-top-left-radius:4px}:host(.tds-table__header-cell:last-of-type) th{border-top-right-radius:4px}:host(.tds-table--extra-column:first-of-type) th{border-top-left-radius:0}:host(.tds-table--toolbar-available) th{border-radius:0}:host(.tds-table--extra-column.tds-table--toolbar-available) th{border-radius:0}:host(.tds-table__header-cell.tds-table--toolbar-available:first-of-type) th{border-top-left-radius:0}:host(.tds-table__header-cell.tds-table--toolbar-available:last-of-type) th{border-top-right-radius:0}";export{i as tds_header_cell}