Skip to content

Commit e7f1c99

Browse files
committed
support config
1 parent a37075d commit e7f1c99

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

config.dist.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"rowName": "tableRow"
3+
}

src/component.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { uuid } from '@sanity/uuid';
22
import React from 'react';
33
import PropTypes from 'prop-types';
4-
import Table from './components/table';
4+
import config from 'config:table'
55
import PatchEvent, { set, unset } from 'part:@sanity/form-builder/patch-event';
66
import FieldSet from 'part:@sanity/components/fieldsets/default';
77
import ButtonGrid from 'part:@sanity/components/buttons/button-grid';
88
import Button from 'part:@sanity/components/buttons/default';
9+
import Table from './components/table';
910

1011
import styles from './component.css';
1112

@@ -36,7 +37,11 @@ export default class TableInput extends React.Component {
3637
const { onChange } = this.props;
3738
// Add a single row with a single empty cell (1 row, 1 column)
3839
const newValue = {
39-
rows: [{ _type: 'tableRow', _key: uuid(), cells: [''] }],
40+
rows: [{
41+
_type: config.rowName,
42+
_key: uuid(),
43+
cells: [''],
44+
}],
4045
};
4146
return onChange(createPatchFrom(newValue));
4247
};
@@ -51,7 +56,7 @@ export default class TableInput extends React.Component {
5156
const columnCount = value.rows[0].cells.length;
5257
// Add as many cells as we have columns
5358
newValue.rows.push({
54-
_type: 'tableRow',
59+
_type: config.rowName,
5560
_key: uuid(),
5661
cells: Array(columnCount).fill(''),
5762
});

src/schema/row.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import config from 'config:table'
2+
13
export default {
24
title: 'Table Row',
3-
name: 'tableRow',
5+
name: config.rowName,
46
type: 'object',
57
fields: [
68
{

src/schema/table.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import config from 'config:table'
12
import TableInput from '../component';
23

34
export default {
@@ -10,7 +11,7 @@ export default {
1011
type: 'array',
1112
of: [
1213
{
13-
type: 'tableRow',
14+
type: config.rowName,
1415
},
1516
],
1617
},

0 commit comments

Comments
 (0)