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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
import React from 'react';
import PropTypes from 'prop-types';
import SyntaxHighlighter, { registerLanguage } from 'react-syntax-highlighter/prism-light';
import jsx from 'react-syntax-highlighter/languages/prism/jsx';
import themeSource from 'react-syntax-highlighter/styles/prism/prism';
import { withStyles } from '@material-ui/core/styles';
import {
Typography,
Button,
Icon,
Divider,
Dialog,
DialogActions,
DialogContent,
DialogTitle,
Slide,
} from '@material-ui/core';
const Transition = React.forwardRef(function Transition(props, ref) { // eslint-disable-line
return <Slide direction="up" ref={ref} {...props} />;
});
const humanize = (str, space) => {
let string = str;
if (str === '3d_rotation') {
string = 'three_d_rotation';
}
const frags = string.split('_');
for (let i = 0; i < frags.length; i += 1) {
frags[i] = frags[i].charAt(0).toUpperCase() + frags[i].slice(1);
}
if (space) {
return frags.join(' ');
}
return frags.join('');
};
const styles = theme => ({
code: {
fontSize: 12,
padding: '5px !important'
},
divider: {
display: 'block',
margin: `${theme.spacing(3)}px 0`,
},
bigIcon: {
textAlign: 'center',
marginBottom: 30,
'& span': {
fontSize: 128
}
},
title: {
marginBottom: 40,
fontSize: 22,
paddingBottom: 20,
position: 'relative',
fontWeight: 500,
color: theme.palette.grey[700],
textTransform: 'uppercase',
'&:after': {
content: '""',
display: 'block',
position: 'absolute',
bottom: 0,
left: 24,
width: 40,
borderBottom: `5px solid ${theme.palette.primary.main}`
}
},
});
class DetailIcon extends React.Component {
render() {
registerLanguage('jsx', jsx);
const {
isOpenDetail,
iconName,
iconCode,
closeDetail
} = this.props;
const { classes } = this.props;
const linkCode = '<link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" />';
const fontCode = '<Icon>' + iconName + '</Icon>';
const importCode = 'import ' + humanize(iconName, false) + " from '@material-ui/icons/" + humanize(iconName, false) + "';";
const importIconCode = "import Icon from '@material-ui/core/Icon';";
const svgCode = '<' + humanize(iconName, false) + ' />';
return (
<Dialog
open={isOpenDetail}
TransitionComponent={Transition}
keepMounted
maxWidth="md"
onClose={closeDetail}
aria-labelledby="alert-dialog-slide-title"
aria-describedby="alert-dialog-slide-description"
>
<DialogTitle id="alert-dialog-slide-title" className={classes.title}>
{humanize(iconName, true)}
{' '}
(
{iconCode}
)
</DialogTitle>
<DialogContent>
<div className={classes.bigIcon}>
<Icon className={classes.icon}>{iconName}</Icon>
</div>
<Typography variant="subtitle1" gutterBottom>Use with Font Icons</Typography>
<SyntaxHighlighter className={classes.code} language="jsx" style={themeSource}>
{linkCode}
</SyntaxHighlighter>
<SyntaxHighlighter className={classes.code} language="jsx" style={themeSource}>
{importIconCode}
</SyntaxHighlighter>
<SyntaxHighlighter className={classes.code} language="jsx" style={themeSource}>
{fontCode}
</SyntaxHighlighter>
<Divider className={classes.divider} />
<Typography variant="subtitle1" gutterBottom>Use with SVG Material icons</Typography>
<SyntaxHighlighter className={classes.code} language="jsx" style={themeSource}>
{importCode}
</SyntaxHighlighter>
<SyntaxHighlighter className={classes.code} language="jsx" style={themeSource}>
{svgCode}
</SyntaxHighlighter>
</DialogContent>
<DialogActions>
<Button onClick={closeDetail} color="primary">
Close
</Button>
</DialogActions>
</Dialog>
);
}
}
DetailIcon.propTypes = {
classes: PropTypes.object.isRequired,
isOpenDetail: PropTypes.bool.isRequired,
closeDetail: PropTypes.func.isRequired,
iconName: PropTypes.string.isRequired,
iconCode: PropTypes.string.isRequired,
};
export default withStyles(styles)(DetailIcon);
|