Skip to content

Commit

Permalink
refactor(tabs): use react hooks (#294)
Browse files Browse the repository at this point in the history
  • Loading branch information
redgeoff authored Sep 23, 2021
1 parent 28f426c commit d1110b5
Showing 1 changed file with 26 additions and 31 deletions.
57 changes: 26 additions & 31 deletions src/tabs.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,45 @@
import React from 'react';
import attach from './attach';
import AppBar from '@material-ui/core/AppBar';
import TabsMui from '@material-ui/core/Tabs';
import Tab from '@material-ui/core/Tab';
import Icon from './icon';
import useComponent from './use-component';

class Tabs extends React.Component {
handleChange = (event, value) => {
const { component, items } = this.props;
export default function Tabs(props) {
const { component } = props;
const { items, value } = useComponent(component, ['items', 'value']);

function handleChange(event, value) {
component.set({ value });

const itemName = items[value].name;
component.emitChange(itemName);
};

render() {
const { items, value } = this.props;
}

// FUTURE: option to make this fixed under the main app bar?
return (
<AppBar
position="static"
color="default"
elevation={1} // tone down the elevation>
// FUTURE: option to make this fixed under the main app bar?
return (
<AppBar
position="static"
color="default"
elevation={1} // tone down the elevation>
>
<TabsMui
value={value}
onChange={handleChange}
indicatorColor="primary"
textColor="primary"
scrollButtons="auto"
variant="fullWidth"
>
<TabsMui
value={value}
onChange={this.handleChange}
indicatorColor="primary"
textColor="primary"
scrollButtons="auto"
variant="fullWidth"
>
{items.map((item, index) => (
{items &&
items.map((item, index) => (
<Tab
label={item.label}
icon={<Icon icon={item.icon} />}
key={index}
/>
))}
</TabsMui>
</AppBar>
);
}
</TabsMui>
</AppBar>
);
}

Tabs = attach(['items', 'value'])(Tabs);

export default Tabs;

0 comments on commit d1110b5

Please sign in to comment.