@instructure/ui-editable 8.25.1-snapshot-10 → 8.25.1-snapshot-15
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.
- package/CHANGELOG.md +1 -1
- package/es/Editable/index.js +143 -140
- package/es/Editable/props.js +0 -40
- package/es/InPlaceEdit/index.js +83 -82
- package/es/InPlaceEdit/props.js +0 -70
- package/lib/Editable/index.js +144 -141
- package/lib/Editable/props.js +0 -40
- package/lib/InPlaceEdit/index.js +83 -82
- package/lib/InPlaceEdit/props.js +0 -70
- package/package.json +13 -13
- package/src/Editable/index.tsx +33 -42
- package/src/Editable/props.ts +78 -31
- package/src/InPlaceEdit/index.tsx +29 -26
- package/src/InPlaceEdit/props.ts +62 -37
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/Editable/index.d.ts +30 -49
- package/types/Editable/index.d.ts.map +1 -1
- package/types/Editable/props.d.ts +75 -5
- package/types/Editable/props.d.ts.map +1 -1
- package/types/InPlaceEdit/index.d.ts +45 -38
- package/types/InPlaceEdit/index.d.ts.map +1 -1
- package/types/InPlaceEdit/props.d.ts +86 -5
- package/types/InPlaceEdit/props.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
## [8.25.1-snapshot-
|
|
6
|
+
## [8.25.1-snapshot-15](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-15) (2022-06-23)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-editable
|
|
9
9
|
|
package/es/Editable/index.js
CHANGED
|
@@ -32,26 +32,140 @@ import { propTypes, allowedProps } from './props';
|
|
|
32
32
|
category: components
|
|
33
33
|
experimental: true
|
|
34
34
|
---
|
|
35
|
+
@tsProps
|
|
35
36
|
**/
|
|
36
37
|
class Editable extends Component {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
38
|
+
constructor(_props) {
|
|
39
|
+
var _this;
|
|
40
|
+
|
|
41
|
+
super(_props);
|
|
42
|
+
_this = this;
|
|
43
|
+
this.state = {
|
|
44
|
+
showModeToggle: false,
|
|
45
|
+
valueOnEdit: null // the value when mode flips from view -> edit
|
|
46
|
+
|
|
47
|
+
};
|
|
48
|
+
this._editorRef = null;
|
|
49
|
+
this._editButtonRef = null;
|
|
50
|
+
|
|
51
|
+
this.handleEditESC = event => {
|
|
52
|
+
if (event.key === 'Escape') {
|
|
53
|
+
this.enterView();
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
this.handleViewMouseOver = event => {
|
|
58
|
+
if (this.props.mode === 'view') {
|
|
59
|
+
// because the mouse event handlers are on the container, not the view
|
|
60
|
+
event.stopPropagation();
|
|
61
|
+
this.setState({
|
|
62
|
+
showModeToggle: true
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
this.handleViewMouseOut = event => {
|
|
68
|
+
if (this.props.mode === 'view') {
|
|
69
|
+
event.stopPropagation();
|
|
70
|
+
this.setState({
|
|
71
|
+
showModeToggle: document.activeElement === this._editButtonRef
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
this.handleViewClick = event => {
|
|
77
|
+
if (event.buttons === 1) {
|
|
78
|
+
requestAnimationFrame(() => {
|
|
79
|
+
this.enterEdit();
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
this.handleEditBlur = () => {
|
|
85
|
+
this.enterView();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
this.handleEditButtonFocus = () => {
|
|
89
|
+
this.setState({
|
|
90
|
+
showModeToggle: true
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
this.handleEditButtonBlur = () => {
|
|
95
|
+
this.setState({
|
|
96
|
+
showModeToggle: false
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
this.handleEditButtonClick = () => {
|
|
101
|
+
this.enterEdit();
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
this.ref = null;
|
|
105
|
+
|
|
106
|
+
this.handleContainerRef = el => {
|
|
107
|
+
const elementRef = this.props.elementRef;
|
|
108
|
+
this.ref = el;
|
|
109
|
+
|
|
110
|
+
if (typeof elementRef === 'function') {
|
|
111
|
+
elementRef(el);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
this.getContainerProps = function () {
|
|
116
|
+
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
117
|
+
const _this$props = _this.props,
|
|
118
|
+
mode = _this$props.mode,
|
|
119
|
+
readOnly = _this$props.readOnly;
|
|
120
|
+
return {
|
|
121
|
+
onMouseOver: _this.handleViewMouseOver,
|
|
122
|
+
onMouseOut: _this.handleViewMouseOut,
|
|
123
|
+
onMouseDown: mode !== 'edit' ? _this.handleViewClick : void 0,
|
|
124
|
+
onKeyUp: mode === 'edit' ? _this.handleEditESC : void 0,
|
|
125
|
+
readOnly,
|
|
126
|
+
...props,
|
|
127
|
+
ref: _this.handleContainerRef
|
|
128
|
+
};
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
this.getViewerProps = function () {
|
|
132
|
+
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
133
|
+
return {
|
|
134
|
+
mode: _this.props.mode,
|
|
135
|
+
readOnly: _this.props.readOnly,
|
|
136
|
+
...props
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
this.getEditorProps = function () {
|
|
141
|
+
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
142
|
+
return {
|
|
143
|
+
mode: _this.props.mode,
|
|
144
|
+
onBlur: _this.handleEditBlur,
|
|
145
|
+
editorRef: el => {
|
|
146
|
+
_this._editorRef = el;
|
|
147
|
+
},
|
|
148
|
+
readOnly: _this.props.readOnly,
|
|
149
|
+
...props
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
this.getEditButtonProps = function () {
|
|
154
|
+
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
155
|
+
return {
|
|
156
|
+
onClick: _this.handleEditButtonClick,
|
|
157
|
+
onFocus: _this.handleEditButtonFocus,
|
|
158
|
+
onBlur: _this.handleEditButtonBlur,
|
|
159
|
+
isVisible: _this.state.showModeToggle,
|
|
160
|
+
buttonRef: el => {
|
|
161
|
+
_this._editButtonRef = el;
|
|
162
|
+
},
|
|
163
|
+
readOnly: _this.props.readOnly,
|
|
164
|
+
...props
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
warn(_props.readOnly ? _props.mode === 'view' : true, '[Editable] When readOnly is true, mode must be "view"');
|
|
55
169
|
}
|
|
56
170
|
|
|
57
171
|
componentDidMount() {
|
|
@@ -60,13 +174,11 @@ class Editable extends Component {
|
|
|
60
174
|
}
|
|
61
175
|
}
|
|
62
176
|
|
|
63
|
-
componentWillUnmount() {}
|
|
64
|
-
|
|
65
177
|
componentDidUpdate(prevProps) {
|
|
66
|
-
const _this$
|
|
67
|
-
mode = _this$
|
|
68
|
-
value = _this$
|
|
69
|
-
onChange = _this$
|
|
178
|
+
const _this$props2 = this.props,
|
|
179
|
+
mode = _this$props2.mode,
|
|
180
|
+
value = _this$props2.value,
|
|
181
|
+
onChange = _this$props2.onChange; // on the switch from view -> edit
|
|
70
182
|
|
|
71
183
|
if (prevProps.mode !== 'edit' && mode === 'edit') {
|
|
72
184
|
this.setState({
|
|
@@ -114,122 +226,6 @@ class Editable extends Component {
|
|
|
114
226
|
}
|
|
115
227
|
}
|
|
116
228
|
|
|
117
|
-
handleEditESC = event => {
|
|
118
|
-
if (event.key === 'Escape') {
|
|
119
|
-
this.enterView();
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
handleViewMouseOver = event => {
|
|
123
|
-
if (this.props.mode === 'view') {
|
|
124
|
-
// because the mouse event handlers are on the container, not the view
|
|
125
|
-
event.stopPropagation();
|
|
126
|
-
this.setState({
|
|
127
|
-
showModeToggle: true
|
|
128
|
-
});
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
handleViewMouseOut = event => {
|
|
132
|
-
if (this.props.mode === 'view') {
|
|
133
|
-
event.stopPropagation();
|
|
134
|
-
this.setState({
|
|
135
|
-
showModeToggle: document.activeElement === this._editButtonRef
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
handleViewClick = event => {
|
|
140
|
-
if (event.buttons === 1) {
|
|
141
|
-
requestAnimationFrame(() => {
|
|
142
|
-
this.enterEdit();
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
handleEditBlur = event => {
|
|
147
|
-
this.enterView();
|
|
148
|
-
};
|
|
149
|
-
handleEditButtonFocus = event => {
|
|
150
|
-
this.setState({
|
|
151
|
-
showModeToggle: true
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
handleEditButtonBlur = event => {
|
|
155
|
-
this.setState({
|
|
156
|
-
showModeToggle: false
|
|
157
|
-
});
|
|
158
|
-
};
|
|
159
|
-
handleEditButtonClick = event => {
|
|
160
|
-
this.enterEdit();
|
|
161
|
-
};
|
|
162
|
-
ref = null;
|
|
163
|
-
handleContainerRef = el => {
|
|
164
|
-
const elementRef = this.props.elementRef;
|
|
165
|
-
this.ref = el;
|
|
166
|
-
|
|
167
|
-
if (typeof elementRef === 'function') {
|
|
168
|
-
elementRef(el);
|
|
169
|
-
}
|
|
170
|
-
}; // ------- prop getters ------
|
|
171
|
-
|
|
172
|
-
getContainerProps = (() => {
|
|
173
|
-
var _this = this;
|
|
174
|
-
|
|
175
|
-
return function () {
|
|
176
|
-
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
177
|
-
const _this$props2 = _this.props,
|
|
178
|
-
mode = _this$props2.mode,
|
|
179
|
-
readOnly = _this$props2.readOnly;
|
|
180
|
-
return {
|
|
181
|
-
onMouseOver: _this.handleViewMouseOver,
|
|
182
|
-
onMouseOut: _this.handleViewMouseOut,
|
|
183
|
-
onMouseDown: mode !== 'edit' ? _this.handleViewClick : null,
|
|
184
|
-
onKeyUp: mode === 'edit' ? _this.handleEditESC : null,
|
|
185
|
-
readOnly,
|
|
186
|
-
...props,
|
|
187
|
-
ref: _this.handleContainerRef
|
|
188
|
-
};
|
|
189
|
-
};
|
|
190
|
-
})();
|
|
191
|
-
getViewerProps = (() => {
|
|
192
|
-
var _this2 = this;
|
|
193
|
-
|
|
194
|
-
return function () {
|
|
195
|
-
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
196
|
-
return {
|
|
197
|
-
mode: _this2.props.mode,
|
|
198
|
-
readOnly: _this2.props.readOnly,
|
|
199
|
-
...props
|
|
200
|
-
};
|
|
201
|
-
};
|
|
202
|
-
})();
|
|
203
|
-
getEditorProps = props => {
|
|
204
|
-
return {
|
|
205
|
-
mode: this.props.mode,
|
|
206
|
-
onBlur: this.handleEditBlur,
|
|
207
|
-
editorRef: el => {
|
|
208
|
-
this._editorRef = el;
|
|
209
|
-
},
|
|
210
|
-
readOnly: this.props.readOnly,
|
|
211
|
-
...props
|
|
212
|
-
};
|
|
213
|
-
};
|
|
214
|
-
getEditButtonProps = (() => {
|
|
215
|
-
var _this3 = this;
|
|
216
|
-
|
|
217
|
-
return function () {
|
|
218
|
-
let props = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
|
|
219
|
-
return {
|
|
220
|
-
onClick: _this3.handleEditButtonClick,
|
|
221
|
-
onFocus: _this3.handleEditButtonFocus,
|
|
222
|
-
onBlur: _this3.handleEditButtonBlur,
|
|
223
|
-
isVisible: _this3.state.showModeToggle,
|
|
224
|
-
buttonRef: el => {
|
|
225
|
-
_this3._editButtonRef = el;
|
|
226
|
-
},
|
|
227
|
-
readOnly: _this3.props.readOnly,
|
|
228
|
-
...props
|
|
229
|
-
};
|
|
230
|
-
};
|
|
231
|
-
})();
|
|
232
|
-
|
|
233
229
|
render() {
|
|
234
230
|
const _this$props3 = this.props,
|
|
235
231
|
children = _this$props3.children,
|
|
@@ -252,5 +248,12 @@ class Editable extends Component {
|
|
|
252
248
|
|
|
253
249
|
}
|
|
254
250
|
|
|
251
|
+
Editable.displayName = "Editable";
|
|
252
|
+
Editable.propTypes = propTypes;
|
|
253
|
+
Editable.allowedProps = allowedProps;
|
|
254
|
+
Editable.defaultProps = {
|
|
255
|
+
readOnly: false,
|
|
256
|
+
children: null
|
|
257
|
+
};
|
|
255
258
|
export default Editable;
|
|
256
259
|
export { Editable };
|
package/es/Editable/props.js
CHANGED
|
@@ -23,53 +23,13 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import PropTypes from 'prop-types';
|
|
25
25
|
const propTypes = {
|
|
26
|
-
/**
|
|
27
|
-
* If `'view'`: the view component is rendered,
|
|
28
|
-
* if `'edit'`: the edit component is rendered
|
|
29
|
-
*/
|
|
30
26
|
mode: PropTypes.oneOf(['view', 'edit']).isRequired,
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Called when the component's mode changes
|
|
34
|
-
* @param {string} new_mode
|
|
35
|
-
*/
|
|
36
27
|
onChangeMode: PropTypes.func.isRequired,
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @param {Object} renderProps
|
|
40
|
-
* @param {Boolean} mode
|
|
41
|
-
* @param {Function} renderProps.getContainerProps - Props to be spread onto the container element
|
|
42
|
-
* @param {Function} renderProps.getEditorProps - Props to be spread onto the editor element
|
|
43
|
-
* @param {Function} renderProps.getEditButtonProps - Props to be spread onto the edit button element
|
|
44
|
-
*/
|
|
45
28
|
children: PropTypes.func,
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Identical to children
|
|
49
|
-
*/
|
|
50
29
|
render: PropTypes.func,
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* The current value.
|
|
54
|
-
* The value is managed by the consuming app, but we need to tell Editable
|
|
55
|
-
* it's changed or it won't re-render
|
|
56
|
-
*/
|
|
57
30
|
value: PropTypes.any,
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Called when Editable switches from edit to view mode and the value has changed.
|
|
61
|
-
* @param {any} value
|
|
62
|
-
*/
|
|
63
31
|
onChange: PropTypes.func,
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* The mode is fixed as 'view'
|
|
67
|
-
*/
|
|
68
32
|
readOnly: PropTypes.bool,
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* provides a reference to the underlying html root element (container)
|
|
72
|
-
*/
|
|
73
33
|
elementRef: PropTypes.func
|
|
74
34
|
};
|
|
75
35
|
const allowedProps = ['mode', 'onChangeMode', 'children', 'render', 'value', 'onChange', 'readOnly', 'elementRef'];
|
package/es/InPlaceEdit/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
|
|
|
2
2
|
const _excluded = ["buttonRef"],
|
|
3
3
|
_excluded2 = ["isVisible", "readOnly", "label"];
|
|
4
4
|
|
|
5
|
-
var _dec, _class;
|
|
5
|
+
var _dec, _class, _class2;
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
8
|
* The MIT License (MIT)
|
|
@@ -45,50 +45,67 @@ import { propTypes, allowedProps } from './props';
|
|
|
45
45
|
---
|
|
46
46
|
category: components
|
|
47
47
|
---
|
|
48
|
+
@tsProps
|
|
48
49
|
**/
|
|
49
|
-
let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class InPlaceEdit extends Component {
|
|
50
|
-
static displayName = "InPlaceEdit";
|
|
51
|
-
static componentId = 'InPlaceEdit';
|
|
52
|
-
static propTypes = propTypes;
|
|
53
|
-
static allowedProps = allowedProps;
|
|
54
|
-
static defaultProps = {
|
|
55
|
-
readOnly: false,
|
|
56
|
-
showFocusRing: true,
|
|
57
|
-
inline: true,
|
|
58
|
-
editButtonPlacement: 'end'
|
|
59
|
-
};
|
|
60
|
-
ref = null;
|
|
61
|
-
handleRef = el => {
|
|
62
|
-
this.ref = el;
|
|
63
|
-
};
|
|
64
|
-
|
|
50
|
+
let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = (_class2 = class InPlaceEdit extends Component {
|
|
65
51
|
constructor(props) {
|
|
66
52
|
super(props);
|
|
53
|
+
this.ref = null;
|
|
54
|
+
this._editButtonRef = null;
|
|
55
|
+
|
|
56
|
+
this.handleRef = el => {
|
|
57
|
+
this.ref = el;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
this.handleEditButtonRef = el => {
|
|
61
|
+
this._editButtonRef = el;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
this.renderAll = _ref => {
|
|
65
|
+
let getContainerProps = _ref.getContainerProps,
|
|
66
|
+
getViewerProps = _ref.getViewerProps,
|
|
67
|
+
getEditorProps = _ref.getEditorProps,
|
|
68
|
+
getEditButtonProps = _ref.getEditButtonProps;
|
|
69
|
+
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
70
|
+
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
71
|
+
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
72
|
+
return jsx(Flex, Object.assign({
|
|
73
|
+
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
74
|
+
direction: flexDir,
|
|
75
|
+
justifyItems: justifyItems
|
|
76
|
+
}, getContainerProps()), jsx(Flex.Item, {
|
|
77
|
+
shouldGrow: true,
|
|
78
|
+
shouldShrink: true
|
|
79
|
+
}, this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())), jsx(Flex.Item, {
|
|
80
|
+
margin: buttonMargin
|
|
81
|
+
}, this.renderEditButton(getEditButtonProps())));
|
|
82
|
+
};
|
|
83
|
+
|
|
67
84
|
warn(props.readOnly ? props.mode === 'view' : true, '[InPlaceEdit] When readOnly is true, mode is forced to "view"');
|
|
68
85
|
}
|
|
69
86
|
|
|
70
87
|
componentDidMount() {
|
|
71
|
-
|
|
72
|
-
}
|
|
88
|
+
var _this$props$makeStyle, _this$props;
|
|
73
89
|
|
|
74
|
-
|
|
75
|
-
this.props.makeStyles();
|
|
90
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props);
|
|
76
91
|
}
|
|
77
92
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
93
|
+
componentDidUpdate() {
|
|
94
|
+
var _this$props$makeStyle2, _this$props2;
|
|
95
|
+
|
|
96
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2);
|
|
97
|
+
}
|
|
81
98
|
|
|
82
|
-
renderEditor(
|
|
99
|
+
renderEditor(_ref2) {
|
|
83
100
|
var _this$props$styles;
|
|
84
101
|
|
|
85
|
-
let mode =
|
|
86
|
-
onBlur =
|
|
87
|
-
editorRef =
|
|
88
|
-
readOnly =
|
|
89
|
-
const _this$
|
|
90
|
-
showFocusRing = _this$
|
|
91
|
-
renderEditor = _this$
|
|
102
|
+
let mode = _ref2.mode,
|
|
103
|
+
onBlur = _ref2.onBlur,
|
|
104
|
+
editorRef = _ref2.editorRef,
|
|
105
|
+
readOnly = _ref2.readOnly;
|
|
106
|
+
const _this$props3 = this.props,
|
|
107
|
+
showFocusRing = _this$props3.showFocusRing,
|
|
108
|
+
renderEditor = _this$props3.renderEditor;
|
|
92
109
|
const isEditMode = !readOnly && mode === 'edit';
|
|
93
110
|
return isEditMode ? jsx(View, {
|
|
94
111
|
as: "span",
|
|
@@ -104,15 +121,15 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class In
|
|
|
104
121
|
})) : null;
|
|
105
122
|
}
|
|
106
123
|
|
|
107
|
-
renderViewer(
|
|
108
|
-
let readOnly =
|
|
109
|
-
mode =
|
|
124
|
+
renderViewer(_ref3) {
|
|
125
|
+
let readOnly = _ref3.readOnly,
|
|
126
|
+
mode = _ref3.mode;
|
|
110
127
|
return readOnly || mode === 'view' ? this.props.renderViewer() : null;
|
|
111
128
|
}
|
|
112
129
|
|
|
113
|
-
renderEditButton(
|
|
114
|
-
let buttonRef =
|
|
115
|
-
rest = _objectWithoutProperties(
|
|
130
|
+
renderEditButton(_ref4) {
|
|
131
|
+
let buttonRef = _ref4.buttonRef,
|
|
132
|
+
rest = _objectWithoutProperties(_ref4, _excluded);
|
|
116
133
|
|
|
117
134
|
return this.props.renderEditButton({
|
|
118
135
|
elementRef: createChainedFunction(this.handleEditButtonRef, buttonRef),
|
|
@@ -122,50 +139,13 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class In
|
|
|
122
139
|
// the margin makes room for the focus ring
|
|
123
140
|
|
|
124
141
|
|
|
125
|
-
static renderDefaultEditButton = _ref4 => {
|
|
126
|
-
let isVisible = _ref4.isVisible,
|
|
127
|
-
readOnly = _ref4.readOnly,
|
|
128
|
-
label = _ref4.label,
|
|
129
|
-
buttonProps = _objectWithoutProperties(_ref4, _excluded2);
|
|
130
|
-
|
|
131
|
-
if (readOnly) {
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return jsx(IconButton, Object.assign({
|
|
136
|
-
size: "small",
|
|
137
|
-
screenReaderLabel: label,
|
|
138
|
-
withBackground: false,
|
|
139
|
-
withBorder: false
|
|
140
|
-
}, buttonProps), isVisible ? IconEditLine : null);
|
|
141
|
-
};
|
|
142
|
-
renderAll = _ref5 => {
|
|
143
|
-
let getContainerProps = _ref5.getContainerProps,
|
|
144
|
-
getViewerProps = _ref5.getViewerProps,
|
|
145
|
-
getEditorProps = _ref5.getEditorProps,
|
|
146
|
-
getEditButtonProps = _ref5.getEditButtonProps;
|
|
147
|
-
const flexDir = this.props.editButtonPlacement === 'start' ? 'row-reverse' : 'row';
|
|
148
|
-
const justifyItems = flexDir === 'row-reverse' ? 'end' : 'start';
|
|
149
|
-
const buttonMargin = this.props.editButtonPlacement === 'start' ? '0 xx-small 0 0' : '0 0 0 xx-small';
|
|
150
|
-
return jsx(Flex, Object.assign({
|
|
151
|
-
display: this.props.inline ? 'inline-flex' : 'flex',
|
|
152
|
-
direction: flexDir,
|
|
153
|
-
justifyItems: justifyItems
|
|
154
|
-
}, getContainerProps()), jsx(Flex.Item, {
|
|
155
|
-
shouldGrow: true,
|
|
156
|
-
shouldShrink: true
|
|
157
|
-
}, this.renderEditor(getEditorProps()), this.renderViewer(getViewerProps())), jsx(Flex.Item, {
|
|
158
|
-
margin: buttonMargin
|
|
159
|
-
}, this.renderEditButton(getEditButtonProps())));
|
|
160
|
-
};
|
|
161
|
-
|
|
162
142
|
render() {
|
|
163
|
-
const _this$
|
|
164
|
-
mode = _this$
|
|
165
|
-
value = _this$
|
|
166
|
-
onChange = _this$
|
|
167
|
-
onChangeMode = _this$
|
|
168
|
-
readOnly = _this$
|
|
143
|
+
const _this$props4 = this.props,
|
|
144
|
+
mode = _this$props4.mode,
|
|
145
|
+
value = _this$props4.value,
|
|
146
|
+
onChange = _this$props4.onChange,
|
|
147
|
+
onChangeMode = _this$props4.onChangeMode,
|
|
148
|
+
readOnly = _this$props4.readOnly;
|
|
169
149
|
return jsx(Editable, {
|
|
170
150
|
mode: mode,
|
|
171
151
|
onChangeMode: onChangeMode,
|
|
@@ -177,6 +157,27 @@ let InPlaceEdit = (_dec = withStyle(generateStyle, null), _dec(_class = class In
|
|
|
177
157
|
});
|
|
178
158
|
}
|
|
179
159
|
|
|
180
|
-
}
|
|
160
|
+
}, _class2.displayName = "InPlaceEdit", _class2.componentId = 'InPlaceEdit', _class2.propTypes = propTypes, _class2.allowedProps = allowedProps, _class2.defaultProps = {
|
|
161
|
+
readOnly: false,
|
|
162
|
+
showFocusRing: true,
|
|
163
|
+
inline: true,
|
|
164
|
+
editButtonPlacement: 'end'
|
|
165
|
+
}, _class2.renderDefaultEditButton = _ref5 => {
|
|
166
|
+
let isVisible = _ref5.isVisible,
|
|
167
|
+
readOnly = _ref5.readOnly,
|
|
168
|
+
label = _ref5.label,
|
|
169
|
+
buttonProps = _objectWithoutProperties(_ref5, _excluded2);
|
|
170
|
+
|
|
171
|
+
if (readOnly) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return jsx(IconButton, Object.assign({
|
|
176
|
+
size: "small",
|
|
177
|
+
screenReaderLabel: label,
|
|
178
|
+
withBackground: false,
|
|
179
|
+
withBorder: false
|
|
180
|
+
}, buttonProps), isVisible ? IconEditLine : null);
|
|
181
|
+
}, _class2)) || _class);
|
|
181
182
|
export default InPlaceEdit;
|
|
182
183
|
export { InPlaceEdit };
|
package/es/InPlaceEdit/props.js
CHANGED
|
@@ -23,86 +23,16 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import PropTypes from 'prop-types';
|
|
25
25
|
const propTypes = {
|
|
26
|
-
/**
|
|
27
|
-
* Function to render the view mode component.
|
|
28
|
-
* It is the consumer's responsibility to provide the
|
|
29
|
-
* current value or children.
|
|
30
|
-
*
|
|
31
|
-
* @returns {element} the viewer DOM sub-tree.
|
|
32
|
-
*/
|
|
33
26
|
renderViewer: PropTypes.func.isRequired,
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Function to render the edit mode component
|
|
37
|
-
* It is the consumer's responsibility to provide the
|
|
38
|
-
* current value, and to attach the appropriate onChange
|
|
39
|
-
* event handler needed to capture the updated value. This
|
|
40
|
-
* new value must then be forwarded to the view mode component.
|
|
41
|
-
*
|
|
42
|
-
* @returns {element} the editor DOM sub-tree.
|
|
43
|
-
*/
|
|
44
27
|
renderEditor: PropTypes.func.isRequired,
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Function to render the edit button.
|
|
48
|
-
*
|
|
49
|
-
* @param {Object} { isVisible, onClick, onFocus, onBlur, buttonRef }
|
|
50
|
-
* @returns {element} the edit button DOM sub-tree
|
|
51
|
-
*
|
|
52
|
-
* If you choose to use the default edit button, add `label` to the
|
|
53
|
-
* incoming `props` parameter and call `InPlaceEdit.renderDefaultEditButton(props)`
|
|
54
|
-
*
|
|
55
|
-
* If you choose to render a custom button, attach the on* event handlers
|
|
56
|
-
* and set `buttonRef` as a `ref` type property on the `button` element.
|
|
57
|
-
*
|
|
58
|
-
* `isVisible` is a hint as to whether the button is _typically_ shown,
|
|
59
|
-
* but you're free to ignore it for your use-case.
|
|
60
|
-
*/
|
|
61
28
|
renderEditButton: PropTypes.func.isRequired,
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* If `'view'`: the view component is rendered,
|
|
65
|
-
* if `'edit'`: the edit component is rendered
|
|
66
|
-
*/
|
|
67
29
|
mode: PropTypes.oneOf(['view', 'edit']).isRequired,
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Called when the component's mode changes
|
|
71
|
-
* @param {string} newMode
|
|
72
|
-
*/
|
|
73
30
|
onChangeMode: PropTypes.func.isRequired,
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* The current value.
|
|
77
|
-
* The value is managed by the consuming app, but we need to tell InPlaceEdit
|
|
78
|
-
* it's changed or it won't re-render
|
|
79
|
-
*/
|
|
80
31
|
value: PropTypes.any,
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Called when Editable switches from edit to view mode and the value has changed.
|
|
84
|
-
* @param {any} value
|
|
85
|
-
*/
|
|
86
32
|
onChange: PropTypes.func,
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* The mode is fixed as 'view'
|
|
90
|
-
*/
|
|
91
33
|
readOnly: PropTypes.bool,
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Show a focus outline when the input is focused
|
|
95
|
-
*/
|
|
96
34
|
showFocusRing: PropTypes.bool,
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Put the edit button before or after the view
|
|
100
|
-
*/
|
|
101
35
|
editButtonPlacement: PropTypes.oneOf(['start', 'end']),
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Render outermost element inline v. block
|
|
105
|
-
*/
|
|
106
36
|
inline: PropTypes.bool
|
|
107
37
|
};
|
|
108
38
|
const allowedProps = ['renderViewer', 'renderEditor', 'renderEditButton', 'mode', 'onChangeMode', 'value', 'onChange', 'readOnly', 'showFocusRing', 'editButtonPlacement', 'inline'];
|