platform/packages/ui/src/components/SelectPopup.svelte

66 lines
2.1 KiB
Svelte
Raw Normal View History

<!--
// Copyright © 2020 Anticrm Platform Contributors.
//
// 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 { Asset, IntlString } from '@anticrm/platform'
import { translate } from '@anticrm/platform'
import { createEventDispatcher } from 'svelte'
2022-04-14 11:03:49 +00:00
import { Icon, Label } from '..'
export let placeholder: IntlString | undefined = undefined
export let placeholderParam: any | undefined = undefined
export let searchable: boolean = false
2022-04-29 05:27:17 +00:00
export let value: Array<{ id: number | string; icon: Asset; label?: IntlString; text?: string }>
let search: string = ''
let phTraslate: string = ''
2022-04-29 05:27:17 +00:00
$: if (placeholder) {
translate(placeholder, placeholderParam ?? {}).then((res) => {
phTraslate = res
})
}
const dispatch = createEventDispatcher()
</script>
<div class="selectPopup">
{#if searchable}
<div class="header">
2022-04-29 05:27:17 +00:00
<input type="text" bind:value={search} placeholder={phTraslate} on:input={(ev) => {}} on:change />
</div>
{/if}
<div class="scroll">
<div class="box">
2022-04-29 05:27:17 +00:00
{#each value.filter((el) => (el.label ?? el.text ?? '').toLowerCase().includes(search.toLowerCase())) as item}
<button
class="menu-item"
on:click={() => {
dispatch('close', item.id)
}}
>
2022-04-14 11:03:49 +00:00
<div class="icon"><Icon icon={item.icon} size={'small'} /></div>
<span class="label">
{#if item.label}
<Label label={item.label} />
{:else if item.text}
<span>{item.text}</span>
{/if}
</span>
</button>
{/each}
</div>
</div>
</div>