ca-web-components
Version:
web components for Clínica Alemana
156 lines (150 loc) • 5.36 kB
JavaScript
var g=Object.defineProperty;var f=(n,s,t)=>s in n?g(n,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):n[s]=t;var r=(n,s,t)=>f(n,typeof s!="symbol"?s+"":s,t);import{i as v,r as u,x as b}from"../assets/unsafe-html-DS3AO1W7.js";const y=v`
.container {
padding: 32px 0 24px;
}
.card {
scroll-snap-align: center;
display: grid;
grid-template-columns: 177px 1fr;
border-radius: 20px;
width: 487px;
min-width: 487px;
border: 1px solid #F2F5F9;
background: #FFF;
box-shadow: 0px 30px 40px 0px rgba(200, 200, 200, 0.25);
}
.card__image {
position: relative;
border-radius: 20px 0 0 20px;
height: 248px;
overflow: hidden;
}
.card__image img {
width: 100%;
height: 100%;
object-fit: cover;
}
.card__content {
display: flex;
flex-direction: column;
gap: 4px;
padding: 32px 24px;
color: #364855;
}
.card__link {
margin-top: 8px;
display: flex;
justify-content: start;
}
.card__link .button {
display: flex;
border-radius: 20px;
border: 1px solid #203442;
background: #FFF;
padding: 4px 16px;
}
a {
text-decoration: none;
color: currentColor;
}
.list {
display: flex;
gap: 16px;
//padding: 32px 32px 86px;
padding: 0 32px;
overflow-x: auto;
scroll-snap-type: x mandatory;
scroll-behavior: smooth;
//width: calc(100vw - 32px);
}
.actions {
display: none;
justify-content: end;
gap: 12px;
padding: 0 16px;
margin-top: 12px;
}
.actions button {
background-color: #4DBFB8;
width: 40px;
height: 40px;
border-radius: 50%;
border: none;
cursor: pointer;
display: flex;
align-items: center;
justify-content: center;
--eloisa-ds-icon-color: currentColor;
color: #FFF;
}
.actions button:disabled {
background-color: #E9EBEC;
color: #909AA1;
cursor: initial;
}
(max-width: 768px) {
.list {
padding: 32px 16px;
}
.card {
display: flex;
width: 315px;
min-width: 315px;
flex-direction: column;
}
.card__image {
border-radius: 20px 20px 0 0;
height: 149px;
}
.card__content {
padding: 16px 16px 32px 16px;
}
}
`;class c extends u{constructor(){super();r(this,"handleScroll",(t,o,i)=>{const e=t.target.scrollLeft,a=t.target.scrollWidth,d=t.target.clientWidth,p=a-e-d;e>0?o.disabled=!1:o.disabled=!0,p>0?i.disabled=!1:i.disabled=!0});r(this,"handlePrev",()=>{const t=this.shadowRoot.querySelector(".list");t.scrollLeft-=480});r(this,"handleNext",()=>{const t=this.shadowRoot.querySelector(".list");t.scrollLeft+=480});this.name="",this.value="",this.data=[]}updated(t){if(t.has("data")){const o=this.shadowRoot.querySelector(".list"),i=this.shadowRoot.querySelector(".actions");o.scrollWidth>o.clientWidth&&(i.style.display="flex")}}firstUpdated(){this.data=this.data.map(e=>{var a,d;return{subtitle:e.Subtitulo,title:e.Identifier,description:e.Bajada,images:{desktop:(a=e.imagenes[0])==null?void 0:a.imagen,mobile:(d=e.imagenes[1])==null?void 0:d.imagen},link_button:e.LinkBoton,name_button:e.TextoBoton}}),this.requestUpdate();const t=this.shadowRoot.querySelector(".list"),o=this.shadowRoot.querySelector(".prev"),i=this.shadowRoot.querySelector(".next");t.addEventListener("scroll",e=>this.handleScroll(e,o,i)),o.addEventListener("click",this.handlePrev),i.addEventListener("click",this.handleNext)}render(){const t=({subtitle:o,title:i,description:e,images:a,name_button:d="Ver más",link_button:p})=>{const x=({text:l,length:h=100})=>(l==null?void 0:l.length)>h?`${l.substring(0,h)}...`:l;return b`
<article class="card">
<div class="card__image">
<picture>
<source media="(min-width: 600px)" srcset="${a==null?void 0:a.desktop}">
<img src="${a==null?void 0:a.mobile}" alt="${i}">
</picture>
</div>
<div class="card__content">
<cas-text variant="body2"
>${x({text:o,length:38})}</cas-text
>
<cas-text variant="headline2"
>${x({text:i,length:38})}</cas-text
>
<cas-text variant="caption2"
>${x({text:e,length:83})}</cas-text
>
<div class="card__link">
<a href="${p}" class="button">
<cas-text variant="footnote1">${d}</cas-text>
</a>
</div>
</div>
</article>
`};return b`
<section class="container">
<div class="list">${this.data.map(o=>t(o))}</div>
<div class="actions">
<button class="prev" disabled>
<cas-icon
disabled
variant="flat"
name="flat-arrowLeft"
size="16"
></cas-icon>
</button>
<button class="next">
<cas-icon
disabled
variant="flat"
name="flat-arrowRight"
size="16"
></cas-icon>
</button>
</div>
</section>
`}}r(c,"styles",y),r(c,"shadowRootOptions",{...u.shadowRootOptions,mode:"open"}),r(c,"properties",{name:{type:String},value:{type:String},data:{type:Array}});customElements.get("ca-banners-cta")||customElements.define("ca-banners-cta",c);