Skip to content

Commit

Permalink
Merge pull request #159 from pt-kompas-media-nusantara/feat/81062-imp…
Browse files Browse the repository at this point in the history
…rovement-metered-paywall

[Feat] 81062 Create Metered Register Component
  • Loading branch information
billsur authored Aug 30, 2023
2 parents 4d699ec + ec67b05 commit 0102075
Show file tree
Hide file tree
Showing 10 changed files with 497 additions and 127 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kompasid/web-components",
"version": "v1.6.2",
"version": "v1.7.0",
"description": "Kompas.id reusable web components",
"main": "dist/index.cjs.js",
"module": "dist/custom-elements/index.js",
Expand Down
21 changes: 21 additions & 0 deletions src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,12 @@ export namespace Components {
*/
"userInitialName": string;
}
interface KompasMeteredRegister {
/**
* prop countdownArticle untuk menghandle sudah berapa artikel gratis yang user baca.
*/
"countdownArticle": number;
}
interface KompasPaywall {
"countdownArticle": number;
"isLogin": boolean;
Expand Down Expand Up @@ -388,6 +394,12 @@ declare global {
prototype: HTMLKompasHeaderAccountProfileElement;
new (): HTMLKompasHeaderAccountProfileElement;
};
interface HTMLKompasMeteredRegisterElement extends Components.KompasMeteredRegister, HTMLStencilElement {
}
var HTMLKompasMeteredRegisterElement: {
prototype: HTMLKompasMeteredRegisterElement;
new (): HTMLKompasMeteredRegisterElement;
};
interface HTMLKompasPaywallElement extends Components.KompasPaywall, HTMLStencilElement {
}
var HTMLKompasPaywallElement: {
Expand Down Expand Up @@ -437,6 +449,7 @@ declare global {
"kompas-header-account-help-center": HTMLKompasHeaderAccountHelpCenterElement;
"kompas-header-account-menu": HTMLKompasHeaderAccountMenuElement;
"kompas-header-account-profile": HTMLKompasHeaderAccountProfileElement;
"kompas-metered-register": HTMLKompasMeteredRegisterElement;
"kompas-paywall": HTMLKompasPaywallElement;
"kompas-paywall-banner-registration": HTMLKompasPaywallBannerRegistrationElement;
"kompas-paywall-body": HTMLKompasPaywallBodyElement;
Expand Down Expand Up @@ -666,6 +679,12 @@ declare namespace LocalJSX {
*/
"userInitialName"?: string;
}
interface KompasMeteredRegister {
/**
* prop countdownArticle untuk menghandle sudah berapa artikel gratis yang user baca.
*/
"countdownArticle"?: number;
}
interface KompasPaywall {
"countdownArticle"?: number;
"isLogin"?: boolean;
Expand Down Expand Up @@ -766,6 +785,7 @@ declare namespace LocalJSX {
"kompas-header-account-help-center": KompasHeaderAccountHelpCenter;
"kompas-header-account-menu": KompasHeaderAccountMenu;
"kompas-header-account-profile": KompasHeaderAccountProfile;
"kompas-metered-register": KompasMeteredRegister;
"kompas-paywall": KompasPaywall;
"kompas-paywall-banner-registration": KompasPaywallBannerRegistration;
"kompas-paywall-body": KompasPaywallBody;
Expand All @@ -790,6 +810,7 @@ declare module "@stencil/core" {
"kompas-header-account-help-center": LocalJSX.KompasHeaderAccountHelpCenter & JSXBase.HTMLAttributes<HTMLKompasHeaderAccountHelpCenterElement>;
"kompas-header-account-menu": LocalJSX.KompasHeaderAccountMenu & JSXBase.HTMLAttributes<HTMLKompasHeaderAccountMenuElement>;
"kompas-header-account-profile": LocalJSX.KompasHeaderAccountProfile & JSXBase.HTMLAttributes<HTMLKompasHeaderAccountProfileElement>;
"kompas-metered-register": LocalJSX.KompasMeteredRegister & JSXBase.HTMLAttributes<HTMLKompasMeteredRegisterElement>;
"kompas-paywall": LocalJSX.KompasPaywall & JSXBase.HTMLAttributes<HTMLKompasPaywallElement>;
"kompas-paywall-banner-registration": LocalJSX.KompasPaywallBannerRegistration & JSXBase.HTMLAttributes<HTMLKompasPaywallBannerRegistrationElement>;
"kompas-paywall-body": LocalJSX.KompasPaywallBody & JSXBase.HTMLAttributes<HTMLKompasPaywallBodyElement>;
Expand Down
37 changes: 37 additions & 0 deletions src/components/kompas-metered-register/kompas-metered-register.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.body {
position: sticky;
top: 0;
height: 100%;
width: 100%;
}

.chevron-down {
transform: rotate(180deg);
-webkit-transform: rotate(180deg);
transition: transform 0.2s ease-out;
}

.icon {
@apply h-3 w-3;

&.lg {
@apply h-6;

& svg {
@apply h-6;
}
}

&-blue-600 {
@apply text-blue-600;
& svg {
@apply fill-current;
}
}
}

@screen sm {
.banner-opened {
height: 400px;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { newE2EPage } from '@stencil/core/testing';

describe('kompas-metered-register', () => {
it('renders', async () => {
const page = await newE2EPage();
await page.setContent('<kompas-metered-register></kompas-metered-register>');

const element = await page.find('kompas-metered-register');
expect(element).toHaveClass('hydrated');
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
jest.mock('../../../assets/fontawesome-free-5.15.3-web/svgs/solid/chevron-down.svg', () => ({ chevronDown: '' }));
jest.mock('../../../assets/fontawesome-free-5.15.3-web/svgs/solid/chevron-up.svg', () => ({ chevronUp: '' }));

import { newSpecPage } from '@stencil/core/testing';
import { KompasMeteredRegister } from './kompas-metered-register';

describe('kompas-metered-register', () => {
// countdown-article = 0 or nothing passed
it('should renders nothing', async () => {
const page = await newSpecPage({
components: [KompasMeteredRegister],
html: `<kompas-metered-register></kompas-metered-register>`,
});
expect(page.root).toEqualHtml(`
<kompas-metered-register>
<mock:shadow-root>
</mock:shadow-root>
</kompas-metered-register>
`);
});

// countdown-article = 1
it('should renders content for last article quota', async () => {
const page = await newSpecPage({
components: [KompasMeteredRegister],
html: `<kompas-metered-register countdown-article=1></kompas-metered-register>`,
});
expect(page.root).toEqualHtml(`
<kompas-metered-register countdown-article=1>
<mock:shadow-root>
<div class="bottom-0 h-full sticky w-full">
<div class="bg-blue-100 bottom-0 px-4 py-4 w-full xl:px-0">
<div class="flex justify-center lg:max-w-7xl m-auto relative">
<div class="flex flex-col">
<div class="block gap-8 items-center justify-center lg:flex md:text-lg ml-auto self-center text-grey-600 text-left text-sm">
<div class="font-lora mb-3 md:mb-0 md:mt-0 md:px-0 md:text-lg mt-1 pr-14 text-base">
<span>
Ini Adalah
<b>
Artikel Gratis Terakhir
</b>
Anda.
<b>
Daftar Akun untuk Terus Membaca.
</b>
</span>
</div>
<div class="md:self-center">
<button class="bg-green-500 font-bold md:text-base md:w-auto p-1.5 px-5 rounded-md text-grey-100 text-sm w-full">
Daftar Akun
</button>
</div>
</div>
</div>
<div class="absolute right-0 top-0.5">
<button class="bg-blue-200 p-2.5 rounded-md">
<div class="false icon icon-blue-600"></div>
</button>
</div>
</div>
</div>
</div>
</mock:shadow-root>
</kompas-metered-register>
`);
});

// countdown-article = 2 ( > 1 )
it('should renders content for article quota more than one', async () => {
const page = await newSpecPage({
components: [KompasMeteredRegister],
html: `<kompas-metered-register countdown-article=2></kompas-metered-register>`,
});
expect(page.root).toEqualHtml(`
<kompas-metered-register countdown-article=2>
<mock:shadow-root>
<div class="bottom-0 h-full sticky w-full">
<div class="bg-blue-100 bottom-0 px-4 py-4 w-full xl:px-0">
<div class="flex justify-center lg:max-w-7xl m-auto relative">
<div class="flex flex-col">
<div class="block gap-8 items-center justify-center lg:flex md:text-lg ml-auto self-center text-grey-600 text-left text-sm">
<div class="font-lora mb-3 md:mb-0 md:mt-0 md:px-0 md:text-lg mt-1 pr-14 text-base">
<b>
Dukung Jurnalisme Berkualitas dengan Mendaftar Akun Kompas.id.
</b>
</div>
<div class="md:self-center">
<button class="bg-green-500 font-bold md:text-base md:w-auto p-1.5 px-5 rounded-md text-grey-100 text-sm w-full">
Daftar Akun
</button>
</div>
</div>
</div>
<div class="absolute right-0 top-0.5">
<button class="bg-blue-200 p-2.5 rounded-md">
<div class="false icon icon-blue-600"></div>
</button>
</div>
</div>
</div>
</div>
</mock:shadow-root>
</kompas-metered-register>
`);
});
});
131 changes: 131 additions & 0 deletions src/components/kompas-metered-register/kompas-metered-register.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { Component, h, State, Prop, Fragment, Host } from '@stencil/core';
import chevronUp from '../../../assets/fontawesome-free-5.15.3-web/svgs/solid/chevron-up.svg';

@Component({
tag: 'kompas-metered-register',
styleUrl: 'kompas-metered-register.css',
shadow: true,
})
export class KompasMeteredRegister {
/**
* state
*/
/**
* state registerUrl untuk memberikan link kemana user akan dialihkan.
*/
@State() registerUrl: string = 'https://account.kompas.cloud/register';
@State() isShowBanner: boolean = true;
@State() isExpandBanner: boolean = false;
/**
* prop countdownArticle untuk menghandle sudah berapa artikel gratis yang user baca.
*/
@Prop() countdownArticle: number = 0;

/**
* mengelola tampilan pada section metered register
*/
private bannerContent(): void {
if (!this.isExpandBanner) {
return (
<Fragment>
<div class="text-base md:text-lg font-lora mb-3 mt-1 md:mb-0 md:mt-0 pr-14 md:px-0">
{this.countdownArticle > 1 ? (
<b>Dukung Jurnalisme Berkualitas dengan Mendaftar Akun Kompas.id.</b>
) : (
<span>
Ini Adalah <b>Artikel Gratis Terakhir</b> Anda. <b>Daftar Akun untuk Terus Membaca.</b>
</span>
)}
</div>
<div class="md:self-center">{this.registerButtonTemplate()}</div>
</Fragment>
);
} else {
return (
<Fragment>
<div class="flex flex-col-reverse md:flex-row justify-center gap-4 md:gap-8">
<div class="flex flex-col justify-evenly text-center md:text-left md:w-5/12 gap-4 md:gap-2">
<p class="text-lg md:text-2xl font-lora">
{this.countdownArticle > 1 ? (
<b>Tertarik dengan Artikel Ini? Daftar untuk Akses Artikel Menarik Lainnya</b>
) : (
<span>
Anda Sedang Membaca <b>Artikel Premium Gratis Terakhir</b> dari Kompas.id
</span>
)}
</p>
<p class="text-sm md:text-base">
{this.countdownArticle > 1 ? (
<Fragment>Dapatkan akses ke beragam konten dan fitur premium Kompas.id.</Fragment>
) : (
<Fragment>Ayo daftar akun untuk akses ke beragam artikel dan fitur premium.</Fragment>
)}{' '}
Anda juga mendukung jurnalisme berkualitas dengan mendaftar akun.
</p>
<div class="md:self-start">{this.registerButtonTemplate()}</div>
</div>
<div class="flex justify-center">
<img src="https://d3w4qaq4xm1ncv.cloudfront.net/paywall-asset/paywall_ilustrasi3-03_1.png" class="h-40 w-40 md:w-full md:h-full" />
</div>
</div>
</Fragment>
);
}
}

/**
* template button register
*/
private registerButtonTemplate = (): void => {
return (
<button onClick={this.redirectToRegister} class="bg-green-500 p-1.5 w-full md:w-auto rounded-md font-bold text-grey-100 px-5 text-sm md:text-base">
Daftar Akun
</button>
);
};

private bannerTemplate = (): void => {
return (
<Fragment>
<div class="block lg:flex items-center justify-center gap-8 text-grey-600 text-sm md:text-lg self-center text-left ml-auto">{this.bannerContent()}</div>
</Fragment>
);
};

private redirectToRegister = (): void => {
window.location.href = this.registerUrl;
};

private triggerExpandBanner = (): void => {
this.isExpandBanner = !this.isExpandBanner;
};

componentWillLoad() {
const getCountdown = this.countdownArticle;
if (!getCountdown) {
this.isShowBanner = false;
return;
}
}

render() {
return (
<Host>
{this.isShowBanner ? (
<div class="sticky bottom-0 w-full h-full">
<div class={`w-full bg-blue-100 px-4 xl:px-0 bottom-0 py-4`}>
<div class="flex lg:max-w-7xl m-auto justify-center relative">
<div class="flex flex-col">{this.bannerTemplate()}</div>
<div class="absolute right-0 top-0.5">
<button onClick={this.triggerExpandBanner} class="bg-blue-200 p-2.5 rounded-md ">
<div class={`icon icon-blue-600 ${this.isExpandBanner && 'chevron-down'}`} innerHTML={chevronUp}></div>
</button>
</div>
</div>
</div>
</div>
) : null}
</Host>
);
}
}
Loading

0 comments on commit 0102075

Please sign in to comment.