2023-07-27 07:31:52 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-11-25 13:31:34 +01:00
|
|
|
<template>
|
2023-05-10 10:53:01 +02:00
|
|
|
<div :class="[$style.root, { [$style.disabled]: disabled, [$style.checked]: checked }]">
|
2021-09-29 17:50:45 +02:00
|
|
|
<input
|
|
|
|
ref="input"
|
2021-11-19 11:36:12 +01:00
|
|
|
type="checkbox"
|
2021-09-29 17:50:45 +02:00
|
|
|
:disabled="disabled"
|
2023-05-10 10:53:01 +02:00
|
|
|
:class="$style.input"
|
2021-09-29 17:50:45 +02:00
|
|
|
@keydown.enter="toggle"
|
2020-11-25 13:31:34 +01:00
|
|
|
>
|
2023-05-10 10:53:01 +02:00
|
|
|
<span ref="button" v-tooltip="checked ? i18n.ts.itsOn : i18n.ts.itsOff" :class="$style.button" data-cy-switch-toggle @click.prevent="toggle">
|
|
|
|
<div :class="$style.knob"></div>
|
2021-09-29 17:50:45 +02:00
|
|
|
</span>
|
2023-05-10 10:53:01 +02:00
|
|
|
<span :class="$style.body">
|
2021-12-30 13:47:48 +01:00
|
|
|
<!-- TODO: 無名slotの方は廃止 -->
|
2023-05-10 10:53:01 +02:00
|
|
|
<span :class="$style.label" @click="toggle"><slot name="label"></slot><slot></slot></span>
|
|
|
|
<p :class="$style.caption"><slot name="caption"></slot></p>
|
2021-09-29 17:50:45 +02:00
|
|
|
</span>
|
2020-11-25 13:31:34 +01:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-30 06:11:52 +01:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { toRefs, Ref } from 'vue';
|
2022-07-20 15:24:26 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-01-30 06:11:52 +01:00
|
|
|
const props = defineProps<{
|
|
|
|
modelValue: boolean | Ref<boolean>;
|
|
|
|
disabled?: boolean;
|
|
|
|
}>();
|
2021-12-27 14:59:14 +01:00
|
|
|
|
2022-01-30 06:11:52 +01:00
|
|
|
const emit = defineEmits<{
|
2022-05-26 15:53:09 +02:00
|
|
|
(ev: 'update:modelValue', v: boolean): void;
|
2022-01-30 06:11:52 +01:00
|
|
|
}>();
|
2021-12-27 14:59:14 +01:00
|
|
|
|
2023-01-03 02:12:37 +01:00
|
|
|
let button = $shallowRef<HTMLElement>();
|
2022-01-30 06:11:52 +01:00
|
|
|
const checked = toRefs(props).modelValue;
|
|
|
|
const toggle = () => {
|
|
|
|
if (props.disabled) return;
|
|
|
|
emit('update:modelValue', !checked.value);
|
2021-12-27 14:59:14 +01:00
|
|
|
|
2022-01-30 06:11:52 +01:00
|
|
|
if (!checked.value) {
|
2022-06-26 09:38:27 +02:00
|
|
|
|
2022-01-30 06:11:52 +01:00
|
|
|
}
|
|
|
|
};
|
2020-11-25 13:31:34 +01:00
|
|
|
</script>
|
|
|
|
|
2023-05-10 10:53:01 +02:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2021-09-29 17:50:45 +02:00
|
|
|
position: relative;
|
|
|
|
display: flex;
|
2021-12-27 14:59:14 +01:00
|
|
|
transition: all 0.2s ease;
|
2023-05-10 10:53:01 +02:00
|
|
|
user-select: none;
|
2021-12-25 17:42:50 +01:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
> .button {
|
|
|
|
border-color: var(--inputBorderHover) !important;
|
2020-11-25 13:31:34 +01:00
|
|
|
}
|
2021-09-29 17:50:45 +02:00
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2021-09-29 17:50:45 +02:00
|
|
|
&.disabled {
|
|
|
|
opacity: 0.6;
|
|
|
|
cursor: not-allowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.checked {
|
|
|
|
> .button {
|
2023-01-07 07:00:29 +01:00
|
|
|
background-color: var(--switchOnBg) !important;
|
|
|
|
border-color: var(--switchOnBg) !important;
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2022-06-26 09:38:27 +02:00
|
|
|
> .knob {
|
|
|
|
left: 12px;
|
2023-01-07 07:00:29 +01:00
|
|
|
background: var(--switchOnFg);
|
2020-11-25 13:31:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-10 10:53:01 +02:00
|
|
|
|
|
|
|
.input {
|
|
|
|
position: absolute;
|
|
|
|
width: 0;
|
|
|
|
height: 0;
|
|
|
|
opacity: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.button {
|
|
|
|
position: relative;
|
|
|
|
display: inline-flex;
|
|
|
|
flex-shrink: 0;
|
|
|
|
margin: 0;
|
|
|
|
box-sizing: border-box;
|
|
|
|
width: 32px;
|
|
|
|
height: 23px;
|
|
|
|
outline: none;
|
|
|
|
background: var(--switchOffBg);
|
|
|
|
background-clip: content-box;
|
|
|
|
border: solid 1px var(--switchOffBg);
|
|
|
|
border-radius: 999px;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: inherit;
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.knob {
|
|
|
|
position: absolute;
|
|
|
|
top: 3px;
|
|
|
|
left: 3px;
|
|
|
|
width: 15px;
|
|
|
|
height: 15px;
|
|
|
|
background: var(--switchOffFg);
|
|
|
|
border-radius: 999px;
|
|
|
|
transition: all 0.2s ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
.body {
|
|
|
|
margin-left: 12px;
|
|
|
|
margin-top: 2px;
|
|
|
|
display: block;
|
|
|
|
transition: inherit;
|
|
|
|
color: var(--fg);
|
|
|
|
}
|
|
|
|
|
|
|
|
.label {
|
|
|
|
display: block;
|
|
|
|
line-height: 20px;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: inherit;
|
|
|
|
}
|
|
|
|
|
|
|
|
.caption {
|
|
|
|
margin: 8px 0 0 0;
|
|
|
|
color: var(--fgTransparentWeak);
|
|
|
|
font-size: 0.85em;
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 13:31:34 +01:00
|
|
|
</style>
|