migrate Controls
This commit is contained in:
@@ -3,28 +3,29 @@
|
|||||||
|
|
||||||
import type { ControlButtonProps } from './types';
|
import type { ControlButtonProps } from './types';
|
||||||
|
|
||||||
type $$Props = ControlButtonProps;
|
let {
|
||||||
|
class: className,
|
||||||
let className: $$Props['class'] = undefined;
|
bgColor,
|
||||||
let bgColor: $$Props['bgColor'] = undefined;
|
bgColorHover,
|
||||||
let bgColorHover: $$Props['bgColorHover'] = undefined;
|
color,
|
||||||
let color: $$Props['color'] = undefined;
|
colorHover,
|
||||||
let colorHover: $$Props['colorHover'] = undefined;
|
borderColor,
|
||||||
let borderColor: $$Props['borderColor'] = undefined;
|
onclick,
|
||||||
|
children,
|
||||||
export { className as class };
|
...restProps
|
||||||
|
}: ControlButtonProps = $props();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
on:click
|
{onclick}
|
||||||
class={cc(['svelte-flow__controls-button', className])}
|
class={cc(['svelte-flow__controls-button', className])}
|
||||||
style:--xy-controls-button-background-color-props={bgColor}
|
style:--xy-controls-button-background-color-props={bgColor}
|
||||||
style:--xy-controls-button-background-color-hover-props={bgColorHover}
|
style:--xy-controls-button-background-color-hover-props={bgColorHover}
|
||||||
style:--xy-controls-button-color-props={color}
|
style:--xy-controls-button-color-props={color}
|
||||||
style:--xy-controls-button-color-hover-props={colorHover}
|
style:--xy-controls-button-color-hover-props={colorHover}
|
||||||
style:--xy-controls-button-border-color-props={borderColor}
|
style:--xy-controls-button-border-color-props={borderColor}
|
||||||
{...$$restProps}
|
{...restProps}
|
||||||
>
|
>
|
||||||
<slot class="button-svg" />
|
{@render children?.()}
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -12,35 +12,36 @@
|
|||||||
|
|
||||||
import type { ControlsProps } from './types';
|
import type { ControlsProps } from './types';
|
||||||
|
|
||||||
type $$Props = ControlsProps;
|
let {
|
||||||
|
position = 'bottom-left',
|
||||||
export let position: $$Props['position'] = 'bottom-left';
|
orientation = 'vertical',
|
||||||
export let showZoom: $$Props['showZoom'] = true;
|
showZoom = true,
|
||||||
export let showFitView: $$Props['showFitView'] = true;
|
showFitView = true,
|
||||||
export let showLock: $$Props['showLock'] = true;
|
showLock = true,
|
||||||
export let buttonBgColor: $$Props['buttonBgColor'] = undefined;
|
style,
|
||||||
export let buttonBgColorHover: $$Props['buttonBgColorHover'] = undefined;
|
class: className,
|
||||||
export let buttonColor: $$Props['buttonColor'] = undefined;
|
buttonBgColor,
|
||||||
export let buttonColorHover: $$Props['buttonColorHover'] = undefined;
|
buttonBgColorHover,
|
||||||
export let buttonBorderColor: $$Props['buttonColorHover'] = undefined;
|
buttonColor,
|
||||||
export let ariaLabel: $$Props['aria-label'] = undefined;
|
buttonColorHover,
|
||||||
export let style: $$Props['style'] = undefined;
|
buttonBorderColor,
|
||||||
export let orientation: $$Props['orientation'] = 'vertical';
|
'aria-label': ariaLabel,
|
||||||
export let fitViewOptions: $$Props['fitViewOptions'] = undefined;
|
fitViewOptions,
|
||||||
|
children,
|
||||||
let className: $$Props['class'] = '';
|
before,
|
||||||
export { className as class };
|
after
|
||||||
|
}: ControlsProps = $props();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
zoomIn,
|
|
||||||
zoomOut,
|
|
||||||
fitView,
|
|
||||||
viewport,
|
viewport,
|
||||||
minZoom,
|
minZoom,
|
||||||
maxZoom,
|
maxZoom,
|
||||||
nodesDraggable,
|
nodesDraggable,
|
||||||
nodesConnectable,
|
nodesConnectable,
|
||||||
elementsSelectable
|
elementsSelectable,
|
||||||
|
zoomIn,
|
||||||
|
zoomOut,
|
||||||
|
fitView
|
||||||
} = useStore();
|
} = useStore();
|
||||||
|
|
||||||
const buttonProps = {
|
const buttonProps = {
|
||||||
@@ -51,9 +52,10 @@
|
|||||||
borderColor: buttonBorderColor
|
borderColor: buttonBorderColor
|
||||||
};
|
};
|
||||||
|
|
||||||
$: isInteractive = $nodesDraggable || $nodesConnectable || $elementsSelectable;
|
let isInteractive = $state($nodesDraggable || $nodesConnectable || $elementsSelectable);
|
||||||
$: minZoomReached = $viewport.zoom <= $minZoom;
|
let minZoomReached = $derived($viewport.zoom <= $minZoom);
|
||||||
$: maxZoomReached = $viewport.zoom >= $maxZoom;
|
let maxZoomReached = $derived($viewport.zoom >= $maxZoom);
|
||||||
|
let orientationClass = $derived(orientation === 'horizontal' ? 'horizontal' : 'vertical');
|
||||||
|
|
||||||
const onZoomInHandler = () => {
|
const onZoomInHandler = () => {
|
||||||
zoomIn();
|
zoomIn();
|
||||||
@@ -74,8 +76,6 @@
|
|||||||
nodesConnectable.set(isInteractive);
|
nodesConnectable.set(isInteractive);
|
||||||
elementsSelectable.set(isInteractive);
|
elementsSelectable.set(isInteractive);
|
||||||
};
|
};
|
||||||
|
|
||||||
$: orientationClass = orientation === 'horizontal' ? 'horizontal' : 'vertical';
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Panel
|
<Panel
|
||||||
@@ -85,10 +85,12 @@
|
|||||||
aria-label={ariaLabel ?? 'Svelte Flow controls'}
|
aria-label={ariaLabel ?? 'Svelte Flow controls'}
|
||||||
{style}
|
{style}
|
||||||
>
|
>
|
||||||
<slot name="before" />
|
{#if before}
|
||||||
|
{@render before()}
|
||||||
|
{/if}
|
||||||
{#if showZoom}
|
{#if showZoom}
|
||||||
<ControlButton
|
<ControlButton
|
||||||
on:click={onZoomInHandler}
|
onclick={onZoomInHandler}
|
||||||
class="svelte-flow__controls-zoomin"
|
class="svelte-flow__controls-zoomin"
|
||||||
title="zoom in"
|
title="zoom in"
|
||||||
aria-label="zoom in"
|
aria-label="zoom in"
|
||||||
@@ -98,7 +100,7 @@
|
|||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
</ControlButton>
|
</ControlButton>
|
||||||
<ControlButton
|
<ControlButton
|
||||||
on:click={onZoomOutHandler}
|
onclick={onZoomOutHandler}
|
||||||
class="svelte-flow__controls-zoomout"
|
class="svelte-flow__controls-zoomout"
|
||||||
title="zoom out"
|
title="zoom out"
|
||||||
aria-label="zoom out"
|
aria-label="zoom out"
|
||||||
@@ -111,7 +113,7 @@
|
|||||||
{#if showFitView}
|
{#if showFitView}
|
||||||
<ControlButton
|
<ControlButton
|
||||||
class="svelte-flow__controls-fitview"
|
class="svelte-flow__controls-fitview"
|
||||||
on:click={onFitViewHandler}
|
onclick={onFitViewHandler}
|
||||||
title="fit view"
|
title="fit view"
|
||||||
aria-label="fit view"
|
aria-label="fit view"
|
||||||
{...buttonProps}
|
{...buttonProps}
|
||||||
@@ -122,7 +124,7 @@
|
|||||||
{#if showLock}
|
{#if showLock}
|
||||||
<ControlButton
|
<ControlButton
|
||||||
class="svelte-flow__controls-interactive"
|
class="svelte-flow__controls-interactive"
|
||||||
on:click={onToggleInteractivity}
|
onclick={onToggleInteractivity}
|
||||||
title="toggle interactivity"
|
title="toggle interactivity"
|
||||||
aria-label="toggle interactivity"
|
aria-label="toggle interactivity"
|
||||||
{...buttonProps}
|
{...buttonProps}
|
||||||
@@ -130,6 +132,10 @@
|
|||||||
{#if isInteractive}<UnlockIcon />{:else}<LockIcon />{/if}
|
{#if isInteractive}<UnlockIcon />{:else}<LockIcon />{/if}
|
||||||
</ControlButton>
|
</ControlButton>
|
||||||
{/if}
|
{/if}
|
||||||
<slot />
|
{#if children}
|
||||||
<slot name="after" />
|
{@render children()}
|
||||||
|
{/if}
|
||||||
|
{#if after}
|
||||||
|
{@render after()}
|
||||||
|
{/if}
|
||||||
</Panel>
|
</Panel>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { Snippet } from 'svelte';
|
||||||
import type { HTMLButtonAttributes } from 'svelte/elements';
|
import type { HTMLButtonAttributes } from 'svelte/elements';
|
||||||
import type { PanelPosition } from '@xyflow/system';
|
import type { PanelPosition } from '@xyflow/system';
|
||||||
|
|
||||||
@@ -19,10 +20,14 @@ export type ControlsProps = {
|
|||||||
buttonBgColorHover?: string;
|
buttonBgColorHover?: string;
|
||||||
buttonColor?: string;
|
buttonColor?: string;
|
||||||
buttonColorHover?: string;
|
buttonColorHover?: string;
|
||||||
|
buttonBorderColor?: string;
|
||||||
'aria-label'?: string;
|
'aria-label'?: string;
|
||||||
style?: string;
|
style?: string;
|
||||||
class?: string;
|
class?: string;
|
||||||
orientation?: 'horizontal' | 'vertical';
|
orientation?: 'horizontal' | 'vertical';
|
||||||
|
children?: Snippet;
|
||||||
|
before?: Snippet;
|
||||||
|
after?: Snippet;
|
||||||
fitViewOptions?: FitViewOptions;
|
fitViewOptions?: FitViewOptions;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -33,4 +38,5 @@ export type ControlButtonProps = HTMLButtonAttributes & {
|
|||||||
color?: string;
|
color?: string;
|
||||||
colorHover?: string;
|
colorHover?: string;
|
||||||
borderColor?: string;
|
borderColor?: string;
|
||||||
|
children?: Snippet;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user