accounts-frontend/packages/app/components/profile/ProfileField.tsx

48 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

import React from 'react';
import { Link } from 'react-router-dom';
import styles from './profile.scss';
function ProfileField({
2020-05-24 04:38:24 +05:30
label,
value,
warningMessage,
link,
onChange,
}: {
2020-07-22 20:45:58 +05:30
label?: React.ReactNode;
2020-05-24 04:38:24 +05:30
link?: string;
onChange?: () => void;
value: React.ReactNode;
warningMessage?: React.ReactNode;
}) {
2020-05-24 04:38:24 +05:30
let Action: React.ElementType | null = null;
if (link) {
Action = (props) => <Link to={link} {...props} />;
}
if (onChange) {
Action = (props) => <a {...props} onClick={onChange} href="#" />;
}
return (
<div className={styles.paramItem} data-testid="profile-item">
<div className={styles.paramRow}>
2020-07-22 20:45:58 +05:30
{label ? <div className={styles.paramName}>{label}</div> : ''}
2020-05-24 04:38:24 +05:30
<div className={styles.paramValue}>{value}</div>
{Action && (
<Action to={link} className={styles.paramAction} data-testid="profile-action">
<span className={styles.paramEditIcon} />
</Action>
)}
</div>
{warningMessage && <div className={styles.paramMessage}>{warningMessage}</div>}
</div>
);
}
export default ProfileField;