From 89d7e4ead67b86210bc8c399c662c969a0c57836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Kube=C5=A1?= <46596180+KubesDavid@users.noreply.github.com> Date: Thu, 27 Oct 2022 21:32:23 +0200 Subject: [PATCH] chore: refactor thumbnail (#5682) --- .../dashboard/components/widgets/Avatar.vue | 62 ++----------- .../components/widgets/Thumbnail.vue | 92 +++++-------------- 2 files changed, 32 insertions(+), 122 deletions(-) diff --git a/app/javascript/dashboard/components/widgets/Avatar.vue b/app/javascript/dashboard/components/widgets/Avatar.vue index df654ee7e..6d7e17d50 100644 --- a/app/javascript/dashboard/components/widgets/Avatar.vue +++ b/app/javascript/dashboard/components/widgets/Avatar.vue @@ -1,10 +1,6 @@ @@ -16,69 +12,26 @@ export default { type: String, default: '', }, - backgroundColor: { - type: String, - default: '#c2e1ff', - }, - color: { - type: String, - default: '#1976cc', - }, - customStyle: { - type: Object, - default: undefined, - }, size: { type: Number, default: 40, }, - src: { - type: String, - default: '', - }, - rounded: { - type: Boolean, - default: true, - }, - variant: { - type: String, - default: 'circle', - }, }, computed: { style() { - let style = { - width: `${this.size}px`, - height: `${this.size}px`, - borderRadius: - this.variant === 'square' ? 'var(--border-radius-large)' : '50%', - lineHeight: `${this.size + Math.floor(this.size / 20)}px`, + return { fontSize: `${Math.floor(this.size / 2.5)}px`, }; - - if (this.backgroundColor) { - style = { ...style, backgroundColor: this.backgroundColor }; - } - if (this.color) { - style = { ...style, color: this.color }; - } - return style; }, userInitial() { - return this.initials || this.initial(this.username); - }, - }, - methods: { - initial(username) { - const parts = username ? username.split(/[ -]/) : []; - let initials = ''; - for (let i = 0; i < parts.length; i += 1) { - initials += parts[i].charAt(0); - } + const parts = this.username.split(/[ -]/); + let initials = parts.reduce((acc, curr) => acc + curr.charAt(0), ''); + if (initials.length > 2 && initials.search(/[A-Z]/) !== -1) { initials = initials.replace(/[a-z]+/g, ''); } initials = initials.substring(0, 2).toUpperCase(); + return initials; }, }, @@ -88,6 +41,7 @@ export default {