campfire/src/lib/ui/post/ReactionButton.svelte

89 lines
1.8 KiB
Svelte
Raw Normal View History

<script>
import { play_sound } from '../../sound.js';
2024-06-28 08:43:12 +01:00
import { createEventDispatcher } from 'svelte';
const dispatch = createEventDispatcher();
2024-06-28 08:43:12 +01:00
export let type = "react";
export let label = "React";
export let title = label;
export let count = 0;
2024-06-28 08:43:12 +01:00
export let active = false;
export let disabled = false;
export let sound = "default";
2024-06-28 08:43:12 +01:00
function click() {
play_sound(sound);
dispatch('click');
}
</script>
<button
type="button"
2024-06-28 08:43:12 +01:00
class={[
type,
active ? "active" : "",
disabled ? "disabled" : "",
].join(' ')}
aria-label="{label}"
title="{title}"
2024-06-28 08:43:12 +01:00
on:click={click}>
<span class="icon">
<slot/>
</span>
{#if count}
<span class="count">{count}</span>
{/if}
</button>
<style>
button {
height: 32px;
padding: 6px 8px;
display: flex;
flex-direction: row;
gap: 4px;
font-size: 1em;
background: none;
color: inherit;
border: none;
border-radius: 8px;
2024-06-28 08:43:12 +01:00
transition: background-color .1s, color .1s;
cursor: pointer;
}
button.active {
2024-06-28 08:43:12 +01:00
background-color: color-mix(in srgb, transparent, var(--accent) 50%);
color: var(--bg-1000);
}
button:not(.disabled):hover {
background-color: var(--bg-600);
color: var(--text);
}
2024-06-28 08:43:12 +01:00
button:not(.disabled):active {
background-color: var(--bg-1000);
color: var(--text);
}
2024-06-28 08:43:12 +01:00
button.disabled {
cursor: initial;
}
.icon {
width: 20px;
height: 20px;
display: flex;
justify-content: center;
align-items: center;
}
.count {
opacity: .5;
}
button:hover .count {
opacity: 1;
}
</style>