Skip to content

Commit ea9dc1a

Browse files
Merge pull request #25 from VictorCazanave/dev-1.3.0
v1.2.0 to v1.3.0
2 parents 5e07fb9 + a8a15d5 commit ea9dc1a

16 files changed

+159
-90
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
README.md
2+
jest.config.js

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.DS_Store
2+
.vscode
23
node_modules
34
lib
45
dist
56
coverage
6-
.vscode

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,15 @@ All notable changes to this project will be documented in this file.
33

44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
55

6+
## [1.3.0]
7+
### Added
8+
- Allow function locationClassName prop of SVGMap, CheckboxSVGMap and RadioSVGMap components
9+
10+
### Changed
11+
- Update examples
12+
- Externalize Jest config
13+
- Update Jest config
14+
615
## [1.2.0]
716
### Added
817
- Create CheckboxSVGMap and RadioSVGMap components

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ ReactDOM.render(
122122
| map | object | **required** | Describe SVG map to display. See [maps section](#maps) for more details. |
123123
| className | string | `'svg-map'` | CSS class of `<svg>`. |
124124
| role | string | `'none'` | ARIA role of `<svg>`. |
125-
| locationClassName | string or function | `'svg-map__location'` | CSS class of each `<path>`. |
126-
| locationTabIndex | string or function | `'0'` | Tabindex each `<path>`. |
125+
| locationClassName | string or function | `'svg-map__location'` | CSS class of each `<path>`. The function parameters are the location object and the location index. |
126+
| locationTabIndex | string or function | `'0'` | Tabindex each `<path>`. The function parameters are the location object and the location index. |
127127
| locationRole | string | `'none'` | ARIA role of each `<path>`. |
128128
| onLocationMouseOver | function | | Invoked when the user puts the mouse over a location. |
129129
| onLocationMouseOut | function | | Invoked when the user puts the mouse out of a location. |
@@ -136,14 +136,13 @@ ReactDOM.render(
136136
| tabIndex | string | `'0'` | **DEPRECATED:** Although this property still works, it has been replaced by `locationTabIndex` and will be removed in next major version. |
137137
| type | string | `'none'` | **DEPRECATED:** Although this property still works, it has been replaced by `locationRole` and will be removed in next major version. |
138138

139-
140139
### CheckboxSVGMap
141140

142141
| Prop | Type | Default | Description |
143142
| ---- | ---- | ------- | ----------- |
144143
| map | object | **required** | Describe SVG map to display. See [maps section](#maps) for more details. |
145144
| className | string | `'svg-map'` | CSS class of `<svg>`. |
146-
| locationClassName | string | `'svg-map__location'` | CSS class of each `<path>`. |
145+
| locationClassName | string or function | `'svg-map__location'` | CSS class of each `<path>`. The function parameters are the location object and the location index. |
147146
| onChange | function | | Invoked when the user selects/deselects a location. The list of selected locations is passed as parameter. |
148147
| onLocationMouseOver | function | | Invoked when the user puts the mouse over a location. |
149148
| onLocationMouseOut | function | | Invoked when the user puts the mouse out of a location. |
@@ -157,7 +156,7 @@ ReactDOM.render(
157156
| ---- | ---- | ------- | ----------- |
158157
| map | object | **required** | Describe SVG map to display. See [maps section](#maps) for more details. |
159158
| className | string | `'svg-map'` | CSS class of `<svg>`. |
160-
| locationClassName | string | `'svg-map__location'` | CSS class of each `<path>`. |
159+
| locationClassName | string or function | `'svg-map__location'` | CSS class of each `<path>`. The function parameters are the location object and the location index. |
161160
| onChange | function | | Invoked when the user selects a location. The selected location is passed as parameter. |
162161
| onLocationMouseOver | function | | Invoked when the user puts the mouse over a location. |
163162
| onLocationMouseOut | function | | Invoked when the user puts the mouse out of a location. |
@@ -327,8 +326,8 @@ You can modify existing maps or create your own.
327326
#### Modify a map
328327

329328
1. Import the map to modify.
330-
2. Create a new object from this map.
331-
3. Pass this new object as `map` prop of `<SVGMap />` component.
329+
1. Create a new object from this map.
330+
1. Pass this new object as `map` prop of `<SVGMap />` component.
332331

333332
```javascript
334333
import React from 'react';

__tests__/__snapshots__/svg-map.test.js.snap

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2248,7 +2248,52 @@ exports[`SVGMap component Maps displays map of Utah 1`] = `
22482248
</svg>
22492249
`;
22502250

2251-
exports[`SVGMap component Properties displays heat map with custom location css 1`] = `
2251+
exports[`SVGMap component Properties displays map with custom function location props 1`] = `
2252+
<svg
2253+
aria-label="label"
2254+
className="svg-map"
2255+
role="none"
2256+
viewBox="viewBox"
2257+
xmlns="http://www.w3.org/2000/svg"
2258+
>
2259+
<path
2260+
aria-checked={undefined}
2261+
aria-label="name0"
2262+
className="locationClassName-0"
2263+
d="path0"
2264+
id="id0"
2265+
name="name0"
2266+
onBlur={undefined}
2267+
onClick={undefined}
2268+
onFocus={undefined}
2269+
onKeyDown={undefined}
2270+
onMouseMove={undefined}
2271+
onMouseOut={undefined}
2272+
onMouseOver={undefined}
2273+
role="none"
2274+
tabIndex="locationTabIndex-0"
2275+
/>
2276+
<path
2277+
aria-checked={undefined}
2278+
aria-label="name1"
2279+
className="locationClassName-1"
2280+
d="path1"
2281+
id="id1"
2282+
name="name1"
2283+
onBlur={undefined}
2284+
onClick={undefined}
2285+
onFocus={undefined}
2286+
onKeyDown={undefined}
2287+
onMouseMove={undefined}
2288+
onMouseOut={undefined}
2289+
onMouseOver={undefined}
2290+
role="none"
2291+
tabIndex="locationTabIndex-1"
2292+
/>
2293+
</svg>
2294+
`;
2295+
2296+
exports[`SVGMap component Properties displays map with custom props 1`] = `
22522297
<svg
22532298
aria-label="label"
22542299
className="className"
@@ -2258,11 +2303,11 @@ exports[`SVGMap component Properties displays heat map with custom location css
22582303
>
22592304
<path
22602305
aria-checked="isLocationSelected"
2261-
aria-label="name"
2262-
className="svg-map__location heat0"
2263-
d="path"
2264-
id="id"
2265-
name="name"
2306+
aria-label="name0"
2307+
className="locationClassName"
2308+
d="path0"
2309+
id="id0"
2310+
name="name0"
22662311
onBlur={[Function]}
22672312
onClick={[Function]}
22682313
onFocus={[Function]}
@@ -2273,24 +2318,13 @@ exports[`SVGMap component Properties displays heat map with custom location css
22732318
role="locationRole"
22742319
tabIndex="locationTabIndex"
22752320
/>
2276-
</svg>
2277-
`;
2278-
2279-
exports[`SVGMap component Properties displays map with custom props 1`] = `
2280-
<svg
2281-
aria-label="label"
2282-
className="className"
2283-
role="role"
2284-
viewBox="viewBox"
2285-
xmlns="http://www.w3.org/2000/svg"
2286-
>
22872321
<path
22882322
aria-checked="isLocationSelected"
2289-
aria-label="name"
2323+
aria-label="name1"
22902324
className="locationClassName"
2291-
d="path"
2292-
id="id"
2293-
name="name"
2325+
d="path1"
2326+
id="id1"
2327+
name="name1"
22942328
onBlur={[Function]}
22952329
onClick={[Function]}
22962330
onFocus={[Function]}
@@ -2314,11 +2348,28 @@ exports[`SVGMap component Properties displays map with default props 1`] = `
23142348
>
23152349
<path
23162350
aria-checked={undefined}
2317-
aria-label="name"
2351+
aria-label="name0"
23182352
className="svg-map__location"
2319-
d="path"
2320-
id="id"
2321-
name="name"
2353+
d="path0"
2354+
id="id0"
2355+
name="name0"
2356+
onBlur={undefined}
2357+
onClick={undefined}
2358+
onFocus={undefined}
2359+
onKeyDown={undefined}
2360+
onMouseMove={undefined}
2361+
onMouseOut={undefined}
2362+
onMouseOver={undefined}
2363+
role="none"
2364+
tabIndex="0"
2365+
/>
2366+
<path
2367+
aria-checked={undefined}
2368+
aria-label="name1"
2369+
className="svg-map__location"
2370+
d="path1"
2371+
id="id1"
2372+
name="name1"
23222373
onBlur={undefined}
23232374
onClick={undefined}
23242375
onFocus={undefined}

__tests__/checkbox-svg-map.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ describe('CheckboxSVGMap component', () => {
1111
let location = null;
1212

1313
beforeEach(() => {
14+
// TODO: Use fake map to simplify tests?
1415
wrapper = mount(<CheckboxSVGMap map={Australia} onChange={handleOnChange} />);
1516
location = wrapper.find(locationSelector);
1617
});

__tests__/radio-svg-map.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ describe('RadioSVGMap component', () => {
2121
let nextLocation = null;
2222

2323
beforeEach(() => {
24+
// TODO: Use fake map to simplify tests?
2425
wrapper = mount(<RadioSVGMap map={Australia} onChange={handleOnChange} />);
2526
location = wrapper.find(locationSelector);
2627
previousLocation = wrapper.find(previousLocationSelector);
@@ -84,7 +85,6 @@ describe('RadioSVGMap component', () => {
8485
});
8586
});
8687

87-
// TODO: Add tests for first/last location and right/left arrow
8888
describe('Keyboard navigation', () => {
8989
test('selects focused unselected location when hitting spacebar', () => {
9090
expect(location.props()['aria-checked']).toBeFalsy();

__tests__/svg-map.test.js

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,14 @@ describe('SVGMap component', () => {
88
label: 'label',
99
viewBox: 'viewBox',
1010
locations: [{
11-
name: 'name',
12-
id: 'id',
13-
path: 'path'
11+
name: 'name0',
12+
id: 'id0',
13+
path: 'path0'
14+
},
15+
{
16+
name: 'name1',
17+
id: 'id1',
18+
path: 'path1'
1419
}]
1520
};
1621

@@ -46,25 +51,13 @@ describe('SVGMap component', () => {
4651
expect(tree).toMatchSnapshot();
4752
});
4853

49-
test('displays heat map with custom location css', () => {
50-
const eventHandler = () => 'eventHandler';
51-
const isLocationSelected = () => 'isLocationSelected';
52-
const generateHeat = () => 'svg-map__location heat0';
54+
test('displays map with custom function location props', () => {
55+
const locationClassName = (location, index) => `locationClassName-${index}`;
56+
const locationTabIndex = (location, index) => `locationTabIndex-${index}`;
5357
const component = renderer.create(
5458
<SVGMap map={map}
55-
className="className"
56-
role="role"
57-
locationTabIndex="locationTabIndex"
58-
locationRole="locationRole"
59-
onLocationMouseOver={eventHandler}
60-
onLocationMouseOut={eventHandler}
61-
onLocationMouseMove={eventHandler}
62-
onLocationClick={eventHandler}
63-
onLocationKeyDown={eventHandler}
64-
onLocationFocus={eventHandler}
65-
onLocationBlur={eventHandler}
66-
isLocationSelected={isLocationSelected}
67-
locationClassName={generateHeat}
59+
locationClassName={locationClassName}
60+
locationTabIndex={locationTabIndex}
6861
/>
6962
);
7063
const tree = component.toJSON();
@@ -73,7 +66,6 @@ describe('SVGMap component', () => {
7366
});
7467
});
7568

76-
7769
describe('Maps', () => {
7870
test('displays map of Australia', () => {
7971
const component = renderer.create(<SVGMap map={Australia} />);

examples/src/components/examples-app.jsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import React from 'react';
22
import CheckboxMap from './checkbox-map';
33
import RadioMap from './radio-map';
44
import LinkMap from './link-map';
5-
import TooltipMap from './tooltip-map';
6-
import HeatMap from './heat-map';
5+
import TooltipHeatMap from './tooltip-heat-map';
76
import './examples-app.scss';
87

98
class ExamplesApp extends React.Component {
@@ -20,8 +19,7 @@ class ExamplesApp extends React.Component {
2019
<RadioMap />
2120
<CheckboxMap />
2221
<LinkMap />
23-
<TooltipMap />
24-
<HeatMap />
22+
<TooltipHeatMap />
2523
</section>
2624
);
2725
}

examples/src/components/examples-app.scss

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,27 @@
5151

5252
&--usa {
5353
width: 800px; // USA needs more space for tooltip
54-
.svg-map{
55-
&__location {
56-
&.heat1{
57-
opacity:0.8;
58-
}
59-
&.heat2{
60-
opacity:0.6;
61-
}
62-
&.heat3{
63-
opacity:0.4;
64-
}
54+
55+
.svg-map__location {
56+
&--heat0 {
57+
fill: blue;
58+
}
59+
60+
&--heat1 {
61+
fill: lightblue;
62+
}
63+
64+
&--heat2 {
65+
fill: orange;
66+
}
67+
68+
&--heat3 {
69+
fill: red;
70+
}
71+
72+
&:focus,
73+
&:hover {
74+
opacity: 0.75;
6575
}
6676
}
6777
}

0 commit comments

Comments
 (0)