mirror of
https://github.com/ankitects/anki.git
synced 2025-09-23 00:12:25 -04:00
Remove $$restProps and make explicit dropdown support in buttons
* Currently LabelButton, CommandIconButtton, and IconButton support dropdowns
This commit is contained in:
parent
920b740c8f
commit
1eafa7d9d0
10 changed files with 56 additions and 28 deletions
|
@ -2,7 +2,7 @@
|
||||||
import type { ToolbarItem } from "./types";
|
import type { ToolbarItem } from "./types";
|
||||||
import ButtonGroup from "./ButtonGroup.svelte";
|
import ButtonGroup from "./ButtonGroup.svelte";
|
||||||
|
|
||||||
export let id = "";
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
|
|
||||||
function extendClassName(className: string): string {
|
function extendClassName(className: string): string {
|
||||||
|
@ -12,4 +12,4 @@
|
||||||
export let buttons: ToolbarItem[];
|
export let buttons: ToolbarItem[];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonGroup {id} className={extendClassName(className)} {buttons} {...$$restProps} />
|
<ButtonGroup {id} className={extendClassName(className)} {buttons} />
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import type { ToolbarItem } from "./types";
|
import type { ToolbarItem } from "./types";
|
||||||
|
|
||||||
export let id;
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let buttons: ToolbarItem[];
|
export let buttons: ToolbarItem[];
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<ul {id} class={className} {...$$restProps}>
|
<ul {id} class={className}>
|
||||||
{#each buttons as button}
|
{#each buttons as button}
|
||||||
{#if !button.hidden}
|
{#if !button.hidden}
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
export let id = "";
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
|
|
||||||
|
@ -46,7 +46,6 @@
|
||||||
{id}
|
{id}
|
||||||
class={className}
|
class={className}
|
||||||
title={tooltip}
|
title={tooltip}
|
||||||
{...$$restProps}
|
|
||||||
on:mousedown|preventDefault>
|
on:mousedown|preventDefault>
|
||||||
<span> <input type="color" on:change={onChange} /> </span>
|
<span> <input type="color" on:change={onChange} /> </span>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -36,13 +36,15 @@
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import SquareButton from "./SquareButton.svelte";
|
import SquareButton from "./SquareButton.svelte";
|
||||||
|
|
||||||
export let id = "";
|
export let id;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
|
|
||||||
export let icon;
|
export let icon;
|
||||||
export let command: string;
|
export let command: string;
|
||||||
export let activatable = true;
|
export let activatable = true;
|
||||||
|
export let disables = true;
|
||||||
|
export let dropdownToggle = false;
|
||||||
|
|
||||||
let active = false;
|
let active = false;
|
||||||
|
|
||||||
|
@ -61,6 +63,14 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SquareButton {id} {className} {tooltip} {active} {onClick} {...$$restProps} on:mount>
|
<SquareButton
|
||||||
|
{id}
|
||||||
|
{className}
|
||||||
|
{tooltip}
|
||||||
|
{active}
|
||||||
|
{disables}
|
||||||
|
{dropdownToggle}
|
||||||
|
{onClick}
|
||||||
|
on:mount>
|
||||||
{@html icon}
|
{@html icon}
|
||||||
</SquareButton>
|
</SquareButton>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
export let id = "";
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
|
|
||||||
|
@ -12,7 +12,6 @@
|
||||||
{id}
|
{id}
|
||||||
class={`dropdown-item ${className}`}
|
class={`dropdown-item ${className}`}
|
||||||
title={tooltip}
|
title={tooltip}
|
||||||
{...$$restProps}
|
|
||||||
on:click={onClick}
|
on:click={onClick}
|
||||||
on:mousedown|preventDefault>
|
on:mousedown|preventDefault>
|
||||||
<span class="float-start">{label}</span>
|
<span class="float-start">{label}</span>
|
||||||
|
|
|
@ -1,14 +1,16 @@
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import SquareButton from "./SquareButton.svelte";
|
import SquareButton from "./SquareButton.svelte";
|
||||||
|
|
||||||
export let id = "";
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
|
export let disables = true;
|
||||||
|
export let dropdownToggle = false;
|
||||||
|
|
||||||
export let icon = "";
|
export let icon = "";
|
||||||
export let onClick: (event: MouseEvent) => void;
|
export let onClick: (event: MouseEvent) => void;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SquareButton {id} {className} {tooltip} {onClick} {...$$restProps} on:mount>
|
<SquareButton {id} {className} {tooltip} {onClick} {disables} {dropdownToggle} on:mount>
|
||||||
{@html icon}
|
{@html icon}
|
||||||
</SquareButton>
|
</SquareButton>
|
||||||
|
|
|
@ -2,13 +2,21 @@
|
||||||
import { onMount, createEventDispatcher, getContext } from "svelte";
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
||||||
import { disabledKey } from "./contextKeys";
|
import { disabledKey } from "./contextKeys";
|
||||||
|
|
||||||
export let id = "";
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
|
|
||||||
export let label: string;
|
export let label: string;
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
export let onClick: (event: MouseEvent) => void;
|
export let onClick: (event: MouseEvent) => void;
|
||||||
export let disables = true;
|
export let disables = true;
|
||||||
|
export let dropdownToggle = false;
|
||||||
|
|
||||||
|
$: extraProps = dropdownToggle
|
||||||
|
? {
|
||||||
|
"data-bs-toggle": "dropdown",
|
||||||
|
"aria-expanded": "false",
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
|
||||||
let buttonRef: HTMLButtonElement;
|
let buttonRef: HTMLButtonElement;
|
||||||
|
|
||||||
|
@ -51,13 +59,14 @@
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
tabindex="-1"
|
|
||||||
bind:this={buttonRef}
|
bind:this={buttonRef}
|
||||||
disabled={_disabled}
|
|
||||||
{id}
|
{id}
|
||||||
class={extendClassName(className)}
|
class={extendClassName(className)}
|
||||||
|
class:dropdown-toggle={dropdownToggle}
|
||||||
|
tabindex="-1"
|
||||||
|
disabled={_disabled}
|
||||||
title={tooltip}
|
title={tooltip}
|
||||||
{...$$restProps}
|
{...extraProps}
|
||||||
on:click={onClick}
|
on:click={onClick}
|
||||||
on:mousedown|preventDefault>
|
on:mousedown|preventDefault>
|
||||||
{label}
|
{label}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
selected: boolean;
|
selected: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export let id = "";
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
|
|
||||||
|
@ -58,8 +58,7 @@
|
||||||
disabled={_disabled}
|
disabled={_disabled}
|
||||||
{id}
|
{id}
|
||||||
class={extendClassName(className)}
|
class={extendClassName(className)}
|
||||||
title={tooltip}
|
title={tooltip}>
|
||||||
{...$$restProps}>
|
|
||||||
{#each options as option}
|
{#each options as option}
|
||||||
<SelectOption {...option} />
|
<SelectOption {...option} />
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -3,17 +3,26 @@
|
||||||
import type { Readable } from "svelte/store";
|
import type { Readable } from "svelte/store";
|
||||||
import { disabledKey } from "./contextKeys";
|
import { disabledKey } from "./contextKeys";
|
||||||
|
|
||||||
export let id = "";
|
export let id: string;
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let tooltip: string;
|
export let tooltip: string;
|
||||||
|
|
||||||
export let onClick: (event: MouseEvent) => void;
|
export let onClick: (event: MouseEvent) => void;
|
||||||
export let active = false;
|
export let active = false;
|
||||||
|
export let disables = true;
|
||||||
|
export let dropdownToggle = false;
|
||||||
|
|
||||||
|
$: extraProps = dropdownToggle
|
||||||
|
? {
|
||||||
|
"data-bs-toggle": "dropdown",
|
||||||
|
"aria-expanded": "false",
|
||||||
|
}
|
||||||
|
: {};
|
||||||
|
|
||||||
let buttonRef: HTMLButtonElement;
|
let buttonRef: HTMLButtonElement;
|
||||||
|
|
||||||
const disabled = getContext(disabledKey);
|
const disabled = getContext(disabledKey);
|
||||||
$: _disabled = $disabled;
|
$: _disabled = disables && $disabled;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
onMount(() => dispatch("mount", { button: buttonRef }));
|
onMount(() => dispatch("mount", { button: buttonRef }));
|
||||||
|
@ -74,8 +83,7 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* for DropdownMenu */
|
.dropdown-toggle::after {
|
||||||
:global(.dropdown-toggle)::after {
|
|
||||||
margin-right: 0.25rem;
|
margin-right: 0.25rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -84,11 +92,12 @@
|
||||||
bind:this={buttonRef}
|
bind:this={buttonRef}
|
||||||
{id}
|
{id}
|
||||||
class={className}
|
class={className}
|
||||||
title={tooltip}
|
|
||||||
class:active
|
class:active
|
||||||
|
class:dropdown-toggle={dropdownToggle}
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
|
title={tooltip}
|
||||||
disabled={_disabled}
|
disabled={_disabled}
|
||||||
{...$$restProps}
|
{...extraProps}
|
||||||
on:click={onClick}
|
on:click={onClick}
|
||||||
on:mousedown|preventDefault>
|
on:mousedown|preventDefault>
|
||||||
<span class="p-1"><slot /></span>
|
<span class="p-1"><slot /></span>
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import type { ToolbarItem } from "./types";
|
import type { ToolbarItem } from "./types";
|
||||||
|
|
||||||
|
/* Bootstrap dropdown are normally declared alongside the associated button
|
||||||
|
* However we cannot do that, as the menus cannot be declared in sticky-positioned elements
|
||||||
|
*/
|
||||||
export let button: ToolbarItem;
|
export let button: ToolbarItem;
|
||||||
export let menuId: string;
|
export let menuId: string;
|
||||||
|
|
||||||
|
@ -9,9 +12,7 @@
|
||||||
...rest
|
...rest
|
||||||
}: DynamicSvelteComponent): DynamicSvelteComponent {
|
}: DynamicSvelteComponent): DynamicSvelteComponent {
|
||||||
return {
|
return {
|
||||||
className: `${className} dropdown-toggle`,
|
dropdownToggle: true,
|
||||||
"data-bs-toggle": "dropdown",
|
|
||||||
"aria-expanded": "false",
|
|
||||||
...rest,
|
...rest,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue