refactor(client): use css modules

This commit is contained in:
syuilo 2023-01-14 11:59:08 +09:00
parent c84d86b368
commit 30fc166c08

View file

@ -1,38 +1,38 @@
<template> <template>
<div v-if="playerEnabled" class="player" :style="`padding: ${(player.height || 0) / (player.width || 1) * 100}% 0 0`"> <div v-if="playerEnabled" :class="$style.player" :style="`padding: ${(player.height || 0) / (player.width || 1) * 100}% 0 0`">
<button class="disablePlayer" :title="i18n.ts.disablePlayer" @click="playerEnabled = false"><i class="ti ti-x"></i></button> <button :class="$style.disablePlayer" :title="i18n.ts.disablePlayer" @click="playerEnabled = false"><i class="ti ti-x"></i></button>
<iframe :src="player.url + (player.url.match(/\?/) ? '&autoplay=1&auto_play=1' : '?autoplay=1&auto_play=1')" :width="player.width || '100%'" :heigth="player.height || 250" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen/> <iframe :class="$style.playerIframe" :src="player.url + (player.url.match(/\?/) ? '&autoplay=1&auto_play=1' : '?autoplay=1&auto_play=1')" :width="player.width || '100%'" :heigth="player.height || 250" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen/>
</div> </div>
<div v-else-if="tweetId && tweetExpanded" ref="twitter" class="twitter"> <div v-else-if="tweetId && tweetExpanded" ref="twitter" :class="$style.twitter">
<iframe ref="tweet" scrolling="no" frameborder="no" :style="{ position: 'relative', width: '100%', height: `${tweetHeight}px` }" :src="`https://platform.twitter.com/embed/index.html?embedId=${embedId}&amp;hideCard=false&amp;hideThread=false&amp;lang=en&amp;theme=${$store.state.darkMode ? 'dark' : 'light'}&amp;id=${tweetId}`"></iframe> <iframe ref="tweet" scrolling="no" frameborder="no" :style="{ position: 'relative', width: '100%', height: `${tweetHeight}px` }" :src="`https://platform.twitter.com/embed/index.html?embedId=${embedId}&amp;hideCard=false&amp;hideThread=false&amp;lang=en&amp;theme=${$store.state.darkMode ? 'dark' : 'light'}&amp;id=${tweetId}`"></iframe>
</div> </div>
<div v-else class="mk-url-preview"> <div v-else :class="$style.urlPreview">
<component :is="self ? 'MkA' : 'a'" class="link" :class="{ compact }" :[attr]="self ? url.substr(local.length) : url" rel="nofollow noopener" :target="target" :title="url"> <component :is="self ? 'MkA' : 'a'" :class="[$style.link, { [$style.compact]: compact }]" :[attr]="self ? url.substr(local.length) : url" rel="nofollow noopener" :target="target" :title="url">
<div v-if="thumbnail" class="thumbnail" :style="`background-image: url('${thumbnail}')`"> <div v-if="thumbnail" :class="$style.thumbnail" :style="`background-image: url('${thumbnail}')`">
</div> </div>
<article> <article :class="$style.body">
<header> <header :class="$style.header">
<h1 v-if="unknownUrl">{{ url }}</h1> <h1 v-if="unknownUrl" :class="$style.title">{{ url }}</h1>
<h1 v-else-if="fetching"><MkEllipsis/></h1> <h1 v-else-if="fetching" :class="$style.title"><MkEllipsis/></h1>
<h1 v-else :title="title">{{ title }}</h1> <h1 v-else :class="$style.title" :title="title">{{ title }}</h1>
</header> </header>
<p v-if="unknownUrl">{{ i18n.ts.cannotLoad }}</p> <p v-if="unknownUrl" :class="$style.text">{{ i18n.ts.cannotLoad }}</p>
<p v-else-if="fetching"><MkEllipsis/></p> <p v-else-if="fetching" :class="$style.text"><MkEllipsis/></p>
<p v-else-if="description" :title="description">{{ description.length > 85 ? description.slice(0, 85) + '…' : description }}</p> <p v-else-if="description" :class="$style.text" :title="description">{{ description.length > 85 ? description.slice(0, 85) + '…' : description }}</p>
<footer> <footer :class="$style.footer">
<img v-if="icon" class="icon" :src="icon"/> <img v-if="icon" :class="$style.siteIcon" :src="icon"/>
<p v-if="unknownUrl">?</p> <p v-if="unknownUrl" :class="$style.siteName">?</p>
<p v-else-if="fetching"><MkEllipsis/></p> <p v-else-if="fetching" :class="$style.siteName"><MkEllipsis/></p>
<p v-else :title="sitename">{{ sitename }}</p> <p v-else :class="$style.siteName" :title="sitename">{{ sitename }}</p>
</footer> </footer>
</article> </article>
</component> </component>
<div v-if="tweetId" class="action"> <div v-if="tweetId" :class="$style.action">
<MkButton :small="true" inline @click="tweetExpanded = true"> <MkButton :small="true" inline @click="tweetExpanded = true">
<i class="ti ti-brand-twitter"></i> {{ i18n.ts.expandTweet }} <i class="ti ti-brand-twitter"></i> {{ i18n.ts.expandTweet }}
</MkButton> </MkButton>
</div> </div>
<div v-if="!playerEnabled && player.url" class="action"> <div v-if="!playerEnabled && player.url" :class="$style.action">
<MkButton :small="true" inline @click="playerEnabled = true"> <MkButton :small="true" inline @click="playerEnabled = true">
<i class="ti ti-player-play"></i> {{ i18n.ts.enablePlayer }} <i class="ti ti-player-play"></i> {{ i18n.ts.enablePlayer }}
</MkButton> </MkButton>
@ -136,12 +136,13 @@ onUnmounted(() => {
}); });
</script> </script>
<style lang="scss" scoped> <style lang="scss" module>
.player { .player {
position: relative; position: relative;
width: 100%; width: 100%;
}
> button { .disablePlayer {
position: absolute; position: absolute;
top: -1.5em; top: -1.5em;
right: 0; right: 0;
@ -159,17 +160,22 @@ onUnmounted(() => {
} }
} }
> iframe { .playerIframe {
height: 100%; height: 100%;
left: 0; left: 0;
position: absolute; position: absolute;
top: 0; top: 0;
width: 100%; width: 100%;
} }
.twitter {
} }
.mk-url-preview { .urlPreview {
> .link { }
.link {
position: relative; position: relative;
display: block; display: block;
font-size: 14px; font-size: 14px;
@ -181,12 +187,23 @@ onUnmounted(() => {
text-decoration: none; text-decoration: none;
border-color: rgba(0, 0, 0, 0.2); border-color: rgba(0, 0, 0, 0.2);
> article > header > h1 { > .body > .header > .title {
text-decoration: underline; text-decoration: underline;
} }
} }
> .thumbnail { &.compact {
> .body {
> .header .title, .text, .footer {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
}
}
.thumbnail {
position: absolute; position: absolute;
width: 100px; width: 100px;
height: 100%; height: 100%;
@ -196,36 +213,38 @@ onUnmounted(() => {
justify-content: center; justify-content: center;
align-items: center; align-items: center;
& + article { & + .body {
left: 100px; left: 100px;
width: calc(100% - 100px); width: calc(100% - 100px);
} }
} }
> article { .body {
position: relative; position: relative;
box-sizing: border-box; box-sizing: border-box;
padding: 16px; padding: 16px;
}
> header { .header {
margin-bottom: 8px; margin-bottom: 8px;
}
> h1 { .title {
margin: 0; margin: 0;
font-size: 1em; font-size: 1em;
} }
}
> p { .text {
margin: 0; margin: 0;
font-size: 0.8em; font-size: 0.8em;
} }
> footer { .footer {
margin-top: 8px; margin-top: 8px;
height: 16px; height: 16px;
}
> img { .siteIcon {
display: inline-block; display: inline-block;
width: 16px; width: 16px;
height: 16px; height: 16px;
@ -233,7 +252,7 @@ onUnmounted(() => {
vertical-align: top; vertical-align: top;
} }
> p { .siteName {
display: inline-block; display: inline-block;
margin: 0; margin: 0;
color: var(--urlPreviewInfo); color: var(--urlPreviewInfo);
@ -241,70 +260,32 @@ onUnmounted(() => {
line-height: 16px; line-height: 16px;
vertical-align: top; vertical-align: top;
} }
}
}
&.compact { .action {
> article {
> header h1, p, footer {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
}
}
}
> .action {
display: flex; display: flex;
gap: 6px; gap: 6px;
flex-wrap: wrap; flex-wrap: wrap;
margin-top: 6px; margin-top: 6px;
} }
}
@container (max-width: 400px) { @container (max-width: 400px) {
.mk-url-preview { .link {
> .link {
font-size: 12px; font-size: 12px;
}
> .thumbnail { .thumbnail {
height: 80px; height: 80px;
} }
> article { .body {
padding: 12px; padding: 12px;
} }
} }
}
}
@container (max-width: 350px) { @container (max-width: 350px) {
.mk-url-preview { .link {
> .link {
font-size: 10px; font-size: 10px;
> .thumbnail {
height: 70px;
}
> article {
padding: 8px;
> header {
margin-bottom: 4px;
}
> footer {
margin-top: 4px;
> img {
width: 12px;
height: 12px;
}
}
}
&.compact { &.compact {
> .thumbnail { > .thumbnail {
position: absolute; position: absolute;
@ -312,21 +293,41 @@ onUnmounted(() => {
height: 100%; height: 100%;
} }
> article { > .body {
left: 56px; left: 56px;
width: calc(100% - 56px); width: calc(100% - 56px);
padding: 4px; padding: 4px;
> header { > .header {
margin-bottom: 2px; margin-bottom: 2px;
} }
> footer { > .footer {
margin-top: 2px; margin-top: 2px;
} }
} }
} }
} }
.thumbnail {
height: 70px;
}
.body {
padding: 8px;
}
.header {
margin-bottom: 4px;
}
.footer {
margin-top: 4px;
}
.siteIcon {
width: 12px;
height: 12px;
} }
} }
</style> </style>