import { html, css, SkhemataBase, property, CSSResult, unsafeHTML, } from '@skhemata/skhemata-base'; import { FontAwesomeIcon } from '@riovir/wc-fontawesome'; import { fas } from '@fortawesome/free-solid-svg-icons'; export class SkhemataSubscriptionPlan extends SkhemataBase { static get styles() { return [ ...super.styles, css` .plan-meta-price { background: red; } .feature-list li { border-bottom: 1px solid #e3e3e3; padding: 0.3rem 0; } .feature-list li:hover { background: #f9f9f9; } .feature-list li:first-child { border-top: 1px solid #e3e3e3; } .feature-list li:last-child { border-bottom: none; } .plan { border: 1px solid #e3e3e3; padding-top: 1.25rem; padding-bottom: 1.25rem; transition: all 0.6s ease-in-out; background: white; cursor: pointer; margin-bottom: 3rem; } .plan-name, .plan-price { margin-bottom: 1rem; } .box { padding: 0px; } .feature-item { margin: auto; } .bottom-button .button { width: 10rem; } @media screen and (min-width: 500px) { .plan.default { transform: scale(1.02); } .plan:hover { transform: scale(1.02); } } .plan.default .plan-button { border: none; color: #fff; } .plan .plan-button { border: 3px solid #e3e3e3; color: #b0b0b0; background: #fff; } .plan:hover .plan-button { border: none; color: #fff; } @media screen and (min-width: 769px) { .plan { padding-bottom: 6rem; margin-bottom: 0rem; } .bottom-button .button { position: absolute; bottom: 1rem; transform: translate(-50%, 0); } } `, ]; } static get scopedElements() { return { 'fa-icon': FontAwesomeIcon, }; } // Don't use hover js on mobile @property({ type: Boolean }) mobile = false; @property({ type: Object }) currency = { locale: 'en-US', code: 'USD', }; @property({ type: Array }) plans: { name: string; price: string; description: string; features: any[]; interval: string; icon: any; color: number; default: boolean; trial: { price: number; periodType: string; periodLength: number; } | null; }[] = [ { name: '', price: '', description: '', features: [], interval: '', icon: '', color: 777, default: false, trial: null, }, ]; openSubscription(index: number) { this.dispatchEvent( new CustomEvent('select-plan', { detail: { data: index, }, bubbles: true, composed: true, }) ); } updateButtonStyle(e: any) { if (this.mobile) { return; } // Remove default from all plans const plans: HTMLElement[] = Array.from( e.target.parentNode.getElementsByClassName('plan') ); plans.forEach(plan => { plan.classList.remove('default'); const button = plan.querySelector('button'); if (button) button.style.background = 'white'; }); const color = e.target.getAttribute('plan-color'); const button = e.target.querySelector('button'); button.style.background = color; } removeButtonStyle(e: InputEvent) { if (this.mobile) { return; } // const color = ( e.target)?.getAttribute('plan-color'); const button = (e.target)?.querySelector('button'); if (button) button.style.background = 'white'; } async firstUpdated() { super.firstUpdated(); const ua = navigator.userAgent; const isMobile = /Android|webOS|iPhone|iPad|iPod/i.test(ua); if (isMobile) { this.mobile = true; } this.shadowRoot ?.querySelectorAll('a') .forEach((link: HTMLAnchorElement) => { link.addEventListener('click', event => { event.stopPropagation(); }); }); } render() { return html`
${this.plans?.map( (plan, index) => html`
this.openSubscription(index)} @keydown=${(e: KeyboardEvent) => { if (e.code === '13') this.openSubscription(index); }} plan-color="${plan.color}" >

${plan.name}

${this.currency ? new Intl.NumberFormat(this.currency.locale, { style: 'currency', currency: this.currency.code, }).format(parseFloat(plan.price)) : ''} / mo

    ${plan.features.map( (feature: any) => html`
  • ${unsafeHTML(feature)}

  • ` )}
` )}
`; } }