Skip to content

Commit

Permalink
[ListItem] Improve props type ergonomics
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Mar 1, 2019
1 parent 026d544 commit 4d1847c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
8 changes: 2 additions & 6 deletions docs/src/pages/demos/lists/SimpleList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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, ListItemTypeMap } from '@material-ui/core/ListItem';
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';
Expand All @@ -18,11 +18,7 @@ const styles = (theme: Theme) =>
},
});

interface ListItemLinkProps {
href: string;
}

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

Expand Down
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;

0 comments on commit 4d1847c

Please sign in to comment.