@finema/finework-layer 0.2.138 → 0.2.140

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.2.140](https://gitlab.finema.co/finema/finework/finework-frontend-layer/compare/0.2.139...0.2.140) (2026-02-17)
4
+
5
+ ### Features
6
+
7
+ * refactor TimeFromNow component and add RelativeTimeFromNow component for enhanced date formatting ([b7c9d76](https://gitlab.finema.co/finema/finework/finework-frontend-layer/commit/b7c9d76dfdc8f5ec901daa582fec4e16db1ccd20))
8
+
9
+ ## [0.2.139](https://gitlab.finema.co/finema/finework/finework-frontend-layer/compare/0.2.138...0.2.139) (2026-02-16)
10
+
11
+ ### Bug Fixes
12
+
13
+ * adjust table header and cell styles for pinned variants ([54fa9bb](https://gitlab.finema.co/finema/finework/finework-frontend-layer/commit/54fa9bbaeb3b1f3f9d143424b0207f90e287b489))
14
+
3
15
  ## [0.2.138](https://gitlab.finema.co/finema/finework/finework-frontend-layer/compare/0.2.137...0.2.138) (2026-02-16)
4
16
 
5
17
  ### Features
package/app/app.config.ts CHANGED
@@ -133,8 +133,8 @@ export default defineAppConfig({
133
133
  variants: {
134
134
  pinned: {
135
135
  true: {
136
- th: 'sticky bg-[#F9FAFB] data-[pinned=left]:left-0 data-[pinned=right]:right-0 z-[100] ',
137
- td: 'sticky bg-white data-[pinned=left]:left-0 data-[pinned=right]:right-0 ',
136
+ th: 'sticky translate-x-px bg-[#F9FAFB] data-[pinned=left]:left-0 data-[pinned=right]:right-0 z-[100] ',
137
+ td: 'sticky translate-x-px bg-white data-[pinned=left]:left-0 data-[pinned=right]:right-0 ',
138
138
  },
139
139
  },
140
140
  },
@@ -0,0 +1,106 @@
1
+ <template>
2
+ <component
3
+ :is="props.as || 'span'"
4
+ :title="TimeHelper.displayDateTime(props.value)"
5
+ >
6
+ {{ getValue }}
7
+ </component>
8
+ </template>
9
+
10
+ <script lang="ts" setup>
11
+ import { differenceInDays, differenceInHours, differenceInMinutes, differenceInMonths, differenceInWeeks, startOfDay, addDays } from 'date-fns'
12
+
13
+ const props = defineProps<{
14
+ value: string | Date
15
+ as?: string
16
+ }>()
17
+
18
+ const config = useAppConfig()
19
+ const localeInject = inject('locale')
20
+
21
+ const isThaiLocale = computed(() => {
22
+ return (localeInject ?? config.core.locale) === 'th'
23
+ })
24
+
25
+ const getValue = computed(() => {
26
+ const targetDate = new Date(props.value)
27
+ const now = new Date()
28
+
29
+ const nowDate = startOfDay(now)
30
+ const dueDateOnly = startOfDay(targetDate)
31
+
32
+ if (nowDate > dueDateOnly) {
33
+ const dueDateEnd = addDays(dueDateOnly, 1)
34
+
35
+ const months = differenceInMonths(now, dueDateEnd)
36
+
37
+ if (months > 0) {
38
+ if (isThaiLocale.value) {
39
+ return months === 1 ? '1 เดือนที่แล้ว' : `${months} เดือนที่แล้ว`
40
+ }
41
+
42
+ return months === 1 ? '1 month ago' : `${months} months ago`
43
+ }
44
+
45
+ const weeks = differenceInWeeks(now, dueDateEnd)
46
+
47
+ if (weeks > 0) {
48
+ if (isThaiLocale.value) {
49
+ return weeks === 1 ? '1 สัปดาห์ที่แล้ว' : `${weeks} สัปดาห์ที่แล้ว`
50
+ }
51
+
52
+ return weeks === 1 ? '1 week ago' : `${weeks} weeks ago`
53
+ }
54
+
55
+ const days = differenceInDays(now, dueDateEnd)
56
+
57
+ if (days > 0) {
58
+ if (isThaiLocale.value) {
59
+ return days === 1 ? '1 วันที่แล้ว' : `${days} วันที่แล้ว`
60
+ }
61
+
62
+ return days === 1 ? '1 day ago' : `${days} days ago`
63
+ }
64
+
65
+ const hours = differenceInHours(now, dueDateEnd)
66
+
67
+ if (hours > 0) {
68
+ if (isThaiLocale.value) {
69
+ return hours === 1 ? '1 ชม.ที่แล้ว' : `${hours} ชม.ที่แล้ว`
70
+ }
71
+
72
+ return hours === 1 ? '1hr ago' : `${hours}hr ago`
73
+ }
74
+
75
+ const minutes = differenceInMinutes(now, dueDateEnd)
76
+
77
+ if (minutes > 0) {
78
+ if (isThaiLocale.value) {
79
+ return minutes === 1 ? '1 นาทีที่แล้ว' : `${minutes} นาทีที่แล้ว`
80
+ }
81
+
82
+ return minutes === 1 ? '1m ago' : `${minutes}m ago`
83
+ }
84
+
85
+ return isThaiLocale.value ? 'เมื่อสักครู่' : 'just now'
86
+ }
87
+
88
+ if (nowDate.getTime() === dueDateOnly.getTime()) {
89
+ return isThaiLocale.value ? 'วันนี้' : 'Today'
90
+ }
91
+
92
+ const tomorrow = addDays(nowDate, 1)
93
+
94
+ if (tomorrow.getTime() === dueDateOnly.getTime()) {
95
+ return isThaiLocale.value ? 'พรุ่งนี้' : 'Tomorrow'
96
+ }
97
+
98
+ const days = differenceInDays(dueDateOnly, nowDate)
99
+
100
+ if (isThaiLocale.value) {
101
+ return `อีก ${days} วัน`
102
+ }
103
+
104
+ return `in ${days}d`
105
+ })
106
+ </script>
@@ -8,72 +8,32 @@
8
8
  </template>
9
9
 
10
10
  <script lang="ts" setup>
11
- import { differenceInDays, differenceInHours, differenceInMinutes, differenceInMonths, differenceInWeeks, startOfDay, addDays } from 'date-fns'
11
+ import { formatDistanceToNow, differenceInDays } from 'date-fns'
12
+ import * as locales from 'date-fns/locale'
12
13
 
13
14
  const props = defineProps<{
14
15
  value: string | Date
15
16
  as?: string
16
17
  }>()
17
18
 
18
- const getValue = computed(() => {
19
- const targetDate = new Date(props.value)
20
- const now = new Date()
21
-
22
- // Compare only the date part
23
- const nowDate = startOfDay(now)
24
- const dueDateOnly = startOfDay(targetDate)
25
-
26
- if (nowDate > dueDateOnly) {
27
- const dueDateEnd = addDays(dueDateOnly, 1)
28
-
29
- const months = differenceInMonths(now, dueDateEnd)
30
-
31
- if (months > 0) {
32
- return months === 1 ? '1 month ago' : `${months} months ago`
33
- }
34
-
35
- const weeks = differenceInWeeks(now, dueDateEnd)
36
-
37
- if (weeks > 0) {
38
- return weeks === 1 ? '1 week ago' : `${weeks} weeks ago`
39
- }
40
-
41
- const days = differenceInDays(now, dueDateEnd)
42
-
43
- if (days > 0) {
44
- return days === 1 ? '1 day ago' : `${days} days ago`
45
- }
19
+ const config = useAppConfig()
20
+ const localeInject = inject('locale')
46
21
 
47
- const hours = differenceInHours(now, dueDateEnd)
48
-
49
- if (hours > 0) {
50
- return hours === 1 ? '1hr ago' : `${hours}hr ago`
51
- }
52
-
53
- const minutes = differenceInMinutes(now, dueDateEnd)
54
-
55
- if (minutes > 0) {
56
- return minutes === 1 ? '1m ago' : `${minutes}m ago`
57
- }
58
-
59
- return 'just now'
60
- }
61
-
62
- // Today
63
- if (nowDate.getTime() === dueDateOnly.getTime()) {
64
- return 'Today'
65
- }
22
+ const getValue = computed(() => {
23
+ const locale = (localeInject ?? config.core.locale) === 'th'
24
+ ? locales.th
25
+ : locales.enUS
66
26
 
67
- // Tomorrow
68
- const tomorrow = addDays(nowDate, 1)
27
+ const targetDate = new Date(props.value)
28
+ const daysDiff = differenceInDays(new Date(), targetDate)
69
29
 
70
- if (tomorrow.getTime() === dueDateOnly.getTime()) {
71
- return 'Tomorrow'
30
+ if (daysDiff <= 6) {
31
+ return formatDistanceToNow(targetDate, {
32
+ addSuffix: true,
33
+ locale,
34
+ })
72
35
  }
73
36
 
74
- // In X days (future)
75
- const days = differenceInDays(dueDateOnly, nowDate)
76
-
77
- return `in ${days}d`
37
+ return TimeHelper.displayDateTime(props.value)
78
38
  })
79
39
  </script>
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@finema/finework-layer",
3
3
  "type": "module",
4
- "version": "0.2.138",
4
+ "version": "0.2.140",
5
5
  "main": "./nuxt.config.ts",
6
6
  "scripts": {
7
7
  "dev": "nuxi dev .playground -o",