mirror of
https://github.com/hcengineering/platform.git
synced 2025-04-29 11:43:49 +00:00
Add scroll in Popups (#233)
Signed-off-by: Alexander Platov <sas_lord@mail.ru>
This commit is contained in:
parent
8d4d052a5d
commit
d39f7f7d61
@ -23,6 +23,7 @@
|
|||||||
import { createQuery } from '../utils'
|
import { createQuery } from '../utils'
|
||||||
|
|
||||||
export let _class: Ref<Class<Space>>
|
export let _class: Ref<Class<Space>>
|
||||||
|
export let maxHeight: number = 0
|
||||||
|
|
||||||
let search: string = ''
|
let search: string = ''
|
||||||
let objects: Space[] = []
|
let objects: Space[] = []
|
||||||
@ -32,16 +33,20 @@
|
|||||||
$: query.query(_class, {}, result => { objects = result })
|
$: query.query(_class, {}, result => { objects = result })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="popup">
|
<div class="popup" style="max-height: {(maxHeight) ? maxHeight + 'px' : 'max-content'}">
|
||||||
<div class="flex-col">
|
<div class="flex-col">
|
||||||
<EditWithIcon icon={IconSearch} bind:value={search} placeholder={'Search...'} />
|
<EditWithIcon icon={IconSearch} bind:value={search} placeholder={'Search...'} />
|
||||||
<div class="label"><Label label={'SUGGESTED'} /></div>
|
<div class="label"><Label label={'SUGGESTED'} /></div>
|
||||||
</div>
|
</div>
|
||||||
{#each objects as space}
|
<div class="flex-grow scroll">
|
||||||
<button class="menu-item" on:click={() => { dispatch('close', space) }}>
|
<div class="flex-col h-full box">
|
||||||
<SpaceInfo size={'large'} value={space} />
|
{#each objects as space}
|
||||||
</button>
|
<button class="menu-item" on:click={() => { dispatch('close', space) }}>
|
||||||
{/each}
|
<SpaceInfo size={'large'} value={space} />
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@ -65,6 +70,11 @@
|
|||||||
color: var(--theme-content-dark-color);
|
color: var(--theme-content-dark-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.scroll {
|
||||||
|
overflow-y: scroll;
|
||||||
|
.box { margin-right: 1px; }
|
||||||
|
}
|
||||||
|
|
||||||
.menu-item {
|
.menu-item {
|
||||||
justify-content: start;
|
justify-content: start;
|
||||||
padding: .375rem;
|
padding: .375rem;
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
export let _class: Ref<Class<Person>>
|
export let _class: Ref<Class<Person>>
|
||||||
export let title: IntlString
|
export let title: IntlString
|
||||||
export let caption: IntlString
|
export let caption: IntlString
|
||||||
|
export let maxHeight: number = 0
|
||||||
|
|
||||||
let search: string = ''
|
let search: string = ''
|
||||||
let objects: Person[] = []
|
let objects: Person[] = []
|
||||||
@ -35,17 +36,21 @@
|
|||||||
$: query.query(_class, { name: { $like: '%'+search+'%' } }, result => { objects = result })
|
$: query.query(_class, { name: { $like: '%'+search+'%' } }, result => { objects = result })
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="popup">
|
<div class="popup" style="max-height: {(maxHeight) ? maxHeight + 'px' : 'max-content'}">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="title"><Label label={title} /></div>
|
<div class="title"><Label label={title} /></div>
|
||||||
<EditWithIcon icon={IconSearch} bind:value={search} placeholder={'Search...'} />
|
<EditWithIcon icon={IconSearch} bind:value={search} placeholder={'Search...'} />
|
||||||
<div class="caption"><Label label={caption} /></div>
|
<div class="caption"><Label label={caption} /></div>
|
||||||
</div>
|
</div>
|
||||||
{#each objects as person}
|
<div class="flex-grow scroll">
|
||||||
<button class="menu-item" on:click={() => { dispatch('close', person) }}>
|
<div class="flex-col h-full box">
|
||||||
<UserInfo size={'medium'} value={person} />
|
{#each objects as person}
|
||||||
</button>
|
<button class="menu-item" on:click={() => { dispatch('close', person) }}>
|
||||||
{/each}
|
<UserInfo size={'medium'} value={person} />
|
||||||
|
</button>
|
||||||
|
{/each}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@ -77,6 +82,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.scroll {
|
||||||
|
overflow-y: scroll;
|
||||||
|
.box { margin-right: 1px; }
|
||||||
|
}
|
||||||
|
|
||||||
.menu-item {
|
.menu-item {
|
||||||
justify-content: start;
|
justify-content: start;
|
||||||
padding: .375rem;
|
padding: .375rem;
|
||||||
|
@ -26,6 +26,7 @@ export let zIndex: number
|
|||||||
|
|
||||||
let modalHTML: HTMLElement
|
let modalHTML: HTMLElement
|
||||||
let modalOHTML: HTMLElement
|
let modalOHTML: HTMLElement
|
||||||
|
let maxHeight: number = 0
|
||||||
|
|
||||||
function close(result: any) {
|
function close(result: any) {
|
||||||
console.log('popup close result', result)
|
console.log('popup close result', result)
|
||||||
@ -36,23 +37,19 @@ function close(result: any) {
|
|||||||
$: {
|
$: {
|
||||||
if (modalHTML) {
|
if (modalHTML) {
|
||||||
if (element) {
|
if (element) {
|
||||||
|
maxHeight = 0
|
||||||
if (typeof element !== 'string') {
|
if (typeof element !== 'string') {
|
||||||
const rect = element.getBoundingClientRect()
|
const rect = element.getBoundingClientRect()
|
||||||
const rectPopup = modalHTML.getBoundingClientRect()
|
const rectPopup = modalHTML.getBoundingClientRect()
|
||||||
if (rect.bottom + rectPopup.height + 28 < document.body.clientHeight) {
|
if (rect.bottom + rectPopup.height + 28 < document.body.clientHeight) {
|
||||||
modalHTML.style.top = `calc(${rect.bottom}px + .75rem)`
|
modalHTML.style.top = `calc(${rect.bottom}px + .75rem)`
|
||||||
|
maxHeight = document.body.clientHeight - rect.bottom - 28
|
||||||
} else if (rect.top > document.body.clientHeight - rect.bottom) {
|
} else if (rect.top > document.body.clientHeight - rect.bottom) {
|
||||||
modalHTML.style.bottom = `calc(${document.body.clientHeight - rect.y}px + .75rem)`
|
modalHTML.style.bottom = `calc(${document.body.clientHeight - rect.y}px + .75rem)`
|
||||||
if (rectPopup.height > rect.top - 28) {
|
maxHeight = rect.top - 28
|
||||||
modalHTML.style.top = '1rem'
|
|
||||||
modalHTML.style.height = rect.top - 28 + 'px'
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
modalHTML.style.top = `calc(${rect.bottom}px + .75rem)`
|
modalHTML.style.top = `calc(${rect.bottom}px + .75rem)`
|
||||||
if (rectPopup.height > document.body.clientHeight - rect.bottom - 28) {
|
maxHeight = document.body.clientHeight - rect.bottom - 28
|
||||||
modalHTML.style.bottom = '1rem'
|
|
||||||
modalHTML.style.height = document.body.clientHeight - rect.bottom - 28 + 'px'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (rect.left + rectPopup.width + 16 > document.body.clientWidth) {
|
if (rect.left + rectPopup.width + 16 > document.body.clientWidth) {
|
||||||
modalHTML.style.left = ''
|
modalHTML.style.left = ''
|
||||||
@ -85,7 +82,7 @@ $: {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="popup" bind:this={modalHTML} style={`z-index: ${zIndex + 1};`}>
|
<div class="popup" bind:this={modalHTML} style={`z-index: ${zIndex + 1};`}>
|
||||||
<svelte:component this={is} {...props} on:close={ (ev) => close(ev.detail) } />
|
<svelte:component this={is} {...props} {maxHeight} on:close={ (ev) => close(ev.detail) } />
|
||||||
</div>
|
</div>
|
||||||
<div bind:this={modalOHTML} class="modal-overlay" style={`z-index: ${zIndex};`} on:click={() => close(undefined)} />
|
<div bind:this={modalOHTML} class="modal-overlay" style={`z-index: ${zIndex};`} on:click={() => close(undefined)} />
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user