1.0.0 • Published 5 months ago

rdf-data-table v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

RDF Data Table

A reusable data table component built with RDF Data Fetcher.

Installation

npm install rdf-data-table

Features

  • Built on top of RDF Data Fetcher for seamless data fetching
  • Support for both static and dynamic data
  • Customizable column rendering
  • Loading and error states
  • TypeScript support

Usage

Basic Usage with Static Data

import { DataTable } from 'rdf-data-table';

interface User {
  id: number;
  name: string;
  email: string;
}

const columns = [
  { key: 'id', header: 'ID' },
  { key: 'name', header: 'Name' },
  { key: 'email', header: 'Email' }
];

const data = [
  { id: 1, name: 'John Doe', email: 'john@example.com' },
  { id: 2, name: 'Jane Smith', email: 'jane@example.com' }
];

function MyComponent() {
  return (
    <DataTable
      data={data}
      columns={columns}
    />
  );
}

Usage with Data Fetching

import { DataTableWithFetch, registerDataTable } from 'rdf-data-table';
import { createAsyncLarge } from 'rdf-data-fetcher';

interface User {
  id: number;
  name: string;
  email: string;
}

const columns = [
  { key: 'id', header: 'ID' },
  { key: 'name', header: 'Name' },
  { key: 'email', header: 'Email' }
];

// Create a fetch function
const fetchUsers = async () => {
  const response = await fetch('https://api.example.com/users');
  return response.json();
};

// Create a configured fetch function
const asyncUsers = createAsyncLarge(fetchUsers, { config: 'server' });

// Register the fetch function
registerDataTable(asyncUsers, 'users');

function MyComponent() {
  return (
    <DataTableWithFetch
      columns={columns}
      fetchFunction={asyncUsers}
      componentName="users"
    />
  );
}

Custom Column Rendering

const columns = [
  { key: 'id', header: 'ID' },
  { 
    key: 'name', 
    header: 'Name',
    render: (value, row) => (
      <div className="user-name">
        <span className="first-name">{value}</span>
        <span className="last-name">{row.lastName}</span>
      </div>
    )
  },
  { key: 'email', header: 'Email' }
];

Props

DataTableProps

PropTypeDescription
dataT[]Array of data to display
columnsColumn[]Array of column definitions
loading?booleanLoading state
error?ErrorError state
className?stringAdditional CSS classes

DataTableWithFetchProps

PropTypeDescription
columnsColumn[]Array of column definitions
fetchFunctionFetchFunction<T[]>Function to fetch data
componentNamestringName of the component for registry
className?stringAdditional CSS classes

License

MIT

1.0.0

5 months ago