Make any drawer expandable

This commit is contained in:
Andrew Kingston 2024-03-06 13:59:20 +00:00
parent 84fb0dd9de
commit d38a6ed0d3
3 changed files with 42 additions and 29 deletions

View File

@ -61,6 +61,7 @@
import Button from "../Button/Button.svelte" import Button from "../Button/Button.svelte"
import { setContext, createEventDispatcher, onDestroy } from "svelte" import { setContext, createEventDispatcher, onDestroy } from "svelte"
import { generate } from "shortid" import { generate } from "shortid"
import { Icon, ActionButton } from "@budibase/bbui"
export let title export let title
export let forceModal = false export let forceModal = false
@ -184,10 +185,24 @@
{style} {style}
> >
<header> <header>
<div class="text">{title || "Bindings"}</div> {#if $$slots.title}
<slot name="title" />
{:else}
<div class="text">{title || "Bindings"}</div>
{/if}
<div class="buttons"> <div class="buttons">
<Button secondary quiet on:click={hide}>Cancel</Button> <Button secondary quiet on:click={hide}>Cancel</Button>
<slot name="buttons" /> <slot name="buttons" />
{#if $resizable}
<ActionButton
size="M"
quiet
selected={$modal}
on:click={() => modal.set(!$modal)}
>
<Icon name={$modal ? "Minimize" : "Maximize"} size="S" />
</ActionButton>
{/if}
</div> </div>
</header> </header>
<slot name="body" /> <slot name="body" />
@ -274,4 +289,8 @@
align-items: center; align-items: center;
gap: var(--spacing-m); gap: var(--spacing-m);
} }
.buttons :global(.icon) {
width: 16px;
display: flex;
}
</style> </style>

View File

@ -30,7 +30,6 @@
import formatHighlight from "json-format-highlight" import formatHighlight from "json-format-highlight"
import { capitalise } from "helpers" import { capitalise } from "helpers"
import { Utils } from "@budibase/frontend-core" import { Utils } from "@budibase/frontend-core"
import { get } from "svelte/store"
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
@ -46,7 +45,6 @@
export let autofocusEditor = false export let autofocusEditor = false
export let placeholder = null export let placeholder = null
const drawerContext = getContext("drawer")
const Modes = { const Modes = {
Text: "Text", Text: "Text",
JavaScript: "JavaScript", JavaScript: "JavaScript",
@ -66,10 +64,8 @@
let insertAtPos let insertAtPos
let targetMode = null let targetMode = null
let expressionResult let expressionResult
let drawerIsModal
let evaluating = false let evaluating = false
$: drawerContext?.modal.subscribe(val => (drawerIsModal = val))
$: editorModeOptions = getModeOptions(allowHBS, allowJS) $: editorModeOptions = getModeOptions(allowHBS, allowJS)
$: sidePanelOptions = getSidePanelOptions( $: sidePanelOptions = getSidePanelOptions(
bindings, bindings,
@ -239,18 +235,22 @@
<div class="binding-panel"> <div class="binding-panel">
<div class="main"> <div class="main">
<div class="tabs"> <div class="tabs">
<div class="editor-tabs"> {#if $$slots.tabs}
{#each editorModeOptions as editorMode} <slot name="tabs" />
<ActionButton {:else}
size="M" <div class="editor-tabs">
quiet {#each editorModeOptions as editorMode}
selected={mode === editorMode} <ActionButton
on:click={() => changeMode(editorMode)} size="M"
> quiet
{capitalise(editorMode)} selected={mode === editorMode}
</ActionButton> on:click={() => changeMode(editorMode)}
{/each} >
</div> {capitalise(editorMode)}
</ActionButton>
{/each}
</div>
{/if}
<div class="side-tabs"> <div class="side-tabs">
{#each sidePanelOptions as panel} {#each sidePanelOptions as panel}
<ActionButton <ActionButton
@ -262,16 +262,6 @@
<Icon name={panel} size="S" /> <Icon name={panel} size="S" />
</ActionButton> </ActionButton>
{/each} {/each}
{#if drawerContext && get(drawerContext.resizable)}
<ActionButton
size="M"
quiet
selected={drawerIsModal}
on:click={() => drawerContext.modal.set(!drawerIsModal)}
>
<Icon name={drawerIsModal ? "Minimize" : "Maximize"} size="S" />
</ActionButton>
{/if}
</div> </div>
</div> </div>
<div class="editor"> <div class="editor">

View File

@ -1,5 +1,5 @@
<script> <script>
import { Button, Drawer } from "@budibase/bbui" import { Button, Drawer, Input } from "@budibase/bbui"
import BindingPanel from "components/common/bindings/BindingPanel.svelte" import BindingPanel from "components/common/bindings/BindingPanel.svelte"
import { decodeJSBinding, encodeJSBinding } from "@budibase/string-templates" import { decodeJSBinding, encodeJSBinding } from "@budibase/string-templates"
import { snippetStore } from "stores/builder" import { snippetStore } from "stores/builder"
@ -47,7 +47,11 @@
placeholder="return function(input) &#10100; ... &#10101;" placeholder="return function(input) &#10100; ... &#10101;"
value={code} value={code}
on:change={e => (code = e.detail)} on:change={e => (code = e.detail)}
/> >
<div slot="tabs">
<Input placeholder="Name" />
</div>
</BindingPanel>
{/key} {/key}
</svelte:fragment> </svelte:fragment>
</Drawer> </Drawer>