diff --git a/README.md b/README.md index 7ee4f35..2cbe962 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,30 @@ -# sanity-plugin-table - -[Sanity](https://www.sanity.io/) plugin that implements a `table` schema type and input component. +
+

Sanity Plugin Table

+

+ NPM version + NPM downloads + GitHub Release Date + License +

+

+

+

Sanity plugin that implements a table schema type and input component.

+
+
+
+ +> **Notice**: Version 2.x of this plugin includes a breaking change, see the [Configuration](#configuration) section to migrate existing data. + +
![example](https://user-images.githubusercontent.com/8467307/48703530-e369be00-ebeb-11e8-8299-14812461aee8.gif) -## Installing +## Install Install using the [Sanity CLI](https://www.sanity.io/docs/cli). -``` -sanity install table +```bash +$ sanity install table ``` ## Usage @@ -25,14 +40,23 @@ export default { { name: 'sizeChart', title: 'Size Chart', - type: 'table', // Specify table type - } + type: 'table', // Specify 'table' type + }, ], }; ``` -## Similar Packages -* [sanity-datatable](https://github.com/fredjens/sanity-datatable/) by [fredjens](https://github.com/fredjens/) +## Configuration + +You can create a configuration file to provide the `_type` used for table row data. This is especially useful if you are upgrading or have existing data, as version `2.x` of this plugin uses `tableRow` by default, replacing `row` used in version `1.x`. + +In your studio, create a `config/table.json` file (relative to the root directory). The `rowType` string value can be whatever you like. Use `row` if you are migrating existing data from version 1 to 2. + +```json +{ + "rowType": "row" +} +``` ## License diff --git a/config.dist.json b/config.dist.json index bcd48d3..365b503 100644 --- a/config.dist.json +++ b/config.dist.json @@ -1,3 +1,3 @@ { - "rowName": "tableRow" + "rowType": "tableRow" } \ No newline at end of file diff --git a/src/component.js b/src/component.js index 25d565d..876a555 100644 --- a/src/component.js +++ b/src/component.js @@ -38,7 +38,7 @@ export default class TableInput extends React.Component { // Add a single row with a single empty cell (1 row, 1 column) const newValue = { rows: [{ - _type: config.rowName, + _type: config.rowType, _key: uuid(), cells: [''], }], @@ -56,7 +56,7 @@ export default class TableInput extends React.Component { const columnCount = value.rows[0].cells.length; // Add as many cells as we have columns newValue.rows.push({ - _type: config.rowName, + _type: config.rowType, _key: uuid(), cells: Array(columnCount).fill(''), }); diff --git a/src/schema/row.js b/src/schema/row.js index 115038a..6a65dfa 100644 --- a/src/schema/row.js +++ b/src/schema/row.js @@ -2,7 +2,7 @@ import config from 'config:table' export default { title: 'Table Row', - name: config.rowName, + name: config.rowType, type: 'object', fields: [ { diff --git a/src/schema/table.js b/src/schema/table.js index 10d202e..9d0d7e9 100644 --- a/src/schema/table.js +++ b/src/schema/table.js @@ -11,7 +11,7 @@ export default { type: 'array', of: [ { - type: config.rowName, + type: config.rowType, }, ], },