Add screen width setting with backwards compatibility

This commit is contained in:
Andrew Kingston 2022-05-10 14:54:53 +01:00
parent 6922852d01
commit 78b5e7707d
3 changed files with 41 additions and 12 deletions

View File

@ -9,6 +9,7 @@
Toggle, Toggle,
Checkbox, Checkbox,
Banner, Banner,
Select,
notifications, notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import PropertyControl from "components/design/settings/controls/PropertyControl.svelte" import PropertyControl from "components/design/settings/controls/PropertyControl.svelte"
@ -135,6 +136,15 @@
text: "Show navigation", text: "Show navigation",
}, },
}, },
{
key: "width",
label: "Width",
control: Select,
props: {
options: ["Extra small", "Small", "Medium", "Large", "Max"],
placeholder: "Default",
},
},
] ]
const removeCustomLayout = async () => { const removeCustomLayout = async () => {

View File

@ -23,17 +23,19 @@
export let navBackground export let navBackground
export let navTextColor export let navTextColor
export let navWidth export let navWidth
export let pageWidth
const NavigationClasses = { const NavigationClasses = {
Top: "top", Top: "top",
Left: "left", Left: "left",
None: "none", None: "none",
} }
const WidthStyles = { const WidthClasses = {
Max: "100%", Max: "max",
Large: "1400px", Large: "l",
Medium: "1100px", Medium: "m",
Small: "800px", Small: "s",
"Extra small": "xs",
} }
// Set some layout context. This isn't used in bindings but can be used // Set some layout context. This isn't used in bindings but can be used
@ -48,8 +50,8 @@
$: validLinks = links?.filter(link => link.text && link.url) || [] $: validLinks = links?.filter(link => link.text && link.url) || []
$: typeClass = NavigationClasses[navigation] || NavigationClasses.None $: typeClass = NavigationClasses[navigation] || NavigationClasses.None
$: navWidthStyle = WidthStyles[navWidth || width] || WidthStyles.Large $: navWidthClass = WidthClasses[navWidth || width] || WidthClasses.Large
$: pageWidthStyle = WidthStyles[width] || WidthStyles.Max $: pageWidthClass = WidthClasses[pageWidth || width] || WidthClasses.Large
$: navStyle = getNavStyle( $: navStyle = getNavStyle(
navBackground, navBackground,
navTextColor, navTextColor,
@ -116,7 +118,7 @@
on:click={$builderStore.inBuilder ? builderStore.actions.clickNav : null} on:click={$builderStore.inBuilder ? builderStore.actions.clickNav : null}
style={navStyle} style={navStyle}
> >
<div class="nav nav--{typeClass}" style={`width: ${navWidthStyle};`}> <div class="nav nav--{typeClass} size--{navWidthClass}">
<div class="nav-header"> <div class="nav-header">
{#if validLinks?.length} {#if validLinks?.length}
<div class="burger"> <div class="burger">
@ -183,7 +185,7 @@
</div> </div>
{/if} {/if}
<div class="main-wrapper"> <div class="main-wrapper">
<div class="main" style={`--pageWidth: ${pageWidthStyle};`}> <div class="main size--{pageWidthClass}">
<slot /> <slot />
</div> </div>
</div> </div>
@ -274,11 +276,25 @@
max-width: 100%; max-width: 100%;
position: relative; position: relative;
padding: 32px; padding: 32px;
width: 100%;
} }
.layout--none .main { .layout--none .main {
padding: 0; padding: 0;
} }
.size--xs {
width: 400px;
}
.size--s {
width: 800px;
}
.size--m {
width: 1100px;
}
.size--l {
width: 1400px;
}
.size--max {
width: 100%;
}
/* Nav components */ /* Nav components */
.burger { .burger {

View File

@ -44,10 +44,13 @@ const createScreenStore = () => {
if (!activeLayout) { if (!activeLayout) {
let navigationSettings = { let navigationSettings = {
navigation: "None", navigation: "None",
pageWidth: activeScreen?.width || "Large",
} }
if (activeScreen?.showNavigation) { if (activeScreen?.showNavigation) {
navigationSettings = navigationSettings = {
$builderStore.navigation || $appStore.application?.navigation || {} ...navigationSettings,
...($builderStore.navigation || $appStore.application?.navigation),
}
// Default navigation to top // Default navigation to top
if (!navigationSettings.navigation) { if (!navigationSettings.navigation) {