2020-11-25 14:31:34 +02:00
|
|
|
<template>
|
2021-09-29 18:50:45 +03:00
|
|
|
<div
|
2022-06-26 10:38:27 +03:00
|
|
|
class="ziffeomt"
|
2021-09-29 18:50:45 +03:00
|
|
|
:class="{ disabled, checked }"
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
ref="input"
|
2021-11-19 12:36:12 +02:00
|
|
|
type="checkbox"
|
2021-09-29 18:50:45 +03:00
|
|
|
:disabled="disabled"
|
|
|
|
@keydown.enter="toggle"
|
2020-11-25 14:31:34 +02:00
|
|
|
>
|
2022-07-20 16:24:26 +03:00
|
|
|
<span ref="button" v-tooltip="checked ? i18n.ts.itsOn : i18n.ts.itsOff" class="button" @click.prevent="toggle">
|
2022-06-26 10:38:27 +03:00
|
|
|
<div class="knob"></div>
|
2021-09-29 18:50:45 +03:00
|
|
|
</span>
|
|
|
|
<span class="label">
|
2021-12-30 14:47:48 +02:00
|
|
|
<!-- TODO: 無名slotの方は廃止 -->
|
|
|
|
<span @click="toggle"><slot name="label"></slot><slot></slot></span>
|
2021-11-28 13:07:37 +02:00
|
|
|
<p class="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';
|
2021-12-27 15:59:14 +02:00
|
|
|
import * as os from '@/os';
|
2022-07-20 16:24:26 +03:00
|
|
|
import { i18n } from '@/i18n';
|
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;
|
|
|
|
}>();
|
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
|
|
|
|
2023-01-03 03:12:37 +02:00
|
|
|
let button = $shallowRef<HTMLElement>();
|
2022-01-30 07:11:52 +02:00
|
|
|
const checked = toRefs(props).modelValue;
|
|
|
|
const toggle = () => {
|
|
|
|
if (props.disabled) return;
|
|
|
|
emit('update:modelValue', !checked.value);
|
2021-12-27 15:59:14 +02:00
|
|
|
|
2022-01-30 07:11:52 +02:00
|
|
|
if (!checked.value) {
|
2022-06-26 10:38:27 +03:00
|
|
|
|
2022-01-30 07:11:52 +02:00
|
|
|
}
|
|
|
|
};
|
2020-11-25 14:31:34 +02:00
|
|
|
</script>
|
|
|
|
|
2022-12-27 11:29:39 +02:00
|
|
|
<style lang="scss" scoped>
|
2022-06-26 10:38:27 +03:00
|
|
|
.ziffeomt {
|
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;
|
2021-09-29 18:50:45 +03:00
|
|
|
|
|
|
|
> * {
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
> input {
|
|
|
|
position: absolute;
|
|
|
|
width: 0;
|
|
|
|
height: 0;
|
|
|
|
opacity: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
2020-11-25 14:31:34 +02:00
|
|
|
|
2021-09-29 18:50:45 +03:00
|
|
|
> .button {
|
|
|
|
position: relative;
|
2021-12-25 18:42:50 +02:00
|
|
|
display: inline-flex;
|
2021-09-29 18:50:45 +03:00
|
|
|
flex-shrink: 0;
|
|
|
|
margin: 0;
|
2021-12-25 18:42:50 +02:00
|
|
|
box-sizing: border-box;
|
2022-06-26 10:38:27 +03:00
|
|
|
width: 32px;
|
2021-12-25 18:42:50 +02:00
|
|
|
height: 23px;
|
2021-09-29 18:50:45 +03:00
|
|
|
outline: none;
|
2023-01-07 08:00:29 +02:00
|
|
|
background: var(--switchOffBg);
|
2022-06-26 10:38:27 +03:00
|
|
|
background-clip: content-box;
|
2023-01-07 08:00:29 +02:00
|
|
|
border: solid 1px var(--switchOffBg);
|
2022-06-26 10:38:27 +03:00
|
|
|
border-radius: 999px;
|
2021-12-25 18:42:50 +02:00
|
|
|
cursor: pointer;
|
2021-09-29 18:50:45 +03:00
|
|
|
transition: inherit;
|
2022-06-27 18:20:51 +03:00
|
|
|
user-select: none;
|
2021-09-29 18:50:45 +03:00
|
|
|
|
2022-06-26 10:38:27 +03:00
|
|
|
> .knob {
|
|
|
|
position: absolute;
|
|
|
|
top: 3px;
|
|
|
|
left: 3px;
|
|
|
|
width: 15px;
|
|
|
|
height: 15px;
|
2023-01-07 08:00:29 +02:00
|
|
|
background: var(--switchOffFg);
|
2022-06-26 10:38:27 +03:00
|
|
|
border-radius: 999px;
|
2021-12-27 15:59:14 +02:00
|
|
|
transition: all 0.2s ease;
|
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
|
|
|
> .label {
|
2022-01-04 08:36:14 +02:00
|
|
|
margin-left: 12px;
|
2021-09-29 18:50:45 +03:00
|
|
|
margin-top: 2px;
|
|
|
|
display: block;
|
|
|
|
transition: inherit;
|
|
|
|
color: var(--fg);
|
2020-11-25 14:31:34 +02:00
|
|
|
|
2021-09-29 18:50:45 +03:00
|
|
|
> span {
|
|
|
|
display: block;
|
|
|
|
line-height: 20px;
|
2021-12-25 18:42:50 +02:00
|
|
|
cursor: pointer;
|
2021-09-29 18:50:45 +03:00
|
|
|
transition: inherit;
|
2020-11-25 14:31:34 +02:00
|
|
|
}
|
|
|
|
|
2021-11-28 13:07:37 +02:00
|
|
|
> .caption {
|
|
|
|
margin: 8px 0 0 0;
|
2021-09-29 18:50:45 +03:00
|
|
|
color: var(--fgTransparentWeak);
|
2021-11-28 13:07:37 +02:00
|
|
|
font-size: 0.85em;
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.checked {
|
|
|
|
> .button {
|
2023-01-07 08:00:29 +02:00
|
|
|
background-color: var(--switchOnBg) !important;
|
|
|
|
border-color: var(--switchOnBg) !important;
|
2020-11-25 14:31:34 +02:00
|
|
|
|
2022-06-26 10:38:27 +03:00
|
|
|
> .knob {
|
|
|
|
left: 12px;
|
2023-01-07 08:00:29 +02:00
|
|
|
background: var(--switchOnFg);
|
2020-11-25 14:31:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|