npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@blb-ventures/react-flat-list

v0.10.2

Published

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

Downloads

39

Readme

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: '[email protected]',
      isAdmin: false,
      image: '/images/john-doe.jpg',
    },
    {
      name: 'Jane Doe',
      id: 2,
      email: '[email protected]',
      isAdmin: false,
      image: '/images/jane-doe.jpg',
    },
    { name: 'Admin', id: 3, email: '[email protected]', 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