-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathmodeButton.tsx
55 lines (48 loc) · 1.81 KB
/
modeButton.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
import {Constants} from "../../constants";
import {Localization} from "../../localization/localization";
import {ClipMode} from "../clipMode";
import {ComponentBase} from "../componentBase";
import {AriaSetProps} from "./ariaSetProps";
export interface PropsForModeElementNoAriaGrouping {
imgSrc: string;
label: string;
myMode: ClipMode;
selected?: boolean;
tabIndex?: number;
onModeSelected: (modeButton: ClipMode) => void;
tooltipText?: string;
}
export interface PropsForModeButton extends PropsForModeElementNoAriaGrouping, AriaSetProps { }
class ModeButtonClass extends ComponentBase<{}, PropsForModeButton> {
initiallySetFocus(element: HTMLElement) {
if (this.props.selected) {
element.focus();
}
}
buttonHandler() {
this.props.onModeSelected(this.props.myMode);
}
public render() {
let className = "modeButton";
if (this.props.selected) {
className += " selected";
}
let clipMode: string = ClipMode[this.props.myMode];
clipMode = clipMode[0].toLowerCase() + clipMode.slice(1);
let idName: string = clipMode + "Button";
return (
<a className={className} role="button" aria-selected={this.props.selected}
id={idName} title={this.props.tooltipText ? this.props.tooltipText : ""}
aria-setsize={this.props["aria-setsize"]} aria-posinset={this.props["aria-posinset"]}
{...this.onElementFirstDraw(this.initiallySetFocus)}
{...this.enableAriaInvoke({callback: this.buttonHandler, tabIndex: this.props.tabIndex, ariaSetName: Constants.AriaSet.modeButtonSet})}>
<img className="icon" src={this.props.imgSrc} aria-hidden="true" />
<span className="label buttonLabelFont" style={Localization.getFontFamilyAsStyle(Localization.FontFamily.Regular)}>
{this.props.label}
</span>
</a>
);
}
}
let component = ModeButtonClass.componentize();
export {component as ModeButton};