refactor(svelte): add slot to controls, cleanup ControlButton types closes #3788
This commit is contained in:
@@ -13,7 +13,8 @@
|
|||||||
type Node,
|
type Node,
|
||||||
type Edge,
|
type Edge,
|
||||||
ConnectionMode,
|
ConnectionMode,
|
||||||
useSvelteFlow
|
useSvelteFlow,
|
||||||
|
ControlButton
|
||||||
} from '@xyflow/svelte';
|
} from '@xyflow/svelte';
|
||||||
|
|
||||||
import CustomNode from './CustomNode.svelte';
|
import CustomNode from './CustomNode.svelte';
|
||||||
@@ -187,7 +188,12 @@
|
|||||||
connectionMode={ConnectionMode.Strict}
|
connectionMode={ConnectionMode.Strict}
|
||||||
attributionPosition={'top-center'}
|
attributionPosition={'top-center'}
|
||||||
>
|
>
|
||||||
<Controls />
|
<Controls>
|
||||||
|
<ControlButton slot="before">xy</ControlButton>
|
||||||
|
<ControlButton aria-label="log" on:click={() => console.log('control button')}
|
||||||
|
>log</ControlButton
|
||||||
|
>
|
||||||
|
</Controls>
|
||||||
<Background variant={BackgroundVariant.Dots} />
|
<Background variant={BackgroundVariant.Dots} />
|
||||||
<MiniMap />
|
<MiniMap />
|
||||||
<Panel position="top-right">
|
<Panel position="top-right">
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import cc from 'classcat';
|
import cc from 'classcat';
|
||||||
|
|
||||||
let className: string;
|
import type { ControlButtonProps } from './types';
|
||||||
let bgColor: string | undefined = undefined;
|
|
||||||
let bgColorHover: string | undefined = undefined;
|
type $$Props = ControlButtonProps;
|
||||||
let color: string | undefined = undefined;
|
|
||||||
let colorHover: string | undefined = undefined;
|
let className: $$Props['class'] = undefined;
|
||||||
let borderColor: string | undefined = undefined;
|
let bgColor: $$Props['bgColor'] = undefined;
|
||||||
|
let bgColorHover: $$Props['bgColorHover'] = undefined;
|
||||||
|
let color: $$Props['color'] = undefined;
|
||||||
|
let colorHover: $$Props['colorHover'] = undefined;
|
||||||
|
let borderColor: $$Props['borderColor'] = undefined;
|
||||||
|
|
||||||
export { className as class };
|
export { className as class };
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -74,6 +74,7 @@
|
|||||||
data-testid="svelte-flow__controls"
|
data-testid="svelte-flow__controls"
|
||||||
aria-label={ariaLabel ?? 'Svelte Flow controls'}
|
aria-label={ariaLabel ?? 'Svelte Flow controls'}
|
||||||
>
|
>
|
||||||
|
<slot name="before" />
|
||||||
{#if showZoom}
|
{#if showZoom}
|
||||||
<ControlButton
|
<ControlButton
|
||||||
on:click={onZoomInHandler}
|
on:click={onZoomInHandler}
|
||||||
@@ -118,4 +119,6 @@
|
|||||||
{#if isInteractive}<UnlockIcon />{:else}<LockIcon />{/if}
|
{#if isInteractive}<UnlockIcon />{:else}<LockIcon />{/if}
|
||||||
</ControlButton>
|
</ControlButton>
|
||||||
{/if}
|
{/if}
|
||||||
|
<slot />
|
||||||
|
<slot name="after" />
|
||||||
</Panel>
|
</Panel>
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import type { HTMLButtonAttributes } from 'svelte/elements';
|
||||||
import type { PanelPosition } from '@xyflow/system';
|
import type { PanelPosition } from '@xyflow/system';
|
||||||
|
|
||||||
export type ControlsProps = {
|
export type ControlsProps = {
|
||||||
@@ -11,3 +12,12 @@ export type ControlsProps = {
|
|||||||
buttonColorHover?: string;
|
buttonColorHover?: string;
|
||||||
'aria-label'?: string;
|
'aria-label'?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ControlButtonProps = HTMLButtonAttributes & {
|
||||||
|
class?: string;
|
||||||
|
bgColor?: string;
|
||||||
|
bgColorHover?: string;
|
||||||
|
color?: string;
|
||||||
|
colorHover?: string;
|
||||||
|
borderColor?: string;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user