1.5.0 • Published 3 months ago

react-usa-map-select v1.5.0

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

React USAMapSelect Component

The USAMapSelect component is a React SVG map of the United States of Americca with simple interactive features. It allows you to highlight and interact with individual states, providing callbacks for mouse events and some customization options for styling.

USA Map

Live example

Installation

npm install react-usa-map-select

Usage

const MyComponent = () => {
 const handleClick = (event) => {
  // Handle click event
  console.log(`Clicked on state: ${event.currentTarget.getAttribute('name')}`);
 };

 const handleMouseEnter = (event) => {
  // Handle mouse enter event
  console.log(`Mouse entered state: ${event.currentTarget.getAttribute('name')}`);
 };

 const handleMouseLeave = () => {
  // Handle mouse leave event
  console.log('Mouse left a state');
 };

 return (
  <>
   <h1>Interactive USA Map</h1>
   <USAMapSelect
    onClick={handleClick}
    onUSAStateMouseEnter={handleMouseEnter}
    onUSAStateMouseLeave={handleMouseLeave}
    showStateNameOnHover={true}
    USAStateOnHoverColor="blue"
    USAStateOnHoverStrokeColor="white"
   />
  </>
 );
};

export default MyComponent;

Props

API

PropTypeDefaultDescription
onClick(event: React.SyntheticEvent<SVGGElement>) => void-Callback function triggered on clicking a state.
onUSAStateMouseEnter(event?: React.SyntheticEvent<SVGGElement>) => void-Callback function triggered on mouse enter over a state.
onUSAStateMouseLeave(event?: React.SyntheticEvent<SVGGElement>) => void-Callback function triggered on mouse leave from a state.
showStateNameOnHoverbooleanfalseBoolean indicating whether to display the state name on hover.
USAStateTextColorkeyof ReturnType<typeof colorVariants>slateColor variant for the state text if showStateNameOnHover is true. Choose from: slate, white, gray, yellow, green, emerald, blue, purple, orange, pink.
USAStateColorkeyof ReturnType<typeof colorVariants>grayColor variant for the state. Choose from: slate, white, gray, yellow, green, emerald, blue, purple, orange, pink.
USAStateOnHoverColorkeyof ReturnType<typeof colorVariants>slateColor variant for the state on hover. Choose from: slate, white, gray, yellow, green, emerald, blue, purple, orange, pink.
USAStateOnHoverStrokeColorkeyof ReturnType<typeof colorVariants>-Stroke color variant for the state on hover. Choose from the same options as USAStateOnHoverColor.
USAStatePosition{ x: string, y: string } or "center"-Position of the state name relative to the SVG wrapper. If center, the state name will persist the center position relative to the SVG wrapper.

Styling

The USAMapSelect component is built using Tailwind CSS. You can customize the styling of the state name that shows on the top of the map by passing in your own Tailwind CSS classes as props. You can also style the svg wrapper element by passing in a class name to the wrapperClassName prop.

PropTypeDefaultDescription
stateTextClassnamestring-Class name for the element that renders the state name when showStateNameOnHover is true
wrapperClassNamestring-Class name for the element that wraps the map.

License

MIT ©

1.5.0

3 months ago

1.4.9

3 months ago

1.4.8

5 months ago

1.4.7

5 months ago

1.4.6

5 months ago

1.4.5

5 months ago

1.4.4

5 months ago

1.4.3

5 months ago

1.4.2

5 months ago

1.4.1

5 months ago

1.4.0

5 months ago

1.3.0

5 months ago

1.2.0

5 months ago

1.0.1

6 months ago

1.0.0

6 months ago