@postnord/web-components
Version:
PostNord Web Components
91 lines (85 loc) • 8.75 kB
JavaScript
/*!
* Built with Stencil
* By PostNord.
*/
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const index = require('./index-ec4ed1cc.js');
const arrow_right = require('./arrow_right-8a1192e2.js');
const open_in_new = require('./open_in_new-5149c4cf.js');
const helpers = require('./helpers-2e2349b4.js');
const pnCardCss = "pn-card{position:relative;display:block}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);}pn-card .pn-card[data-link]:hover{background-color:#e0f8ff}pn-card .pn-card[data-link][data-focus]{outline-color:#005d92}pn-card .pn-card[data-link] .pn-card-navigation>[slot=navigation]{display:none}pn-card .pn-card[data-horizontal]{flex-direction:row}pn-card .pn-card[data-horizontal][data-reverse]{flex-direction:row-reverse}pn-card .pn-card[data-horizontal][data-reverse] .pn-card-picture{clip-path:ellipse(100% 175% at right center)}pn-card .pn-card[data-horizontal] .pn-card-content{flex:1 1 50%}pn-card .pn-card[data-horizontal] .pn-card-image{flex:1 1 50%;flex-direction:row}pn-card .pn-card[data-horizontal] .pn-card-picture{width:100%;clip-path:ellipse(100% 175% at left center)}pn-card .pn-card[data-reverse]{flex-direction:column-reverse}pn-card .pn-card[data-reverse] .pn-card-picture{clip-path:ellipse(175% 100% at bottom center)}pn-card .pn-card-header{display:flex;flex-direction:column;gap:clamp(0.5em, 5vw, 0.75em)}pn-card .pn-card-label{font-size:clamp(1.125em, 5vw, 1.5em);font-weight:700;margin:0}pn-card .pn-card-label-overline{color:#5e554a;font-size:0.875em;font-weight:400;margin:0}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)}pn-card .pn-card-link:hover{color:#0d234b;text-decoration-color:#0d234b}pn-card .pn-card-link:hover>pn-icon>.pn-icon-svg>path{fill:#0d234b}pn-card .pn-card-link:focus{outline:0;color:#0d234b;text-decoration-color:#0d234b}pn-card .pn-card-link:focus>pn-icon>.pn-icon-svg>path{fill:#0d234b}pn-card .pn-card-link:before{content:\"\";position:absolute;top:0;left:0;width:100%;height:100%}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)}pn-card .pn-card-section{display:flex;flex-direction:column;gap:0.5em;color:#5e554a}pn-card .pn-card-section-paragraph,pn-card .pn-card-section p{margin:0 0 0.25em}pn-card .pn-card-section-paragraph:last-child,pn-card .pn-card-section p:last-child{margin:0em}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}pn-card .pn-card-navigation>pn-button{flex:1 1 12em}pn-card .pn-card-navigation:empty{display:none}pn-card .pn-card-image{position:relative;display:flex;flex-direction:column}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)}pn-card .pn-card-picture:empty{display:none}pn-card .pn-card-picture>*[slot=image]{display:block;height:100%;width:100%;object-fit:cover}pn-card .pn-card-tags{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:0.5em}pn-card .pn-card-tags:empty{display:none}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}@keyframes ripple{to{transform:translate(-50%, -50%) scale(1);opacity:0}}";
const PnCardStyle0 = pnCardCss;
const PnCard = class {
constructor(hostRef) {
index.registerInstance(this, hostRef);
this.pnCard = index.createEvent(this, "pnCard", 7);
this.visibleOutline = false;
this.label = undefined;
this.labelTag = 'h3';
this.overline = undefined;
this.text = undefined;
this.cardId = null;
this.horizontal = false;
this.reverse = false;
this.aspectRatio = '';
this.href = undefined;
this.hrefLabel = undefined;
this.target = undefined;
this.rel = 'noopener noreferrer';
this.icon = null;
}
id = `pn-card-${helpers.uuidv4()}`;
idTitle = `${this.id}-title`;
get hostElement() { return index.getElement(this); }
watchCardId() {
const id = this.cardId || this.id;
this.idTitle = `${id}-title`;
}
/** Emitted when you click on the card link (if you use the `href` prop). */
pnCard;
componentWillLoad() {
this.watchCardId();
}
isExternal() {
return this.target === '_blank';
}
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() {
if (!!this.icon)
return this.icon;
return this.isExternal() ? open_in_new.open_in_new : arrow_right.arrow_right;
}
getHeadingTag() {
const tags = ['h2', 'h3', 'h4', 'h5', 'h6', 'p'];
return tags.includes(this.labelTag) ? this.labelTag : 'h3';
}
handleFocus({ type, target }) {
this.visibleOutline = type === 'focus' && target.matches(':focus-visible');
}
handleClick(event) {
helpers.ripple(event, this.hostElement, '.pn-card');
this.pnCard.emit({ click: event });
}
render() {
const TitleTag = this.getHeadingTag();
return (index.h(index.Host, { key: '5059ced25e86a6fe205d470bf3591cd971adf8f1' }, index.h("article", { key: 'f1135d78ed76c1bbd4c2f4064d83d0df93aca339', id: this.cardId, class: "pn-card", "data-link": !!this.href, "data-horizontal": this.horizontal, "data-reverse": this.reverse, "data-focus": this.visibleOutline }, index.h("div", { key: 'c2ee9fa9314c19d40ad7725866dddfdd41bde019', class: "pn-card-image" }, index.h("picture", { key: '75b53ffaf62275459085540c4670801f20c943b5', class: "pn-card-picture", style: { '--pn-card-aspect-ratio': this.aspectRatio || 'unset' } }, index.h("slot", { key: '83a17d8a5c675d0b6e22a6683c697fce689a901c', name: "image" }))), index.h("div", { key: '8939d981a52f0802fd39e2fec5e9b430aa0d0d7e', class: "pn-card-content" }, index.h("header", { key: 'ba23d81d3f9d1770a94625db39ef10b79f52e588', class: "pn-card-header" }, index.h("div", { key: '4ac22c93173cde6cee1bd05557322733e6a1a358', class: "pn-card-tags" }, index.h("slot", { key: 'a9764743f78b34dbe4762ab5e7f7df5812bff9a0', name: "tags" })), !!this.overline && index.h("p", { key: '5b931af9c1d702439c3d7044549a8a0b721d0732', class: "pn-card-label-overline" }, this.overline), !!this.label && (index.h(TitleTag, { key: 'f431c3b6a7f0864ad12d0b585d6014657bda8163', id: this.getTitleId(), class: "pn-card-label" }, this.label)), index.h("slot", { key: '9500f8d69acd614b628fe97a8a1a3fe36ee0e64e', name: "header" })), index.h("section", { key: '8ace8af3b532dadaf129ffe12d6159a6e9c4820e', class: "pn-card-section" }, !!this.text && index.h("p", { key: 'ac162dbd6fd940e3a1b87b38ffa1acdb8dbfab76', class: "pn-card-section-paragraph" }, this.text), index.h("slot", { key: '814238314b9b5e77e6f7eb1c044016eb59f0d23b' })), index.h("nav", { key: '22cd78b16c68c5a0449223ad12c3bf756642928a', class: "pn-card-navigation" }, this.showHref() && (index.h("a", { key: '6fbfd640bdc555f272fb1cf72b27525fbb0e0e8f', class: "pn-card-link", href: this.href, target: this.target, rel: this.rel, "aria-labelledby": this.getLabelledby(), onClick: event => this.handleClick(event), onFocus: event => this.handleFocus(event), onBlur: event => this.handleFocus(event) }, this.hrefLabel, index.h("pn-icon", { key: '263e2160a76fc5258a44aa40bc6d52df8ec25086', color: "blue700", icon: this.getIcon() }))), index.h("slot", { key: 'edfeca3a4eb44e246a199985577355f570356258', name: "navigation" }))))));
}
static get watchers() { return {
"cardId": ["watchCardId"]
}; }
};
PnCard.style = PnCardStyle0;
exports.pn_card = PnCard;
//# sourceMappingURL=pn-card.cjs.entry.js.map