Skip to content

Commit 903aa18

Browse files
authored
Add schematicSvgOptions to Runframe for custom css style classes override (#3671)
1 parent 1827704 commit 903aa18

8 files changed

Lines changed: 265 additions & 283 deletions

File tree

bun.lock

Lines changed: 203 additions & 279 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { CircuitJsonPreview } from "lib/components/CircuitJsonPreview/CircuitJsonPreview"
2+
import { renderToCircuitJson } from "lib/dev/render-to-circuit-json"
3+
4+
export default () => (
5+
<CircuitJsonPreview
6+
circuitJson={renderToCircuitJson(
7+
<board width="10mm" height="10mm">
8+
<chip
9+
name="U1"
10+
pinLabels={{
11+
pin1: "D0",
12+
pin2: "D1",
13+
pin3: "D2",
14+
pin4: "GND",
15+
pin5: "D3",
16+
pin6: "EN",
17+
pin7: "D4",
18+
pin8: "VCC",
19+
}}
20+
footprint="soic8"
21+
schX={0}
22+
schY={-1.5}
23+
/>
24+
</board>,
25+
)}
26+
schematicSvgOptions={{
27+
css: `
28+
.custom-theme .sch-component-body {
29+
fill: #c7d2fe !important;
30+
stroke: #4338ca !important;
31+
}
32+
`,
33+
className: "custom-theme",
34+
}}
35+
/>
36+
)

lib/components/CircuitJsonPreview/CircuitJsonPreview.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ import {
66
} from "lib/components/ui/tabs"
77
import { cn } from "lib/utils"
88
import { CadViewer } from "@tscircuit/3d-viewer"
9-
import { useCallback, useEffect, useState, useMemo } from "react"
9+
import {
10+
useCallback,
11+
useEffect,
12+
useState,
13+
useMemo,
14+
type ComponentProps,
15+
} from "react"
1016
import { ErrorFallback } from "../ErrorFallback"
1117
import { ErrorBoundary, type FallbackProps } from "react-error-boundary"
1218
import { ErrorTabContent } from "../ErrorTabContent/ErrorTabContent"
@@ -122,6 +128,7 @@ export const CircuitJsonPreview = ({
122128
showFileMenu = false,
123129
isWebEmbedded = false,
124130
projectName,
131+
schematicSvgOptions,
125132
onRerunWithDebug,
126133
solverEvents,
127134
onPcbBoundsSelected,
@@ -685,6 +692,8 @@ export const CircuitJsonPreview = ({
685692
}}
686693
debugGrid={showSchematicDebugGrid}
687694
showSchematicPorts={showSchematicPorts}
695+
css={schematicSvgOptions?.css}
696+
className={schematicSvgOptions?.className}
688697
/>
689698
) : (
690699
<PreviewEmptyState onRunClicked={onRunClicked} />

lib/components/CircuitJsonPreview/PreviewContentProps.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ export interface PreviewContentProps {
3535
autoroutingGraphics?: any
3636
circuitJson: CircuitJson | null
3737
className?: string
38+
schematicSvgOptions?: {
39+
css?: string
40+
className?: string
41+
}
3842
showCodeTab?: boolean
3943
showRenderLogTab?: boolean
4044
codeTabContent?: React.ReactNode

lib/components/RunFrame/RunFrame.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,7 @@ export const RunFrame = (props: RunFrameProps) => {
628628
defaultActiveTab={props.defaultActiveTab ?? props.defaultTab}
629629
defaultTab={props.defaultTab}
630630
availableTabs={props.availableTabs}
631+
schematicSvgOptions={props.schematicSvgOptions}
631632
showToggleFullScreen={props.showToggleFullScreen}
632633
autoroutingGraphics={autoroutingGraphics}
633634
autoroutingLog={autoroutingLog}

lib/components/RunFrame/RunFrameProps.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ export interface RunFrameProps {
126126
*/
127127
availableTabs?: TabId[]
128128

129+
schematicSvgOptions?: {
130+
css?: string
131+
className?: string
132+
}
133+
129134
evalWebWorkerBlobUrl?: string
130135

131136
evalVersion?: string

lib/components/RunFrameWithApi/RunFrameWithApi.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useLocalStorageState } from "lib/hooks/use-local-storage-state"
77
import { useSyncPageTitle } from "lib/hooks/use-sync-page-title"
88
import { useCallback, useEffect, useMemo, useState } from "react"
99
import { RunFrame } from "../RunFrame/RunFrame"
10+
import type { RunFrameProps } from "../RunFrame/RunFrameProps"
1011
import { cn } from "lib/utils"
1112
import type { RunCompletedPayload } from "../RunFrame/run-completion"
1213
import { API_BASE } from "./api-base"
@@ -84,6 +85,7 @@ export interface RunFrameWithApiProps {
8485
workerBlobUrl?: string
8586
evalWebWorkerBlobUrl?: string
8687
showFileMenu?: boolean
88+
schematicSvgOptions?: RunFrameProps["schematicSvgOptions"]
8789

8890
/**
8991
* Enable fetch proxy for the web worker (useful for standalone bundles)
@@ -294,6 +296,7 @@ export const RunFrameWithApi = (props: RunFrameWithApiProps) => {
294296
<RunFrame
295297
fsMap={fsMap}
296298
showFileMenu={props.showFileMenu}
299+
schematicSvgOptions={props.schematicSvgOptions}
297300
isLoadingFiles={isLoadingFiles}
298301
evalVersion={props.evalVersion}
299302
forceLatestEvalVersion={props.forceLatestEvalVersion}

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"@react-hook/resize-observer": "^2.0.2",
4848
"@resvg/resvg-wasm": "^2.6.2",
4949
"@tscircuit/3d-viewer": "^0.0.565",
50-
"@tscircuit/assembly-viewer": "^0.0.5",
50+
"@tscircuit/assembly-viewer": "^0.0.6",
5151
"@tscircuit/create-snippet-url": "^0.0.9",
5252
"@tscircuit/fake-snippets": "^0.0.163",
5353
"@tscircuit/file-server": "^0.0.32",
@@ -67,7 +67,7 @@
6767
"circuit-json-to-kicad": "^0.0.150",
6868
"circuit-json-to-lbrn": "^0.0.74",
6969
"circuit-json-to-pnp-csv": "^0.0.7",
70-
"circuit-json-to-step": "^0.0.28",
70+
"circuit-json-to-step": "^0.0.34",
7171
"class-variance-authority": "^0.7.1",
7272
"clsx": "^2.1.1",
7373
"cmdk": "^1.1.1",
@@ -107,7 +107,7 @@
107107
"tailwind-merge": "^2.6.0",
108108
"tailwindcss": "^3.4.17",
109109
"tailwindcss-animate": "^1.0.7",
110-
"tscircuit": "^0.0.1774",
110+
"tscircuit": "^0.0.1869",
111111
"tsup": "^8.3.5",
112112
"vite": "^7.1.2",
113113
"yargs": "^17.7.2"

0 commit comments

Comments
 (0)