@treasured/zod-to-leva-schema
v0.0.8
Published
Converts a typed schema written in [Zod](https://github.com/colinhacks/zod) into a schema that can be used by [Leva](https://github.com/pmndrs/leva).
Downloads
3
Readme
zod-to-leva-schema
Converts a typed schema written in Zod into a schema that can be used by Leva.
We use this library in the Treasured player to easily modify portions of the level schema for debugging purposes.
Usage
Imagine we have the following schema written in Zod:
import { z } from "zod";
const FeaturesSchema = z.object({
matterportStyleNavigation: z.boolean().default(true),
guidedTour: z.boolean().default(false),
});
We can convert this into the equivalent schema in Leva:
import zodToLevaSchema from "@treasured/zod-to-leva-schema";
import { useControls } from "leva";
const levaSchema = zodToLevaSchema(FeaturesSchema);
and levaSchema will be:
{
matterportStyleNavigation: {
type: "boolean",
value: false,
},
guidedTour: {
type: "boolean",
value: false,
},
}