2020-11-25 04:31:34 -08:00
|
|
|
<template>
|
2021-09-29 08:50:45 -07:00
|
|
|
<div
|
|
|
|
class="ziffeoms"
|
|
|
|
:class="{ disabled, checked }"
|
|
|
|
>
|
|
|
|
<input
|
|
|
|
ref="input"
|
2021-11-19 02:36:12 -08:00
|
|
|
type="checkbox"
|
2021-09-29 08:50:45 -07:00
|
|
|
:disabled="disabled"
|
|
|
|
@keydown.enter="toggle"
|
2020-11-25 04:31:34 -08:00
|
|
|
>
|
2021-12-27 05:59:14 -08:00
|
|
|
<span ref="button" v-adaptive-border v-tooltip="checked ? $ts.itsOn : $ts.itsOff" class="button" @click.prevent="toggle">
|
2021-12-25 08:42:50 -08:00
|
|
|
<i class="check fas fa-check"></i>
|
2021-09-29 08:50:45 -07:00
|
|
|
</span>
|
|
|
|
<span class="label">
|
2021-12-30 04:47:48 -08:00
|
|
|
<!-- TODO: 無名slotの方は廃止 -->
|
|
|
|
<span @click="toggle"><slot name="label"></slot><slot></slot></span>
|
2021-11-28 03:07:37 -08:00
|
|
|
<p class="caption"><slot name="caption"></slot></p>
|
2021-09-29 08:50:45 -07:00
|
|
|
</span>
|
2020-11-25 04:31:34 -08:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2021-12-27 05:59:14 -08:00
|
|
|
import { defineComponent, ref, toRefs } from 'vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import Ripple from '@/components/ripple.vue';
|
2020-11-25 04:31:34 -08:00
|
|
|
|
|
|
|
export default defineComponent({
|
|
|
|
props: {
|
2021-09-29 08:50:45 -07:00
|
|
|
modelValue: {
|
2020-11-25 04:31:34 -08:00
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
|
|
|
disabled: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
},
|
2021-12-27 05:59:14 -08:00
|
|
|
|
|
|
|
setup(props, context) {
|
|
|
|
const button = ref<HTMLElement>();
|
|
|
|
const checked = toRefs(props).modelValue;
|
|
|
|
const toggle = () => {
|
|
|
|
if (props.disabled) return;
|
|
|
|
context.emit('update:modelValue', !checked.value);
|
|
|
|
|
|
|
|
if (!checked.value) {
|
|
|
|
const rect = button.value.getBoundingClientRect();
|
|
|
|
const x = rect.left + (button.value.offsetWidth / 2);
|
|
|
|
const y = rect.top + (button.value.offsetHeight / 2);
|
|
|
|
os.popup(Ripple, { x, y, particle: false }, {}, 'end');
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
button,
|
|
|
|
checked,
|
|
|
|
toggle,
|
|
|
|
};
|
2020-11-25 04:31:34 -08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-09-29 08:50:45 -07:00
|
|
|
.ziffeoms {
|
|
|
|
position: relative;
|
|
|
|
display: flex;
|
2021-12-27 05:59:14 -08:00
|
|
|
transition: all 0.2s ease;
|
2021-09-29 08:50:45 -07:00
|
|
|
|
|
|
|
> * {
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
> input {
|
|
|
|
position: absolute;
|
|
|
|
width: 0;
|
|
|
|
height: 0;
|
|
|
|
opacity: 0;
|
|
|
|
margin: 0;
|
|
|
|
}
|
2020-11-25 04:31:34 -08:00
|
|
|
|
2021-09-29 08:50:45 -07:00
|
|
|
> .button {
|
|
|
|
position: relative;
|
2021-12-25 08:42:50 -08:00
|
|
|
display: inline-flex;
|
2021-09-29 08:50:45 -07:00
|
|
|
flex-shrink: 0;
|
|
|
|
margin: 0;
|
2021-12-25 08:42:50 -08:00
|
|
|
box-sizing: border-box;
|
|
|
|
width: 23px;
|
|
|
|
height: 23px;
|
2021-09-29 08:50:45 -07:00
|
|
|
outline: none;
|
2021-12-25 08:42:50 -08:00
|
|
|
background: var(--panel);
|
|
|
|
border: solid 1px var(--panel);
|
|
|
|
border-radius: 4px;
|
|
|
|
cursor: pointer;
|
2021-09-29 08:50:45 -07:00
|
|
|
transition: inherit;
|
|
|
|
|
2021-12-25 08:42:50 -08:00
|
|
|
> .check {
|
|
|
|
margin: auto;
|
|
|
|
opacity: 0;
|
|
|
|
color: var(--fgOnAccent);
|
|
|
|
font-size: 13px;
|
2021-12-27 05:59:14 -08:00
|
|
|
transform: scale(0.5);
|
|
|
|
transition: all 0.2s ease;
|
2021-12-25 08:42:50 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
> .button {
|
|
|
|
border-color: var(--inputBorderHover) !important;
|
2020-11-25 04:31:34 -08:00
|
|
|
}
|
2021-09-29 08:50:45 -07:00
|
|
|
}
|
2020-11-25 04:31:34 -08:00
|
|
|
|
2021-09-29 08:50:45 -07:00
|
|
|
> .label {
|
|
|
|
margin-left: 16px;
|
|
|
|
margin-top: 2px;
|
|
|
|
display: block;
|
|
|
|
transition: inherit;
|
|
|
|
color: var(--fg);
|
2020-11-25 04:31:34 -08:00
|
|
|
|
2021-09-29 08:50:45 -07:00
|
|
|
> span {
|
|
|
|
display: block;
|
|
|
|
line-height: 20px;
|
2021-12-25 08:42:50 -08:00
|
|
|
cursor: pointer;
|
2021-09-29 08:50:45 -07:00
|
|
|
transition: inherit;
|
2020-11-25 04:31:34 -08:00
|
|
|
}
|
|
|
|
|
2021-11-28 03:07:37 -08:00
|
|
|
> .caption {
|
|
|
|
margin: 8px 0 0 0;
|
2021-09-29 08:50:45 -07:00
|
|
|
color: var(--fgTransparentWeak);
|
2021-11-28 03:07:37 -08:00
|
|
|
font-size: 0.85em;
|
|
|
|
|
|
|
|
&:empty {
|
|
|
|
display: none;
|
|
|
|
}
|
2020-11-25 04:31:34 -08:00
|
|
|
}
|
2021-09-29 08:50:45 -07:00
|
|
|
}
|
2020-11-25 04:31:34 -08:00
|
|
|
|
2021-09-29 08:50:45 -07:00
|
|
|
&.disabled {
|
|
|
|
opacity: 0.6;
|
|
|
|
cursor: not-allowed;
|
|
|
|
}
|
|
|
|
|
|
|
|
&.checked {
|
|
|
|
> .button {
|
2021-12-25 08:42:50 -08:00
|
|
|
background-color: var(--accent) !important;
|
|
|
|
border-color: var(--accent) !important;
|
2020-11-25 04:31:34 -08:00
|
|
|
|
2021-12-25 08:42:50 -08:00
|
|
|
> .check {
|
|
|
|
opacity: 1;
|
2021-12-27 05:59:14 -08:00
|
|
|
transform: scale(1);
|
2020-11-25 04:31:34 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|