sanity-plugin-power-table
v0.0.14
Published
Create tables cell by cell, with a custom schema for rows and cells
Downloads
686
Readme
sanity-plugin-power-table
Create powerful tables in sanity:
- Custom row and cell schema
- Cell-level management, each cell can have its own rowSpan and colSpan
based on sanity-plugin-byo-table
Installation
sanity install power-table
Usage
First import the schema generating function:
import tableSchema from 'part:power-table/schema'
Next create and export schema for your table.
Row Schema is optional. It should be an object if provided.
Cell schema can be a string or object.
Minimal example:
export const myTableSchemas = tableSchema({ name: 'myTable', title: 'My table', cellSchema: { type: 'string', }, })
Bigger example:
export const myTableSchemas = tableSchema({ name: 'myTable', title: 'My table', rowSchema: { type: 'object', fields: [ { name: 'heading', title: 'Heading', type: 'boolean', }, ], }, cellSchema: { type: 'object', fields: [ { name: 'contents', title: 'Contents', type: 'array', of: [{ type: 'block' }] }, ], }, })
Use the table by the name you provided
export default { name: 'mySchema', title: 'My Schema', type: 'document', fields: [ { name: 'headline', title: 'Headline', type: 'array', of: [{ type: 'block' }], }, { name: 'table', title: 'My Table', type: 'myTable' } ], }
Import the table schemas in your schema.js:
import createSchema from 'part:@sanity/base/schema-creator' import mySchema, {myTableSchemas} from './mySchema' export default createSchema({ name: 'default', types: [ mySchema, ...myTableSchemas ], });
License
MIT © Christopher Fraser See LICENSE