@ramathibodi/nuxt-commons 0.1.17 → 0.1.18

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/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.0.0"
6
6
  },
7
- "version": "0.1.17"
7
+ "version": "0.1.18"
8
8
  }
@@ -0,0 +1,41 @@
1
+ <script setup lang="ts">
2
+ import { DateTime, type ToRelativeOptions } from "luxon";
3
+ import { computed } from "vue";
4
+
5
+ interface Props {
6
+ modelValue: DateTime;
7
+ locale?: 'TH' | 'EN';
8
+ }
9
+
10
+ const props = withDefaults(defineProps<Props>(), {
11
+ locale: 'TH',
12
+ });
13
+
14
+ const timeAgo = computed(() => {
15
+ const now = DateTime.now();
16
+ const diff = now.diff(props.modelValue, ['years', 'months', 'days', 'hours', 'minutes', 'seconds']).toObject();
17
+
18
+ let unit: ToRelativeOptions['unit'] = 'seconds';
19
+ if (diff.years && diff.years > 0) {
20
+ unit = 'years';
21
+ } else if (diff.months && diff.months > 0) {
22
+ unit = 'months';
23
+ } else if (diff.days && diff.days > 0) {
24
+ unit = 'days';
25
+ } else if (diff.hours && diff.hours > 0) {
26
+ unit = 'hours';
27
+ } else if (diff.minutes && diff.minutes > 0) {
28
+ unit = 'minutes';
29
+ }
30
+
31
+ return props.modelValue.setLocale(props.locale).toRelative({ unit });
32
+ });
33
+ </script>
34
+
35
+ <template>
36
+ <span>{{ timeAgo }}</span>
37
+ </template>
38
+
39
+ <style scoped>
40
+
41
+ </style>
@@ -1,48 +1,100 @@
1
1
  <script lang="ts" setup>
2
- import {computed} from 'vue'
2
+ import { computed, ref } from 'vue';
3
+
3
4
  interface Props {
4
- label: string
5
- value?: string | null | undefined
6
- horizontal?: boolean
7
- size? : 'large' | 'medium'
5
+ label: string;
6
+ value?: string | null;
7
+ horizontal?: boolean;
8
+ size?: 'large' | 'medium';
9
+ truncate?: boolean;
8
10
  }
9
11
 
10
12
  const props = withDefaults(defineProps<Props>(), {
11
- label: '', value: '',
12
- })
13
- const cal_size = computed(()=>{
14
- if(props.size=='medium') return 'text-subtitle-1'
15
- else return 'text-h6'
16
- })
13
+ label: '',
14
+ value: '',
15
+ horizontal: false,
16
+ size: 'large',
17
+ truncate: false,
18
+ });
19
+
20
+ const valueText = ref<HTMLElement | null>(null);
21
+ const isTooltip = ref(false);
22
+
23
+ const calSize = computed(() => (props.size === 'medium' ? 'text-subtitle-1' : 'text-h6'));
24
+ const calTruncate = computed(() => (props.truncate ? 'text-truncate' : ''));
25
+
26
+ const setTruncate = (event: Event) => {
27
+ const target = event.target as HTMLElement;
28
+ isTooltip.value = target.offsetWidth < target.scrollWidth;
29
+ };
30
+
17
31
  </script>
18
32
 
19
33
  <template>
20
- <div v-if="horizontal" class="d-flex align-end" :="$attrs">
34
+ <div
35
+ v-if="props.horizontal"
36
+ class="d-flex align-top"
37
+ v-bind="$attrs"
38
+ @resize="setTruncate"
39
+ >
21
40
  <div class="text-medium-emphasis text-no-wrap">
22
- <slot name="label">
23
- {{ label }}:
24
- </slot>
41
+ <slot name="label">{{ props.label }}:</slot>
25
42
  </div>
26
- <div class="ml-1">
43
+ <div :class="`ml-1 ${calTruncate}`" ref="valueText">
27
44
  <slot name="value">
28
- {{ value }}
45
+ <div v-if="!props.truncate">{{ props.value }}</div>
46
+ <div
47
+ v-else
48
+ @mouseover="setTruncate"
49
+ @mouseout="isTooltip = false"
50
+ >
51
+ <v-tooltip :model-value="isTooltip" location="bottom">
52
+ <template #activator="{ props }">
53
+ <div
54
+ class="text-truncate"
55
+ v-bind="isTooltip ? props : ''"
56
+ >
57
+ {{ value }}
58
+ </div>
59
+ </template>
60
+ <span>{{ value }}</span>
61
+ </v-tooltip>
62
+ </div>
29
63
  </slot>
30
64
  </div>
31
65
  </div>
32
- <v-card v-else variant="text" :="$attrs">
33
- <VCardSubtitle class="ma-0 pa-0 text-black">
34
- <slot name="label">
35
- {{ label }}
36
- </slot>
37
- </VCardSubtitle>
38
- <VCardText :class="`pa-0 mb-2 ${cal_size}`">
39
- <slot name="value">
40
- {{ value }}
41
- </slot>
42
- </VCardText>
43
- </v-card>
66
+
67
+ <v-card v-else variant="text" v-bind="$attrs">
68
+ <VCardSubtitle class="ma-0 pa-0 text-black">
69
+ <slot name="label">{{ props.label }}</slot>
70
+ </VCardSubtitle>
71
+ <VCardText :class="`pa-0 mb-2 ${calSize}`">
72
+ <div :class="calTruncate" ref="valueText">
73
+ <slot name="value">
74
+ <div v-if="!props.truncate">{{ props.value }}</div>
75
+ <div
76
+ v-else
77
+ @mouseover="setTruncate"
78
+ @mouseout="isTooltip = false"
79
+ >
80
+ <v-tooltip :model-value="isTooltip" location="bottom">
81
+ <template #activator="{ props }">
82
+ <div
83
+ class="text-truncate"
84
+ v-bind="isTooltip ? props : ''"
85
+ >
86
+ {{ value }}
87
+ </div>
88
+ </template>
89
+ <span>{{ value }}</span>
90
+ </v-tooltip>
91
+ </div>
92
+ </slot>
93
+ </div>
94
+ </VCardText>
95
+ </v-card>
44
96
  </template>
45
97
 
46
- <style lang="">
98
+ <style scoped>
47
99
 
48
100
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "0.1.17",
3
+ "version": "0.1.18",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",