0.0.3 • Published 12 months ago

upn-doctor-package v0.0.3

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

Table Component Library - upn-table

Table component renders tabular data with various optional features such as pagination, filtering, sorting, and customizable actions.

Props

PropTypeDescription
dataArray<Object>Array of data objects to display in the table.
columnsArray<Object>Array of column configurations defining headers and other settings.
showShowEntriesbooleanFlag to display the entries per page selector.
showEntriesOptionsArray<number>Options for entries per page selector.
showPaginationbooleanFlag to show the pagination component.
tableCaptionstringOptional caption for the table.
showViewallbooleanFlag to display the "View All" button.
showActionsbooleanFlag to show an actions column in the table.
actionsHeaderstringHeader text for the actions column.
actionButtonsArray<Object>Configuration for action buttons.
showFiltersbooleanFlag to show the filter button and popup.
filterOptionsObjectConfiguration for filter options.
exportButtonObjectConfiguration for an export button.
showCheckboxbooleanFlag to show checkboxes for row selection.
searchOptionsObjectConfiguration for search options.
gappedbooleanFlag to add spacing between table cells.
classNamesObjectOptional object containing CSS class names for customization.

Example Usage

import React, { useState } from 'react';
import Table from './components/Table/Table';
import { ButtonConfig, Column, DataObject } from './types/TableTypes';
import { ChevronDown } from 'upn-icons';

const App: React.FC = () => {
  const columns: Column[] = [
    { key: 'id', header: 'ID', sortable: true },
    { key: 'profile', header: 'Profile', sortable: false, image: true },
    { key: 'name', header: 'Name', sortable: true },
    { key: 'details', header: 'Details', sortable: false },
    { key: 'svg', header: 'SVG' }
  ];

  const data: DataObject[] = [
    {
      id: 1,
      profile: { image: '../../assets/User.svg', name: 'John Doe' },
      name: 'John Doe',
      details: { age: 30, country: 'USA' },
      svg: <ChevronDown className="arrowDown-svg" />
    },
    {
      id: 2,
      profile: { image: '../../assets/User.svg', name: 'Jane Smith' },
      name: 'Jane Smith',
      details: { age: 25, country: 'Canada' }
    },
    {
      id: 3,
      profile: { image: '../../assets/User.svg', name: 'Michael Johnson' },
      name: 'Michael Johnson',
      details: { age: 40, country: 'UK' }
    },
    {
      id: 4,
      profile: { image: '../../assets/User.svg', name: 'Emily Brown' },
      name: 'Emily Brown',
      details: { age: 35, country: 'Australia' }
    },
    {
      id: 5,
      profile: { image: '../../assets/User.svg', name: 'Christopher Lee' },
      name: 'Christopher Lee',
      details: { age: 28, country: 'Germany' }
    },
    {
      id: 6,
      profile: { image: '../../assets/User.svg', name: 'Jessica Taylor' },
      name: 'Jessica Taylor',
      details: { age: 32, country: 'France' }
    },
    {
      id: 7,
      profile: { image: '../../assets/User.svg', name: 'Daniel Wilson' },
      name: 'Daniel Wilson',
      details: { age: 45, country: 'Japan' }
    },
    {
      id: 8,
      profile: { image: '../../assets/User.svg', name: 'Sarah Anderson' },
      name: 'Sarah Anderson',
      details: { age: 37, country: 'China' }
    },
    {
      id: 9,
      profile: { image: '../../assets/User.svg', name: 'John Doe' },
      name: 'Matthew Martinez',
      details: { age: 29, country: 'Brazil' }
    },
    {
      id: 10,
      profile: { image: '../../assets/User.svg', name: 'John Doe' },
      name: 'Ashley Thomas',
      details: { age: 31, country: 'India' }
    },
    {
      id: 11,
      profile: { image: '../../assets/User.svg', name: 'John Doe' },
      name: 'Ram Bahadur',
      details: { age: 31, country: 'Nepal' }
    },
    {
      id: 12,
      profile: { image: '../../assets/User.svg', name: 'John Doe' },
      name: 'Ashley Thomas',
      details: { age: 31, country: 'India' }
    },
    {
      id: 13,
      profile: { image: '../../assets/User.svg', name: 'John Doe' },
      name: 'Ashley Thomas',
      details: { age: 31, country: 'India' }
    },
    {
      id: 14,
      profile: { image: '../../assets/User.svg', name: 'John Doe' },
      name: 'Ashley Thomas',
      details: { age: 31, country: 'India' }
    },
    {
      id: 15,
      profile: { image: '../../assets/User.svg', name: 'John Doe' },
      name: 'Shyam Magar',
      details: { age: 31, country: 'Nepal' }
    }
  ];

  const handleEditClick = () => {
    // Handle edit button click
    console.log('edit button clicked');
  };

  const handleDeleteClick = () => {
    // Handle delete button click
    console.log('delete button clicked');
  };

  // Define button configurations
  const actionButtons: ButtonConfig[] = [
    { label: 'Edit', className: 'edit-btn', onClick: () => handleEditClick() },
    { label: 'Delete', className: 'delete-btn', onClick: () => handleDeleteClick() }
  ];

  const [selectedOption, setSelectedOption] = useState<string | null>('');
  const [invoiceId, setInvoiceId] = useState<string>('');
  const [patient, setPatient] = useState<string>('');
  const [category, setCategory] = useState<string | null>('All Category');
  const [date, setDate] = useState(new Date());

  return (
    <div className="App">
      <h1>Nested Table Example</h1>
      <Table
        data={data}
        columns={columns}
        showShowEntries
        showEntriesOptions={[1, 2, 5, 10, 15]}
        showPagination
        showViewall
        tableCaption="Users"
        showActions
        actionsHeader="Actions"
        actionButtons={actionButtons}
        showFilters
        filterOptions={[
          {
            label: 'Patient',
            type: 'text',
            props: {
              value: patient,
              onChange: (e: React.ChangeEvent<HTMLInputElement>) => {
                setPatient(e.target.value);
              },
              placeholder: 'Patient Name, Patient ID, P...'
            }
          },
          {
            label: 'Category',
            type: 'dropdown',
            options: ['Dropdown 1 ', 'Dropdown 2 ', 'Dropdown 3'],
            value: category,
            onSelect: () => {
              setCategory(category);
            }
          },
          {
            label: 'Date of Joining',
            type: 'date',
            selectedDate: date,
            setSelectedDate: (date: Date) => {
              setDate(date);
            }
          }
        ]}
        saveAsDraftButton={{
          label: 'Save as Draft',
          onClick: () => {
            console.log('saved as draft');
          }
        }}
        showCheckbox
        searchOptions={{
          startDate: true,
          endDate: true,
          columnSearches: [
            {
              label: 'Supplier Name',
              type: 'dropdown',
              options: ['Dropdown 1 ', 'Dropdown 2 ', 'Dropdown 3'],
              value: selectedOption,
              onSelect: (selectedOpt: string) => {
                setSelectedOption(selectedOpt);
              }
            },
            {
              label: 'Invoice ID',
              type: 'text',
              props: {
                value: invoiceId,
                onChange: (e: React.ChangeEvent<HTMLInputElement>) => {
                  setInvoiceId(e.target.value);
                }
              }
            }
          ]
        }}
        exportButton={{
          label: 'Export',
          onClick: () => {
            console.log('Exported');
          }
        }}
        // gapped
      />
    </div>
  );
};

export default App;