mirror of
https://github.com/gotify/server.git
synced 2026-05-31 07:21:42 +08:00
Add ToggleVisibility Component
This commit is contained in:
committed by
Jannis Mattheis
parent
c19f5b62a0
commit
bdf4109a8f
38
ui/src/component/ToggleVisibility.js
Normal file
38
ui/src/component/ToggleVisibility.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import React, {Component} from 'react';
|
||||
import Typography from 'material-ui/Typography';
|
||||
import IconButton from 'material-ui/IconButton';
|
||||
import VisibilityOff from 'material-ui-icons/VisibilityOff';
|
||||
import Visibility from 'material-ui-icons/Visibility';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
class ToggleVisibility extends Component {
|
||||
static propTypes = {
|
||||
value: PropTypes.string.isRequired,
|
||||
style: PropTypes.object,
|
||||
};
|
||||
|
||||
constructor() {
|
||||
super();
|
||||
this.state = {visible: false};
|
||||
}
|
||||
|
||||
toggleVisibility = () => this.setState({visible: !this.state.visible});
|
||||
|
||||
render() {
|
||||
const {value, style} = this.props;
|
||||
const text = this.state.visible ? value : '•••••••••••••••';
|
||||
return (
|
||||
<div style={style}>
|
||||
<IconButton onClick={this.toggleVisibility}>
|
||||
{this.state.visible ? <VisibilityOff/> : <Visibility/>}
|
||||
</IconButton>
|
||||
<Typography style={{fontFamily: '\'Roboto Mono\', monospace'}}>
|
||||
{text}
|
||||
</Typography>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export default ToggleVisibility;
|
||||
Reference in New Issue
Block a user