2020-02-03 19:38:09 +01:00
|
|
|
<script>
|
2020-02-14 15:00:12 +01:00
|
|
|
import { setContext, getContext } from "svelte"
|
2020-02-18 16:05:09 +01:00
|
|
|
import Icon from "../Common/Icon.svelte"
|
|
|
|
import ripple from "../Common/Ripple.js"
|
2020-02-14 15:00:12 +01:00
|
|
|
import ClassBuilder from "../ClassBuilder.js"
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-21 16:00:42 +01:00
|
|
|
const cb = new ClassBuilder("button", ["primary", "medium", "text"])
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-22 23:09:26 +01:00
|
|
|
export let onClick
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-21 16:00:42 +01:00
|
|
|
export let variant = "text"
|
2020-02-14 15:00:12 +01:00
|
|
|
export let colour = "primary"
|
|
|
|
export let size = "medium"
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-14 15:00:12 +01:00
|
|
|
export let href = ""
|
|
|
|
export let icon = ""
|
|
|
|
export let trailingIcon = false
|
|
|
|
export let fullwidth = false
|
2020-02-10 11:04:20 +01:00
|
|
|
|
2020-02-14 15:00:12 +01:00
|
|
|
export let text = ""
|
|
|
|
export let disabled = false
|
2020-02-10 11:04:20 +01:00
|
|
|
|
2020-02-22 23:09:26 +01:00
|
|
|
export let _bb
|
|
|
|
|
2020-02-14 15:00:12 +01:00
|
|
|
let modifiers = {}
|
|
|
|
let customs = { size, colour }
|
2020-02-10 11:04:20 +01:00
|
|
|
|
2020-02-14 15:00:12 +01:00
|
|
|
if (!href) modifiers = { variant }
|
2020-02-10 11:04:20 +01:00
|
|
|
|
2020-02-14 15:00:12 +01:00
|
|
|
let props = { modifiers, customs }
|
|
|
|
|
|
|
|
let blockClasses = cb.build({ props })
|
|
|
|
const labelClass = cb.elem("label")
|
2020-02-03 19:38:09 +01:00
|
|
|
|
2020-02-22 23:09:26 +01:00
|
|
|
const clicked = () => _bb.call(onClick)
|
|
|
|
|
2020-02-14 15:00:12 +01:00
|
|
|
$: renderLeadingIcon = !!icon && !trailingIcon
|
|
|
|
$: renderTrailingIcon = !!icon && trailingIcon
|
2020-02-03 19:38:09 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if href}
|
2020-02-22 23:09:26 +01:00
|
|
|
<a class={blockClasses} {href} on:click={clicked}>
|
2020-02-10 11:04:20 +01:00
|
|
|
<span class={labelClass}>{text}</span>
|
2020-02-03 19:38:09 +01:00
|
|
|
</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}
|
2020-02-22 23:09:26 +01:00
|
|
|
on:click={clicked}>
|
2020-02-03 19:38:09 +01:00
|
|
|
{#if renderLeadingIcon}
|
2020-03-03 16:23:03 +01:00
|
|
|
<Icon context="button" {icon} />
|
2020-02-03 19:38:09 +01:00
|
|
|
{/if}
|
2020-02-10 11:04:20 +01:00
|
|
|
<span class={labelClass}>{text}</span>
|
2020-02-03 19:38:09 +01:00
|
|
|
{#if renderTrailingIcon}
|
2020-03-03 16:23:03 +01:00
|
|
|
<Icon context="button" {icon} />
|
2020-02-03 19:38:09 +01:00
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
{/if}
|
2020-02-14 15:00:12 +01:00
|
|
|
|
|
|
|
<style>
|
|
|
|
.fullwidth {
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
</style>
|