-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from tscircuit/use-led
Add useLed hook
- Loading branch information
Showing
3 changed files
with
39 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ledPins, type LedProps } from "@tscircuit/props" | ||
import { createUseComponent } from "./create-use-component" | ||
|
||
export const useLed = createUseComponent( | ||
(props: LedProps) => <led {...props} />, | ||
ledPins, | ||
) |
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
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,31 @@ | ||
import { test, expect } from "bun:test" | ||
import { useLed } from "lib/hooks/use-led" | ||
import { Circuit } from "lib/Circuit" | ||
|
||
test("useLed hook creates component with correct props and traces", () => { | ||
const circuit = new Circuit() | ||
|
||
const LED1 = useLed("LED1", { footprint: "1206" }) | ||
const LED2 = useLed("LED2", { footprint: "0603" }) | ||
|
||
circuit.add( | ||
<board width="10mm" height="10mm"> | ||
<LED1 anode="net.VCC" cathode="net.GND" /> | ||
<LED2 pos={LED1.anode} neg="net.GND" /> | ||
</board>, | ||
) | ||
|
||
circuit.render() | ||
|
||
// Check if LED components were created correctly | ||
const leds = circuit.selectAll("led") | ||
expect(leds.length).toBe(2) | ||
expect(leds[0].props.name).toBe("LED1") | ||
expect(leds[0].props.footprint).toBe("1206") | ||
expect(leds[1].props.name).toBe("LED2") | ||
expect(leds[1].props.footprint).toBe("0603") | ||
|
||
// Check if traces were created correctly | ||
const traces = circuit.selectAll("trace") | ||
expect(traces.length).toBe(4) | ||
}) |