blob: e9a029c99316bb1919d0dd597528371756706f48 (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
<span
v-tooltip="checked ? i18n.ts.itsOn : i18n.ts.itsOff"
:class="{
[$style.button]: true,
[$style.buttonChecked]: checked,
[$style.buttonDisabled]: props.disabled
}"
data-cy-switch-toggle
@click.prevent.stop="toggle"
>
<div :class="{ [$style.knob]: true, [$style.knobChecked]: checked }"></div>
</span>
</template>
<script lang="ts" setup>
import { toRefs } from 'vue';
import type { Ref } from 'vue';
import { i18n } from '@/i18n.js';
const props = withDefaults(defineProps<{
checked: boolean | Ref<boolean>;
disabled?: boolean | Ref<boolean>;
}>(), {
disabled: false,
});
const emit = defineEmits<{
(ev: 'toggle'): void;
}>();
const checked = toRefs(props).checked;
const toggle = () => {
emit('toggle');
};
</script>
<style lang="scss" module>
.button {
--height: 21px;
position: relative;
display: inline-flex;
flex-shrink: 0;
margin: 0;
box-sizing: border-box;
width: calc(var(--height) * 1.6);
height: calc(var(--height) + 2px); // 枠線
outline: none;
background: var(--MI_THEME-switchOffBg);
background-clip: content-box;
border: solid 1px var(--MI_THEME-switchOffBg);
border-radius: var(--MI-radius-ellipse);
cursor: pointer;
transition: inherit;
user-select: none;
}
.buttonChecked {
background-color: var(--MI_THEME-switchOnBg) !important;
border-color: var(--MI_THEME-switchOnBg) !important;
}
.buttonDisabled {
cursor: not-allowed;
}
.knob {
position: absolute;
box-sizing: border-box;
top: 3px;
width: calc(var(--height) - 6px);
height: calc(var(--height) - 6px);
border-radius: var(--MI-radius-ellipse);
transition: all 0.2s ease;
&:not(.knobChecked) {
left: 3px;
background: var(--MI_THEME-switchOffFg);
}
}
.knobChecked {
left: calc(calc(100% - var(--height)) + 3px);
background: var(--MI_THEME-switchOnFg);
}
</style>
|