@datametria/vue-components 2.3.1 → 2.4.1
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/README.md +625 -594
- package/dist/index.es.js +1962 -1887
- package/dist/index.umd.js +6 -6
- package/dist/src/components/DatametriaForm.vue.d.ts +1 -1
- package/dist/src/components/DatametriaInput.vue.d.ts +9 -1
- package/dist/src/components/DatametriaSelect.vue.d.ts +10 -1
- package/dist/vue-components.css +1 -1
- package/package.json +103 -102
- package/src/components/DatametriaAlert.vue +151 -133
- package/src/components/DatametriaAutocomplete.vue +250 -229
- package/src/components/DatametriaAvatar.vue +256 -238
- package/src/components/DatametriaBadge.vue +101 -96
- package/src/components/DatametriaBreadcrumb.vue +132 -128
- package/src/components/DatametriaButton.vue +191 -173
- package/src/components/DatametriaCard.vue +84 -66
- package/src/components/DatametriaCheckbox.vue +197 -193
- package/src/components/DatametriaChip.vue +159 -141
- package/src/components/DatametriaContainer.vue +70 -52
- package/src/components/DatametriaDataTable.vue +318 -300
- package/src/components/DatametriaDatePicker.vue +396 -378
- package/src/components/DatametriaDialog.vue +297 -293
- package/src/components/DatametriaDivider.vue +105 -98
- package/src/components/DatametriaDropdown.vue +356 -350
- package/src/components/DatametriaEmpty.vue +155 -151
- package/src/components/DatametriaFileUpload.vue +413 -395
- package/src/components/DatametriaFloatingBar.vue +144 -126
- package/src/components/DatametriaForm.vue +174 -156
- package/src/components/DatametriaFormItem.vue +183 -179
- package/src/components/DatametriaGrid.vue +55 -37
- package/src/components/DatametriaInput.vue +314 -263
- package/src/components/DatametriaMenu.vue +618 -600
- package/src/components/DatametriaModal.vue +147 -129
- package/src/components/DatametriaNavbar.vue +277 -223
- package/src/components/DatametriaPagination.vue +375 -371
- package/src/components/DatametriaPasswordInput.vue +446 -426
- package/src/components/DatametriaPopconfirm.vue +240 -234
- package/src/components/DatametriaProgress.vue +228 -224
- package/src/components/DatametriaRadio.vue +151 -147
- package/src/components/DatametriaResult.vue +135 -131
- package/src/components/DatametriaSelect.vue +311 -211
- package/src/components/DatametriaSidebar.vue +294 -222
- package/src/components/DatametriaSkeleton.vue +257 -234
- package/src/components/DatametriaSlider.vue +409 -391
- package/src/components/DatametriaSortableTable.vue +826 -802
- package/src/components/DatametriaSpinner.vue +114 -110
- package/src/components/DatametriaSteps.vue +318 -312
- package/src/components/DatametriaSwitch.vue +146 -142
- package/src/components/DatametriaTabPane.vue +94 -76
- package/src/components/DatametriaTable.vue +118 -100
- package/src/components/DatametriaTabs.vue +315 -297
- package/src/components/DatametriaTextarea.vue +213 -195
- package/src/components/DatametriaTimePicker.vue +317 -299
- package/src/components/DatametriaToast.vue +176 -176
- package/src/components/DatametriaTooltip.vue +421 -400
- package/src/components/DatametriaTree.vue +126 -122
- package/src/components/DatametriaTreeNode.vue +176 -172
- package/src/components/DatametriaUpload.vue +379 -361
- package/src/components/__tests__/DatametriaAlert.test.js +35 -35
- package/src/components/__tests__/DatametriaAlert.test.ts +190 -190
- package/src/components/__tests__/DatametriaAvatar.test.ts +151 -151
- package/src/components/__tests__/DatametriaBadge.test.js +29 -29
- package/src/components/__tests__/DatametriaBadge.test.ts +167 -167
- package/src/components/__tests__/DatametriaBreadcrumb.test.ts +187 -0
- package/src/components/__tests__/DatametriaButton.test.js +30 -30
- package/src/components/__tests__/DatametriaButton.test.ts +283 -283
- package/src/components/__tests__/DatametriaCard.test.ts +201 -201
- package/src/components/__tests__/DatametriaCheckbox.test.ts +204 -0
- package/src/components/__tests__/DatametriaChip.test.js +38 -38
- package/src/components/__tests__/DatametriaContainer.test.ts +52 -52
- package/src/components/__tests__/DatametriaDialog.test.ts +338 -0
- package/src/components/__tests__/DatametriaDivider.test.ts +54 -54
- package/src/components/__tests__/DatametriaDropdown.test.ts +357 -0
- package/src/components/__tests__/DatametriaEmpty.test.ts +261 -0
- package/src/components/__tests__/DatametriaFileUpload.test.ts +290 -290
- package/src/components/__tests__/DatametriaFloatingBar.test.ts +137 -137
- package/src/components/__tests__/DatametriaForm.test.ts +96 -0
- package/src/components/__tests__/DatametriaFormItem.test.ts +58 -0
- package/src/components/__tests__/DatametriaGrid.test.ts +31 -31
- package/src/components/__tests__/DatametriaInput.test.ts +72 -72
- package/src/components/__tests__/DatametriaMenu.test.ts +366 -366
- package/src/components/__tests__/DatametriaModal.test.ts +86 -86
- package/src/components/__tests__/DatametriaNavbar.test.js +48 -48
- package/src/components/__tests__/DatametriaNavbar.test.ts +203 -203
- package/src/components/__tests__/DatametriaPasswordInput.test.js +305 -305
- package/src/components/__tests__/DatametriaRadio.test.ts +195 -0
- package/src/components/__tests__/DatametriaSelect.test.ts +77 -77
- package/src/components/__tests__/DatametriaSidebar.test.ts +169 -169
- package/src/components/__tests__/DatametriaSlider.test.ts +261 -261
- package/src/components/__tests__/DatametriaSortableTable.test.js +168 -168
- package/src/components/__tests__/DatametriaSpinner.test.ts +156 -156
- package/src/components/__tests__/DatametriaSteps.test.ts +211 -0
- package/src/components/__tests__/DatametriaSwitch.test.ts +129 -0
- package/src/components/__tests__/DatametriaTabPane.test.ts +205 -0
- package/src/components/__tests__/DatametriaTable.test.ts +97 -97
- package/src/components/__tests__/DatametriaTabs.test.ts +232 -232
- package/src/components/__tests__/DatametriaToast.test.js +48 -48
- package/src/components/__tests__/DatametriaToast.test.ts +99 -99
- package/src/components/__tests__/DatametriaTree.test.ts +376 -0
- package/src/components/__tests__/index.test.ts +48 -0
- package/src/composables/useAccessibilityScale.ts +94 -94
- package/src/composables/useBreakpoints.ts +82 -82
- package/src/composables/useHapticFeedback.ts +439 -439
- package/src/composables/useRipple.ts +218 -218
- package/src/composables/useTheme.ts +5 -1
- package/src/index.ts +84 -84
- package/src/stories/Variants.stories.js +95 -95
- package/src/styles/design-tokens.css +623 -623
- package/src/theme/ThemeProvider.vue +96 -96
- package/src/theme/__tests__/ThemeProvider.test.ts +208 -208
- package/src/theme/__tests__/constants.test.ts +31 -31
- package/src/theme/__tests__/presets.test.ts +166 -166
- package/src/theme/__tests__/tokens.test.ts +155 -155
- package/src/theme/__tests__/types.test.ts +153 -153
- package/src/theme/__tests__/useTheme.test.ts +146 -146
- package/src/theme/constants.ts +14 -14
- package/src/theme/index.ts +12 -12
- package/src/theme/presets/datametria.ts +94 -94
- package/src/theme/presets/default.ts +94 -94
- package/src/theme/presets/index.ts +8 -8
- package/src/theme/tokens/colors.ts +28 -28
- package/src/theme/tokens/index.ts +47 -47
- package/src/theme/tokens/spacing.ts +21 -21
- package/src/theme/tokens/typography.ts +35 -35
- package/src/theme/types.ts +111 -111
- package/src/theme/useTheme.ts +28 -28
- package/src/types/index.ts +55 -55
|
@@ -1,217 +1,317 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div class="datametria-select" :class="{ 'is-disabled': disabled }">
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
<span class="datametria-
|
|
7
|
-
</
|
|
8
|
-
|
|
9
|
-
<
|
|
10
|
-
<
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
1
|
+
<template>
|
|
2
|
+
<div class="datametria-select" :class="{ 'is-disabled': disabled }">
|
|
3
|
+
<!-- Label -->
|
|
4
|
+
<label v-if="label" class="datametria-select__label">
|
|
5
|
+
{{ label }}
|
|
6
|
+
<span v-if="required" class="datametria-select__required">*</span>
|
|
7
|
+
</label>
|
|
8
|
+
|
|
9
|
+
<div ref="triggerRef" class="datametria-select__trigger" @click.stop="toggleDropdown">
|
|
10
|
+
<span v-if="displayValue" class="datametria-select__value">{{ displayValue }}</span>
|
|
11
|
+
<span v-else class="datametria-select__placeholder">{{ placeholder }}</span>
|
|
12
|
+
<span class="datametria-select__arrow">▼</span>
|
|
13
|
+
|
|
14
|
+
<!-- Hidden select for testing -->
|
|
15
|
+
<select
|
|
16
|
+
v-model="selectedValue"
|
|
17
|
+
:disabled="disabled"
|
|
18
|
+
style="position: absolute; opacity: 0; pointer-events: none;"
|
|
19
|
+
@change="handleNativeChange"
|
|
20
|
+
>
|
|
21
|
+
<option value="" disabled>{{ placeholder }}</option>
|
|
22
|
+
<option
|
|
23
|
+
v-for="option in options"
|
|
24
|
+
:key="option.value"
|
|
25
|
+
:value="option.value"
|
|
26
|
+
>
|
|
27
|
+
{{ option.label }}
|
|
28
|
+
</option>
|
|
29
|
+
</select>
|
|
30
|
+
</div>
|
|
31
|
+
|
|
32
|
+
<Teleport to="body">
|
|
33
|
+
<div v-if="isOpen" class="datametria-select__dropdown" :style="dropdownStyle">
|
|
34
|
+
<input
|
|
35
|
+
v-if="filterable"
|
|
36
|
+
v-model="filterText"
|
|
37
|
+
class="datametria-select__filter"
|
|
38
|
+
placeholder="Buscar..."
|
|
39
|
+
@click.stop
|
|
40
|
+
/>
|
|
41
|
+
<div class="datametria-select__options">
|
|
42
|
+
<div
|
|
43
|
+
v-for="option in filteredOptions"
|
|
44
|
+
:key="option.value"
|
|
45
|
+
class="datametria-select__option"
|
|
46
|
+
:class="{ 'is-selected': isSelected(option.value) }"
|
|
47
|
+
@click="handleSelect(option)"
|
|
48
|
+
>
|
|
49
|
+
{{ option.label }}
|
|
50
|
+
</div>
|
|
51
|
+
<div v-if="filteredOptions.length === 0" class="datametria-select__empty">
|
|
52
|
+
Nenhum resultado
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
</div>
|
|
56
|
+
</Teleport>
|
|
57
|
+
|
|
58
|
+
<!-- Error Message -->
|
|
59
|
+
<div v-if="errorMessage" class="datametria-select__error">
|
|
60
|
+
{{ errorMessage }}
|
|
61
|
+
</div>
|
|
62
|
+
</div>
|
|
63
|
+
</template>
|
|
64
|
+
|
|
65
|
+
<script setup lang="ts">
|
|
66
|
+
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
|
67
|
+
|
|
68
|
+
interface SelectOption {
|
|
69
|
+
label: string
|
|
70
|
+
value: any
|
|
71
|
+
disabled?: boolean
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface Props {
|
|
75
|
+
modelValue: any | any[]
|
|
76
|
+
options: SelectOption[]
|
|
77
|
+
/** Label do select */
|
|
78
|
+
label?: string
|
|
79
|
+
/** Campo obrigatório */
|
|
80
|
+
required?: boolean
|
|
81
|
+
/** Mensagem de erro */
|
|
82
|
+
errorMessage?: string
|
|
83
|
+
placeholder?: string
|
|
84
|
+
disabled?: boolean
|
|
85
|
+
clearable?: boolean
|
|
86
|
+
filterable?: boolean
|
|
87
|
+
multiple?: boolean
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
91
|
+
placeholder: 'Selecione',
|
|
92
|
+
disabled: false,
|
|
93
|
+
clearable: false,
|
|
94
|
+
filterable: false,
|
|
95
|
+
multiple: false,
|
|
96
|
+
required: false
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
const emit = defineEmits<{
|
|
100
|
+
'update:modelValue': [value: any]
|
|
101
|
+
'change': [value: any]
|
|
102
|
+
}>()
|
|
103
|
+
|
|
104
|
+
const isOpen = ref(false)
|
|
105
|
+
const filterText = ref('')
|
|
106
|
+
const dropdownStyle = ref({})
|
|
107
|
+
const triggerRef = ref<HTMLElement>()
|
|
108
|
+
|
|
109
|
+
const selectedValue = computed({
|
|
110
|
+
get: () => props.modelValue,
|
|
111
|
+
set: (value) => {
|
|
112
|
+
emit('update:modelValue', value)
|
|
113
|
+
emit('change', value)
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
const displayValue = computed(() => {
|
|
118
|
+
if (props.multiple && Array.isArray(props.modelValue)) {
|
|
119
|
+
const labels = props.modelValue.map(v =>
|
|
120
|
+
props.options.find(o => o.value === v)?.label
|
|
121
|
+
).filter(Boolean)
|
|
122
|
+
return labels.join(', ')
|
|
123
|
+
}
|
|
124
|
+
return props.options.find(o => o.value === props.modelValue)?.label || ''
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const filteredOptions = computed(() => {
|
|
128
|
+
if (!props.filterable || !filterText.value) return props.options
|
|
129
|
+
return props.options.filter(o =>
|
|
130
|
+
o.label.toLowerCase().includes(filterText.value.toLowerCase())
|
|
131
|
+
)
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
const isSelected = (value: any) => {
|
|
135
|
+
if (props.multiple && Array.isArray(props.modelValue)) {
|
|
136
|
+
return props.modelValue.includes(value)
|
|
137
|
+
}
|
|
138
|
+
return props.modelValue === value
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const toggleDropdown = () => {
|
|
142
|
+
if (!props.disabled) {
|
|
143
|
+
isOpen.value = !isOpen.value
|
|
144
|
+
if (isOpen.value && triggerRef.value) {
|
|
145
|
+
updateDropdownPosition()
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const updateDropdownPosition = () => {
|
|
151
|
+
if (!triggerRef.value) return
|
|
152
|
+
const rect = triggerRef.value.getBoundingClientRect()
|
|
153
|
+
dropdownStyle.value = {
|
|
154
|
+
top: `${rect.bottom + window.scrollY + 4}px`,
|
|
155
|
+
left: `${rect.left + window.scrollX}px`,
|
|
156
|
+
width: `${rect.width}px`
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
const handleSelect = (option: SelectOption) => {
|
|
161
|
+
if (props.multiple) {
|
|
162
|
+
const current = Array.isArray(props.modelValue) ? [...props.modelValue] : []
|
|
163
|
+
const index = current.indexOf(option.value)
|
|
164
|
+
if (index > -1) {
|
|
165
|
+
current.splice(index, 1)
|
|
166
|
+
} else {
|
|
167
|
+
current.push(option.value)
|
|
168
|
+
}
|
|
169
|
+
emit('update:modelValue', current)
|
|
170
|
+
emit('change', current)
|
|
171
|
+
} else {
|
|
172
|
+
emit('update:modelValue', option.value)
|
|
173
|
+
emit('change', option.value)
|
|
174
|
+
isOpen.value = false
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const handleNativeChange = (event: Event) => {
|
|
179
|
+
const target = event.target as HTMLSelectElement
|
|
180
|
+
emit('update:modelValue', target.value)
|
|
181
|
+
emit('change', target.value)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const handleClickOutside = (e: MouseEvent) => {
|
|
185
|
+
const target = e.target as HTMLElement
|
|
186
|
+
if (!target.closest('.datametria-select')) {
|
|
187
|
+
isOpen.value = false
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
onMounted(() => {
|
|
192
|
+
document.addEventListener('click', handleClickOutside)
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
onUnmounted(() => {
|
|
196
|
+
document.removeEventListener('click', handleClickOutside)
|
|
197
|
+
})
|
|
198
|
+
</script>
|
|
199
|
+
|
|
200
|
+
<style scoped>
|
|
201
|
+
.datametria-select__label {
|
|
202
|
+
display: block;
|
|
203
|
+
margin-bottom: 4px;
|
|
204
|
+
font-size: 14px;
|
|
205
|
+
font-weight: 500;
|
|
206
|
+
color: var(--dm-text-primary, #1f2937);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.datametria-select__required {
|
|
210
|
+
color: var(--dm-error, #ef4444);
|
|
211
|
+
margin-left: 2px;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
.datametria-select__error {
|
|
215
|
+
margin-top: 4px;
|
|
216
|
+
font-size: 12px;
|
|
217
|
+
color: var(--dm-error, #ef4444);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
.datametria-select {
|
|
221
|
+
position: relative;
|
|
222
|
+
width: 100%;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.datametria-select__trigger {
|
|
226
|
+
display: flex;
|
|
227
|
+
align-items: center;
|
|
228
|
+
justify-content: space-between;
|
|
229
|
+
padding: 8px 12px;
|
|
230
|
+
border: 1px solid var(--dm-border-color, #d1d5db);
|
|
231
|
+
border-radius: 6px;
|
|
232
|
+
background: var(--dm-bg-color, #fff);
|
|
233
|
+
cursor: pointer;
|
|
234
|
+
transition: all 0.2s;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.datametria-select__trigger:hover {
|
|
238
|
+
border-color: var(--dm-primary, #3b82f6);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.is-disabled .datametria-select__trigger {
|
|
242
|
+
opacity: 0.6;
|
|
243
|
+
cursor: not-allowed;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
.datametria-select__placeholder {
|
|
247
|
+
color: var(--dm-text-secondary, #9ca3af);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
.datametria-select__arrow {
|
|
251
|
+
font-size: 12px;
|
|
252
|
+
transition: transform 0.2s;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
.datametria-select__dropdown {
|
|
256
|
+
position: fixed;
|
|
257
|
+
z-index: 2000;
|
|
258
|
+
background: var(--dm-bg-color, #fff);
|
|
259
|
+
border: 1px solid var(--dm-border-color, #d1d5db);
|
|
260
|
+
border-radius: 6px;
|
|
261
|
+
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
|
262
|
+
max-height: 300px;
|
|
263
|
+
overflow: hidden;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
.datametria-select__filter {
|
|
267
|
+
width: 100%;
|
|
268
|
+
padding: 8px 12px;
|
|
269
|
+
border: none;
|
|
270
|
+
border-bottom: 1px solid var(--dm-border-color, #d1d5db);
|
|
271
|
+
outline: none;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
.datametria-select__options {
|
|
275
|
+
max-height: 250px;
|
|
276
|
+
overflow-y: auto;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
.datametria-select__option {
|
|
280
|
+
padding: 8px 12px;
|
|
281
|
+
cursor: pointer;
|
|
282
|
+
transition: background 0.2s;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.datametria-select__option:hover {
|
|
286
|
+
background: var(--dm-bg-hover, #f3f4f6);
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
.datametria-select__option.is-selected {
|
|
290
|
+
background: var(--dm-primary-light, #dbeafe);
|
|
291
|
+
color: var(--dm-primary, #3b82f6);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
.datametria-select__empty {
|
|
295
|
+
padding: 16px;
|
|
296
|
+
text-align: center;
|
|
297
|
+
color: var(--dm-text-secondary, #9ca3af);
|
|
298
|
+
}
|
|
36
299
|
|
|
37
|
-
|
|
38
|
-
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
|
300
|
+
/* Dark Mode Support - Hybrid Approach */
|
|
39
301
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
interface Props {
|
|
47
|
-
modelValue: any | any[]
|
|
48
|
-
options: SelectOption[]
|
|
49
|
-
placeholder?: string
|
|
50
|
-
disabled?: boolean
|
|
51
|
-
clearable?: boolean
|
|
52
|
-
filterable?: boolean
|
|
53
|
-
multiple?: boolean
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const props = withDefaults(defineProps<Props>(), {
|
|
57
|
-
placeholder: 'Selecione',
|
|
58
|
-
disabled: false,
|
|
59
|
-
clearable: false,
|
|
60
|
-
filterable: false,
|
|
61
|
-
multiple: false
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
const emit = defineEmits<{
|
|
65
|
-
'update:modelValue': [value: any]
|
|
66
|
-
'change': [value: any]
|
|
67
|
-
}>()
|
|
68
|
-
|
|
69
|
-
const isOpen = ref(false)
|
|
70
|
-
const filterText = ref('')
|
|
71
|
-
const dropdownStyle = ref({})
|
|
72
|
-
|
|
73
|
-
const displayValue = computed(() => {
|
|
74
|
-
if (props.multiple && Array.isArray(props.modelValue)) {
|
|
75
|
-
const labels = props.modelValue.map(v =>
|
|
76
|
-
props.options.find(o => o.value === v)?.label
|
|
77
|
-
).filter(Boolean)
|
|
78
|
-
return labels.join(', ')
|
|
79
|
-
}
|
|
80
|
-
return props.options.find(o => o.value === props.modelValue)?.label || ''
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
const filteredOptions = computed(() => {
|
|
84
|
-
if (!props.filterable || !filterText.value) return props.options
|
|
85
|
-
return props.options.filter(o =>
|
|
86
|
-
o.label.toLowerCase().includes(filterText.value.toLowerCase())
|
|
87
|
-
)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
const isSelected = (value: any) => {
|
|
91
|
-
if (props.multiple && Array.isArray(props.modelValue)) {
|
|
92
|
-
return props.modelValue.includes(value)
|
|
302
|
+
/* Fallback automático (sem JS) */
|
|
303
|
+
@media (prefers-color-scheme: dark) {
|
|
304
|
+
.datametria-select {
|
|
305
|
+
background: var(--dm-bg-color-dark, #1e1e1e);
|
|
306
|
+
color: var(--dm-text-primary-dark, #e0e0e0);
|
|
307
|
+
border-color: var(--dm-border-color-dark, #404040);
|
|
93
308
|
}
|
|
94
|
-
return props.modelValue === value
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const toggleDropdown = () => {
|
|
98
|
-
if (!props.disabled) {
|
|
99
|
-
isOpen.value = !isOpen.value
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const handleSelect = (option: SelectOption) => {
|
|
104
|
-
if (props.multiple) {
|
|
105
|
-
const current = Array.isArray(props.modelValue) ? [...props.modelValue] : []
|
|
106
|
-
const index = current.indexOf(option.value)
|
|
107
|
-
if (index > -1) {
|
|
108
|
-
current.splice(index, 1)
|
|
109
|
-
} else {
|
|
110
|
-
current.push(option.value)
|
|
111
|
-
}
|
|
112
|
-
emit('update:modelValue', current)
|
|
113
|
-
emit('change', current)
|
|
114
|
-
} else {
|
|
115
|
-
emit('update:modelValue', option.value)
|
|
116
|
-
emit('change', option.value)
|
|
117
|
-
isOpen.value = false
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const handleClickOutside = (e: MouseEvent) => {
|
|
122
|
-
const target = e.target as HTMLElement
|
|
123
|
-
if (!target.closest('.datametria-select')) {
|
|
124
|
-
isOpen.value = false
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
onMounted(() => {
|
|
129
|
-
document.addEventListener('click', handleClickOutside)
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
onUnmounted(() => {
|
|
133
|
-
document.removeEventListener('click', handleClickOutside)
|
|
134
|
-
})
|
|
135
|
-
</script>
|
|
136
|
-
|
|
137
|
-
<style scoped>
|
|
138
|
-
.datametria-select {
|
|
139
|
-
position: relative;
|
|
140
|
-
width: 100%;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
.datametria-select__trigger {
|
|
144
|
-
display: flex;
|
|
145
|
-
align-items: center;
|
|
146
|
-
justify-content: space-between;
|
|
147
|
-
padding: 8px 12px;
|
|
148
|
-
border: 1px solid var(--color-border, #d1d5db);
|
|
149
|
-
border-radius: 6px;
|
|
150
|
-
background: var(--color-background, #fff);
|
|
151
|
-
cursor: pointer;
|
|
152
|
-
transition: all 0.2s;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
.datametria-select__trigger:hover {
|
|
156
|
-
border-color: var(--color-primary, #3b82f6);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
.is-disabled .datametria-select__trigger {
|
|
160
|
-
opacity: 0.6;
|
|
161
|
-
cursor: not-allowed;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
.datametria-select__placeholder {
|
|
165
|
-
color: var(--color-text-secondary, #9ca3af);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
.datametria-select__arrow {
|
|
169
|
-
font-size: 12px;
|
|
170
|
-
transition: transform 0.2s;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
.datametria-select__dropdown {
|
|
174
|
-
position: fixed;
|
|
175
|
-
z-index: 2000;
|
|
176
|
-
background: var(--color-background, #fff);
|
|
177
|
-
border: 1px solid var(--color-border, #d1d5db);
|
|
178
|
-
border-radius: 6px;
|
|
179
|
-
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
|
180
|
-
max-height: 300px;
|
|
181
|
-
overflow: hidden;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
.datametria-select__filter {
|
|
185
|
-
width: 100%;
|
|
186
|
-
padding: 8px 12px;
|
|
187
|
-
border: none;
|
|
188
|
-
border-bottom: 1px solid var(--color-border, #d1d5db);
|
|
189
|
-
outline: none;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
.datametria-select__options {
|
|
193
|
-
max-height: 250px;
|
|
194
|
-
overflow-y: auto;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
.datametria-select__option {
|
|
198
|
-
padding: 8px 12px;
|
|
199
|
-
cursor: pointer;
|
|
200
|
-
transition: background 0.2s;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
.datametria-select__option:hover {
|
|
204
|
-
background: var(--color-background-hover, #f3f4f6);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
.datametria-select__option.is-selected {
|
|
208
|
-
background: var(--color-primary-light, #dbeafe);
|
|
209
|
-
color: var(--color-primary, #3b82f6);
|
|
210
309
|
}
|
|
211
310
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
color: var(--
|
|
311
|
+
/* Controle manual via useTheme() */
|
|
312
|
+
[data-theme="dark"] .datametria-select {
|
|
313
|
+
background: var(--dm-bg-color-dark, #1e1e1e);
|
|
314
|
+
color: var(--dm-text-primary-dark, #e0e0e0);
|
|
315
|
+
border-color: var(--dm-border-color-dark, #404040);
|
|
216
316
|
}
|
|
217
|
-
</style>
|
|
317
|
+
</style>
|