import {computed} from 'mobx'; import * as React from 'react'; import {Tab} from './Tab/Tab'; import styles from './Tabs.scss'; import {observer} from 'mobx-react'; import classNames from 'classnames'; interface TabOption { label: string; value: string; } interface TabsProps { options: Array; selectedValue: string; onChange: (newSelectedValue: string) => void; className?: string; } @observer export class Tabs extends React.Component { @computed private get tabWidth() { const {options} = this.props; return options.length > 0 ? 100 / options.length : 0; } render() { const {options, selectedValue, onChange, className} = this.props; const selectedTabIndex = options.findIndex((option) => option.value === selectedValue); const tabLeftOffset = this.tabWidth * selectedTabIndex; return (
{options.map((option: TabOption) => { return onChange(option.value)} isSelected={option.value === selectedValue} key={option.value}/>; })}
); } }