@kompasid/lit-web-components 0.3.1 → 0.4.1

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 (70) hide show
  1. package/assets/video.jpg +0 -0
  2. package/demo/index.html +38 -37
  3. package/dist/src/components/{kompas-footer → kompasid-footer}/KompasFooter.js +16 -4
  4. package/dist/src/components/kompasid-footer/KompasFooter.js.map +1 -0
  5. package/dist/src/components/kompasid-footer/types.js.map +1 -0
  6. package/dist/src/components/{kompas-metered-paywall → kompasid-metered-paywall}/KompasMeteredPaywall.js +3 -3
  7. package/dist/src/components/kompasid-metered-paywall/KompasMeteredPaywall.js.map +1 -0
  8. package/dist/src/components/{kompas-paywall → kompasid-paywall}/KompasPaywall.d.ts +3 -3
  9. package/dist/src/components/{kompas-paywall → kompasid-paywall}/KompasPaywall.js +17 -20
  10. package/dist/src/components/kompasid-paywall/KompasPaywall.js.map +1 -0
  11. package/dist/src/components/kompasid-paywall/types.js.map +1 -0
  12. package/dist/src/components/{kompas-paywall-banner-registration → kompasid-paywall-banner-registration}/KompasPaywallBannerRegistration.d.ts +1 -1
  13. package/dist/src/components/{kompas-paywall-banner-registration → kompasid-paywall-banner-registration}/KompasPaywallBannerRegistration.js +1 -1
  14. package/dist/src/components/kompasid-paywall-banner-registration/KompasPaywallBannerRegistration.js.map +1 -0
  15. package/dist/src/components/{kompas-paywall-body → kompasid-paywall-body}/KompasPaywallBody.d.ts +36 -9
  16. package/dist/src/components/{kompas-paywall-body → kompasid-paywall-body}/KompasPaywallBody.js +405 -288
  17. package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js.map +1 -0
  18. package/dist/src/components/{kompas-paywall-information-header → kompasid-paywall-information-header}/KompasPaywallInformationHeader.js +1 -1
  19. package/dist/src/components/kompasid-paywall-information-header/KompasPaywallInformationHeader.js.map +1 -0
  20. package/dist/src/components/{kompas-paywall-video → kompasid-paywall-video}/KompasPaywallVideo.d.ts +41 -5
  21. package/dist/src/components/kompasid-paywall-video/KompasPaywallVideo.js +302 -0
  22. package/dist/src/components/kompasid-paywall-video/KompasPaywallVideo.js.map +1 -0
  23. package/dist/src/index.d.ts +4 -4
  24. package/dist/src/index.js +4 -4
  25. package/dist/src/index.js.map +1 -1
  26. package/dist/src/utils/formatRupiah.d.ts +1 -0
  27. package/dist/src/utils/formatRupiah.js +7 -0
  28. package/dist/src/utils/formatRupiah.js.map +1 -0
  29. package/dist/tailwind/tailwind.js +123 -95
  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/{kompas-footer → kompasid-footer}/KompasFooter.ts +16 -4
  34. package/src/components/{kompas-metered-paywall → kompasid-metered-paywall}/KompasMeteredPaywall.ts +3 -3
  35. package/src/components/{kompas-metered-paywall → kompasid-metered-paywall}/readme.md +1 -1
  36. package/src/components/{kompas-paywall → kompasid-paywall}/KompasPaywall.ts +17 -20
  37. package/src/components/{kompas-paywall → kompasid-paywall}/readme.md +8 -8
  38. package/src/components/{kompas-paywall-banner-registration → kompasid-paywall-banner-registration}/KompasPaywallBannerRegistration.ts +2 -2
  39. package/src/components/{kompas-paywall-banner-registration → kompasid-paywall-banner-registration}/readme.md +4 -4
  40. package/src/components/{kompas-paywall-body → kompasid-paywall-body}/KompasPaywallBody.ts +345 -197
  41. package/src/components/{kompas-paywall-body → kompasid-paywall-body}/readme.md +4 -4
  42. package/src/components/{kompas-paywall-information-header → kompasid-paywall-information-header}/KompasPaywallInformationHeader.ts +1 -1
  43. package/src/components/{kompas-paywall-information-header → kompasid-paywall-information-header}/readme.md +4 -4
  44. package/src/components/kompasid-paywall-video/KompasPaywallVideo.ts +269 -0
  45. package/src/components/{kompas-paywall-video → kompasid-paywall-video}/readme.md +4 -3
  46. package/src/index.ts +4 -4
  47. package/src/utils/formatRupiah.ts +6 -0
  48. package/tailwind/tailwind.css +120 -92
  49. package/tailwind/tailwind.ts +123 -95
  50. package/tailwind.config.js +3 -1
  51. package/dist/src/components/kompas-footer/KompasFooter.js.map +0 -1
  52. package/dist/src/components/kompas-footer/types.js.map +0 -1
  53. package/dist/src/components/kompas-metered-paywall/KompasMeteredPaywall.js.map +0 -1
  54. package/dist/src/components/kompas-paywall/KompasPaywall.js.map +0 -1
  55. package/dist/src/components/kompas-paywall/types.js.map +0 -1
  56. package/dist/src/components/kompas-paywall-banner-registration/KompasPaywallBannerRegistration.js.map +0 -1
  57. package/dist/src/components/kompas-paywall-body/KompasPaywallBody.js.map +0 -1
  58. package/dist/src/components/kompas-paywall-information-header/KompasPaywallInformationHeader.js.map +0 -1
  59. package/dist/src/components/kompas-paywall-video/KompasPaywallVideo.js +0 -240
  60. package/dist/src/components/kompas-paywall-video/KompasPaywallVideo.js.map +0 -1
  61. package/src/components/kompas-paywall-video/KompasPaywallVideo.ts +0 -195
  62. /package/dist/src/components/{kompas-footer → kompasid-footer}/KompasFooter.d.ts +0 -0
  63. /package/dist/src/components/{kompas-footer → kompasid-footer}/types.d.ts +0 -0
  64. /package/dist/src/components/{kompas-footer → kompasid-footer}/types.js +0 -0
  65. /package/dist/src/components/{kompas-metered-paywall → kompasid-metered-paywall}/KompasMeteredPaywall.d.ts +0 -0
  66. /package/dist/src/components/{kompas-paywall → kompasid-paywall}/types.d.ts +0 -0
  67. /package/dist/src/components/{kompas-paywall → kompasid-paywall}/types.js +0 -0
  68. /package/dist/src/components/{kompas-paywall-information-header → kompasid-paywall-information-header}/KompasPaywallInformationHeader.d.ts +0 -0
  69. /package/src/components/{kompas-footer → kompasid-footer}/types.ts +0 -0
  70. /package/src/components/{kompas-paywall → kompasid-paywall}/types.ts +0 -0
@@ -1,4 +1,4 @@
1
- # kompas-paywall-body
1
+ # kompasid-paywall-body
2
2
 
3
3
  ## Properties
4
4
 
@@ -35,13 +35,13 @@
35
35
 
36
36
  ### Used by
37
37
 
38
- - [kompas-paywall](../kompas-paywall)
38
+ - [kompasid-paywall](../kompasid-paywall)
39
39
 
40
40
  ### Graph
41
41
  ```mermaid
42
42
  graph TD;
43
- kompas-paywall --> kompas-paywall-body
44
- style kompas-paywall-body fill:#f9f,stroke:#333,stroke-width:4px
43
+ kompasid-paywall --> kompasid-paywall-body
44
+ style kompasid-paywall-body fill:#f9f,stroke:#333,stroke-width:4px
45
45
  ```
46
46
 
47
47
  ----------------------------------------------
@@ -3,7 +3,7 @@ import { html, css, LitElement } from 'lit'
3
3
  import { property, customElement } from 'lit/decorators.js'
4
4
  import { TWStyles } from '../../../tailwind/tailwind.js'
5
5
 
6
- @customElement('kompas-paywall-information-header')
6
+ @customElement('kompasid-paywall-information-header')
7
7
  export class KompasPaywallInformationHeader extends LitElement {
8
8
  static styles = [css``, TWStyles]
9
9
 
@@ -1,4 +1,4 @@
1
- # kompas-paywall-information-header
1
+ # kompasid-paywall-information-header
2
2
 
3
3
  ## Properties
4
4
 
@@ -11,13 +11,13 @@
11
11
 
12
12
  ### Used by
13
13
 
14
- - [kompas-paywall](../kompas-paywall)
14
+ - [kompasid-paywall](../kompasid-paywall)
15
15
 
16
16
  ### Graph
17
17
  ```mermaid
18
18
  graph TD;
19
- kompas-paywall --> kompas-paywall-information-header
20
- style kompas-paywall-information-header fill:#f9f,stroke:#333,stroke-width:4px
19
+ kompasid-paywall --> kompasid-paywall-information-header
20
+ style kompasid-paywall-information-header fill:#f9f,stroke:#333,stroke-width:4px
21
21
  ```
22
22
 
23
23
  ----------------------------------------------
@@ -0,0 +1,269 @@
1
+ /* eslint-disable class-methods-use-this */
2
+ import { html, css, LitElement, nothing } from 'lit'
3
+ import { property, customElement, state } from 'lit/decorators.js'
4
+ import { TWStyles } from '../../../tailwind/tailwind.js'
5
+ import { deviceType } from '../../utils/deviceType.js'
6
+ import { formatRupiah } from '../../utils/formatRupiah.js'
7
+
8
+ @customElement('kompasid-paywall-video')
9
+ export class KompasPaywallVideo extends LitElement {
10
+ static styles = [css``, TWStyles]
11
+
12
+ /**
13
+ * Props
14
+ */
15
+ /**
16
+ * prop isLogin untuk menghandle apakah user sudah login atau belum
17
+ * prop paywall_location = The location where user encounter the paywall
18
+ * prop paywall_subscription_package = The name of the subscription package viewed by user
19
+ * prop paywall_subscription_id = The ID of the subscription package viewed by user
20
+ * prop paywall_subscription_price = The price of the subscriprtion package viewed by user
21
+ * prop paywall_position = The position of the subscription package viewed by user
22
+ * prop page_type = Type of the page
23
+ * prop content_id = ID of article (slug)
24
+ * prop content_type = Whether it's free article or paid article
25
+ * prop content_title = The title of article
26
+ * prop tracker_content_categories = The category of the content
27
+ * prop user_type = Type of user based on their subscription
28
+ * prop subscription_status = Status of their subscription
29
+ * prop page_domain = Page Domain
30
+ * prop metered_wall_type = The type of Metered Wall
31
+ * prop metered_wall_balance = The balance of their metered wall
32
+ * prop type = The type of video paywall
33
+ */
34
+
35
+ @property({ type: Boolean }) isLogin = false
36
+ @property({ type: String }) paywall_location = ''
37
+ @property({ type: String }) paywall_subscription_package = ''
38
+ @property({ type: String }) paywall_subscription_id = ''
39
+ @property({ type: Number }) paywall_subscription_price = 0
40
+ @property({ type: Number }) paywall_position = 0
41
+ @property({ type: String }) tracker_page_type = ''
42
+ @property({ type: String }) tracker_content_id = ''
43
+ @property({ type: String }) tracker_content_title = ''
44
+ @property({ type: String }) tracker_content_categories = ''
45
+ @property({ type: String }) tracker_content_type = ''
46
+ @property({ type: String }) tracker_user_type = ''
47
+ @property({ type: String }) tracker_subscription_status = ''
48
+ @property({ type: String }) tracker_page_domain = ''
49
+ @property({ type: String }) tracker_metered_wall_type = ''
50
+ @property({ type: Number }) tracker_metered_wall_balance = 0
51
+ @property({ type: String }) type: 'article' | 'homepage' = 'article'
52
+
53
+ /**
54
+ * State
55
+ */
56
+
57
+ @state() private subscriptionUrl: string =
58
+ 'https://www.kompas.id/berlangganan'
59
+ @state() private checkoutHost: string = 'https://checkoutv2.kompas.id'
60
+
61
+ /**
62
+ * Component
63
+ */
64
+
65
+ private regulerRegistrationSection() {
66
+ return html`
67
+ <div
68
+ class="flex flex-col text-white text-sm md:text-base font-sans items-center justify-center"
69
+ >
70
+ <div>
71
+ <button
72
+ @click=${() => this.redirectToRegister('Daftar')}
73
+ class="text-blue-300 font-bold"
74
+ >
75
+ Daftar
76
+ </button>
77
+ <span> untuk akses konten gratis.</span>
78
+ </div>
79
+ <div>
80
+ <span>Sudah punya akun? </span>
81
+ <button
82
+ @click=${this.redirectToLogin}
83
+ class="text-blue-300 font-bold"
84
+ >
85
+ Masuk<span class="text-white font-normal">.</span>
86
+ </button>
87
+ </div>
88
+ </div>
89
+ `
90
+ }
91
+
92
+ private defaultComponent() {
93
+ return html`
94
+ <div class="flex font-sans flex-col items-center space-y-2 md:space-y-4">
95
+ ${this.sendDataLayeronNonLogin()} ${this.sendDataLayerPaywallViewed()}
96
+ <h5
97
+ class="leading-5 md:leading-6 w-[296px] md:w-[400px] text-white text-center text-base mb-2 md:mb-0 ${!this
98
+ .isLogin &&
99
+ !this.isArticle &&
100
+ 'mb-0'} md:text-xl max-w-xl"
101
+ >
102
+ ${this.isArticle
103
+ ? 'Langganan untuk lanjut menonton video'
104
+ : 'Langganan sekarang untuk akses seluruh konten Kompas.id'}
105
+ </h5>
106
+ <button
107
+ @click=${this.redirectToSelectedPackage}
108
+ class="bg-green-500 rounded md:rounded-lg h-8 md:h-12 px-4 md:px-6 text-sm md:text-lg text-white font-bold leading-[18px]"
109
+ >
110
+ Langganan ${formatRupiah(this.showPackage.price)}
111
+ /${this.generateCopyDuration(this.showPackage.durationType)}
112
+ </button>
113
+ <button
114
+ @click=${this.redirectToBerlangganan}
115
+ class="text-sm md:text-lg leading-[22px] text-white font-bold underline ${!this
116
+ .isLogin && this.isArticle
117
+ ? 'pb-3'
118
+ : 'pb-2'} md:pb-4"
119
+ >
120
+ Paket Lainnya
121
+ </button>
122
+ ${!this.isLogin ? this.regulerRegistrationSection() : nothing}
123
+ </div>
124
+ `
125
+ }
126
+
127
+ /**
128
+ * Data Layer
129
+ */
130
+
131
+ private sendDataLayer(event: string): void {
132
+ const baseData = {
133
+ event,
134
+ paywall_location: this.paywall_location,
135
+ paywall_subscription_package:
136
+ this.paywall_subscription_package || this.showPackage.title,
137
+ paywall_subscription_id:
138
+ this.paywall_subscription_id || this.showPackage.id,
139
+ paywall_subscription_price:
140
+ this.paywall_subscription_price || this.showPackage.price,
141
+ paywall_position: this.paywall_position || this.showPackage.position,
142
+ user_type: this.tracker_user_type,
143
+ subscription_status: this.tracker_subscription_status,
144
+ page_domain: this.tracker_page_domain || 'Kompas.id',
145
+ metered_wall_type: this.tracker_metered_wall_type || 'HP',
146
+ metered_wall_balance: this.tracker_metered_wall_balance,
147
+ }
148
+
149
+ const data = this.isArticle
150
+ ? {
151
+ ...baseData,
152
+ page_type: this.tracker_page_type,
153
+ content_id: this.tracker_content_id,
154
+ content_title: this.tracker_content_title,
155
+ content_categories: this.tracker_content_categories,
156
+ content_type: this.tracker_content_type,
157
+ }
158
+ : baseData
159
+
160
+ window.dataLayer.push(data)
161
+ }
162
+
163
+ private sendDataLayerPaywallViewed(): void {
164
+ this.sendDataLayer('paywall_viewed')
165
+ }
166
+
167
+ private sendDataLayerSubscribeButtonClicked(): void {
168
+ this.sendDataLayer('subscribe_button_clicked')
169
+ }
170
+
171
+ private sendDataLayerOtherPackagesClicked(): void {
172
+ this.sendDataLayer('other_packages_clicked')
173
+ }
174
+
175
+ private sendDataLayeronButtonLogin(triggerClick: string): void {
176
+ window.dataLayer.push({
177
+ event: 'registrationOfferClick',
178
+ interface: deviceType(),
179
+ buttonClicked: triggerClick,
180
+ })
181
+ }
182
+
183
+ private sendDataLayeronNonLogin(): void {
184
+ window.dataLayer.push({
185
+ event: 'registrationOfferimppression',
186
+ interface: deviceType(),
187
+ })
188
+ }
189
+
190
+ /**
191
+ * Getter
192
+ */
193
+
194
+ get isArticle() {
195
+ return this.type === 'article'
196
+ }
197
+
198
+ // temporary mocking data package for component and dataLayer
199
+ get showPackage() {
200
+ return {
201
+ duration: 1,
202
+ durationType: 3,
203
+ id: '9802035',
204
+ link: 'kdp?productId=9802035&referrer=https%3A%2F%2Fwww.kompas.cloud%2Fberlangganan',
205
+ price: 50000,
206
+ position: 1,
207
+ title: 'Kompas Digital Premium 1 Bulan',
208
+ }
209
+ }
210
+
211
+ /**
212
+ * Logic Function
213
+ */
214
+
215
+ private redirectToRegister(triggerClick: string): void {
216
+ this.sendDataLayeronButtonLogin(triggerClick)
217
+ const registerHost: string = 'https://account.kompas.id/register'
218
+ const nextParams: string = encodeURIComponent(window.location.href)
219
+ const directUrlRegister: string = `${registerHost}?next=${nextParams}?status=sukses_login&status_login=login&loc=video_paywall`
220
+ window.open(directUrlRegister, '_blank')
221
+ }
222
+
223
+ private redirectToLogin(): void {
224
+ const loginHost: string = 'https://account.kompas.id/login'
225
+ const nextParams: string = encodeURIComponent(window.location.href)
226
+ const directUrlLogin: string = `${loginHost}?next=${nextParams}&loc=video_paywall`
227
+ window.open(directUrlLogin, '_blank')
228
+ }
229
+
230
+ private redirectToSelectedPackage(): void {
231
+ const url = `${this.checkoutHost}/${this.showPackage.link}&source=${this.type}`
232
+ this.sendDataLayerSubscribeButtonClicked()
233
+ window.open(url, '_blank')
234
+ }
235
+
236
+ private redirectToBerlangganan(): void {
237
+ this.sendDataLayerOtherPackagesClicked()
238
+ window.open(this.subscriptionUrl, '_blank')
239
+ }
240
+
241
+ private generateCopyDuration(type: number): string {
242
+ switch (type) {
243
+ case 1:
244
+ return 'hari'
245
+ case 2:
246
+ return 'minggu'
247
+ case 3:
248
+ return 'bulan'
249
+ case 4:
250
+ return 'tahun'
251
+ default:
252
+ return ''
253
+ }
254
+ }
255
+
256
+ /**
257
+ * Render Statement
258
+ */
259
+
260
+ render() {
261
+ return html`
262
+ <div
263
+ class="radius absolute z-20 bg-black bg-opacity-75 p-4 top-0 bottom-0 left-0 flex flex-col w-full h-full justify-center items-center"
264
+ >
265
+ ${this.defaultComponent()}
266
+ </div>
267
+ `
268
+ }
269
+ }
@@ -1,13 +1,13 @@
1
- # kompas-paywall-video
1
+ # kompasid-paywall-video
2
2
 
3
3
  ### Standar
4
- Anda perlu meletakkan _tag_ komponen `<kompas-paywall-video />` pada child component (komponen ini memiliki style `position: absolute` sehingga parent componentnya harus menggunakan style `position:relative`).
4
+ Anda perlu meletakkan _tag_ komponen `<kompasid-paywall-video />` pada child component (komponen ini memiliki style `position: absolute` sehingga parent componentnya harus menggunakan style `position:relative`).
5
5
 
6
6
  ### Elemen
7
7
  ```javascript
8
8
  <div style="position:relative">
9
9
  <your-content-component/>
10
- <kompas-paywall-video />
10
+ <kompasid-paywall-video />
11
11
  </div>
12
12
  ```
13
13
 
@@ -36,6 +36,7 @@ Contoh Penerapan:
36
36
  | `tracker_page_type` | `tracker_page_type` | prop page_type = Type of the page | `string` | `''` |
37
37
  | `tracker_subscription_status` | `tracker_subscription_status` | prop subscription_status = Status of their subscription | `string` | `''` |
38
38
  | `tracker_user_type` | `tracker_user_type` | prop user_type = Type of user based on their subscription | `string` | `''` |
39
+ | `type` | `type` | prop type = The type of video paywall | `"article" \| "homepage"` | `"article"` |
39
40
 
40
41
  ----------------------------------------------
41
42
 
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
- export { KompasPaywall } from './components/kompas-paywall/KompasPaywall.js'
2
- export { KompasFooter } from './components/kompas-footer/KompasFooter.js'
3
- export { KompasPaywallVideo } from './components/kompas-paywall-video/KompasPaywallVideo.js'
4
- export { KompasMeteredPaywall } from './components/kompas-metered-paywall/KompasMeteredPaywall.js'
1
+ export { KompasPaywall } from './components/kompasid-paywall/KompasPaywall.js'
2
+ export { KompasFooter } from './components/kompasid-footer/KompasFooter.js'
3
+ export { KompasPaywallVideo } from './components/kompasid-paywall-video/KompasPaywallVideo.js'
4
+ export { KompasMeteredPaywall } from './components/kompasid-metered-paywall/KompasMeteredPaywall.js'
5
5
 
6
6
  declare global {
7
7
  interface Window {
@@ -0,0 +1,6 @@
1
+ export const formatRupiah = (value: number) => {
2
+ const roundedValue = Math.round(value)
3
+ return `Rp ${roundedValue
4
+ .toString()
5
+ .replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.')}`
6
+ }