UNPKG

@postnord/web-components

Version:
109 lines (104 loc) 10.7 kB
/*! * Built with Stencil * By PostNord. */ 'use strict'; var index = require('./index-DWu-2oJc.js'); var arrow_right = require('./arrow_right-CABi9Wkp.js'); var open_in_new = require('./open_in_new-B-zmn5xr.js'); var index$1 = require('./index.cjs.js'); const pnCardCss = () => `${index.transformTag("pn-card")}{position:relative;display:block}${index.transformTag("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)}@media (prefers-reduced-motion: reduce){${index.transformTag("pn-card")} .pn-card{transition-duration:0s;transition-delay:0s}}${index.transformTag("pn-card")} .pn-card[data-link]:hover{background-color:#e0f8ff}${index.transformTag("pn-card")} .pn-card[data-link][data-focus]{outline-color:#005d92}${index.transformTag("pn-card")} .pn-card{}${index.transformTag("pn-card")} .pn-card[data-link] .pn-card-navigation>[slot=navigation]{display:none}${index.transformTag("pn-card")} .pn-card[data-horizontal]{flex-direction:row}${index.transformTag("pn-card")} .pn-card[data-horizontal][data-reverse]{flex-direction:row-reverse}${index.transformTag("pn-card")} .pn-card[data-horizontal][data-reverse] .pn-card-picture{clip-path:ellipse(100% 175% at right center)}${index.transformTag("pn-card")} .pn-card[data-horizontal] .pn-card-content{flex:1 1 50%}${index.transformTag("pn-card")} .pn-card[data-horizontal] .pn-card-image{flex:1 1 50%;flex-direction:row}${index.transformTag("pn-card")} .pn-card[data-horizontal] .pn-card-picture{width:100%;clip-path:ellipse(100% 175% at left center)}${index.transformTag("pn-card")} .pn-card[data-reverse]{flex-direction:column-reverse}${index.transformTag("pn-card")} .pn-card[data-reverse] .pn-card-picture{clip-path:ellipse(175% 100% at bottom center)}${index.transformTag("pn-card")} .pn-card-header{display:flex;flex-direction:column;gap:clamp(0.5em, 5vw, 0.75em)}${index.transformTag("pn-card")} .pn-card-label{font-size:clamp(1.125em, 5vw, 1.5em);font-weight:700;margin:0}${index.transformTag("pn-card")} .pn-card-label-overline{color:#5e554a;font-size:0.875em;font-weight:400;margin:0}${index.transformTag("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)}@media (prefers-reduced-motion: reduce){${index.transformTag("pn-card")} .pn-card-link{transition-duration:0s;transition-delay:0s}}${index.transformTag("pn-card")} .pn-card-link:hover{color:#0d234b;text-decoration-color:#0d234b}${index.transformTag("pn-card")} .pn-card-link:hover>${index.transformTag("pn-icon")} .pn-icon-svg>path{fill:#0d234b}${index.transformTag("pn-card")} .pn-card-link:focus{outline:0;color:#0d234b;text-decoration-color:#0d234b}${index.transformTag("pn-card")} .pn-card-link:focus>${index.transformTag("pn-icon")} .pn-icon-svg>path{fill:#0d234b}${index.transformTag("pn-card")} .pn-card-link:before{content:"";position:absolute;top:0;left:0;width:100%;height:100%}${index.transformTag("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)}${index.transformTag("pn-card")} .pn-card-section{display:flex;flex-direction:column;gap:0.5em;color:#5e554a}${index.transformTag("pn-card")} .pn-card-section-paragraph,${index.transformTag("pn-card")} .pn-card-section p{margin:0 0 0.25em}${index.transformTag("pn-card")} .pn-card-section-paragraph:last-child,${index.transformTag("pn-card")} .pn-card-section p:last-child{margin:0em}${index.transformTag("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}${index.transformTag("pn-card")} .pn-card-navigation>${index.transformTag("pn-button")}{flex:1 1 12em}${index.transformTag("pn-card")} .pn-card-navigation:empty{display:none}${index.transformTag("pn-card")} .pn-card-image{position:relative;display:flex;flex-direction:column}${index.transformTag("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)}${index.transformTag("pn-card")} .pn-card-picture:empty{display:none}${index.transformTag("pn-card")} .pn-card-picture>*[slot=image]{display:block;height:100%;width:100%;object-fit:cover}${index.transformTag("pn-card")} .pn-card-tags{display:flex;flex-direction:row;flex-wrap:wrap;align-items:center;gap:0.5em}${index.transformTag("pn-card")} .pn-card-tags:empty{display:none}${index.transformTag("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 PnCard = class { constructor(hostRef) { index.registerInstance(this, hostRef); this.pnCard = index.createEvent(this, "pnCard", 7); } id = `pn-card-${index$1.uuidv4()}`; idTitle = `${this.id}-title`; visibleOutline = false; get hostElement() { return index.getElement(this); } /** Headline of the card. Will act as label for the link if there is no `href-label` set. */ label; /** The label HTML tag. Default is `h3`. */ labelTag = 'h3'; /** Set a smaller text above the `label` text. */ overline; /** Text content of the card. */ text; /** Set a HTML id for the card. Optional and not required. */ cardId = null; /** * Uee the horizontal card layout. * @category Features * */ horizontal = false; /** Reverse the order of which the image will wrap. @category Features */ reverse = false; /** * Select image aspect ratio. Example: '3/3', '16/9'. * @see {@link https://developer.mozilla.org/en-US/docs/Web/CSS/aspect-ratio CSS documentation.} * @category Features * */ aspectRatio = ''; /** The card link. @category Href */ href; /** The link text. @category Href */ hrefLabel; /** The target attribute of the link. @category Href */ target; /** The rel attribute of the link. @category Href */ rel = 'noopener noreferrer'; /** The link icon. Defaults to `arrow_right` or `open_in_new` if `target="_blank"`. @category Href */ icon = null; 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) { index$1.ripple(event, this.hostElement, '.pn-card'); this.pnCard.emit({ click: event }); } render() { const TitleTag = this.getHeadingTag(); return (index.h(index.Host, { key: '65ed28a0a625760d11f9bd7961978af7573f7062' }, index.h("article", { key: '2f05480099b5bedddba115a3f00174d0ed4f9658', 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: '1ec2a31f2e71b9f4a511efb49461541f141ff077', class: "pn-card-image" }, index.h("picture", { key: '869648c55b9e64091b55f501b759ffcddc33a8c5', class: "pn-card-picture", style: { '--pn-card-aspect-ratio': this.aspectRatio || 'unset' } }, index.h("slot", { key: '9e31feb5e4c486159fb4f9ebb57cefbd7d156988', name: "image" }))), index.h("div", { key: 'e2cfd35b304c05fb569da26aa7f248ed53b1e7aa', class: "pn-card-content" }, index.h("header", { key: 'a5730ce876dd1b5fa0c6c37ba400801530bf99ea', class: "pn-card-header" }, index.h("div", { key: '4e9566e679185db1704e313002d20d7016558c25', class: "pn-card-tags" }, index.h("slot", { key: '0c4863c1ef7b69ef8a333dd7ac834f76b8a3fc00', name: "tags" })), !!this.overline && index.h("p", { key: '8129ee0e178e4db9fcbf9895e75d64c02279a0a6', class: "pn-card-label-overline" }, this.overline), !!this.label && (index.h(TitleTag, { key: '62a8d9c1512683f3e4248eac05bf2f33e0374fe9', id: this.getTitleId(), class: "pn-card-label" }, this.label)), index.h("slot", { key: '13f3c2e3e182ce134dc7be0af3c8c2dec1c1f751', name: "header" })), index.h("section", { key: 'c34ddb8484423b65927ace2e0b46deed6b1d3b64', class: "pn-card-section" }, !!this.text && index.h("p", { key: '8370b223a2af93f64eb2efd84dda0b172324be54', class: "pn-card-section-paragraph" }, this.text), index.h("slot", { key: '363cc14089263d2e640f35707a6503aeb77ae8a6' })), index.h("nav", { key: '5636561cc2dc0eb1a1f42d213e87e73da9a3ce98', class: "pn-card-navigation" }, this.showHref() && (index.h("a", { key: '9c7be2037e54320ccb2668170828e7ffc8fd7d25', 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: 'd77e3349eb1ed2cb3e8e72418c70d66b93ad5b20', color: "blue700", icon: this.getIcon() }))), index.h("slot", { key: 'c28d4208e146a77f334fc326e7abbbf53e86e028', name: "navigation" })))))); } static get watchers() { return { "cardId": [{ "watchCardId": 0 }] }; } }; PnCard.style = pnCardCss(); exports.pn_card = PnCard;