{"id":13421996,"url":"https://github.com/VictorCazanave/react-svg-map","last_synced_at":"2025-03-15T10:31:34.911Z","repository":{"id":43221923,"uuid":"124777731","full_name":"VictorCazanave/react-svg-map","owner":"VictorCazanave","description":"A set of React.js components to display an interactive SVG map","archived":false,"fork":false,"pushed_at":"2022-11-19T14:49:29.000Z","size":1501,"stargazers_count":232,"open_issues_count":10,"forks_count":50,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-02-27T01:04:39.171Z","etag":null,"topics":["checkbox","component","interactive","map","radiobutton","react","svg"],"latest_commit_sha":null,"homepage":"https://victorcazanave.github.io/react-svg-map/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VictorCazanave.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-11T16:48:49.000Z","updated_at":"2025-02-26T15:45:14.000Z","dependencies_parsed_at":"2023-01-21T12:40:17.840Z","dependency_job_id":null,"html_url":"https://github.com/VictorCazanave/react-svg-map","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCazanave%2Freact-svg-map","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCazanave%2Freact-svg-map/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCazanave%2Freact-svg-map/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VictorCazanave%2Freact-svg-map/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VictorCazanave","download_url":"https://codeload.github.com/VictorCazanave/react-svg-map/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243719090,"owners_count":20336591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["checkbox","component","interactive","map","radiobutton","react","svg"],"created_at":"2024-07-30T23:00:35.189Z","updated_at":"2025-03-15T10:31:34.279Z","avatar_url":"https://github.com/VictorCazanave.png","language":"JavaScript","funding_links":[],"categories":["UI Components","JavaScript"],"sub_categories":["Map","Data Visualization"],"readme":"# react-svg-map\n\n[![npm version](https://img.shields.io/npm/v/react-svg-map)](https://www.npmjs.com/package/react-svg-map)\n[![Build Status](https://travis-ci.org/VictorCazanave/react-svg-map.svg?branch=master)](https://travis-ci.org/VictorCazanave/react-svg-map)\n[![codecov](https://codecov.io/gh/VictorCazanave/react-svg-map/branch/master/graph/badge.svg)](https://codecov.io/gh/VictorCazanave/react-svg-map)\n[![Dependency Status](https://david-dm.org/VictorCazanave/react-svg-map.svg)](https://david-dm.org/VictorCazanave/react-svg-map)\n[![peerDependencies Status](https://david-dm.org/VictorCazanave/react-svg-map/peer-status.svg)](https://david-dm.org/VictorCazanave/react-svg-map?type=peer)\n\n_A set of React.js components to display an interactive SVG map._\n\n![React SVG Map](https://media.giphy.com/media/QWpIwVdhY81RL05iNo/giphy.gif)\n\n## Demo\n\n[Take a look at the live demo!](https://victorcazanave.github.io/react-svg-map/)\n\n## Installation\n\n### npm\n\n`npm install --save react-svg-map`\n\n### yarn\n\n`yarn add react-svg-map`\n\n## Usage\n\n### :warning: Breaking change from v1\n\n**This package does not include maps anymore!**\n\nYou have to install the map you need from [svg-maps](https://github.com/VictorCazanave/svg-maps) or you can use your own map. See [maps section](#maps) for more details.\n\nIf you are still using the 1.x.x version, look at the [v1 documentation](https://github.com/VictorCazanave/react-svg-map/tree/v1.3.2#react-svg-map).\n\n### :earth_africa: Simple SVG Map\n\nThis is the base component to display an SVG map.\n\n- Import `SVGMap` component from `react-svg-map`\n- Import the map you want\n- Optionally, import `react-svg-map/lib/index.css` if you want to apply the default styles\n\n```javascript\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport Taiwan from \"@svg-maps/taiwan\";\nimport { SVGMap } from \"react-svg-map\";\nimport \"react-svg-map/lib/index.css\";\n\nclass App extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n\n  render() {\n    return \u003cSVGMap map={Taiwan} /\u003e;\n  }\n}\n\nReactDOM.render(\u003cApp /\u003e, document.getElementById(\"app\"));\n```\n\n#### API\n\n| Prop                | Type             | Default               | Description                                                                                                      |\n| ------------------- | ---------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------- |\n| map                 | Object           | **required**          | Describe SVG map to display. See [maps section](#maps) for more details.                                         |\n| className           | String           | `'svg-map'`           | CSS class of `\u003csvg\u003e`.                                                                                            |\n| role                | String           | `'none'`              | ARIA role of `\u003csvg\u003e`.                                                                                            |\n| locationClassName   | String\\|Function | `'svg-map__location'` | CSS class of each `\u003cpath\u003e`. The function parameters are the location object and the location index.              |\n| locationTabIndex    | String\\|Function | `'0'`                 | Tabindex each `\u003cpath\u003e`. The function parameters are the location object and the location index.                  |\n| locationRole        | String           | `'none'`              | ARIA role of each `\u003cpath\u003e`.                                                                                      |\n| locationAriaLabel   | Function         | `location.name`       | ARIA label of each `\u003cpath\u003e`. The function parameters are the location object and the location index.             |\n| onLocationMouseOver | Function         |                       | Invoked when the user puts the mouse over a location.                                                            |\n| onLocationMouseOut  | Function         |                       | Invoked when the user puts the mouse out of a location.                                                          |\n| onLocationMouseMove | Function         |                       | Invoked when the user moves the mouse on a location.                                                             |\n| onLocationClick     | Function         |                       | Invoked when the user clicks on a location.                                                                      |\n| onLocationKeyDown   | Function         |                       | Invoked when the user hits a keyboard key on a location.                                                         |\n| onLocationFocus     | Function         |                       | Invoked when the user focuses a location.                                                                        |\n| onLocationBlur      | Function         |                       | Invoked when the user unfocuses a location.                                                                      |\n| isLocationSelected  | Function         |                       | Executed to determine if a location is selected. This property is used to set the `aria-checked` HTML attribute. |\n| childrenBefore      | Node             |                       | \"Slot\" before all the locations (`\u003cpath\u003e`).                                                                      |\n| childrenAfter       | Node             |                       | \"Slot\" after all the locations (`\u003cpath\u003e`).                                                                       |\n\n### :ballot_box_with_check: Checkbox SVG Map\n\nThis is an implementation of `SVGMap` that behaves like a group of checkboxes.  \nIt is based on this [WAI-ARIA example](https://www.w3.org/TR/wai-aria-practices/examples/checkbox/checkbox-1/checkbox-1.html) to support keyboard navigation and be accessible.\n\n- Import `CheckboxSVGMap` component from `react-svg-map`\n- Import the map you want\n- Optionally, import `react-svg-map/lib/index.css` if you want to apply the default styles\n\n```javascript\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport Taiwan from \"@svg-maps/taiwan\";\nimport { CheckboxSVGMap } from \"react-svg-map\";\nimport \"react-svg-map/lib/index.css\";\n\nclass App extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n\n  render() {\n    return \u003cCheckboxSVGMap map={Taiwan} /\u003e;\n  }\n}\n\nReactDOM.render(\u003cApp /\u003e, document.getElementById(\"app\"));\n```\n\n#### API\n\n| Prop                | Type             | Default               | Description                                                                                                                              |\n| ------------------- | ---------------- | --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |\n| map                 | Object           | **required**          | Describe SVG map to display. See [maps section](#maps) for more details.                                                                 |\n| className           | String           | `'svg-map'`           | CSS class of `\u003csvg\u003e`.                                                                                                                    |\n| locationClassName   | String\\|Function | `'svg-map__location'` | CSS class of each `\u003cpath\u003e`. The function parameters are the location object and the location index.                                      |\n| locationAriaLabel   | Function         | `location.name`       | ARIA label of each `\u003cpath\u003e`. The function parameters are the location object and the location index.                                     |\n| selectedLocationIds | String[]         |                       | List of `id`s of the **initial** selected locations. It is used only when the component is mounted and is not synchronized when updated. |\n| onChange            | Function         |                       | Invoked when the user selects/deselects a location. The list of selected locations is passed as parameter.                               |\n| onLocationMouseOver | Function         |                       | Invoked when the user puts the mouse over a location.                                                                                    |\n| onLocationMouseOut  | Function         |                       | Invoked when the user puts the mouse out of a location.                                                                                  |\n| onLocationMouseMove | Function         |                       | Invoked when the user moves the mouse on a location.                                                                                     |\n| onLocationFocus     | Function         |                       | Invoked when the user focuses a location.                                                                                                |\n| onLocationBlur      | Function         |                       | Invoked when the user unfocuses a location.                                                                                              |\n| childrenBefore      | Node             |                       | \"Slot\" before all the locations (`\u003cpath\u003e`).                                                                                              |\n| childrenAfter       | Node             |                       | \"Slot\" after all the locations (`\u003cpath\u003e`).                                                                                               |\n\n### :radio_button: Radio SVG Map\n\nThis is an implementation of `SVGMap` that behaves like a group of radio buttons.  \nIt is based on this [WAI-ARIA example](https://www.w3.org/TR/wai-aria-practices/examples/radio/radio-1/radio-1.html) to support keyboard navigation and be accessible.\n\n- Import `RadioSVGMap` component from `react-svg-map`\n- Import the map you want\n- Optionally, import `react-svg-map/lib/index.css` if you want to apply the default styles\n\n```javascript\nimport React from \"react\";\nimport ReactDOM from \"react-dom\";\nimport Taiwan from \"@svg-maps/taiwan\";\nimport { RadioSVGMap } from \"react-svg-map\";\nimport \"react-svg-map/lib/index.css\";\n\nclass App extends React.Component {\n  constructor(props) {\n    super(props);\n  }\n\n  render() {\n    return \u003cRadioSVGMap map={Taiwan} /\u003e;\n  }\n}\n\nReactDOM.render(\u003cApp /\u003e, document.getElementById(\"app\"));\n```\n\n#### API\n\n| Prop                | Type             | Default               | Description                                                                                                                    |\n| ------------------- | ---------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------ |\n| map                 | Object           | **required**          | Describe SVG map to display. See [maps section](#maps) for more details.                                                       |\n| className           | String           | `'svg-map'`           | CSS class of `\u003csvg\u003e`.                                                                                                          |\n| locationClassName   | String\\|Function | `'svg-map__location'` | CSS class of each `\u003cpath\u003e`. The function parameters are the location object and the location index.                            |\n| locationAriaLabel   | Function         | `location.name`       | ARIA label of each `\u003cpath\u003e`. The function parameters are the location object and the location index.                           |\n| selectedLocationId  | String           |                       | `id` of the **initial** selected location. It is used only when the component is mounted and is not synchronized when updated. |\n| onChange            | Function         |                       | Invoked when the user selects a location. The selected location is passed as parameter.                                        |\n| onLocationMouseOver | Function         |                       | Invoked when the user puts the mouse over a location.                                                                          |\n| onLocationMouseOut  | Function         |                       | Invoked when the user puts the mouse out of a location.                                                                        |\n| onLocationMouseMove | Function         |                       | Invoked when the user moves the mouse on a location.                                                                           |\n| onLocationFocus     | Function         |                       | Invoked when the user focuses a location.                                                                                      |\n| onLocationBlur      | Function         |                       | Invoked when the user unfocuses a location.                                                                                    |\n| childrenBefore      | Node             |                       | \"Slot\" before all the locations (`\u003cpath\u003e`).                                                                                    |\n| childrenAfter       | Node             |                       | \"Slot\" after all the locations (`\u003cpath\u003e`).                                                                                     |\n\n## Maps\n\n### Existing maps\n\nSince v2.0.0 this package does not provide maps anymore. All the existing maps have been moved to the independant [svg-maps](https://github.com/VictorCazanave/svg-maps) project because they may be useful for other components/projects.\n\n### Custom maps\n\nYou can modify existing maps or create your own.\n\n#### Modify a map\n\n1. Import the map to modify\n1. Create a new object from this map\n1. Pass this new object as `map` prop of `\u003cSVGMap /\u003e` component\n\n```javascript\nimport React from \"react\";\nimport Taiwan from \"@svg-maps/taiwan\";\nimport { SVGMap } from \"react-svg-map\";\n\nclass App extends React.Component {\n  constructor(props) {\n    super(props);\n\n    // Create new map object\n    this.customTaiwan = {\n      ...Taiwan,\n      label: \"Custom map label\",\n      locations: Taiwan.locations.map(location =\u003e {\n        // Modify each location\n      })\n    };\n  }\n\n  render() {\n    return \u003cSVGMap map={this.customTaiwan} /\u003e;\n  }\n}\n```\n\nIt is recommended to not modify the SVG properties (viewBox, path), because it may break the map's display.\n\n#### Create a map\n\nIf you create a new map (other country, city...), feel free to [contribute to svg-maps project](https://github.com/VictorCazanave/svg-maps/blob/master/CONTRIBUTING.md)!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVictorCazanave%2Freact-svg-map","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FVictorCazanave%2Freact-svg-map","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FVictorCazanave%2Freact-svg-map/lists"}