budibase/packages/builder/src/components/common/NavHeader.svelte

149 lines
2.6 KiB
Svelte
Raw Normal View History

<script>
import { tick } from "svelte"
import { Icon, Body } from "@budibase/bbui"
2023-11-09 15:44:34 +01:00
import { keyUtils } from "helpers/keyUtils"
export let title
export let placeholder
2023-11-09 15:12:17 +01:00
export let value
let searchInput
let search = false
const openSearch = async () => {
search = true
await tick()
searchInput.focus()
}
const closeSearch = async () => {
search = false
2023-11-09 15:14:58 +01:00
value = ""
}
const onKeyDown = e => {
if (e.key === "Escape") {
closeSearch()
}
}
2023-11-09 15:37:01 +01:00
const handleAddButton = () => {
if (search) {
closeSearch()
} else {
alert("todo")
}
}
</script>
<svelte:window on:keydown={onKeyDown} />
<div class="header" class:search>
<input
readonly={!search}
2023-11-09 15:12:17 +01:00
bind:value
bind:this={searchInput}
2023-11-09 13:11:29 +01:00
class="searchBox"
class:hide={!search}
{placeholder}
/>
2023-11-09 12:53:47 +01:00
<div class="title" class:hide={search}>
<Body size="S">{title}</Body>
</div>
2023-11-09 15:44:34 +01:00
<div
on:click={openSearch}
on:keydown={keyUtils.handleEnter(openSearch)}
class="searchButton"
class:hide={search}
>
<Icon size="S" name="Search" />
</div>
2023-11-09 15:37:01 +01:00
2023-11-09 15:44:34 +01:00
<div
on:click={handleAddButton}
on:keydown={keyUtils.handleEnter(handleAddButton)}
class="addButton"
class:rotate={search}
>
2023-11-09 15:37:01 +01:00
<Icon name="Add" />
</div>
</div>
<style>
.search {
transition: height 300ms ease-out;
max-height: none;
}
.header {
flex-shrink: 0;
flex-direction: row;
position: relative;
height: 50px;
width: 100%;
box-sizing: border-box;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 2px solid transparent;
transition: border-bottom 130ms ease-out;
2023-11-09 15:37:01 +01:00
gap: var(--spacing-l);
}
2023-11-09 13:11:29 +01:00
.searchBox {
font-family: var(--font-sans);
color: var(--ink);
background-color: transparent;
border: none;
font-size: var(--spectrum-alias-font-size-default);
2023-11-09 13:11:29 +01:00
display: flex;
}
2023-11-09 13:11:29 +01:00
.searchBox:focus {
outline: none;
}
2023-11-09 13:11:29 +01:00
.searchBox::placeholder {
color: var(--spectrum-global-color-gray-600);
}
.title {
display: flex;
align-items: center;
height: 100%;
box-sizing: border-box;
flex: 1;
opacity: 1;
z-index: 1;
}
.searchButton {
color: var(--grey-7);
cursor: pointer;
opacity: 1;
}
.searchButton:hover {
color: var(--ink);
}
.hide {
opacity: 0;
pointer-events: none;
2023-11-09 13:11:29 +01:00
display: none !important;
}
2023-11-09 15:37:01 +01:00
.addButton {
2023-11-09 13:11:29 +01:00
display: flex;
2023-11-09 15:37:01 +01:00
transition: transform 300ms ease-out;
2023-11-09 12:53:47 +01:00
color: var(--grey-7);
cursor: pointer;
}
2023-11-09 15:37:01 +01:00
.addButton:hover {
2023-11-09 12:53:47 +01:00
color: var(--ink);
}
2023-11-09 15:37:01 +01:00
.rotate {
transform: rotate(45deg);
}
</style>