Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generated/COMPONENT_TYPES.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export const cadModelJscad = cadModelBase.extend({
})
export const cadModelProp = z.union([
z.null(),
url,
z.string().min(1),
z.custom<ReactElement>((v) => {
return v && typeof v === "object" && "type" in v && "props" in v
}),
Expand Down
12 changes: 10 additions & 2 deletions lib/common/cadModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,18 @@ export const cadModelJscad = cadModelBase.extend({
jscad: z.record(z.any()),
})

/**
* A Footprinter string used to procedurally generate the component's CAD model,
* independently of the component's PCB footprint.
*
* @example "soic8"
*/
export type CadModelFootprinterString = string

export type CadModelProp =
| null
| string
| ReactElement
| CadModelFootprinterString
| CadModelStl
| CadModelObj
| CadModelGltf
Expand All @@ -127,7 +135,7 @@ export type CadModelProp =

export const cadModelProp = z.union([
z.null(),
url,
z.string().min(1),
z.custom<ReactElement>((v) => {
return v && typeof v === "object" && "type" in v && "props" in v
}),
Expand Down
15 changes: 15 additions & 0 deletions tests/cad-model-prop.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { expect, test } from "bun:test"
import { cadModelProp } from "../lib/common/cadModel"
import { chipProps } from "../lib/components/chip"

test("cadModel accepts a Footprinter string as the procedural model", () => {
expect(cadModelProp.parse("soic8")).toBe("soic8")
expect(() => cadModelProp.parse("")).toThrow()

const parsedChip = chipProps.parse({
name: "U1",
cadModel: "soic8",
})

expect(parsedChip.cadModel).toBe("soic8")
})
Loading