-
Notifications
You must be signed in to change notification settings - Fork 37
Add double click handler for schematic components #133
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
Open
nailoo
wants to merge
20
commits into
tscircuit:main
Choose a base branch
from
nailoo:dbl2
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 3 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b1a8c21
Add double click handler for schematic components
nailoo abc0fbd
Create example14
nailoo 20e4a18
Update example14
nailoo 4bc32d9
update
nailoo 596bfcb
Create useSchematicComponentDoubleClick.ts
nailoo 3baafa3
Update
nailoo fe9f000
remove always hover
nailoo 6ee6ab2
Update
nailoo 7a29020
patch
nailoo 48a1f1c
Update
nailoo a112cd0
Update
nailoo ff184ee
Update done
nailoo 253fe73
d
nailoo 19e353d
Improve hover bounding boxes for clickable components
nailoo a2deb30
Update
nailoo d71905d
hover highlight overlay
nailoo f1c751e
up
nailoo 7e09aa8
add boundary
nailoo 4207d33
dd
nailoo 224cf53
Fu*k
nailoo 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 hidden or 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,89 @@ | ||
| import { useCallback, useState } from "react" | ||
| import { ControlledSchematicViewer } from "lib/components/ControlledSchematicViewer" | ||
| import { renderToCircuitJson } from "lib/dev/render-to-circuit-json" | ||
|
|
||
| export default function Example14DoubleClickEdit() { | ||
| const [lastDoubleClickedComponent, setLastDoubleClickedComponent] = useState< | ||
| string | null | ||
| >(null) | ||
|
|
||
| const handleDoubleClick = useCallback( | ||
| ({ schematicComponentId }: { schematicComponentId: string }) => { | ||
| setLastDoubleClickedComponent(schematicComponentId) | ||
|
|
||
| if (typeof window !== "undefined") { | ||
| window.alert(`Open edit dialog for ${schematicComponentId}`) | ||
| } | ||
| }, | ||
| [], | ||
| ) | ||
|
|
||
| return ( | ||
| <div | ||
| style={{ | ||
| display: "flex", | ||
| flexDirection: "column", | ||
| gap: "1rem", | ||
| padding: "1rem", | ||
| height: "100%", | ||
| boxSizing: "border-box", | ||
| }} | ||
| > | ||
| <div style={{ flex: 1, minHeight: 400 }}> | ||
| <ControlledSchematicViewer | ||
| circuitJson={renderToCircuitJson( | ||
| <board width="12mm" height="12mm"> | ||
| <resistor | ||
| name="R1" | ||
| resistance={220} | ||
| schX={-4} | ||
| schY={1} | ||
| /> | ||
| <capacitor | ||
| name="C1" | ||
| capacitance="10uF" | ||
| schX={4} | ||
| schY={-1} | ||
| /> | ||
| <chip | ||
| name="U1" | ||
| footprint="soic8" | ||
| pinLabels={{ | ||
| pin1: "OUT", | ||
| pin2: "GND", | ||
| pin3: "IN-", | ||
| pin4: "IN+", | ||
| pin5: "VREF", | ||
| pin6: "NC", | ||
| pin7: "NC", | ||
| pin8: "VCC", | ||
| }} | ||
| schX={0} | ||
| schY={0} | ||
| /> | ||
| <trace from=".R1 .pin2" to=".U1 .pin4" /> | ||
| <trace from=".C1 .pin1" to=".U1 .pin3" /> | ||
| <trace from=".R1 .pin1" to=".C1 .pin2" /> | ||
| </board>, | ||
| )} | ||
| containerStyle={{ height: "100%" }} | ||
| onClickComponent={handleDoubleClick} | ||
| /> | ||
| </div> | ||
|
|
||
| <div> | ||
| <p> | ||
| Double-click any component to simulate opening its editing dialog. The | ||
| cursor becomes a pointer to indicate interactivity. | ||
| </p> | ||
| {lastDoubleClickedComponent ? ( | ||
| <p> | ||
| Last double-clicked component: <strong>{lastDoubleClickedComponent}</strong> | ||
| </p> | ||
| ) : ( | ||
| <p>Double-click a component to see its identifier here.</p> | ||
| )} | ||
| </div> | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
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.
too much code in this file (keep things clean, move functionality to separate files appropriately)