@kompasid/lit-web-components 0.6.7 → 0.7.0
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.
- package/demo/index.html +35 -1
- package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js +39 -11
- package/dist/src/components/kompasid-paywall-body/KompasPaywallBody.js.map +1 -1
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.d.ts +39 -0
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js +340 -0
- package/dist/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js.map +1 -0
- package/dist/src/components/kompasid-widget-recirculations-default/types.d.ts +27 -0
- package/dist/src/components/kompasid-widget-recirculations-default/types.js +2 -0
- package/dist/src/components/kompasid-widget-recirculations-default/types.js.map +1 -0
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.d.ts +28 -0
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js +188 -0
- package/dist/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js.map +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/index.js +2 -0
- package/dist/src/index.js.map +1 -1
- package/dist/tailwind/tailwind.js +88 -170
- package/dist/tailwind/tailwind.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -1
- package/src/components/kompasid-paywall-body/KompasPaywallBody.ts +39 -11
- package/src/components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.ts +342 -0
- package/src/components/kompasid-widget-recirculations-default/readme.md +57 -0
- package/src/components/kompasid-widget-recirculations-default/types.ts +28 -0
- package/src/components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.ts +230 -0
- package/src/components/kompasid-widget-recirculations-list/readme.md +27 -0
- package/src/index.ts +2 -0
- package/tailwind/tailwind.css +85 -170
- package/tailwind/tailwind.ts +88 -170
- package/tailwind.config.js +2 -1
- package/assets/kompas-free-trial.png +0 -0
- package/assets/qr-code.png +0 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
import { html, css, LitElement } from 'lit'
|
|
2
|
+
import { customElement, property } from 'lit/decorators.js'
|
|
3
|
+
import { format } from 'date-fns'
|
|
4
|
+
import { id } from 'date-fns/locale/id'
|
|
5
|
+
import { TWStyles } from '../../../tailwind/tailwind.js'
|
|
6
|
+
|
|
7
|
+
interface PostTag {
|
|
8
|
+
slug: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface ListItem {
|
|
12
|
+
title: string
|
|
13
|
+
isAnalisis?: boolean
|
|
14
|
+
isEksklusif?: boolean
|
|
15
|
+
isFreemium?: boolean
|
|
16
|
+
permalink: string
|
|
17
|
+
publishedDate?: string
|
|
18
|
+
postTag?: PostTag[]
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@customElement('kompasid-widget-recirculations-list')
|
|
22
|
+
export class KompasWidgetRecirculationsList extends LitElement {
|
|
23
|
+
@property({ type: String }) widgetTitle = ''
|
|
24
|
+
@property({ type: Array }) articleList: ListItem[] = []
|
|
25
|
+
@property({ type: String }) accessToken = ''
|
|
26
|
+
@property({ type: String }) apiSlug = ''
|
|
27
|
+
|
|
28
|
+
static styles = [
|
|
29
|
+
css`
|
|
30
|
+
:host {
|
|
31
|
+
font-family: 'PT Sans', sans-serif;
|
|
32
|
+
}
|
|
33
|
+
.chip {
|
|
34
|
+
align-items: center;
|
|
35
|
+
border-radius: 0.25rem;
|
|
36
|
+
display: flex;
|
|
37
|
+
font-family: 'PT Sans', sans-serif;
|
|
38
|
+
font-size: 0.75rem;
|
|
39
|
+
font-weight: bold;
|
|
40
|
+
height: 1.5rem;
|
|
41
|
+
justify-content: center;
|
|
42
|
+
line-height: 1rem;
|
|
43
|
+
margin-bottom: 0.25rem;
|
|
44
|
+
padding: 0.375rem 0.5rem;
|
|
45
|
+
}
|
|
46
|
+
`,
|
|
47
|
+
TWStyles,
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
async connectedCallback() {
|
|
51
|
+
super.connectedCallback()
|
|
52
|
+
try {
|
|
53
|
+
await this.fetchAccessToken()
|
|
54
|
+
await this.fetchArticles()
|
|
55
|
+
} catch (error) {
|
|
56
|
+
this.handleFetchError(error)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
async fetchAccessToken() {
|
|
61
|
+
const response = await fetch(
|
|
62
|
+
'https://api.kompas.id/account/api/v1/login/guest',
|
|
63
|
+
{
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: {
|
|
66
|
+
'Content-Type': 'application/json',
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify({
|
|
69
|
+
email: 'anonynous.user@kompas.id',
|
|
70
|
+
}),
|
|
71
|
+
}
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
const result = await response.json()
|
|
75
|
+
|
|
76
|
+
if (result?.data?.accessToken) {
|
|
77
|
+
this.accessToken = result.data.accessToken
|
|
78
|
+
} else {
|
|
79
|
+
throw new Error('Token akses tidak tersedia dalam respons')
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async fetchArticles() {
|
|
84
|
+
if (!this.accessToken) {
|
|
85
|
+
throw new Error('Token akses tidak tersedia')
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const endpoint = `https://cds.kompas.id/api/v1/article/${this.apiSlug}`
|
|
89
|
+
|
|
90
|
+
const response = await fetch(endpoint, {
|
|
91
|
+
headers: {
|
|
92
|
+
Authorization: `Bearer ${this.accessToken}`,
|
|
93
|
+
'Content-Type': 'application/json',
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
|
|
97
|
+
const result = await response.json()
|
|
98
|
+
|
|
99
|
+
if (result?.result) {
|
|
100
|
+
this.articleList = result.result.map(
|
|
101
|
+
(article: {
|
|
102
|
+
postTag?: never[] | undefined
|
|
103
|
+
isFreemium?: false | undefined
|
|
104
|
+
title: any
|
|
105
|
+
permalink: any
|
|
106
|
+
publishedDate: any
|
|
107
|
+
}) => {
|
|
108
|
+
const {
|
|
109
|
+
postTag = [],
|
|
110
|
+
isFreemium = false,
|
|
111
|
+
title,
|
|
112
|
+
permalink,
|
|
113
|
+
publishedDate,
|
|
114
|
+
} = article
|
|
115
|
+
|
|
116
|
+
const isAnalisis = postTag.some(
|
|
117
|
+
(tag: { slug: string }) => tag.slug === 'analisis'
|
|
118
|
+
)
|
|
119
|
+
const isEksklusif = postTag.some(
|
|
120
|
+
(tag: { slug: string }) => tag.slug === 'eksklusif'
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
isAnalisis,
|
|
125
|
+
isEksklusif,
|
|
126
|
+
isFreemium,
|
|
127
|
+
title,
|
|
128
|
+
permalink,
|
|
129
|
+
publishedDate,
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
)
|
|
133
|
+
} else {
|
|
134
|
+
throw new Error('Data artikel populer tidak ditemukan')
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
formatDate(date: string) {
|
|
139
|
+
return format(new Date(date), "dd MMMM yyyy' · 'HH:mm' WIB", { locale: id })
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
handleFetchError(error: unknown) {
|
|
143
|
+
const errorMessage =
|
|
144
|
+
error instanceof Error ? error.message : 'Kesalahan tidak diketahui'
|
|
145
|
+
alert(`Terjadi kesalahan: ${errorMessage}`)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
renderChips(item: ListItem) {
|
|
149
|
+
const chips = []
|
|
150
|
+
|
|
151
|
+
if (item.isAnalisis) {
|
|
152
|
+
chips.push(
|
|
153
|
+
html`
|
|
154
|
+
<div class="flex">
|
|
155
|
+
<div class="chip bg-orange-100 text-orange-500">Analisis</div>
|
|
156
|
+
</div>
|
|
157
|
+
`
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (item.isEksklusif) {
|
|
162
|
+
chips.push(
|
|
163
|
+
html`
|
|
164
|
+
<div class="flex">
|
|
165
|
+
<div class="chip bg-grey-600 text-white">
|
|
166
|
+
<img
|
|
167
|
+
src="https://cdn-www.kompas.id/assets/img/icons/kompas-icon-small.svg"
|
|
168
|
+
alt="Kompas Icon"
|
|
169
|
+
style="width: 16px; height: 16px; margin-right: 4px;"
|
|
170
|
+
/>
|
|
171
|
+
Eksklusif
|
|
172
|
+
</div>
|
|
173
|
+
</div>
|
|
174
|
+
`
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (item.isFreemium) {
|
|
179
|
+
chips.push(
|
|
180
|
+
html`
|
|
181
|
+
<div class="flex">
|
|
182
|
+
<div class="chip bg-blue-100 text-brand-1">Bebas Akses</div>
|
|
183
|
+
</div>
|
|
184
|
+
`
|
|
185
|
+
)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return chips
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
render() {
|
|
192
|
+
return html`
|
|
193
|
+
<div>
|
|
194
|
+
<div class="mb-6">
|
|
195
|
+
<h5 class="capitalize font-bold text-grey-600 font-sans">
|
|
196
|
+
${this.widgetTitle}
|
|
197
|
+
</h5>
|
|
198
|
+
</div>
|
|
199
|
+
|
|
200
|
+
<ul class="flex flex-col">
|
|
201
|
+
${this.articleList.slice(0, 5).map(
|
|
202
|
+
item =>
|
|
203
|
+
html`
|
|
204
|
+
<li class="flex flex-col items-start mb-3">
|
|
205
|
+
<div class="flex w-full">
|
|
206
|
+
<div class="flex flex-col w-full">
|
|
207
|
+
${this.renderChips(item)}
|
|
208
|
+
<a
|
|
209
|
+
href="${item.permalink}"
|
|
210
|
+
class="font-bold font-sans hover:underline leading-tight text-base text-grey-600"
|
|
211
|
+
>
|
|
212
|
+
${item.title}
|
|
213
|
+
</a>
|
|
214
|
+
<div
|
|
215
|
+
class="flex w-full flex-row items-center leading-normal justify-between text-sm text-grey-500 font-sans pt-2"
|
|
216
|
+
>
|
|
217
|
+
${item.publishedDate
|
|
218
|
+
? this.formatDate(item.publishedDate)
|
|
219
|
+
: 'Tanggal tidak tersedia'}
|
|
220
|
+
</div>
|
|
221
|
+
</div>
|
|
222
|
+
</div>
|
|
223
|
+
</li>
|
|
224
|
+
`
|
|
225
|
+
)}
|
|
226
|
+
</ul>
|
|
227
|
+
</div>
|
|
228
|
+
`
|
|
229
|
+
}
|
|
230
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# kompasid-widget-recirculations-list
|
|
2
|
+
|
|
3
|
+
Komponen ini adalah komponen web berbasis LitElement yang digunakan untuk menampilkan daftar aliran artikel dari Kompas.id.
|
|
4
|
+
|
|
5
|
+
### Element
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
<kompasid-widget-recirculations-list
|
|
9
|
+
widgetTitle="Terpopuler"
|
|
10
|
+
apiSlug="popular-article"
|
|
11
|
+
></kompasid-widget-recirculations-list>
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Properties
|
|
15
|
+
|
|
16
|
+
| Property | Attribute | Description | Tipe | Default | Content |
|
|
17
|
+
| -------------| -------------| ----------------------------------------------- | -------- | ------- | ---------------- |
|
|
18
|
+
| `widgetTitle`| `widgetTitle`| Judul untuk widget. | `string` | `''` | `"Terbaru" \| "Terpopuler"` |
|
|
19
|
+
| `apiSlug` | `apiSlug` | Slug yang digunakan untuk mengidentifikasi endpoint API untuk mengambil daftar artikel. | `string` | `''` | `"list" \| "popular-article"` |
|
|
20
|
+
|
|
21
|
+
### Used by
|
|
22
|
+
|
|
23
|
+
- [kompasid-widget-recirculations-list](../kompasid-widget-recirculations-list)
|
|
24
|
+
|
|
25
|
+
## Contributors
|
|
26
|
+
|
|
27
|
+
*Dokumentasi ini dibuat oleh tim front-end Kompas.id.*
|
package/src/index.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export { KompasWidgetRecirculationsDefault } from './components/kompasid-widget-recirculations-default/KompasWidgetRecirculationsDefault.js'
|
|
2
|
+
export { KompasWidgetRecirculationsList } from './components/kompasid-widget-recirculations-list/KompasWidgetRecirculationsList.js'
|
|
1
3
|
export { KompasPaywall } from './components/kompasid-paywall/KompasPaywall.js'
|
|
2
4
|
export { KompasFooter } from './components/kompasid-footer/KompasFooter.js'
|
|
3
5
|
export { KompasPaywallVideo } from './components/kompasid-paywall-video/KompasPaywallVideo.js'
|