@postnord/web-components
Version:
PostNord Web Components
5 lines • 8.39 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
import{transformTag as e,proxyCustomElement as a,HTMLElement as r,createEvent as n,h as t,Host as i}from"@stencil/core/internal/client";import{a as c}from"./arrow_right.js";import{o as d}from"./open_in_new.js";import{u as o,o as l}from"./helpers.js";import{d as p}from"./pn-icon2.js";const s=a(class extends r{constructor(e){super(),!1!==e&&this.__registerHost(),this.pnCard=n(this,"pnCard",7)}id="pn-card-"+o();idTitle=this.id+"-title";visibleOutline=!1;get hostElement(){return this}label;labelTag="h3";overline;text;cardId=null;horizontal=!1;reverse=!1;aspectRatio="";href;hrefLabel;target;rel="noopener noreferrer";icon=null;watchCardId(){this.idTitle=(this.cardId||this.id)+"-title"}pnCard;componentWillLoad(){this.watchCardId()}isExternal(){return"_blank"===this.target}showTitle(){return!!this.label}showHref(){return!!this.href&&(this.hrefLabel||this.showTitle())}getTitleId(){return this.hrefLabel?null:this.idTitle}getLabelledby(){return this.hrefLabel?null:this.showTitle()?this.idTitle:null}getIcon(){return this.icon?this.icon:this.isExternal()?d:c}getHeadingTag(){return["h2","h3","h4","h5","h6","p"].includes(this.labelTag)?this.labelTag:"h3"}handleFocus({type:e,target:a}){this.visibleOutline="focus"===e&&a.matches(":focus-visible")}handleClick(e){l(e,this.hostElement,".pn-card"),this.pnCard.emit({click:e})}render(){const e=this.getHeadingTag();return t(i,{key:"8126385831d763637aed6ebe4fa61fd0bdb42764"},t("article",{key:"93c75dc2d9e71844e36a9cdd6914f42eae34f7b0",id:this.cardId,class:"pn-card","data-link":!!this.href,"data-horizontal":this.horizontal,"data-reverse":this.reverse,"data-focus":this.visibleOutline},t("div",{key:"140936bb72867a5ef4351363dfda52698b9d9df0",class:"pn-card-image"},t("picture",{key:"60de2f3f53b4d7f1e1cbe37b1ff47686c9e48b72",class:"pn-card-picture",style:{"--pn-card-aspect-ratio":this.aspectRatio||"unset"}},t("slot",{key:"47cffafc0d642f6cf0c682cd96f9fd11609f924e",name:"image"}))),t("div",{key:"6768342177fe3884d9bd20b0ca516cf026b69751",class:"pn-card-content"},t("header",{key:"91e023c92c33bf74c39200387edc7a3d3c2f2d42",class:"pn-card-header"},t("div",{key:"9d7771c4275569012021a07f9165ba4a8ce8c297",class:"pn-card-tags"},t("slot",{key:"c45641bd02093f8001dee361b6b8577a383f72ba",name:"tags"})),!!this.overline&&t("p",{key:"b152b16d2488e82556e9f56f90daf0edfe8ae33f",class:"pn-card-label-overline"},this.overline),!!this.label&&t(e,{key:"3bc086490090afc05ad44c0e1736009b82fbe814",id:this.getTitleId(),class:"pn-card-label"},this.label),t("slot",{key:"1188ca2c3260dd509811cfb5aa5356488f211e1a",name:"header"})),t("section",{key:"ba0b7362ddd721041466ac979ba198170b016fb1",class:"pn-card-section"},!!this.text&&t("p",{key:"76aa9e90ac18ff66ec15a436ec8eec9e22c67748",class:"pn-card-section-paragraph"},this.text),t("slot",{key:"bd0f035ce418425c1ac1871ec1cb98f850cd97e1"})),t("nav",{key:"1a538e55ed6c9c07f3f8c5dd823f80ed3a149ed6",class:"pn-card-navigation"},this.showHref()&&t("a",{key:"a18605058f0dc733ceeeab9fa6a44fb524c93630",class:"pn-card-link",href:this.href,target:this.target,rel:this.rel,"aria-labelledby":this.getLabelledby(),onClick:e=>this.handleClick(e),onFocus:e=>this.handleFocus(e),onBlur:e=>this.handleFocus(e)},this.hrefLabel,t("pn-icon",{key:"066242008cd49a69d64db93da7a87bbdcdd1beda",color:"blue700",icon:this.getIcon()})),t("slot",{key:"bbe0271663622b8adf542232daa573a467b34f16",name:"navigation"})))))}static get watchers(){return{cardId:[{watchCardId:0}]}}static get style(){return`${e("pn-card")}{position:relative;display:block}${e("pn-card")} .pn-card{position:relative;background-color:#ffffff;color:#2d2013;border-radius:0.5em;display:flex;flex-direction:column;height:100%;overflow:hidden;box-shadow:0em 0.0625em 0.125em 0em rgba(20, 20, 20, 0.11), 0em 0.1875em 0.4375em 0em rgba(0, 0, 0, 0.13);outline:0.2rem solid transparent;outline-offset:0.2rem;transition-property:background-color, outline-color;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)} (prefers-reduced-motion: reduce){${e("pn-card")} .pn-card{transition-duration:0s;transition-delay:0s}}${e("pn-card")} .pn-card[data-link]:hover{background-color:#e0f8ff}${e("pn-card")} .pn-card[data-link][data-focus]{outline-color:#005d92}${e("pn-card")} .pn-card{}${e("pn-card")} .pn-card[data-link] .pn-card-navigation>[slot=navigation]{display:none}${e("pn-card")} .pn-card[data-horizontal]{flex-direction:row}${e("pn-card")} .pn-card[data-horizontal][data-reverse]{flex-direction:row-reverse}${e("pn-card")} .pn-card[data-horizontal][data-reverse] .pn-card-picture{clip-path:ellipse(100% 175% at right center)}${e("pn-card")} .pn-card[data-horizontal] .pn-card-content{flex:1 1 50%}${e("pn-card")} .pn-card[data-horizontal] .pn-card-image{flex:1 1 50%;flex-direction:row}${e("pn-card")} .pn-card[data-horizontal] .pn-card-picture{width:100%;clip-path:ellipse(100% 175% at left center)}${e("pn-card")} .pn-card[data-reverse]{flex-direction:column-reverse}${e("pn-card")} .pn-card[data-reverse] .pn-card-picture{clip-path:ellipse(175% 100% at bottom center)}${e("pn-card")} .pn-card-header{display:flex;flex-direction:column;gap:clamp(0.5em, 5vw, 0.75em)}${e("pn-card")} .pn-card-label{font-size:clamp(1.125em, 5vw, 1.5em);font-weight:700;margin:0}${e("pn-card")} .pn-card-label-overline{color:#5e554a;font-size:0.875em;font-weight:400;margin:0}${e("pn-card")} .pn-card-link{display:inline-flex;align-items:center;gap:0.25em;color:#005d92;text-decoration-color:transparent;-webkit-tap-highlight-color:transparent;transition-property:color, text-decoration-color;transition-duration:0.2s;transition-timing-function:cubic-bezier(0.7, 0, 0.3, 1)} (prefers-reduced-motion: reduce){${e("pn-card")} .pn-card-link{transition-duration:0s;transition-delay:0s}}${e("pn-card")} .pn-card-link:hover{color:#0d234b;text-decoration-color:#0d234b}${e("pn-card")} .pn-card-link:hover>${e("pn-icon")} .pn-icon-svg>path{fill:#0d234b}${e("pn-card")} .pn-card-link:focus{outline:0;color:#0d234b;text-decoration-color:#0d234b}${e("pn-card")} .pn-card-link:focus>${e("pn-icon")} .pn-icon-svg>path{fill:#0d234b}${e("pn-card")} .pn-card-link:before{content:"";position:absolute;top:0;left:0;width:100%;height:100%}${e("pn-card")} .pn-card-content{display:flex;flex-direction:column;flex-wrap:nowrap;flex:1;gap:clamp(0.5em, 5vw, 0.75em);padding:clamp(0.75em, 5vw, 1.5em) clamp(0.75em, 5vw, 1.5em)}${e("pn-card")} .pn-card-section{display:flex;flex-direction:column;gap:0.5em;color:#5e554a}${e("pn-card")} .pn-card-section-paragraph,${e("pn-card")} .pn-card-section p{margin:0 0 0.25em}${e("pn-card")} .pn-card-section-paragraph:last-child,${e("pn-card")} .pn-card-section p:last-child{margin:0em}${e("pn-card")} .pn-card-navigation{margin-top:auto;padding-top:clamp(0.5em, 5vw, 0.75em);display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:0.5em}${e("pn-card")} .pn-card-navigation>${e("pn-button")}{flex:1 1 12em}${e("pn-card")} .pn-card-navigation:empty{display:none}${e("pn-card")} .pn-card-image{position:relative;display:flex;flex-direction:column}${e("pn-card")} .pn-card-picture{margin:0;padding:0;display:block;overflow:hidden;clip-path:ellipse(175% 100% at top center);aspect-ratio:var(--pn-card-aspect-ratio)}${e("pn-card")} .pn-card-picture:empty{display:none}${e("pn-card")} .pn-card-picture>*[slot=image]{display:block;height:100%;width:100%;object-fit:cover}${e("pn-card")} .pn-card-tags{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:0.5em}${e("pn-card")} .pn-card-tags:empty{display:none}${e("pn-card")} .pn-card>.pn-ripple{animation:ripple 0.4s cubic-bezier(0.7, 0, 0.3, 1);position:absolute;border-radius:50%;background-color:#005d92;transform:translate(-50%, -50%) scale(0);opacity:0.1;pointer-events:none;z-index:3} ripple{to{transform:translate(-50%, -50%) scale(1);opacity:0}}`}},[772,"pn-card",{label:[1],labelTag:[1,"label-tag"],overline:[1],text:[1],cardId:[1,"card-id"],horizontal:[4],reverse:[4],aspectRatio:[1,"aspect-ratio"],href:[1],hrefLabel:[1,"href-label"],target:[1],rel:[1],icon:[1],visibleOutline:[32]},void 0,{cardId:[{watchCardId:0}]}]),f=s,h=function(){"undefined"!=typeof customElements&&["pn-card","pn-icon"].forEach((a=>{switch(a){case"pn-card":customElements.get(e(e(a)))||customElements.define(e(e(a)),s);break;case"pn-icon":customElements.get(e(e(a)))||p()}}))};export{f as PnCard,h as defineCustomElement}