2020-02-03 19:38:09 +01:00
|
|
|
<script>
|
2020-02-03 22:10:47 +01:00
|
|
|
import { setContext, getContext } from "svelte"
|
|
|
|
import Icon from "../Icon.svelte"
|
|
|
|
import ripple from "../Ripple.js"
|
|
|
|
import ClassBuilder from "../ClassBuilder.js"
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-03 22:10:47 +01:00
|
|
|
const cb = new ClassBuilder("button", ["primary", "medium"])
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-03 22:10:47 +01:00
|
|
|
export let variant = "raised"
|
|
|
|
export let colour = "primary"
|
|
|
|
export let size = "medium"
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-03 22:10:47 +01:00
|
|
|
export let href = ""
|
|
|
|
export let icon = ""
|
|
|
|
export let trailingIcon = false
|
2020-02-07 21:56:00 +01:00
|
|
|
export let fullwidth = false
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-03 22:10:47 +01:00
|
|
|
export let text = ""
|
|
|
|
export let disabled = false
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-03 22:10:47 +01:00
|
|
|
$: if (icon) {
|
|
|
|
setContext("BBMD:icon:context", "button")
|
2020-02-03 19:38:09 +01:00
|
|
|
}
|
|
|
|
|
2020-02-03 22:10:47 +01:00
|
|
|
$: renderLeadingIcon = !!icon && !trailingIcon
|
|
|
|
$: renderTrailingIcon = !!icon && trailingIcon
|
2020-02-03 19:38:09 +01:00
|
|
|
|
|
|
|
let blockClasses = cb.blocks({
|
|
|
|
modifiers: !href ? [variant] : null,
|
2020-02-03 22:10:47 +01:00
|
|
|
customs: { size, colour },
|
|
|
|
})
|
2020-02-03 19:38:09 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- TODO: Activated colour on primary elevated buttons seems to be rendering weird -->
|
|
|
|
{#if href}
|
|
|
|
<a class={blockClasses} {href} on:click>
|
|
|
|
<span class={cb.elements('label')}>{text}</span>
|
|
|
|
</a>
|
|
|
|
{:else}
|
|
|
|
<button
|
|
|
|
use:ripple={{ colour }}
|
|
|
|
class={blockClasses}
|
2020-02-07 21:56:00 +01:00
|
|
|
class:fullwidth
|
2020-02-03 19:38:09 +01:00
|
|
|
{disabled}
|
|
|
|
on:click>
|
|
|
|
{#if renderLeadingIcon}
|
|
|
|
<Icon {icon} />
|
|
|
|
{/if}
|
|
|
|
<span class={cb.elements('label')}>{text}</span>
|
|
|
|
{#if renderTrailingIcon}
|
|
|
|
<Icon {icon} />
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
{/if}
|
2020-02-03 22:10:47 +01:00
|
|
|
|
|
|
|
<style>
|
2020-02-07 21:56:00 +01:00
|
|
|
.fullwidth {
|
2020-02-03 22:10:47 +01:00
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
</style>
|