import React, { Component } from 'react'; import PropTypes from 'prop-types'; import cx from 'classnames'; import Button from '../button'; import Icon from '../icon'; import zhCN from '../locale/zh-cn'; import { func, obj, guid } from '../util'; const { makeChain } = func; const { pickOthers } = obj; const noop = () => {}; export default class Inner extends Component { static propTypes = { prefix: PropTypes.string, className: PropTypes.string, title: PropTypes.node, children: PropTypes.node, footer: PropTypes.oneOfType([PropTypes.bool, PropTypes.node]), footerAlign: PropTypes.oneOf(['left', 'center', 'right']), footerActions: PropTypes.array, onOk: PropTypes.func, onCancel: PropTypes.func, okProps: PropTypes.object, cancelProps: PropTypes.object, closeable: PropTypes.bool, onClose: PropTypes.func, locale: PropTypes.object, role: PropTypes.string, rtl: PropTypes.bool, // set value for a fixed height dialog. Passing a value will absolutely position the footer to the bottom. height: PropTypes.string, }; static defaultProps = { prefix: 'next-', footerAlign: 'right', footerActions: ['ok', 'cancel'], onOk: noop, onCancel: noop, okProps: {}, cancelProps: {}, closeable: true, onClose: noop, locale: zhCN.Dialog, role: 'dialog', }; getNode(name, ref) { this[name] = ref; } renderHeader() { const { prefix, title } = this.props; if (title) { this.titleId = guid('dialog-title-'); return (
{title}
); } return null; } renderBody() { const { prefix, children } = this.props; if (children) { return (
{children}
); } return null; } renderFooter() { const { prefix, footer, footerAlign, footerActions, locale, height, } = this.props; if (footer === false) { return null; } const newClassName = cx({ [`${prefix}dialog-footer`]: true, [`${prefix}align-${footerAlign}`]: true, [`${prefix}dialog-footer-fixed-height`]: !!height, }); const footerContent = footer === true || !footer ? footerActions.map(action => { const btnProps = this.props[`${action}Props`]; const newBtnProps = { ...btnProps, prefix, className: cx( `${prefix}dialog-btn`, btnProps.className, ), onClick: makeChain( this.props[ `on${action[0].toUpperCase() + action.slice(1)}` ], btnProps.onClick, ), children: btnProps.children || locale[action], }; if (action === 'ok') { newBtnProps.type = 'primary'; } return