-
Notifications
You must be signed in to change notification settings - Fork 286
/
svgList.tsx
68 lines (62 loc) · 2.61 KB
/
svgList.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
'use strict';
import * as React from 'react';
import { SvgLoader } from 'react-svgmt';
import { getLocString } from '../react-common/locReactSide';
import './svgList.css';
interface ISvgListProps {
images: string[];
currentImage: number;
themeMatplotlibBackground: boolean;
imageClicked(index: number): void;
}
export class SvgList extends React.Component<ISvgListProps> {
public override render() {
return (
<div className="svg-list-container">
<div className="svg-list">{this.renderImages()}</div>
</div>
);
}
private renderImages() {
return this.props.images.map((image, index) => {
const className = `svg-list-item${this.props.currentImage === index ? ' svg-list-item-selected' : ''}${
this.props.themeMatplotlibBackground ? '' : ' svg-list-white-background'
}`;
const ariaLabel =
index === this.props.currentImage
? getLocString('DataScience.selectedImageListLabel', 'Selected Image')
: getLocString('DataScience.selectedImageLabel', 'Image');
const ariaPressed = index === this.props.currentImage ? 'true' : 'false';
const clickHandler = () => this.props.imageClicked(index);
const keyDownHandler = (e: React.KeyboardEvent<HTMLDivElement>) => this.onKeyDown(e, index);
return (
<div
className={className}
tabIndex={0}
role="button"
aria-label={ariaLabel}
aria-pressed={ariaPressed}
// See the comments here: https://github.com/Microsoft/tslint-microsoft-contrib/issues/676
// eslint-disable-next-line
onClick={clickHandler}
// See the comments here: https://github.com/Microsoft/tslint-microsoft-contrib/issues/676
// eslint-disable-next-line
onKeyDown={keyDownHandler}
key={index}
>
<div className="svg-list-item-image">
<SvgLoader svgXML={image}></SvgLoader>
</div>
</div>
);
});
}
private onKeyDown = (event: React.KeyboardEvent<HTMLDivElement>, index: number) => {
// Enter and Space commit an action the same as a click does
if (event.key === 'Enter' || event.key === ' ') {
this.props.imageClicked(index);
}
};
}