feat: add alt indicator in post form attachments

This commit is contained in:
Lhcfl 2024-03-25 12:29:06 +08:00
parent a7d6e8eb1a
commit 69d214accc
3 changed files with 40 additions and 7 deletions

View file

@ -4,9 +4,10 @@
v-if="isThumbnailAvailable"
:hash="file.blurhash"
:src="file.thumbnailUrl"
:alt="file.name"
:alt="file.comment"
:title="file.name"
:cover="fit !== 'contain'"
:show_alt_indicator="show_alt_indicator"
/>
<i v-else-if="is === 'image'" :class="icon('ph-file-image icon')"></i>
<i v-else-if="is === 'video'" :class="icon('ph-file-video icon')"></i>
@ -33,10 +34,16 @@ import type { entities } from "firefish-js";
import ImgWithBlurhash from "@/components/MkImgWithBlurhash.vue";
import icon from "@/scripts/icon";
const props = defineProps<{
file: entities.DriveFile;
fit: string;
}>();
const props = withDefaults(
defineProps<{
file: entities.DriveFile;
fit: string;
show_alt_indicator?: boolean
}>(),
{
show_alt_indicator: false,
}
);
const is = computed(() => {
if (props.file.type.startsWith("image/")) return "image";

View file

@ -21,30 +21,38 @@
loading="lazy"
@load="onLoad"
/>
<i
class="alt-indicator"
:class="icon('ph-subtitles')"
v-if="alt && show_alt_indicator"
></i>
</template>
<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { decodeBlurHash } from "fast-blurhash";
import icon from "@/scripts/icon";
const props = withDefaults(
defineProps<{
src?: string | null;
hash?: string;
alt?: string;
alt?: string | null;
type?: string | null;
title?: string | null;
size?: number;
cover?: boolean;
largestDimension?: "width" | "height";
show_alt_indicator?: boolean
}>(),
{
src: null,
type: null,
alt: "",
alt: null,
title: null,
size: 64,
cover: true,
show_alt_indicator: false
},
);
@ -96,4 +104,21 @@ img {
height: 100%;
}
}
i.alt-indicator {
display: flex;
gap: 4px;
position: absolute;
border-radius: 6px;
overflow: hidden;
top: 0;
right: 0;
background-color: var(--accentedBg);
-webkit-backdrop-filter: var(--blur, blur(15px));
backdrop-filter: var(--blur, blur(15px));
color: var(--accent);
font-size: 0.8em;
padding: 6px 8px;
text-align: center;
}
</style>

View file

@ -19,6 +19,7 @@
class="thumbnail"
:file="element"
fit="cover"
:show_alt_indicator="true"
/>
<div v-if="element.isSensitive" class="sensitive">
<i :class="icon('ph-warning icon')"></i>