UNPKG

1.21 kBTypeScriptView Raw
1import * as React from 'react';
2import * as PropTypes from 'prop-types';
3import { ListProps as ReakitListProps } from 'reakit/ts';
4
5import _List from './styled';
6import ListItem, { ListItemProps } from './ListItem';
7
8export type LocalListProps = {
9 children: React.ReactNode;
10 className?: string;
11 isOrdered?: boolean;
12 isHorizontal?: boolean;
13};
14export type ListProps = LocalListProps & ReakitListProps;
15export type ListComponents = {
16 Item: React.FunctionComponent<ListItemProps>;
17};
18
19export const List: React.FunctionComponent<LocalListProps> & ListComponents = ({
20 children,
21 className,
22 isOrdered,
23 ...props
24}) => (
25 <_List use={isOrdered ? 'ol' : undefined} className={className} isOrdered={isOrdered} {...props}>
26 {children}
27 </_List>
28);
29
30List.Item = ListItem;
31
32export const listPropTypes = {
33 children: PropTypes.node.isRequired,
34 className: PropTypes.string,
35 isOrdered: PropTypes.bool,
36 isHorizontal: PropTypes.bool
37};
38List.propTypes = listPropTypes;
39
40export const listDefaultProps = {
41 className: undefined,
42 isOrdered: false,
43 isHorizontal: false
44};
45List.defaultProps = listDefaultProps;
46
47const C: React.FunctionComponent<ListProps> & ListComponents = List;
48export default C;