我正在为 Material UI 选项卡实现一个 React 类。我基本上从 material ui 网站中获取了选项卡的示例,并将其转换为类兼容格式。他们网站上的例子如下:import React from 'react';import PropTypes from 'prop-types';import { makeStyles } from '@material-ui/core/styles';import AppBar from '@material-ui/core/AppBar';import Tabs from '@material-ui/core/Tabs';import Tab from '@material-ui/core/Tab';import Typography from '@material-ui/core/Typography';function TabContainer(props) { return ( <Typography component="div" style={{ padding: 8 * 3 }}> {props.children} </Typography> );}TabContainer.propTypes = { children: PropTypes.node.isRequired,};const useStyles = makeStyles(theme => ({ root: { flexGrow: 1, backgroundColor: theme.palette.background.paper, },}));export default function SimpleTabs() { const classes = useStyles(); const [value, setValue] = React.useState(0); function handleChange(event, newValue) { setValue(newValue); } return ( <div className={classes.root}> <AppBar position="static"> <Tabs value={value} onChange={handleChange}> <Tab label="Item One" /> <Tab label="Item Two" /> <Tab label="Item Three" /> </Tabs> </AppBar> {value === 0 && <TabContainer>Item One</TabContainer>} {value === 1 && <TabContainer>Item Two</TabContainer>} {value === 2 && <TabContainer>Item Three</TabContainer>} </div> );}
添加回答
举报
0/150
提交
取消