@elastic/eui
Version:
Elastic UI Component Library
396 lines (393 loc) • 30.8 kB
JavaScript
"use strict";
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SMALL_SIZE_FORM = exports.MEDIUM_SIZE_FORM = exports.EuiInlineEditForm = void 0;
var _react = _interopRequireWildcard(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _classnames = _interopRequireDefault(require("classnames"));
var _form = require("../form");
var _form2 = require("../form/form.styles");
var _button = require("../button");
var _flex = require("../flex");
var _skeleton = require("../skeleton");
var _services = require("../../services");
var _i18n = require("../i18n");
var _accessibility = require("../../services/accessibility");
var _inline_edit_form = require("./inline_edit_form.styles");
var _react2 = require("@emotion/react");
var _excluded = ["className", "children", "sizes", "defaultValue", "value", "onChange", "onCancel", "placeholder", "inputAriaLabel", "startWithEditOpen", "readModeProps", "editModeProps", "isLoading", "isInvalid", "onSave", "isReadOnly"];
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
// Props shared between the internal form component as well as consumer-facing components
// Internal-only props, passed by the consumer-facing components
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], t.indexOf(o) >= 0 || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.indexOf(n) >= 0) continue; t[n] = r[n]; } return t; }
var SMALL_SIZE_FORM = exports.SMALL_SIZE_FORM = {
iconSize: 's',
compressed: true,
buttonSize: 's'
};
var MEDIUM_SIZE_FORM = exports.MEDIUM_SIZE_FORM = {
iconSize: 'm',
compressed: false,
buttonSize: 'm'
};
var EuiInlineEditForm = exports.EuiInlineEditForm = function EuiInlineEditForm(_ref) {
var _editModeProps$inputP, _editModeProps$formRo, _editModeProps$inputP6;
var className = _ref.className,
children = _ref.children,
sizes = _ref.sizes,
_ref$defaultValue = _ref.defaultValue,
defaultValue = _ref$defaultValue === void 0 ? '' : _ref$defaultValue,
_ref$value = _ref.value,
controlledValue = _ref$value === void 0 ? '' : _ref$value,
_onChange = _ref.onChange,
onCancel = _ref.onCancel,
_ref$placeholder = _ref.placeholder,
placeholder = _ref$placeholder === void 0 ? '' : _ref$placeholder,
inputAriaLabel = _ref.inputAriaLabel,
startWithEditOpen = _ref.startWithEditOpen,
readModeProps = _ref.readModeProps,
editModeProps = _ref.editModeProps,
_ref$isLoading = _ref.isLoading,
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
isInvalid = _ref.isInvalid,
onSave = _ref.onSave,
isReadOnly = _ref.isReadOnly,
rest = _objectWithoutProperties(_ref, _excluded);
var classes = (0, _classnames.default)('euiInlineEdit', className);
var _useEuiMemoizedStyles = (0, _services.useEuiMemoizedStyles)(_form2.euiFormVariables),
controlHeight = _useEuiMemoizedStyles.controlHeight,
controlCompressedHeight = _useEuiMemoizedStyles.controlCompressedHeight;
var loadingSkeletonSize = sizes.compressed ? controlCompressedHeight : controlHeight;
var defaultSaveButtonAriaLabel = (0, _i18n.useEuiI18n)('euiInlineEditForm.saveButtonAriaLabel', 'Save edit');
var defaultCancelButtonAriaLabel = (0, _i18n.useEuiI18n)('euiInlineEditForm.cancelButtonAriaLabel', 'Cancel edit');
var readModeDescribedById = (0, _accessibility.useGeneratedHtmlId)({
prefix: 'inlineEdit'
});
var editModeDescribedById = (0, _accessibility.useGeneratedHtmlId)({
prefix: 'inlineEdit'
});
var readModeFocusRef = (0, _react.useRef)(null);
var editModeFocusRef = (0, _react.useRef)(null);
var setReadModeRefs = (0, _services.useCombinedRefs)([readModeFocusRef, readModeProps === null || readModeProps === void 0 ? void 0 : readModeProps.buttonRef]);
var setEditModeRefs = (0, _services.useCombinedRefs)([editModeFocusRef, editModeProps === null || editModeProps === void 0 || (_editModeProps$inputP = editModeProps.inputProps) === null || _editModeProps$inputP === void 0 ? void 0 : _editModeProps$inputP.inputRef]);
var _useState = (0, _react.useState)(false || startWithEditOpen),
_useState2 = _slicedToArray(_useState, 2),
isEditing = _useState2[0],
setIsEditing = _useState2[1];
var _useState3 = (0, _react.useState)(defaultValue),
_useState4 = _slicedToArray(_useState3, 2),
editModeValue = _useState4[0],
setEditModeValue = _useState4[1];
// readModeValue accepts controlledValue here to provide a reliable backup for the onCancel callback
var _useState5 = (0, _react.useState)(controlledValue || defaultValue),
_useState6 = _slicedToArray(_useState5, 2),
readModeValue = _useState6[0],
setReadModeValue = _useState6[1];
var value = (0, _react.useMemo)(function () {
if (controlledValue) {
return controlledValue;
} else {
return isEditing ? editModeValue : readModeValue || placeholder;
}
}, [controlledValue, editModeValue, readModeValue, isEditing, placeholder]);
var readModeStyles = (0, _services.useEuiMemoizedStyles)(_inline_edit_form.euiInlineEditReadModeStyles);
var readModeCssStyles = [readModeStyles.euiInlineEditReadMode, isReadOnly && readModeStyles.isReadOnly, placeholder && !readModeValue && readModeStyles.hasPlaceholder];
var activateEditMode = function activateEditMode() {
setIsEditing(true);
// Waits a tick for state to settle and the focus target to render
requestAnimationFrame(function () {
var _editModeFocusRef$cur;
return (_editModeFocusRef$cur = editModeFocusRef.current) === null || _editModeFocusRef$cur === void 0 ? void 0 : _editModeFocusRef$cur.focus();
});
};
var cancelInlineEdit = function cancelInlineEdit() {
setEditModeValue(readModeValue);
onCancel === null || onCancel === void 0 || onCancel(readModeValue);
setIsEditing(false);
requestAnimationFrame(function () {
var _readModeFocusRef$cur;
return (_readModeFocusRef$cur = readModeFocusRef.current) === null || _readModeFocusRef$cur === void 0 ? void 0 : _readModeFocusRef$cur.focus();
});
};
var saveInlineEditValue = /*#__PURE__*/function () {
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
var onSaveReturn, awaitedReturn;
return _regeneratorRuntime().wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
if (!onSave) {
_context.next = 12;
break;
}
onSaveReturn = onSave(value);
if (!(onSaveReturn instanceof Promise)) {
_context.next = 8;
break;
}
_context.next = 5;
return onSaveReturn;
case 5:
_context.t0 = _context.sent;
_context.next = 9;
break;
case 8:
_context.t0 = onSaveReturn;
case 9:
awaitedReturn = _context.t0;
if (!(awaitedReturn === false)) {
_context.next = 12;
break;
}
return _context.abrupt("return");
case 12:
setReadModeValue(editModeValue);
setIsEditing(false);
requestAnimationFrame(function () {
var _readModeFocusRef$cur2;
return (_readModeFocusRef$cur2 = readModeFocusRef.current) === null || _readModeFocusRef$cur2 === void 0 ? void 0 : _readModeFocusRef$cur2.focus();
});
case 15:
case "end":
return _context.stop();
}
}, _callee);
}));
return function saveInlineEditValue() {
return _ref2.apply(this, arguments);
};
}();
var editModeInputOnKeyDown = function editModeInputOnKeyDown(event) {
switch (event.key) {
case _services.keys.ENTER:
event.preventDefault(); // Enter keypresses will not proceed otherwise on webkit browsers & screen readers
saveInlineEditValue();
break;
case _services.keys.ESCAPE:
cancelInlineEdit();
break;
}
};
// If the state of isReadOnly changes while in edit mode, switch back to read mode
(0, _react.useEffect)(function () {
if (isReadOnly) {
setIsEditing(false);
}
}, [isReadOnly]);
var editModeForm = (0, _react2.jsx)(_flex.EuiFlexGroup, {
gutterSize: "s",
responsive: false
}, (0, _react2.jsx)(_flex.EuiFlexItem, null, (0, _react2.jsx)(_form.EuiFormRow, _extends({
fullWidth: true,
isInvalid: isInvalid,
error: isInvalid && (editModeProps === null || editModeProps === void 0 || (_editModeProps$formRo = editModeProps.formRowProps) === null || _editModeProps$formRo === void 0 ? void 0 : _editModeProps$formRo.error)
}, editModeProps === null || editModeProps === void 0 ? void 0 : editModeProps.formRowProps), (0, _react2.jsx)(_form.EuiFieldText, _extends({
fullWidth: true,
value: value,
"aria-label": inputAriaLabel,
compressed: sizes.compressed,
isInvalid: isInvalid,
isLoading: isLoading,
"data-test-subj": "euiInlineEditModeInput",
placeholder: placeholder || undefined // Opt not to render the prop entirely if an empty string is passed
}, editModeProps === null || editModeProps === void 0 ? void 0 : editModeProps.inputProps, {
inputRef: setEditModeRefs,
onChange: function onChange(e) {
var _editModeProps$inputP2, _editModeProps$inputP3;
setEditModeValue(e.target.value);
_onChange === null || _onChange === void 0 || _onChange(e);
editModeProps === null || editModeProps === void 0 || (_editModeProps$inputP2 = editModeProps.inputProps) === null || _editModeProps$inputP2 === void 0 || (_editModeProps$inputP3 = _editModeProps$inputP2.onChange) === null || _editModeProps$inputP3 === void 0 || _editModeProps$inputP3.call(_editModeProps$inputP2, e);
},
onKeyDown: function onKeyDown(e) {
var _editModeProps$inputP4, _editModeProps$inputP5;
editModeInputOnKeyDown(e);
editModeProps === null || editModeProps === void 0 || (_editModeProps$inputP4 = editModeProps.inputProps) === null || _editModeProps$inputP4 === void 0 || (_editModeProps$inputP5 = _editModeProps$inputP4.onKeyDown) === null || _editModeProps$inputP5 === void 0 || _editModeProps$inputP5.call(_editModeProps$inputP4, e);
},
"aria-describedby": (0, _classnames.default)(editModeDescribedById, editModeProps === null || editModeProps === void 0 || (_editModeProps$inputP6 = editModeProps.inputProps) === null || _editModeProps$inputP6 === void 0 ? void 0 : _editModeProps$inputP6['aria-describedby'])
}))), (0, _react2.jsx)("span", {
id: editModeDescribedById,
hidden: true
}, (0, _react2.jsx)(_i18n.EuiI18n, {
token: "euiInlineEditForm.inputKeyboardInstructions",
default: "Press Enter to save your edited text. Press Escape to cancel your edit."
}))), (0, _react2.jsx)(_flex.EuiFlexItem, {
grow: false
}, (0, _react2.jsx)(_skeleton.EuiSkeletonLoading, {
isLoading: isLoading,
announceLoadingStatus: true,
announceLoadedStatus: false,
loadingContent: (0, _react2.jsx)(_flex.EuiFlexGroup, {
gutterSize: "s"
}, (0, _react2.jsx)(_skeleton.EuiSkeletonRectangle, {
height: loadingSkeletonSize,
width: loadingSkeletonSize,
borderRadius: "m"
}), (0, _react2.jsx)(_skeleton.EuiSkeletonRectangle, {
height: loadingSkeletonSize,
width: loadingSkeletonSize,
borderRadius: "m"
})),
loadedContent: (0, _react2.jsx)(_flex.EuiFlexGroup, {
gutterSize: "s"
}, (0, _react2.jsx)(_button.EuiButtonIcon, _extends({
iconType: "check",
"aria-label": defaultSaveButtonAriaLabel,
color: "success",
display: "base",
size: sizes.buttonSize,
iconSize: sizes.iconSize,
"data-test-subj": "euiInlineEditModeSaveButton"
}, editModeProps === null || editModeProps === void 0 ? void 0 : editModeProps.saveButtonProps, {
onClick: function onClick(e) {
var _editModeProps$saveBu, _editModeProps$saveBu2;
saveInlineEditValue();
editModeProps === null || editModeProps === void 0 || (_editModeProps$saveBu = editModeProps.saveButtonProps) === null || _editModeProps$saveBu === void 0 || (_editModeProps$saveBu2 = _editModeProps$saveBu.onClick) === null || _editModeProps$saveBu2 === void 0 || _editModeProps$saveBu2.call(_editModeProps$saveBu, e);
}
})), (0, _react2.jsx)(_button.EuiButtonIcon, _extends({
iconType: "cross",
"aria-label": defaultCancelButtonAriaLabel,
color: "danger",
display: "base",
size: sizes.buttonSize,
iconSize: sizes.iconSize,
"data-test-subj": "euiInlineEditModeCancelButton"
}, editModeProps === null || editModeProps === void 0 ? void 0 : editModeProps.cancelButtonProps, {
onClick: function onClick(e) {
var _editModeProps$cancel, _editModeProps$cancel2;
cancelInlineEdit();
editModeProps === null || editModeProps === void 0 || (_editModeProps$cancel = editModeProps.cancelButtonProps) === null || _editModeProps$cancel === void 0 || (_editModeProps$cancel2 = _editModeProps$cancel.onClick) === null || _editModeProps$cancel2 === void 0 || _editModeProps$cancel2.call(_editModeProps$cancel, e);
}
})))
})));
var readModeElement = (0, _react2.jsx)(_react.default.Fragment, null, (0, _react2.jsx)(_button.EuiButtonEmpty, _extends({
color: "text",
iconType: isReadOnly ? undefined : 'pencil',
iconSide: "right",
flush: "both",
iconSize: sizes.iconSize,
size: sizes.buttonSize,
"data-test-subj": "euiInlineReadModeButton",
disabled: isReadOnly,
css: readModeCssStyles,
title: value
}, readModeProps, {
buttonRef: setReadModeRefs,
"aria-describedby": (0, _classnames.default)(readModeDescribedById, readModeProps === null || readModeProps === void 0 ? void 0 : readModeProps['aria-describedby']),
onClick: function onClick(e) {
var _readModeProps$onClic;
activateEditMode();
readModeProps === null || readModeProps === void 0 || (_readModeProps$onClic = readModeProps.onClick) === null || _readModeProps$onClic === void 0 || _readModeProps$onClic.call(readModeProps, e);
}
}), children(value)), (0, _react2.jsx)("span", {
id: readModeDescribedById,
hidden: true
}, !isReadOnly && (0, _react2.jsx)(_i18n.EuiI18n, {
token: "euiInlineEditForm.activateEditModeDescription",
default: "Click to edit this text inline."
})));
return (0, _react2.jsx)("div", _extends({
className: classes
}, rest), isEditing ? editModeForm : readModeElement);
};
EuiInlineEditForm.propTypes = {
className: _propTypes.default.string,
"aria-label": _propTypes.default.string,
"data-test-subj": _propTypes.default.string,
css: _propTypes.default.any,
placeholder: _propTypes.default.string,
/**
* Callback that fires when a user clicks the save button.
* Passes the current edited text value as an argument.
*
* To validate the value of the edited text, pass back a boolean flag.
* If `false`, EuiInlineEdit will remain in edit mode, where loading or invalid states can be set.
* If `true`, EuiInlineEdit will return to read mode.
*/
onSave: _propTypes.default.func,
/**
* Form label that appears above the form control.
* This is required for accessibility because there is no visual label on the input.
*/
inputAriaLabel: _propTypes.default.string.isRequired,
/**
* Starts the component in edit mode
*/
startWithEditOpen: _propTypes.default.bool,
/**
* Props that will be applied directly to the `EuiEmptyButton` displayed in read mode
*/
readModeProps: _propTypes.default.any,
/**
* Multiple props objects that can be applied directly to various child components displayed in edit mode.
* - `formRowProps` will be passed to `EuiFormRow`
* - `inputProps` will be passed to `EuiFieldText`
* - `saveButtonProps` & `cancelButtonProps` will be passed to their respective `EuiButtonIcon`s
*/
editModeProps: _propTypes.default.shape({
formRowProps: _propTypes.default.any,
inputProps: _propTypes.default.any,
saveButtonProps: _propTypes.default.any,
cancelButtonProps: _propTypes.default.any
}),
/**
* Loading state - only displayed in edit mode
*/
isLoading: _propTypes.default.bool,
/**
* Invalid state - only displayed edit mode
*/
isInvalid: _propTypes.default.bool,
/**
* Locks inline edit in read mode and displays the text value
*/
isReadOnly: _propTypes.default.bool,
/**
* Initial inline edit text value
*/
defaultValue: _propTypes.default.string,
/**
* Callback required to reset `value` to the previous read mode text value.
*/
onCancel: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.func.isRequired]),
/**
* To use inline edit as a controlled component, continuously pass the value via this prop
*/
value: _propTypes.default.string,
/**
* Callback required to receive and update `value` based on user input
*/
onChange: _propTypes.default.func,
/**
* Form sizes
*/
sizes: _propTypes.default.shape({
compressed: _propTypes.default.bool.isRequired,
buttonSize: _propTypes.default.oneOfType([_propTypes.default.any, _propTypes.default.any]).isRequired,
iconSize: _propTypes.default.any.isRequired
}).isRequired,
/**
* Render prop that returns the read mode value as an arg
*/
children: _propTypes.default.func.isRequired
};