UNPKG

859 BJavaScriptView Raw
1import React, { forwardRef } from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4import { mapToCssModules, tagPropType } from './utils';
5
6const propTypes = {
7 /** Add custom class */
8 className: PropTypes.string,
9 /** Change underlying component's CSS base class name */
10 cssModule: PropTypes.object,
11 /** Set a custom element for this component */
12 tag: tagPropType,
13 /** Type of list `unstyled` or `inline` */
14 type: PropTypes.string,
15};
16
17const List = forwardRef((props, ref) => {
18 const { className, cssModule, tag: Tag = 'ul', type, ...attributes } = props;
19 const classes = mapToCssModules(
20 classNames(className, type ? `list-${type}` : false),
21 cssModule,
22 );
23
24 return <Tag {...attributes} className={classes} ref={ref} />;
25});
26
27List.name = 'List';
28List.propTypes = propTypes;
29
30export default List;
31
\No newline at end of file