refactor(frontend): use css module

This commit is contained in:
syuilo 2023-05-10 17:53:01 +09:00
parent f9f115b66d
commit ed634b4b3d

View file

@ -1,21 +1,19 @@
<template> <template>
<div <div :class="[$style.root, { [$style.disabled]: disabled, [$style.checked]: checked }]">
class="ziffeomt"
:class="{ disabled, checked }"
>
<input <input
ref="input" ref="input"
type="checkbox" type="checkbox"
:disabled="disabled" :disabled="disabled"
:class="$style.input"
@keydown.enter="toggle" @keydown.enter="toggle"
> >
<span ref="button" v-tooltip="checked ? i18n.ts.itsOn : i18n.ts.itsOff" class="button" data-cy-switch-toggle @click.prevent="toggle"> <span ref="button" v-tooltip="checked ? i18n.ts.itsOn : i18n.ts.itsOff" :class="$style.button" data-cy-switch-toggle @click.prevent="toggle">
<div class="knob"></div> <div :class="$style.knob"></div>
</span> </span>
<span class="label"> <span :class="$style.body">
<!-- TODO: 無名slotの方は廃止 --> <!-- TODO: 無名slotの方は廃止 -->
<span @click="toggle"><slot name="label"></slot><slot></slot></span> <span :class="$style.label" @click="toggle"><slot name="label"></slot><slot></slot></span>
<p class="caption"><slot name="caption"></slot></p> <p :class="$style.caption"><slot name="caption"></slot></p>
</span> </span>
</div> </div>
</template> </template>
@ -45,52 +43,12 @@ const toggle = () => {
}; };
</script> </script>
<style lang="scss" scoped> <style lang="scss" module>
.ziffeomt { .root {
position: relative; position: relative;
display: flex; display: flex;
transition: all 0.2s ease; transition: all 0.2s ease;
user-select: none;
> * {
user-select: none;
}
> 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;
}
}
&:hover { &:hover {
> .button { > .button {
@ -98,31 +56,6 @@ const toggle = () => {
} }
} }
> .label {
margin-left: 12px;
margin-top: 2px;
display: block;
transition: inherit;
color: var(--fg);
> span {
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;
}
}
}
&.disabled { &.disabled {
opacity: 0.6; opacity: 0.6;
cursor: not-allowed; cursor: not-allowed;
@ -140,4 +73,66 @@ const toggle = () => {
} }
} }
} }
.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;
}
}
</style> </style>