@talend/react-containers
Version:
Provide connected components aka containers for @talend/react-cmf based on @talend/react-components.
103 lines • 3.47 kB
JavaScript
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { Component as RComponent } from 'react';
import PropTypes from 'prop-types';
import Immutable from 'immutable';
import { cmfConnect } from '@talend/react-cmf';
import { omit } from "lodash";
import { EditableText as Component } from "@talend/react-components";
import { jsx as _jsx } from "react/jsx-runtime";
export const DISPLAY_NAME = 'Container(EditableText)';
export const DEFAULT_STATE = new Immutable.Map({
editMode: false
});
class EditableText extends RComponent {
constructor(props) {
super(props);
this.onCancel = this.onCancel.bind(this);
this.onEdit = this.onEdit.bind(this);
this.onSubmit = this.onSubmit.bind(this);
this.onChange = this.onChange.bind(this);
}
onSubmit(event, data) {
this.props.setState({
editMode: false
});
if (this.props.onSubmit) {
this.props.onSubmit(event, data);
}
if (this.props.actionCreatorSubmit) {
this.props.dispatchActionCreator(this.props.actionCreatorSubmit, event, {
props: this.props,
data
});
}
}
onCancel(event) {
this.props.setState({
editMode: false
});
if (this.props.onCancel) {
this.props.onCancel(event);
}
if (this.props.actionCreatorCancel) {
this.props.dispatchActionCreator(this.props.actionCreatorCancel, event, {
props: this.props
});
}
}
onEdit(event) {
this.props.setState({
editMode: true
});
if (this.props.onEdit) {
this.props.onEdit(event);
}
if (this.props.actionCreatorEdit) {
this.props.dispatchActionCreator(this.props.actionCreatorEdit, event, {
props: this.props
});
}
}
onChange(event) {
if (this.props.onChange) {
this.props.onChange(event, event.target.value);
}
if (this.props.actionCreatorChange) {
this.props.dispatchActionCreator(this.props.actionCreatorChange, event, {
props: this.props,
value: event.target.value
});
}
}
render() {
const state = this.props.state || DEFAULT_STATE;
const props = {
...omit(this.props, cmfConnect.INJECTED_PROPS),
onEdit: this.onEdit,
onCancel: this.onCancel,
onSubmit: this.onSubmit,
onChange: this.onChange,
...state.toJS()
};
return /*#__PURE__*/_jsx(Component, {
...props
});
}
}
_defineProperty(EditableText, "displayName", DISPLAY_NAME);
_defineProperty(EditableText, "propTypes", {
...cmfConnect.propTypes,
actionCreatorCancel: PropTypes.string,
actionCreatorEdit: PropTypes.string,
actionCreatorSubmit: PropTypes.string,
actionCreatorChange: PropTypes.string,
onCancel: PropTypes.func,
onEdit: PropTypes.func,
onSubmit: PropTypes.func,
onChange: PropTypes.func,
text: PropTypes.string.isRequired
});
export default EditableText;
//# sourceMappingURL=EditableText.container.js.map