1
0
mirror of https://github.com/MisskeyIO/misskey synced 2024-12-15 07:08:53 +09:00
MisskeyIO/packages/frontend/src/components/MkCwButton.vue

63 lines
1.3 KiB
Vue
Raw Normal View History

<template>
2023-01-14 11:46:22 +09:00
<button class="_button" :class="$style.root" @click="toggle">
<b>{{ modelValue ? i18n.ts._cw.hide : i18n.ts._cw.show }}</b>
2023-01-14 11:46:22 +09:00
<span v-if="!modelValue" :class="$style.label">{{ label }}</span>
</button>
</template>
2022-01-07 13:26:12 +09:00
<script lang="ts" setup>
import { computed } from 'vue';
import { length } from 'stringz';
2022-01-07 13:26:12 +09:00
import * as misskey from 'misskey-js';
2021-11-12 02:02:25 +09:00
import { concat } from '@/scripts/array';
2022-01-07 13:26:12 +09:00
import { i18n } from '@/i18n';
const props = defineProps<{
modelValue: boolean;
note: misskey.entities.Note;
}>();
const emit = defineEmits<{
(ev: 'update:modelValue', v: boolean): void;
2022-01-07 13:26:12 +09:00
}>();
const label = computed(() => {
return concat([
props.note.text ? [i18n.t('_cw.chars', { count: length(props.note.text) })] : [],
props.note.files && props.note.files.length !== 0 ? [i18n.t('_cw.files', { count: props.note.files.length })] : [],
props.note.poll != null ? [i18n.ts.poll] : [],
2022-01-07 13:26:12 +09:00
] as string[][]).join(' / ');
});
2022-01-07 13:26:12 +09:00
const toggle = () => {
emit('update:modelValue', !props.modelValue);
};
</script>
2023-01-14 11:46:22 +09:00
<style lang="scss" module>
.root {
display: inline-block;
padding: 4px 8px;
font-size: 0.7em;
color: var(--cwFg);
background: var(--cwBg);
border-radius: 2px;
&:hover {
background: var(--cwHoverBg);
}
2023-01-14 11:46:22 +09:00
}
2023-01-14 11:46:22 +09:00
.label {
margin-left: 4px;
2023-01-14 11:46:22 +09:00
&:before {
content: '(';
}
2023-01-14 11:46:22 +09:00
&:after {
content: ')';
}
}
</style>