Cell Plugins

Cell plugins define how specific properties behave and render in the Notion database.

A CellPlugin is a generic interface that accepts four type parameters:

  • Key: The unique identifier for the plugin.
  • Data: The data type stored in the cell.
  • Config (optional): The configuration type for the plugin.
  • Actions (optional): The actions that can be performed on the cell.

API Reference

CellPlugin

PropTypeDescription
id*KeyUnique identifier of the plugin.
meta.name*stringThe name of the plugin. This will be displayed in the UI.
meta.desc*stringThe description of the plugin. This will be displayed in the UI.
meta.icon*React.ReactNodeThe icon of the plugin. This will be displayed in the UI.
default.name*stringDefault name used when a new column of this plugin is created.
default.icon*React.ReactNodeDefault icon used when a new column of this plugin is created.
default.config*ConfigDefault config used when a new column of this plugin is created.
default.widthnumberDefault width used when a new column of this plugin is created.
default.data*DataDefault data used when a new cell of this plugin is created.
fromValue*(value: ComparableValue, config: Config) => DataConverts value to the plugin's data type.
toValue*(data: Data, row: Row) => ComparableValueConverts the plugin's data type to a value. This is useful for sorting a column.
toGroupValue(data: Data, row: Row) => ComparableValueConverts the plugin's data type to a grouping value. This is useful for grouping by a column.
toTextValue*(data: Data, row: Row) => stringConverts the plugin's data type to a string value. This is useful for displaying/exporting the data in a compact format.
transferConfig(column: ColumnInfo<TPlugin>, data: Row<TPlugin[]>[]) => ConfigConverts the given column and rows data to this plugin configuration. This is useful for changing column types.
compare*(rowA: Row, rowB: Row, colId: string) => numberCompares two rows based on the plugin's data type. This is useful for sorting a column.
reducer*React.Reducer<TableDataAtom<TPlugins>, Actions>The reducer function to handle actions related to this plugin. This is useful for updating the table state.
renderCell*(props: CellProps<Data, Config>) => React.ReactNodeRenders the cell for this plugin. This is where you define how the cell should look and behave in the UI.
renderConfigMenu(props: ConfigMenuProps<Config>) => React.ReactNodeRenders the configuration menu for this plugin. This is where you define how the column configuration should look.
renderGroupingValue(props: GroupingValueProps) => React.ReactNodeRenders the grouping value for this plugin. This is where you define how the grouping value should look.

CellProps

PropTypeDescription
propId*stringThe ID of the column this cell belongs to. This is useful for identifying the column in the table.
row*RowThe row this cell belongs to. This is useful for identifying the row in the table.
data*DataThe data of the cell. This is the value stored in the cell.
config*ConfigThe configuration of the cell. This can be used to customize the cell's behavior.
wrappedbooleanWhether the cell should be wrapped. This is useful for long text values that need to be displayed in multiple lines.
onChange*OnChangeFn<Data>A callback function that is called when the cell data changes.
onConfigChangeOnChangeFn<Config>A callback function that is called when the column configuration changes.

ConfigMenuProps

PropTypeDescription
propId*stringThe ID of the column this configuration menu belongs to. This is useful for identifying the column in the table.
config*ConfigThe configuration of the column. This can be used to customize the column's behavior.
onChange*OnChangeFn<Config>A callback function that is called when the column configuration changes.

GroupingValueProps

PropTypeDescription
value*ComparableValueThe grouping value.
table*Table<Row>The table instance.

TableDataAtom

A TableDataAtom represents the atom state of a table, including its column informations and row data.

PropTypeDefaultDescription
properties*Record<string, ColumnInfo>-The column informations of the table.
data*Row[]-The rows of the table.

Type Inference Utilities

TypeDescription
InferKey<TPlugin>Infers the plugin ID from CellPlugin.
InferData<TPlugin>Infers the cell data type.
InferConfig<TPlugin>Infers the column config type.
InferActions<TPlugin>Infers the plugin action type.
InferPlugin<TPlugins>Merges plugin types into a unified CellPlugin.

What's Next?

You can define plugins, columns, and rows in a flexible and strongly-typed way using these abstractions.