1
0
Fork 0
mirror of synced 2024-07-05 14:31:17 +12:00

Add preview device selection buttons and pass device preview down to client app

This commit is contained in:
Andrew Kingston 2021-09-07 16:02:11 +01:00
parent d371344d9b
commit fbbeccc0a1
5 changed files with 56 additions and 2 deletions

View file

@ -56,6 +56,7 @@ const INITIAL_FRONTEND_STATE = {
clientLibPath: "", clientLibPath: "",
theme: "", theme: "",
customTheme: {}, customTheme: {},
previewDevice: "desktop",
} }
export const getFrontendStore = () => { export const getFrontendStore = () => {
@ -230,6 +231,12 @@ export const getFrontendStore = () => {
await store.actions.layouts.save(selectedAsset) await store.actions.layouts.save(selectedAsset)
} }
}, },
setDevice: device => {
store.update(state => {
state.previewDevice = device
return state
})
},
}, },
layouts: { layouts: {
select: layoutId => { select: layoutId => {

View file

@ -50,6 +50,7 @@
previewType: $store.currentFrontEndType, previewType: $store.currentFrontEndType,
theme: $store.theme, theme: $store.theme,
customTheme: $store.customTheme, customTheme: $store.customTheme,
previewDevice: $store.previewDevice,
} }
// Saving pages and screens to the DB causes them to have _revs. // Saving pages and screens to the DB causes them to have _revs.
@ -140,11 +141,12 @@
</div> </div>
{/if} {/if}
<iframe <iframe
style="height: 100%; width: 100%"
title="componentPreview" title="componentPreview"
bind:this={iframe} bind:this={iframe}
srcdoc={template} srcdoc={template}
class:hidden={loading || error} class:hidden={loading || error}
class:tablet={$store.previewDevice === "tablet"}
class:mobile={$store.previewDevice === "mobile"}
/> />
</div> </div>
<ConfirmDialog <ConfirmDialog
@ -160,6 +162,8 @@
.component-container { .component-container {
grid-row-start: middle; grid-row-start: middle;
grid-column-start: middle; grid-column-start: middle;
display: grid;
place-items: center;
position: relative; position: relative;
overflow: hidden; overflow: hidden;
margin: auto; margin: auto;
@ -200,4 +204,20 @@
font-weight: 400; font-weight: 400;
margin: 0; margin: 0;
} }
iframe {
width: 100%;
height: 100%;
}
/*iframe.tablet {*/
/* width: 1024px;*/
/* height: 768px;*/
/*}*/
/*iframe.mobile {*/
/* width: calc(390px + 16px);*/
/* height: calc(844px + 16px);*/
/*}*/
/*iframe.mobile :global(#spectrum-root) {*/
/* border-radius: 12px;*/
/*}*/
</style> </style>

View file

@ -0,0 +1,22 @@
<script>
import { ActionGroup, ActionButton } from "@budibase/bbui"
import { store } from "builderStore"
</script>
<ActionGroup compact>
<ActionButton
icon="DeviceDesktop"
selected={$store.previewDevice === "desktop"}
on:click={() => store.actions.preview.setDevice("desktop")}
/>
<ActionButton
icon="DeviceTablet"
selected={$store.previewDevice === "tablet"}
on:click={() => store.actions.preview.setDevice("tablet")}
/>
<ActionButton
icon="DevicePhone"
selected={$store.previewDevice === "mobile"}
on:click={() => store.actions.preview.setDevice("mobile")}
/>
</ActionGroup>

View file

@ -67,7 +67,8 @@ export default `
previewType, previewType,
appId, appId,
theme, theme,
customTheme customTheme,
previewDevice
} = parsed } = parsed
// Set some flags so the app knows we're in the builder // Set some flags so the app knows we're in the builder
@ -80,6 +81,7 @@ export default `
window["##BUDIBASE_PREVIEW_TYPE##"] = previewType window["##BUDIBASE_PREVIEW_TYPE##"] = previewType
window["##BUDIBASE_PREVIEW_THEME##"] = theme window["##BUDIBASE_PREVIEW_THEME##"] = theme
window["##BUDIBASE_PREVIEW_CUSTOM_THEME##"] = customTheme window["##BUDIBASE_PREVIEW_CUSTOM_THEME##"] = customTheme
window["##BUDIBASE_PREVIEW_DEVICE##"] = previewDevice
// Initialise app // Initialise app
try { try {

View file

@ -15,6 +15,7 @@
import { get } from "svelte/store" import { get } from "svelte/store"
import AppThemeSelect from "components/design/AppPreview/AppThemeSelect.svelte" import AppThemeSelect from "components/design/AppPreview/AppThemeSelect.svelte"
import ThemeEditor from "components/design/AppPreview/ThemeEditor.svelte" import ThemeEditor from "components/design/AppPreview/ThemeEditor.svelte"
import DevicePreviewSelect from "components/design/AppPreview/DevicePreviewSelect.svelte"
// Cache previous values so we don't update the URL more than necessary // Cache previous values so we don't update the URL more than necessary
let previousType let previousType
@ -151,6 +152,7 @@
{#if $currentAsset} {#if $currentAsset}
<div class="preview-header"> <div class="preview-header">
<ComponentSelectionList /> <ComponentSelectionList />
<DevicePreviewSelect />
{#if $store.clientFeatures.customThemes} {#if $store.clientFeatures.customThemes}
<ThemeEditor /> <ThemeEditor />
{:else if $store.clientFeatures.spectrumThemes} {:else if $store.clientFeatures.spectrumThemes}
@ -209,6 +211,7 @@
flex-direction: row; flex-direction: row;
justify-content: flex-start; justify-content: flex-start;
align-items: center; align-items: center;
gap: 1rem;
} }
.preview-header > :global(*) { .preview-header > :global(*) {
flex: 0 0 auto; flex: 0 0 auto;