adds an ActionButton component to bbui

This commit is contained in:
Keviin Åberg Kultalahti 2021-04-09 13:38:48 +02:00
parent 5a2287ddcb
commit b43e0e6547
6 changed files with 76 additions and 5 deletions

View File

@ -40,6 +40,7 @@
"build:docker:staging": "cd hosting/scripts/linux/ && ./release-to-docker-hub.sh staging && cd -"
},
"dependencies": {
"@spectrum-css/actionbutton": "^1.0.1",
"@spectrum-css/toast": "^3.0.1"
}
}

View File

@ -0,0 +1,67 @@
<script>
import "@spectrum-css/actionbutton/dist/index-vars.css"
import { createEventDispatcher } from "svelte"
const dispatch = createEventDispatcher()
export let disabled = false
/** @type {('S', 'M', 'L', 'XL')} Size of button */
export let size = "M";
/** @type {('cta','primary','secondary','warning', 'overBackground')} Type of button */
export let type = "primary"
export let quiet = false;
export let selected = false;
export let longPressable = false;
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
class="spectrum-ActionButton spectrum-ActionButton--size{size.toUpperCase()} spectrum-ActionButton--{type} {quiet && 'spectrum-ActionButton--quiet'}"
{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>
<style>
</style>

View File

@ -1,8 +1,6 @@
<script>
import "@spectrum-css/button/dist/index-vars.css"
export let href = false
export let disabled = false

View File

@ -1,6 +1,6 @@
<script>
import Flatpickr from "svelte-flatpickr"
import { Label, Input } from "../"
import { Label } from "../"
import "flatpickr/dist/flatpickr.css"
const PICKER_OPTIONS = {

View File

@ -1,7 +1,7 @@
<script>
import { slide } from "svelte/transition"
import Portal from "svelte-portal"
import clickOutside from "../Actions/click_outside"
import ActionButton from '../Button/ActionButton.svelte'
export let title
@ -40,7 +40,7 @@
</div>
<div class="controls">
<slot name="buttons" />
<i class="ri-close-fill close" on:click={hide} />
<ActionButton quiet icon="Close" on:click={hide} />
</div>
</header>
<slot name="body" />

View File

@ -824,6 +824,11 @@
estree-walker "^1.0.1"
micromatch "^4.0.2"
"@spectrum-css/actionbutton@^1.0.1":
version "1.0.1"
resolved "https://registry.yarnpkg.com/@spectrum-css/actionbutton/-/actionbutton-1.0.1.tgz#9c75da37ea6915919fb574c74bd60dacc03b6577"
integrity sha512-AUqtyNabHF451Aj9i3xz82TxS5Z6k1dttA68/1hMeU9kbPCSS4P6Viw3vaRGs9CSspuR8xnnhDgrq+F+zMy2Hw==
"@spectrum-css/toast@^3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@spectrum-css/toast/-/toast-3.0.1.tgz#36f62ea05302761e59b9d53e05f6c04423861796"