summaryrefslogtreecommitdiff
path: root/packages/frontend/src/components/MkPreferenceContainer.vue
blob: 70b111513c0c5ec1401ae02cc70c96414c27ec67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<!--
SPDX-FileCopyrightText: syuilo and misskey-project
SPDX-License-Identifier: AGPL-3.0-only
-->

<template>
<div :class="$style.root" @contextmenu.prevent.stop="showMenu($event, true)">
	<div :class="$style.body">
		<slot></slot>
	</div>
	<div :class="$style.menu">
		<i v-if="isSyncEnabled" class="ti ti-cloud-cog" style="color: var(--MI_THEME-accent); opacity: 0.7;"></i>
		<i v-if="isAccountOverrided" class="ti ti-user-cog" style="color: var(--MI_THEME-accent); opacity: 0.7;"></i>
		<div :class="$style.buttons">
			<button class="_button" style="color: var(--MI_THEME-fg)" @click="showMenu($event)"><i class="ti ti-dots"></i></button>
		</div>
	</div>
</div>
</template>

<script lang="ts" setup>
import { ref } from 'vue';
import type { PREF_DEF } from '@/preferences/def.js';
import * as os from '@/os.js';
import { prefer } from '@/preferences.js';

const props = withDefaults(defineProps<{
	k: keyof typeof PREF_DEF;
}>(), {
});

const isAccountOverrided = ref(prefer.isAccountOverrided(props.k));
const isSyncEnabled = ref(prefer.isSyncEnabled(props.k));

function showMenu(ev: MouseEvent, contextmenu?: boolean) {
	const i = window.setInterval(() => {
		isAccountOverrided.value = prefer.isAccountOverrided(props.k);
		isSyncEnabled.value = prefer.isSyncEnabled(props.k);
	}, 100);
	if (contextmenu) {
		os.contextMenu(prefer.getPerPrefMenu(props.k), ev).then(() => {
			window.clearInterval(i);
		});
	} else {
		os.popupMenu(prefer.getPerPrefMenu(props.k), ev.currentTarget ?? ev.target, {
			onClosing: () => {
				window.clearInterval(i);
			},
		});
	}
}
</script>

<style lang="scss" module>
.root {
	position: relative;
	display: flex;

	&:hover {
		&::before {
			content: '';
			position: absolute;
			top: -8px;
			left: -8px;
			width: calc(100% + 16px);
			height: calc(100% + 16px);
			border-radius: 8px;
			background: light-dark(rgba(0, 0, 0, 0.02), rgba(255, 255, 255, 0.02));
			pointer-events: none;
		}

		.menu {
			.buttons {
				opacity: 0.7;
			}
		}
	}

	.body {
		flex: 1;
	}

	.menu {
		display: flex;
		gap: 8px;
		align-items: center;
		margin-left: 12px;
		font-size: 12px;
		padding-left: 8px;
		border-left: solid 1px var(--MI_THEME-divider);

		&:hover {
			.buttons {
				opacity: 1;
			}
		}

		.buttons {
			opacity: 0.3;
		}
	}
}
</style>