Improve Select component and add it back to Change Notetype screen (#2239)
* Do not include oldIdx in Select change event I included it due to confusion about the variable names in the Change Notetype components. * Remove redundant on:change listener from NotetypeSelector * Use Select component in Change Notetype MapperRow (again) * Remove redundant --cols and --col-size definitions Bootstrap divides rows into columns of equal width by default. * Add highlight to active DropdownItem * Remove bootstrap dropdown item styling * Fix JS error on dropdown accept action cause: When closing the dropdown, buttonRef was removed before the callback in setTimeout was run.
This commit is contained in:
parent
9dc6e41153
commit
e059aab184
@ -5,6 +5,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Col from "../components/Col.svelte";
|
import Col from "../components/Col.svelte";
|
||||||
import Row from "../components/Row.svelte";
|
import Row from "../components/Row.svelte";
|
||||||
|
import Select from "../components/Select.svelte";
|
||||||
|
import SelectOption from "../components/SelectOption.svelte";
|
||||||
import type { ChangeNotetypeState, MapContext } from "./lib";
|
import type { ChangeNotetypeState, MapContext } from "./lib";
|
||||||
|
|
||||||
export let state: ChangeNotetypeState;
|
export let state: ChangeNotetypeState;
|
||||||
@ -12,26 +14,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
export let newIndex: number;
|
export let newIndex: number;
|
||||||
|
|
||||||
const info = state.info;
|
const info = state.info;
|
||||||
|
$: oldIndex = $info.getOldIndex(ctx, newIndex);
|
||||||
|
|
||||||
function onChange(evt: Event) {
|
function onChange(evt: CustomEvent) {
|
||||||
const oldIdx = parseInt((evt.target as HTMLSelectElement).value, 10);
|
oldIndex = evt.detail.value;
|
||||||
state.setOldIndex(ctx, newIndex, oldIdx);
|
state.setOldIndex(ctx, newIndex, oldIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$: label = $info.getOldNamesIncludingNothing(ctx)[oldIndex];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Row --cols={2}>
|
<Row>
|
||||||
<Col --col-size={1}>
|
<Col>
|
||||||
<select
|
<Select value={oldIndex} {label} on:change={onChange}>
|
||||||
value={$info.getOldIndex(ctx, newIndex)}
|
|
||||||
class="form-select"
|
|
||||||
on:change={onChange}
|
|
||||||
>
|
|
||||||
{#each $info.getOldNamesIncludingNothing(ctx) as name, idx}
|
{#each $info.getOldNamesIncludingNothing(ctx) as name, idx}
|
||||||
<option value={idx}>{name}</option>
|
<SelectOption value={idx}>{name}</SelectOption>
|
||||||
{/each}
|
{/each}
|
||||||
</select>
|
</Select>
|
||||||
</Col>
|
</Col>
|
||||||
<Col --col-size={1}>
|
<Col>
|
||||||
{$info.getNewName(ctx, newIndex)}
|
{$info.getNewName(ctx, newIndex)}
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
@ -20,9 +20,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
$: options = Array.from($notetypes, (notetype) => notetype.name);
|
$: options = Array.from($notetypes, (notetype) => notetype.name);
|
||||||
$: label = options[value];
|
$: label = options[value];
|
||||||
|
|
||||||
function blur(e: CustomEvent): void {
|
$: state.setTargetNotetypeIndex(value);
|
||||||
state.setTargetNotetypeIndex(e.detail.newIdx);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonToolbar class="justify-content-between" wrap={false}>
|
<ButtonToolbar class="justify-content-between" wrap={false}>
|
||||||
@ -36,7 +34,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
{@html arrowRightIcon}
|
{@html arrowRightIcon}
|
||||||
{/if}
|
{/if}
|
||||||
</Badge>
|
</Badge>
|
||||||
<Select class="flex-grow-1" bind:value {label} on:change={blur}>
|
<Select class="flex-grow-1" bind:value {label}>
|
||||||
{#each options as option, idx}
|
{#each options as option, idx}
|
||||||
<SelectOption value={idx}>{option}</SelectOption>
|
<SelectOption value={idx}>{option}</SelectOption>
|
||||||
{/each}
|
{/each}
|
||||||
|
@ -14,13 +14,13 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
export let active = false;
|
export let active = false;
|
||||||
export let disabled = false;
|
export let disabled = false;
|
||||||
|
|
||||||
|
const rtl: boolean = window.getComputedStyle(document.body).direction == "rtl";
|
||||||
|
|
||||||
$: if (buttonRef && active) {
|
$: if (buttonRef && active) {
|
||||||
setTimeout(() =>
|
buttonRef!.scrollIntoView({
|
||||||
buttonRef!.scrollIntoView({
|
behavior: "smooth",
|
||||||
behavior: "smooth",
|
block: "nearest",
|
||||||
block: "nearest",
|
});
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export let tabbable = false;
|
export let tabbable = false;
|
||||||
@ -33,6 +33,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
class="dropdown-item {className}"
|
class="dropdown-item {className}"
|
||||||
class:active
|
class:active
|
||||||
class:disabled
|
class:disabled
|
||||||
|
class:rtl
|
||||||
title={tooltip}
|
title={tooltip}
|
||||||
on:mouseenter
|
on:mouseenter
|
||||||
on:focus
|
on:focus
|
||||||
@ -61,5 +62,21 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
background: var(--highlight-bg);
|
background: var(--highlight-bg);
|
||||||
color: var(--highlight-fg);
|
color: var(--highlight-fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -4,6 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher, setContext } from "svelte";
|
import { createEventDispatcher, setContext } from "svelte";
|
||||||
|
import { writable } from "svelte/store";
|
||||||
|
|
||||||
import { selectKey } from "./context-keys";
|
import { selectKey } from "./context-keys";
|
||||||
import IconConstrain from "./IconConstrain.svelte";
|
import IconConstrain from "./IconConstrain.svelte";
|
||||||
@ -23,8 +24,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
function setValue(v: number) {
|
function setValue(v: number) {
|
||||||
dispatch("change", { oldIdx: value, newIdx: v });
|
|
||||||
value = v;
|
value = v;
|
||||||
|
dispatch("change", { value });
|
||||||
}
|
}
|
||||||
|
|
||||||
export let element: HTMLElement | undefined = undefined;
|
export let element: HTMLElement | undefined = undefined;
|
||||||
@ -44,7 +45,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setContext(selectKey, setValue);
|
const selectStore = writable({ value, setValue });
|
||||||
|
$: $selectStore.value = value;
|
||||||
|
setContext(selectKey, selectStore);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<WithFloating
|
<WithFloating
|
||||||
|
@ -4,6 +4,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { getContext } from "svelte";
|
import { getContext } from "svelte";
|
||||||
|
import type { Writable } from "svelte/store";
|
||||||
|
|
||||||
import { selectKey } from "./context-keys";
|
import { selectKey } from "./context-keys";
|
||||||
import DropdownItem from "./DropdownItem.svelte";
|
import DropdownItem from "./DropdownItem.svelte";
|
||||||
@ -39,11 +40,14 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const setValue: Function = getContext(selectKey);
|
const selectContext: Writable<{ value: number; setValue: Function }> =
|
||||||
|
getContext(selectKey);
|
||||||
|
const setValue = $selectContext.setValue;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<DropdownItem
|
<DropdownItem
|
||||||
{disabled}
|
{disabled}
|
||||||
|
active={value == $selectContext.value}
|
||||||
on:click={() => setValue(value)}
|
on:click={() => setValue(value)}
|
||||||
on:keydown={handleKey}
|
on:keydown={handleKey}
|
||||||
bind:buttonRef={element}
|
bind:buttonRef={element}
|
||||||
|
@ -30,7 +30,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
}
|
}
|
||||||
|
|
||||||
function blur(e: CustomEvent): void {
|
function blur(e: CustomEvent): void {
|
||||||
state.setCurrentIndex(e.detail.newIdx);
|
state.setCurrentIndex(e.detail.value);
|
||||||
dispatchPresetChange();
|
dispatchPresetChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// override Bootstrap transition duration
|
// override Bootstrap transition duration
|
||||||
$carousel-transition: 0.2s;
|
$carousel-transition: 0.2s;
|
||||||
|
|
||||||
@import "bootstrap/scss/dropdown";
|
|
||||||
@import "bootstrap/scss/buttons";
|
@import "bootstrap/scss/buttons";
|
||||||
@import "bootstrap/scss/button-group";
|
@import "bootstrap/scss/button-group";
|
||||||
@import "bootstrap/scss/transitions";
|
@import "bootstrap/scss/transitions";
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
$btn-disabled-opacity: 0.4;
|
$btn-disabled-opacity: 0.4;
|
||||||
@import "bootstrap/scss/buttons";
|
@import "bootstrap/scss/buttons";
|
||||||
@import "bootstrap/scss/button-group";
|
@import "bootstrap/scss/button-group";
|
||||||
@import "bootstrap/scss/dropdown";
|
|
||||||
@import "sass/bootstrap-tooltip";
|
@import "sass/bootstrap-tooltip";
|
||||||
|
|
||||||
html,
|
html,
|
||||||
|
Loading…
Reference in New Issue
Block a user