2020-03-11 15:04:47 +01:00
|
|
|
<script>
|
2020-03-11 17:28:09 +01:00
|
|
|
import ripple from "../Common/Ripple.js"
|
|
|
|
import ClassBuilder from "../ClassBuilder.js"
|
2020-03-11 15:04:47 +01:00
|
|
|
|
2020-03-11 17:28:09 +01:00
|
|
|
const cb = new ClassBuilder("icon-button")
|
2020-03-11 15:04:47 +01:00
|
|
|
|
2020-03-12 15:07:20 +01:00
|
|
|
let on = false
|
|
|
|
|
2020-03-11 17:28:09 +01:00
|
|
|
export let _bb
|
|
|
|
export let context = ""
|
|
|
|
export let onClick = () => {}
|
|
|
|
export let disabled = false
|
|
|
|
export let href = ""
|
|
|
|
export let icon = ""
|
|
|
|
export let onIcon = "" //on state icon for toggle button
|
|
|
|
export let size = "medium"
|
2020-03-11 15:04:47 +01:00
|
|
|
|
2020-03-12 15:07:20 +01:00
|
|
|
function onButtonClick() {
|
|
|
|
open = !open
|
|
|
|
onClick()
|
|
|
|
}
|
|
|
|
|
2020-03-11 17:28:09 +01:00
|
|
|
$: isToggleButton = !!icon && !!onIcon
|
|
|
|
$: useLinkButton = !!href
|
2020-03-11 15:04:47 +01:00
|
|
|
|
2020-03-11 17:28:09 +01:00
|
|
|
$: customs = { size }
|
|
|
|
$: props = { customs, extras: ["material-icons", context] }
|
|
|
|
$: iconBtnClass = cb.build({ props })
|
2020-03-11 15:04:47 +01:00
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if useLinkButton}
|
2020-03-12 15:07:20 +01:00
|
|
|
<a
|
|
|
|
on:click={onButtonClick}
|
|
|
|
class={iconBtnClass}
|
|
|
|
{href}
|
|
|
|
{disabled}
|
|
|
|
role="button"
|
|
|
|
tabindex="0">
|
2020-03-11 15:04:47 +01:00
|
|
|
{#if isToggleButton}
|
2020-03-11 17:28:09 +01:00
|
|
|
<i
|
|
|
|
use:ripple
|
|
|
|
class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">
|
2020-03-11 15:04:47 +01:00
|
|
|
{onIcon}
|
|
|
|
</i>
|
2020-03-11 17:28:09 +01:00
|
|
|
<i use:ripple class="material-icons mdc-icon-button__icon">{icon}</i>
|
2020-03-11 15:04:47 +01:00
|
|
|
{:else}{icon}{/if}
|
|
|
|
</a>
|
|
|
|
{:else}
|
2020-03-11 17:28:09 +01:00
|
|
|
<button
|
2020-03-12 15:07:20 +01:00
|
|
|
on:click={onButtonClick}
|
2020-03-11 17:28:09 +01:00
|
|
|
class={iconBtnClass}
|
|
|
|
{disabled}
|
|
|
|
role="button"
|
2020-03-12 15:07:20 +01:00
|
|
|
aria-label="Add to favorites"
|
|
|
|
aria-pressed="false"
|
2020-03-11 17:28:09 +01:00
|
|
|
tabindex="0">
|
2020-03-11 15:04:47 +01:00
|
|
|
{#if isToggleButton}
|
2020-03-12 15:07:20 +01:00
|
|
|
<i use:ripple class="material-icons mdc-icon-button__icon">{icon}</i>
|
2020-03-11 17:28:09 +01:00
|
|
|
<i
|
|
|
|
use:ripple
|
|
|
|
class="material-icons mdc-icon-button__icon mdc-icon-button__icon--on">
|
2020-03-11 15:04:47 +01:00
|
|
|
{onIcon}
|
|
|
|
</i>
|
|
|
|
{:else}{icon}{/if}
|
|
|
|
</button>
|
|
|
|
{/if}
|