accounts-frontend/src/components/profile/ProfileField.js

52 lines
1.6 KiB
JavaScript
Raw Normal View History

import React, { Component, PropTypes } from 'react';
import { Link } from 'react-router-dom';
import styles from './profile.scss';
export default class ProfileField extends Component {
static displayName = 'ProfileField';
static propTypes = {
2016-03-20 14:00:58 +05:30
label: React.PropTypes.oneOfType([PropTypes.string, PropTypes.element]).isRequired,
link: PropTypes.string,
2016-05-20 01:11:43 +05:30
onChange: PropTypes.func,
value: React.PropTypes.oneOfType([PropTypes.string, PropTypes.element]).isRequired,
2016-05-20 01:11:43 +05:30
warningMessage: React.PropTypes.oneOfType([PropTypes.string, PropTypes.element])
};
render() {
2016-05-20 01:11:43 +05:30
const {label, value, warningMessage, link, onChange} = this.props;
let Action = null;
if (link) {
Action = (props) => <Link to={link} {...props} />;
}
if (onChange) {
Action = (props) => <a onClick={onChange} {...props} href="#" />;
}
return (
<div className={styles.paramItem}>
<div className={styles.paramRow}>
<div className={styles.paramName}>{label}:</div>
<div className={styles.paramValue}>{value}</div>
2016-05-20 01:11:43 +05:30
{Action ? (
<Action to={link} className={styles.paramAction}>
<span className={styles.paramEditIcon} />
</Action>
) : null}
</div>
{warningMessage ? (
<div className={styles.paramMessage}>
{warningMessage}
</div>
) : ''}
</div>
);
}
}