@energysage/es-ds-components 3.3.2 → 3.4.0
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 +7 -0
- package/components/es-dropdown-select.vue +241 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [3.4.0](https://github.com/EnergySage/es-ds/compare/es-ds-components-v3.3.2...es-ds-components-v3.4.0) (2025-08-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* create es-dropdown ([#1642](https://github.com/EnergySage/es-ds/issues/1642)) ([bcf8860](https://github.com/EnergySage/es-ds/commit/bcf886075b0b6c9b2d0724616124b01a12a74550))
|
|
9
|
+
|
|
3
10
|
## [3.3.2](https://github.com/EnergySage/es-ds/compare/es-ds-components-v3.3.1...es-ds-components-v3.3.2) (2025-08-06)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import Dropdown from 'primevue/dropdown';
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
label?: string;
|
|
7
|
+
modelValue?: any;
|
|
8
|
+
options?: string[] | { label: string; value: string }[];
|
|
9
|
+
placeholder?: string;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
state?: boolean | null;
|
|
12
|
+
}
|
|
13
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
14
|
+
disabled: false,
|
|
15
|
+
modelValue: undefined,
|
|
16
|
+
options: () => [],
|
|
17
|
+
placeholder: '',
|
|
18
|
+
label: '',
|
|
19
|
+
required: false,
|
|
20
|
+
state: null,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const slots = useSlots();
|
|
24
|
+
const hasError = () => !!slots.errorMessage;
|
|
25
|
+
|
|
26
|
+
const emit = defineEmits(['update:modelValue']);
|
|
27
|
+
|
|
28
|
+
const isOpen = ref(false);
|
|
29
|
+
const isFocused = ref(false);
|
|
30
|
+
const isInputClicked = ref(false);
|
|
31
|
+
const isLabelClicked = ref(false);
|
|
32
|
+
|
|
33
|
+
const isSelected = (option: any) => option === props.modelValue;
|
|
34
|
+
|
|
35
|
+
const id = useId();
|
|
36
|
+
const labelId = useId();
|
|
37
|
+
|
|
38
|
+
const blur = () => {
|
|
39
|
+
if (!isOpen.value && (isInputClicked.value || isLabelClicked.value)) {
|
|
40
|
+
isInputClicked.value = false;
|
|
41
|
+
isLabelClicked.value = false;
|
|
42
|
+
}
|
|
43
|
+
isFocused.value = false;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const hide = () => {
|
|
47
|
+
isOpen.value = false;
|
|
48
|
+
|
|
49
|
+
if (!isFocused.value) {
|
|
50
|
+
isInputClicked.value = false;
|
|
51
|
+
isLabelClicked.value = false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
</script>
|
|
55
|
+
|
|
56
|
+
<template>
|
|
57
|
+
<div
|
|
58
|
+
class="input-wrapper justify-content-end"
|
|
59
|
+
:class="$attrs.class">
|
|
60
|
+
<label
|
|
61
|
+
:id="labelId"
|
|
62
|
+
:for="id"
|
|
63
|
+
:class="{ 'sr-only': !label }"
|
|
64
|
+
@click="isLabelClicked = true">
|
|
65
|
+
{{ label || 'Select an option' }}
|
|
66
|
+
<span
|
|
67
|
+
v-if="required && label !== ''"
|
|
68
|
+
class="text-danger">
|
|
69
|
+
*
|
|
70
|
+
</span>
|
|
71
|
+
</label>
|
|
72
|
+
<dropdown
|
|
73
|
+
:input-id="id"
|
|
74
|
+
:class="[
|
|
75
|
+
'es-dropdown es-form-input form-control d-flex align-items-center justify-content-between',
|
|
76
|
+
{
|
|
77
|
+
disabled: disabled,
|
|
78
|
+
focused: isFocused && !isInputClicked && !isOpen && !isLabelClicked,
|
|
79
|
+
'focused-on-click': isOpen || isLabelClicked || isInputClicked,
|
|
80
|
+
'is-invalid': state === false,
|
|
81
|
+
},
|
|
82
|
+
]"
|
|
83
|
+
:aria-labelledby="labelId"
|
|
84
|
+
:disabled="disabled"
|
|
85
|
+
:focus-on-hover="false"
|
|
86
|
+
:model-value="modelValue"
|
|
87
|
+
:option-label="options.length > 0 && typeof options[0] === 'object' ? 'label' : undefined"
|
|
88
|
+
:options="options"
|
|
89
|
+
:placeholder="placeholder"
|
|
90
|
+
:pt="{
|
|
91
|
+
panel: { class: 'es-dropdown-panel bg-white rounded-xs' },
|
|
92
|
+
wrapper: { class: 'es-dropdown-wrapper' },
|
|
93
|
+
list: { class: 'p-0 m-0 list-unstyled' },
|
|
94
|
+
input: {
|
|
95
|
+
class: [
|
|
96
|
+
'es-dropdown-input',
|
|
97
|
+
{
|
|
98
|
+
'es-dropdown-input--placeholder': modelValue === undefined && state !== false,
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
},
|
|
102
|
+
item: {
|
|
103
|
+
class: [
|
|
104
|
+
'es-dropdown-item d-flex justify-content-between p-100 pl-200',
|
|
105
|
+
{
|
|
106
|
+
'input-focused position-relative': isFocused && !isInputClicked && !isLabelClicked,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
}"
|
|
111
|
+
scroll-height="15.75rem"
|
|
112
|
+
@update:model-value="emit('update:modelValue', $event)"
|
|
113
|
+
@blur="blur"
|
|
114
|
+
@focus="isFocused = true"
|
|
115
|
+
@click="isInputClicked = true"
|
|
116
|
+
@hide="hide"
|
|
117
|
+
@show="isOpen = true">
|
|
118
|
+
<template #dropdownicon>
|
|
119
|
+
<icon-chevron-down
|
|
120
|
+
aria-hidden="true"
|
|
121
|
+
height="1.125rem"
|
|
122
|
+
:class="[
|
|
123
|
+
{
|
|
124
|
+
'text-gray-500': disabled,
|
|
125
|
+
'text-gray-900': !disabled && state !== false,
|
|
126
|
+
},
|
|
127
|
+
]" />
|
|
128
|
+
</template>
|
|
129
|
+
<template #option="slotProps">
|
|
130
|
+
<span>{{ slotProps.option.label ? slotProps.option.label : slotProps.option }}</span>
|
|
131
|
+
<icon-check
|
|
132
|
+
v-if="isSelected(slotProps.option)"
|
|
133
|
+
height="1.5rem"
|
|
134
|
+
class="text-gray-700" />
|
|
135
|
+
</template>
|
|
136
|
+
</dropdown>
|
|
137
|
+
<small
|
|
138
|
+
v-if="state === false && (hasError() || required)"
|
|
139
|
+
class="text-danger">
|
|
140
|
+
<slot
|
|
141
|
+
v-if="hasError()"
|
|
142
|
+
name="errorMessage" />
|
|
143
|
+
<template v-else-if="required"> This field is required. </template>
|
|
144
|
+
</small>
|
|
145
|
+
</div>
|
|
146
|
+
</template>
|
|
147
|
+
|
|
148
|
+
<style lang="scss">
|
|
149
|
+
@use '@energysage/es-ds-styles/scss/variables' as variables;
|
|
150
|
+
|
|
151
|
+
.es-dropdown {
|
|
152
|
+
user-select: none;
|
|
153
|
+
|
|
154
|
+
&:hover,
|
|
155
|
+
&:active,
|
|
156
|
+
&.focused-on-click {
|
|
157
|
+
border-color: variables.$blue-300;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
&.focused {
|
|
161
|
+
border-color: variables.$blue-600;
|
|
162
|
+
outline: 0.125rem solid variables.$blue-600;
|
|
163
|
+
outline-offset: 0.125rem;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.es-dropdown-input {
|
|
167
|
+
&:focus-visible {
|
|
168
|
+
outline: 0;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
&--placeholder {
|
|
172
|
+
color: variables.$input-color-placeholder;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
&:disabled,
|
|
177
|
+
&.disabled {
|
|
178
|
+
background-color: variables.$gray-50;
|
|
179
|
+
border-color: variables.$gray-500;
|
|
180
|
+
cursor: not-allowed;
|
|
181
|
+
.es-dropdown-input {
|
|
182
|
+
color: variables.$gray-500;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
.es-dropdown-panel {
|
|
188
|
+
border: variables.$border-width solid variables.$gray-500;
|
|
189
|
+
box-shadow: variables.$popover-box-shadow;
|
|
190
|
+
overflow: hidden;
|
|
191
|
+
|
|
192
|
+
// matched animation to PrimeVue styled mode
|
|
193
|
+
&.p-connected-overlay-enter-from {
|
|
194
|
+
opacity: 0;
|
|
195
|
+
transform: scaleY(0.8);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
&.p-connected-overlay-enter-active {
|
|
199
|
+
transition:
|
|
200
|
+
transform 0.12s cubic-bezier(0, 0, 0.2, 1),
|
|
201
|
+
opacity 0.12s cubic-bezier(0, 0, 0.2, 1);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
&.p-connected-overlay-leave-active {
|
|
205
|
+
transition: opacity 0.1s linear;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
&.p-connected-overlay-leave-to {
|
|
209
|
+
opacity: 0;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.es-dropdown-wrapper {
|
|
214
|
+
overflow-y: auto;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.es-dropdown-item {
|
|
218
|
+
cursor: pointer;
|
|
219
|
+
transition: background-color 0.15s ease-in-out;
|
|
220
|
+
|
|
221
|
+
&:hover,
|
|
222
|
+
&:not(.input-focused)[data-p-focused='true'] {
|
|
223
|
+
background-color: variables.$blue-50;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
&.input-focused[data-p-focused='true']::after {
|
|
227
|
+
border: 2px solid variables.$blue-600;
|
|
228
|
+
border-radius: variables.$border-radius-xs;
|
|
229
|
+
bottom: 2px;
|
|
230
|
+
content: '';
|
|
231
|
+
left: 2px;
|
|
232
|
+
position: absolute;
|
|
233
|
+
right: 2px;
|
|
234
|
+
top: 2px;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
&:active {
|
|
238
|
+
background-color: variables.$blue-100;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
</style>
|