make the leftpane header a bit more generic to handle tabs
parent
7e02536e27
commit
04227e7fb7
@ -0,0 +1,96 @@
|
||||
import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { SessionButton } from './SessionButton';
|
||||
|
||||
const Tab = ({
|
||||
isSelected,
|
||||
label,
|
||||
onSelect,
|
||||
type,
|
||||
}: {
|
||||
isSelected: boolean;
|
||||
label: string;
|
||||
onSelect?: (event: number) => void;
|
||||
type: number;
|
||||
}) => {
|
||||
const handleClick = onSelect
|
||||
? () => {
|
||||
onSelect(type);
|
||||
}
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<h1
|
||||
className={classNames(
|
||||
'module-left-pane__title',
|
||||
isSelected ? 'active' : null
|
||||
)}
|
||||
onClick={handleClick}
|
||||
role="button"
|
||||
>
|
||||
{label}
|
||||
</h1>
|
||||
);
|
||||
};
|
||||
|
||||
interface Props {
|
||||
onTabSelected: any;
|
||||
selectedTab: number;
|
||||
labels: Array<string>;
|
||||
notificationCount?: number;
|
||||
buttonLabel?: string;
|
||||
buttonClicked?: any;
|
||||
}
|
||||
|
||||
interface State {
|
||||
selectedTab: number;
|
||||
}
|
||||
|
||||
export class LeftPaneSectionHeader extends React.Component<Props, State> {
|
||||
constructor(props: any) {
|
||||
super(props);
|
||||
this.state = { selectedTab: 0 };
|
||||
}
|
||||
|
||||
public render() {
|
||||
return this.renderTabs();
|
||||
}
|
||||
|
||||
private renderTabs() {
|
||||
const { selectedTab } = this.state;
|
||||
const { labels, buttonLabel, buttonClicked } = this.props;
|
||||
|
||||
const children = [];
|
||||
//loop to create children
|
||||
for (let i = 0; i < labels.length; i++) {
|
||||
children.push(
|
||||
<Tab
|
||||
label={labels[i]}
|
||||
type={i}
|
||||
isSelected={selectedTab === i}
|
||||
onSelect={this.handleTabSelect}
|
||||
key={i}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
if (buttonLabel) {
|
||||
children.push(
|
||||
<SessionButton
|
||||
text={window.i18n('compose')}
|
||||
onClick={buttonClicked}
|
||||
key={window.i18n('compose')}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
//Create the parent and add the children
|
||||
return <div className="module-left-pane__header">{children}</div>;
|
||||
}
|
||||
|
||||
private readonly handleTabSelect = (tabType: number): void => {
|
||||
this.setState({
|
||||
selectedTab: tabType,
|
||||
});
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue