@studio206/create-sanity-field
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-rc.4 • Public • Published

Create Sanity Field

Magic sanity field creator.

Usage

Import field for quick usage.

Import field from @studio206/create-sanity-field. This is the barebones field function. Doesn't give you typesafety but does speed things up.

import { field } from "@studio206/create-sanity-field";

field("title");
// {
//   name: 'title',
//   title: 'Title',
//   type: 'string'
// }

If the type does not exist within src/typeDefaults.ts, you will have to pass it.

import { field } from "@studio206/create-sanity-field";

field("fubar"); // ❌
// Error: Undefined type for field name: fubar. Please add type or add to dictionary

field("fubar", "boolean"); // ✅
// {
//   name: 'fubar',
//   title: 'Fubar',
//   type: 'boolean'
// }

Configure createSanityField and add your own type definitions 🪄 ⭐️

This is where a solid attempt at typesafety comes into play.

Import createSanityField from @studio206/create-sanity-field.

// createSanityField.config.ts
import { createSanityField } from "@studio206/create-sanity-field";

export { field } = createSanityField({
  typeDefinitions: {
    authorName: "string",
  },
});

Import this field function from createSanityField.config.ts

import { field } from "path-to/createSanityField.config";

field("authorName");
// {
//   name: 'authorName',
//   title: 'Author Name',
//   type: 'string'
// }

You will also get an intellisense member list:

Screenshot 2023-01-25 at 22 23 10

Readme

Keywords

none

Package Sidebar

Install

npm i @studio206/create-sanity-field

Weekly Downloads

1

Version

1.0.0-rc.4

License

MIT

Unpacked Size

15.1 kB

Total Files

15

Last publish

Collaborators

  • samscott3000
  • pvalentim
  • karltaylor