2022-04-08 18:05:49 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
|
|
|
import { formatName, Person } from '@anticrm/contact'
|
|
|
|
import { Hierarchy } from '@anticrm/core'
|
2022-04-28 12:03:10 +00:00
|
|
|
import { IntlString } from '@anticrm/platform'
|
2022-04-08 18:05:49 +00:00
|
|
|
import { Avatar } from '@anticrm/presentation'
|
2022-06-07 04:10:34 +00:00
|
|
|
import { getPanelURI, Label, LabelAndProps, tooltip } from '@anticrm/ui'
|
2022-04-08 18:05:49 +00:00
|
|
|
import view from '@anticrm/view'
|
|
|
|
|
2022-06-07 08:57:05 +00:00
|
|
|
export let value: Person | undefined | null
|
2022-04-08 18:05:49 +00:00
|
|
|
export let inline: boolean = false
|
2022-04-28 12:03:10 +00:00
|
|
|
export let isInteractive = true
|
2022-05-12 07:05:26 +00:00
|
|
|
export let shouldShowAvatar: boolean = true
|
2022-04-08 18:05:49 +00:00
|
|
|
export let shouldShowName = true
|
|
|
|
export let shouldShowPlaceholder = false
|
2022-04-28 12:03:10 +00:00
|
|
|
export let defaultName: IntlString | undefined = undefined
|
|
|
|
export let avatarSize: 'inline' | 'tiny' | 'x-small' | 'small' | 'medium' | 'large' | 'x-large' = 'x-small'
|
|
|
|
export let onEdit: ((event: MouseEvent) => void) | undefined = undefined
|
2022-06-07 04:10:34 +00:00
|
|
|
export let showTooltip: LabelAndProps | undefined = undefined
|
2022-04-08 18:05:49 +00:00
|
|
|
|
2022-04-28 12:03:10 +00:00
|
|
|
$: element = getElement(value, onEdit, shouldShowPlaceholder, isInteractive)
|
|
|
|
|
|
|
|
const getElement = (
|
2022-06-07 08:57:05 +00:00
|
|
|
person: Person | undefined | null,
|
2022-04-28 12:03:10 +00:00
|
|
|
onEdit: Function | undefined,
|
|
|
|
shouldShowEmpty: boolean,
|
|
|
|
isInteractive: boolean
|
|
|
|
) => {
|
|
|
|
if (!person && !shouldShowEmpty) {
|
|
|
|
return undefined
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isInteractive) {
|
|
|
|
return 'div'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (person && !onEdit) {
|
|
|
|
return 'a'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'div'
|
|
|
|
}
|
2022-04-08 18:05:49 +00:00
|
|
|
</script>
|
|
|
|
|
2022-04-28 12:03:10 +00:00
|
|
|
<svelte:element
|
|
|
|
this={element}
|
2022-06-07 04:10:34 +00:00
|
|
|
use:tooltip={showTooltip}
|
2022-04-28 12:03:10 +00:00
|
|
|
class="contentPresenter"
|
|
|
|
class:inline-presenter={inline}
|
|
|
|
class:mContentPresenterNotInteractive={!isInteractive}
|
|
|
|
on:click={onEdit}
|
|
|
|
href={!isInteractive || onEdit || !value
|
|
|
|
? undefined
|
|
|
|
: `#${getPanelURI(view.component.EditDoc, value._id, Hierarchy.mixinOrClass(value), 'content')}`}
|
|
|
|
>
|
2022-05-12 07:05:26 +00:00
|
|
|
{#if shouldShowAvatar}
|
2022-07-02 04:03:25 +00:00
|
|
|
<div class="eContentPresenterIcon" class:mr-2={shouldShowName}>
|
2022-05-12 07:05:26 +00:00
|
|
|
<Avatar size={avatarSize} avatar={value?.avatar} />
|
|
|
|
</div>
|
|
|
|
{/if}
|
2022-04-28 12:03:10 +00:00
|
|
|
{#if value && shouldShowName}
|
|
|
|
<span class="eContentPresenterLabel">{formatName(value.name)}</span>
|
|
|
|
{/if}
|
|
|
|
{#if !value && shouldShowName && defaultName}
|
|
|
|
<div class="eContentPresenterLabel">
|
|
|
|
<Label label={defaultName} />
|
2022-04-08 18:05:49 +00:00
|
|
|
</div>
|
|
|
|
{/if}
|
2022-04-28 12:03:10 +00:00
|
|
|
</svelte:element>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.contentPresenter {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
flex-wrap: nowrap;
|
|
|
|
cursor: pointer;
|
|
|
|
|
|
|
|
&.mContentPresenterNotInteractive {
|
|
|
|
cursor: default;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
.eContentPresenterIcon {
|
|
|
|
color: var(--theme-content-dark-color);
|
|
|
|
}
|
|
|
|
.eContentPresenterLabel {
|
|
|
|
text-decoration: none;
|
|
|
|
color: var(--theme-content-accent-color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.eContentPresenterIcon {
|
|
|
|
color: var(--theme-content-dark-color);
|
|
|
|
}
|
|
|
|
.eContentPresenterLabel {
|
|
|
|
min-width: 0;
|
|
|
|
font-weight: 500;
|
|
|
|
text-align: left;
|
|
|
|
color: var(--theme-content-accent-color);
|
|
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
visibility: visible;
|
|
|
|
display: -webkit-box;
|
|
|
|
/* autoprefixer: ignore next */
|
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
-webkit-line-clamp: 2;
|
|
|
|
line-clamp: 2;
|
|
|
|
user-select: none;
|
|
|
|
}
|
|
|
|
&:hover {
|
|
|
|
.eContentPresenterIcon {
|
|
|
|
color: var(--theme-caption-color);
|
|
|
|
}
|
|
|
|
.eContentPresenterLabel {
|
|
|
|
text-decoration: underline;
|
|
|
|
color: var(--theme-caption-color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|