@kompasid/lit-web-components 0.6.2 → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/demo/index.html +31 -0
  2. package/dist/src/components/kompasid-header-account/KompasHeaderAccount.d.ts +27 -0
  3. package/dist/src/components/kompasid-header-account/KompasHeaderAccount.js +233 -0
  4. package/dist/src/components/kompasid-header-account/KompasHeaderAccount.js.map +1 -0
  5. package/dist/src/components/kompasid-header-account/types.d.ts +8 -0
  6. package/dist/src/components/kompasid-header-account/types.js +2 -0
  7. package/dist/src/components/kompasid-header-account/types.js.map +1 -0
  8. package/dist/src/components/kompasid-header-account-help-center/KompasHeaderAccountHelpCenter.d.ts +13 -0
  9. package/dist/src/components/kompasid-header-account-help-center/KompasHeaderAccountHelpCenter.js +172 -0
  10. package/dist/src/components/kompasid-header-account-help-center/KompasHeaderAccountHelpCenter.js.map +1 -0
  11. package/dist/src/components/kompasid-header-account-menu/KompasHeaderAccountMenu.d.ts +37 -0
  12. package/dist/src/components/kompasid-header-account-menu/KompasHeaderAccountMenu.js +185 -0
  13. package/dist/src/components/kompasid-header-account-menu/KompasHeaderAccountMenu.js.map +1 -0
  14. package/dist/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.d.ts +12 -0
  15. package/dist/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.js +172 -0
  16. package/dist/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.js.map +1 -0
  17. package/dist/src/components/kompasid-paywall/KompasPaywall.js +5 -20
  18. package/dist/src/components/kompasid-paywall/KompasPaywall.js.map +1 -1
  19. package/dist/src/components/kompasid-paywall/types.d.ts +4 -0
  20. package/dist/src/components/kompasid-paywall/types.js.map +1 -1
  21. package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js +56 -30
  22. package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js.map +1 -1
  23. package/dist/src/index.d.ts +1 -0
  24. package/dist/src/index.js +1 -0
  25. package/dist/src/index.js.map +1 -1
  26. package/dist/src/utils/text.d.ts +2 -0
  27. package/dist/src/utils/text.js +9 -0
  28. package/dist/src/utils/text.js.map +1 -0
  29. package/dist/tailwind/tailwind.js +186 -4
  30. package/dist/tailwind/tailwind.js.map +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +1 -1
  33. package/src/components/kompasid-header-account/KompasHeaderAccount.ts +197 -0
  34. package/src/components/kompasid-header-account/types.ts +8 -0
  35. package/src/components/kompasid-header-account-help-center/KompasHeaderAccountHelpCenter.ts +177 -0
  36. package/src/components/kompasid-header-account-menu/KompasHeaderAccountMenu.ts +172 -0
  37. package/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.ts +161 -0
  38. package/src/components/kompasid-paywall/KompasPaywall.ts +5 -20
  39. package/src/components/kompasid-paywall/types.ts +4 -0
  40. package/src/components/kompasid-paywall-body/KompasPaywallBody.ts +64 -38
  41. package/src/index.ts +1 -0
  42. package/src/utils/text.ts +9 -0
  43. package/tailwind/tailwind.css +177 -4
  44. package/tailwind/tailwind.ts +186 -4
@@ -0,0 +1,172 @@
1
+ import { LitElement, html, css } from 'lit'
2
+ import { customElement, state, property } from 'lit/decorators.js'
3
+ import { unsafeSVG } from 'lit/directives/unsafe-svg.js'
4
+ import { getFontAwesomeIcon } from '../../utils/fontawesome-setup.js'
5
+ import { TWStyles } from '../../../tailwind/tailwind.js'
6
+
7
+ @customElement('kompasid-header-account-menu')
8
+ export class KompasHeaderAccountMenu extends LitElement {
9
+ static styles = [
10
+ css`
11
+ :host {
12
+ font-family: 'PT Sans', sans-serif;
13
+ }
14
+ .header-account-menu--item {
15
+ display: flex;
16
+ flex-direction: row;
17
+ align-items: center;
18
+ padding: 0.75rem;
19
+ transition: background-color 0.3s ease-in-out;
20
+ border-radius: 0.25rem;
21
+ }
22
+ .header-account-menu--item:hover {
23
+ background-color: #e5e7eb; /* Assuming grey-200 */
24
+ }
25
+ .header-account-menu--title {
26
+ flex-grow: 1;
27
+ font-size: 1rem;
28
+ font-weight: bold;
29
+ margin-left: 1rem;
30
+ }
31
+ .header-account-menu--notification-info {
32
+ font-size: 0.875rem;
33
+ border-radius: 1.5rem;
34
+ display: flex;
35
+ align-items: center;
36
+ justify-content: center;
37
+ background-color: rgb(255, 122, 0);
38
+ color: #f7fafc;
39
+ height: 1.75rem;
40
+ width: 1.75rem;
41
+ }
42
+ .icon {
43
+ width: 20px;
44
+ height: 20px;
45
+ margin-top: auto;
46
+ margin-bottom: auto;
47
+ color: rgb(0 85 154);
48
+ }
49
+ `,
50
+ TWStyles,
51
+ ]
52
+
53
+ kompasKring?: HTMLInputElement
54
+
55
+ @state() clipboardClicked: boolean = false
56
+
57
+ /**
58
+ * Cart Url
59
+ */
60
+ @property({ type: String }) cartUrl = 'https://gerai.kompas.id/cart'
61
+
62
+ /**
63
+ * Logout Url
64
+ */
65
+ @property({ type: String }) logoutUrl = 'https://account.kompas.id/logout'
66
+
67
+ /**
68
+ * Manage Account Url
69
+ */
70
+ @property({ type: String }) manageAccountUrl =
71
+ 'https://account.kompas.id/manage-account/my-account'
72
+
73
+ /**
74
+ * Notification Url
75
+ */
76
+ @property({ type: String }) notificationUrl =
77
+ 'https://account.kompas.id/manage-account/notification'
78
+
79
+ /**
80
+ * Orders Url
81
+ */
82
+ @property({ type: String }) ordersUrl =
83
+ 'https://gerai.kompas.id/my-account/orders'
84
+
85
+ /**
86
+ * Read Later Url
87
+ */
88
+ @property({ type: String }) readLaterUrl = 'https://www.kompas.id/baca-nanti'
89
+
90
+ /**
91
+ * Total Notification Count
92
+ */
93
+ @property({ type: Number }) notificationTotal: number = 0
94
+
95
+ // Render Total Bubble
96
+ private renderTotalBubble = (total: number) => {
97
+ if (!total) {
98
+ return html``
99
+ }
100
+
101
+ const isOneDigitNotification = total > 0 && total <= 9
102
+ const additionalStyling = isOneDigitNotification ? '' : 'pl-0.5'
103
+
104
+ return html`
105
+ <div
106
+ class=${`header-account-menu--notification-info ${additionalStyling}`}
107
+ >
108
+ <!-- Limit Display to use "9+"" if total notification exceed 9 -->
109
+ ${isOneDigitNotification
110
+ ? total
111
+ : html`<span>9<span class="pl-px">+</span></span>`}
112
+ </div>
113
+ `
114
+ }
115
+
116
+ override async connectedCallback() {
117
+ super.connectedCallback()
118
+ }
119
+
120
+ render() {
121
+ return html`
122
+ <div class="border-b border-grey-300 text-grey-600">
123
+ <li
124
+ class="font-bold flex flex-shrink-0 flex-col text-left text-sm mb-4"
125
+ >
126
+ <!-- Cart -->
127
+ <!--<a href={this.cartUrl} class="header-account-menu--item">
128
+ <div class="icon icon-md icon-blue-600">{unsafeSVG(getFontAwesomeIcon('fas', 'cart-shopping'))}</div>
129
+ <p class="header-account-menu--title">Keranjang</p>
130
+ </a> -->
131
+ <!-- Manage Account -->
132
+ <a href=${this.manageAccountUrl} class="header-account-menu--item">
133
+ <div class="icon icon-md icon-blue-600">
134
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'user-gear'))}
135
+ </div>
136
+ <p class="header-account-menu--title">Kelola Akun</p>
137
+ </a>
138
+ <!-- Transaction -->
139
+ <!-- <a href={this.ordersUrl} class="header-account-menu--item">
140
+ <div class="icon icon-md icon-blue-600">{unsafeSVG(getFontAwesomeIcon('fas', 'arrow-right-arrow-left'))}</div>
141
+ <p class="header-account-menu--title">Transaksi</p>
142
+ </a> -->
143
+ <!-- Notifications -->
144
+ <a href=${this.notificationUrl} class="header-account-menu--item">
145
+ <div class="icon icon-md icon-blue-600">
146
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'bell'))}
147
+ </div>
148
+ <p class="header-account-menu--title">Notifikasi</p>
149
+ <p class="flex-none">
150
+ <!-- Conditional rendering based on notification count -->
151
+ ${this.renderTotalBubble(this.notificationTotal)}
152
+ </p>
153
+ </a>
154
+ <!-- Read Later -->
155
+ <a href=${this.readLaterUrl} class="header-account-menu--item">
156
+ <div class="icon icon-md icon-blue-600">
157
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'bookmark'))}
158
+ </div>
159
+ <p class="header-account-menu--title">Baca Nanti</p>
160
+ </a>
161
+ <!-- Logout -->
162
+ <a href=${this.logoutUrl} class="header-account-menu--item">
163
+ <div class="icon icon-md icon-blue-600">
164
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'right-from-bracket'))}
165
+ </div>
166
+ <p class="header-account-menu--title">Keluar</p>
167
+ </a>
168
+ </li>
169
+ </div>
170
+ `
171
+ }
172
+ }
@@ -0,0 +1,161 @@
1
+ import { LitElement, html, css } from 'lit'
2
+ import { customElement, property } from 'lit/decorators.js'
3
+ import { TWStyles } from '../../../tailwind/tailwind.js'
4
+ import { truncate } from '../../utils/text.js'
5
+
6
+ @customElement('kompasid-header-account-profile')
7
+ export class KompasHeaderAccountProfile extends LitElement {
8
+ static styles = [
9
+ css`
10
+ .header-account--membership-icon {
11
+ position: absolute;
12
+ bottom: -2px;
13
+ right: -2px;
14
+ }
15
+ `,
16
+ TWStyles,
17
+ ]
18
+
19
+ @property({ type: String }) userInitialName = ''
20
+ @property({ type: Object }) userData = {}
21
+ @property({ type: String }) subscriptionUrl = ''
22
+ @property({ type: Number }) totalGracePeriod = 0
23
+
24
+ private renderSkeletonLoading() {
25
+ return html`
26
+ <div>
27
+ <div class="flex flex-row mb-5 items-center gap-4 leading-none">
28
+ <div
29
+ class="bg-grey-300 py-5 rounded-full h-16 w-16 animate-pulse"
30
+ ></div>
31
+ <div class="flex flex-col text-left w-40 gap-y-2">
32
+ <div class="h-3 rounded-sm w-full bg-grey-300 animate-pulse"></div>
33
+ <div class="h-3 rounded-sm w-full bg-grey-300 animate-pulse"></div>
34
+ <div class="h-3 rounded-sm w-full bg-grey-300 animate-pulse"></div>
35
+ </div>
36
+ </div>
37
+ <div>
38
+ <div class="h-6 rounded-sm w-full bg-grey-300 animate-pulse"></div>
39
+ </div>
40
+ </div>
41
+ `
42
+ }
43
+
44
+ private renderProfileContent() {
45
+ /**
46
+ * Expired Button Element
47
+ */
48
+ const subscribeButton = () => {
49
+ if ((this.userData as any)?.updateMembership !== null) {
50
+ return html``
51
+ }
52
+ const handleSubscribe = () => {
53
+ window.location.href = this.subscriptionUrl
54
+ }
55
+
56
+ return html`
57
+ <div class="w-full">
58
+ <button
59
+ onClick=${handleSubscribe()}
60
+ class="w-full rounded-lg px-4 py-3 mt-4 h-10 flex justify-center items-center bg-green-500 text-grey-100 font-bold text-base focus:outline-none"
61
+ >
62
+ ${(this.userData as any)?.updateMembership}
63
+ </button>
64
+ </div>
65
+ `
66
+ }
67
+ /**
68
+ * expired Info Element
69
+ */
70
+ const expiredInfo = () => {
71
+ const isNearExpired = (this.userData as any)?.isNearExpired
72
+ const expiredTextColor = isNearExpired
73
+ ? `text-orange-400`
74
+ : `text-grey-600`
75
+
76
+ return html`<p class="${expiredTextColor} font-bold">
77
+ ${(this.userData as any)?.expired}
78
+ </p>`
79
+ }
80
+
81
+ /**
82
+ * membership icon element, show if isMebership has truthy value
83
+ */
84
+ const membershipIcon = () => {
85
+ if (!(this.userData as any)?.isMembership) {
86
+ return html``
87
+ }
88
+
89
+ return html`
90
+ <div>
91
+ <img
92
+ class="header-account--membership-icon"
93
+ src="https://d3w4qaq4xm1ncv.cloudfront.net/global-header/crown-blue-10.svg"
94
+ alt="membership-crown-icon"
95
+ />
96
+ </div>
97
+ `
98
+ }
99
+
100
+ /**
101
+ * Active Info Element
102
+ */
103
+
104
+ const activeInfo = () => {
105
+ const isNearExpired = (this.userData as any)?.isNearExpired
106
+ const expiredTextColor = isNearExpired
107
+ ? `text-orange-400`
108
+ : `text-grey-600`
109
+
110
+ return html`<p class="capitalize text-sm ${expiredTextColor}">
111
+ ${(this.userData as any)?.activeInfo}
112
+ </p>`
113
+ }
114
+
115
+ return html`<div
116
+ class="active-info flex flex-col items-start leading-none text-left"
117
+ >
118
+ <div class="flex flex-row items-center gap-4">
119
+ <div
120
+ class="flex bg-brand-1 flex-shrink-0 p-5 rounded-full h-16 w-16 items-center justify-center relative"
121
+ >
122
+ <span class="capitalize text-2xl text-grey-100 font-bold"
123
+ >${this.userInitialName}</span
124
+ >
125
+ ${membershipIcon()}
126
+ </div>
127
+
128
+ <div class="flex flex-col text-left">
129
+ <p class="capitalize font-bold text-base text-blue-600">
130
+ ${truncate((this.userData as any)?.userName, 25)}
131
+ </p>
132
+ ${activeInfo()} ${expiredInfo()}
133
+ </div>
134
+ </div>
135
+
136
+ <div class="mt-4">
137
+ <!-- <kompas-grace-period
138
+ totalGracePeriod="{this.totalGracePeriod}"
139
+ isColoumn="{true}"
140
+ isShowButton="{true}"
141
+ /> -->
142
+ </div>
143
+
144
+ ${subscribeButton()}
145
+ </div>`
146
+ }
147
+
148
+ override async connectedCallback() {
149
+ super.connectedCallback()
150
+ }
151
+
152
+ render() {
153
+ return html`
154
+ <div class="flex flex-shrink-0 flex-col bg-blue-100 p-4">
155
+ ${!this.userData
156
+ ? this.renderSkeletonLoading()
157
+ : this.renderProfileContent()}
158
+ </div>
159
+ `
160
+ }
161
+ }
@@ -120,26 +120,7 @@ export class KompasPaywall extends LitElement {
120
120
  },
121
121
  packages: {
122
122
  title: 'Sekali bayar, tanpa perpanjang otomatis',
123
- memberships: [
124
- {
125
- title: 'Kompas Digital Premium 12 Bulan (Hemat 40%)',
126
- percentage: 40,
127
- price: 360000,
128
- discountPrice: 600000,
129
- periode: 'Tahun',
130
- isHighlight: true,
131
- url: 'https://checkoutv2.kompas.id/kdp?productId=9802032&referrer=',
132
- },
133
- {
134
- title: 'Kompas Digital Premium 1 Bulan',
135
- percentage: 0,
136
- discountPrice: 0,
137
- price: 50000,
138
- periode: 'Bulan',
139
- isHighlight: false,
140
- url: 'https://checkoutv2.kompas.id/kdp?productId=9802035&referrer=',
141
- },
142
- ],
123
+ memberships: [],
143
124
  },
144
125
  payment: {
145
126
  desktop: [
@@ -277,6 +258,10 @@ export class KompasPaywall extends LitElement {
277
258
  title: json[this.type].head,
278
259
  description: json[this.type].content,
279
260
  },
261
+ packages: {
262
+ ...this.mockResult.packages,
263
+ memberships: json[this.type].memberships,
264
+ },
280
265
  }
281
266
  } catch (error) {
282
267
  throw Error('failed to get paywall data')
@@ -3,9 +3,13 @@ export interface Product {
3
3
  percentage: number
4
4
  price: number
5
5
  discountPrice: number
6
+ savingPrice: number
6
7
  periode: string
7
8
  isHighlight: boolean
8
9
  url: string
10
+ package: string
11
+ subscriptionId: string
12
+ position: number
9
13
  }
10
14
  export interface Metered {
11
15
  maxQuota: number
@@ -480,18 +480,13 @@ export class KompasIdPaywallBody extends LitElement {
480
480
  }
481
481
 
482
482
  private generalPaywallDataLayer(event: string): Record<string, any> {
483
- const impressions = [
484
- {
485
- package: 'Cash-B2C-Halaman Berlangganan-Reguler_Digital-KDP 12',
486
- subscription_id: '9802032',
487
- price: '360000',
488
- },
489
- {
490
- package: 'Cash-B2C-Halaman Berlangganan-Reguler_Digital-KDP 1',
491
- subscription_id: '9802035',
492
- price: '50000',
493
- },
494
- ]
483
+ const packages = this.paywallData?.packages ?? ({} as Packages)
484
+
485
+ const impressions = packages.memberships.map(membership => ({
486
+ package: membership.package,
487
+ subscription_id: membership.subscriptionId,
488
+ price: membership.price.toString(),
489
+ }))
495
490
 
496
491
  return this.buildGtmParams(event, impressions)
497
492
  }
@@ -619,7 +614,7 @@ export class KompasIdPaywallBody extends LitElement {
619
614
  if (type === 'epaper') {
620
615
  buttonContent = html` <button
621
616
  @click=${this.redirectToPrevUrl}
622
- class="hidden lg:block w-8 h-8 pl-4 ${this.isDark
617
+ class="hidden md:block w-8 h-8 pl-4 ${this.isDark
623
618
  ? 'text-blue-300'
624
619
  : 'text-blue-600'}"
625
620
  >
@@ -640,7 +635,7 @@ export class KompasIdPaywallBody extends LitElement {
640
635
 
641
636
  const headerClass = `text-base flex justify-center self-center md:block md:text-xl ${
642
637
  this.isDark ? 'text-white' : 'text-grey-600'
643
- } text-center font-lora font-bold tracking-wide md:tracking-normal w-4/5 md:w-full ${
638
+ } text-center font-lora font-bold tracking-wide md:tracking-normal max-w-xs sm:max-w-lg md:w-full md:max-w-full ${
644
639
  type === 'audio' && 'sm:px-16 md:px-20'
645
640
  }`
646
641
 
@@ -816,11 +811,23 @@ export class KompasIdPaywallBody extends LitElement {
816
811
  / ${product.periode}
817
812
  </h6>
818
813
  </div>
819
- <div class="flex items-center">
820
- <p class="text-xs ${this.isDark ? 'text-dark-7' : 'text-grey-600'}">
821
- hanya <span class="text-orange-400">Rp 30.000</span> / bulan
822
- </p>
823
- </div>
814
+ ${product.savingPrice
815
+ ? html`
816
+ <div class="flex items-center">
817
+ <p
818
+ class="text-xs ${this.isDark
819
+ ? 'text-dark-7'
820
+ : 'text-grey-600'}"
821
+ >
822
+ hanya
823
+ <span class="text-orange-400"
824
+ >${formatRupiah(product.savingPrice)}</span
825
+ >
826
+ / bulan
827
+ </p>
828
+ </div>
829
+ `
830
+ : nothing}
824
831
  </div>
825
832
  <button
826
833
  class="h-8 ${this.isDark
@@ -829,10 +836,10 @@ export class KompasIdPaywallBody extends LitElement {
829
836
  @click=${() =>
830
837
  this.redirectToCheckout(
831
838
  product.url,
832
- 'Cash-B2C-Halaman Berlangganan-Reguler_Digital-KDP 12',
833
- '9802032',
834
- 360000,
835
- 1
839
+ product.package,
840
+ product.subscriptionId,
841
+ product.price,
842
+ product.position
836
843
  )}
837
844
  >
838
845
  <h6
@@ -859,26 +866,45 @@ export class KompasIdPaywallBody extends LitElement {
859
866
  ? 'bg-grey-600'
860
867
  : 'bg-white'} py-3 px-4 rounded-lg md:mx-0 w-full h-[68px] max-w-xs md:max-w-sm md:w-3/5 mt-3 md:mt-4"
861
868
  >
862
- <div class="flex items-center">
863
- <h5 class="text-base md:text-lg font-bold text-orange-400">
864
- ${formatRupiah(product.price)}
865
- </h5>
866
- <h6
867
- class="text-xs md:text-base ${this.isDark
868
- ? 'text-dark-7'
869
- : 'text-grey-600'} font-bold pl-1"
870
- >
871
- / ${product.periode}
872
- </h6>
869
+ <div class="flex flex-col">
870
+ <div class="flex items-center">
871
+ <h5 class="text-base md:text-lg font-bold text-orange-400">
872
+ ${formatRupiah(product.price)}
873
+ </h5>
874
+ <h6
875
+ class="text-xs md:text-base ${this.isDark
876
+ ? 'text-dark-7'
877
+ : 'text-grey-600'} font-bold pl-1"
878
+ >
879
+ / ${product.periode}
880
+ </h6>
881
+ </div>
882
+ ${product.savingPrice
883
+ ? html`
884
+ <div class="flex items-center">
885
+ <p
886
+ class="text-xs ${this.isDark
887
+ ? 'text-dark-7'
888
+ : 'text-grey-600'}"
889
+ >
890
+ hanya
891
+ <span class="text-orange-400"
892
+ >${formatRupiah(product.savingPrice)}</span
893
+ >
894
+ / bulan
895
+ </p>
896
+ </div>
897
+ `
898
+ : nothing}
873
899
  </div>
874
900
  <button
875
901
  @click=${() =>
876
902
  this.redirectToCheckout(
877
903
  product.url,
878
- 'Cash-B2C-Halaman Berlangganan-Reguler_Digital-KDP 1',
879
- '9802035',
880
- 50000,
881
- 2
904
+ product.package,
905
+ product.subscriptionId,
906
+ product.price,
907
+ product.position
882
908
  )}
883
909
  class="h-8 ${!this.isDark &&
884
910
  'bg-white'} border border-green-500 rounded"
package/src/index.ts CHANGED
@@ -4,6 +4,7 @@ export { KompasPaywallVideo } from './components/kompasid-paywall-video/KompasPa
4
4
  export { KompasMeteredPaywall } from './components/kompasid-metered-paywall/KompasMeteredPaywall.js'
5
5
  export { KompasFreewall } from './components/kompasid-freewall/KompasFreewall.js'
6
6
  export { KompasMeteredWallRegister } from './components/kompasid-metered-wall-register/KompasMeteredWallRegister.js'
7
+ export { KompasHeaderAccount } from './components/kompasid-header-account/KompasHeaderAccount.js'
7
8
 
8
9
  declare global {
9
10
  interface Window {
@@ -0,0 +1,9 @@
1
+ const truncate = (str: string, len: number = 155): string => {
2
+ if (str.length <= len) {
3
+ return str
4
+ }
5
+ const truncatedStr = str.substr(0, len - 1)
6
+ return `${truncatedStr.substr(0, truncatedStr.lastIndexOf(' '))}...`
7
+ }
8
+
9
+ export { truncate }