dispatch/client/js/components/TabListItem.js

47 lines
933 B
JavaScript
Raw Normal View History

import React from 'react';
import classnames from 'classnames';
2015-12-28 23:34:32 +00:00
2020-06-19 02:38:26 +00:00
function splitContent(content) {
let start = 0;
while (content[start] === '#') {
start++;
}
if (start > 0) {
return [content.slice(0, start), content.slice(start)];
}
return [null, content];
}
const TabListItem = ({
target,
content,
2020-06-15 08:58:51 +00:00
network,
selected,
connected,
joined,
error,
onClick
}) => {
const className = classnames({
2020-06-15 08:58:51 +00:00
'tab-network': !target,
success: !target && connected,
error: (!target && !connected) || (!joined && error),
disabled: !!target && !error && joined === false,
selected
});
2016-01-05 18:29:22 +00:00
2020-06-19 02:38:26 +00:00
const [prefix, name] = splitContent(content);
return (
2020-06-15 08:58:51 +00:00
<p className={className} onClick={() => onClick(network, target)}>
2020-06-19 02:38:26 +00:00
<span className="tab-content">
{prefix && <span className="tab-prefix">{prefix}</span>}
{name}
</span>
</p>
);
};
2015-12-28 23:34:32 +00:00
export default TabListItem;