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

@milon27/react-media-library

v2.1.6

Published

Compitable with react js and next js.

Downloads

29

Readme

React Media Library (like wordpress media library)

Compitable with react js and next js.

Installation Commands

npm install axios @milon27/react-media-library

How to use

  1. import css in index.js/ts or app.jsx or app.tsx.
import '@milon27/react-media-library/dist/react-media-library.css';
  1. Create the media library page
import { MediaLibrary, SelectImageButton } from '@milon27/react-media-library';

const MediaLibraryPage=()=>{
  const UPLOAD_URL = '/upload'; // upload endpoint should give back the full image url as string (this will visible as preview when upload a new image.) 
  const GET_ALL_IMAGE_API_URL = '/get-all';
  const [imageList, setImageList] = useState<string[]>([] as string[])
  
  // load all images here which are already in the server
  useEffect(() => {
    axios.get(GET_ALL_IMAGE_API_URL).then(listres => {
      const data = listres.data
      setImageList(data)
    })
  }, [])

  const deleteFile=(index:number)=>{
    const url = imageList[index]
    const name=url.substring(url.lastIndexOf('/') + 1);
    axios.delete('/file/:name', {
        params: {
            name: name
        }
    }).then(res => {
        console.log(res.data)
        setImageList(old => {
          old.splice(index, 1)
          return [...old]
        })
    }).catch(e => {
        console.log(e)
    })
  }

  return <div>
      <MediaLibrary uploadUrl={UPLOAD_URL} previewList={imageList} setPreviewList={setImageList} onFileDelete={(index: number) => {
      //do axios impliemntaion
      deleteFile(index);
    }} />
  </div>
}
  1. Create a select button that will upload and select image
import { MediaLibrary, SelectImageButton } from '@milon27/react-media-library';

const SelectImagePage=()=>{
  const UPLOAD_URL = '/upload';// upload endpoint should give back the full image url as string (this will visible as preview when upload a new image.)
  const GET_ALL_IMAGE_API_URL = '/get-all';
  const [imageList, setImageList] = useState<string[]>([] as string[])
  const [select, setSelect] = useState<string[]>([])
  
  // load all images here which are already in the server
  useEffect(() => {
    axios.get(GET_ALL_IMAGE_API_URL).then(listres => {
      const data = listres.data
      setImageList(data)
    })
  }, [])

  const onSelect = (urls: string[]) => {
    setSelect(urls)
  }

  return <>
    {/* multiple image select */}
    <SelectImageButton uploadUrl={UPLOAD_URL} title='Select Multiple Image' previewList={imageList} setPreviewList={setImageList} onSelect={onSelect} multiple={true} />

    {/* single image select */}
    <SelectImageButton uploadUrl={UPLOAD_URL} title='Select Single Image' previewList={imageList} setPreviewList={setImageList} onSelect={onSelect} multiple={false} />

    <br /><br />
    {select.toString()}

  </>
}

screenshot

screenshot screenshot