aboutsummaryrefslogtreecommitdiffstats
path: root/apps/settings/src/components/PersonalInfo/ProfileSection/ProfilePreviewCard.vue
blob: 47894f64f3478f1eb9496e6d4dcdbca304ec9c71 (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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!--
  - SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
  - SPDX-License-Identifier: AGPL-3.0-or-later
-->

<template>
	<a class="preview-card"
		:class="{ disabled }"
		:href="profilePageLink">
		<NcAvatar class="preview-card__avatar"
			:user="userId"
			:size="48"
			:show-user-status="true"
			:show-user-status-compact="false"
			:disable-menu="true"
			:disable-tooltip="true" />
		<div class="preview-card__header">
			<span>{{ displayName }}</span>
		</div>
		<div class="preview-card__footer">
			<span>{{ organisation }}</span>
		</div>
	</a>
</template>

<script>
import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl } from '@nextcloud/router'

import NcAvatar from '@nextcloud/vue/components/NcAvatar'

export default {
	name: 'ProfilePreviewCard',

	components: {
		NcAvatar,
	},

	props: {
		displayName: {
			type: String,
			required: true,
		},
		organisation: {
			type: String,
			required: true,
		},
		profileEnabled: {
			type: Boolean,
			required: true,
		},
		userId: {
			type: String,
			required: true,
		},
	},

	computed: {
		disabled() {
			return !this.profileEnabled
		},

		profilePageLink() {
			if (this.profileEnabled) {
				return generateUrl('/u/{userId}', { userId: getCurrentUser().uid })
			}
			// Since an anchor element is used rather than a button for better UX,
			// this hack removes href if the profile is disabled so that disabling pointer-events is not needed to prevent a click from opening a page
			// and to allow the hover event (which disabling pointer-events wouldn't allow) for styling
			return null
		},
	},
}
</script>

<style lang="scss" scoped>
.preview-card {
	display: flex;
	flex-direction: column;
	position: relative;
	width: min(100%, 290px);
	height: 116px;
	margin: 14px auto;
	border-radius: var(--border-radius-large);
	background-color: var(--color-main-background);
	font-weight: bold;
	box-shadow: 0 2px 9px var(--color-box-shadow);

	&:hover,
	&:focus,
	&:active {
		box-shadow: 0 2px 12px var(--color-box-shadow);
	}

	&:focus-visible {
		outline: var(--color-main-text) solid 1px;
		outline-offset: 3px;
	}

	&.disabled {
		filter: grayscale(1);
		opacity: 0.5;
		cursor: default;
		box-shadow: 0 0 3px var(--color-box-shadow);

		& *,
		&:deep(*) {
			cursor: default;
		}
	}

	&__avatar {
		// Override Avatar component position to fix positioning on rerender
		position: absolute !important;
		top: 40px;
		inset-inline-start: 18px;
		z-index: 1;

		&:not(.avatardiv--unknown) {
			box-shadow: 0 0 0 3px var(--color-main-background) !important;
		}
	}

	&__header,
	&__footer {
		position: relative;
		width: auto;

		span {
			position: absolute;
			inset-inline-start: 78px;
			overflow: hidden;
			text-overflow: ellipsis;
			overflow-wrap: anywhere;

			@supports (-webkit-line-clamp: 2) {
				display: -webkit-box;
				-webkit-line-clamp: 2;
				-webkit-box-orient: vertical;
			}
		}
	}

	&__header {
		height: 70px;
		border-radius: var(--border-radius-large) var(--border-radius-large) 0 0;
		background-color: var(--color-primary-element);

		span {
			bottom: 0;
			color: var(--color-primary-element-text);
			font-size: 18px;
			font-weight: bold;
			margin-block: 0 8px;
			margin-inline: 0 4px;
		}
	}

	&__footer {
		height: 46px;

		span {
			top: 0;
			color: var(--color-text-maxcontrast);
			font-size: 14px;
			font-weight: normal;
			margin-block: 4px 0;
			margin-inline: 0 4px;
			line-height: 1.3;
		}
	}
}
</style>