badguardhome/client/src/components/ui/Tab.js

38 lines
907 B
JavaScript
Raw Normal View History

import React from 'react';
2019-01-18 17:17:48 +00:00
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { useTranslation } from 'react-i18next';
2019-01-18 17:17:48 +00:00
const Tab = ({
activeTabLabel, label, title, onClick,
}) => {
const [t] = useTranslation();
const handleClick = () => onClick(label);
2019-01-18 17:17:48 +00:00
const tabClass = classnames({
tab__control: true,
'tab__control--active': activeTabLabel === label,
});
2019-01-18 17:17:48 +00:00
return (
<div
className={tabClass}
onClick={handleClick}
>
<svg className="tab__icon">
<use xlinkHref={`#${label.toLowerCase()}`} />
</svg>
{t(title || label)}
</div>
);
};
2019-01-18 17:17:48 +00:00
Tab.propTypes = {
activeTabLabel: PropTypes.string.isRequired,
2019-01-18 17:17:48 +00:00
label: PropTypes.string.isRequired,
onClick: PropTypes.func.isRequired,
title: PropTypes.string,
2019-01-18 17:17:48 +00:00
};
export default Tab;