2021-04-15 15:59:52 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2021-10-26 00:43:02 +02:00
|
|
|
<script lang="ts">
|
2021-05-07 15:10:28 +02:00
|
|
|
export let id: string | undefined = undefined;
|
2023-11-21 05:23:18 +01:00
|
|
|
export let role: string | undefined = undefined;
|
|
|
|
export let selected = false;
|
2021-04-28 22:15:24 +02:00
|
|
|
let className = "";
|
|
|
|
export { className as class };
|
2021-04-01 01:22:06 +02:00
|
|
|
|
2022-09-27 04:16:45 +02:00
|
|
|
export let buttonRef: HTMLButtonElement | undefined = undefined;
|
2022-09-10 10:46:59 +02:00
|
|
|
|
2021-05-07 15:10:28 +02:00
|
|
|
export let tooltip: string | undefined = undefined;
|
2022-09-10 10:46:59 +02:00
|
|
|
|
|
|
|
export let active = false;
|
2022-09-27 04:16:45 +02:00
|
|
|
export let disabled = false;
|
2022-09-10 10:46:59 +02:00
|
|
|
|
2022-12-07 06:31:37 +01:00
|
|
|
const rtl: boolean = window.getComputedStyle(document.body).direction == "rtl";
|
|
|
|
|
2022-09-10 10:46:59 +02:00
|
|
|
$: if (buttonRef && active) {
|
2022-12-07 06:31:37 +01:00
|
|
|
buttonRef!.scrollIntoView({
|
|
|
|
behavior: "smooth",
|
|
|
|
block: "nearest",
|
|
|
|
});
|
2022-09-10 10:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export let tabbable = false;
|
2021-04-01 01:22:06 +02:00
|
|
|
</script>
|
|
|
|
|
2021-05-26 01:21:33 +02:00
|
|
|
<button
|
2022-09-10 10:46:59 +02:00
|
|
|
bind:this={buttonRef}
|
2021-05-26 01:21:33 +02:00
|
|
|
{id}
|
2023-11-21 05:23:18 +01:00
|
|
|
{role}
|
|
|
|
aria-selected={selected}
|
2021-06-25 17:34:04 +02:00
|
|
|
tabindex={tabbable ? 0 : -1}
|
2022-09-10 10:46:59 +02:00
|
|
|
class="dropdown-item {className}"
|
|
|
|
class:active
|
2022-12-07 06:31:37 +01:00
|
|
|
class:rtl
|
2021-05-26 01:21:33 +02:00
|
|
|
title={tooltip}
|
2022-12-11 04:06:18 +01:00
|
|
|
{disabled}
|
2021-06-26 03:20:27 +02:00
|
|
|
on:mouseenter
|
2021-06-25 00:49:17 +02:00
|
|
|
on:focus
|
|
|
|
on:keydown
|
2022-02-22 13:17:22 +01:00
|
|
|
on:click
|
2021-05-26 01:21:33 +02:00
|
|
|
on:mousedown|preventDefault
|
|
|
|
>
|
|
|
|
<slot />
|
|
|
|
</button>
|
|
|
|
|
2021-04-14 19:36:41 +02:00
|
|
|
<style lang="scss">
|
|
|
|
button {
|
|
|
|
display: flex;
|
2022-02-22 13:17:22 +01:00
|
|
|
justify-content: start;
|
2022-09-27 04:16:45 +02:00
|
|
|
width: 100%;
|
2022-12-09 04:44:06 +01:00
|
|
|
padding: 0.25rem 1rem;
|
|
|
|
white-space: nowrap;
|
2022-11-27 01:47:31 +01:00
|
|
|
font-size: var(--dropdown-font-size, small);
|
2021-05-24 19:53:30 +02:00
|
|
|
|
|
|
|
background: none;
|
2021-06-25 00:49:17 +02:00
|
|
|
box-shadow: none !important;
|
2021-05-24 19:53:30 +02:00
|
|
|
border: none;
|
2022-02-22 13:17:22 +01:00
|
|
|
border-radius: 0;
|
2022-09-27 04:16:45 +02:00
|
|
|
color: var(--fg);
|
2021-04-14 19:36:41 +02:00
|
|
|
|
2023-12-08 05:32:04 +01:00
|
|
|
&:hover {
|
|
|
|
border: none;
|
|
|
|
}
|
|
|
|
|
2022-12-11 04:06:18 +01:00
|
|
|
&:hover:not([disabled]) {
|
2022-09-27 04:16:45 +02:00
|
|
|
background: var(--highlight-bg);
|
|
|
|
color: var(--highlight-fg);
|
2021-04-16 18:14:09 +02:00
|
|
|
}
|
2022-12-07 06:31:37 +01:00
|
|
|
|
2023-11-21 05:23:18 +01:00
|
|
|
&.focus {
|
|
|
|
// TODO this is subtly different from hovering with the mouse for some reason
|
|
|
|
@extend button, :hover;
|
|
|
|
}
|
|
|
|
|
2022-12-11 04:06:18 +01:00
|
|
|
&[disabled] {
|
|
|
|
cursor: default;
|
|
|
|
color: var(--fg-disabled);
|
|
|
|
}
|
|
|
|
|
2022-12-07 06:31:37 +01:00
|
|
|
/* selection highlight */
|
|
|
|
&:not(.rtl) {
|
|
|
|
border-left: 3px solid transparent;
|
|
|
|
}
|
|
|
|
&.rtl {
|
|
|
|
border-right: 3px solid transparent;
|
|
|
|
}
|
|
|
|
&.active {
|
|
|
|
&:not(.rtl) {
|
|
|
|
border-left-color: var(--border-focus);
|
|
|
|
}
|
|
|
|
&.rtl {
|
|
|
|
border-right-color: var(--border-focus);
|
|
|
|
}
|
|
|
|
}
|
2021-04-16 18:14:09 +02:00
|
|
|
}
|
2021-04-14 19:36:41 +02:00
|
|
|
</style>
|