Move add component button from above preview to new floating animated button on top of preview

This commit is contained in:
Andrew Kingston 2022-07-25 11:42:18 +01:00
parent 8296c8f996
commit 4657ea6f11
2 changed files with 45 additions and 1 deletions

View File

@ -3,6 +3,7 @@
import { onMount, onDestroy } from "svelte" import { onMount, onDestroy } from "svelte"
import { import {
store, store,
selectedComponent,
selectedScreen, selectedScreen,
selectedLayout, selectedLayout,
currentAsset, currentAsset,
@ -14,6 +15,7 @@
Layout, Layout,
Heading, Heading,
Body, Body,
Icon,
notifications, notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import ErrorSVG from "@budibase/frontend-core/assets/error.svg?raw" import ErrorSVG from "@budibase/frontend-core/assets/error.svg?raw"
@ -96,6 +98,9 @@
$: json = JSON.stringify(previewData) $: json = JSON.stringify(previewData)
$: refreshContent(json) $: refreshContent(json)
// Determine if the add component menu is active
$: isAddingComponent = $isActive(`./components/${$selectedComponent._id}/new`)
// Update the iframe with the builder info to render the correct preview // Update the iframe with the builder info to render the correct preview
const refreshContent = message => { const refreshContent = message => {
if (iframe) { if (iframe) {
@ -219,6 +224,16 @@
idToDelete = null idToDelete = null
} }
const toggleAddComponent = () => {
if (isAddingComponent) {
$goto(`../${$selectedScreen._id}/components/${$selectedComponent._id}`)
} else {
$goto(
`../${$selectedScreen._id}/components/${$selectedComponent._id}/new`
)
}
}
onMount(() => { onMount(() => {
window.addEventListener("message", receiveMessage) window.addEventListener("message", receiveMessage)
if (!$store.clientFeatures.messagePassing) { if (!$store.clientFeatures.messagePassing) {
@ -282,6 +297,13 @@
class:tablet={$store.previewDevice === "tablet"} class:tablet={$store.previewDevice === "tablet"}
class:mobile={$store.previewDevice === "mobile"} class:mobile={$store.previewDevice === "mobile"}
/> />
<div
class="add-component"
class:active={isAddingComponent}
on:click={toggleAddComponent}
>
<Icon size="XL" name="Add">Component</Icon>
</div>
</div> </div>
<ConfirmDialog <ConfirmDialog
bind:this={confirmDeleteDialog} bind:this={confirmDeleteDialog}
@ -343,4 +365,26 @@
width: 100%; width: 100%;
height: 100%; height: 100%;
} }
.add-component {
position: absolute;
bottom: 20px;
right: 20px;
width: 60px;
height: 60px;
border-radius: 50%;
background: var(--spectrum-global-color-blue-500);
display: grid;
place-items: center;
color: white;
box-shadow: 1px 3px 8px 0 rgba(0, 0, 0, 0.3);
cursor: pointer;
transition: transform ease-out 300ms, background ease-out 130ms;
}
.add-component:hover {
background: var(--spectrum-global-color-blue-600);
}
.add-component.active {
transform: rotate(-45deg);
}
</style> </style>

View File

@ -151,7 +151,7 @@
}) })
</script> </script>
<div class="new-component" transition:fly|local={{ x: 260 }}> <div class="new-component" transition:fly|local={{ x: 260, duration: 300 }}>
<Panel <Panel
title="Add component" title="Add component"
showCloseButton showCloseButton