MCPcopy Create free account
hub / github.com/SuboptimalEng/coding-tutorials / Key

Class Key

react-piano/src/components/Key.js:7–39  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5import { NOTE_TO_KEY } from '../global/constants';
6
7class Key extends React.Component {
8 noteIsFlat = (note) => {
9 return note.length > 1;
10 }
11
12 keyIsPressed = (note, pressedKeys) => {
13 return _.includes(pressedKeys, NOTE_TO_KEY[note]);
14 }
15
16 render() {
17 let keyClassName = "key";
18 const noteIsFlat = this.noteIsFlat(this.props.note);
19 const keyIsPressed = this.keyIsPressed(this.props.note, this.props.pressedKeys);
20 if (noteIsFlat) {
21 keyClassName += " flat";
22 }
23 if (keyIsPressed) {
24 keyClassName += " pressed";
25 }
26
27 let key;
28 if (noteIsFlat) {
29 key = <div className={keyClassName}></div>;
30 } else {
31 key = (
32 <div className={keyClassName}>
33 <div className="key-text">{this.props.note.toUpperCase()}</div>
34 </div>
35 );
36 }
37 return key;
38 }
39}
40
41export { Key };

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected