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); const nightMode = getContext(nightModeKey);
</script> </script>
<div {#if image}
style="--top: {top}px; --left: {left}px; --width: {width}px; --height: {height}px;" <div
class="image-handle-selection" style="--top: {top}px; --left: {left}px; --width: {width}px; --height: {height}px;"
{hidden} class="image-handle-selection"
> {hidden}
<div class="image-handle-bg" /> >
<div class="image-handle-buttons"> <div class="image-handle-bg" />
<ImageHandleButtons <div class="image-handle-buttons">
on:floatleft={floatLeft} <ImageHandleButtons bind:float={image.style.float} />
on:floatright={floatRight} </div>
on:floatreset={floatReset} <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>
<div class="image-handle-dimensions"> {/if}
{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>
<style lang="scss"> <style lang="scss">
div { 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 License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="typescript"> <script lang="typescript">
import { createEventDispatcher } from "svelte";
import ButtonToolbar from "components/ButtonToolbar.svelte"; import ButtonToolbar from "components/ButtonToolbar.svelte";
import ButtonGroup from "components/ButtonGroup.svelte"; import ButtonGroup from "components/ButtonGroup.svelte";
import ButtonGroupItem from "components/ButtonGroupItem.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"; import { floatLeftIcon, floatRightIcon, resetIcon } from "./icons";
const dispatch = createEventDispatcher(); export let float: string;
</script> </script>
<ButtonToolbar size={1.6} wrap={false}> <ButtonToolbar size={1.6} wrap={false}>
<ButtonGroup> <ButtonGroup>
<ButtonGroupItem> <ButtonGroupItem>
<IconButton on:click={() => dispatch("floatleft")} <IconButton active={float === "left"} on:click={() => (float = "left")}
>{@html floatLeftIcon}</IconButton >{@html floatLeftIcon}</IconButton
> >
</ButtonGroupItem> </ButtonGroupItem>
<ButtonGroupItem> <ButtonGroupItem>
<IconButton on:click={() => dispatch("floatright")} <IconButton active={float === "right"} on:click={() => (float = "right")}
>{@html floatRightIcon}</IconButton >{@html floatRightIcon}</IconButton
> >
</ButtonGroupItem> </ButtonGroupItem>
<ButtonGroupItem> <ButtonGroupItem>
<IconButton on:click={() => dispatch("floatreset")} <IconButton
>{@html resetIcon}</IconButton active={float === "" || float === "none"}
on:click={() => (float = "")}>{@html resetIcon}</IconButton
> >
</ButtonGroupItem> </ButtonGroupItem>
</ButtonGroup> </ButtonGroup>