2023-08-01 08:32:03 +02:00
|
|
|
<!--
|
2024-02-13 16:59:27 +01:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-08-01 08:32:03 +02:00
|
|
|
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, Ref } from 'vue';
|
2023-09-19 09:37:43 +02:00
|
|
|
import { i18n } from '@/i18n.js';
|
2023-08-01 08:32:03 +02:00
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
checked: boolean | Ref<boolean>;
|
2024-01-30 11:53:53 +01:00
|
|
|
disabled?: boolean | Ref<boolean>;
|
2023-08-01 08:32:03 +02:00
|
|
|
}>(), {
|
|
|
|
disabled: false,
|
|
|
|
});
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
|
(ev: 'toggle'): void;
|
|
|
|
}>();
|
|
|
|
|
|
|
|
const checked = toRefs(props).checked;
|
|
|
|
const toggle = () => {
|
|
|
|
emit('toggle');
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.button {
|
2024-03-30 08:02:03 +01:00
|
|
|
--height: 21px;
|
|
|
|
|
2023-08-01 08:32:03 +02:00
|
|
|
position: relative;
|
|
|
|
display: inline-flex;
|
|
|
|
flex-shrink: 0;
|
|
|
|
margin: 0;
|
|
|
|
box-sizing: border-box;
|
2024-03-30 08:02:03 +01:00
|
|
|
width: calc(var(--height) * 1.6);
|
|
|
|
height: calc(var(--height) + 2px); // 枠線
|
2023-08-01 08:32:03 +02:00
|
|
|
outline: none;
|
|
|
|
background: var(--switchOffBg);
|
|
|
|
background-clip: content-box;
|
|
|
|
border: solid 1px var(--switchOffBg);
|
2023-10-31 19:44:34 +01:00
|
|
|
border-radius: var(--radius-ellipse);
|
2023-08-01 08:32:03 +02:00
|
|
|
cursor: pointer;
|
|
|
|
transition: inherit;
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.buttonChecked {
|
|
|
|
background-color: var(--switchOnBg) !important;
|
|
|
|
border-color: var(--switchOnBg) !important;
|
|
|
|
}
|
|
|
|
|
|
|
|
.buttonDisabled {
|
|
|
|
cursor: not-allowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
.knob {
|
|
|
|
position: absolute;
|
2024-03-30 08:02:03 +01:00
|
|
|
box-sizing: border-box;
|
2023-08-01 08:32:03 +02:00
|
|
|
top: 3px;
|
2024-03-30 08:02:03 +01:00
|
|
|
width: calc(var(--height) - 6px);
|
|
|
|
height: calc(var(--height) - 6px);
|
2023-10-31 19:44:34 +01:00
|
|
|
border-radius: var(--radius-ellipse);
|
2023-08-01 08:32:03 +02:00
|
|
|
transition: all 0.2s ease;
|
|
|
|
|
|
|
|
&:not(.knobChecked) {
|
|
|
|
left: 3px;
|
|
|
|
background: var(--switchOffFg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.knobChecked {
|
2024-03-30 08:02:03 +01:00
|
|
|
left: calc(calc(100% - var(--height)) + 3px);
|
2023-08-01 08:32:03 +02:00
|
|
|
background: var(--switchOnFg);
|
|
|
|
}
|
|
|
|
</style>
|