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-world-maps

v0.0.1

Published

This package comes with various SVG maps of the main continents, a map of the United States, and a simple component to render your own maps if your provide the data set.

Downloads

38

Readme

react-world-maps | Various svg continent maps with React

This package comes with various SVG maps of the main continents, a map of the United States, and a simple component to render your own maps if your provide the data set.

A map of territories:

// Use ComposedMap to render multiple territories
import * as React from 'react'
import { ComposedMap } from 'react-world-maps'

let myCustomData = [
  {
    name: "Territory 1", // should be unique in the set
    d: "M 10 10 L 50 50 L 10 50 Z", // An svg path string representing the map
  },
  {
    name: "Territory 2",
    d: "M 10 10 L 100 10 L 100 50 L 50 50 Z",
  }
]

const MyCustomMapComponent = () => (
  <ComposedMap
    viewBox={[100, 50]}
    data={myCustomData}
    title="My Country"
  />
)

Installation

yarn add react-world-maps

or

npm install react-world-maps --save

Usage

The below example could be a way to add a map to a Geography quiz.

import * as React from "react"
import { AfricaMap } from "react-world-maps"

export const MapQuiz = ({guess, setGuess, answer}) => {
  let config = {
    [guess]: {
      fill: guess === answer ? "#0f0" : "#f00"
    },
    [answer]: guess ? "#0f0" : "#ccc"
  }
  
  const mapHandler = (event) => {
    if (guess) return
    setGuess(event.target.dataset.name)
  }

  return (
    <AfricaMap
      customize={config}
      defaultClickHandler={mapHandler}
      hideTitles
    />
  )
}

API:

import {
  ComposedMap,
  AfricaMap,
  AsiaMap,
  EuropeMap,
  NorthAmericaMap,
  SouthAmericaMap,
  UnitedStatesMap,
} from "react-world-map"

ComposedMap

Use this component to create your own map component | prop | type | description | | ---------------- | -------------| ----------------------------------------------- | | data | required {name: string, d: string}[] | Array of svg names and paths that will compose the map. | defaultClickHandler | (event: React.MouseEvent<SVGPathElement, MouseEvent>) => any | Default function to attach to each path. | viewBox | [width: number, height: number] | Viewbox settings for svg container | title | string | Title of svg container | customize | {[key: string // should be same as name in data]: {React.SVGAttributes<SVGPathElement>}} | Object of attributes to be passed on to svg path element for keyed territories | hideTitles | boolean | prevent path title from appearing on hover |

Territory Map (AfricaMap, AsiaMap, EuropeMap, NorthAmericaMap, SouthAmericaMap, UnitedStatesMap)

These are just wrappers around the ComposedMap, using predefined data sets. They take an optional subset of the props above: hideTitles, customize, defaultClickHandler.

License

MIT

Sources and prior art

The map data are sourced from Natural Earth, and converted to SVG paths with mapshaper. This package is inspired on the react-usa-map package. In fact the USA map data was derived from there.