@finema/finework-layer 0.2.19 → 0.2.20

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.
@@ -1,202 +1,202 @@
1
- <template>
2
- <div
3
- :class="[
4
- 'grid w-full gap-4',
5
- {
6
- 'lg:grid-cols-2': !vertical,
7
- },
8
- customClass,
9
- ]"
10
- >
11
- <div
12
- v-for="item in items"
13
- :key="item.label"
14
- :class="[
15
- 'lg:flex',
16
- {
17
- 'flex-col': !inline,
18
- 'flex-row': inline,
19
- },
20
- item.customClass,
21
-
22
- ]"
23
- >
24
- <template v-if="!item.hide">
25
- <p
26
- v-if="item.type !== TYPE_INFO_ITEM.BOOLEAN"
27
- :class="[
28
- 'mb-1',
29
- {
30
- 'mb-2 block text-sm font-bold text-black': !inline,
31
- 'mr-2 font-bold': inline,
32
- },
33
- ]"
34
- >
35
- {{ item.label }}
36
- </p>
37
- <component
38
- :is="item.component"
39
- v-if="item.component"
40
- v-bind="item.props"
41
- />
42
- <slot
43
- v-else-if="item.key && $slots[`${item.key}-item`]"
44
- :name="`${item.key}-item`"
45
- :row="item"
46
- :item="item"
47
- :value="item.value"
48
- :label="item.label"
49
- />
50
- <div
51
- v-else
52
- class="whitespace-pre-line text-gray-900"
53
- >
54
- <span
55
- v-if="shouldTruncateText(item)"
56
- v-show="!expandedItems[item.label]"
57
- >
58
- {{ truncateText(item.value || '-', item.max || 0) }}
59
- <button
60
- class="
61
- text-info-600 ml-1 cursor-pointer text-sm
62
- hover:text-info-800
63
- "
64
- @click="toggleExpanded(item.label)"
65
- >
66
- เพิ่มเติม
67
- </button>
68
- </span>
69
- <span
70
- v-if="shouldTruncateText(item)"
71
- v-show="expandedItems[item.label]"
72
- >
73
- {{ item.value || '-' }}
74
- <button
75
- class="
76
- text-info-600 ml-1 cursor-pointer text-sm
77
- hover:text-info-800
78
- "
79
- @click="toggleExpanded(item.label)"
80
- >
81
- แสดงน้อยลง
82
- </button>
83
- </span>
84
- <!-- <span >
85
- <Icon
86
- class="size-5"
87
- :class="item.value ? 'text-success' : 'text-error'"
88
- :name="item.value
89
- ? 'material-symbols:check-circle-outline-rounded'
90
- : 'material-symbols:cancel-outline-rounded'"
91
- />
92
- </span> -->
93
- <Checkbox
94
- v-if="item.type === TYPE_INFO_ITEM.BOOLEAN"
95
- v-model="item.value"
96
- :label="item.label"
97
- class="pointer-events-none"
98
- />
99
- <span v-else-if="!shouldTruncateText(item)">
100
- {{ getValue(item) }}
101
- </span>
102
- </div>
103
- </template>
104
- </div>
105
- </div>
106
- </template>
107
-
108
- <script lang="ts" setup>
109
- import { reactive } from 'vue'
110
-
111
- enum TYPE_INFO_ITEM {
112
- TEXT = 'text',
113
- NUMBER = 'number',
114
- CURRENCY = 'currency',
115
- DATE = 'date',
116
- DATE_TIME = 'date_time',
117
- BOOLEAN = 'boolean',
118
- }
119
-
120
- defineProps<{
121
- items: Array<{
122
- label: string
123
- value?: any
124
- component?: any
125
- props?: Record<string, any>
126
- max?: number
127
- key?: string
128
- type?: TYPE_INFO_ITEM
129
- customClass?: string
130
- hide?: boolean
131
- }>
132
- vertical?: boolean
133
- inline?: boolean
134
- customClass?: string
135
-
136
- }>()
137
-
138
- const expandedItems = reactive<Record<string, boolean>>({})
139
-
140
- const shouldTruncateText = (item: any): boolean => {
141
- return item.max && item.value && item.value.length > item.max
142
- }
143
-
144
- const truncateText = (text: string, maxLength: number): string => {
145
- if (!maxLength || text.length <= maxLength) return text
146
-
147
- return text.slice(0, maxLength) + '...'
148
- }
149
-
150
- const toggleExpanded = (label: string): void => {
151
- expandedItems[label] = !expandedItems[label]
152
- }
153
-
154
- const getValue = (item: any): string => {
155
- if (item.type === TYPE_INFO_ITEM.DATE) {
156
- return item.value
157
- ? new Date(item.value).toLocaleDateString('en', {
158
- year: 'numeric',
159
- month: 'long',
160
- day: 'numeric',
161
- })
162
- : '-'
163
- }
164
-
165
- if (item.type === TYPE_INFO_ITEM.DATE_TIME) {
166
- return item.value
167
- ? new Date(item.value).toLocaleString('en', {
168
- year: 'numeric',
169
- month: 'long',
170
- day: 'numeric',
171
- hour: '2-digit',
172
- minute: '2-digit',
173
- second: '2-digit',
174
- hour12: false,
175
- timeZone: 'UTC',
176
- })
177
- : '-'
178
- }
179
-
180
- if (item.value === undefined || item.value === null) {
181
- return '-'
182
- }
183
-
184
- if (typeof item.value === 'number') {
185
- if (item.type === 'currency') {
186
- return NumberHelper.toCurrency(item.value)
187
- }
188
-
189
- return NumberHelper.withFixed(item.value)
190
- }
191
-
192
- if (item.type === 'currency') {
193
- return NumberHelper.toCurrency(item.value)
194
- }
195
-
196
- if (item.type === 'number') {
197
- return NumberHelper.withFixed(item.value)
198
- }
199
-
200
- return item.value || '-'
201
- }
202
- </script>
1
+ <template>
2
+ <div
3
+ :class="[
4
+ 'grid w-full gap-4',
5
+ {
6
+ 'lg:grid-cols-2': !vertical,
7
+ },
8
+ customClass,
9
+ ]"
10
+ >
11
+ <div
12
+ v-for="item in items"
13
+ :key="item.label"
14
+ :class="[
15
+ 'lg:flex',
16
+ {
17
+ 'flex-col': !inline,
18
+ 'flex-row': inline,
19
+ },
20
+ item.customClass,
21
+
22
+ ]"
23
+ >
24
+ <template v-if="!item.hide">
25
+ <p
26
+ v-if="item.type !== TYPE_INFO_ITEM.BOOLEAN"
27
+ :class="[
28
+ 'mb-1',
29
+ {
30
+ 'mb-2 block text-sm font-bold text-black': !inline,
31
+ 'mr-2 font-bold': inline,
32
+ },
33
+ ]"
34
+ >
35
+ {{ item.label }}
36
+ </p>
37
+ <component
38
+ :is="item.component"
39
+ v-if="item.component"
40
+ v-bind="item.props"
41
+ />
42
+ <slot
43
+ v-else-if="item.key && $slots[`${item.key}-item`]"
44
+ :name="`${item.key}-item`"
45
+ :row="item"
46
+ :item="item"
47
+ :value="item.value"
48
+ :label="item.label"
49
+ />
50
+ <div
51
+ v-else
52
+ class="whitespace-pre-line text-gray-900"
53
+ >
54
+ <span
55
+ v-if="shouldTruncateText(item)"
56
+ v-show="!expandedItems[item.label]"
57
+ >
58
+ {{ truncateText(item.value || '-', item.max || 0) }}
59
+ <button
60
+ class="
61
+ text-info-600 ml-1 cursor-pointer text-sm
62
+ hover:text-info-800
63
+ "
64
+ @click="toggleExpanded(item.label)"
65
+ >
66
+ เพิ่มเติม
67
+ </button>
68
+ </span>
69
+ <span
70
+ v-if="shouldTruncateText(item)"
71
+ v-show="expandedItems[item.label]"
72
+ >
73
+ {{ item.value || '-' }}
74
+ <button
75
+ class="
76
+ text-info-600 ml-1 cursor-pointer text-sm
77
+ hover:text-info-800
78
+ "
79
+ @click="toggleExpanded(item.label)"
80
+ >
81
+ แสดงน้อยลง
82
+ </button>
83
+ </span>
84
+ <!-- <span >
85
+ <Icon
86
+ class="size-5"
87
+ :class="item.value ? 'text-success' : 'text-error'"
88
+ :name="item.value
89
+ ? 'material-symbols:check-circle-outline-rounded'
90
+ : 'material-symbols:cancel-outline-rounded'"
91
+ />
92
+ </span> -->
93
+ <Checkbox
94
+ v-if="item.type === TYPE_INFO_ITEM.BOOLEAN"
95
+ v-model="item.value"
96
+ :label="item.label"
97
+ class="pointer-events-none"
98
+ />
99
+ <span v-else-if="!shouldTruncateText(item)">
100
+ {{ getValue(item) }}
101
+ </span>
102
+ </div>
103
+ </template>
104
+ </div>
105
+ </div>
106
+ </template>
107
+
108
+ <script lang="ts" setup>
109
+ import { reactive } from 'vue'
110
+
111
+ enum TYPE_INFO_ITEM {
112
+ TEXT = 'text',
113
+ NUMBER = 'number',
114
+ CURRENCY = 'currency',
115
+ DATE = 'date',
116
+ DATE_TIME = 'date_time',
117
+ BOOLEAN = 'boolean',
118
+ }
119
+
120
+ defineProps<{
121
+ items: Array<{
122
+ label: string
123
+ value?: any
124
+ component?: any
125
+ props?: Record<string, any>
126
+ max?: number
127
+ key?: string
128
+ type?: TYPE_INFO_ITEM
129
+ customClass?: string
130
+ hide?: boolean
131
+ }>
132
+ vertical?: boolean
133
+ inline?: boolean
134
+ customClass?: string
135
+
136
+ }>()
137
+
138
+ const expandedItems = reactive<Record<string, boolean>>({})
139
+
140
+ const shouldTruncateText = (item: any): boolean => {
141
+ return item.max && item.value && item.value.length > item.max
142
+ }
143
+
144
+ const truncateText = (text: string, maxLength: number): string => {
145
+ if (!maxLength || text.length <= maxLength) return text
146
+
147
+ return text.slice(0, maxLength) + '...'
148
+ }
149
+
150
+ const toggleExpanded = (label: string): void => {
151
+ expandedItems[label] = !expandedItems[label]
152
+ }
153
+
154
+ const getValue = (item: any): string => {
155
+ if (item.type === TYPE_INFO_ITEM.DATE) {
156
+ return item.value
157
+ ? new Date(item.value).toLocaleDateString('en', {
158
+ year: 'numeric',
159
+ month: 'long',
160
+ day: 'numeric',
161
+ })
162
+ : '-'
163
+ }
164
+
165
+ if (item.type === TYPE_INFO_ITEM.DATE_TIME) {
166
+ return item.value
167
+ ? new Date(item.value).toLocaleString('en', {
168
+ year: 'numeric',
169
+ month: 'long',
170
+ day: 'numeric',
171
+ hour: '2-digit',
172
+ minute: '2-digit',
173
+ second: '2-digit',
174
+ hour12: false,
175
+ timeZone: 'UTC',
176
+ })
177
+ : '-'
178
+ }
179
+
180
+ if (item.value === undefined || item.value === null) {
181
+ return '-'
182
+ }
183
+
184
+ if (typeof item.value === 'number') {
185
+ if (item.type === 'currency') {
186
+ return NumberHelper.toCurrency(item.value)
187
+ }
188
+
189
+ return NumberHelper.withFixed(item.value)
190
+ }
191
+
192
+ if (item.type === 'currency') {
193
+ return NumberHelper.toCurrency(item.value)
194
+ }
195
+
196
+ if (item.type === 'number') {
197
+ return NumberHelper.withFixed(item.value)
198
+ }
199
+
200
+ return item.value || '-'
201
+ }
202
+ </script>