budibase/packages/standard-components/src/Container.svelte

123 lines
2.6 KiB
Svelte
Raw Normal View History

<script>
2020-02-25 16:21:23 +01:00
import { cssVars, createClasses } from "./cssVars"
2020-02-21 12:43:21 +01:00
2020-02-25 16:21:23 +01:00
export let className = ""
export let onLoad
export let type = "div"
2020-02-25 16:21:23 +01:00
export let backgroundColor
export let color
export let borderWidth
export let borderColor
export let borderStyle
export let _bb
2020-02-21 12:43:21 +01:00
2020-02-25 16:21:23 +01:00
let containerElement
let hasLoaded
let currentChildren
2020-02-21 12:43:21 +01:00
2020-02-25 16:21:23 +01:00
$: cssVariables = {
backgroundColor,
color,
borderWidth,
borderColor,
borderStyle,
}
$: classes = `${createClasses(cssVariables)} ${className}`
2020-02-21 12:43:21 +01:00
2020-02-25 16:21:23 +01:00
$: {
if (containerElement) {
_bb.attachChildren(containerElement)
if (!hasLoaded) {
_bb.call(onLoad)
hasLoaded = true
}
}
}
</script>
2020-02-25 16:21:23 +01:00
{#if type === 'div'}
<div
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'header'}
<header
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'main'}
<main
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'footer'}
<footer
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'aside'}
<aside
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'summary'}
<summary
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'details'}
<details
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'article'}
<article
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'nav'}
<nav
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'mark'}
<mark
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'figure'}
<figure
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'figcaption'}
<figcaption
class={classes}
bind:this={containerElement}
use:cssVars={cssVariables} />
{:else if type === 'paragraph'}
<p class={classes} bind:this={containerElement} use:cssVars={cssVariables} />
{/if}
2020-02-21 12:43:21 +01:00
<style>
2020-02-25 16:21:23 +01:00
.backgroundColor {
background-color: var(--backgroundColor);
}
2020-02-21 12:43:21 +01:00
2020-02-25 16:21:23 +01:00
.color {
color: var(--color);
}
2020-02-21 12:43:21 +01:00
2020-02-25 16:21:23 +01:00
.borderColor {
border-color: var(--borderColor);
}
2020-02-21 12:43:21 +01:00
2020-02-25 16:21:23 +01:00
.borderWidth {
border-width: var(--borderWidth);
}
2020-02-21 12:43:21 +01:00
2020-02-25 16:21:23 +01:00
.borderStyle {
border-style: var(--borderStyle);
}
2020-02-21 12:43:21 +01:00
</style>