This repository has been archived by the owner on Mar 29, 2023. It is now read-only.
/
OfficeToggle.vue
60 lines (54 loc) · 2.05 KB
/
OfficeToggle.vue
1
2
3
4
5
6
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<template>
<div :class="classNames.root">
<OfficeLabel v-if="!!label" :for="id" :class="classNames.label">{{ label }}</OfficeLabel>
<div :class="classNames.container">
<button :class="classNames.pill"
:disabled="disabled"
:id="id"
@click="onClick"
role="switch"
type="button">
<div :class="classNames.thumb"></div>
</button>
<OfficeLabel v-if="!!stateText" :class="classNames.text">{{ stateText }}</OfficeLabel>
</div>
</div>
</template>
<script lang="ts">
import OfficeLabel from "../Label/OfficeLabel.vue";
import {getStyles} from "./OfficeToggle.styles";
import {IOfficeToggleProps} from "./OfficeToggle.types";
import {loadTheme} from "@s-bauer/uifabric-styling"
import {getId} from "@s-bauer/uifabric-utilities";
import {mergeStyleSets} from "@uifabric/merge-styles";
import {Component, Model, Prop, Vue} from "vue-property-decorator";
@Component({
components: {
OfficeLabel
}
})
export default class OfficeToggle extends Vue implements IOfficeToggleProps {
@Prop({type: Boolean, default: false}) public disabled!: boolean;
@Model("change", {type: Boolean, default: false}) public checked!: boolean;
@Prop({type: String}) public label?: string;
@Prop({type: String}) public onText?: string;
@Prop({type: String}) public offText?: string;
private id = getId("Toggle");
private get stateText() {
return this.checked ? this.onText : this.offText;
}
private get classNames() {
return mergeStyleSets(getStyles({
theme: loadTheme({}),
checked: this.checked,
disabled: this.disabled
}));
}
private onClick() {
if (!this.disabled) {
this.$emit("change", !this.checked);
this.$emit("click");
}
}
}
</script>