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
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// @flow
import React, { PureComponent } from "react";
import { connect } from "../../utils/connect";
import AccessibleImage from "./AccessibleImage";
import { getSourceClassnames, isPretty } from "../../utils/source";
import { getFramework } from "../../utils/tabs";
import { getSymbols, getTabs } from "../../selectors";
import type { Source } from "../../types";
import type { Symbols } from "../../reducers/types";
import "./SourceIcon.css";
type OwnProps = {|
source: Source,
// An additional validator for the icon returned
modifier?: string => string | null,
|};
type Props = {
source: Source,
modifier?: string => string | null,
// symbols will provide framework information
symbols: ?Symbols,
framework: ?string,
};
class SourceIcon extends PureComponent<Props> {
render() {
const { modifier, source, symbols, framework } = this.props;
let iconClass = "";
if (isPretty(source)) {
iconClass = "prettyPrint";
} else {
iconClass = framework
? framework.toLowerCase()
: getSourceClassnames(source, symbols);
}
if (modifier) {
const modified = modifier(iconClass);
if (!modified) {
return null;
}
iconClass = modified;
}
return <AccessibleImage className={`source-icon ${iconClass}`} />;
}
}
export default connect<Props, OwnProps, _, _, _, _>((state, props) => ({
symbols: getSymbols(state, props.source),
framework: getFramework(getTabs(state), props.source.url),
}))(SourceIcon);
|