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-03-31 15:40:11 +02:00
|
|
|
<script lang="typescript">
|
2021-04-15 02:32:58 +02:00
|
|
|
import type { Readable } from "svelte/store";
|
2021-03-31 15:40:11 +02:00
|
|
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
2021-05-18 17:50:18 +02:00
|
|
|
import { disabledKey, nightModeKey } from "./contextKeys";
|
2021-03-31 15:40:11 +02:00
|
|
|
|
2021-05-18 16:32:29 +02:00
|
|
|
export let id: string | undefined = undefined;
|
|
|
|
let className = "";
|
|
|
|
export { className as class };
|
2021-03-31 15:40:11 +02:00
|
|
|
|
2021-05-18 16:32:29 +02:00
|
|
|
export let tooltip: string | undefined = undefined;
|
2021-03-31 15:40:11 +02:00
|
|
|
|
2021-04-01 18:55:34 +02:00
|
|
|
export let disables = true;
|
2021-03-31 15:40:11 +02:00
|
|
|
|
2021-05-18 17:50:18 +02:00
|
|
|
const nightMode = getContext<boolean>(nightModeKey);
|
|
|
|
const disabled = getContext<Readable<boolean>>(disabledKey);
|
|
|
|
$: _disabled = disables && $disabled;
|
|
|
|
|
2021-03-31 15:40:11 +02:00
|
|
|
let buttonRef: HTMLSelectElement;
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
|
|
|
</script>
|
|
|
|
|
2021-05-18 16:32:29 +02:00
|
|
|
<!-- svelte-ignore a11y-no-onchange -->
|
|
|
|
|
2021-03-31 15:40:11 +02:00
|
|
|
<select
|
2021-03-31 16:24:28 +02:00
|
|
|
tabindex="-1"
|
2021-03-31 15:40:11 +02:00
|
|
|
bind:this={buttonRef}
|
2021-04-01 18:36:03 +02:00
|
|
|
disabled={_disabled}
|
2021-03-31 15:40:11 +02:00
|
|
|
{id}
|
2021-05-20 04:43:47 +02:00
|
|
|
class="{className} form-select"
|
2021-05-18 17:50:18 +02:00
|
|
|
class:btn-day={!nightMode}
|
|
|
|
class:btn-night={nightMode}
|
2021-05-18 16:32:29 +02:00
|
|
|
title={tooltip}
|
2021-05-26 01:21:33 +02:00
|
|
|
on:change
|
|
|
|
>
|
2021-05-18 16:32:29 +02:00
|
|
|
<slot />
|
2021-03-31 15:40:11 +02:00
|
|
|
</select>
|
2021-05-26 01:21:33 +02:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
@use "ts/sass/button_mixins" as button;
|
|
|
|
|
|
|
|
select {
|
2021-05-27 17:13:36 +02:00
|
|
|
height: var(--buttons-size);
|
2021-05-28 21:33:34 +02:00
|
|
|
/* Long option name can create overflow */
|
|
|
|
overflow-x: hidden;
|
2021-05-26 01:21:33 +02:00
|
|
|
}
|
|
|
|
|
2021-05-27 20:28:23 +02:00
|
|
|
.btn-night {
|
|
|
|
/* override the default down arrow */
|
|
|
|
background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23FFFFFF' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e");
|
|
|
|
}
|
|
|
|
|
2021-05-26 01:21:33 +02:00
|
|
|
@include button.btn-day($with-hover: false);
|
|
|
|
@include button.btn-night($with-hover: false);
|
|
|
|
</style>
|