mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 06:22:22 -04:00
Add SelectButton
This commit is contained in:
parent
fa900e1565
commit
f526b51ea2
5 changed files with 67 additions and 5 deletions
|
@ -14,7 +14,8 @@
|
||||||
padding-inline-start: 0;
|
padding-inline-start: 0;
|
||||||
margin-bottom: 0;
|
margin-bottom: 0;
|
||||||
|
|
||||||
& :global(button) {
|
& :global(button),
|
||||||
|
& :global(select) {
|
||||||
margin-left: -1px;
|
margin-left: -1px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,7 +27,8 @@
|
||||||
&:nth-child(1) {
|
&:nth-child(1) {
|
||||||
margin-left: 0.25rem;
|
margin-left: 0.25rem;
|
||||||
|
|
||||||
& > :global(button) {
|
& > :global(button),
|
||||||
|
& > :global(select) {
|
||||||
border-top-left-radius: 0.25rem;
|
border-top-left-radius: 0.25rem;
|
||||||
border-bottom-left-radius: 0.25rem;
|
border-bottom-left-radius: 0.25rem;
|
||||||
}
|
}
|
||||||
|
@ -35,7 +37,8 @@
|
||||||
&:nth-last-child(1) {
|
&:nth-last-child(1) {
|
||||||
margin-right: 0.25rem;
|
margin-right: 0.25rem;
|
||||||
|
|
||||||
& > :global(button) {
|
& > :global(button),
|
||||||
|
& > :global(select) {
|
||||||
border-top-right-radius: 0.25rem;
|
border-top-right-radius: 0.25rem;
|
||||||
border-bottom-right-radius: 0.25rem;
|
border-bottom-right-radius: 0.25rem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { onMount, createEventDispatcher, getContext } from "svelte";
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
||||||
import type { Readable } from "svelte/store";
|
|
||||||
import { disabledKey } from "./contextKeys";
|
import { disabledKey } from "./contextKeys";
|
||||||
|
|
||||||
export let id = "";
|
export let id = "";
|
||||||
|
@ -18,7 +17,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
onMount(() => dispatch("mount", { button: buttonRef }));
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
||||||
|
|
||||||
const disabledStore = getContext(disabledKey);
|
const disabledStore = getContext(disabledKey);
|
||||||
|
|
52
ts/editor-toolbar/SelectButton.svelte
Normal file
52
ts/editor-toolbar/SelectButton.svelte
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<script lang="typescript">
|
||||||
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
||||||
|
import type { Readable } from "svelte/store";
|
||||||
|
import { disabledKey } from "./contextKeys";
|
||||||
|
import SelectOption from "./SelectOption.svelte";
|
||||||
|
|
||||||
|
interface Option {
|
||||||
|
label: string;
|
||||||
|
value: string;
|
||||||
|
selected: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export let id = "";
|
||||||
|
export let className = "";
|
||||||
|
export let props: Record<string, string> = {};
|
||||||
|
|
||||||
|
function extendClassName(classes: string) {
|
||||||
|
return `form-select ${classes}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
export let disables;
|
||||||
|
export let options: Option[];
|
||||||
|
|
||||||
|
let buttonRef: HTMLSelectElement;
|
||||||
|
|
||||||
|
const dispatch = createEventDispatcher();
|
||||||
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
||||||
|
|
||||||
|
const disabledStore = getContext(disabledKey);
|
||||||
|
$: disabled = disables && $disabledStore;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
select {
|
||||||
|
height: 30px;
|
||||||
|
width: auto;
|
||||||
|
|
||||||
|
font-size: smaller;
|
||||||
|
border-radius: 0;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<select
|
||||||
|
bind:this={buttonRef}
|
||||||
|
{disabled}
|
||||||
|
{id}
|
||||||
|
class={extendClassName(className)}
|
||||||
|
{...props}>
|
||||||
|
{#each options as option}
|
||||||
|
<SelectOption {...option} />
|
||||||
|
{/each}
|
||||||
|
</select>
|
7
ts/editor-toolbar/SelectOption.svelte
Normal file
7
ts/editor-toolbar/SelectOption.svelte
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<script lang="typescript">
|
||||||
|
export let label: string;
|
||||||
|
export let value: string;
|
||||||
|
export let selected = false;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<option {selected} {value}>{label}</option>
|
|
@ -7,6 +7,7 @@ import EditorToolbarSvelte from "./EditorToolbar.svelte";
|
||||||
|
|
||||||
import DropdownMenu from "./DropdownMenu.svelte";
|
import DropdownMenu from "./DropdownMenu.svelte";
|
||||||
import WithDropdownMenu from "./WithDropdownMenu.svelte";
|
import WithDropdownMenu from "./WithDropdownMenu.svelte";
|
||||||
|
import SelectButton from "./SelectButton.svelte";
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
||||||
|
@ -58,6 +59,7 @@ const defaultButtons = [
|
||||||
clozeButton,
|
clozeButton,
|
||||||
{ component: WithDropdownMenu, menuId: "mathjaxMenu", button: mathjaxButton },
|
{ component: WithDropdownMenu, menuId: "mathjaxMenu", button: mathjaxButton },
|
||||||
htmlButton,
|
htmlButton,
|
||||||
|
{ component: SelectButton, options: [{ label: "Test" }, { label: "Test2" }] },
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue