@saasmakers/ui 0.1.76 → 0.1.77
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.
|
@@ -2,56 +2,32 @@
|
|
|
2
2
|
import type { FieldTabs, FieldTabsAction } from '../../types/fields'
|
|
3
3
|
import { NuxtLinkLocale } from '#components'
|
|
4
4
|
|
|
5
|
-
const
|
|
5
|
+
const _props = withDefaults(defineProps<Omit<FieldTabs, 'modelValue'>>(), {
|
|
6
6
|
minimizeOnMobile: false,
|
|
7
|
-
multiple: false,
|
|
8
7
|
size: 'base',
|
|
9
8
|
tabs: undefined,
|
|
10
9
|
theme: 'rounded',
|
|
11
10
|
})
|
|
12
11
|
|
|
13
12
|
const emit = defineEmits<{
|
|
14
|
-
change: [event: MouseEvent, tabValue:
|
|
15
|
-
click: [event: MouseEvent, tabValue:
|
|
13
|
+
change: [event: MouseEvent, tabValue: string, action: FieldTabsAction, activeTab: string]
|
|
14
|
+
click: [event: MouseEvent, tabValue: string, activeTab: string]
|
|
16
15
|
}>()
|
|
17
16
|
|
|
18
|
-
const modelValue = defineModel<FieldTabs['modelValue']>({ default:
|
|
19
|
-
|
|
20
|
-
function isTabActive(tabValue: number | string) {
|
|
21
|
-
if (props.multiple) {
|
|
22
|
-
return Array.isArray(modelValue.value) && modelValue.value.includes(tabValue)
|
|
23
|
-
}
|
|
17
|
+
const modelValue = defineModel<FieldTabs['modelValue']>({ default: '' })
|
|
24
18
|
|
|
19
|
+
function isTabActive(tabValue: string) {
|
|
25
20
|
return modelValue.value === tabValue
|
|
26
21
|
}
|
|
27
22
|
|
|
28
|
-
function onTabClick(event: MouseEvent, tabValue:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// When multiple values are not allowed and tab is not already active
|
|
32
|
-
if (!props.multiple && modelValue.value !== tabValue) {
|
|
33
|
-
emit('change', event, tabValue, 'added', activeTabs)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// When multiple values are allowed
|
|
37
|
-
if (props.multiple) {
|
|
38
|
-
// Remove the tab when already active
|
|
39
|
-
if (Array.isArray(modelValue.value) && modelValue.value.includes(tabValue)) {
|
|
40
|
-
activeTabs = modelValue.value.filter(item => item !== tabValue)
|
|
41
|
-
|
|
42
|
-
emit('change', event, tabValue, 'removed', activeTabs)
|
|
43
|
-
}
|
|
44
|
-
// Push the tab when not already active
|
|
45
|
-
else {
|
|
46
|
-
activeTabs = Array.isArray(modelValue.value) ? [...modelValue.value, tabValue] : [tabValue]
|
|
47
|
-
|
|
48
|
-
emit('change', event, tabValue, 'added', activeTabs)
|
|
49
|
-
}
|
|
23
|
+
function onTabClick(event: MouseEvent, tabValue: string) {
|
|
24
|
+
if (modelValue.value !== tabValue) {
|
|
25
|
+
emit('change', event, tabValue, 'added', tabValue)
|
|
50
26
|
}
|
|
51
27
|
|
|
52
|
-
modelValue.value =
|
|
28
|
+
modelValue.value = tabValue
|
|
53
29
|
|
|
54
|
-
emit('click', event, tabValue,
|
|
30
|
+
emit('click', event, tabValue, tabValue)
|
|
55
31
|
}
|
|
56
32
|
</script>
|
|
57
33
|
|
package/app/types/fields.d.ts
CHANGED
|
@@ -140,8 +140,7 @@ export type FieldSelectMaxHeight = 'lg' | 'md' | 'sm' | 'xs'
|
|
|
140
140
|
|
|
141
141
|
export interface FieldTabs {
|
|
142
142
|
minimizeOnMobile?: boolean
|
|
143
|
-
modelValue:
|
|
144
|
-
multiple?: boolean
|
|
143
|
+
modelValue: string
|
|
145
144
|
size?: FieldSize
|
|
146
145
|
tabs: FieldTabsTab[]
|
|
147
146
|
theme?: FieldTabsTheme
|
|
@@ -152,7 +151,7 @@ export interface FieldTabsTab {
|
|
|
152
151
|
icon?: string
|
|
153
152
|
label: string
|
|
154
153
|
to?: RouteLocationNamedI18n
|
|
155
|
-
value:
|
|
154
|
+
value: string
|
|
156
155
|
}
|
|
157
156
|
|
|
158
157
|
export type FieldTabsAction = 'added' | 'removed'
|