@rh-support/components 1.2.16 → 1.2.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,10 +19,6 @@ interface IProps {
19
19
  onSave: any;
20
20
  onCancel: any;
21
21
  cancelOnToggle?: boolean;
22
- charCount: number;
23
- charTotal: number;
24
- cancelToggleState?: boolean;
25
- saveToggleState?: boolean;
26
22
  collapseOnBlur?: boolean;
27
23
  saveOnBlur?: boolean;
28
24
  saveDisabled?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"InlineEdit.d.ts","sourceRoot":"","sources":["../../../src/InlineEdit/InlineEdit.tsx"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAI1B,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAG9D,UAAU,MAAM;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IACtC,UAAU,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACxC,YAAY,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAC1C,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAC5C,gBAAgB,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;IAC/B,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IAClC,SAAS,EAAE,GAA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vC,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;IAC/B,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IAClC,SAAS,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE,GAAG,CAAC;IACZ,QAAQ,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,OAAO,CAAC;IAGzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAsBD,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,eAmKhC;kBAnKQ,UAAU;;;AAsKnB,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -117,13 +117,6 @@ function InlineEdit(props) {
117
117
  // editingTrueOnStart is a state to track if inlineEdit component is open on start, we don't want to focus
118
118
  // on input/textareat in this situation as we may have other form elements on page that we want to focus
119
119
  var _c = __read(react_1.useState(!props.initialIsEditing), 2), canAutoSetFocus = _c[0], setCanAutoSfocus = _c[1];
120
- // To close InlineEdit input and show content whenever cancel is clicked
121
- react_1.useEffect(function () {
122
- if (isEditing) {
123
- setIsEditing(!isEditing);
124
- }
125
- // eslint-disable-next-line react-hooks/exhaustive-deps
126
- }, [props.cancelToggleState, props.saveToggleState]);
127
120
  var onEditClicked = function (e) {
128
121
  setCanAutoSfocus(true);
129
122
  e.preventDefault();
@@ -218,21 +211,19 @@ function InlineEdit(props) {
218
211
  react_1.default.createElement(react_i18next_1.Trans, null, props.cancelLabel))));
219
212
  };
220
213
  var canShowContent = !isEditing && props.allowInlineEdit && props.content;
221
- var showCount = " " + props.charCount + " / " + props.charTotal;
222
214
  return (react_1.default.createElement("div", { className: "form-group edit-question " + props.formClassName, id: props.formId },
223
215
  !props.hideLabel && (react_1.default.createElement(react_1.default.Fragment, null,
224
216
  react_1.default.createElement("label", __assign({}, props.labelProps),
225
217
  react_1.default.createElement("span", { className: "label-edit" }, props.labelContent),
226
218
  props.helperContent,
227
- !props.content && !isEditing ? renderEditButton() : null))),
219
+ renderEditButton()))),
228
220
  renderSaveCancel(),
229
- props.hideSaveCancel && isEditing && (react_1.default.createElement("span", { className: "\n " + (props.charCount > props.charTotal ? 'char-count pf-u-danger-color-100' : 'char-count') }, props.charCount ? showCount : null)),
230
221
  canShowContent && !props.usePreformattedTag && (react_1.default.createElement(react_1.default.Fragment, null,
231
222
  react_1.default.createElement("p", { id: props.inputId, style: { display: props.hideLabel ? 'inline' : 'block' } },
232
223
  props.content,
233
- react_1.default.createElement(react_1.default.Fragment, null,
224
+ props.hideLabel && (react_1.default.createElement(react_1.default.Fragment, null,
234
225
  props.helperContent,
235
- renderEditButton()),
226
+ renderEditButton())),
236
227
  props.loadingIndicator && react_1.default.createElement("span", { className: "loading-indicator" }, props.loadingIndicator)))),
237
228
  canShowContent && props.usePreformattedTag && react_1.default.createElement("pre", { id: props.inputId }, props.content),
238
229
  react_1.default.createElement(react_1.default.Fragment, null,
@@ -0,0 +1,44 @@
1
+ .edit-question .btn-edit {
2
+ padding: 0 0.5rem !important;
3
+ margin-left: 0.5rem;
4
+ }
5
+
6
+ .edit-question .edit-actions {
7
+ float: right;
8
+ position: relative;
9
+ top: 38px;
10
+ margin-top: -34px;
11
+ }
12
+
13
+ .edit-question .edit-actions > * {
14
+ padding: 2px 1rem !important;
15
+ font-size: 13px !important;
16
+ float: right;
17
+ }
18
+
19
+ .edit-question input {
20
+ padding-right: 150px;
21
+ }
22
+
23
+ .edit-question .loading-indicator {
24
+ margin-left: 10px;
25
+ }
26
+
27
+ .case-overview .edit-question .loading-indicator {
28
+ margin-left: 0px;
29
+ }
30
+
31
+ /* Character Count */
32
+ .char-count {
33
+ float: right;
34
+ position: relative;
35
+ padding-right: var(--pf-global--spacer--4xl);
36
+ margin-right: var(--pf-global--spacer--lg);
37
+ font-size: 12px;
38
+ }
39
+
40
+ @media (max-width: 415px) {
41
+ .char-count {
42
+ padding-right: var(--pf-global--spacer--2xl);
43
+ }
44
+ }
@@ -0,0 +1,40 @@
1
+ import './NewInlineEdit.css';
2
+ import { HTMLProps } from 'react';
3
+ interface IProps {
4
+ inputId?: string;
5
+ children: JSX.Element | JSX.Element[];
6
+ labelProps: HTMLProps<HTMLLabelElement>;
7
+ labelContent: JSX.Element | JSX.Element[];
8
+ helperContent?: JSX.Element | JSX.Element[];
9
+ loadingIndicator: JSX.Element | string;
10
+ content?: string | JSX.Element;
11
+ allowInlineEdit: boolean;
12
+ formClassName?: string;
13
+ formId?: string;
14
+ dataTrackingId?: string;
15
+ usePreformattedTag: boolean;
16
+ hideSaveCancel: boolean;
17
+ cancelLabel: JSX.Element | string;
18
+ saveLabel: JSX.Element | string;
19
+ onSave: any;
20
+ onCancel: any;
21
+ cancelOnToggle?: boolean;
22
+ charCount: number;
23
+ charTotal: number;
24
+ cancelToggleState?: boolean;
25
+ saveToggleState?: boolean;
26
+ collapseOnBlur?: boolean;
27
+ saveOnBlur?: boolean;
28
+ saveDisabled?: boolean;
29
+ cancelOnBlur?: boolean;
30
+ initialIsEditing?: boolean;
31
+ hideLabel?: boolean;
32
+ isSpaceAllowed?: boolean;
33
+ inputValue?: string;
34
+ }
35
+ declare function NewInlineEdit(props: IProps): JSX.Element;
36
+ declare namespace NewInlineEdit {
37
+ var defaultProps: Partial<IProps>;
38
+ }
39
+ export { NewInlineEdit };
40
+ //# sourceMappingURL=NewInlineEdit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NewInlineEdit.d.ts","sourceRoot":"","sources":["../../../src/InlineEdit/NewInlineEdit.tsx"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAI7B,OAAc,EAAE,SAAS,EAAuB,MAAM,OAAO,CAAC;AAG9D,UAAU,MAAM;IACZ,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IACtC,UAAU,EAAE,SAAS,CAAC,gBAAgB,CAAC,CAAC;IACxC,YAAY,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAC1C,aAAa,CAAC,EAAE,GAAG,CAAC,OAAO,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAC5C,gBAAgB,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IACvC,OAAO,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC,OAAO,CAAC;IAC/B,eAAe,EAAE,OAAO,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,WAAW,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IAClC,SAAS,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,CAAC;IAChC,MAAM,EAAE,GAAG,CAAC;IACZ,QAAQ,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAG1B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAsBD,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,eAqLnC;kBArLQ,aAAa;;;AAwLtB,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,263 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
33
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
+ return new (P || (P = Promise))(function (resolve, reject) {
35
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
36
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
37
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
38
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
39
+ });
40
+ };
41
+ var __generator = (this && this.__generator) || function (thisArg, body) {
42
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
43
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
44
+ function verb(n) { return function (v) { return step([n, v]); }; }
45
+ function step(op) {
46
+ if (f) throw new TypeError("Generator is already executing.");
47
+ while (_) try {
48
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
49
+ if (y = 0, t) op = [op[0] & 2, t.value];
50
+ switch (op[0]) {
51
+ case 0: case 1: t = op; break;
52
+ case 4: _.label++; return { value: op[1], done: false };
53
+ case 5: _.label++; y = op[1]; op = [0]; continue;
54
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
55
+ default:
56
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
57
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
58
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
59
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
60
+ if (t[2]) _.ops.pop();
61
+ _.trys.pop(); continue;
62
+ }
63
+ op = body.call(thisArg, _);
64
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
65
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
66
+ }
67
+ };
68
+ var __read = (this && this.__read) || function (o, n) {
69
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
70
+ if (!m) return o;
71
+ var i = m.call(o), r, ar = [], e;
72
+ try {
73
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
74
+ }
75
+ catch (error) { e = { error: error }; }
76
+ finally {
77
+ try {
78
+ if (r && !r.done && (m = i["return"])) m.call(i);
79
+ }
80
+ finally { if (e) throw e.error; }
81
+ }
82
+ return ar;
83
+ };
84
+ var __importDefault = (this && this.__importDefault) || function (mod) {
85
+ return (mod && mod.__esModule) ? mod : { "default": mod };
86
+ };
87
+ Object.defineProperty(exports, "__esModule", { value: true });
88
+ exports.NewInlineEdit = void 0;
89
+ require("./NewInlineEdit.css");
90
+ var pencil_alt_icon_1 = __importDefault(require("@patternfly/react-icons/dist/js/icons/pencil-alt-icon"));
91
+ var lodash_1 = require("lodash");
92
+ var react_1 = __importStar(require("react"));
93
+ var react_i18next_1 = require("react-i18next");
94
+ var defaultProps = {
95
+ allowInlineEdit: false,
96
+ formClassName: '',
97
+ formId: '',
98
+ dataTrackingId: '',
99
+ usePreformattedTag: false,
100
+ hideSaveCancel: false,
101
+ saveLabel: 'Save',
102
+ cancelLabel: 'Cancel',
103
+ cancelOnToggle: false,
104
+ loadingIndicator: '',
105
+ initialIsEditing: false,
106
+ collapseOnBlur: false,
107
+ saveOnBlur: false,
108
+ cancelOnBlur: false,
109
+ saveDisabled: false,
110
+ hideLabel: false,
111
+ isSpaceAllowed: true,
112
+ };
113
+ function NewInlineEdit(props) {
114
+ var _this = this;
115
+ var _a;
116
+ var _b = __read(react_1.useState(props.initialIsEditing), 2), isEditing = _b[0], setIsEditing = _b[1];
117
+ // editingTrueOnStart is a state to track if inlineEdit component is open on start, we don't want to focus
118
+ // on input/textareat in this situation as we may have other form elements on page that we want to focus
119
+ var _c = __read(react_1.useState(!props.initialIsEditing), 2), canAutoSetFocus = _c[0], setCanAutoSfocus = _c[1];
120
+ // To close InlineEdit input and show content whenever cancel is clicked
121
+ react_1.useEffect(function () {
122
+ if (isEditing) {
123
+ setIsEditing(!isEditing);
124
+ }
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps
126
+ }, [props.cancelToggleState, props.saveToggleState]);
127
+ var onEditClicked = function (e) {
128
+ setCanAutoSfocus(true);
129
+ e.preventDefault();
130
+ props.cancelOnToggle && isEditing && props.onCancel && props.onCancel();
131
+ setIsEditing(!isEditing);
132
+ };
133
+ var renderEditButton = function () {
134
+ if (!props.allowInlineEdit) {
135
+ return null;
136
+ }
137
+ return (react_1.default.createElement("button", { className: "btn btn-link btn-app btn-edit", "aria-label": "Edit", onClick: onEditClicked },
138
+ react_1.default.createElement(pencil_alt_icon_1.default, null)));
139
+ };
140
+ var onBlurChild = function () {
141
+ props.collapseOnBlur && setIsEditing(!isEditing);
142
+ props.saveOnBlur && !props.saveDisabled && props.onSave && props.onSave();
143
+ props.cancelOnBlur && props.onCancel && props.onCancel();
144
+ };
145
+ var onCancelClicked = function () {
146
+ props.onCancel && props.onCancel();
147
+ setIsEditing(false);
148
+ };
149
+ var onSave = function () { return __awaiter(_this, void 0, void 0, function () {
150
+ var _a, e_1;
151
+ return __generator(this, function (_b) {
152
+ switch (_b.label) {
153
+ case 0:
154
+ _b.trys.push([0, 3, , 4]);
155
+ _a = props.onSave;
156
+ if (!_a) return [3 /*break*/, 2];
157
+ return [4 /*yield*/, props.onSave()];
158
+ case 1:
159
+ _a = (_b.sent());
160
+ _b.label = 2;
161
+ case 2:
162
+ _a;
163
+ setIsEditing(false);
164
+ return [3 /*break*/, 4];
165
+ case 3:
166
+ e_1 = _b.sent();
167
+ return [3 /*break*/, 4];
168
+ case 4: return [2 /*return*/];
169
+ }
170
+ });
171
+ }); };
172
+ var onSaveClicked = function () { return __awaiter(_this, void 0, void 0, function () {
173
+ return __generator(this, function (_a) {
174
+ switch (_a.label) {
175
+ case 0:
176
+ if (props.saveDisabled)
177
+ return [2 /*return*/];
178
+ return [4 /*yield*/, onSave()];
179
+ case 1:
180
+ _a.sent();
181
+ return [2 /*return*/];
182
+ }
183
+ });
184
+ }); };
185
+ // Disables button if isSpaceAllowed is False and Input has Spaces
186
+ var diabledCheckForSpaceAllowed = !props.isSpaceAllowed && lodash_1.isEmpty((_a = props.inputValue) === null || _a === void 0 ? void 0 : _a.trim());
187
+ var handleKeyDown = function (e) { return __awaiter(_this, void 0, void 0, function () {
188
+ return __generator(this, function (_a) {
189
+ switch (_a.label) {
190
+ case 0:
191
+ if (!(props.allowInlineEdit && isEditing && e.keyCode === 27)) return [3 /*break*/, 1];
192
+ props.onCancel && props.onCancel();
193
+ setIsEditing(false);
194
+ return [3 /*break*/, 3];
195
+ case 1:
196
+ if (!(!props.hideSaveCancel &&
197
+ props.allowInlineEdit &&
198
+ isEditing &&
199
+ !diabledCheckForSpaceAllowed &&
200
+ !props.saveDisabled &&
201
+ e.keyCode === 13)) return [3 /*break*/, 3];
202
+ return [4 /*yield*/, onSave()];
203
+ case 2:
204
+ _a.sent();
205
+ _a.label = 3;
206
+ case 3: return [2 /*return*/];
207
+ }
208
+ });
209
+ }); };
210
+ var renderSaveCancel = function () {
211
+ return !props.hideSaveCancel &&
212
+ props.allowInlineEdit &&
213
+ isEditing && (react_1.default.createElement("span", { className: "edit-actions" },
214
+ props.loadingIndicator && react_1.default.createElement("span", null, props.loadingIndicator),
215
+ react_1.default.createElement("button", { "data-tracking-id": props.dataTrackingId ? props.dataTrackingId + "-inline-edit-save" : null, className: "btn btn-app btn-link", type: "button", onClick: onSaveClicked, disabled: diabledCheckForSpaceAllowed || props.saveDisabled },
216
+ react_1.default.createElement(react_i18next_1.Trans, null, props.saveLabel)),
217
+ react_1.default.createElement("button", { type: "button", "data-tracking-id": props.dataTrackingId ? props.dataTrackingId + "-inline-edit-cancel" : null, className: "btn btn-app btn-link", onClick: onCancelClicked },
218
+ react_1.default.createElement(react_i18next_1.Trans, null, props.cancelLabel))));
219
+ };
220
+ var canShowContent = !isEditing && props.allowInlineEdit && props.content;
221
+ var showCount = " " + props.charCount + " / " + props.charTotal;
222
+ return (react_1.default.createElement("div", { className: "form-group edit-question " + props.formClassName, id: props.formId },
223
+ !props.hideLabel && (react_1.default.createElement(react_1.default.Fragment, null,
224
+ react_1.default.createElement("label", __assign({}, props.labelProps),
225
+ react_1.default.createElement("span", { className: "label-edit" }, props.labelContent),
226
+ props.helperContent,
227
+ !props.content && !isEditing ? renderEditButton() : null))),
228
+ renderSaveCancel(),
229
+ props.hideSaveCancel && isEditing && (react_1.default.createElement("span", { className: "\n " + (props.charCount > props.charTotal ? 'char-count pf-u-danger-color-100' : 'char-count') }, props.charCount ? showCount : null)),
230
+ canShowContent && !props.usePreformattedTag && (react_1.default.createElement(react_1.default.Fragment, null,
231
+ react_1.default.createElement("p", { id: props.inputId, style: { display: props.hideLabel ? 'inline' : 'block' } },
232
+ props.content,
233
+ react_1.default.createElement(react_1.default.Fragment, null,
234
+ props.helperContent,
235
+ renderEditButton()),
236
+ props.loadingIndicator && react_1.default.createElement("span", { className: "loading-indicator" }, props.loadingIndicator)))),
237
+ canShowContent && props.usePreformattedTag && react_1.default.createElement("pre", { id: props.inputId }, props.content),
238
+ react_1.default.createElement(react_1.default.Fragment, null,
239
+ react_1.default.createElement("div", { onBlur: onBlurChild, onKeyDown: handleKeyDown, className: "inlineEdit-wrapper", "data-tracking-id": "inline-edit-input-wrapper" },
240
+ !props.allowInlineEdit && props.children,
241
+ props.allowInlineEdit &&
242
+ isEditing &&
243
+ react_1.default.Children.map(props.children, function (child) {
244
+ if (!child)
245
+ return;
246
+ var canFocusChild = (child.type === 'input' || child.type === 'textarea') && canAutoSetFocus;
247
+ // if input/textarea had autoFocus but focus was lost in the wrapper component
248
+ var needsReFocus = !canAutoSetFocus && child.props.autoFocus;
249
+ if (canFocusChild || needsReFocus) {
250
+ return react_1.default.cloneElement(child, {
251
+ ref: function (node) {
252
+ node && node.focus();
253
+ setCanAutoSfocus(false);
254
+ },
255
+ });
256
+ }
257
+ else {
258
+ return child;
259
+ }
260
+ })))));
261
+ }
262
+ exports.NewInlineEdit = NewInlineEdit;
263
+ NewInlineEdit.defaultProps = defaultProps;
@@ -1,2 +1,3 @@
1
1
  export * from './InlineEdit';
2
+ export * from './NewInlineEdit';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/InlineEdit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/InlineEdit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
@@ -11,3 +11,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./InlineEdit"), exports);
14
+ __exportStar(require("./NewInlineEdit"), exports);
@@ -27,18 +27,3 @@
27
27
  .case-overview .edit-question .loading-indicator {
28
28
  margin-left: 0px;
29
29
  }
30
-
31
- /* Character Count */
32
- .char-count {
33
- float: right;
34
- position: relative;
35
- padding-right: var(--pf-global--spacer--4xl);
36
- margin-right: var(--pf-global--spacer--lg);
37
- font-size: 12px;
38
- }
39
-
40
- @media (max-width: 415px) {
41
- .char-count {
42
- padding-right: var(--pf-global--spacer--2xl);
43
- }
44
- }
@@ -19,10 +19,6 @@ interface IProps {
19
19
  onSave: any;
20
20
  onCancel: any;
21
21
  cancelOnToggle?: boolean;
22
- charCount: number;
23
- charTotal: number;
24
- cancelToggleState?: boolean;
25
- saveToggleState?: boolean;
26
22
  collapseOnBlur?: boolean;
27
23
  saveOnBlur?: boolean;
28
24
  saveDisabled?: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"Inl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MAAM,CAAC;IAChC,MAAM,EAAE,GAAG,CAAC;IACZ,QAAQ,EAAE,GAAG,CAAC;IACd,cAAc,CAAC,EAAE,OAAO,CAAC;IAGzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAsBD,iBAAS,UAAU,CAAC,KAAK,EAAE,MAAM,eAmKhC;kBAnKQ,UAAU;;;AAsKnB,OAAO,EAAE,UAAU,EAAE,CAAC"}
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import './inlineEdit.css';
11
11
  import PencilAltIcon from '@patternfly/react-icons/dist/js/icons/pencil-alt-icon';
12
12
  import { isEmpty } from 'lodash';
13
- import React, { useEffect, useState } from 'react';
13
+ import React, { useState } from 'react';
14
14
  import { Trans } from 'react-i18next';
15
15
  const defaultProps = {
16
16
  allowInlineEdit: false,
@@ -37,13 +37,6 @@ function InlineEdit(props) {
37
37
  // editingTrueOnStart is a state to track if inlineEdit component is open on start, we don't want to focus
38
38
  // on input/textareat in this situation as we may have other form elements on page that we want to focus
39
39
  const [canAutoSetFocus, setCanAutoSfocus] = useState(!props.initialIsEditing);
40
- // To close InlineEdit input and show content whenever cancel is clicked
41
- useEffect(() => {
42
- if (isEditing) {
43
- setIsEditing(!isEditing);
44
- }
45
- // eslint-disable-next-line react-hooks/exhaustive-deps
46
- }, [props.cancelToggleState, props.saveToggleState]);
47
40
  const onEditClicked = (e) => {
48
41
  setCanAutoSfocus(true);
49
42
  e.preventDefault();
@@ -107,22 +100,19 @@ function InlineEdit(props) {
107
100
  React.createElement("button", { type: "button", "data-tracking-id": props.dataTrackingId ? `${props.dataTrackingId}-inline-edit-cancel` : null, className: "btn btn-app btn-link", onClick: onCancelClicked },
108
101
  React.createElement(Trans, null, props.cancelLabel))));
109
102
  const canShowContent = !isEditing && props.allowInlineEdit && props.content;
110
- const showCount = ` ${props.charCount} / ${props.charTotal}`;
111
103
  return (React.createElement("div", { className: `form-group edit-question ${props.formClassName}`, id: props.formId },
112
104
  !props.hideLabel && (React.createElement(React.Fragment, null,
113
105
  React.createElement("label", Object.assign({}, props.labelProps),
114
106
  React.createElement("span", { className: "label-edit" }, props.labelContent),
115
107
  props.helperContent,
116
- !props.content && !isEditing ? renderEditButton() : null))),
108
+ renderEditButton()))),
117
109
  renderSaveCancel(),
118
- props.hideSaveCancel && isEditing && (React.createElement("span", { className: `
119
- ${props.charCount > props.charTotal ? 'char-count pf-u-danger-color-100' : 'char-count'}` }, props.charCount ? showCount : null)),
120
110
  canShowContent && !props.usePreformattedTag && (React.createElement(React.Fragment, null,
121
111
  React.createElement("p", { id: props.inputId, style: { display: props.hideLabel ? 'inline' : 'block' } },
122
112
  props.content,
123
- React.createElement(React.Fragment, null,
113
+ props.hideLabel && (React.createElement(React.Fragment, null,
124
114
  props.helperContent,
125
- renderEditButton()),
115
+ renderEditButton())),
126
116
  props.loadingIndicator && React.createElement("span", { className: "loading-indicator" }, props.loadingIndicator)))),
127
117
  canShowContent && props.usePreformattedTag && React.createElement("pre", { id: props.inputId }, props.content),
128
118
  React.createElement(React.Fragment, null,
@@ -0,0 +1,44 @@
1
+ .edit-question .btn-edit {
2
+ padding: 0 0.5rem !important;
3
+ margin-left: 0.5rem;
4
+ }
5
+
6
+ .edit-question .edit-actions {
7
+ float: right;
8
+ position: relative;
9
+ top: 38px;
10
+ margin-top: -34px;
11
+ }
12
+
13
+ .edit-question .edit-actions > * {
14
+ padding: 2px 1rem !important;
15
+ font-size: 13px !important;
16
+ float: right;
17
+ }
18
+
19
+ .edit-question input {
20
+ padding-right: 150px;
21
+ }
22
+
23
+ .edit-question .loading-indicator {
24
+ margin-left: 10px;
25
+ }
26
+
27
+ .case-overview .edit-question .loading-indicator {
28
+ margin-left: 0px;
29
+ }
30
+
31
+ /* Character Count */
32
+ .char-count {
33
+ float: right;
34
+ position: relative;
35
+ padding-right: var(--pf-global--spacer--4xl);
36
+ margin-right: var(--pf-global--spacer--lg);
37
+ font-size: 12px;
38
+ }
39
+
40
+ @media (max-width: 415px) {
41
+ .char-count {
42
+ padding-right: var(--pf-global--spacer--2xl);
43
+ }
44
+ }
@@ -0,0 +1,40 @@
1
+ import './NewInlineEdit.css';
2
+ import { HTMLProps } from 'react';
3
+ interface IProps {
4
+ inputId?: string;
5
+ children: JSX.Element | JSX.Element[];
6
+ labelProps: HTMLProps<HTMLLabelElement>;
7
+ labelContent: JSX.Element | JSX.Element[];
8
+ helperContent?: JSX.Element | JSX.Element[];
9
+ loadingIndicator: JSX.Element | string;
10
+ content?: string | JSX.Element;
11
+ allowInlineEdit: boolean;
12
+ formClassName?: string;
13
+ formId?: string;
14
+ dataTrackingId?: string;
15
+ usePreformattedTag: boolean;
16
+ hideSaveCancel: boolean;
17
+ cancelLabel: JSX.Element | string;
18
+ saveLabel: JSX.Element | string;
19
+ onSave: any;
20
+ onCancel: any;
21
+ cancelOnToggle?: boolean;
22
+ charCount: number;
23
+ charTotal: number;
24
+ cancelToggleState?: boolean;
25
+ saveToggleState?: boolean;
26
+ collapseOnBlur?: boolean;
27
+ saveOnBlur?: boolean;
28
+ saveDisabled?: boolean;
29
+ cancelOnBlur?: boolean;
30
+ initialIsEditing?: boolean;
31
+ hideLabel?: boolean;
32
+ isSpaceAllowed?: boolean;
33
+ inputValue?: string;
34
+ }
35
+ declare function NewInlineEdit(props: IProps): JSX.Element;
36
+ declare namespace NewInlineEdit {
37
+ var defaultProps: Partial<IProps>;
38
+ }
39
+ export { NewInlineEdit };
40
+ //# sourceMappingURL=NewInlineEdit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,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AAY,CAAC,EAAE,OAAO,CAAC;IACvB,YAAY,CAAC,EAAE,OAAO,CAAC;IAEvB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACvB;AAsBD,iBAAS,aAAa,CAAC,KAAK,EAAE,MAAM,eAqLnC;kBArLQ,aAAa;;;AAwLtB,OAAO,EAAE,aAAa,EAAE,CAAC"}
@@ -0,0 +1,153 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import './NewInlineEdit.css';
11
+ import PencilAltIcon from '@patternfly/react-icons/dist/js/icons/pencil-alt-icon';
12
+ import { isEmpty } from 'lodash';
13
+ import React, { useEffect, useState } from 'react';
14
+ import { Trans } from 'react-i18next';
15
+ const defaultProps = {
16
+ allowInlineEdit: false,
17
+ formClassName: '',
18
+ formId: '',
19
+ dataTrackingId: '',
20
+ usePreformattedTag: false,
21
+ hideSaveCancel: false,
22
+ saveLabel: 'Save',
23
+ cancelLabel: 'Cancel',
24
+ cancelOnToggle: false,
25
+ loadingIndicator: '',
26
+ initialIsEditing: false,
27
+ collapseOnBlur: false,
28
+ saveOnBlur: false,
29
+ cancelOnBlur: false,
30
+ saveDisabled: false,
31
+ hideLabel: false,
32
+ isSpaceAllowed: true,
33
+ };
34
+ function NewInlineEdit(props) {
35
+ var _a;
36
+ const [isEditing, setIsEditing] = useState(props.initialIsEditing);
37
+ // editingTrueOnStart is a state to track if inlineEdit component is open on start, we don't want to focus
38
+ // on input/textareat in this situation as we may have other form elements on page that we want to focus
39
+ const [canAutoSetFocus, setCanAutoSfocus] = useState(!props.initialIsEditing);
40
+ // To close InlineEdit input and show content whenever cancel is clicked
41
+ useEffect(() => {
42
+ if (isEditing) {
43
+ setIsEditing(!isEditing);
44
+ }
45
+ // eslint-disable-next-line react-hooks/exhaustive-deps
46
+ }, [props.cancelToggleState, props.saveToggleState]);
47
+ const onEditClicked = (e) => {
48
+ setCanAutoSfocus(true);
49
+ e.preventDefault();
50
+ props.cancelOnToggle && isEditing && props.onCancel && props.onCancel();
51
+ setIsEditing(!isEditing);
52
+ };
53
+ const renderEditButton = () => {
54
+ if (!props.allowInlineEdit) {
55
+ return null;
56
+ }
57
+ return (React.createElement("button", { className: "btn btn-link btn-app btn-edit", "aria-label": "Edit", onClick: onEditClicked },
58
+ React.createElement(PencilAltIcon, null)));
59
+ };
60
+ const onBlurChild = () => {
61
+ props.collapseOnBlur && setIsEditing(!isEditing);
62
+ props.saveOnBlur && !props.saveDisabled && props.onSave && props.onSave();
63
+ props.cancelOnBlur && props.onCancel && props.onCancel();
64
+ };
65
+ const onCancelClicked = () => {
66
+ props.onCancel && props.onCancel();
67
+ setIsEditing(false);
68
+ };
69
+ const onSave = () => __awaiter(this, void 0, void 0, function* () {
70
+ try {
71
+ props.onSave && (yield props.onSave());
72
+ setIsEditing(false);
73
+ }
74
+ catch (e) {
75
+ // we will keep the user in the editing state. so nothing to do here
76
+ }
77
+ });
78
+ const onSaveClicked = () => __awaiter(this, void 0, void 0, function* () {
79
+ if (props.saveDisabled)
80
+ return;
81
+ yield onSave();
82
+ });
83
+ // Disables button if isSpaceAllowed is False and Input has Spaces
84
+ const diabledCheckForSpaceAllowed = !props.isSpaceAllowed && isEmpty((_a = props.inputValue) === null || _a === void 0 ? void 0 : _a.trim());
85
+ const handleKeyDown = (e) => __awaiter(this, void 0, void 0, function* () {
86
+ // Cancel on pressing esc
87
+ if (props.allowInlineEdit && isEditing && e.keyCode === 27) {
88
+ props.onCancel && props.onCancel();
89
+ setIsEditing(false);
90
+ }
91
+ // Save on pressing enter
92
+ else if (!props.hideSaveCancel &&
93
+ props.allowInlineEdit &&
94
+ isEditing &&
95
+ !diabledCheckForSpaceAllowed &&
96
+ !props.saveDisabled &&
97
+ e.keyCode === 13) {
98
+ yield onSave();
99
+ }
100
+ });
101
+ const renderSaveCancel = () => !props.hideSaveCancel &&
102
+ props.allowInlineEdit &&
103
+ isEditing && (React.createElement("span", { className: "edit-actions" },
104
+ props.loadingIndicator && React.createElement("span", null, props.loadingIndicator),
105
+ React.createElement("button", { "data-tracking-id": props.dataTrackingId ? `${props.dataTrackingId}-inline-edit-save` : null, className: "btn btn-app btn-link", type: "button", onClick: onSaveClicked, disabled: diabledCheckForSpaceAllowed || props.saveDisabled },
106
+ React.createElement(Trans, null, props.saveLabel)),
107
+ React.createElement("button", { type: "button", "data-tracking-id": props.dataTrackingId ? `${props.dataTrackingId}-inline-edit-cancel` : null, className: "btn btn-app btn-link", onClick: onCancelClicked },
108
+ React.createElement(Trans, null, props.cancelLabel))));
109
+ const canShowContent = !isEditing && props.allowInlineEdit && props.content;
110
+ const showCount = ` ${props.charCount} / ${props.charTotal}`;
111
+ return (React.createElement("div", { className: `form-group edit-question ${props.formClassName}`, id: props.formId },
112
+ !props.hideLabel && (React.createElement(React.Fragment, null,
113
+ React.createElement("label", Object.assign({}, props.labelProps),
114
+ React.createElement("span", { className: "label-edit" }, props.labelContent),
115
+ props.helperContent,
116
+ !props.content && !isEditing ? renderEditButton() : null))),
117
+ renderSaveCancel(),
118
+ props.hideSaveCancel && isEditing && (React.createElement("span", { className: `
119
+ ${props.charCount > props.charTotal ? 'char-count pf-u-danger-color-100' : 'char-count'}` }, props.charCount ? showCount : null)),
120
+ canShowContent && !props.usePreformattedTag && (React.createElement(React.Fragment, null,
121
+ React.createElement("p", { id: props.inputId, style: { display: props.hideLabel ? 'inline' : 'block' } },
122
+ props.content,
123
+ React.createElement(React.Fragment, null,
124
+ props.helperContent,
125
+ renderEditButton()),
126
+ props.loadingIndicator && React.createElement("span", { className: "loading-indicator" }, props.loadingIndicator)))),
127
+ canShowContent && props.usePreformattedTag && React.createElement("pre", { id: props.inputId }, props.content),
128
+ React.createElement(React.Fragment, null,
129
+ React.createElement("div", { onBlur: onBlurChild, onKeyDown: handleKeyDown, className: "inlineEdit-wrapper", "data-tracking-id": "inline-edit-input-wrapper" },
130
+ !props.allowInlineEdit && props.children,
131
+ props.allowInlineEdit &&
132
+ isEditing &&
133
+ React.Children.map(props.children, (child) => {
134
+ if (!child)
135
+ return;
136
+ const canFocusChild = (child.type === 'input' || child.type === 'textarea') && canAutoSetFocus;
137
+ // if input/textarea had autoFocus but focus was lost in the wrapper component
138
+ const needsReFocus = !canAutoSetFocus && child.props.autoFocus;
139
+ if (canFocusChild || needsReFocus) {
140
+ return React.cloneElement(child, {
141
+ ref: (node) => {
142
+ node && node.focus();
143
+ setCanAutoSfocus(false);
144
+ },
145
+ });
146
+ }
147
+ else {
148
+ return child;
149
+ }
150
+ })))));
151
+ }
152
+ NewInlineEdit.defaultProps = defaultProps;
153
+ export { NewInlineEdit };
@@ -1,2 +1,3 @@
1
1
  export * from './InlineEdit';
2
+ export * from './NewInlineEdit';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/InlineEdit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/InlineEdit/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC"}
@@ -1 +1,2 @@
1
1
  export * from './InlineEdit';
2
+ export * from './NewInlineEdit';
@@ -27,18 +27,3 @@
27
27
  .case-overview .edit-question .loading-indicator {
28
28
  margin-left: 0px;
29
29
  }
30
-
31
- /* Character Count */
32
- .char-count {
33
- float: right;
34
- position: relative;
35
- padding-right: var(--pf-global--spacer--4xl);
36
- margin-right: var(--pf-global--spacer--lg);
37
- font-size: 12px;
38
- }
39
-
40
- @media (max-width: 415px) {
41
- .char-count {
42
- padding-right: var(--pf-global--spacer--2xl);
43
- }
44
- }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rh-support/components",
3
- "version": "1.2.16",
3
+ "version": "1.2.18",
4
4
  "description": "Contains all reusabel components for support app",
5
5
  "author": "Vikas Rathee <vrathee@redhat.com>",
6
6
  "license": "ISC",
@@ -110,6 +110,10 @@
110
110
  "storybook-readme": "^5.0.8",
111
111
  "use-deep-compare-effect": "^1.6.1"
112
112
  },
113
+ "resolutions": {
114
+ "@types/react": "17.0.14",
115
+ "@types/react-dom": "17.0.9"
116
+ },
113
117
  "devDependencies": {
114
118
  "@testing-library/jest-dom": "^5.14.1",
115
119
  "@testing-library/react": "^12.0.0",
@@ -117,8 +121,9 @@
117
121
  "@types/dompurify": "^2.2.1",
118
122
  "@types/lodash": "^4.14.136",
119
123
  "@types/marked": "^1.1.0",
120
- "@types/react": "^17.0.14",
124
+ "@types/react": "17.0.14",
121
125
  "@types/react-bootstrap-typeahead": "^5.1.3",
126
+ "@types/react-dom": "17.0.9",
122
127
  "identity-obj-proxy": "^3.0.0"
123
128
  },
124
129
  "browserslist": [
@@ -126,5 +131,5 @@
126
131
  "not ie <= 11",
127
132
  "not op_mini all"
128
133
  ],
129
- "gitHead": "af45effefff4d9434a171992428c249f80fc84ce"
134
+ "gitHead": "67c86ae65999c9e8d868a567bcd70f8d7401d386"
130
135
  }