Skip to content

Commit dd4895f

Browse files
docs: Added snap-connection documentation and example
1 parent 37972df commit dd4895f

7 files changed

Lines changed: 105 additions & 0 deletions

File tree

projects/f-examples/_flow-common.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
--node-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
77

88
--connection-color: rgba(60, 60, 67, 0.78);
9+
--snap-connection-color: rgba(60, 60, 67, 0.38);
910
--connection-gradient-1: #915930;
1011
--connection-gradient-2: #18794e;
1112

@@ -25,6 +26,7 @@
2526
--node-shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
2627

2728
--connection-color: rgba(235, 235, 245, 0.6);
29+
--snap-connection-color: rgba(235, 235, 245, 0.2);
2830
--connection-gradient-1: #f9b44e;
2931
--connection-gradient-2: #3dd68c;
3032

@@ -58,6 +60,12 @@
5860
fill: var(--connection-color);
5961
color: var(--connection-color);
6062
}
63+
64+
&.f-snap-connection {
65+
.f-connection-path {
66+
stroke: var(--snap-connection-color);
67+
}
68+
}
6169
}
6270
}
6371

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<f-flow fDraggable (fCreateConnection)="addConnection($event)">
2+
<f-canvas>
3+
<f-connection-for-create></f-connection-for-create>
4+
<f-snap-connection [fSnapThreshold]="50"></f-snap-connection>
5+
6+
@for (connection of connections; track connection.inputId) {
7+
<f-connection [fReassignDisabled]="true"
8+
[fOutputId]="connection.outputId" [fInputId]="connection.inputId">
9+
</f-connection>
10+
}
11+
12+
<div fNode fDragHandle [fNodePosition]="{ x: 24, y: 24 }" fNodeOutput fOutputConnectableSide="right">drag me</div>
13+
<div fNode fDragHandle [fNodePosition]="{ x: 244, y: 24 }" fNodeInput fInputConnectableSide="left">to me</div>
14+
15+
</f-canvas>
16+
</f-flow>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@use "../flow-common";
2+
3+
::ng-deep drag-snap-connection {
4+
@include flow-common.connection;
5+
}
6+
7+
.f-node {
8+
@include flow-common.node;
9+
}
10+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';
2+
import { FCreateConnectionEvent, FFlowModule } from '@foblex/flow';
3+
4+
@Component({
5+
selector: 'drag-snap-connection',
6+
styleUrls: [ './drag-snap-connection.component.scss' ],
7+
templateUrl: './drag-snap-connection.component.html',
8+
changeDetection: ChangeDetectionStrategy.OnPush,
9+
standalone: true,
10+
imports: [
11+
FFlowModule
12+
]
13+
})
14+
export class DragSnapConnectionComponent {
15+
16+
public connections: { outputId: string, inputId: string }[] = [];
17+
18+
constructor(
19+
private changeDetectorRef: ChangeDetectorRef
20+
) {
21+
}
22+
23+
public addConnection(event: FCreateConnectionEvent): void {
24+
if(!event.fInputId) {
25+
return;
26+
}
27+
this.connections.push({ outputId: event.fOutputId, inputId: event.fInputId });
28+
this.changeDetectorRef.detectChanges();
29+
}
30+
}

public/docs/en/environment.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ function createEnvironment(): IDocsEnvironment {
3737
{ tag: 'custom-connection-type', component: import('../../../projects/f-examples/custom-connection-type/custom-connection-type.component') },
3838
{ tag: 'drag-to-connect', component: import('../../../projects/f-examples/drag-to-connect/drag-to-connect.component') },
3939
{ tag: 'drag-to-reassign', component: import('../../../projects/f-examples/drag-to-reassign/drag-to-reassign.component') },
40+
{ tag: 'drag-snap-connection', component: import('../../../projects/f-examples/drag-snap-connection/drag-snap-connection.component') },
4041
{ tag: 'connectable-side', component: import('../../../projects/f-examples/connectable-side/connectable-side.component') },
4142
{ tag: 'connection-from-outlet', component: import('../../../projects/f-examples/connection-from-outlet/connection-from-outlet.component') },
4243
{ tag: 'connection-markers', component: import('../../../projects/f-examples/connection-markers/connection-markers.component') },
@@ -138,6 +139,11 @@ function connectionGroup(): INavigationGroup {
138139
text: 'Connection Marker',
139140
description: 'The FMarkerDirective in Foblex Flow defines start or end markers for connections within a flow, enabling customization of marker type, size, and position. It ensures precise control over the visual representation of connection endpoints using SVG elements in your diagrams.',
140141
},
142+
{
143+
link: 'f-snap-connection-component',
144+
text: 'Snap Connection',
145+
description: 'The FSnapConnection component in Foblex Flow allows users to create connections between nodes by snapping to the nearest input. It supports dynamic connection creation within a flow, working seamlessly with the draggable directive for flexible node interaction in diagrams and workflows.',
146+
},
141147
],
142148
}
143149
}

public/docs/en/f-db-management-flow.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This example demonstrates how to use the Foblex Flow to create a database manage
1111

1212
- Connect nodes using [f-connection-for-create](f-connection-for-create-component) component.
1313
- Reassign connections.
14+
- Snap connection.
1415
- Move nodes.
1516
- Move canvas.
1617
- Zoom with the `mouse wheel`, `double click` and `buttons` using [fZoom](f-zoom-directive) directive.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Snap Connection
2+
3+
**Selector:** f-snap-connection
4+
5+
It is used to help users create or reassign connections to the nearest input.
6+
7+
## Inputs
8+
9+
- Similar to the [f-connection](f-connection-component) component
10+
11+
- `fSnapThreshold: number;` The distance in pixels at which the connection snaps to the input. Default: `20`.
12+
13+
## Usage
14+
15+
Add the `f-snap-connection` component to the [f-canvas](f-canvas-component). Works with [f-connection-for-create](f-connection-for-create-component) or [f-connection](f-connection-component) components.
16+
17+
```html
18+
<f-flow |:|fDraggable|:|>
19+
<f-canvas>
20+
|:|<f-snap-connection></f-snap-connection>|:|
21+
</f-canvas>
22+
</f-flow>
23+
```
24+
25+
## Examples
26+
27+
The following example shows how to create a connection between two nodes with snap connection.
28+
29+
::: ng-component <drag-snap-connection></drag-snap-connection>
30+
[component.html] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/drag-snap-connection/drag-snap-connection.component.html
31+
[component.ts] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/drag-snap-connection/drag-snap-connection.component.ts
32+
[component.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/drag-snap-connection/drag-snap-connection.component.scss
33+
[common.scss] <<< https://raw.githubusercontent.com/Foblex/f-flow/main/projects/f-examples/_flow-common.scss
34+
:::

0 commit comments

Comments
 (0)