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

@moted/react-leaflet-sidebarv2

v1.0.3

Published

A react-leaflet plugin for leaflet-sidebar-v2

Downloads

3

Readme

React-Leaflet Sidebar-v2

A react-leaflet plugin for leaflet-sidebar-v2 (which is a leaflet-only fork of sidebar-v2)

The twist is the implementation of sidebar-v2 isn't very compatible with React, so this plugin actually renders all markup via React, including event handling, and just leverages the CSS from sidebar-v2.

Getting Started

You will need to include the sidebar-v2 css in your page somehow, for example via a CDN. The close icons default to fontawesome, so this will also need to be included.

You will typically include Sidebar as a sibling component of react-leaflet Map, contained in a wrapper div so the sidebar is positioned relative to the map, with whatever Tab children are required for your layout. This is because of event handling: if the sidebar is a child of the map element, events will bubble up and be handled by leaflet first (this is because React events are actually handled by a single handler at the document root, so they will always bubble up through leaflet first). A previous commit (a9156e8bb7) attempted to solve this by disabling native events at the sidebar root, but I found too many complications. If anyone solves this I would love a PR!

The Sidebar component is stateless; all state information should be passed as props, and desired state changes communicated upwards via the onOpen and onClose callback. A minimal example might look like the following (also note that to work with the default css, the Map needs a sidebar-map class, and the Sidebar needs to be before the Map):

import React, { Component } from 'react';
import { Map, TileLayer } from 'react-leaflet';
import { Sidebar, Tab } from 'react-leaflet-sidebarv2';

export default class SidebarExample extends Component {
  constructor(props) {
    super(props);
    this.state = {
      collapsed: false,
      selected: 'home'
    };
  }

  onClose() {
    this.setState({ collapsed: true });
  }
  onOpen(id) {
    this.setState({
      collapsed: false,
      selected: id
    });
  }

  render() {
    return (
      <div>
        <Sidebar
          id="sidebar"
          collapsed={this.state.collapsed}
          selected={this.state.selected}
          onOpen={this.onOpen.bind(this)}
          onClose={this.onClose.bind(this)}
        >
          <Tab id="home" header="Home" icon="fa fa-home">
            <p>No place like home!</p>
          </Tab>
          <Tab id="settings" header="Settings" icon="fa fa-cog" anchor="bottom">
            <p>Settings dialogue.</p>
          </Tab>
        </Sidebar>
        <Map
          className="sidebar-map"
          center={[51.505, -0.09]}
          zoom={13}
          zoomControl={false}
        >
          <TileLayer
            attribution='&copy; <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
            url="http://{s}.tile.osm.org/{z}/{x}/{y}.png"
          />
        </Map>
      </div>
    );
  }
}

API

Sidebar

  • id: String Required ID of sidebar
  • position: String position of sidebar. Values: "left", "right"
  • collapsed: Boolean initial collapsed state
  • selected: String ID of selected tab
  • closeIcon: String/Component Required Icon for close button, E.g. "fa fa-times", or React component
  • onOpen: Func Event
  • onClose: Func Event

Tab

  • id: String Required ID of tab for use with state
  • header: String Required Title of tab
  • icon: String/Component Required Icon for the tab E.g. "fa fa-cog", or React component
  • anchor: String Fix tab to top or bottom. Values: "top", "bottom"
  • active: Boolean Initial active state
  • disabled: Boolean