New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@blb-ventures/react-flat-list

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blb-ventures/react-flat-list

A React.js component to help render a list of components.

  • 0.10.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
11
increased by57.14%
Maintainers
1
Weekly downloads
 
Created
Source

React Flat List

A React.js component to help render a list of components.

The idea behind this library is to create Item Components that display a single element given a specific data type and can be reused on multiple lists. Or a single behavior that can accept multiple data types. It was inspired by React Native FlatList.

Install

npm i @blb-ventures/resource
# or
yarn add @blb-ventures/resource
# or
pnpm i @blb-ventures/resource

Usage and Examples

Components:

  • FlatList: the list wrapper that renders an array of data using the ListItemComponent;
  • FlatListHeader: A default header to render a title and some ReactNode to the right;
  • FlatListSubHeader: A default ListItem with bigger text to separate sections of items;
  • FlatListEmptyMessage: A muted text to render a message when the data array is empty;
  • FlatListErrorMessage: A red text to render a message when there was an error trying to load the data;
  • FlatListItem: a default list item;
  • CommonFlatListItemMapper: A base FlatListItem that spreads the data directly into the FlatListItem;
  • ObjectFlatListItem: A helper FlatListItem when you have an object and want the items to be mapping over the keys/values of the object; and
  • LinkWrapper: It uses the LinkComponent to wrap around the FlatListItem content when a url is defined.

Complete Example

import {
  FlatList,
  FlatListEmptyMessage,
  FlatListErrorMessage,
  FlatListHeader,
  FlatListItem,
  FlatListMapItemProps,
} from '@blb-ventures/react-flat-list';
import AddOutlinedIcon from '@mui/icons-material/AddOutlined';
import PersonIcon from '@mui/icons-material/Person';
import { Avatar, Button } from '@mui/material';
import { FC } from 'react'

interface User {
  name: string;
  id: number;
  email: string;
  isAdmin: boolean;
  image: string | null;
}

const UserListItem: FC<FlatListMapItemProps<User>> = ({ data }) => (
  <FlatListItem
    imageLeft={data.image}
    imageLeftOptions={{ width: '40px', height: '40px', className: 'rounded-full' }}
    left={
      data.image == null && (
        <Avatar>
          <PersonIcon />
        </Avatar>
      )
    }
    leftOptions={{ style: { minWidth: '350px' } }}
    subtitleLeft={data.email}
    subtitleRight={data.isAdmin ? 'Admin' : 'User'}
    title={data.name}
    url={`/users/${data.id}`}
  />
);

const TestPage: FC = () => {
  const users: User[] = [
    {
      name: 'John Doe',
      id: 1,
      email: 'john.doe@example.com',
      isAdmin: false,
      image: '/images/john-doe.jpg',
    },
    {
      name: 'Jane Doe',
      id: 2,
      email: 'jane.doe@example.com',
      isAdmin: false,
      image: '/images/jane-doe.jpg',
    },
    { name: 'Admin', id: 3, email: 'admin@example.com', isAdmin: true, image: null },
  ];
  const error = false;
  return (
    <FlatList
      data={users}
      dataKey="id"
      EmptyListElement={<FlatListEmptyMessage>There are no users.</FlatListEmptyMessage>}
      error={error}
      ErrorElement={
        <FlatListErrorMessage>Error while trying to load users.</FlatListErrorMessage>
      }
      HeaderElement={
        <FlatListHeader
          right={
            <Button
              onClick={() => {
                console.log('ADD USER');
              }}
              size="small"
              startIcon={<AddOutlinedIcon />}
              variant="contained"
            >
              Add User
            </Button>
          }
          title="All Users"
        />
      }
      ListItemComponent={UserListItem}
    />
  );
};
export default TestPage;
Output

Screenshot 2023-08-21 at 7 30 07 PM

Output with Error

Screenshot 2023-08-21 at 7 29 08 PM

Output for empty list

Screenshot 2023-08-21 at 7 29 32 PM

FAQs

Package last updated on 21 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc