2016-09-07 03:10:18 +08:00
|
|
|
import React, { Component, PropTypes, Children, cloneElement } from 'react';
|
|
|
|
import cx from 'classnames';
|
2016-08-25 22:34:27 +08:00
|
|
|
import styles from '../styles';
|
|
|
|
|
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() {
|
2016-09-15 01:48:50 +08:00
|
|
|
const { placement, className, children, style } = this.props;
|
2016-09-07 03:10:18 +08:00
|
|
|
const { dropdownToggle, dropdownShow, dropdownHide } = this.props;
|
|
|
|
|
|
|
|
let placementName = placement.split(' ').join('-');
|
|
|
|
|
|
|
|
const boundChildren = Children.map(children, child => cloneElement(child, {
|
|
|
|
dropdownToggle: dropdownToggle,
|
|
|
|
dropdownShow: dropdownShow,
|
|
|
|
dropdownHide: dropdownHide,
|
|
|
|
}));
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2016-09-15 01:48:50 +08:00
|
|
|
style={style}
|
2016-09-07 03:10:18 +08:00
|
|
|
aria-expanded={this.props['aria-expanded']}
|
|
|
|
className={cx(styles.content, styles[placementName], className)}>
|
|
|
|
{boundChildren}
|
|
|
|
</div>
|
|
|
|
);
|
2016-08-25 22:34:27 +08:00
|
|
|
}
|
|
|
|
}
|
2016-09-07 03:10:18 +08:00
|
|
|
|
|
|
|
DropdownContent.propTypes = propTypes;
|
|
|
|
DropdownContent.defaultProps = defaultProps;
|