2021-04-09 13:38:48 +02:00
|
|
|
<script>
|
|
|
|
import "@spectrum-css/actionbutton/dist/index-vars.css"
|
|
|
|
import { createEventDispatcher } from "svelte"
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
|
2021-04-09 14:57:31 +02:00
|
|
|
|
2021-04-09 13:38:48 +02:00
|
|
|
/** @type {('S', 'M', 'L', 'XL')} Size of button */
|
|
|
|
export let size = "M";
|
|
|
|
export let quiet = false;
|
2021-04-09 14:57:31 +02:00
|
|
|
export let emphasized = false;
|
|
|
|
export let selected = false
|
2021-04-09 13:38:48 +02:00
|
|
|
export let longPressable = false;
|
2021-04-09 14:57:31 +02:00
|
|
|
export let disabled = false
|
2021-04-09 13:38:48 +02:00
|
|
|
export let icon = '';
|
|
|
|
|
|
|
|
function longPress(element) {
|
|
|
|
if (!longPressable) return
|
|
|
|
let timer
|
|
|
|
|
|
|
|
const listener = () => {
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
dispatch('longpress')
|
|
|
|
}, 700)
|
|
|
|
}
|
|
|
|
|
|
|
|
element.addEventListener('pointerdown', listener)
|
|
|
|
|
|
|
|
return {
|
|
|
|
destroy() {
|
|
|
|
clearTimeout(timer)
|
|
|
|
element.removeEventListener('pointerdown', longPress)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<button
|
|
|
|
use:longPress
|
2021-04-09 14:57:31 +02:00
|
|
|
class:spectrum-ActionButton--quiet={quiet}
|
|
|
|
class:spectrum-ActionButton--emphasized={emphasized}
|
|
|
|
class:is-selected={selected}
|
|
|
|
class="spectrum-ActionButton spectrum-ActionButton--size{size.toUpperCase()}"
|
2021-04-09 13:38:48 +02:00
|
|
|
{disabled}
|
|
|
|
on:longPress
|
|
|
|
on:click|preventDefault>
|
|
|
|
{#if longPressable}
|
|
|
|
<svg class="spectrum-Icon spectrum-UIIcon-CornerTriangle100 spectrum-ActionButton-hold" focusable="false" aria-hidden="true">
|
|
|
|
<use xlink:href="#spectrum-css-icon-CornerTriangle100" />
|
|
|
|
</svg>
|
|
|
|
{/if}
|
|
|
|
{#if icon}
|
|
|
|
<svg class="spectrum-Icon spectrum-Icon--size{size.toUpperCase()}" focusable="false" aria-hidden="true" aria-label="{icon}">
|
|
|
|
<use xlink:href="#spectrum-icon-18-{icon}" />
|
|
|
|
</svg>
|
|
|
|
{/if}
|
|
|
|
{#if $$slots}
|
|
|
|
<span class="spectrum-ActionButton-label"><slot /></span>
|
|
|
|
{/if}
|
|
|
|
</button>
|
|
|
|
|
2021-04-16 12:40:34 +02:00
|
|
|
<style>
|
|
|
|
span {
|
|
|
|
text-transform: capitalize;
|
|
|
|
}
|
|
|
|
</style>
|
2021-04-09 13:38:48 +02:00
|
|
|
|