refactor(frontend): use css modules

This commit is contained in:
syuilo 2023-05-02 09:07:57 +09:00
parent e48926b01d
commit 1631e62739

View file

@ -1,12 +1,13 @@
<template> <template>
<div class="matxzzsk"> <div>
<div class="label" @click="focus"><slot name="label"></slot></div> <div :class="$style.label" @click="focus"><slot name="label"></slot></div>
<div class="input" :class="{ inline, disabled, focused }"> <div :class="$style.input" :class="{ inline, disabled, focused }">
<div ref="prefixEl" class="prefix"><slot name="prefix"></slot></div> <div ref="prefixEl" :class="$style.prefix"><div :class="$style.prefixOrSuffixText"><slot name="prefix"></slot></div></div>
<input <input
ref="inputEl" ref="inputEl"
v-model="v" v-model="v"
v-adaptive-border v-adaptive-border
:class="$style.inputCore"
:type="type" :type="type"
:disabled="disabled" :disabled="disabled"
:required="required" :required="required"
@ -25,11 +26,11 @@
<datalist v-if="datalist" :id="id"> <datalist v-if="datalist" :id="id">
<option v-for="data in datalist" :key="data" :value="data"/> <option v-for="data in datalist" :key="data" :value="data"/>
</datalist> </datalist>
<div ref="suffixEl" class="suffix"><slot name="suffix"></slot></div> <div ref="suffixEl" :class="$style.suffix"><div :class="$style.prefixOrSuffixText"><slot name="suffix"></slot></div></div>
</div> </div>
<div class="caption"><slot name="caption"></slot></div> <div :class="$style.caption"><slot name="caption"></slot></div>
<MkButton v-if="manualSave && changed" primary class="save" @click="updated"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton> <MkButton v-if="manualSave && changed" primary :class="$style.save" @click="updated"><i class="ti ti-check"></i> {{ i18n.ts.save }}</MkButton>
</div> </div>
</template> </template>
@ -151,9 +152,8 @@ onMounted(() => {
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" module>
.matxzzsk { .label {
> .label {
font-size: 0.85em; font-size: 0.85em;
padding: 0 0 8px 0; padding: 0 0 8px 0;
user-select: none; user-select: none;
@ -161,9 +161,9 @@ onMounted(() => {
&:empty { &:empty {
display: none; display: none;
} }
} }
> .caption { .caption {
font-size: 0.85em; font-size: 0.85em;
padding: 8px 0 0 0; padding: 8px 0 0 0;
color: var(--fgTransparentWeak); color: var(--fgTransparentWeak);
@ -171,12 +171,34 @@ onMounted(() => {
&:empty { &:empty {
display: none; display: none;
} }
} }
> .input { .input {
position: relative; position: relative;
> input { &.inline {
display: inline-block;
margin: 0;
}
&.focused {
> .inputCore {
border-color: var(--accent) !important;
//box-shadow: 0 0 0 4px var(--focus);
}
}
&.disabled {
opacity: 0.7;
&,
> .inputCore {
cursor: not-allowed !important;
}
}
}
.inputCore {
appearance: none; appearance: none;
-webkit-appearance: none; -webkit-appearance: none;
display: block; display: block;
@ -199,10 +221,10 @@ onMounted(() => {
&:hover { &:hover {
border-color: var(--inputBorderHover) !important; border-color: var(--inputBorderHover) !important;
} }
} }
> .prefix, .prefix,
> .suffix { .suffix {
display: flex; display: flex;
align-items: center; align-items: center;
position: absolute; position: absolute;
@ -216,50 +238,28 @@ onMounted(() => {
&:empty { &:empty {
display: none; display: none;
} }
}
> * { .prefix {
left: 0;
padding-right: 6px;
}
.suffix {
right: 0;
padding-left: 6px;
}
.prefixOrSuffixText {
display: inline-block; display: inline-block;
min-width: 16px; min-width: 16px;
max-width: 150px; max-width: 150px;
overflow: hidden; overflow: hidden;
white-space: nowrap; white-space: nowrap;
text-overflow: ellipsis; text-overflow: ellipsis;
} }
}
> .prefix { .save {
left: 0;
padding-right: 6px;
}
> .suffix {
right: 0;
padding-left: 6px;
}
&.inline {
display: inline-block;
margin: 0;
}
&.focused {
> input {
border-color: var(--accent) !important;
//box-shadow: 0 0 0 4px var(--focus);
}
}
&.disabled {
opacity: 0.7;
&, * {
cursor: not-allowed !important;
}
}
}
> .save {
margin: 8px 0 0 0; margin: 8px 0 0 0;
}
} }
</style> </style>