4.3.3 • Published 3 months ago
notion-like-table v4.3.3
React + TypeScript + Vite
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
Currently, two official plugins are available:
- @vitejs/plugin-react uses Babel for Fast Refresh
- @vitejs/plugin-react-swc uses SWC for Fast Refresh
Expanding the ESLint configuration
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
export default tseslint.config({
extends: [
// Remove ...tseslint.configs.recommended and replace with this
...tseslint.configs.recommendedTypeChecked,
// Alternatively, use this for stricter rules
...tseslint.configs.strictTypeChecked,
// Optionally, add this for stylistic rules
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
// other options...
parserOptions: {
project: ['./tsconfig.node.json', './tsconfig.app.json'],
tsconfigRootDir: import.meta.dirname,
},
},
})
You can also install eslint-plugin-react-x and eslint-plugin-react-dom for React-specific lint rules:
// eslint.config.js
import reactX from 'eslint-plugin-react-x'
import reactDom from 'eslint-plugin-react-dom'
export default tseslint.config({
plugins: {
// Add the react-x and react-dom plugins
'react-x': reactX,
'react-dom': reactDom,
},
rules: {
// other rules...
// Enable its recommended typescript rules
...reactX.configs['recommended-typescript'].rules,
...reactDom.configs.recommended.rules,
},
})
Notion Table
A React component library for creating Notion-like tables with features such as:
- Cell selection and editing
- Column resizing
- Column type changing
- Column insertion and deletion
- Data management
Installation
npm install notion-table
# or
yarn add notion-table
Usage
import { useState } from 'react';
import { DataTable, ColumnType, TableDataItem } from 'notion-table';
function MyComponent() {
// Your data
const [data, setData] = useState([
{ col1: "Hello", col2: "World", col3: "!", col4: "$", empty: "" },
{ col1: "React", col2: "Table", col3: "!!", col4: "$$", empty: "" },
{ col1: "Cell", col2: "Select", col3: "!!!", col4: "$$$", empty: "" }
]);
// Your columns
const [columns, setColumns] = useState([
{ Header: "Column 1", accessor: "col1", width: 150, type: "text" },
{ Header: "Column 2", accessor: "col2", width: 150, type: "text" },
{ Header: "Column 3", accessor: "col3", width: 150, type: "text" },
{ Header: "Column 4", accessor: "col4", width: 150, type: "text" },
{ Header: "+", accessor: "empty", width: 50, type: "text" }
]);
// Handlers for data and column changes
const handleDataChange = (newData) => {
setData(newData);
};
const handleColumnsChange = (newColumns) => {
setColumns(newColumns);
};
return (
<DataTable
initialData={data}
initialColumns={columns}
onDataChange={handleDataChange}
onColumnsChange={handleColumnsChange}
/>
);
}
Props
DataTable Props
Prop | Type | Description |
---|---|---|
initialData | TableDataItem[] | Initial data for the table |
initialColumns | ColumnType[] | Initial columns configuration |
onDataChange | (data: TableDataItem[]) => void | Callback when data changes |
onColumnsChange | (columns: ColumnType[]) => void | Callback when columns change |
Types
interface ColumnType {
Header: string;
accessor: string;
width: number;
type: string;
id?: string;
}
interface TableDataItem {
[key: string]: string | number | boolean;
}
Development
To run the development server:
npm run dev
# or
yarn dev
To build the package:
npm run build:lib
# or
yarn build:lib
License
MIT