UNPKG

@scania/tegel

Version:
1 lines 5.67 kB
import{t as e,p as t,H as a,c as d,h as s,a as r}from"./index.js";import{g as i}from"./p-Cn4f8w1e.js";import{h as o}from"./p-DDX6uFcm.js";import{d as c}from"./p-D0Aaqu_c.js";import{d as h}from"./p-7g_ABN5n.js";import{d as n}from"./p-CIt4YhvL.js";const l=t(class extends a{constructor(e){super(),!1!==e&&this.__registerHost(),this.__attachShadow(),this.tdsClick=d(this,"tdsClick",6),this.modeVariant=null,this.imagePlacement="below-header",this.bodyDivider=!1,this.clickable=!1,this.stretch=!1,this.cardId=i(),this.expandable=!1,this.expanded=!1,this.toggleExpand=()=>{this.expandable&&(this.expanded=!this.expanded)},this.handleClick=()=>{this.tdsClick.emit({cardId:this.cardId})},this.getCardHeader=()=>{const e=o("header",this.host),t=o("subheader",this.host),a=o("thumbnail",this.host);return s("div",{class:{"card-header":!0,expandable:this.expandable,expanded:this.expanded}},a&&s("slot",{name:"thumbnail"}),s("div",{class:"header-subheader",id:"header-"+this.cardId},this.header&&s("span",{class:"header"},this.header),e&&s("slot",{name:"header"}),this.subheader&&s("span",{class:"subheader"},this.subheader),t&&s("slot",{name:"subheader"})),this.expandable&&s("tds-button",{type:"button",variant:"ghost",size:"sm","tds-aria-label":"Toggle card content","aria-expanded":this.expanded?"true":"false",onClick:this.toggleExpand},s("tds-icon",{slot:"icon",size:"16px",name:"chevron_down",svgTitle:"Chevron Down",class:{rotated:this.expanded}})))},this.getCardContent=()=>{const e=o("body",this.host),t=o("body-image",this.host),a=o("actions",this.host),d="body-"+this.cardId;return s("div",{class:{stretch:this.stretch},"aria-describedby":e?d:null},"below-header"===this.imagePlacement&&this.getCardHeader(),s("div",{class:"card-body",id:d},t&&s("slot",{name:"body-image"}),this.bodyImg&&s("img",{class:"card-body-img",src:this.bodyImg,alt:this.bodyImgAlt}),"above-header"===this.imagePlacement&&this.getCardHeader(),this.bodyDivider&&s("tds-divider",null),e&&s("slot",{name:"body"})),a&&s("slot",{name:"actions"}))}}render(){const e={card:!0,clickable:this.clickable,[this.imagePlacement]:!this.stretch,[this.imagePlacement+"-stretch"]:this.stretch},t=this.header?this.header:"Card "+this.cardId;return s(r,{key:"a02da4f8704ad22664fec6ba0b97421094e4cda0",class:{["tds-mode-variant-"+this.modeVariant]:!!this.modeVariant}},this.clickable?s("button",{class:e,onClick:this.handleClick,"aria-label":t,"aria-describedby":"header-"+this.cardId},this.getCardContent()):s("div",{class:e},this.getCardContent()))}get host(){return this}static get style(){return".card{box-sizing:border-box;box-shadow:var(--tds-card-box);background-color:var(--tds-card-background);display:block;border-radius:4px;overflow:hidden}.card *{box-sizing:border-box}.card.clickable:hover{box-shadow:var(--tds-card-box-hover);cursor:pointer}.card .card-header{font:var(--tds-headline-06);letter-spacing:var(--tds-headline-06-ls);padding:16px;display:flex;align-items:center}.card .card-header slot[name=thumbnail]::slotted(*){width:36px;height:36px;border-radius:100%;margin-right:16px}.card .card-header .card-top-header{padding-left:16px;display:flex;flex-direction:column}.card .card-header .card-top-header.no-header-img{padding-left:0}.card .card-header.below{padding-top:16px}.card .card-header.expandable tds-icon{cursor:pointer;margin-left:auto;transition:transform 160ms ease-in-out, opacity 120ms ease-in-out}.card .card-header.expandable tds-icon.rotated{transform:rotate(180deg)}.card .header-subheader{display:flex;flex-direction:column;width:100%;gap:4px}.card .header-subheader .header,.card .header-subheader slot[name=header]{color:var(--tds-card-headline)}.card .header-subheader .subheader,.card .header-subheader slot[name=subheader]{color:var(--tds-card-sub-headline)}.card .card-body-img{width:100%}.card .tds-divider{margin:16px 16px 0;background-color:var(--tds-card-divider);height:1px}.card .card-body{display:block;word-wrap:break-word}.card slot[name=body]::slotted(*){font:var(--tds-detail-03) !important;letter-spacing:var(--tds-detail-03-ls) !important;color:var(--tds-card-body-color);padding:0 16px;margin-bottom:16px;margin-top:16px;max-width:336px}.card slot[name=actions]::slotted(*){display:flex;padding:16px;color:var(--tds-card-icon-color)}button{width:100%;border:none;text-align:left;padding:0}button:focus-visible{outline:2px solid var(--tds-blue-400);outline-offset:-2px}button:active{box-shadow:var(--tds-card-box-pressed)}.below-header-stretch,.above-header-stretch{display:flex;flex-direction:column}.below-header-stretch .stretch,.above-header-stretch .stretch{display:flex;flex-direction:column;flex-grow:1;width:100%}.below-header-stretch .card-body,.above-header-stretch .card-body{display:flex;flex-direction:column;flex-grow:1}.below-header-stretch .card-body slot[name=body]::slotted(*),.above-header-stretch .card-body slot[name=body]::slotted(*){max-width:unset;flex-grow:1}:host([expandable]:not([expanded])) .card-body slot[name=body]{display:none}"}},[257,"tds-card",{modeVariant:[1,"mode-variant"],imagePlacement:[1,"image-placement"],header:[1],subheader:[1],bodyImg:[1,"body-img"],bodyImgAlt:[1,"body-img-alt"],bodyDivider:[4,"body-divider"],clickable:[4],stretch:[4],cardId:[1,"card-id"],expandable:[4],expanded:[1540]}]);function b(){"undefined"!=typeof customElements&&["tds-card","tds-button","tds-divider","tds-icon"].forEach((t=>{switch(t){case"tds-card":customElements.get(e(t))||customElements.define(e(t),l);break;case"tds-button":customElements.get(e(t))||c();break;case"tds-divider":customElements.get(e(t))||h();break;case"tds-icon":customElements.get(e(t))||n()}}))}b();const m=l,p=b;export{m as TdsCard,p as defineCustomElement}