Bind to style properties instead of events

This commit is contained in:
Henrik Giesel 2021-07-21 03:50:52 +02:00 committed by Damien Elmes
parent 8429d00081
commit b3c921b86c
2 changed files with 28 additions and 31 deletions

View file

@ -89,32 +89,30 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
const nightMode = getContext(nightModeKey);
</script>
<div
style="--top: {top}px; --left: {left}px; --width: {width}px; --height: {height}px;"
class="image-handle-selection"
{hidden}
>
<div class="image-handle-bg" />
<div class="image-handle-buttons">
<ImageHandleButtons
on:floatleft={floatLeft}
on:floatright={floatRight}
on:floatreset={floatReset}
{#if image}
<div
style="--top: {top}px; --left: {left}px; --width: {width}px; --height: {height}px;"
class="image-handle-selection"
{hidden}
>
<div class="image-handle-bg" />
<div class="image-handle-buttons">
<ImageHandleButtons bind:float={image.style.float} />
</div>
<div class="image-handle-dimensions">
{width}&times;{height} (Original: {naturalWidth}&times;{naturalHeight})
</div>
<div class:nightMode class="image-handle-control image-handle-control-nw" />
<div class:nightMode class="image-handle-control image-handle-control-ne" />
<div class:nightMode class="image-handle-control image-handle-control-sw" />
<div
class:nightMode
class="image-handle-control image-handle-control-se is-active"
on:pointerdown={setPointerCapture}
on:pointermove={resize}
/>
</div>
<div class="image-handle-dimensions">
{width}&times;{height} (Original: {naturalWidth}&times;{naturalHeight})
</div>
<div class:nightMode class="image-handle-control image-handle-control-nw" />
<div class:nightMode class="image-handle-control image-handle-control-ne" />
<div class:nightMode class="image-handle-control image-handle-control-sw" />
<div
class:nightMode
class="image-handle-control image-handle-control-se is-active"
on:pointerdown={setPointerCapture}
on:pointermove={resize}
/>
</div>
{/if}
<style lang="scss">
div {

View file

@ -3,8 +3,6 @@ Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import { createEventDispatcher } from "svelte";
import ButtonToolbar from "components/ButtonToolbar.svelte";
import ButtonGroup from "components/ButtonGroup.svelte";
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
@ -12,26 +10,27 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { floatLeftIcon, floatRightIcon, resetIcon } from "./icons";
const dispatch = createEventDispatcher();
export let float: string;
</script>
<ButtonToolbar size={1.6} wrap={false}>
<ButtonGroup>
<ButtonGroupItem>
<IconButton on:click={() => dispatch("floatleft")}
<IconButton active={float === "left"} on:click={() => (float = "left")}
>{@html floatLeftIcon}</IconButton
>
</ButtonGroupItem>
<ButtonGroupItem>
<IconButton on:click={() => dispatch("floatright")}
<IconButton active={float === "right"} on:click={() => (float = "right")}
>{@html floatRightIcon}</IconButton
>
</ButtonGroupItem>
<ButtonGroupItem>
<IconButton on:click={() => dispatch("floatreset")}
>{@html resetIcon}</IconButton
<IconButton
active={float === "" || float === "none"}
on:click={() => (float = "")}>{@html resetIcon}</IconButton
>
</ButtonGroupItem>
</ButtonGroup>