forked from dnnsoftware/Dnn.Platform
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.jsx
More file actions
71 lines (64 loc) · 1.78 KB
/
Copy pathindex.jsx
File metadata and controls
71 lines (64 loc) · 1.78 KB
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
69
70
71
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";
const getStyle = (url) => ({
position: "relative",
display: "inline-flex",
alignItems: "center",
justifyContent: "center",
width: "27px",
height: "18px",
marginRight: "5px",
backgroundColor: "transparent",
backgroundImage: url ? `url(${url})` : "none",
backgroundRepeat: "no-repeat",
backgroundPosition: "center",
backgroundSize: "contain",
color: "#FFF",
fontWeight: "bold",
textTransform: "uppercase",
});
const overlayStyle = {
position: "absolute",
left: 0,
top: 0,
width: "100%",
height: "100%",
display: "flex",
alignItems: "center",
justifyContent: "center",
fontSize: "8px",
fontWeight: "900",
color: "#000",
textTransform: "uppercase",
whiteSpace: "nowrap",
transform: "scale(0.9, 1.1)",
};
function Flag({ culture = "", onClick, title }) {
const [flagUrl, setFlagUrl] = useState(undefined);
const [isFallback, setIsFallback] = useState(false);
useEffect(() => {
try {
setFlagUrl(require(`./img/flags/${culture}.png`).default);
setIsFallback(false);
} catch {
try {
setFlagUrl(require("./img/flags/none.png").default);
setIsFallback(true);
} catch {
setFlagUrl(undefined);
setIsFallback(true);
}
}
}, [culture]);
return (
<div onClick={onClick} title={title} style={getStyle(flagUrl)}>
{isFallback && culture ? <div style={overlayStyle}>{culture}</div> : null}
</div>
);
}
Flag.propTypes = {
culture: PropTypes.string,
onClick: PropTypes.func,
title: PropTypes.string,
};
export default Flag;