2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component, Children, cloneElement } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2016-09-07 03:10:18 +08:00
|
|
|
import cx from 'classnames';
|
2018-01-08 14:17:18 +08:00
|
|
|
import { styles } from '../styles';
|
2016-08-25 22:34:27 +08:00
|
|
|
|
2016-09-07 03:10:18 +08:00
|
|
|
const PLACEMENTS = [
|
|
|
|
'top left', 'top', 'top right',
|
|
|
|
'right top', 'right', 'right bottom',
|
|
|
|
'bottom right', 'bottom', 'bottom left',
|
|
|
|
'left bottom', 'left', 'left top',
|
|
|
|
];
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
/**
|
|
|
|
* Placements of the dropdown and its caret
|
|
|
|
* @defaultValue 'top'
|
|
|
|
*/
|
|
|
|
placement: PropTypes.oneOf(PLACEMENTS),
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
placement: 'top',
|
|
|
|
'aria-expanded': false,
|
|
|
|
};
|
|
|
|
|
2016-08-25 22:34:27 +08:00
|
|
|
export default class DropdownContent extends Component {
|
|
|
|
render() {
|
2017-11-04 15:38:44 +08:00
|
|
|
const {
|
2020-03-31 03:41:36 +08:00
|
|
|
placement,
|
|
|
|
children,
|
|
|
|
className,
|
|
|
|
dropdownToggle,
|
|
|
|
dropdownShow,
|
|
|
|
dropdownHide,
|
|
|
|
dropdownIsOpen,
|
|
|
|
keepOpen,
|
2018-04-16 22:06:29 +08:00
|
|
|
...restProps
|
2017-11-04 15:38:44 +08:00
|
|
|
} = this.props;
|
2016-09-07 03:10:18 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const placementName = placement.split(' ').join('-');
|
2016-09-07 03:10:18 +08:00
|
|
|
|
|
|
|
const boundChildren = Children.map(children, child => cloneElement(child, {
|
2018-04-16 22:06:29 +08:00
|
|
|
dropdownIsOpen,
|
2017-06-03 03:25:02 +08:00
|
|
|
dropdownToggle,
|
|
|
|
dropdownShow,
|
|
|
|
dropdownHide,
|
2020-03-31 03:41:36 +08:00
|
|
|
keepOpen,
|
2016-09-07 03:10:18 +08:00
|
|
|
}));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2017-11-04 15:38:44 +08:00
|
|
|
data-test="dropdownContent"
|
2017-06-03 03:25:02 +08:00
|
|
|
className={cx(styles.content, styles[placementName], className)}
|
2018-04-16 22:06:29 +08:00
|
|
|
{...restProps}
|
2017-06-03 03:25:02 +08:00
|
|
|
>
|
2017-03-16 22:34:03 +08:00
|
|
|
<div className={styles.scrollable}>
|
|
|
|
{boundChildren}
|
|
|
|
</div>
|
2016-09-07 03:10:18 +08:00
|
|
|
</div>
|
|
|
|
);
|
2016-08-25 22:34:27 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 03:10:18 +08:00
|
|
|
|
|
|
|
DropdownContent.propTypes = propTypes;
|
|
|
|
DropdownContent.defaultProps = defaultProps;
|