Skip to content

Commit

Permalink
[docs] Add simple list typescript demo (#14485)
Browse files Browse the repository at this point in the history
Testing #11731
  • Loading branch information
eps1lon authored Mar 2, 2019
1 parent 23549d4 commit ecc2c85
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 3 deletions.
62 changes: 62 additions & 0 deletions docs/src/pages/demos/lists/SimpleList.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import React from 'react';
import PropTypes from 'prop-types';
import { createStyles, Theme, withStyles, WithStyles } from '@material-ui/core/styles';
import List from '@material-ui/core/List';
import ListItem, { ListItemProps } from '@material-ui/core/ListItem';
import ListItemIcon from '@material-ui/core/ListItemIcon';
import ListItemText from '@material-ui/core/ListItemText';
import Divider from '@material-ui/core/Divider';
import InboxIcon from '@material-ui/icons/Inbox';
import DraftsIcon from '@material-ui/icons/Drafts';

const styles = (theme: Theme) =>
createStyles({
root: {
width: '100%',
maxWidth: 360,
backgroundColor: theme.palette.background.paper,
},
});

function ListItemLink(props: ListItemProps<'a', { button?: true }>) {
return <ListItem button component="a" {...props} />;
}

export interface SimpleListProps extends WithStyles<typeof styles> {}

function SimpleList(props: SimpleListProps) {
const { classes } = props;
return (
<div className={classes.root}>
<List component="nav">
<ListItem button>
<ListItemIcon>
<InboxIcon />
</ListItemIcon>
<ListItemText primary="Inbox" />
</ListItem>
<ListItem button>
<ListItemIcon>
<DraftsIcon />
</ListItemIcon>
<ListItemText primary="Drafts" />
</ListItem>
</List>
<Divider />
<List component="nav">
<ListItem button>
<ListItemText primary="Trash" />
</ListItem>
<ListItemLink href="#simple-list">
<ListItemText primary="Spam" />
</ListItemLink>
</List>
</div>
);
}

SimpleList.propTypes = {
classes: PropTypes.object.isRequired,
} as any;

export default withStyles(styles)(SimpleList);
7 changes: 5 additions & 2 deletions packages/material-ui/src/ListItem/ListItem.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react';
import { StandardProps } from '..';
import ButtonBase, { ButtonBaseProps } from '../ButtonBase';
import { OverridableComponent, SimplifiedPropsOf, OverrideProps } from '../OverridableComponent';
import { OverridableComponent, OverrideProps } from '../OverridableComponent';

export interface ListItemTypeMap<P, D extends React.ReactType> {
props: P & {
Expand Down Expand Up @@ -36,6 +36,9 @@ export type ListItemClassKey =
| 'secondaryAction'
| 'selected';

export type ListItemProps = SimplifiedPropsOf<typeof ListItem>;
export type ListItemProps<D extends React.ReactType = 'li', P = {}> = OverrideProps<
ListItemTypeMap<P, D>,
D
>;

export default ListItem;
6 changes: 5 additions & 1 deletion pages/demos/lists.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import React from 'react';
import MarkdownDocs from 'docs/src/modules/components/MarkdownDocs';

const req = require.context('docs/src/pages/demos/lists', false, /\.md|\.js$/);
const reqSource = require.context('!raw-loader!../../docs/src/pages/demos/lists', false, /\.js$/);
const reqSource = require.context(
'!raw-loader!../../docs/src/pages/demos/lists',
false,
/\.(js|tsx)$/,
);
const reqPrefix = 'pages/demos/lists';

function Page() {
Expand Down

0 comments on commit ecc2c85

Please sign in to comment.