Skip to content

Commit

Permalink
support config
Browse files Browse the repository at this point in the history
  • Loading branch information
rdunk committed Mar 16, 2021
1 parent a37075d commit e7f1c99
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions config.dist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"rowName": "tableRow"
}
11 changes: 8 additions & 3 deletions src/component.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { uuid } from '@sanity/uuid';
import React from 'react';
import PropTypes from 'prop-types';
import Table from './components/table';
import config from 'config:table'
import PatchEvent, { set, unset } from 'part:@sanity/form-builder/patch-event';
import FieldSet from 'part:@sanity/components/fieldsets/default';
import ButtonGrid from 'part:@sanity/components/buttons/button-grid';
import Button from 'part:@sanity/components/buttons/default';
import Table from './components/table';

import styles from './component.css';

Expand Down Expand Up @@ -36,7 +37,11 @@ export default class TableInput extends React.Component {
const { onChange } = this.props;
// Add a single row with a single empty cell (1 row, 1 column)
const newValue = {
rows: [{ _type: 'tableRow', _key: uuid(), cells: [''] }],
rows: [{
_type: config.rowName,
_key: uuid(),
cells: [''],
}],
};
return onChange(createPatchFrom(newValue));
};
Expand All @@ -51,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: 'tableRow',
_type: config.rowName,
_key: uuid(),
cells: Array(columnCount).fill(''),
});
Expand Down
4 changes: 3 additions & 1 deletion src/schema/row.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import config from 'config:table'

export default {
title: 'Table Row',
name: 'tableRow',
name: config.rowName,
type: 'object',
fields: [
{
Expand Down
3 changes: 2 additions & 1 deletion src/schema/table.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import config from 'config:table'
import TableInput from '../component';

export default {
Expand All @@ -10,7 +11,7 @@ export default {
type: 'array',
of: [
{
type: 'tableRow',
type: config.rowName,
},
],
},
Expand Down

0 comments on commit e7f1c99

Please sign in to comment.