forked from evcc-io/evcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'evcc-io:master' into master
- Loading branch information
Showing
69 changed files
with
1,485 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
<template> | ||
<div> | ||
<button | ||
class="form-select text-start text-nowrap" | ||
type="button" | ||
:id="id" | ||
data-bs-toggle="dropdown" | ||
aria-expanded="false" | ||
data-bs-auto-close="outside" | ||
> | ||
<slot></slot> | ||
</button> | ||
<ul class="dropdown-menu dropdown-menu-end" ref="dropdown" :aria-labelledby="id"> | ||
<template v-if="selectAllLabel"> | ||
<li class="dropdown-item p-0"> | ||
<label class="form-check px-3 py-2"> | ||
<input | ||
class="form-check-input ms-0 me-2" | ||
type="checkbox" | ||
value="all" | ||
@change="toggleCheckAll()" | ||
:checked="allOptionsSelected" | ||
/> | ||
<div class="form-check-label">{{ selectAllLabel }}</div> | ||
</label> | ||
</li> | ||
<li><hr class="dropdown-divider" /></li> | ||
</template> | ||
<li v-for="option in options" :key="option.value" class="dropdown-item p-0"> | ||
<label class="form-check px-3 py-2 d-flex" :for="option.value"> | ||
<input | ||
class="form-check-input ms-0 me-2" | ||
type="checkbox" | ||
:id="option.value" | ||
:value="option.value" | ||
v-model="internalValue" | ||
/> | ||
<div class="form-check-label"> | ||
{{ option.name }} | ||
</div> | ||
</label> | ||
</li> | ||
</ul> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Dropdown from "bootstrap/js/dist/dropdown"; | ||
export default { | ||
name: "MultiSelect", | ||
props: { | ||
id: String, | ||
value: { type: Array, default: () => [] }, | ||
options: { type: Array, default: () => [] }, | ||
selectAllLabel: String, | ||
}, | ||
emits: ["open", "update:modelValue"], | ||
data() { | ||
return { | ||
internalValue: [...this.value], | ||
}; | ||
}, | ||
mounted() { | ||
this.$refs.dropdown.addEventListener("show.bs.dropdown", this.open); | ||
}, | ||
unmounted() { | ||
this.$refs.dropdown?.removeEventListener("show.bs.dropdown", this.open); | ||
}, | ||
computed: { | ||
allOptionsSelected() { | ||
return this.internalValue.length === this.options.length; | ||
}, | ||
noneSelected() { | ||
return this.internalValue.length === 0; | ||
}, | ||
}, | ||
watch: { | ||
options: { | ||
immediate: true, | ||
handler(newOptions) { | ||
// If value is empty, set internalValue to include all options | ||
if (this.value.length === 0) { | ||
this.internalValue = newOptions.map((option) => option.value); | ||
} else { | ||
// Otherwise, keep selected options that still exist in the new options | ||
this.internalValue = this.internalValue.filter((value) => | ||
newOptions.some((option) => option.value === value) | ||
); | ||
} | ||
this.$nextTick(() => { | ||
Dropdown.getOrCreateInstance(this.$refs.dropdown).update(); | ||
}); | ||
}, | ||
}, | ||
value: { | ||
immediate: true, | ||
handler(newValue) { | ||
this.internalValue = | ||
newValue.length === 0 && this.options.length > 0 | ||
? this.options.map((o) => o.value) | ||
: [...newValue]; | ||
}, | ||
}, | ||
internalValue(newValue) { | ||
if (this.allOptionsSelected || this.noneSelected) { | ||
this.$emit("update:modelValue", []); | ||
} else { | ||
this.$emit("update:modelValue", newValue); | ||
} | ||
}, | ||
}, | ||
methods: { | ||
open() { | ||
this.$emit("open"); | ||
}, | ||
toggleCheckAll() { | ||
if (this.allOptionsSelected) { | ||
this.internalValue = []; | ||
} else { | ||
this.internalValue = this.options.map((option) => option.value); | ||
} | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.