mirror of
https://github.com/bastienwirtz/homer.git
synced 2026-02-21 05:46:52 +01:00
47 lines
950 B
Vue
47 lines
950 B
Vue
<template>
|
|
<a
|
|
class="navbar-item is-inline-block-mobile"
|
|
@click.prevent="toggleSetting()"
|
|
>
|
|
<span><i :class="['fas', 'fa-fw', value ? icon : secondaryIcon]"></i></span>
|
|
<slot></slot>
|
|
</a>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
name: "SettingToggle",
|
|
props: {
|
|
name: String,
|
|
icon: String,
|
|
iconAlt: String,
|
|
defaultValue: Boolean,
|
|
},
|
|
emits: ["updated"],
|
|
data: function () {
|
|
return {
|
|
secondaryIcon: null,
|
|
value: true,
|
|
};
|
|
},
|
|
created: function () {
|
|
this.secondaryIcon = this.iconAlt || this.icon;
|
|
|
|
if (this.name in localStorage) {
|
|
this.value = JSON.parse(localStorage[this.name]);
|
|
} else {
|
|
this.value = this.defaultValue;
|
|
}
|
|
|
|
this.$emit("updated", this.value);
|
|
},
|
|
methods: {
|
|
toggleSetting: function () {
|
|
this.value = !this.value;
|
|
localStorage[this.name] = this.value;
|
|
this.$emit("updated", this.value);
|
|
},
|
|
},
|
|
};
|
|
</script>
|