-
-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create 'getting started with rf components' guide & expand our components offering. #602
Open
hayleigh-dot-dev
wants to merge
14
commits into
main
Choose a base branch
from
hayleigh/getting-started-with-components
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a61b8e2
:memo:
hayleigh-dot-dev d2b7ba2
:heavy_plus_sign: Add shadcn dropdown.
hayleigh-dot-dev cc82816
:sparkles: Create node-header container and child components.
hayleigh-dot-dev 95a2c96
:recycle: Remove too-specific delete and copy actions.
hayleigh-dot-dev 6f11dc1
:sparkles: Create docs page for node-header component.
hayleigh-dot-dev 1391ed2
:recycle: Remove unused imports.
hayleigh-dot-dev d88aa4a
:recycle: Correctly name _meta file.
hayleigh-dot-dev 40c321e
:sparkles: Create a new DataEdge component.
hayleigh-dot-dev d083f4c
:memo: Add docs page for new DataEdge component.
hayleigh-dot-dev 93accb6
:wrench: Lock nextra to v3.0.15
hayleigh-dot-dev 8e30d25
:bug: Fixed a bug where data-edge did not have a default type param.
hayleigh-dot-dev 864448e
:sparkles: Create examples for components guide.
hayleigh-dot-dev bf62d9b
:memo: Create guide on how to get started with React Flow Components.
hayleigh-dot-dev 440ad48
Merge branch 'main' into hayleigh/getting-started-with-components
hayleigh-dot-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
apps/example-apps/react/tutorials/components/tooltip/App.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import React, { useCallback } from 'react'; | ||
import { | ||
ReactFlow, | ||
type Node, | ||
type Edge, | ||
type OnConnect, | ||
Position, | ||
addEdge, | ||
useNodesState, | ||
useEdgesState, | ||
} from '@xyflow/react'; | ||
|
||
import '@xyflow/react/dist/style.css'; | ||
|
||
import { TooltipNode } from './components/tooltip-node'; | ||
|
||
const nodeTypes = { | ||
tooltip: TooltipNode, | ||
}; | ||
|
||
const initialNodes: Node[] = [ | ||
{ | ||
id: '1', | ||
position: { x: 0, y: 0 }, | ||
data: { | ||
label: 'Hover me', | ||
tooltip: { | ||
label: 'Boo!', | ||
position: Position.Bottom, | ||
}, | ||
}, | ||
type: 'tooltip', | ||
}, | ||
]; | ||
|
||
const initialEdges: Edge[] = []; | ||
|
||
function Flow() { | ||
const [nodes, , onNodesChange] = useNodesState(initialNodes); | ||
const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); | ||
|
||
const onConnect: OnConnect = (params) => { | ||
setEdges((edges) => addEdge(params, edges)); | ||
}; | ||
|
||
return ( | ||
<div className="h-screen w-screen p-8 bg-gray-50 rounded-xl"> | ||
<ReactFlow | ||
nodes={nodes} | ||
edges={edges} | ||
onNodesChange={onNodesChange} | ||
onEdgesChange={onEdgesChange} | ||
onConnect={onConnect} | ||
nodeTypes={nodeTypes} | ||
fitView | ||
/> | ||
</div> | ||
); | ||
} | ||
export function App() { | ||
return <Flow />; | ||
} |
19 changes: 19 additions & 0 deletions
19
apps/example-apps/react/tutorials/components/tooltip/components/base-node.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react'; | ||
import { cn } from '../lib/utils'; | ||
|
||
export const BaseNode = React.forwardRef< | ||
HTMLDivElement, | ||
React.HTMLAttributes<HTMLDivElement> & { selected?: boolean } | ||
>(({ className, selected, ...props }, ref) => ( | ||
<div | ||
ref={ref} | ||
className={cn( | ||
'rounded-md border bg-card p-5 text-card-foreground font-mono font-bold', | ||
className, | ||
selected ? 'border-muted-foreground shadow-lg' : '', | ||
'hover:ring-1', | ||
)} | ||
{...props} | ||
/> | ||
)); | ||
BaseNode.displayName = 'BaseNode'; |
41 changes: 41 additions & 0 deletions
41
apps/example-apps/react/tutorials/components/tooltip/components/tooltip-node.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from 'react'; | ||
import { | ||
type Node, | ||
type NodeProps, | ||
type NodeToolbarProps, | ||
NodeToolbar, | ||
Handle, | ||
Position, | ||
} from '@xyflow/react'; | ||
import { BaseNode } from './base-node'; | ||
|
||
export type TooltipNodeType = Node<{ | ||
label: string; | ||
tooltip?: { | ||
label: string; | ||
position?: NodeToolbarProps['position']; | ||
}; | ||
}>; | ||
|
||
export function TooltipNode({ data, selected }: NodeProps<TooltipNodeType>) { | ||
const [isTooltipVisible, setTooltipVisible] = useState(false); | ||
|
||
return ( | ||
<BaseNode | ||
onMouseEnter={() => setTooltipVisible(true)} | ||
onMouseLeave={() => setTooltipVisible(false)} | ||
selected={selected} | ||
> | ||
<NodeToolbar | ||
isVisible={isTooltipVisible || selected} | ||
className="rounded-sm bg-primary p-2 text-primary-foreground" | ||
position={data.tooltip?.position} | ||
> | ||
{data.tooltip?.label} | ||
</NodeToolbar> | ||
<div>{data.label}</div> | ||
<Handle type="target" position={Position.Top} /> | ||
<Handle type="source" position={Position.Bottom} /> | ||
</BaseNode> | ||
); | ||
} |
1 change: 1 addition & 0 deletions
1
apps/example-apps/react/tutorials/components/tooltip/dependencies.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["@xyflow/react", "react-dom", "react", "tailwindcss", "clsx", "tailwind-merge"] |
64 changes: 64 additions & 0 deletions
64
apps/example-apps/react/tutorials/components/tooltip/index.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
html, | ||
body { | ||
margin: 0; | ||
font-family: sans-serif; | ||
} | ||
|
||
#app { | ||
width: 100vw; | ||
height: 100vh; | ||
} | ||
|
||
:root { | ||
--background: 0 0% 100%; | ||
--foreground: 0 0% 3.9%; | ||
--card: 0 0% 100%; | ||
--card-foreground: 0 0% 3.9%; | ||
--popover: 0 0% 100%; | ||
--popover-foreground: 0 0% 3.9%; | ||
--primary: 0 0% 9%; | ||
--primary-foreground: 0 0% 98%; | ||
--secondary: 0 0% 96.1%; | ||
--secondary-foreground: 0 0% 9%; | ||
--muted: 0 0% 96.1%; | ||
--muted-foreground: 0 0% 45.1%; | ||
--accent: 0 0% 96.1%; | ||
--accent-foreground: 0 0% 9%; | ||
--destructive: 0 84.2% 60.2%; | ||
--destructive-foreground: 0 0% 98%; | ||
--border: 0 0% 89.8%; | ||
--input: 0 0% 89.8%; | ||
--ring: 0 0% 3.9%; | ||
--chart-1: 12 76% 61%; | ||
--chart-2: 173 58% 39%; | ||
--chart-3: 197 37% 24%; | ||
--chart-4: 43 74% 66%; | ||
--chart-5: 27 87% 67%; | ||
--radius: 0.5rem; | ||
} | ||
.dark { | ||
--background: 0 0% 3.9%; | ||
--foreground: 0 0% 98%; | ||
--card: 0 0% 3.9%; | ||
--card-foreground: 0 0% 98%; | ||
--popover: 0 0% 3.9%; | ||
--popover-foreground: 0 0% 98%; | ||
--primary: 0 0% 98%; | ||
--primary-foreground: 0 0% 9%; | ||
--secondary: 0 0% 14.9%; | ||
--secondary-foreground: 0 0% 98%; | ||
--muted: 0 0% 14.9%; | ||
--muted-foreground: 0 0% 63.9%; | ||
--accent: 0 0% 14.9%; | ||
--accent-foreground: 0 0% 98%; | ||
--destructive: 0 62.8% 30.6%; | ||
--destructive-foreground: 0 0% 98%; | ||
--border: 0 0% 14.9%; | ||
--input: 0 0% 14.9%; | ||
--ring: 0 0% 83.1%; | ||
--chart-1: 220 70% 50%; | ||
--chart-2: 160 60% 45%; | ||
--chart-3: 30 80% 55%; | ||
--chart-4: 280 65% 60%; | ||
--chart-5: 340 75% 55%; | ||
} |
70 changes: 70 additions & 0 deletions
70
apps/example-apps/react/tutorials/components/tooltip/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>React Flow Example</title> | ||
<script src="https://cdn.tailwindcss.com"></script> | ||
<script> | ||
/** @type {import('tailwindcss').Config} */ | ||
tailwind.config = { | ||
content: ['./index.html', './src/**/*.{ts,tsx,js,jsx}'], | ||
theme: { | ||
extend: { | ||
borderRadius: { | ||
lg: 'var(--radius)', | ||
md: 'calc(var(--radius) - 2px)', | ||
sm: 'calc(var(--radius) - 4px)', | ||
}, | ||
colors: { | ||
background: 'hsl(var(--background))', | ||
foreground: 'hsl(var(--foreground))', | ||
card: { | ||
DEFAULT: 'hsl(var(--card))', | ||
foreground: 'hsl(var(--card-foreground))', | ||
}, | ||
popover: { | ||
DEFAULT: 'hsl(var(--popover))', | ||
foreground: 'hsl(var(--popover-foreground))', | ||
}, | ||
primary: { | ||
DEFAULT: 'hsl(var(--primary))', | ||
foreground: 'hsl(var(--primary-foreground))', | ||
}, | ||
secondary: { | ||
DEFAULT: 'hsl(var(--secondary))', | ||
foreground: 'hsl(var(--secondary-foreground))', | ||
}, | ||
muted: { | ||
DEFAULT: 'hsl(var(--muted))', | ||
foreground: 'hsl(var(--muted-foreground))', | ||
}, | ||
accent: { | ||
DEFAULT: 'hsl(var(--accent))', | ||
foreground: 'hsl(var(--accent-foreground))', | ||
}, | ||
destructive: { | ||
DEFAULT: 'hsl(var(--destructive))', | ||
foreground: 'hsl(var(--destructive-foreground))', | ||
}, | ||
border: 'hsl(var(--border))', | ||
input: 'hsl(var(--input))', | ||
ring: 'hsl(var(--ring))', | ||
chart: { | ||
1: 'hsl(var(--chart-1))', | ||
2: 'hsl(var(--chart-2))', | ||
3: 'hsl(var(--chart-3))', | ||
4: 'hsl(var(--chart-4))', | ||
5: 'hsl(var(--chart-5))', | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
</script> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script type="module" src="./index.tsx"></script> | ||
</body> | ||
</html> |
9 changes: 9 additions & 0 deletions
9
apps/example-apps/react/tutorials/components/tooltip/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { createRoot } from 'react-dom/client'; | ||
import { App } from './App'; | ||
|
||
import './index.css'; | ||
|
||
const container = document.querySelector('#app'); | ||
const root = createRoot(container); | ||
|
||
root.render(<App />); |
6 changes: 6 additions & 0 deletions
6
apps/example-apps/react/tutorials/components/tooltip/lib/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { clsx, type ClassValue } from 'clsx'; | ||
import { twMerge } from 'tailwind-merge'; | ||
|
||
export function cn(...inputs: ClassValue[]) { | ||
return twMerge(clsx(inputs)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import DemoWrapper from "@/components/demo-wrapper"; | ||
import Demo from "@/registry/components/node-header/demo"; | ||
|
||
export default function DemoPage() { | ||
return ( | ||
<DemoWrapper> | ||
<Demo /> | ||
</DemoWrapper> | ||
); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Made a fix to tooltip node as an fyi
190f44f