2.0.1 • Published 3 months ago

react-svgmap-india v2.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

React SVG Map India

This package generates an interactive SVG map of India. It allows users to highlight states on hover and retrieve the value of the selected state. The map includes all states and union territories of India.

India Map

Installation

Install the package via npm:

npm install react-svgmap-india

State List

The following are the states and UTs mapped with its ID.

const states = {
  'AN': 'Andaman and Nicobar Islands',
  'AP': 'Andhra Pradesh',
  'AR': 'Arunachal Pradesh',
  'AS': 'Assam',
  'BR': 'Bihar',
  'CH': 'Chandigarh',
  'CT': 'Chhattisgarh',
  'DD': 'Dadra and Nagar Haveli and Daman and Diu',
  'DL': 'Delhi',
  'DN': 'Daman and Diu',
  'GA': 'Goa',
  'GJ': 'Gujarat',
  'HP': 'Himachal Pradesh',
  'HR': 'Haryana',
  'JH': 'Jharkhand',
  'JK': 'Jammu and Kashmir',
  'KA': 'Karnataka',
  'KL': 'Kerala',
  'LA': 'Ladakh',
  'LD': 'Lakshadweep',
  'MH': 'Maharashtra',
  'ML': 'Meghalaya',
  'MN': 'Manipur',
  'MP': 'Madhya Pradesh',
  'MZ': 'Mizoram',
  'NL': 'Nagaland',
  'OR': 'Odisha',
  'PB': 'Punjab',
  'PY': 'Puducherry',
  'RJ': 'Rajasthan',
  'SK': 'Sikkim',
  'TG': 'Telangana',
  'TN': 'Tamil Nadu',
  'TR': 'Tripura',
  'UP': 'Uttar Pradesh',
  'UT': 'Uttarakhand',
  'WB': 'West Bengal'
}

Usage

'use client'

import { useState } from 'react'
import IndiaMap from 'react-svgmap-india'

export default function MapComponent() {
    const [state, setState] = useState('')

    return (
        <>
            <div>{state}</div>
            <IndiaMap
                onClick={(selectedValue: string) => setState(selectedValue)}
                size='500px'
                mapColor='white'
                strokeColor='#4f4f4f'
                strokeWidth='1'
                hoverColor='#48d8f5'
            />
        </>
    )
}

Props Available

PropsDescriptionRequirementDefault Value
onClickCallback function to get the selected state value.RequiredNA
classNameCustom classname for the map component.Optional"svgmap"
sizeWidth of the map.Optional"inherit"
mapColorColor of the map.Optional"#ffffff"
strokeColorBorder color of each state.Optional"#000000"
strokeWidthBorder width of each state.Optional"0.5"
hoverColorColor of the state while hovering on it.Optional"#303030"

Contributing

Pull requests are welcome.

Credits

Reference of SVG map taken from MAPSVG.

2.0.1

3 months ago

2.0.0

3 months ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago