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

react-simple-explorer

v1.1.1

Published

A simple, controlled and unopinionated react file explorer package

Downloads

36

Readme

React Simple Explorer

A simple package for directory tree visualization.

Usage

import React from 'react'
import ReactSimpleExplorer from 'react-simple-explorer'

const folderEntries = [
  {
    name: "some-image.png",
    type: "file",
    size: 3000,
    author: "John Doe",
    createdAt: "2020-12-01T10:23:00-03:00",
    modifiedAt: "2020-12-01T10:23:00-03:00",
  },
  {
    name: "assets",
    type: "folder",
    size: 0,
    author: "John Doe",
    createdAt: "2020-12-01T10:23:00-03:00",
    modifiedAt: "2020-12-01T10:23:00-03:00",
  },
]

const App = () => (
  <ReactSimpleExporer
    entries={folderEntries}
  />
)

Example: Fetching from S3

Let's assume you have a helper function fetchEntriesFromS3() that fetches files and folders from an AWS S3 bucket.

import React, { useState, useEffect } from 'react'
import ReactSimpleExplorer from 'react-simple-explorer'

const App = () => {
  const [currentFolder, setCurrentFolder] = useState('/')
  const [loading, setLoading] = useState(true)
  const [entries, setEntries] = useState([])

  useEffect(async () => {
      setEntries(await fetchEntriesFromS3(currentFolder))
      setLoading(false)
  }, [currentFolder])

  const handleFileClick = () => { ... }

  const handleFolderClick = (folder) => {
    setCurrentFolder(folder)
  }

  return (
    <ReactSimpleExporer
      loading={loading}
      entries={folderEntries}
      onFileClick={handleFileClick}
      onFolderClick={handleFolderClick}
    />
  )
}

Props available

Prop Name | Type | Description | Default --------- | ---- | ----------- | ------- loading | boolean | Shows a spinner and a loading message, defined by the loadingLabel prop, instead of the file and folder entries. | false loadingLabel | string | Sets a custom loading message. | "Loading..." entries | array | An array of files and/or folders entries to populate the explorer list. Each entry must have at least two fields named name and type. The type field must have one of the following values: 'file' or 'folder'. | [] onEntryClick | function | A function that should be called every time an entry is clicked. Will be triggered for both file and folders entries' click. | () => {} onFileClick | function | A function that should be called every time a file entry is clicked. It has precedence over the onEntryClick callback. | () => {} onFolderClick | function | A function that should be called every time a folder entry or breadcrumb piece is clicked. It has precedence over the onEntryClick and handleBreadcrumbClick callbacks. | () => {} currentFolder | string | A string defining the current folder from which the entries are being shown. | / showUpNavigationEntry | boolean | Defines if an entry indicating an upper navigation must be shown. | false navigateUpLabel | string | Sets a custom label for the up navigation entry. | "Navigate up..." handleNavigationUp | function | A function that should be called every time the navigate up entry is clicked. | () => {} showBreadcrumb | boolean | Defines if a breadcrumb must be shown above the file explorer panel. The breadcrumb will use the value of the currentFolder prop to determine its pieces. | false handleBreadcrumbClick | function | A function that should be called every time a breadcrumb piece is clicked. | () => {} enableEntryClick | boolean | Defines if the entries, both files and folders, on the panel should be clickable. | true enableFileClick | boolean | Defines if the file entries on the panel should be clickable. | true enableFolderClick | boolean | Defines if the folder entries on the panel should be clickable. | true customTableDefinitions | array | An array with objects containing two fields, label and key, that should be used to structure the columns for the file explorer table based on the data from the entries prop. | See below dateTimeFormat | string | The datetime format based on the Unicode Tokens that should be used to display the data from the createdAt and modifiedAt fields when they are present within the data from the entries prop. | yyyy-MM-dd HH:m showSearchBar | boolean | Defines if a search bar will be shown | true searchPlaceholder | string | Sets the placeholder for the search bar input | "Type something to search..."

Default Table Definitions

  [
    {
      label: 'Name',
      key: 'name'
    },
    {
      label: 'Size',
      key: 'size'
    },
    {
      label: 'Author',
      key: 'author'
    },
    {
      label: 'Created At',
      key: 'createdAt'
    },
    {
      label: 'Modified At',
      key: 'modifiedAt'
    }
  ]