refactor(panel): simplify / fix panel pointer events #5356
This commit is contained in:
@@ -2,9 +2,6 @@ import { HTMLAttributes, forwardRef } from 'react';
|
|||||||
import cc from 'classcat';
|
import cc from 'classcat';
|
||||||
import type { PanelPosition } from '@xyflow/system';
|
import type { PanelPosition } from '@xyflow/system';
|
||||||
|
|
||||||
import { useStore } from '../../hooks/useStore';
|
|
||||||
import type { ReactFlowState } from '../../types';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expand
|
* @expand
|
||||||
*/
|
*/
|
||||||
@@ -16,8 +13,6 @@ export type PanelProps = HTMLAttributes<HTMLDivElement> & {
|
|||||||
position?: PanelPosition;
|
position?: PanelPosition;
|
||||||
};
|
};
|
||||||
|
|
||||||
const selector = (s: ReactFlowState) => (s.userSelectionActive ? 'none' : 'all');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `<Panel />` component helps you position content above the viewport.
|
* The `<Panel />` component helps you position content above the viewport.
|
||||||
* It is used internally by the [`<MiniMap />`](/api-reference/components/minimap)
|
* It is used internally by the [`<MiniMap />`](/api-reference/components/minimap)
|
||||||
@@ -45,16 +40,10 @@ const selector = (s: ReactFlowState) => (s.userSelectionActive ? 'none' : 'all')
|
|||||||
*/
|
*/
|
||||||
export const Panel = forwardRef<HTMLDivElement, PanelProps>(
|
export const Panel = forwardRef<HTMLDivElement, PanelProps>(
|
||||||
({ position = 'top-left', children, className, style, ...rest }, ref) => {
|
({ position = 'top-left', children, className, style, ...rest }, ref) => {
|
||||||
const pointerEvents = useStore(selector);
|
|
||||||
const positionClasses = `${position}`.split('-');
|
const positionClasses = `${position}`.split('-');
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div className={cc(['react-flow__panel', className, ...positionClasses])} style={style} ref={ref} {...rest}>
|
||||||
className={cc(['react-flow__panel', className, ...positionClasses])}
|
|
||||||
style={{ ...style, pointerEvents }}
|
|
||||||
ref={ref}
|
|
||||||
{...rest}
|
|
||||||
>
|
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,19 +1,11 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { PanelProps } from './types';
|
import type { PanelProps } from './types';
|
||||||
import { useStore } from '$lib/store';
|
|
||||||
|
|
||||||
let { position = 'top-right', style, class: className, children, ...rest }: PanelProps = $props();
|
let { position = 'top-right', style, class: className, children, ...rest }: PanelProps = $props();
|
||||||
|
|
||||||
let store = $derived(useStore());
|
|
||||||
|
|
||||||
let positionClasses = $derived(`${position}`.split('-'));
|
let positionClasses = $derived(`${position}`.split('-'));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div class={['svelte-flow__panel', className, ...positionClasses]} {style} {...rest}>
|
||||||
class={['svelte-flow__panel', className, ...positionClasses]}
|
|
||||||
{style}
|
|
||||||
style:pointer-events={store.selectionRectMode ? 'none' : ''}
|
|
||||||
{...rest}
|
|
||||||
>
|
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -265,6 +265,10 @@ svg.xy-flow__connectionline {
|
|||||||
pointer-events: all;
|
pointer-events: all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.xy-flow__pane.selection .xy-flow__panel {
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
|
|
||||||
.xy-flow__panel {
|
.xy-flow__panel {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 5;
|
z-index: 5;
|
||||||
|
|||||||
Reference in New Issue
Block a user