From 5a246613bd62bb6d67fd907ccb2f0e65dcdb5fb1 Mon Sep 17 00:00:00 2001 From: Wolfr Date: Sat, 5 Jun 2021 13:45:45 +0200 Subject: [PATCH 1/8] Add a radio knob Signed-off-by: Wolfr --- src/lib/index.js | 4 ++++ src/lib/knobs/Radio.svelte | 19 +++++++++++++++++++ src/routes/_/X.svelte | 6 ++++++ 3 files changed, 29 insertions(+) create mode 100644 src/lib/knobs/Radio.svelte diff --git a/src/lib/index.js b/src/lib/index.js index 4221cea..26d6d62 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -7,6 +7,7 @@ import Checkbox from './knobs/Checkbox.svelte'; import Color from './knobs/Color.svelte'; import Range from './knobs/Range.svelte'; import Text from './knobs/Text.svelte'; +import Radio from './knobs/Radio.svelte'; let knobby; @@ -81,6 +82,9 @@ export const range = knobber(Range); /** @type {import('./types').Knobber} */ export const text = knobber(Text); +/** @type {import('./types').Knobber} */ +export const radio = knobber(Radio); + /** * @param {string} label * @param {() => void} action diff --git a/src/lib/knobs/Radio.svelte b/src/lib/knobs/Radio.svelte new file mode 100644 index 0000000..462bb84 --- /dev/null +++ b/src/lib/knobs/Radio.svelte @@ -0,0 +1,19 @@ + + + + + {#each options.radioOptions as item, i} + + {/each} + + diff --git a/src/routes/_/X.svelte b/src/routes/_/X.svelte index b720bb8..9fea1d8 100644 --- a/src/routes/_/X.svelte +++ b/src/routes/_/X.svelte @@ -8,6 +8,9 @@ const bg = knobby.color('background', '#DCFF7A'); const fg = knobby.color('foreground', '#5000C7'); + + const c = knobby.radio('style', 'one', { groupName: 'style', radioOptions: [ 'one', 'two', 'three' ]} ); +
@@ -15,6 +18,9 @@

a: {$a}

b: {$b}

+ +

c: {$c}

+
diff --git a/src/lib/dragcoords.js b/src/lib/dragcoords.js new file mode 100644 index 0000000..bde0962 --- /dev/null +++ b/src/lib/dragcoords.js @@ -0,0 +1,3 @@ +import { writable } from 'svelte/store'; + +export const dragCoords = writable([0,0]); \ No newline at end of file diff --git a/src/lib/draggable.js b/src/lib/draggable.js new file mode 100644 index 0000000..5320b76 --- /dev/null +++ b/src/lib/draggable.js @@ -0,0 +1,47 @@ +export function draggable(node) { + let x; + let y; + + function handleMousedown(event) { + x = event.clientX; + y = event.clientY; + + node.dispatchEvent(new CustomEvent('dragstart', { + detail: { x, y } + })); + + window.addEventListener('mousemove', handleMousemove); + window.addEventListener('mouseup', handleMouseup); + } + + function handleMousemove(event) { + const dx = event.clientX - x; + const dy = event.clientY - y; + x = event.clientX; + y = event.clientY; + + node.dispatchEvent(new CustomEvent('dragmove', { + detail: { x, y, dx, dy } + })); + } + + function handleMouseup(event) { + x = event.clientX; + y = event.clientY; + + node.dispatchEvent(new CustomEvent('dragend', { + detail: { x, y } + })); + + window.removeEventListener('mousemove', handleMousemove); + window.removeEventListener('mouseup', handleMouseup); + } + + node.addEventListener('mousedown', handleMousedown); + + return { + destroy() { + node.removeEventListener('mousedown', handleMousedown); + } + }; +} \ No newline at end of file diff --git a/src/lib/knobs/Action.svelte b/src/lib/knobs/Action.svelte index 228695b..ee1bbc8 100644 --- a/src/lib/knobs/Action.svelte +++ b/src/lib/knobs/Action.svelte @@ -6,23 +6,5 @@ - + - From 87f82d45271829b312c8465706a2f77d649c32f8 Mon Sep 17 00:00:00 2001 From: Wolfr Date: Sat, 5 Jun 2021 14:39:31 +0200 Subject: [PATCH 6/8] Add a select knob Signed-off-by: Wolfr --- src/lib/index.js | 4 ++++ src/lib/knobs/Select.svelte | 16 ++++++++++++++++ src/routes/_/Y.svelte | 5 +++++ 3 files changed, 25 insertions(+) create mode 100644 src/lib/knobs/Select.svelte diff --git a/src/lib/index.js b/src/lib/index.js index 4221cea..7317112 100644 --- a/src/lib/index.js +++ b/src/lib/index.js @@ -7,6 +7,7 @@ import Checkbox from './knobs/Checkbox.svelte'; import Color from './knobs/Color.svelte'; import Range from './knobs/Range.svelte'; import Text from './knobs/Text.svelte'; +import Select from './knobs/Select.svelte'; let knobby; @@ -81,6 +82,9 @@ export const range = knobber(Range); /** @type {import('./types').Knobber} */ export const text = knobber(Text); +/** @type {import('./types').Knobber} */ +export const select = knobber(Select); + /** * @param {string} label * @param {() => void} action diff --git a/src/lib/knobs/Select.svelte b/src/lib/knobs/Select.svelte new file mode 100644 index 0000000..03c1b9b --- /dev/null +++ b/src/lib/knobs/Select.svelte @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/src/routes/_/Y.svelte b/src/routes/_/Y.svelte index 40372b7..9049bec 100644 --- a/src/routes/_/Y.svelte +++ b/src/routes/_/Y.svelte @@ -8,6 +8,9 @@ const bg = knobby.color('background', '#557899'); const fg = knobby.color('foreground', '#ccee33'); + + const e = knobby.select('e', 'a', { options: ['a','b','c','d']}); +
@@ -15,6 +18,8 @@

c: {$c}

d: {$d}

+

e: {$e}

+