@kompasid/lit-web-components 0.5.6 → 0.5.8

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.
@@ -9,6 +9,7 @@ import {
9
9
  Product,
10
10
  Packages,
11
11
  PaymentImage,
12
+ PaywallType,
12
13
  } from '../kompasid-paywall/types.js'
13
14
  import { getFontAwesomeIcon } from '../../utils/fontawesome-setup.js'
14
15
  import { deviceType } from '../../utils/deviceType.js'
@@ -63,12 +64,12 @@ export class KompasIdPaywallBody extends LitElement {
63
64
  * prop tracker_metered_wall_balance = The balance of their metered wall
64
65
  * prop tracker_metered_wall_balance = The edition of epaper viewed by user
65
66
  * prop theme = The theme of the paywall component
67
+ * prop isOpen = The condition for the visibility of the component
66
68
  */
67
69
 
68
70
  @property({ type: String }) slug = ''
69
- @property({ type: Number }) udin = 0
70
71
  @property({ type: Boolean }) isLogin = false
71
- @property({ type: String }) type: 'epaper' | 'reguler' = 'reguler'
72
+ @property({ type: String }) type: PaywallType = 'reguler'
72
73
  @property({ type: Object }) paywallData: PaywallProduct | undefined =
73
74
  undefined
74
75
  @property({ type: String }) userGuid = ''
@@ -92,6 +93,7 @@ export class KompasIdPaywallBody extends LitElement {
92
93
  @property({ type: Number }) tracker_metered_wall_balance = 0
93
94
  @property({ type: String }) tracker_epaper_edition = ''
94
95
  @property({ type: String }) theme = ''
96
+ @property({ type: Boolean }) isOpen = true
95
97
 
96
98
  /**
97
99
  * State
@@ -109,6 +111,7 @@ export class KompasIdPaywallBody extends LitElement {
109
111
  @state() private errorFlag = 0
110
112
 
111
113
  buttonElement!: HTMLButtonElement
114
+ targetElement!: HTMLElement
112
115
 
113
116
  /**
114
117
  * Getter
@@ -141,7 +144,18 @@ export class KompasIdPaywallBody extends LitElement {
141
144
  ): void {
142
145
  this.sendDataLayeronButtonBuyPackage(name, id, price, position)
143
146
  const originHost: string = encodeURIComponent(window.location.href)
144
- const source: string = this.type === 'epaper' ? 'epaper' : 'article'
147
+ let source: string
148
+
149
+ switch (this.type) {
150
+ case 'epaper':
151
+ source = 'epaper'
152
+ break
153
+ case 'audio':
154
+ source = 'news_audio'
155
+ break
156
+ default:
157
+ source = 'article'
158
+ }
145
159
  const directUrlCheckout: string = `${url}${originHost}&source=${source}`
146
160
  window.open(directUrlCheckout)
147
161
  }
@@ -162,6 +176,21 @@ export class KompasIdPaywallBody extends LitElement {
162
176
  )
163
177
  }
164
178
 
179
+ private close() {
180
+ this.isOpen = false
181
+ }
182
+
183
+ private handleClickOutside() {
184
+ if (this.isOpen) {
185
+ if (
186
+ this.targetElement instanceof HTMLElement &&
187
+ this.targetElement.classList.contains('wrapper-body')
188
+ ) {
189
+ this.close()
190
+ }
191
+ }
192
+ }
193
+
165
194
  private parsePrice(price: string): number {
166
195
  const lowerCasePrice = price.toLowerCase()
167
196
 
@@ -368,26 +397,49 @@ export class KompasIdPaywallBody extends LitElement {
368
397
  }
369
398
  }
370
399
 
400
+ constructor() {
401
+ super()
402
+ this.handleClickOutside = this.handleClickOutside.bind(this)
403
+ }
404
+
405
+ protected createRenderRoot() {
406
+ const root = super.createRenderRoot()
407
+ root.addEventListener(
408
+ 'click',
409
+ (e: Event) => (this.targetElement = e.target as HTMLElement)
410
+ )
411
+ return root
412
+ }
413
+
371
414
  override async connectedCallback() {
372
415
  super.connectedCallback()
373
416
  await this.updateComplete
374
417
  if (this.swgEnable) {
375
418
  this.jsonScript()
376
- this.buttonElement = this.shadowRoot?.getElementById(
377
- 'subscribe-with-google'
378
- ) as HTMLButtonElement
379
- if (this.buttonElement) {
380
- const head = document.querySelector('head')
381
- const script = document.createElement('script')
382
- script.src = 'https://news.google.com/swg/js/v1/swg.js'
383
- script.defer = true
384
- script.onload = this.subscribeWithGoogleButton()
385
- if (head) {
386
- head.appendChild(script)
419
+ const appendSWGButton = () => {
420
+ this.buttonElement = this.shadowRoot?.getElementById(
421
+ 'subscribe-with-google'
422
+ ) as HTMLButtonElement
423
+ if (this.buttonElement) {
424
+ const head = document.querySelector('head')
425
+ const script = document.createElement('script')
426
+ script.src = 'https://news.google.com/swg/js/v1/swg.js'
427
+ script.defer = true
428
+ script.onload = this.subscribeWithGoogleButton()
429
+ if (head) {
430
+ head.appendChild(script)
431
+ }
387
432
  }
388
433
  }
434
+ setTimeout(appendSWGButton, 500)
389
435
  }
390
436
  addGoogleFonts(['pt-sans', 'lora'])
437
+ document.addEventListener('click', this.handleClickOutside)
438
+ }
439
+
440
+ override async disconnectedCallback() {
441
+ super.disconnectedCallback()
442
+ document.removeEventListener('click', this.handleClickOutside)
391
443
  }
392
444
 
393
445
  private otherPackagesClicked() {
@@ -571,34 +623,43 @@ export class KompasIdPaywallBody extends LitElement {
571
623
  * Component
572
624
  */
573
625
 
574
- private headerSection(type: 'epaper' | 'reguler') {
575
- const headerSectionText =
576
- type === 'epaper'
577
- ? 'Akses ePaper Ini dengan Berlangganan'
578
- : 'Lanjut Baca Artikel Ini dengan Berlangganan'
626
+ private headerSection(type: PaywallType, title: string) {
627
+ let buttonContent
628
+
629
+ if (type === 'epaper') {
630
+ buttonContent = html` <button
631
+ @click=${this.redirectToPrevUrl}
632
+ class="hidden lg:block w-8 h-8 pl-4 ${this.isDark
633
+ ? 'text-blue-300'
634
+ : 'text-blue-600'}"
635
+ >
636
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
637
+ </button>`
638
+ } else if (type === 'audio') {
639
+ buttonContent = html` <button
640
+ @click=${this.close}
641
+ class="hidden md:block w-8 h-8 pl-4 ${this.isDark
642
+ ? 'text-blue-300'
643
+ : 'text-blue-600'}"
644
+ >
645
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'xmark', 24, 24))}
646
+ </button>`
647
+ } else {
648
+ buttonContent = nothing
649
+ }
650
+
651
+ const headerClass = `text-base flex justify-center self-center md:block md:text-xl ${
652
+ this.isDark ? 'text-white' : 'text-grey-600'
653
+ } text-center font-lora font-bold tracking-wide md:tracking-normal w-4/5 md:w-full ${
654
+ type === 'audio' && 'sm:px-16 md:px-20'
655
+ }`
656
+
579
657
  return html`
580
- <div class="flex w-full items-center justify-center">
581
- ${type === 'epaper'
582
- ? html`<button
583
- @click=${this.redirectToPrevUrl}
584
- class="hidden lg:block w-8 h-8 ${this.isDark
585
- ? 'text-blue-300'
586
- : 'text-blue-600'} pl-4"
587
- >
588
- ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
589
- </button>`
590
- : nothing}
591
- <h4
592
- class="text-base flex justify-center self-center md:block md:text-xl ${this
593
- .isDark
594
- ? 'text-white'
595
- : 'text-grey-600'}
596
- text-center font-lora font-bold tracking-wide md:tracking-normal w-4/5 md:w-full"
597
- >
598
- ${headerSectionText}
599
- </h4>
600
- ${type === 'epaper'
601
- ? html`<div class="w-10 hidden lg:flex"></div>`
658
+ <div class="flex w-full items-start justify-center">
659
+ ${buttonContent}
660
+ <h4 class=${headerClass}>${title}</h4>
661
+ ${type === 'epaper' || type === 'audio'
662
+ ? html`<div class="w-10 hidden md:flex"></div>`
602
663
  : nothing}
603
664
  </div>
604
665
  `
@@ -699,7 +760,7 @@ export class KompasIdPaywallBody extends LitElement {
699
760
  `
700
761
  }
701
762
 
702
- private registrationSection(type: 'epaper' | 'reguler') {
763
+ private registrationSection(type: PaywallType) {
703
764
  return type === 'epaper'
704
765
  ? this.epaperRegistrationSection()
705
766
  : this.regulerRegistrationSection()
@@ -835,7 +896,7 @@ export class KompasIdPaywallBody extends LitElement {
835
896
  <h6
836
897
  class="text-xs md:text-sm ${this.isDark
837
898
  ? 'text-green-300'
838
- : 'text-green-500'} font-bold px-4 "
899
+ : 'text-green-500'} font-bold px-4"
839
900
  >
840
901
  Langganan
841
902
  </h6>
@@ -857,17 +918,31 @@ export class KompasIdPaywallBody extends LitElement {
857
918
  `
858
919
  }
859
920
 
860
- private topNavigator() {
921
+ private topNavigator(type: PaywallType) {
922
+ let icon: string
923
+ let buttonText: string
924
+ let clickAction: Function
925
+
926
+ if (type === 'audio') {
927
+ icon = getFontAwesomeIcon('fas', 'xmark')
928
+ buttonText = 'Tutup'
929
+ clickAction = this.close.bind(this)
930
+ } else {
931
+ icon = getFontAwesomeIcon('fas', 'arrow-left')
932
+ buttonText = 'Kembali'
933
+ clickAction = this.redirectToPrevUrl.bind(this)
934
+ }
935
+
861
936
  return html`
862
- <div class="flex lg:hidden items-center w-full pb-4 ">
937
+ <div class="flex md:hidden w-full pb-4">
863
938
  <button
864
- @click=${this.redirectToPrevUrl}
939
+ @click=${clickAction}
865
940
  class="text-xs md:text-lg text-white flex flex-row"
866
941
  >
867
942
  <div class="icon-lg icon-white w-4 h-4 mr-3.5 md:mr-5 pt-0.5">
868
- ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
943
+ ${unsafeSVG(icon)}
869
944
  </div>
870
- Kembali
945
+ ${buttonText}
871
946
  </button>
872
947
  </div>
873
948
  `
@@ -945,7 +1020,7 @@ export class KompasIdPaywallBody extends LitElement {
945
1020
  <p
946
1021
  class="${this.isDark
947
1022
  ? 'text-dark-7'
948
- : 'text-grey-500'} text-[11px] md:text-xs whitespace-nowrap w-full "
1023
+ : 'text-grey-500'} text-[11px] md:text-xs whitespace-nowrap w-full"
949
1024
  >
950
1025
  Subscribe with
951
1026
  </p>
@@ -971,19 +1046,29 @@ export class KompasIdPaywallBody extends LitElement {
971
1046
  <div
972
1047
  class="${this.type === 'epaper'
973
1048
  ? 'bg-transparent wrapper-body mx-2'
1049
+ : 'wrapper-body'}
1050
+ ${this.type === 'audio'
1051
+ ? `${
1052
+ this.isOpen ? 'visible' : 'invisible'
1053
+ } fixed w-full h-full inset-0 flex justify-center items-center z-50 bg-black bg-opacity-75`
974
1054
  : 'wrapper-body'}"
975
1055
  >
976
1056
  <div
977
- class="flex flex-col justify-center items-center w-full max-w-screen-sm my-5 relative"
1057
+ class="flex flex-col justify-center items-center w-full max-w-screen-sm my-5 px-2 relative"
978
1058
  >
979
- ${this.type === 'epaper' ? this.topNavigator() : nothing}
1059
+ ${this.type === 'epaper' || this.type === 'audio'
1060
+ ? this.topNavigator(this.type)
1061
+ : nothing}
980
1062
  <div
981
1063
  class="flex w-full flex-col items-center justify-center ${this
982
1064
  .isDark
983
1065
  ? 'bg-dark-3'
984
- : 'bg-blue-100'} rounded-xl pt-6 md:pt-8 relative"
1066
+ : 'bg-blue-100'} rounded-xl pt-6 md:pt-8 relative"
985
1067
  >
986
- ${this.headerSection(this.type)}
1068
+ ${this.headerSection(
1069
+ this.type,
1070
+ this.paywallData?.informations?.title ?? ''
1071
+ )}
987
1072
  ${this.descriptionSection(
988
1073
  this.paywallData?.informations?.description ?? []
989
1074
  )}
@@ -29,6 +29,7 @@
29
29
  | `tracker_user_type` | `tracker_user_type` | | `string` | `''` |
30
30
  | `type` | `type` | | `"epaper" \| "reguler"` | `'reguler'` |
31
31
  | `userGuid` | `user-guid` | | `string` | `''` |
32
+ | `isOpen` | `is-open` | | `boolean` | `true` |
32
33
 
33
34
 
34
35
  ## Dependencies
@@ -534,6 +534,14 @@ video {
534
534
  --tw-backdrop-sepia: ;
535
535
  }
536
536
 
537
+ .visible {
538
+ visibility: visible;
539
+ }
540
+
541
+ .invisible {
542
+ visibility: hidden;
543
+ }
544
+
537
545
  .collapse {
538
546
  visibility: collapse;
539
547
  }
@@ -542,6 +550,10 @@ video {
542
550
  position: static;
543
551
  }
544
552
 
553
+ .fixed {
554
+ position: fixed;
555
+ }
556
+
545
557
  .absolute {
546
558
  position: absolute;
547
559
  }
@@ -554,6 +566,10 @@ video {
554
566
  position: sticky;
555
567
  }
556
568
 
569
+ .inset-0 {
570
+ inset: 0px;
571
+ }
572
+
557
573
  .-bottom-6 {
558
574
  bottom: -1.5rem;
559
575
  }
@@ -594,6 +610,10 @@ video {
594
610
  z-index: 20;
595
611
  }
596
612
 
613
+ .z-50 {
614
+ z-index: 50;
615
+ }
616
+
597
617
  .col-span-2 {
598
618
  grid-column: span 2 / span 2;
599
619
  }
@@ -602,6 +622,10 @@ video {
602
622
  grid-column: span 4 / span 4;
603
623
  }
604
624
 
625
+ .m-auto {
626
+ margin: auto;
627
+ }
628
+
605
629
  .mx-2 {
606
630
  margin-left: 0.5rem;
607
631
  margin-right: 0.5rem;
@@ -656,6 +680,10 @@ video {
656
680
  margin-bottom: 0.5rem;
657
681
  }
658
682
 
683
+ .mb-3 {
684
+ margin-bottom: 0.75rem;
685
+ }
686
+
659
687
  .mb-4 {
660
688
  margin-bottom: 1rem;
661
689
  }
@@ -680,10 +708,18 @@ video {
680
708
  margin-left: 0.75rem;
681
709
  }
682
710
 
711
+ .ml-4 {
712
+ margin-left: 1rem;
713
+ }
714
+
683
715
  .ml-8 {
684
716
  margin-left: 2rem;
685
717
  }
686
718
 
719
+ .ml-auto {
720
+ margin-left: auto;
721
+ }
722
+
687
723
  .mr-10 {
688
724
  margin-right: 2.5rem;
689
725
  }
@@ -760,6 +796,10 @@ video {
760
796
  height: 1rem;
761
797
  }
762
798
 
799
+ .h-40 {
800
+ height: 10rem;
801
+ }
802
+
763
803
  .h-5 {
764
804
  height: 1.25rem;
765
805
  }
@@ -942,6 +982,10 @@ video {
942
982
  flex-direction: column;
943
983
  }
944
984
 
985
+ .flex-col-reverse {
986
+ flex-direction: column-reverse;
987
+ }
988
+
945
989
  .flex-wrap {
946
990
  flex-wrap: wrap;
947
991
  }
@@ -1263,6 +1307,11 @@ video {
1263
1307
  padding-right: 1rem;
1264
1308
  }
1265
1309
 
1310
+ .px-5 {
1311
+ padding-left: 1.25rem;
1312
+ padding-right: 1.25rem;
1313
+ }
1314
+
1266
1315
  .px-8 {
1267
1316
  padding-left: 2rem;
1268
1317
  padding-right: 2rem;
@@ -1357,6 +1406,10 @@ video {
1357
1406
  padding-left: 1rem;
1358
1407
  }
1359
1408
 
1409
+ .pr-14 {
1410
+ padding-right: 3.5rem;
1411
+ }
1412
+
1360
1413
  .pr-2 {
1361
1414
  padding-right: 0.5rem;
1362
1415
  }
@@ -1573,6 +1626,11 @@ video {
1573
1626
  .sm\:grid-cols-4 {
1574
1627
  grid-template-columns: repeat(4, minmax(0, 1fr));
1575
1628
  }
1629
+
1630
+ .sm\:px-16 {
1631
+ padding-left: 4rem;
1632
+ padding-right: 4rem;
1633
+ }
1576
1634
  }
1577
1635
 
1578
1636
  @media (min-width: 768px) {
@@ -1606,6 +1664,10 @@ video {
1606
1664
  margin-right: 1.25rem;
1607
1665
  }
1608
1666
 
1667
+ .md\:mt-0 {
1668
+ margin-top: 0px;
1669
+ }
1670
+
1609
1671
  .md\:mt-3 {
1610
1672
  margin-top: 0.75rem;
1611
1673
  }
@@ -1622,6 +1684,10 @@ video {
1622
1684
  display: block;
1623
1685
  }
1624
1686
 
1687
+ .md\:flex {
1688
+ display: flex;
1689
+ }
1690
+
1625
1691
  .md\:hidden {
1626
1692
  display: none;
1627
1693
  }
@@ -1638,6 +1704,10 @@ video {
1638
1704
  height: 68px;
1639
1705
  }
1640
1706
 
1707
+ .md\:h-full {
1708
+ height: 100%;
1709
+ }
1710
+
1641
1711
  .md\:h-max {
1642
1712
  height: -moz-max-content;
1643
1713
  height: max-content;
@@ -1655,6 +1725,10 @@ video {
1655
1725
  width: 10rem;
1656
1726
  }
1657
1727
 
1728
+ .md\:w-5\/12 {
1729
+ width: 41.666667%;
1730
+ }
1731
+
1658
1732
  .md\:w-52 {
1659
1733
  width: 13rem;
1660
1734
  }
@@ -1715,6 +1789,14 @@ video {
1715
1789
  justify-content: center;
1716
1790
  }
1717
1791
 
1792
+ .md\:gap-2 {
1793
+ gap: 0.5rem;
1794
+ }
1795
+
1796
+ .md\:gap-8 {
1797
+ gap: 2rem;
1798
+ }
1799
+
1718
1800
  .md\:space-x-0 > :not([hidden]) ~ :not([hidden]) {
1719
1801
  --tw-space-x-reverse: 0;
1720
1802
  margin-right: calc(0px * var(--tw-space-x-reverse));
@@ -1745,10 +1827,18 @@ video {
1745
1827
  margin-bottom: calc(1rem * var(--tw-space-y-reverse));
1746
1828
  }
1747
1829
 
1830
+ .md\:self-start {
1831
+ align-self: flex-start;
1832
+ }
1833
+
1748
1834
  .md\:self-end {
1749
1835
  align-self: flex-end;
1750
1836
  }
1751
1837
 
1838
+ .md\:self-center {
1839
+ align-self: center;
1840
+ }
1841
+
1752
1842
  .md\:rounded {
1753
1843
  border-radius: 0.25rem;
1754
1844
  }
@@ -1826,6 +1916,11 @@ video {
1826
1916
  text-align: left;
1827
1917
  }
1828
1918
 
1919
+ .md\:text-2xl {
1920
+ font-size: 1.5rem;
1921
+ line-height: 2rem;
1922
+ }
1923
+
1829
1924
  .md\:text-base {
1830
1925
  font-size: 1rem;
1831
1926
  line-height: 1.5rem;
@@ -1898,14 +1993,6 @@ video {
1898
1993
  display: block;
1899
1994
  }
1900
1995
 
1901
- .lg\:flex {
1902
- display: flex;
1903
- }
1904
-
1905
- .lg\:hidden {
1906
- display: none;
1907
- }
1908
-
1909
1996
  .lg\:min-h-\[220px\] {
1910
1997
  min-height: 220px;
1911
1998
  }
@@ -1914,6 +2001,10 @@ video {
1914
2001
  width: 410px;
1915
2002
  }
1916
2003
 
2004
+ .lg\:max-w-7xl {
2005
+ max-width: 80rem;
2006
+ }
2007
+
1917
2008
  .lg\:grid-cols-12 {
1918
2009
  grid-template-columns: repeat(12, minmax(0, 1fr));
1919
2010
  }
@@ -1978,3 +2069,10 @@ video {
1978
2069
  padding-bottom: 1.5rem;
1979
2070
  }
1980
2071
  }
2072
+
2073
+ @media (min-width: 1280px) {
2074
+ .xl\:px-0 {
2075
+ padding-left: 0px;
2076
+ padding-right: 0px;
2077
+ }
2078
+ }