chore(comps): tsdoc update
This commit is contained in:
@@ -2,6 +2,29 @@ import cc from 'classcat';
|
||||
|
||||
import type { ControlButtonProps } from './types';
|
||||
|
||||
/**
|
||||
* You can add buttons to the control panel by using the `<ControlButton />` component
|
||||
*and pass it as a child to the [`<Controls />`](/api-reference/components/controls) component.
|
||||
*
|
||||
* @public
|
||||
* @example
|
||||
*```jsx
|
||||
*import { MagicWand } from '@radix-ui/react-icons'
|
||||
*import { ReactFlow, Controls, ControlButton } from '@xyflow/react'
|
||||
*
|
||||
*export default function Flow() {
|
||||
* return (
|
||||
* <ReactFlow nodes={[...]} edges={[...]}>
|
||||
* <Controls>
|
||||
* <ControlButton onClick={() => alert('Something magical just happened. ✨')}>
|
||||
* <MagicWand />
|
||||
* </ControlButton>
|
||||
* </Controls>
|
||||
* </ReactFlow>
|
||||
* )
|
||||
*}
|
||||
*```
|
||||
*/
|
||||
export function ControlButton({ children, className, ...rest }: ControlButtonProps) {
|
||||
return (
|
||||
<button type="button" className={cc(['react-flow__controls-button', className])} {...rest}>
|
||||
|
||||
@@ -125,4 +125,26 @@ function ControlsComponent({
|
||||
|
||||
ControlsComponent.displayName = 'Controls';
|
||||
|
||||
/**
|
||||
* The `<Controls />` component renders a small panel that contains convenient
|
||||
*buttons to zoom in, zoom out, fit the view, and lock the viewport.
|
||||
*
|
||||
* @public
|
||||
* @example
|
||||
*```tsx
|
||||
*import { ReactFlow, Controls } from '@xyflow/react'
|
||||
*
|
||||
*export default function Flow() {
|
||||
* return (
|
||||
* <ReactFlow nodes={[...]} edges={[...]}>
|
||||
* <Controls />
|
||||
* </ReactFlow>
|
||||
* )
|
||||
*}
|
||||
*```
|
||||
*
|
||||
* @remarks To extend or customise the controls, you can use the [`<ControlButton />`](/api-reference/components/control-button)
|
||||
*component
|
||||
*
|
||||
*/
|
||||
export const Controls = memo(ControlsComponent);
|
||||
|
||||
@@ -178,4 +178,24 @@ function MiniMapComponent<NodeType extends Node = Node>({
|
||||
|
||||
MiniMapComponent.displayName = 'MiniMap';
|
||||
|
||||
/**
|
||||
* The `<MiniMap />` component can be used to render an overview of your flow. It
|
||||
*renders each node as an SVG element and visualizes where the current viewport is
|
||||
*in relation to the rest of the flow.
|
||||
*
|
||||
* @public
|
||||
* @example
|
||||
*
|
||||
* ```jsx
|
||||
*import { ReactFlow, MiniMap } from '@xyflow/react';
|
||||
*
|
||||
*export default function Flow() {
|
||||
* return (
|
||||
* <ReactFlow nodes={[...]]} edges={[...]]}>
|
||||
* <MiniMap nodeStrokeWidth={3} />
|
||||
* </ReactFlow>
|
||||
* );
|
||||
*}
|
||||
*```
|
||||
*/
|
||||
export const MiniMap = memo(MiniMapComponent) as typeof MiniMapComponent;
|
||||
|
||||
@@ -203,4 +203,9 @@ export function ResizeControlLine(props: ResizeControlLineProps) {
|
||||
return <ResizeControl {...props} variant={ResizeControlVariant.Line} />;
|
||||
}
|
||||
|
||||
/**
|
||||
* To create your own resizing UI, you can use the `NodeResizeControl` component where you can pass children (such as icons).
|
||||
* @public
|
||||
*
|
||||
*/
|
||||
export const NodeResizeControl = memo(ResizeControl);
|
||||
|
||||
@@ -3,6 +3,30 @@ import { ResizeControlVariant, XY_RESIZER_HANDLE_POSITIONS, XY_RESIZER_LINE_POSI
|
||||
import { NodeResizeControl } from './NodeResizeControl';
|
||||
import type { NodeResizerProps } from './types';
|
||||
|
||||
/**
|
||||
* The `<NodeResizer />` component can be used to add a resize functionality to your
|
||||
*nodes. It renders draggable controls around the node to resize in all directions.
|
||||
* @public
|
||||
*
|
||||
* @example
|
||||
*```jsx
|
||||
*import { memo } from 'react';
|
||||
*import { Handle, Position, NodeResizer } from '@xyflow/react';
|
||||
*
|
||||
*function ResizableNode({ data }) {
|
||||
* return (
|
||||
* <>
|
||||
* <NodeResizer minWidth={100} minHeight={30} />
|
||||
* <Handle type="target" position={Position.Left} />
|
||||
* <div style={{ padding: 10 }}>{data.label}</div>
|
||||
* <Handle type="source" position={Position.Right} />
|
||||
* </>
|
||||
* );
|
||||
*};
|
||||
*
|
||||
*export default memo(ResizableNode);
|
||||
*```
|
||||
*/
|
||||
export function NodeResizer({
|
||||
nodeId,
|
||||
isVisible = true,
|
||||
|
||||
@@ -38,6 +38,42 @@ const storeSelector = (state: ReactFlowState) => ({
|
||||
selectedNodesCount: state.nodes.filter((node) => node.selected).length,
|
||||
});
|
||||
|
||||
/**
|
||||
* This component can render a toolbar or tooltip to one side of a custom node. This
|
||||
*toolbar doesn't scale with the viewport so that the content is always visible.
|
||||
*
|
||||
* @public
|
||||
* @example
|
||||
* ```jsx
|
||||
*import { memo } from 'react';
|
||||
*import { Handle, Position, NodeToolbar } from '@xyflow/react';
|
||||
*
|
||||
*function CustomNode({ data }) {
|
||||
* return (
|
||||
* <>
|
||||
* <NodeToolbar isVisible={data.toolbarVisible} position={data.toolbarPosition}>
|
||||
* <button>delete</button>
|
||||
* <button>copy</button>
|
||||
* <button>expand</button>
|
||||
* </NodeToolbar>
|
||||
*
|
||||
* <div style={{ padding: '10px 20px' }}>
|
||||
* {data.label}
|
||||
* </div>
|
||||
*
|
||||
* <Handle type="target" position={Position.Left} />
|
||||
* <Handle type="source" position={Position.Right} />
|
||||
* </>
|
||||
* );
|
||||
*};
|
||||
*
|
||||
*export default memo(CustomNode);
|
||||
*```
|
||||
* @remarks By default, the toolbar is only visible when a node is selected. If multiple
|
||||
*nodes are selected it will not be visible to prevent overlapping toolbars or
|
||||
*clutter. You can override this behavior by setting the `isVisible` prop to
|
||||
*`true`.
|
||||
*/
|
||||
export function NodeToolbar({
|
||||
nodeId,
|
||||
children,
|
||||
|
||||
Reference in New Issue
Block a user