@kompasid/lit-web-components 0.8.21 → 0.8.23
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 +15 -8
- package/dist/src/components/kompasid-grace-period/KompasGracePeriod.js +4 -2
- package/dist/src/components/kompasid-grace-period/KompasGracePeriod.js.map +1 -1
- package/dist/src/components/kompasid-header-account/KompasHeaderAccount.d.ts +2 -0
- package/dist/src/components/kompasid-header-account/KompasHeaderAccount.js +17 -5
- package/dist/src/components/kompasid-header-account/KompasHeaderAccount.js.map +1 -1
- package/dist/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.js +12 -6
- package/dist/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.js.map +1 -1
- package/dist/src/components/kompasid-header-notification/KompasHeaderNotification.d.ts +2 -0
- package/dist/src/components/kompasid-header-notification/KompasHeaderNotification.js +15 -3
- package/dist/src/components/kompasid-header-notification/KompasHeaderNotification.js.map +1 -1
- package/dist/src/utils/api/getHeaderTheme.d.ts +1 -0
- package/dist/src/utils/api/getHeaderTheme.js +27 -0
- package/dist/src/utils/api/getHeaderTheme.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/components/kompasid-grace-period/KompasGracePeriod.ts +4 -2
- package/src/components/kompasid-header-account/KompasHeaderAccount.ts +16 -5
- package/src/components/kompasid-header-account-profile/KompasHeaderAccountProfile.ts +19 -14
- package/src/components/kompasid-header-notification/KompasHeaderNotification.ts +13 -4
- package/src/utils/api/getHeaderTheme.ts +29 -0
- package/dist/src/utils/getHeaderTheme.d.ts +0 -3
- package/dist/src/utils/getHeaderTheme.js +0 -17
- package/dist/src/utils/getHeaderTheme.js.map +0 -1
- package/src/utils/getHeaderTheme.ts +0 -19
|
@@ -123,34 +123,39 @@ export class KompasHeaderAccountProfile extends LitElement {
|
|
|
123
123
|
*/
|
|
124
124
|
|
|
125
125
|
const activeInfoTemplate = () => {
|
|
126
|
-
const { isGracePeriod, totalGracePeriod, activeInfo } =
|
|
126
|
+
const { isGracePeriod, totalGracePeriod, activeInfo, expired } =
|
|
127
|
+
this.userData
|
|
128
|
+
|
|
129
|
+
let startGracePeriodDate
|
|
130
|
+
let endGracePeriodDate
|
|
131
|
+
|
|
132
|
+
if (isGracePeriod) {
|
|
133
|
+
const totalGraceSubs = Math.max(totalGracePeriod - 1, 0)
|
|
134
|
+
startGracePeriodDate = this.formatDate(
|
|
135
|
+
subDays(new Date(), totalGraceSubs)
|
|
136
|
+
)
|
|
137
|
+
endGracePeriodDate = this.formatDate(
|
|
138
|
+
addDays(new Date(), this.maxGracePeriod - totalGracePeriod)
|
|
139
|
+
)
|
|
140
|
+
}
|
|
127
141
|
|
|
128
142
|
const expiredTextColor = isGracePeriod
|
|
129
143
|
? `text-orange-500`
|
|
130
144
|
: `text-grey-600`
|
|
131
145
|
|
|
132
|
-
const startGracePeriodDate = this.formatDate(
|
|
133
|
-
subDays(new Date().toLocaleDateString(), totalGracePeriod - 1)
|
|
134
|
-
)
|
|
135
|
-
const endGracePeriodDate = this.formatDate(
|
|
136
|
-
addDays(
|
|
137
|
-
new Date().toLocaleDateString(),
|
|
138
|
-
this.maxGracePeriod - totalGracePeriod
|
|
139
|
-
)
|
|
140
|
-
)
|
|
141
|
-
|
|
142
146
|
const text = isGracePeriod
|
|
143
147
|
? html`<span> Periode Masa Tenggang </span>
|
|
144
148
|
<p class="font-bold">
|
|
145
149
|
${startGracePeriodDate} - ${endGracePeriodDate}
|
|
146
150
|
</p> `
|
|
147
|
-
: activeInfo
|
|
151
|
+
: html`<p>${activeInfo}</p>
|
|
152
|
+
<p class="font-bold">${expired}</p>` || ''
|
|
148
153
|
|
|
149
|
-
return html`<p class="
|
|
154
|
+
return html`<p class="text-sm ${expiredTextColor}">${text}</p>`
|
|
150
155
|
}
|
|
151
156
|
|
|
152
157
|
return html`<div
|
|
153
|
-
class="active-info flex flex-col items-start leading-none text-left"
|
|
158
|
+
class="active-info flex flex-col items-start leading-none text-left font-sans"
|
|
154
159
|
>
|
|
155
160
|
<div class="flex flex-row items-center gap-4">
|
|
156
161
|
<div
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit'
|
|
2
2
|
import { format, isToday, formatDistanceStrict, subDays } from 'date-fns'
|
|
3
|
+
import { cva } from 'class-variance-authority'
|
|
3
4
|
import { id } from 'date-fns/locale/id'
|
|
4
5
|
import { customElement, property, state } from 'lit/decorators.js'
|
|
5
6
|
import { unsafeSVG } from 'lit/directives/unsafe-svg.js'
|
|
@@ -12,7 +13,7 @@ import {
|
|
|
12
13
|
ApiRubrikResponse,
|
|
13
14
|
} from './types.js'
|
|
14
15
|
import { customFetch } from './utils.js'
|
|
15
|
-
import { getHeaderTheme } from '../../utils/getHeaderTheme.js'
|
|
16
|
+
import { getHeaderTheme } from '../../utils/api/getHeaderTheme.js'
|
|
16
17
|
|
|
17
18
|
@customElement('kompasid-header-notification')
|
|
18
19
|
export class KompasHeaderNotification extends LitElement {
|
|
@@ -142,7 +143,7 @@ export class KompasHeaderNotification extends LitElement {
|
|
|
142
143
|
@state() notificationInfoData: UserNotification = {} as UserNotification
|
|
143
144
|
@state() notificationContentData: any[] = []
|
|
144
145
|
@state() isDataLoaded: boolean = false
|
|
145
|
-
|
|
146
|
+
@state() themeList: any = null
|
|
146
147
|
/*
|
|
147
148
|
* property accessToken is the access token of the user
|
|
148
149
|
* property refreshToken is the refresh token of the user
|
|
@@ -189,6 +190,7 @@ export class KompasHeaderNotification extends LitElement {
|
|
|
189
190
|
override async connectedCallback() {
|
|
190
191
|
super.connectedCallback()
|
|
191
192
|
this.isShowDropdown = false
|
|
193
|
+
this.themeList = await getHeaderTheme()
|
|
192
194
|
|
|
193
195
|
if ((this.accessToken || this.refreshToken) && this.domain)
|
|
194
196
|
await this.loadData()
|
|
@@ -200,6 +202,13 @@ export class KompasHeaderNotification extends LitElement {
|
|
|
200
202
|
document.removeEventListener('click', this.handleClickOutside)
|
|
201
203
|
}
|
|
202
204
|
|
|
205
|
+
private setTheme(param: any): String {
|
|
206
|
+
if (!this.themeList) return 'text-grey-100'
|
|
207
|
+
const cvaFn = cva('', { variants: this.themeList })
|
|
208
|
+
|
|
209
|
+
return cvaFn(param)
|
|
210
|
+
}
|
|
211
|
+
|
|
203
212
|
private async apiFetch(url: string, options: any) {
|
|
204
213
|
const response = await customFetch(
|
|
205
214
|
url,
|
|
@@ -337,7 +346,7 @@ export class KompasHeaderNotification extends LitElement {
|
|
|
337
346
|
${notificationIndicator()}
|
|
338
347
|
<div class="flex flex-row items-center self-center">
|
|
339
348
|
<div
|
|
340
|
-
class="cursor-pointer mt-0.5 ${
|
|
349
|
+
class="cursor-pointer mt-0.5 ${this.setTheme({
|
|
341
350
|
icon: this.theme,
|
|
342
351
|
})}"
|
|
343
352
|
>
|
|
@@ -656,7 +665,7 @@ export class KompasHeaderNotification extends LitElement {
|
|
|
656
665
|
${this.isDataLoaded
|
|
657
666
|
? this.notificationIcon()
|
|
658
667
|
: html`<div
|
|
659
|
-
class="cursor-pointer mt-0.5 animate-spin ${
|
|
668
|
+
class="cursor-pointer mt-0.5 animate-spin ${this.setTheme({
|
|
660
669
|
icon: this.theme,
|
|
661
670
|
})}"
|
|
662
671
|
>
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
let cachedHeaderTheme: any = null
|
|
2
|
+
let fetchPromise: Promise<any> | null = null
|
|
3
|
+
|
|
4
|
+
export const getHeaderTheme = async () => {
|
|
5
|
+
if (cachedHeaderTheme) return cachedHeaderTheme // Return cached value if available
|
|
6
|
+
|
|
7
|
+
if (!fetchPromise) {
|
|
8
|
+
fetchPromise = fetch('https://cdn-www.kompas.id/global-header/theme.json', {
|
|
9
|
+
method: 'GET',
|
|
10
|
+
headers: {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
},
|
|
13
|
+
})
|
|
14
|
+
.then(response => response.json())
|
|
15
|
+
.then(data => {
|
|
16
|
+
// Process the fetched data using `cva` and cache it
|
|
17
|
+
cachedHeaderTheme = data.header
|
|
18
|
+
|
|
19
|
+
fetchPromise = null // Reset the fetchPromise
|
|
20
|
+
return cachedHeaderTheme
|
|
21
|
+
})
|
|
22
|
+
.catch(err => {
|
|
23
|
+
fetchPromise = null // Reset the promise in case of error
|
|
24
|
+
throw err // Re-throw the error
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return fetchPromise
|
|
29
|
+
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
import { cva } from 'class-variance-authority';
|
|
3
|
-
let responseData;
|
|
4
|
-
await fetch('https://cdn-www.kompas.id/global-header/theme.json', {
|
|
5
|
-
method: 'GET',
|
|
6
|
-
headers: {
|
|
7
|
-
'Content-Type': 'application/json',
|
|
8
|
-
},
|
|
9
|
-
})
|
|
10
|
-
.then(response => response.json())
|
|
11
|
-
.then(data => {
|
|
12
|
-
responseData = data;
|
|
13
|
-
});
|
|
14
|
-
export const getHeaderTheme = cva('', {
|
|
15
|
-
variants: responseData.header,
|
|
16
|
-
});
|
|
17
|
-
//# sourceMappingURL=getHeaderTheme.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getHeaderTheme.js","sourceRoot":"","sources":["../../../src/utils/getHeaderTheme.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,EAAE,GAAG,EAAE,MAAM,0BAA0B,CAAA;AAE9C,IAAI,YAAY,CAAA;AAEhB,MAAM,KAAK,CAAC,oDAAoD,EAAE;IAChE,MAAM,EAAE,KAAK;IACb,OAAO,EAAE;QACP,cAAc,EAAE,kBAAkB;KACnC;CACF,CAAC;KACC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;KACjC,IAAI,CAAC,IAAI,CAAC,EAAE;IACX,YAAY,GAAG,IAAI,CAAA;AACrB,CAAC,CAAC,CAAA;AAEJ,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,CAAC,EAAE,EAAE;IACpC,QAAQ,EAAG,YAAoB,CAAC,MAAM;CACvC,CAAC,CAAA","sourcesContent":["// eslint-disable-next-line import/no-extraneous-dependencies\nimport { cva } from 'class-variance-authority'\n\nlet responseData\n\nawait fetch('https://cdn-www.kompas.id/global-header/theme.json', {\n method: 'GET',\n headers: {\n 'Content-Type': 'application/json',\n },\n})\n .then(response => response.json())\n .then(data => {\n responseData = data\n })\n\nexport const getHeaderTheme = cva('', {\n variants: (responseData as any).header,\n})\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
2
|
-
import { cva } from 'class-variance-authority'
|
|
3
|
-
|
|
4
|
-
let responseData
|
|
5
|
-
|
|
6
|
-
await fetch('https://cdn-www.kompas.id/global-header/theme.json', {
|
|
7
|
-
method: 'GET',
|
|
8
|
-
headers: {
|
|
9
|
-
'Content-Type': 'application/json',
|
|
10
|
-
},
|
|
11
|
-
})
|
|
12
|
-
.then(response => response.json())
|
|
13
|
-
.then(data => {
|
|
14
|
-
responseData = data
|
|
15
|
-
})
|
|
16
|
-
|
|
17
|
-
export const getHeaderTheme = cva('', {
|
|
18
|
-
variants: (responseData as any).header,
|
|
19
|
-
})
|