mirror of
https://github.com/hcengineering/platform.git
synced 2026-09-24 02:25:00 +02:00
132 lines
3.5 KiB
Svelte
132 lines
3.5 KiB
Svelte
<!--
|
|
// Copyright © 2023 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 type { IntlString } from '@hcengineering/platform'
|
|
import { translateCB } from '@hcengineering/platform'
|
|
import { copyTextToClipboard } from '@hcengineering/presentation'
|
|
import { Button, IconArrowRight, IconBlueCheck, IconClose, IconCopy, Label, themeStore } from '@hcengineering/ui'
|
|
import { createEventDispatcher, onMount } from 'svelte'
|
|
import view from '../plugin'
|
|
|
|
export let value: string | undefined = ''
|
|
export let editable: boolean | undefined = true
|
|
|
|
const placeholder: IntlString = view.string.HyperlinkPlaceholder
|
|
const dispatch = createEventDispatcher()
|
|
let input: HTMLInputElement
|
|
let phTranslate: string
|
|
$: translateCB(placeholder, {}, $themeStore.language, (tr) => (phTranslate = tr))
|
|
|
|
onMount(() => {
|
|
if (input) input.focus()
|
|
})
|
|
const copyLink = (): void => {
|
|
if (value !== undefined) {
|
|
copyTextToClipboard(value)
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<div class="editor-container buttons-group xsmall-gap">
|
|
<div class="cover-channel show">
|
|
{#if editable}
|
|
<input
|
|
bind:this={input}
|
|
class="search"
|
|
type="text"
|
|
bind:value
|
|
placeholder={phTranslate}
|
|
style="width: 100%;"
|
|
on:keypress={(ev) => {
|
|
if (ev.key === 'Enter') {
|
|
ev.preventDefault()
|
|
ev.stopPropagation()
|
|
dispatch('close', value)
|
|
}
|
|
}}
|
|
on:change
|
|
/>
|
|
{:else if value}
|
|
<span class="overflow-label">{value}</span>
|
|
{:else}
|
|
<span class="content-dark-color"><Label label={placeholder} /></span>
|
|
{/if}
|
|
</div>
|
|
{#if editable}
|
|
<Button
|
|
focusIndex={2}
|
|
kind={'ghost'}
|
|
size={'small'}
|
|
icon={IconClose}
|
|
disabled={value === ''}
|
|
on:click={() => {
|
|
if (input) {
|
|
value = ''
|
|
input.focus()
|
|
}
|
|
}}
|
|
/>
|
|
<Button
|
|
id="channel-ok"
|
|
focusIndex={3}
|
|
kind={'ghost'}
|
|
size={'small'}
|
|
icon={IconBlueCheck}
|
|
on:click={() => {
|
|
dispatch('close', value)
|
|
}}
|
|
/>
|
|
{/if}
|
|
<Button
|
|
focusIndex={4}
|
|
kind={'ghost'}
|
|
size={'small'}
|
|
icon={IconCopy}
|
|
disabled={value === undefined || value === ''}
|
|
showTooltip={{ label: view.string.CopyToClipboard }}
|
|
on:click={() => {
|
|
copyLink()
|
|
}}
|
|
/>
|
|
<Button
|
|
focusIndex={5}
|
|
kind={'ghost'}
|
|
size={'small'}
|
|
icon={IconArrowRight}
|
|
disabled={value === undefined || value === ''}
|
|
showTooltip={{ label: view.string.Open }}
|
|
on:click={() => {
|
|
dispatch('update', value)
|
|
dispatch('close', 'open')
|
|
}}
|
|
/>
|
|
</div>
|
|
|
|
<style lang="scss">
|
|
.cover-channel {
|
|
position: relative;
|
|
min-width: 0;
|
|
min-height: 0;
|
|
}
|
|
|
|
.editor-container {
|
|
padding: 0.5rem;
|
|
background-color: var(--theme-popup-color);
|
|
border: 1px solid var(--theme-popup-divider);
|
|
border-radius: 0.75rem;
|
|
box-shadow: var(--theme-popup-shadow);
|
|
}
|
|
</style>
|