feat(controls): add orientation, style and class props closes #4069
This commit is contained in:
@@ -237,7 +237,7 @@ const OverviewFlow = () => {
|
|||||||
onPaneMouseMove={onPaneMouseMove}
|
onPaneMouseMove={onPaneMouseMove}
|
||||||
>
|
>
|
||||||
<MiniMap nodeBorderRadius={2} />
|
<MiniMap nodeBorderRadius={2} />
|
||||||
<Controls />
|
<Controls orientation="horizontal" />
|
||||||
<Background gap={25} />
|
<Background gap={25} />
|
||||||
</ReactFlow>
|
</ReactFlow>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -191,7 +191,7 @@
|
|||||||
attributionPosition={'top-center'}
|
attributionPosition={'top-center'}
|
||||||
deleteKey={['Backspace', 'd']}
|
deleteKey={['Backspace', 'd']}
|
||||||
>
|
>
|
||||||
<Controls>
|
<Controls orientation="horizontal">
|
||||||
<ControlButton slot="before">xy</ControlButton>
|
<ControlButton slot="before">xy</ControlButton>
|
||||||
<ControlButton aria-label="log" on:click={() => console.log('control button')}
|
<ControlButton aria-label="log" on:click={() => console.log('control button')}
|
||||||
>log</ControlButton
|
>log</ControlButton
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ function ControlsComponent({
|
|||||||
className,
|
className,
|
||||||
children,
|
children,
|
||||||
position = 'bottom-left',
|
position = 'bottom-left',
|
||||||
|
orientation = 'vertical',
|
||||||
'aria-label': ariaLabel = 'React Flow controls',
|
'aria-label': ariaLabel = 'React Flow controls',
|
||||||
}: ControlProps) {
|
}: ControlProps) {
|
||||||
const store = useStoreApi();
|
const store = useStoreApi();
|
||||||
@@ -65,9 +66,11 @@ function ControlsComponent({
|
|||||||
onInteractiveChange?.(!isInteractive);
|
onInteractiveChange?.(!isInteractive);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const orientationClass = orientation === 'horizontal' ? 'horizontal' : 'vertical';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Panel
|
<Panel
|
||||||
className={cc(['react-flow__controls', className])}
|
className={cc(['react-flow__controls', orientationClass, className])}
|
||||||
position={position}
|
position={position}
|
||||||
style={style}
|
style={style}
|
||||||
data-testid="rf__controls"
|
data-testid="rf__controls"
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ export type ControlProps = {
|
|||||||
/** ClassName applied to container */
|
/** ClassName applied to container */
|
||||||
className?: string;
|
className?: string;
|
||||||
'aria-label'?: string;
|
'aria-label'?: string;
|
||||||
|
orientation?: 'horizontal' | 'vertical';
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ControlButtonProps = ButtonHTMLAttributes<HTMLButtonElement>;
|
export type ControlButtonProps = ButtonHTMLAttributes<HTMLButtonElement>;
|
||||||
|
|||||||
@@ -1,5 +1,13 @@
|
|||||||
# @xyflow/svelte
|
# @xyflow/svelte
|
||||||
|
|
||||||
|
## 0.0.40
|
||||||
|
|
||||||
|
- add `orientation` ('horizontal' or 'vertical'), `style` and `class` prop for `Controls` component
|
||||||
|
- allow multiple keys for `deleteKey`, `selectionKey`, `multiSelectionKey`, `panActivationKey` and `zoomActivationKey`
|
||||||
|
- fix node observe / unobserve
|
||||||
|
- fix edge and node types
|
||||||
|
- active context menu releases pressed keys to reset selection
|
||||||
|
|
||||||
## 0.0.39
|
## 0.0.39
|
||||||
|
|
||||||
## ⚠️ Breaking changes
|
## ⚠️ Breaking changes
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import cc from 'classcat';
|
||||||
|
|
||||||
import Panel from '$lib/container/Panel/Panel.svelte';
|
import Panel from '$lib/container/Panel/Panel.svelte';
|
||||||
import { useStore } from '$lib/store';
|
import { useStore } from '$lib/store';
|
||||||
import ControlButton from './ControlButton.svelte';
|
import ControlButton from './ControlButton.svelte';
|
||||||
@@ -22,6 +24,11 @@
|
|||||||
export let buttonColorHover: $$Props['buttonColorHover'] = undefined;
|
export let buttonColorHover: $$Props['buttonColorHover'] = undefined;
|
||||||
export let buttonBorderColor: $$Props['buttonColorHover'] = undefined;
|
export let buttonBorderColor: $$Props['buttonColorHover'] = undefined;
|
||||||
export let ariaLabel: $$Props['aria-label'] = undefined;
|
export let ariaLabel: $$Props['aria-label'] = undefined;
|
||||||
|
export let style: $$Props['style'] = undefined;
|
||||||
|
export let orientation: $$Props['orientation'] = 'vertical';
|
||||||
|
|
||||||
|
let className: $$Props['class'] = '';
|
||||||
|
export { className as class };
|
||||||
|
|
||||||
const {
|
const {
|
||||||
zoomIn,
|
zoomIn,
|
||||||
@@ -66,13 +73,16 @@
|
|||||||
nodesConnectable.set(isInteractive);
|
nodesConnectable.set(isInteractive);
|
||||||
elementsSelectable.set(isInteractive);
|
elementsSelectable.set(isInteractive);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$: orientationClass = orientation === 'horizontal' ? 'horizontal' : 'vertical';
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Panel
|
<Panel
|
||||||
class="svelte-flow__controls"
|
class={cc(['svelte-flow__controls', orientationClass, className])}
|
||||||
{position}
|
{position}
|
||||||
data-testid="svelte-flow__controls"
|
data-testid="svelte-flow__controls"
|
||||||
aria-label={ariaLabel ?? 'Svelte Flow controls'}
|
aria-label={ariaLabel ?? 'Svelte Flow controls'}
|
||||||
|
{style}
|
||||||
>
|
>
|
||||||
<slot name="before" />
|
<slot name="before" />
|
||||||
{#if showZoom}
|
{#if showZoom}
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ export type ControlsProps = {
|
|||||||
buttonColor?: string;
|
buttonColor?: string;
|
||||||
buttonColorHover?: string;
|
buttonColorHover?: string;
|
||||||
'aria-label'?: string;
|
'aria-label'?: string;
|
||||||
|
style?: string;
|
||||||
|
class?: string;
|
||||||
|
orientation?: 'horizontal' | 'vertical';
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ControlButtonProps = HTMLButtonAttributes & {
|
export type ControlButtonProps = HTMLButtonAttributes & {
|
||||||
|
|||||||
@@ -397,6 +397,13 @@ svg.xy-flow__connectionline {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.xy-flow__controls {
|
.xy-flow__controls {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
|
||||||
|
&.horizontal {
|
||||||
|
flex-direction: row;
|
||||||
|
}
|
||||||
|
|
||||||
&-button {
|
&-button {
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
|
|||||||
Reference in New Issue
Block a user