1
0
Fork 0
mirror of synced 2024-09-20 19:33:10 +12:00

Further refactoring to grid nested layouts

This commit is contained in:
Andrew Kingston 2024-07-31 13:58:29 +01:00
parent fc2fb81205
commit 0ea9b157c7
No known key found for this signature in database
8 changed files with 50 additions and 31 deletions

View file

@ -200,11 +200,12 @@
// Build up full styles and split them into variables and non-variables // Build up full styles and split them into variables and non-variables
$: baseStyles = getBaseStyles(definition) $: baseStyles = getBaseStyles(definition)
$: parsedStyles = parseStyles({ $: styles = {
...baseStyles, ...baseStyles,
...instance._styles?.normal, ...instance._styles?.normal,
...ephemeralStyles, ...ephemeralStyles,
}) }
$: parsedStyles = parseStyles(styles)
$: wrapperCSS = buildStyleString(parsedStyles.variables) $: wrapperCSS = buildStyleString(parsedStyles.variables)
// Update component context // Update component context
@ -214,6 +215,7 @@
styles: { styles: {
...instance._styles, ...instance._styles,
normal: parsedStyles.nonVariables, normal: parsedStyles.nonVariables,
variables: parsedStyles.variables,
custom: customCSS, custom: customCSS,
id, id,
empty: emptyState, empty: emptyState,

View file

@ -95,7 +95,7 @@
/* Ensure all top level children have grid styles applied */ /* Ensure all top level children have grid styles applied */
.grid :global(> .component) { .grid :global(> .component) {
display: flex; display: flex;
overflow: hidden; overflow: auto;
/* On desktop, use desktop metadata and fall back to mobile */ /* On desktop, use desktop metadata and fall back to mobile */
/* Position vars */ /* Position vars */

View file

@ -1,14 +1,16 @@
<script> <script>
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
import { builderStore, componentStore } from "stores" import { builderStore } from "stores"
import { getGridVarValue } from "utils/grid" import { getGridVarValue } from "utils/grid"
export let style export let style
export let value export let value
export let icon export let icon
export let title export let title
export let gridStyles
export let componentId
$: currentValue = getGridVarValue($componentStore.selectedComponent, style) $: currentValue = getGridVarValue(gridStyles, style)
$: active = currentValue === value $: active = currentValue === value
</script> </script>
@ -18,10 +20,7 @@
{title} {title}
class:active class:active
on:click={() => { on:click={() => {
builderStore.actions.updateStyles( builderStore.actions.updateStyles({ [style]: value }, componentId)
{ [style]: value },
$componentStore.selectedComponent._id
)
}} }}
> >
<Icon name={icon} size="S" /> <Icon name={icon} size="S" />

View file

@ -20,11 +20,12 @@
// TODO: respect dependsOn keys // TODO: respect dependsOn keys
$: id = $builderStore.selectedComponentId $: componentId = $builderStore.selectedComponentId
$: parent = findComponentParent($builderStore.screen.props, id) $: component = $componentStore.selectedComponent
$: instance = componentStore.actions.getComponentInstance(id)
$: state = $instance?.state
$: definition = $componentStore.selectedComponentDefinition $: definition = $componentStore.selectedComponentDefinition
$: parent = findComponentParent($builderStore.screen.props, componentId)
$: instance = componentStore.actions.getComponentInstance(componentId)
$: state = $instance?.state
$: showBar = $: showBar =
definition?.showSettingsBar !== false && definition?.showSettingsBar !== false &&
!$dndIsDragging && !$dndIsDragging &&
@ -36,12 +37,13 @@
} }
} }
$: settings = getBarSettings(definition) $: settings = getBarSettings(definition)
$: isRoot = id === $builderStore.screen?.props?._id $: isRoot = componentId === $builderStore.screen?.props?._id
$: insideGrid = $: insideGrid =
parent?._component.endsWith("/container") && parent.layout === "grid" parent?._component.endsWith("/container") && parent.layout === "grid"
$: showGridStyles = insideGrid && definition?.grid?.showControls !== false $: showGridStyles = insideGrid && definition?.grid?.showControls !== false
$: gridHAlignVar = $getGridVar("h-align") $: gridHAlignVar = $getGridVar("h-align")
$: gridVAlignVar = $getGridVar("v-align") $: gridVAlignVar = $getGridVar("v-align")
$: gridStyles = $state?.styles?.variables
const getBarSettings = definition => { const getBarSettings = definition => {
let allSettings = [] let allSettings = []
@ -141,7 +143,7 @@
{#if showBar} {#if showBar}
<div <div
class="bar" class="bar"
style="top: {top}px; left: {left}px;" style="top:{top}px; left:{left}px;"
bind:this={self} bind:this={self}
class:visible={measured} class:visible={measured}
> >
@ -151,24 +153,32 @@
value="start" value="start"
icon="AlignLeft" icon="AlignLeft"
title="Align left" title="Align left"
{gridStyles}
{componentId}
/> />
<GridStylesButton <GridStylesButton
style={gridHAlignVar} style={gridHAlignVar}
value="center" value="center"
icon="AlignCenter" icon="AlignCenter"
title="Align center" title="Align center"
{gridStyles}
{componentId}
/> />
<GridStylesButton <GridStylesButton
style={gridHAlignVar} style={gridHAlignVar}
value="end" value="end"
icon="AlignRight" icon="AlignRight"
title="Align right" title="Align right"
{gridStyles}
{componentId}
/> />
<GridStylesButton <GridStylesButton
style={gridHAlignVar} style={gridHAlignVar}
value="stretch" value="stretch"
icon="MoveLeftRight" icon="MoveLeftRight"
title="Stretch horizontally" title="Stretch horizontally"
{gridStyles}
{componentId}
/> />
<div class="divider" /> <div class="divider" />
<GridStylesButton <GridStylesButton
@ -176,24 +186,32 @@
value="start" value="start"
icon="AlignTop" icon="AlignTop"
title="Align top" title="Align top"
{gridStyles}
{componentId}
/> />
<GridStylesButton <GridStylesButton
style={gridVAlignVar} style={gridVAlignVar}
value="center" value="center"
icon="AlignMiddle" icon="AlignMiddle"
title="Align middle" title="Align middle"
{gridStyles}
{componentId}
/> />
<GridStylesButton <GridStylesButton
style={gridVAlignVar} style={gridVAlignVar}
value="end" value="end"
icon="AlignBottom" icon="AlignBottom"
title="Align bottom" title="Align bottom"
{gridStyles}
{componentId}
/> />
<GridStylesButton <GridStylesButton
style={gridVAlignVar} style={gridVAlignVar}
value="stretch" value="stretch"
icon="MoveUpDown" icon="MoveUpDown"
title="Stretch vertically" title="Stretch vertically"
{gridStyles}
{componentId}
/> />
<div class="divider" /> <div class="divider" />
{/if} {/if}
@ -206,6 +224,7 @@
value={option.value} value={option.value}
icon={option.barIcon} icon={option.barIcon}
title={option.barTitle || option.label} title={option.barTitle || option.label}
{component}
/> />
{/each} {/each}
{:else} {:else}

View file

@ -1,18 +1,19 @@
<script> <script>
import { Icon } from "@budibase/bbui" import { Icon } from "@budibase/bbui"
import { builderStore, componentStore } from "stores" import { builderStore } from "stores"
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
export let prop export let prop
export let value export let value
export let icon export let icon
export let title export let title
export let rotate = false
export let bool = false export let bool = false
export let active = false export let active = false
export let component
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
$: currentValue = $componentStore.selectedComponent?.[prop]
$: currentValue = component?.[prop]
$: active = prop && (bool ? !!currentValue : currentValue === value) $: active = prop && (bool ? !!currentValue : currentValue === value)
</script> </script>
@ -20,7 +21,6 @@
<!-- svelte-ignore a11y-click-events-have-key-events --> <!-- svelte-ignore a11y-click-events-have-key-events -->
<div <div
{title} {title}
class:rotate
class:active class:active
on:click={() => { on:click={() => {
if (prop) { if (prop) {
@ -50,7 +50,4 @@
background-color: rgba(13, 102, 208, 0.1); background-color: rgba(13, 102, 208, 0.1);
color: var(--spectrum-global-color-blue-600); color: var(--spectrum-global-color-blue-600);
} }
.rotate {
transform: rotate(90deg);
}
</style> </style>

View file

@ -1,10 +1,11 @@
<script> <script>
import { ColorPicker } from "@budibase/bbui" import { ColorPicker } from "@budibase/bbui"
import { builderStore, componentStore } from "stores" import { builderStore } from "stores"
export let prop export let prop
export let component
$: currentValue = $componentStore.selectedComponent?.[prop] $: currentValue = component?.[prop]
</script> </script>
<div> <div>

View file

@ -1,12 +1,13 @@
<script> <script>
import { Select } from "@budibase/bbui" import { Select } from "@budibase/bbui"
import { builderStore, componentStore } from "stores" import { builderStore } from "stores"
export let prop export let prop
export let options export let options
export let label export let label
export let component
$: currentValue = $componentStore.selectedComponent?.[prop] $: currentValue = component?.[prop]
</script> </script>
<div> <div>

View file

@ -1,5 +1,5 @@
import { builderStore } from "stores" import { builderStore, componentStore } from "stores"
import { derived, get } from "svelte/store" import { derived, get, readable } from "svelte/store"
/** /**
* We use CSS variables on components to control positioning and layout of * We use CSS variables on components to control positioning and layout of
@ -91,13 +91,13 @@ export const getBaseGridVars = definition => {
} }
// Gets the current value of a certain grid CSS variable for a component // Gets the current value of a certain grid CSS variable for a component
export const getGridVarValue = (component, variable) => { export const getGridVarValue = (styles, variable) => {
// Try the desired variable // Try the desired variable
let val = component?._styles?.normal?.[variable] let val = styles?.[variable]
// Otherwise try the other device variables // Otherwise try the other device variables
if (!val) { if (!val) {
val = component?._styles?.normal?.[getOtherDeviceGridVar(variable)] val = styles?.[getOtherDeviceGridVar(variable)]
} }
// Otherwise use the default // Otherwise use the default