2021-04-09 13:38:48 +02:00
|
|
|
<script>
|
2021-04-23 09:41:49 +02:00
|
|
|
import "@spectrum-css/actionbutton/dist/index-vars.css"
|
|
|
|
import { createEventDispatcher } from "svelte"
|
|
|
|
const dispatch = createEventDispatcher()
|
2021-04-09 13:38:48 +02:00
|
|
|
|
2021-04-23 09:41:49 +02:00
|
|
|
export let quiet = false
|
|
|
|
export let emphasized = false
|
|
|
|
export let selected = false
|
|
|
|
export let longPressable = false
|
|
|
|
export let disabled = false
|
|
|
|
export let icon = ""
|
2021-04-09 13:38:48 +02:00
|
|
|
|
2021-04-27 16:18:52 +02:00
|
|
|
export let size = "M"
|
2021-04-23 15:45:10 +02:00
|
|
|
|
2021-04-23 09:41:49 +02:00
|
|
|
function longPress(element) {
|
|
|
|
if (!longPressable) return
|
|
|
|
let timer
|
2021-04-09 13:38:48 +02:00
|
|
|
|
2021-04-23 09:41:49 +02:00
|
|
|
const listener = () => {
|
|
|
|
timer = setTimeout(() => {
|
|
|
|
dispatch("longpress")
|
|
|
|
}, 700)
|
|
|
|
}
|
2021-04-09 13:38:48 +02:00
|
|
|
|
2021-04-23 09:41:49 +02:00
|
|
|
element.addEventListener("pointerdown", listener)
|
2021-04-09 13:38:48 +02:00
|
|
|
|
2021-04-23 09:41:49 +02:00
|
|
|
return {
|
|
|
|
destroy() {
|
|
|
|
clearTimeout(timer)
|
|
|
|
element.removeEventListener("pointerdown", longPress)
|
|
|
|
},
|
2021-04-09 13:38:48 +02:00
|
|
|
}
|
2021-04-23 09:41:49 +02:00
|
|
|
}
|
2021-04-09 13:38:48 +02:00
|
|
|
</script>
|
|
|
|
|
2021-04-23 09:41:49 +02:00
|
|
|
<button
|
|
|
|
use:longPress
|
|
|
|
class:spectrum-ActionButton--quiet={quiet}
|
|
|
|
class:spectrum-ActionButton--emphasized={emphasized}
|
|
|
|
class:is-selected={selected}
|
2021-04-27 16:18:52 +02:00
|
|
|
class="spectrum-ActionButton spectrum-ActionButton--size{size}"
|
2021-04-23 09:41:49 +02:00
|
|
|
{disabled}
|
|
|
|
on:longPress
|
2021-04-28 14:59:55 +02:00
|
|
|
on:click|preventDefault>
|
2021-04-23 09:41:49 +02:00
|
|
|
{#if longPressable}
|
|
|
|
<svg
|
|
|
|
class="spectrum-Icon spectrum-UIIcon-CornerTriangle100 spectrum-ActionButton-hold"
|
|
|
|
focusable="false"
|
2021-04-28 14:59:55 +02:00
|
|
|
aria-hidden="true">
|
2021-04-23 09:41:49 +02:00
|
|
|
<use xlink:href="#spectrum-css-icon-CornerTriangle100" />
|
|
|
|
</svg>
|
|
|
|
{/if}
|
|
|
|
{#if icon}
|
|
|
|
<svg
|
2021-04-27 16:18:52 +02:00
|
|
|
class="spectrum-Icon spectrum-Icon--size{size}"
|
2021-04-23 09:41:49 +02:00
|
|
|
focusable="false"
|
|
|
|
aria-hidden="true"
|
2021-04-28 14:59:55 +02:00
|
|
|
aria-label={icon}>
|
2021-04-23 09:41:49 +02:00
|
|
|
<use xlink:href="#spectrum-icon-18-{icon}" />
|
|
|
|
</svg>
|
|
|
|
{/if}
|
|
|
|
{#if $$slots}
|
|
|
|
<span class="spectrum-ActionButton-label"><slot /></span>
|
|
|
|
{/if}
|
2021-04-09 13:38:48 +02:00
|
|
|
</button>
|