-
-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add button and drag to swap colors #227
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
import CopyButton from '$lib/components/util/CopyButton.svelte'; | ||
import type { ColorFormatId } from '$lib/constants'; | ||
import { switchColors } from '$lib/stores'; | ||
import { getSpaceFromFormatId } from '$lib/utils'; | ||
|
||
interface Props { | ||
|
@@ -20,6 +21,7 @@ | |
let editing = $state(false); | ||
let inputValue = $state(''); | ||
let hasError = $state(false); | ||
let isDragging = false; | ||
|
||
// When not editing, sync input value with color (e.g. when sliders change) | ||
$effect(() => { | ||
|
@@ -80,6 +82,12 @@ | |
break; | ||
} | ||
}; | ||
const switchColorsT = () => { | ||
switchColors(); | ||
}; | ||
const makeDropable = (event: DragEvent) => { | ||
if (!isDragging) event.preventDefault(); | ||
}; | ||
Comment on lines
+88
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this do in practice? |
||
</script> | ||
|
||
<div | ||
|
@@ -88,7 +96,16 @@ | |
data-column="tool" | ||
data-needs-changes={hasError} | ||
> | ||
<div class="swatch {type}"></div> | ||
<div | ||
role="complementary" | ||
class="swatch {type}" | ||
draggable="true" | ||
ondrop={switchColorsT} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In practice, this means that colors are switched whenever anything is dropped onto one of the colors. E.g. I can drop an image, URL, etc. Can we limit it to just when the other color is dropped? |
||
ondragenter={makeDropable} | ||
ondragover={makeDropable} | ||
ondragstart={() => (isDragging = true)} | ||
ondragend={() => (isDragging = false)} | ||
></div> | ||
<label for="{type}-color" data-label> | ||
{displayType} Color | ||
</label> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<script lang="ts"> | ||
import Icon from '$lib/components/util/Icon.svelte'; | ||
import { switchColors } from '$lib/stores'; | ||
</script> | ||
|
||
<button type="button" onclick={switchColors} data-btn="icon"> | ||
<Icon name="switch" /> | ||
<span class="sr-only">Click to swap colors</span></button | ||
> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<script lang="ts"> | ||
let props = $props(); | ||
</script> | ||
|
||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
viewBox="0 0 512 512" | ||
width="26" | ||
height="26" | ||
{...props} | ||
> | ||
<path | ||
id="switch" | ||
data-name="switch" | ||
d="M406.6 374.6l96-96c12.5-12.5 12.5-32.8 0-45.3l-96-96c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L402.7 224l-293.5 0 41.4-41.4c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-96 96c-12.5 12.5-12.5 32.8 0 45.3l96 96c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 288l293.5 0-41.4 41.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0z" | ||
/> | ||
</svg> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need to wrap this?