import * as React from 'react';
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,
GridList,
GridListTile,
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,
} from '@material-ui/core';
import {
withStyles,
StyleRulesCallback,
WithStyles,
Theme,
createStyles,
} from '@material-ui/core/styles';
import { Link as ReactRouterLink, LinkProps as ReactRouterLinkProps } from 'react-router-dom';
import { ButtonBaseActions } from '@material-ui/core/ButtonBase';
import { IconButtonProps } from '@material-ui/core/IconButton';
import ScopedCssBaseline from '@material-ui/core/ScopedCssBaseline';
import { expectType } from '@material-ui/types';
const log = console.log;
const FakeIcon = () =>
ICON
;
const TestOverride = React.forwardRef((props, ref) => (
));
const AppBarTest = () => (
Title
Login
);
const AvatarTest = () => (
{
expectType(elem);
}}
onClick={(e) => {
expectType, typeof e>(e);
log(e);
}}
alt="Image Alt"
src="example.jpg"
/>
component="button"
ref={(elem) => {
expectType(elem);
}}
onClick={(e) => {
expectType, typeof e>(e);
log(e);
}}
alt="Image Alt"
src="example.jpg"
/>
{}}
onClick={(e: React.MouseEvent) => log(e)}
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: */}
);
const AvatarClassName = () => ;
const BadgeTest = () => (
);
const BottomNavigationTest = () => {
const value = 123;
return (
log(e)} showLabels>
} />
Nearby} icon={ } />
);
};
const IconButtonTest = () => (
{() => {
const ForwardedLink = React.forwardRef(
(props, ref) => ,
);
const ExtendedIconButton: React.FC> = (props) => (
);
return (
);
}}
);
const CardTest = () => (
Word of the Day
be-nev-o-lent
adjective
well meaning and kindly.
{'"a benevolent smile"'}
Learn More
);
const CardMediaTest = () => (
R}
title="Shrimp and Chorizo Paella"
subheader="September 14, 2016"
/>
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.
);
const ChipsTest = () => (
M} label="Clickable Chip" onClick={(e) => log(e)} />
} label="Deletable Chip" onDelete={(e) => log(e)} />
}
label="Clickable Deletable Chip"
onClick={(e) => log(e)}
onDelete={(e) => log(e)}
/>
);
const DialogTest = () => {
const emails = ['username@gmail.com', 'user02@gmail.com'];
return (
log(e)} open>
Set backup account
{emails.map((email) => (
log(e)} key={email}>
))}
{
expectType(elem);
}}
onClick={(e) => {
expectType, typeof e>(e);
log(e);
}}
>
{
expectType(elem);
}}
onClick={(e) => {
expectType, typeof e>(e);
log(e);
}}
>
component="a"
ref={(elem) => {
expectType(elem);
}}
onClick={(e) => {
expectType, typeof e>(e);
log(e);
}}
button
>
Some text
);
};
const DividerTest = () => (
);
const DrawerTest = () => {
const open = {
top: false,
left: false,
bottom: false,
right: false,
};
return (
log(e)} onClick={(e) => log(e)}>
List
log(e)}
onClick={(e) => log(e)}
ModalProps={{
hideBackdrop: true,
}}
>
List
log(e)}
onClick={(e) => log(e)}
>
List
log(e)}
onClick={(e) => log(e)}
>
List
);
};
const SwipeableDrawerTest = () => {
const open = {
top: false,
left: false,
bottom: false,
right: false,
};
return (
log(e)}
onClick={(e) => log(e)}
onOpen={(e) => log(e)}
>
List
log(e)}
onClick={(e) => log(e)}
onOpen={(e) => log(e)}
ModalProps={{
hideBackdrop: true,
}}
>
List
log(e)}
onClick={(e) => log(e)}
onOpen={(e) => log(e)}
>
List
log(e)}
onClick={(e) => log(e)}
onOpen={(e) => log(e)}
>
List
);
};
const AccordionTest = () => (
log(e)} expanded disabled>
}>
...
...
Save
);
const GridTest = () => (
...
...
...
...
);
const GridListTest = () => (
log(e)}>
log(e)}>
,
);
const ListTest = () => (
{[0, 1, 2, 3].map((value) => (
log(e)}>
))}
an item
);
const 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 (
);
};
const PaperTest = () => (
This is a sheet of paper.
Paper can be used to build surface or other elements for your application.
);
const CircularProgressTest = () => (
);
const LinearProgressTest = () => (
);
const 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"
/>
);
};
const SwitchTest = () => {
const state = {
checkedA: true,
checkedB: false,
checkedE: true,
};
const handleChange = (event: React.ChangeEvent) =>
log({ [event.target.name]: event.target.checked });
return (
);
};
const SnackbarTest = () => (
log(e)}>Open simple snackbar
log(e)}
ContentProps={
{
// 'aria-describedby': 'message-id',
// ^ will work once https://github.com/DefinitelyTyped/DefinitelyTyped/pull/22582 is merged.
}
}
message={Note archived }
action={[
log(e)}>
UNDO
,
log(e)}>
,
]}
/>
);
const SnackbarContentTest = () => {
const action = (
lorem ipsum dolorem
);
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: Next ,
backButton: Back ,
};
return (
);
}
};
const TableTest = () => {
const styles = (theme: Theme) => {
const backgroundColor: string = theme.palette.secondary.light;
return createStyles({
paper: {
width: '100%',
marginTop: theme.spacing(3),
backgroundColor,
overflowX: 'auto',
},
});
};
let id = 0;
function createData(name: string, calories: number, fat: number, carbs: number, protein: number) {
id += 1;
return { id, name, calories, fat, carbs, protein };
}
const data = [
createData('Frozen yoghurt', 159, 6.0, 24, 4.0),
createData('Ice cream sandwich', 237, 9.0, 37, 4.3),
createData('Eclair', 262, 16.0, 24, 6.0),
createData('Cupcake', 305, 3.7, 67, 4.3),
createData('Gingerbread', 356, 16.0, 49, 3.9),
];
function BasicTable(props: WithStyles) {
const classes = props.classes;
return (
Dessert (100g serving)
Calories
Fat (g)
Carbs (g)
Protein (g)
{data.map((n) => {
return (
{n.name}
{n.calories}
{n.fat}
{n.carbs}
{n.protein}
);
})}
{}}
onChangeRowsPerPage={(event) => log({ rowsPerPage: event.target.value })}
/>
);
}
return withStyles(styles)(BasicTable);
};
const TabsTest = () => {
const TabContainer: React.FunctionComponent = (props) => (
{props.children}
);
type ClassKey = 'root' | 'button';
const styles: StyleRulesCallback = (theme) => ({
root: {
flexGrow: 1,
marginTop: theme.spacing(3),
backgroundColor: theme.palette.background.paper,
},
button: {
display: 'flex',
},
});
class BasicTabs extends React.Component> {
state = {
value: 0,
};
render() {
const classes = this.props.classes;
return (
this.setState({ value })}>
{this.state.value === 0 &&
{'Item One'} }
{this.state.value === 1 &&
{'Item Two'} }
{this.state.value === 2 &&
{'Item Three'} }
);
}
}
return withStyles(styles)(BasicTabs);
};
const TextFieldTest = () => (
Name} value={'Alice'} />
log({ name: event.currentTarget.value })}
/>
);
const SelectTest = () => (
} value={10} onChange={(e) => log(e.currentTarget.value)}>
None
Ten
Twenty
Thirty
);
const InputAdornmentTest = () => alert('Hello')} />;
const TooltipComponentTest = () => (
top-start
Add} placement="top-start">
top-start
);
const ClickAwayListenerComponentTest = () => (
{}}>
);
const TransitionTest = () => (
{}}>
);
const BackdropTest = () => {}} />;
const PopoverTest = () => ;
const InputLabelTest = () => (
);
const LinkTest = () => {
const dudUrl = 'javascript:;';
return (
Link
{'color="inherit"'}
{'variant="body1"'}
);
};
const refTest = () => {
// for a detailed explanation of refs in react see https://github.com/mui-org/material-ui/pull/15199
const genericRef = React.createRef();
const divRef = React.createRef();
const inputRef = React.createRef();
;
;
// 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;
}}
/>;
};
const CssBaselineTest = () => Test ;
const ScopedCssBaselineTest = () => Test ;