2023-07-27 08:31:52 +03:00
|
|
|
<!--
|
2024-02-13 17:59:27 +02:00
|
|
|
SPDX-FileCopyrightText: syuilo and misskey-project
|
2023-07-27 08:31:52 +03:00
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-11-25 14:31:34 +02:00
|
|
|
<template>
|
2023-12-10 10:53:38 +02:00
|
|
|
<div :class="[$style.root, { [$style.disabled]: disabled }]">
|
2021-09-29 18:50:45 +03:00
|
|
|
<input
|
|
|
|
ref="input"
|
2021-11-19 12:36:12 +02:00
|
|
|
type="checkbox"
|
2021-09-29 18:50:45 +03:00
|
|
|
:disabled="disabled"
|
2023-05-10 11:53:01 +03:00
|
|
|
:class="$style.input"
|
2021-09-29 18:50:45 +03:00
|
|
|
@keydown.enter="toggle"
|
2020-11-25 14:31:34 +02:00
|
|
|
>
|
2023-08-13 14:12:29 +03:00
|
|
|
<XButton :checked="checked" :disabled="disabled" @toggle="toggle"/>
|
2023-05-10 11:53:01 +03:00
|
|
|
<span :class="$style.body">
|
2021-12-30 14:47:48 +02:00
|
|
|
<!-- TODO: 無名slotの方は廃止 -->
|
2023-08-13 14:12:29 +03:00
|
|
|
<span :class="$style.label">
|
|
|
|
<span @click="toggle">
|
|
|
|
<slot name="label"></slot><slot></slot>
|
|
|
|
</span>
|
2023-09-30 22:53:52 +03:00
|
|
|
<span v-if="helpText" v-tooltip:dialog="helpText" class="_button _help" :class="$style.help"><i class="ph-question ph-bold ph-lg"></i></span>
|
2023-08-13 14:12:29 +03:00
|
|
|
</span>
|
2023-05-10 11:53:01 +03:00
|
|
|
<p :class="$style.caption"><slot name="caption"></slot></p>
|
2021-09-29 18:50:45 +03:00
|
|
|
</span>
|
2020-11-25 14:31:34 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-30 07:11:52 +02:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { toRefs, Ref } from 'vue';
|
2023-08-01 09:32:03 +03:00
|
|
|
import XButton from '@/components/MkSwitch.button.vue';
|
2020-11-25 14:31:34 +02:00
|
|
|
|
2022-01-30 07:11:52 +02:00
|
|
|
const props = defineProps<{
|
|
|
|
modelValue: boolean | Ref<boolean>;
|
|
|
|
disabled?: boolean;
|
2023-08-13 14:12:29 +03:00
|
|
|
helpText?: string;
|
2022-01-30 07:11:52 +02:00
|
|
|
}>();
|
2021-12-27 15:59:14 +02:00
|
|
|
|
2022-01-30 07:11:52 +02:00
|
|
|
const emit = defineEmits<{
|
2022-05-26 16:53:09 +03:00
|
|
|
(ev: 'update:modelValue', v: boolean): void;
|
2022-01-30 07:11:52 +02:00
|
|
|
}>();
|
2021-12-27 15:59:14 +02:00
|
|
|
|
2022-01-30 07:11:52 +02:00
|
|
|
const checked = toRefs(props).modelValue;
|
|
|
|
const toggle = () => {
|
|
|
|
if (props.disabled) return;
|
|
|
|
emit('update:modelValue', !checked.value);
|
|
|
|
};
|
2020-11-25 14:31:34 +02:00
|
|
|
</script>
|
|
|
|
|
2023-05-10 11:53:01 +03:00
|
|
|
<style lang="scss" module>
|
|
|
|
.root {
|
2021-09-29 18:50:45 +03:00
|
|
|
position: relative;
|
|
|
|
display: flex;
|
2021-12-27 15:59:14 +02:00
|
|
|
transition: all 0.2s ease;
|
2023-05-10 11:53:01 +03:00
|
|
|
user-select: none;
|
2021-12-25 18:42:50 +02:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
> .button {
|
|
|
|
border-color: var(--inputBorderHover) !important;
|
2020-11-25 14:31:34 +02:00
|
|
|
}
|
2021-09-29 18:50:45 +03:00
|
|
|
}
|
2020-11-25 14:31:34 +02:00
|
|
|
|
2021-09-29 18:50:45 +03:00
|
|
|
&.disabled {
|
|
|
|
opacity: 0.6;
|
|
|
|
cursor: not-allowed;
|
|
|
|
}
|
2020-11-25 14:31:34 +02:00
|
|
|
}
|
2023-05-10 11:53:01 +03:00
|
|
|
|
|
|
|
.input {
|
|
|
|
position: absolute;
|
|
|
|
width: 0;
|
|
|
|
height: 0;
|
|
|
|
opacity: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
|
|
|
.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;
|
|
|
|
}
|
|
|
|
}
|
2023-08-13 14:12:29 +03:00
|
|
|
|
|
|
|
.help {
|
|
|
|
margin-left: 0.5em;
|
|
|
|
font-size: 85%;
|
|
|
|
vertical-align: top;
|
|
|
|
}
|
2020-11-25 14:31:34 +02:00
|
|
|
</style>
|