Sharkey/packages/frontend/src/components/MkCwButton.vue

69 lines
1.5 KiB
Vue
Raw Normal View History

<!--
SPDX-FileCopyrightText: syuilo and other misskey contributors
SPDX-License-Identifier: AGPL-3.0-only
-->
<template>
2023-10-10 12:08:54 +03:00
<MkButton rounded full small @click="toggle"><b>{{ modelValue ? i18n.ts._cw.hide : i18n.ts._cw.show }}</b><span v-if="!modelValue" :class="$style.label">{{ label }}</span></MkButton>
</template>
2022-01-07 06:26:12 +02:00
<script lang="ts" setup>
import { computed } from 'vue';
import * as Misskey from 'misskey-js';
2023-09-19 10:37:43 +03:00
import { concat } from '@/scripts/array.js';
import { i18n } from '@/i18n.js';
2023-10-10 12:08:54 +03:00
import MkButton from '@/components/MkButton.vue';
2022-01-07 06:26:12 +02:00
const props = defineProps<{
modelValue: boolean;
text: string | null;
renote: Misskey.entities.Note | null;
files: Misskey.entities.DriveFile[];
poll?: {
expiresAt: string | null;
multiple: boolean;
choices: {
isVoted: boolean;
text: string;
votes: number;
}[];
} | {
choices: string[];
multiple: boolean;
expiresAt: string | null;
expiredAfter: string | null;
};
2022-01-07 06:26:12 +02:00
}>();
const emit = defineEmits<{
(ev: 'update:modelValue', v: boolean): void;
2022-01-07 06:26:12 +02:00
}>();
const label = computed(() => {
return concat([
props.text ? [i18n.t('_cw.chars', { count: props.text.length })] : [],
props.renote != null ? [i18n.ts.quote] : [],
props.files.length !== 0 ? [i18n.t('_cw.files', { count: props.files.length })] : [],
props.poll != null ? [i18n.ts.poll] : [],
2022-01-07 06:26:12 +02:00
] as string[][]).join(' / ');
});
2022-01-07 06:26:12 +02:00
2023-10-10 12:08:54 +03:00
function toggle() {
2022-01-07 06:26:12 +02:00
emit('update:modelValue', !props.modelValue);
2023-10-10 12:08:54 +03:00
}
</script>
2023-01-14 04:46:22 +02:00
<style lang="scss" module>
.label {
margin-left: 4px;
2023-01-14 04:46:22 +02:00
&:before {
content: '(';
}
2023-01-14 04:46:22 +02:00
&:after {
content: ')';
}
}
</style>