@kompasid/lit-web-components 0.8.4 → 0.8.6

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.
@@ -3,7 +3,11 @@ import { customElement, state, property } from 'lit/decorators.js'
3
3
  import { unsafeSVG } from 'lit/directives/unsafe-svg.js'
4
4
  import { getFontAwesomeIcon } from '../../utils/fontawesome-setup.js'
5
5
  import { TWStyles } from '../../../tailwind/tailwind.js'
6
- import { meteredRegisterContent } from './types.js'
6
+ import {
7
+ lastArticleData,
8
+ meteredRegisterResponse,
9
+ meteredRegisterContent,
10
+ } from './types.js'
7
11
 
8
12
  @customElement('kompasid-metered-wall-register')
9
13
  export class KompasMeteredWallRegister extends LitElement {
@@ -20,22 +24,9 @@ export class KompasMeteredWallRegister extends LitElement {
20
24
  width: 100%;
21
25
  }
22
26
 
23
- .btn-regis {
24
- margin-left: 16px;
25
- width: 127px;
26
- }
27
-
28
27
  .banner-content {
29
28
  gap: 55px;
30
29
  }
31
-
32
- .cont-banner-content {
33
- justify-content: space-evenly;
34
- }
35
-
36
- .expanded-btn {
37
- width: 127px;
38
- }
39
30
  `,
40
31
  TWStyles,
41
32
  ]
@@ -60,15 +51,25 @@ export class KompasMeteredWallRegister extends LitElement {
60
51
  * state textTemplate untuk menyimpan template yang di berikan.
61
52
  */
62
53
  @state() private textTemplate: meteredRegisterContent = {
63
- default: { title: '', lastArticle: { title: '' } },
64
54
  expand: {
65
- title: '',
66
55
  description: '',
67
- lastArticle: { title: '', description: '' },
56
+ imageUrl: '',
57
+ lastArticle: {
58
+ title: '',
59
+ description: '',
60
+ },
61
+ title: '',
62
+ ctaUrl: '',
63
+ ctaText: '',
64
+ },
65
+ collapse: {
66
+ lastArticle: {
67
+ title: '',
68
+ },
69
+ title: '',
68
70
  },
69
- ctaUrl: '',
70
- ctaText: '',
71
71
  }
72
+
72
73
  /**
73
74
  * Props
74
75
  */
@@ -94,7 +95,7 @@ export class KompasMeteredWallRegister extends LitElement {
94
95
  */
95
96
  @property({ type: Number }) countdownArticle = 0
96
97
  @property({ type: Boolean }) defaultExpandBanner = false
97
- @property({ type: Boolean }) isDesktop = false
98
+
98
99
  @property({ type: String }) tracker_page_title = ''
99
100
  @property({ type: String }) tracker_page_type = ''
100
101
  @property({ type: String }) tracker_content_type = ''
@@ -112,34 +113,37 @@ export class KompasMeteredWallRegister extends LitElement {
112
113
  @property({ type: String }) tracker_page_domain = ''
113
114
  @property({ type: String }) next_param =
114
115
  'https://www.kompas.id/baca/opini/2023/12/05/masa-depan-wolbachia-sebagai-alternatif-pengendalian-dbd?open_from=Section_Opini'
116
+ @property({ type: String }) source = 'default'
115
117
 
116
118
  /**
117
119
  * menentukan template yang akan di render
118
120
  */
119
121
  private setTemplate(
120
122
  prop: string,
121
- mode: keyof meteredRegisterContent = 'default'
123
+ mode: keyof meteredRegisterContent = 'collapse'
122
124
  ): string {
123
- interface LastArticle {
124
- [key: string]: string
125
- }
126
- interface DynamicMode {
127
- lastArticle?: LastArticle
128
- [key: string]: string | LastArticle | undefined
125
+ interface templateType {
126
+ lastArticle?: lastArticleData
127
+ [key: string]: string | lastArticleData | undefined
129
128
  }
130
- const dynamicMode = this.textTemplate[mode] as DynamicMode | string
129
+ const templateObj = this.textTemplate[mode] as unknown as
130
+ | templateType
131
+ | string
131
132
 
132
133
  let template: string = ''
133
134
 
134
- if (typeof dynamicMode === 'object' && dynamicMode !== null) {
135
- // Check if dynamicMode has a lastArticle object and if the prop exists within it
136
- if (dynamicMode.lastArticle && prop in dynamicMode.lastArticle) {
137
- const value = dynamicMode.lastArticle[prop]
138
- if (typeof value === 'string') {
139
- template = value
135
+ if (typeof templateObj === 'object' && templateObj !== null) {
136
+ // Check if templateObj has a lastArticle object and if the prop exists within it
137
+
138
+ if (this.countdownArticle === 1) {
139
+ if (templateObj.lastArticle && prop in templateObj.lastArticle) {
140
+ const value = (templateObj.lastArticle as any)[prop]
141
+ if (typeof value === 'string') {
142
+ template = value
143
+ }
140
144
  }
141
- } else if (prop in dynamicMode) {
142
- const value = dynamicMode[prop]
145
+ } else if (prop in templateObj) {
146
+ const value = templateObj[prop]
143
147
  if (typeof value === 'string') {
144
148
  template = value
145
149
  }
@@ -149,14 +153,6 @@ export class KompasMeteredWallRegister extends LitElement {
149
153
  return template
150
154
  }
151
155
 
152
- private checkIsDesktop() {
153
- if (window.innerWidth >= 960) {
154
- this.isDesktop = true
155
- } else {
156
- this.isDesktop = false
157
- }
158
- }
159
-
160
156
  /**
161
157
  * Render Statement
162
158
  */
@@ -169,24 +165,15 @@ export class KompasMeteredWallRegister extends LitElement {
169
165
 
170
166
  private defaultBannerContent() {
171
167
  return html`
172
- <div>
173
- <div
174
- class="${this.isDesktop
175
- ? 'cont-banner-content'
176
- : 'justify-between'} flex flex-row"
177
- >
178
- <div .hidden="${!this.isDesktop}" class="w-9 h-9"></div>
179
- <div class="banner-content flex flex-row">
168
+ <div class="flex flex-col space-y-4">
169
+ <div class="flex justify-between items-center h-full">
170
+ <div class="w-9 h-9 hidden lg:block"></div>
171
+ <div class="banner-content flex flex-row items-center">
180
172
  <div
181
- class="text-base md:text-lg font-lora mb-3 mt-1 pt-[5px] md:mb-0 md:mt-0 pr-14 md:px-0"
173
+ class="text-base md:text-lg font-lora"
182
174
  .innerHTML=${this.setTemplate('title')}
183
175
  ></div>
184
- <div .hidden="${!this.isDesktop}" class="md:self-center btn-regis">
185
- ${this.isDesktop
186
- ? html`<div class="ml-4"></div>
187
- ${this.registerButtonTemplate()}`
188
- : null}
189
- </div>
176
+ <div class="hidden md:block">${this.registerButtonTemplate()}</div>
190
177
  </div>
191
178
  <div>
192
179
  <button
@@ -203,9 +190,7 @@ export class KompasMeteredWallRegister extends LitElement {
203
190
  </button>
204
191
  </div>
205
192
  </div>
206
- <div class="md:self-center mt-4">
207
- ${!this.isDesktop ? html`${this.registerButtonTemplate()} ` : null}
208
- </div>
193
+ <div class="block md:hidden">${this.registerButtonTemplate()}</div>
209
194
  </div>
210
195
  `
211
196
  }
@@ -213,10 +198,10 @@ export class KompasMeteredWallRegister extends LitElement {
213
198
  private expandedBannerContent() {
214
199
  return html`
215
200
  <div
216
- class="flex flex-col-reverse justify-evenly md:flex-row gap-4 md:gap-8"
201
+ class="flex flex-col-reverse justify-between md:flex-row gap-4 md:gap-8"
217
202
  >
218
203
  <div
219
- class="flex flex-col justify-evenly md:text-left md:w-5/12 gap-4 md:gap-2"
204
+ class="flex flex-col justify-evenly md:text-left md:w-5/12 gap-4 ml-auto"
220
205
  >
221
206
  <p
222
207
  class="text-lg md:text-2xl font-lora"
@@ -226,23 +211,19 @@ export class KompasMeteredWallRegister extends LitElement {
226
211
  class="text-sm md:text-base"
227
212
  .innerHTML=${this.setTemplate('description', 'expand')}
228
213
  ></p>
229
- <div class="${this.isDesktop ? 'expanded-btn' : null} md:self-start">
230
- ${this.registerButtonTemplate()}
231
- </div>
214
+ <div class="md:self-start">${this.registerButtonTemplate()}</div>
232
215
  </div>
233
216
  <div
234
- class="flex justify-center md:max-w-[200px] md:max-h-[220px] md:my-auto"
217
+ class="flex justify-center md:max-w-[200px] md:max-h-[220px] md:my-auto mx-auto"
235
218
  >
236
219
  <img
237
220
  alt="metered-wall-register"
238
- src="https://cdn-www.kompas.id/paywall-asset/paywall_ilustrasi3-03_1.png"
221
+ src="${this.textTemplate.expand.imageUrl ?? ''}"
239
222
  />
240
223
  </div>
241
224
  <button
242
225
  @click="${this.triggerExpandBanner}"
243
- class="h-9 w-9 ${this.isDesktop
244
- ? null
245
- : 'ml-auto'} flex items-center justify-center text-blue-500 rounded bg-blue-200"
226
+ class="h-9 w-9 flex items-center justify-center text-blue-500 rounded bg-blue-200"
246
227
  >
247
228
  <div
248
229
  class="icon icon-blue-600 ${this.isExpandBanner
@@ -262,18 +243,18 @@ export class KompasMeteredWallRegister extends LitElement {
262
243
  private registerButtonTemplate() {
263
244
  return html`
264
245
  <div>
265
- ${!this.textTemplate.ctaUrl
246
+ ${!this.textTemplate.expand.ctaUrl
266
247
  ? html`<button
267
248
  @click=${this.redirectToRegister}
268
- class="bg-green-500 p-1.5 w-full rounded-md font-bold text-grey-100 text-sm md:text-base"
249
+ class="bg-green-500 p-1.5 w-full whitespace-nowrap rounded-md font-bold text-grey-100 text-sm md:text-base"
269
250
  >
270
251
  Daftar Akun
271
252
  </button>`
272
253
  : html`<button
273
254
  @click=${this.redirectToCTAUrl}
274
- class="bg-green-500 p-1.5 w-full rounded-md font-bold text-grey-100 px-5 text-sm md:text-base md:w-[165px]"
255
+ class="bg-green-500 p-1.5 w-full whitespace-nowrap rounded-md font-bold text-grey-100 px-5 text-sm md:text-base md:w-auto"
275
256
  >
276
- ${this.textTemplate.ctaText}
257
+ ${this.textTemplate.expand.ctaText}
277
258
  </button>`}
278
259
  </div>
279
260
  `
@@ -284,8 +265,8 @@ export class KompasMeteredWallRegister extends LitElement {
284
265
  */
285
266
  private redirectToCTAUrl = (): void => {
286
267
  const params = new URLSearchParams(window.location.href)
287
- const newUrl = new URL(this.textTemplate.ctaUrl)
288
- const referrer = new URLSearchParams(this.textTemplate.ctaUrl).get(
268
+ const newUrl = new URL(this.textTemplate.expand.ctaUrl)
269
+ const referrer = new URLSearchParams(this.textTemplate.expand.ctaUrl).get(
289
270
  'referrer'
290
271
  )
291
272
  this.pushToDataLayer('mrw_clicked')
@@ -351,19 +332,23 @@ export class KompasMeteredWallRegister extends LitElement {
351
332
  super.connectedCallback()
352
333
  await this.updateComplete
353
334
  this.loadData()
354
- this.checkIsDesktop()
355
335
  }
356
336
 
357
337
  private async loadData() {
338
+ const { source } = this // kompas_com || default
339
+
358
340
  const req = await fetch(
359
- `https://cdn-www.kompas.id/assets/register_wall.json`
341
+ `https://cdn-www.kompas.id/assets/register_wall_new.json`
360
342
  )
361
343
 
362
344
  if (req.status !== 200) {
363
345
  throw new Error(`${req.status} Ada galat saat memproses permintaan.`)
364
346
  }
365
347
 
366
- this.textTemplate = await req.json()
348
+ const res: meteredRegisterResponse = await req.json()
349
+ const validSource = source in res ? source : 'default'
350
+
351
+ this.textTemplate = res[validSource as keyof typeof res]
367
352
 
368
353
  const getCountdown = this.countdownArticle
369
354
 
@@ -383,8 +368,8 @@ export class KompasMeteredWallRegister extends LitElement {
383
368
  ? html`
384
369
  <div class="sticky bottom-0 w-full h-full z-20">
385
370
  <div class="w-full bg-blue-100 px-4 xl:px-0 bottom-0 py-4">
386
- <div class="lg:max-w-7xl m-auto relative">
387
- <div>${this.bannerTemplate()}</div>
371
+ <div class="lg:max-w-7xl m-auto px-0 lg:px-24 relative">
372
+ ${this.bannerTemplate()}
388
373
  </div>
389
374
  </div>
390
375
  </div>
@@ -1,18 +1,24 @@
1
+ export interface lastArticleData {
2
+ title: string
3
+ description?: string
4
+ }
5
+
1
6
  export interface meteredRegisterContent {
2
7
  expand: {
3
- lastArticle: {
4
- title: string
5
- description: string
6
- }
8
+ lastArticle: lastArticleData
7
9
  title: string
8
10
  description: string
11
+ ctaUrl: string
12
+ ctaText: string
13
+ imageUrl: string
9
14
  }
10
- default: {
11
- lastArticle: {
12
- title: string
13
- }
15
+ collapse: {
16
+ lastArticle: lastArticleData
14
17
  title: string
15
18
  }
16
- ctaUrl: string
17
- ctaText: string
19
+ }
20
+
21
+ export interface meteredRegisterResponse {
22
+ kompascom: meteredRegisterContent
23
+ default: meteredRegisterContent
18
24
  }
@@ -326,7 +326,7 @@ export class KompasIdPaywallBody extends LitElement {
326
326
  const payload = {
327
327
  email,
328
328
  purchase_token: purchaseToken,
329
- products: productId,
329
+ product_id: productId,
330
330
  package_name: packageName,
331
331
  membershipChannelId: swgMembershipChannelId,
332
332
  }