import * as React from 'react'; import { Link as ReactRouterLink, LinkProps as ReactRouterLinkProps } from 'react-router'; import { expectType } from '@mui/types'; import { AppBar, Avatar, Backdrop, Badge, BottomNavigation, BottomNavigationAction, Button, Card, CardActions, CardContent, CardHeader, CardMedia, Checkbox, Chip, CircularProgress, ClickAwayListener, Collapse, CssBaseline, Dialog, DialogTitle, DialogContent, DialogContentText, Divider, Drawer, Accordion, AccordionActions, AccordionDetails, AccordionSummary, Fade, FormControlLabel, FormGroup, Grid, GridLegacy, ImageList, ImageListItem, Grow, IconButton, Input, InputAdornment, InputLabel, Link, LinearProgress, List, ListItem, ListItemAvatar, ListItemIcon, ListItemSecondaryAction, ListItemText, Menu, MenuItem, MobileStepper, Paper, Popover, Select, Snackbar, SnackbarContent, SwipeableDrawer, Switch, Tab, Table, TableBody, TableCell, TableFooter, TableHead, TablePagination, TableRow, Tabs, TextField, Toolbar, Tooltip, Typography, ListItemButton, } from '@mui/material'; import { Theme } from '@mui/material/styles'; import { ButtonBaseActions } from '@mui/material/ButtonBase'; import { IconButtonProps } from '@mui/material/IconButton'; import ScopedCssBaseline from '@mui/material/ScopedCssBaseline'; const log = console.log; function FakeIcon() { return
ICON
; } const TestOverride = React.forwardRef((props, ref) => (
)); function AppBarTest() { return ( Title ); } function AvatarTest() { return (
{ expectType(elem); }} onClick={(event) => { expectType, typeof event>(event); log(event); }} alt="Image Alt" src="example.jpg" /> component="button" ref={(elem) => { expectType(elem); }} onClick={(event) => { expectType, typeof event>(event); log(event); }} alt="Image Alt" src="example.jpg" /> {}} onClick={(event: React.MouseEvent) => log(event)} alt="Image Alt" src="example.jpg" /> component={TestOverride} ref={(elem) => { expectType(elem); }} x={3} alt="Image Alt" src="example.jpg" /> {/* @ts-expect-error onClick isn't allowed since we're overriding with a component that doesn't have that prop: */}
); } function AvatarClassName() { return ; } function BadgeTest() { return ( ); } function BottomNavigationTest() { const value = 123; return ( log(event)} showLabels> } /> Nearby} icon={} /> ); } const iconButtonTest = () => (
); const iconButtonAsLinkTest = () => { const ForwardedLink = React.forwardRef((props, ref) => ( )); const ExtendedIconButton: React.FC> = function ExtendedIconButton(props) { return ; }; return ( ); }; function CardTest() { return ( Word of the Day be-nev-o-lent adjective well meaning and kindly.
a benevolent smile
); } function CardMediaTest() { return ( R
} title="Shrimp and Chorizo Paella" subheader="September 14, 2016" /> Contemplative Reptile This impressive paella is a perfect party dish and a fun meal to cook together with your guests. Add 1 cup of frozen peas along with the mussels, if you like. Method: Heat 1/2 cup of the broth in a pot until simmering, add saffron and set aside for 10 minutes. Heat oil in a (14- to 16-inch) paella pan or a large, deep skillet over medium-high heat. Add chicken, shrimp and chorizo, and cook, stirring occasionally until lightly browned, 6 to 8 minutes. Transfer shrimp to a large plate and set aside, leaving chicken and chorizo in the pan. Add pimentón, bay leaves, garlic, tomatoes, onion, salt and pepper, and cook, stirring often until thickened and fragrant, about 10 minutes. Add saffron broth and remaining 4 1/2 cups chicken broth; bring to a boil. Add rice and stir very gently to distribute. Top with artichokes and peppers, and cook without stirring, until most of the liquid is absorbed, 15 to 18 minutes. Reduce heat to medium-low, add reserved shrimp and mussels, tucking them down into the rice, and cook again without stirring, until mussels have opened and rice is just tender, 5 to 7 minutes more. (Discard any mussels that don't open.) Set aside off of the heat to let rest for 10 minutes, and then serve. ); } function ChipsTest() { return (
M} label="Clickable Chip" onClick={(event) => log(event)} /> } label="Deletable Chip" onDelete={(event) => log(event)} /> } label="Clickable Deletable Chip" onClick={(event) => log(event)} onDelete={(event) => log(event)} />
); } function DialogTest() { const emails = ['username@gmail.com', 'user02@gmail.com']; return ( log(event)} open> Set backup account
{emails.map((email) => ( log(event)} key={email}> ))} { expectType(elem); }} onClick={(event) => { expectType, typeof event>(event); log(event); }} > { expectType(elem); }} onClick={(event) => { expectType, typeof event>(event); log(event); }} > component="a" ref={(elem) => { expectType(elem); }} onClick={(event) => { expectType, typeof event>(event); log(event); }} >
Some text
); } function DividerTest() { return (
); } function DrawerTest() { const open = { top: false, left: false, bottom: false, right: false, }; return (
log(event)} onClick={(event) => log(event)} > List log(event)} onClick={(event) => log(event)} ModalProps={{ hideBackdrop: true, }} > List log(event)} onClick={(event) => log(event)} > List log(event)} onClick={(event) => log(event)} > List
); } function SwipeableDrawerTest() { const open = { top: false, left: false, bottom: false, right: false, }; return (
log(event)} onClick={(event) => log(event)} onOpen={(event) => log(event)} > List log(event)} onClick={(event) => log(event)} onOpen={(event) => log(event)} ModalProps={{ hideBackdrop: true, }} > List log(event)} onClick={(event) => log(event)} onOpen={(event) => log(event)} > List log(event)} onClick={(event) => log(event)} onOpen={(event) => log(event)} > List
); } function AccordionTest() { return (
log(event)} expanded disabled> }> ... ...
); } function GridLegacyTest() { return ( ... ... ... ... ); } function GridTest() { return ( ... ... ... ... ); } function ImageListTest() { return ( log(event)}> log(event)}> alt text , ); } function ListTest() { return ( {[0, 1, 2, 3].map((value) => ( log(event)}> ))} an item ); } function MenuTest() { const anchorEl = document.getElementById('foo')!; const options = [ 'Show all notification content', 'Hide sensitive notification content', 'Hide all notification content', ]; const buttonActionRef = React.useRef(null); return ( log(event)} PopoverClasses={{ paper: 'foo' }} > {options.map((option, index) => ( { expectType(elem); }} onClick={(event) => { expectType, typeof event>(event); log(event); }} > {option} ))} action={(action) => { buttonActionRef.current = action; }} component="a" ref={(elem) => { expectType(elem); }} onClick={(event) => { expectType, typeof event>(event); log(event); }} > Link Item { expectType(elem); }} /> { buttonActionRef.current = action; }} ref={(elem) => { // inferred from `button={false}` instead of `action` expectType(elem); }} /> ); } function CircularProgressTest() { return (
); } function LinearProgressTest() { return (
); } function SelectionControlTest() { const state = { checkedA: true, checkedB: false, checkedF: true, }; const handleChange = (event: React.ChangeEvent) => log({ [event.target.name]: event.target.checked }); return ( } label="Option A" /> } label="Option B" /> } label="Option C" /> } label="Disabled" /> } label="Disabled" /> } label="Indeterminate" /> } label="Custom color" /> ); } function SwitchTest() { const state = { checkedA: true, checkedB: false, checkedE: true, }; const handleChange = (event: React.ChangeEvent) => log({ [event.target.name]: event.target.checked }); return (
); } function SnackbarTest() { return (
log(event)} ContentProps={ { // 'aria-describedby': 'message-id', // ^ will work once https://github.com/DefinitelyTyped/DefinitelyTyped/pull/22582 is merged. } } message={Note archived} action={[ , log(event)} > , ]} />
); } function SnackbarContentTest() { const action = ( ); return (
); } const StepperTest = () => class DotsMobileStepper extends React.Component<{ classes: { root: string }; }> { state = { activeStep: 0, }; handleNext = () => { this.setState({ activeStep: this.state.activeStep + 1, }); }; handleBack = () => { this.setState({ activeStep: this.state.activeStep - 1, }); }; render() { const classes = this.props.classes; const defaultProps = { steps: 2, nextButton: , backButton: , }; return ( ); } }; function TextFieldTest() { return (
Name} value="Alice" /> log({ name: event.currentTarget.value })} />
); } function SelectTest() { return ( ); } function InputAdornmentTest() { return ( alert('Hello')}> Some Icon ); } function TooltipComponentTest() { return (
Add} placement="top-start">
); } function ClickAwayListenerComponentTest() { return ( {}}>
); } function TransitionTest() { return (
{}}>
); } function BackdropTest() { return {}} />; } function PopoverTest() { return ; } function InputLabelTest() { return ( ); } function LinkTest() { const dudUrl = 'javascript'; return ( Link inherit body1 ); } const refTest = () => { // for a detailed explanation of refs in react see https://github.com/mui/material-ui/pull/15199 const genericRef = React.createRef(); const divRef = React.createRef(); const inputRef = React.createRef(); // @ts-expect-error too generic ; ; // undesired: throws when assuming inputRef.current.value !== undefined ; // recommended: soundness is the responsibility of the dev // alternatively use React.useRef() or React.createRef() { // with runtime overhead, sound usage if (ref instanceof HTMLInputElement) { const i: number = ref.valueAsNumber; } // unsafe casts, sound usage, no runtime overhead const j: number = (ref as HTMLInputElement).valueAsNumber; // unsafe casts, unsound usage, no runtime overhead const k: number = (ref as any).valueAsNumber; // @ts-expect-error unsound usage, no runtime overhead, least syntax const n: number = ref.valueAsNumber; }} />; }; function CssBaselineTest() { return Test; } function ScopedCssBaselineTest() { return Test; }