components changes

This commit is contained in:
Michael Shanks 2020-02-21 11:43:21 +00:00
parent 548c8bb305
commit 95dab52619
8 changed files with 152 additions and 43 deletions

View File

@ -24,6 +24,7 @@
}, },
"Button": { "Button": {
"name": "Button", "name": "Button",
"children": false,
"description": "A Material Design button with different variations. It renders as an anchor if href is passed to it.", "description": "A Material Design button with different variations. It renders as an anchor if href is passed to it.",
"props": { "props": {
"onClick": "event", "onClick": "event",

View File

@ -142,7 +142,11 @@
"props": { "props": {
"url": "string", "url": "string",
"openInNewTab": "bool", "openInNewTab": "bool",
"text": "string" "text": "string",
"color": "string",
"hoverColor": "string",
"underline": "bool",
"fontSize": "string"
} }
}, },
"image": { "image": {
@ -179,7 +183,27 @@
"summary" "summary"
], ],
"default": "div" "default": "div"
},
"backgroundColor": "string",
"color": "string",
"borderWidth": "string",
"borderColor": "string",
"borderStyle": {
"type":"options",
"options": [
"none",
"solid",
"dotted",
"dashed",
"double",
"groove",
"ridge",
"inset",
"outset"
],
"default": "none"
} }
}, },
"container": true, "container": true,
"tags": ["div", "container", "layout"] "tags": ["div", "container", "layout"]

View File

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

View File

@ -1,8 +1,14 @@
<script> <script>
import { cssVars, createClasses } from "./cssVars"
export let url = "" export let url = ""
export let text = "" export let text = ""
export let openInNewTab = false export let openInNewTab = false
export let color
export let hoverColor
export let underline = false
export let fontSize
export let _bb export let _bb
@ -10,9 +16,41 @@ let anchorElement
$: anchorElement && !text && _bb.attachChildren(anchorElement) $: anchorElement && !text && _bb.attachChildren(anchorElement)
$: target = openInNewTab ? "_blank" : "_self" $: target = openInNewTab ? "_blank" : "_self"
$: cssVariables = {
hoverColor,
color,
textDecoration: underline ? "underline" : "none",
fontSize
}
$: classes = createClasses(cssVariables)
</script> </script>
<a href={url} bind:this={anchorElement} target={target}>{text}</a> <a
href={url}
bind:this={anchorElement}
class={classes}
target={target}
use:cssVars={cssVariables}>{text}</a>
<style>
.color {
color: var(--color)
}
.hoverColor:hover {
color: var(--color)
}
.textDecoration {
text-decoration: var(--textDecoration)
}
.fontSize {
font-size: var(--fontSize)
}
</style>

View File

@ -21,6 +21,11 @@ export const form = {
{ {
_component: "@budibase/standard-components/container", _component: "@budibase/standard-components/container",
type: "paragraph", type: "paragraph",
backgroundColor: "red",
color: "white",
borderStyle: "solid",
borderWidth: "3px",
borderColor: "blue",
_children: [ _children: [
{ {
_component: "@budibase/standard-components/text", _component: "@budibase/standard-components/text",

View File

@ -1,3 +1,3 @@
import { container, text, heading, input, select, option, button, login, nav, table } from "../index" import * as components from "../index"
export default { container, text, heading, input, select, option, button, login, nav, table } export default components

View File

@ -1,5 +1,5 @@
<script> <script>
import cssVars from "./cssVars" import { cssVars, createClasses } from "./cssVars"
import { buildStyle } from "./buildStyle" import { buildStyle } from "./buildStyle"
export let className = "default" export let className = "default"
export let disabled = false export let disabled = false
@ -24,16 +24,6 @@
let customClasses = "" let customClasses = ""
const createClasses = classes => {
let all = ""
for (let cls in classes) {
if (classes[cls]) {
all = all + " " + cls
}
}
return all
}
$: if(_bb.props._children && _bb.props._children.length > 0) $: if(_bb.props._children && _bb.props._children.length > 0)
theButton && _bb.attachChildren(theButton) theButton && _bb.attachChildren(theButton)

View File

@ -1,6 +1,6 @@
// https://github.com/kaisermann/svelte-css-vars // https://github.com/kaisermann/svelte-css-vars
export default (node, props) => { export const cssVars = (node, props) => {
Object.entries(props).forEach(([key, value]) => { Object.entries(props).forEach(([key, value]) => {
node.style.setProperty(`--${key}`, value) node.style.setProperty(`--${key}`, value)
}) })
@ -17,3 +17,15 @@ export default (node, props) => {
}, },
} }
} }
export const createClasses = classes => {
let all = ""
for (let cls in classes) {
if (classes[cls]) {
all = all + " " + cls
}
}
return all
}
export default cssVars