0.3.73 • Published 4 months ago

react-native-paper-extended v0.3.73

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

Documentation

This library is an extended version of React Native Paper, offering additional components to enhance your development experience. One of the key additions is the DataTableAdvance component, designed for advanced table handling. Below is an overview of its features and functionality.

Features

  • Advanced data table with sortable columns.
  • (DataList) Mobile View for Data Table.
  • Infinite Scrolling for the Mobile View with Custom function.
  • Custom filtering components for specific columns.
  • Custom rendering of cell content.
  • Pagination with adjustable items per page.
  • Integration with react-native-paper-extended for UI components.

Props Overview

(for Advanced Data Table)

Prop NameTypeMandatoryDescription
headersHeadersProp[]YesArray of objects defining column headers. Each object contains keys like key, title, etc.
dataanyYesArray of data objects, where keys should match the key values in headers.
Note: Also "id" key is mandatory for bulk actions
numberOfItemsPerPageListnumber[]YesArray of numbers specifying the items per page options.
enableBulkActionbooleanYesEnables or disables the bulk action functionality.
onBulkSelect(selected: any[]) => voidNoCallback function triggered when items are selected in bulk.
styleStyleProp<ViewStyle>NoCustom styles for the component's container.
renderCellContent(cell: any, headerKey: string) => React.ReactElementNoFunction to render custom cell content.
showActionColumnbooleanNoToggles visibility of the action column.
renderActionColumn(cell: any, index?: string) => React.ReactElementNoFunction to render custom content for the action column.
renderFilterComponent(header: any, close: () => void) => React.ReactElementNoFunction to render custom filter components for a column.

|

Code

import React, { useState } from "react";
import {
  DataTableAdvance,
  Checkbox,
  RadioButton,
} from "react-native-paper-extended";
import { View, Text, TouchableOpacity } from "react-native";
import moment from "moment";

const DataTableAdvanceExample = () => {
  const StatusFilter = ({ close }) => {
    const [status, setStatus] = useState("");

    const handlePress = (value) => setStatus(value);

    return (
      <View>
        {["Incoming", "Outgoing", "Missed", "Bridge Call", "Voicemail"].map(
          (label) => (
            <Checkbox.Item
              key={label}
              label={label}
              status={status === label ? "checked" : "unchecked"}
              onPress={() => handlePress(label)}
            />
          )
        )}
        <View style={{ flexDirection: "row", marginTop: 12 }}>
          <TouchableOpacity
            onPress={close}
            style={{
              flex: 1,
              backgroundColor: "#734BD1",
              borderRadius: 20,
              padding: 8,
            }}
          >
            <Text style={{ color: "white", textAlign: "center" }}>Apply</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  };

  const ContactFilter = ({ close }) => {
    const [contactType, setContactType] = useState([]);
    const [favorite, setFavorite] = useState("");
    const [status, setStatus] = useState("");

    return (
      <View>
        <Text>Contact Type</Text>
        {["HCP", "Staff", "Unknown"].map((type) => (
          <Checkbox.Item
            key={type}
            label={type}
            status={contactType.includes(type) ? "checked" : "unchecked"}
            onPress={() =>
              setContactType((prev) =>
                prev.includes(type)
                  ? prev.filter((t) => t !== type)
                  : [...prev, type]
              )
            }
          />
        ))}
        <Text>Favorite</Text>
        <RadioButton.Group onValueChange={setFavorite} value={favorite}>
          {["Yes", "No"].map((value) => (
            <RadioButton.Item key={value} label={value} value={value} />
          ))}
        </RadioButton.Group>
        <Text>Status</Text>
        <RadioButton.Group onValueChange={setStatus} value={status}>
          {["Opted In", "Opted Out"].map((value) => (
            <RadioButton.Item key={value} label={value} value={value} />
          ))}
        </RadioButton.Group>
        <View style={{ flexDirection: "row", marginTop: 12 }}>
          <TouchableOpacity
            onPress={close}
            style={{
              flex: 1,
              backgroundColor: "#734BD1",
              borderRadius: 20,
              padding: 8,
            }}
          >
            <Text style={{ color: "white", textAlign: "center" }}>Apply</Text>
          </TouchableOpacity>
        </View>
      </View>
    );
  };

  return (
    <DataTableAdvance
      data={[
        {
          id: 1,
          name: "Sheena David",
          status: "incoming",
          datetime: "2024-12-04T12:14:22.813Z",
          callDuration: "20 mins",
        },
        {
          id: 2,
          name: "Satyaki",
          status: "outcoming",
          datetime: "2024-12-05T12:14:22.813Z",
          callDuration: "20 mins",
        },
      ]}
      numberOfItemsPerPageList={[5, 10, 20]}
      headers={[
        { key: "name", title: "Contact Name", sort: true, filter: true },
        { key: "status", title: "Type", sort: true, filter: true },
        { key: "datetime", title: "Date & Time", sort: true },
        { key: "callDuration", title: "Duration", sort: true },
      ]}
      onBulkSelect={(selected) => console.log(selected)}
      renderCellContent={(cell, headerKey) =>
        headerKey === "toName" ? (
          <Text numberOfLines={1}>{cell[headerKey]}</Text>
        ) : (
          cell[headerKey]
        )
      }
    />
  );
};

export default DataTableAdvanceExample;

# DataListProps Type Documentation

The `DataListProps` is a TypeScript type used to define the properties of a customizable data list component in React Native. This type includes several optional and required fields to handle data rendering, styling, and interactivity.

## Properties

| Property                       | Type                                            | Required | Description |
|--------------------------------|-------------------------------------------------|----------|-------------|
| **`data`**                    | `any[]`                                         | Yes      | The array of data items to display in the list. |
| **`selected`**                | `any[]`                                         | Yes      | An array of currently selected items. |
| **`setSelected`**             | `(item: any) => void`                           | Yes      | A callback function to update the selected items. |
| **`expandedItems`**           | `any`                                           | Yes      | Tracks the currently expanded items in the list. |
| **`setExpandedItems`**        | `(item: any) => void`                           | Yes      | A callback function to update the expanded items. |
| **`expandAll`**               | `() => void`                                    | Yes      | Function to expand all items in the list. |
| **`collapseAll`**             | `() => void`                                    | Yes      | Function to collapse all items in the list. |
| **`containerStyle`**          | `TextStyle`                                     | No       | Style for the container of the list. |
| **`titleStyles`**             | `TextStyle`                                     | No       | Style for the title text. |
| **`subtitleStyles`**          | `TextStyle`                                     | No       | Style for subtitle text. |
| **`buttonStyles`**            | `TextStyle`                                     | No       | Style for the button displayed in the list. |
| **`anchorMenuPosition`**      | `{ x: number; y: number }`                      | No       | The position of the anchor menu. |
| **`showButton`**              | `boolean`                                       | No       | Determines if a button should be displayed. |
| **`buttonText`**              | `string`                                        | No       | Text to display on the button. |
| **`dropdownProps`**           | `{ enabled?: boolean; showMenu?: boolean; menuType?: string; menuSubType?: string }` | No       | Configuration for dropdown behavior. |
| **`showTextInsteadOfDropdown`** | `boolean`                                      | No       | If true, displays a text field instead of a dropdown. |
| **`textInsteadOfDropdown`**   | `string`                                        | No       | The text to display when using text instead of a dropdown. |
| **`textInsteadOfDropdownStyles`** | `TextStyle`                                   | No       | Style for the text displayed instead of the dropdown. |
| **`showMediaIcon`**           | `boolean`                                       | No       | Determines if a media icon should be displayed. |
| **`mediaIconName`**           | `string`                                        | No       | Name of the media icon. |
| **`mediaIconSize`**           | `number`                                        | No       | Size of the media icon. |
| **`mediaIconColor`**          | `string`                                        | No       | Color of the media icon. |
| **`showAvatar`**              | `boolean`                                       | No       | Determines if an avatar should be displayed. |
| **`showStatusIcon`**          | `boolean`                                       | No       | Determines if a status icon should be displayed. |
| **`showSubtitle1`**           | `boolean`                                       | No       | Determines if subtitle 1 should be displayed. |
| **`showSubtitle2`**           | `boolean`                                       | No       | Determines if subtitle 2 should be displayed. |
| **`showSubtitle3`**           | `boolean`                                       | No       | Determines if subtitle 3 should be displayed. |
| **`onEndReached`**            | `() => void`                                    | No       | Callback triggered when the end of the list is reached. |

## Example Usage

```tsx
import { View } from "react-native";
import React, { useState } from "react";
import { DataList } from 'react-native-paper-extended';

const videoData = [
    {
        id: '1',
        title: 'Focus on Tasks',
        description: 'Description of the meeting goes here.Description of the meeting...',
        startTime: '1:30 PM',
        endTime: '2:30 PM',
        date: '08/11/2023',
        participants: 'John Doe, Jane Smith',
    },
    {
        id: '2',
        title: "Today's Task Update",
        description: 'Description of the meeting goes here.Description of the meeting...',
        startTime: '1:30 PM',
        endTime: '2:30 PM',
        date: '08/11/2023',
        participants: 'Alice Johnson, Bob Brown',
    },
    {
        id: '3',
        title: 'Working Week Review',
        description: 'Description of the meeting goes here.Description of the meeting...',
        startTime: '1:30 PM',
        endTime: '2:30 PM',
        date: '08/11/2023',
        participants: 'Carlos Perez, Emily Davis',
    },
];

  const [expandedItems, setExpandedItems] = useState({});
    const [selected, setSelected] = useState([]);
    const [activeModule, setActiveModule] = React.useState('video');

    const handleExpandAll = () => {
        
        console.log('handleExpandAll called');
        const newExpandedItems = {};
        selected.forEach((itemId) => {
          newExpandedItems[itemId] = true;
        });
        setExpandedItems(newExpandedItems);
      };
      
      const handleCollapseAll = () => {
        console.log('handleCollapseAll called');
        const newExpandedItems = {};
        selected.forEach((itemId) => {
          newExpandedItems[itemId] = false;
        });
        setExpandedItems(newExpandedItems);
      };

    const handleModuleChange = (module) => {
        setActiveModule(module);
    }
    const handleEndReached = () => {
        alert('End of list reached!');
      };
      
    
    return (

        <View>
                <DataList
                    data={videoData}
                    containerStyle={{
                        marginHorizontal: 10,
                    }}
                    anchorMenuPosition={
                        {
 
                        }
                    }
                    selected={selected}
                    setSelected={setSelected}
                    expandedItems={expandedItems}
                    setExpandedItems={setExpandedItems}
                    expandAll={handleExpandAll}
                    collapseAll={handleCollapseAll}                
                    showButton={true}
                    buttonText="Join"
                    buttonStyles={{
                        backgroundColor: '#734BD1',
                        borderRadius: 20,
                        height: 28,
                        justifyContent: 'center',
                        alignItems: 'center',
                        paddingHorizontal: 14,
                    }}
                    titleStyles={{
                        fontSize: 16,
                        fontWeight: 'bold',
                        color: '#734BD1',
                        alignContent: 'center',
                    }}
                    subtitleStyles={{ fontSize: 12, color: '#868FA7' }}
                    showCheckbox={true}
                    showMediaIcon={false}
                    showAvatar={false}
                    showStatusIcon={true}
                    showSubtitle1={false}
                    showSubtitle2={false}
                    showSubtitle3={true}
                    dropdownProps={{
                        enabled: true,
                        showMenu: true,
                    }}
                    showTextInsteadOfDropdown={false}
                    textInsteadOfDropdown={'HCP'}
                    textInsteadOfDropdownStyles={{ color: '#868FA7', fontWeight: '600', fontSize: 12, position: 'relative', bottom: 8, marginRight: 8 }}
                    onEndReached={handleEndReached}
                    />
                  </View>
    )
export default MyDataList;

This example demonstrates a simple usage of the DataListProps type to create a customizable data list component.

0.3.31

5 months ago

0.3.30

5 months ago

0.3.73

4 months ago

0.1.10

5 months ago

0.3.72

4 months ago

0.1.11

5 months ago

0.3.71

4 months ago

0.1.12

5 months ago

0.3.70

4 months ago

0.1.13

5 months ago

0.1.14

5 months ago

0.3.39

5 months ago

0.3.38

5 months ago

0.3.37

5 months ago

0.3.36

5 months ago

0.3.35

5 months ago

0.3.34

5 months ago

0.3.33

5 months ago

0.3.32

5 months ago

0.3.29

5 months ago

0.3.64

4 months ago

0.3.20

5 months ago

0.3.63

4 months ago

0.3.62

4 months ago

0.3.61

4 months ago

0.3.60

4 months ago

0.3.28

5 months ago

0.3.27

5 months ago

0.3.26

5 months ago

0.3.69

4 months ago

0.3.68

4 months ago

0.3.67

4 months ago

0.3.23

5 months ago

0.3.66

4 months ago

0.3.22

5 months ago

0.3.65

4 months ago

0.3.21

5 months ago

0.3.19

5 months ago

0.3.18

5 months ago

0.1.8

5 months ago

0.1.7

7 months ago

0.3.8

5 months ago

0.1.9

5 months ago

0.3.53

4 months ago

0.3.52

4 months ago

0.3.51

4 months ago

0.3.50

4 months ago

0.3.9

5 months ago

0.3.17

5 months ago

0.3.16

5 months ago

0.3.59

4 months ago

0.3.15

5 months ago

0.3.58

4 months ago

0.3.14

5 months ago

0.3.57

4 months ago

0.3.13

5 months ago

0.3.56

4 months ago

0.3.12

5 months ago

0.3.55

4 months ago

0.3.11

5 months ago

0.3.54

4 months ago

0.3.10

5 months ago

0.3.42

4 months ago

0.3.40

4 months ago

0.3.49

4 months ago

0.3.48

4 months ago

0.3.47

4 months ago

0.3.46

4 months ago

0.3.45

4 months ago

0.3.44

4 months ago

0.3.43

4 months ago

0.2.1

5 months ago

0.2.0

5 months ago

0.2.7

5 months ago

0.2.6

5 months ago

0.2.8

5 months ago

0.2.3

5 months ago

0.2.2

5 months ago

0.2.5

5 months ago

0.2.4

5 months ago

0.1.6

10 months ago

0.1.5

10 months ago

0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago