import React, {Component} from 'react'; import PropTypes from 'prop-types'; import { classNames } from '../utils/ClassNames'; import {Button} from '../button/Button'; export class InplaceDisplay extends Component { render() { return this.props.children; } } export class InplaceContent extends Component { render() { return this.props.children; } } export class Inplace extends Component { static defaultProps = { style: null, className: null, active: false, closable: false, disabled: false, tabIndex: '0', onOpen: null, onClose: null, onToggle: null }; static propTypes = { style: PropTypes.object, className: PropTypes.string, active: PropTypes.bool, closable: PropTypes.bool, disabled: PropTypes.bool, tabIndex: PropTypes.string, onOpen: PropTypes.func, onClose: PropTypes.func, onToggle: PropTypes.func, }; constructor(props) { super(props); if (!this.props.onToggle) { this.state = { active: false } } this.open = this.open.bind(this); this.close = this.close.bind(this); this.onDisplayKeyDown = this.onDisplayKeyDown.bind(this); } open(event) { if (this.props.disabled) { return; } if(this.props.onOpen) { this.props.onOpen(event); } if (this.props.onToggle) { this.props.onToggle({ originalEvent: event, value: true }); } else { this.setState({ active: true }); } } close(event) { if (this.props.onClose) { this.props.onClose(event); } if (this.props.onToggle) { this.props.onToggle({ originalEvent: event, value: false }); } else { this.setState({ active: false }); } } onDisplayKeyDown(event) { if (event.key === 'Enter') { this.open(event); event.preventDefault(); } } isActive() { return this.props.onToggle ? this.props.active: this.state.active; } renderDisplay(content) { const className = classNames('p-inplace-display', {'p-disabled': this.props.disabled}); return (
{content}
); } renderCloseButton() { if (this.props.closable) { return (