UNPKG

@south-paw/react-vector-maps

Version:

A React component for interactive vector maps of the world and 100+ countries

1 lines 2.6 kB
{"version":3,"sources":["../lib/react-shim.js","../src/VectorMap.tsx"],"sourcesContent":["import * as React from 'react';\n\nexport { React };\n","import React from 'react';\n\nexport interface VectorMapLayer {\n /** Unique ID of each layer. */\n id: string;\n /** Name of the layer. */\n name: string;\n /** SVG path for the layer. */\n d: string;\n}\n\nexport interface VectorMapProps extends React.SVGProps<SVGSVGElement> {\n children?: React.ReactNode;\n /** Unique ID of the SVG element. */\n id: string;\n /** Name of the map. */\n name: string;\n /** View box for the map. */\n viewBox: string;\n /** Layers that represent the regions of the map. */\n layers: VectorMapLayer[];\n /** Tab index for each layer. Set to '-1' to disable layer focusing. */\n tabIndex?: number;\n /** Props to spread onto each layer. */\n layerProps?: React.SVGProps<SVGPathElement>;\n /** Layer IDs to 'select' with the 'aria-checked' attribute. */\n checkedLayers?: string[];\n /** Layer IDs to 'select' with the 'aria-current' attribute. */\n currentLayers?: string[];\n}\n\nexport function VectorMap({\n id,\n name,\n layers,\n tabIndex = 0,\n layerProps,\n checkedLayers,\n currentLayers,\n children,\n ...other\n}: VectorMapProps) {\n if (!layers || layers.length === 0) {\n // eslint-disable-next-line no-console\n console.error(\n `[@south-paw/react-vector-maps] No 'layers' prop provided. Did you spread a map object onto the component?`,\n );\n return null;\n }\n\n return (\n <svg xmlns=\"http://www.w3.org/2000/svg\" key={id} aria-label={name} {...other}>\n {children}\n {layers.map((layer) => (\n <path\n key={layer.id}\n tabIndex={tabIndex}\n aria-label={layer.name}\n aria-checked={checkedLayers && checkedLayers.includes(layer.id)}\n aria-current={currentLayers && currentLayers.includes(layer.id)}\n {...layer}\n {...layerProps}\n />\n ))}\n </svg>\n );\n}\n"],"mappings":";AAAA,YAAY,WAAW;;;ACmDnB,SAGI,KAHJ;AApBG,SAAS,UAAU;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,KACG;AACL,GAAmB;AACjB,MAAI,CAAC,UAAU,OAAO,WAAW,GAAG;AAElC,YAAQ;AAAA,MACN;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEA,SACE,qBAAC;AAAA,IAAI,OAAM;AAAA,IAAsC,cAAY;AAAA,IAAO,GAAG;AAAA,IACpE;AAAA;AAAA,MACA,OAAO,IAAI,CAAC,UACX,oBAAC;AAAA,QAEC;AAAA,QACA,cAAY,MAAM;AAAA,QAClB,gBAAc,iBAAiB,cAAc,SAAS,MAAM,EAAE;AAAA,QAC9D,gBAAc,iBAAiB,cAAc,SAAS,MAAM,EAAE;AAAA,QAC7D,GAAG;AAAA,QACH,GAAG;AAAA,SANC,MAAM,EAOb,CACD;AAAA;AAAA,KAZ0C,EAa7C;AAEJ;","names":[]}