Merge pull request #103 from Conor-Mack/bugfix/event-handling-button-textfield
Event handling for MD Buttons and Textfields
This commit is contained in:
commit
4e65562197
|
@ -1,49 +1,45 @@
|
||||||
<script>
|
<script>
|
||||||
import { setContext, getContext } from "svelte";
|
import { setContext, getContext } from "svelte"
|
||||||
import Icon from "../Icon.svelte";
|
import Icon from "../Icon.svelte"
|
||||||
import ripple from "../Ripple.js";
|
import ripple from "../Ripple.js"
|
||||||
import ClassBuilder from "../ClassBuilder.js";
|
import ClassBuilder from "../ClassBuilder.js"
|
||||||
|
|
||||||
const cb = new ClassBuilder("button", ["primary", "medium"]);
|
const cb = new ClassBuilder("button", ["primary", "medium"])
|
||||||
|
|
||||||
export let variant = "raised";
|
export let onClick = () => {}
|
||||||
export let colour = "primary";
|
|
||||||
export let size = "medium";
|
|
||||||
|
|
||||||
export let href = "";
|
export let variant = "raised"
|
||||||
export let icon = "";
|
export let colour = "primary"
|
||||||
export let trailingIcon = false;
|
export let size = "medium"
|
||||||
export let fullwidth = false;
|
|
||||||
|
|
||||||
export let text = "";
|
export let href = ""
|
||||||
export let disabled = false;
|
export let icon = ""
|
||||||
|
export let trailingIcon = false
|
||||||
|
export let fullwidth = false
|
||||||
|
|
||||||
let modifiers = {};
|
export let text = ""
|
||||||
let customs = { size, colour };
|
export let disabled = false
|
||||||
|
|
||||||
if (!href) modifiers = { variant };
|
let modifiers = {}
|
||||||
|
let customs = { size, colour }
|
||||||
|
|
||||||
let props = { modifiers, customs };
|
if (!href) modifiers = { variant }
|
||||||
|
|
||||||
let blockClasses = cb.build({ props });
|
let props = { modifiers, customs }
|
||||||
const labelClass = cb.elem("label");
|
|
||||||
|
let blockClasses = cb.build({ props })
|
||||||
|
const labelClass = cb.elem("label")
|
||||||
|
|
||||||
$: if (icon) {
|
$: if (icon) {
|
||||||
setContext("BBMD:icon:context", "button");
|
setContext("BBMD:icon:context", "button")
|
||||||
}
|
}
|
||||||
|
|
||||||
$: renderLeadingIcon = !!icon && !trailingIcon;
|
$: renderLeadingIcon = !!icon && !trailingIcon
|
||||||
$: renderTrailingIcon = !!icon && trailingIcon;
|
$: renderTrailingIcon = !!icon && trailingIcon
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
|
||||||
.fullwidth {
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
|
|
||||||
{#if href}
|
{#if href}
|
||||||
<a class={blockClasses} {href} on:click>
|
<a class={blockClasses} {href} on:click={onClick}>
|
||||||
<span class={labelClass}>{text}</span>
|
<span class={labelClass}>{text}</span>
|
||||||
</a>
|
</a>
|
||||||
{:else}
|
{:else}
|
||||||
|
@ -52,7 +48,7 @@
|
||||||
class={blockClasses}
|
class={blockClasses}
|
||||||
class:fullwidth
|
class:fullwidth
|
||||||
{disabled}
|
{disabled}
|
||||||
on:click>
|
on:click={onClick}>
|
||||||
{#if renderLeadingIcon}
|
{#if renderLeadingIcon}
|
||||||
<Icon {icon} />
|
<Icon {icon} />
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -62,3 +58,9 @@
|
||||||
{/if}
|
{/if}
|
||||||
</button>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.fullwidth {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
@ -22,6 +22,7 @@ export const props = {
|
||||||
fullwidth: false,
|
fullwidth: false,
|
||||||
text: "I am button",
|
text: "I am button",
|
||||||
disabled: false,
|
disabled: false,
|
||||||
|
onClick: () => alert`Button Clicked`,
|
||||||
},
|
},
|
||||||
icon: {
|
icon: {
|
||||||
_component: "@budibase/materialdesign-components/icon",
|
_component: "@budibase/materialdesign-components/icon",
|
||||||
|
@ -33,10 +34,10 @@ export const props = {
|
||||||
_children: [],
|
_children: [],
|
||||||
label: "First",
|
label: "First",
|
||||||
colour: "secondary",
|
colour: "secondary",
|
||||||
textarea: true,
|
|
||||||
fullwidth: true,
|
fullwidth: true,
|
||||||
helperText: "Add Surname",
|
helperText: "Add Surname",
|
||||||
useCharCounter: true,
|
useCharCounter: true,
|
||||||
|
onChange: text => console.log("Text: ", text),
|
||||||
},
|
},
|
||||||
checkbox: {
|
checkbox: {
|
||||||
_component: "@budibase/materialdesign-components/checkbox",
|
_component: "@budibase/materialdesign-components/checkbox",
|
||||||
|
|
|
@ -21,6 +21,8 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
export let onChange = text => {}
|
||||||
|
|
||||||
export let label = ""
|
export let label = ""
|
||||||
export let variant = "standard" //outlined | filled | standard
|
export let variant = "standard" //outlined | filled | standard
|
||||||
export let disabled = false
|
export let disabled = false
|
||||||
|
@ -112,7 +114,7 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
||||||
{placeholder}
|
{placeholder}
|
||||||
{minLength}
|
{minLength}
|
||||||
{maxLength}
|
{maxLength}
|
||||||
on:change />
|
on:change={e => onChange(e.target.value)} />
|
||||||
{:else}
|
{:else}
|
||||||
{#if renderLeadingIcon}
|
{#if renderLeadingIcon}
|
||||||
<Icon {icon} />
|
<Icon {icon} />
|
||||||
|
@ -120,7 +122,6 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
||||||
<input
|
<input
|
||||||
{id}
|
{id}
|
||||||
{disabled}
|
{disabled}
|
||||||
on:focus={focus}
|
|
||||||
class={inputClasses}
|
class={inputClasses}
|
||||||
{type}
|
{type}
|
||||||
{required}
|
{required}
|
||||||
|
@ -128,7 +129,8 @@ TODO:Needs error handling - this will depend on how Budibase handles errors
|
||||||
{minLength}
|
{minLength}
|
||||||
{maxLength}
|
{maxLength}
|
||||||
aria-label={`Textfield ${variant}`}
|
aria-label={`Textfield ${variant}`}
|
||||||
on:change />
|
on:focus={focus}
|
||||||
|
on:change={e => onChange(e.target.value)} />
|
||||||
{#if renderTrailingIcon}
|
{#if renderTrailingIcon}
|
||||||
<Icon {icon} />
|
<Icon {icon} />
|
||||||
{/if}
|
{/if}
|
||||||
|
|
Loading…
Reference in New Issue