@instructure/ui-editable 10.2.2-snapshot-17 → 10.2.2
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/package.json +14 -14
- package/src/InPlaceEdit/README.md +532 -274
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
|
-
## [10.2.2
|
|
6
|
+
## [10.2.2](https://github.com/instructure/instructure-ui/compare/v10.2.1...v10.2.2) (2024-09-13)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-editable
|
|
9
9
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-editable",
|
|
3
|
-
"version": "10.2.2
|
|
3
|
+
"version": "10.2.2",
|
|
4
4
|
"description": "A UI component library made by Instructure Inc.",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"module": "./es/index.js",
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-axe-check": "10.2.2
|
|
27
|
-
"@instructure/ui-babel-preset": "10.2.2
|
|
26
|
+
"@instructure/ui-axe-check": "10.2.2",
|
|
27
|
+
"@instructure/ui-babel-preset": "10.2.2",
|
|
28
28
|
"@testing-library/jest-dom": "^6.4.6",
|
|
29
29
|
"@testing-library/react": "^15.0.7",
|
|
30
30
|
"@testing-library/user-event": "^14.5.2",
|
|
@@ -32,17 +32,17 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@babel/runtime": "^7.24.5",
|
|
35
|
-
"@instructure/console": "10.2.2
|
|
36
|
-
"@instructure/emotion": "10.2.2
|
|
37
|
-
"@instructure/shared-types": "10.2.2
|
|
38
|
-
"@instructure/ui-a11y-content": "10.2.2
|
|
39
|
-
"@instructure/ui-buttons": "10.2.2
|
|
40
|
-
"@instructure/ui-dom-utils": "10.2.2
|
|
41
|
-
"@instructure/ui-flex": "10.2.2
|
|
42
|
-
"@instructure/ui-focusable": "10.2.2
|
|
43
|
-
"@instructure/ui-icons": "10.2.2
|
|
44
|
-
"@instructure/ui-utils": "10.2.2
|
|
45
|
-
"@instructure/ui-view": "10.2.2
|
|
35
|
+
"@instructure/console": "10.2.2",
|
|
36
|
+
"@instructure/emotion": "10.2.2",
|
|
37
|
+
"@instructure/shared-types": "10.2.2",
|
|
38
|
+
"@instructure/ui-a11y-content": "10.2.2",
|
|
39
|
+
"@instructure/ui-buttons": "10.2.2",
|
|
40
|
+
"@instructure/ui-dom-utils": "10.2.2",
|
|
41
|
+
"@instructure/ui-flex": "10.2.2",
|
|
42
|
+
"@instructure/ui-focusable": "10.2.2",
|
|
43
|
+
"@instructure/ui-icons": "10.2.2",
|
|
44
|
+
"@instructure/ui-utils": "10.2.2",
|
|
45
|
+
"@instructure/ui-view": "10.2.2",
|
|
46
46
|
"prop-types": "^15.8.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
|
@@ -31,352 +31,610 @@ the space it consumes in the app.
|
|
|
31
31
|
Use `InPlaceEdit` to edit `Text` using `Text as="input"`. Also demonstrates how you might wish to handle
|
|
32
32
|
the case when the text is empty. Use the checkbox to switch between inline and block layout.
|
|
33
33
|
|
|
34
|
-
```js
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
- ```js
|
|
35
|
+
class Example extends React.Component {
|
|
36
|
+
constructor(props) {
|
|
37
|
+
super(props)
|
|
38
|
+
this.state = {
|
|
39
|
+
mode: props.mode || 'view',
|
|
40
|
+
value: 'This is some text',
|
|
41
|
+
inline: true
|
|
42
|
+
}
|
|
43
|
+
}
|
|
39
44
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
value: 'This is some text',
|
|
45
|
-
inline: true
|
|
45
|
+
// You must provide this to Editable to be
|
|
46
|
+
// notified of mode changes
|
|
47
|
+
handleChangeMode = (mode) => {
|
|
48
|
+
this.setState({ mode })
|
|
46
49
|
}
|
|
47
|
-
}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// You attach an event handler to your edit component
|
|
52
|
+
// to be notified of value changes from user interactions
|
|
53
|
+
handleChange = (event) => {
|
|
54
|
+
this.setState({ value: event.target.value })
|
|
55
|
+
}
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
// Renders the view component
|
|
58
|
+
// Be sure to give it the current value
|
|
59
|
+
renderView = () => (
|
|
60
|
+
<Text
|
|
61
|
+
color={this.state.value ? 'primary' : 'secondary'}
|
|
62
|
+
weight={this.state.value ? 'normal' : 'light'}
|
|
63
|
+
size="large"
|
|
64
|
+
>
|
|
65
|
+
{this.state.value || 'Enter some text'}
|
|
66
|
+
</Text>
|
|
67
|
+
)
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
// Renders the edit button.
|
|
93
|
-
// Leverage the default implementation provided by InPlaceEdit
|
|
94
|
-
renderEditButton = (props) => {
|
|
95
|
-
props.label = `Edit title "${this.state.value}"`
|
|
96
|
-
return InPlaceEdit.renderDefaultEditButton(props)
|
|
97
|
-
}
|
|
69
|
+
// Renders the edit component.
|
|
70
|
+
// You have to forward the props on, which
|
|
71
|
+
// includes an onBlur property to help manage
|
|
72
|
+
// the mode changes.
|
|
73
|
+
// Be sure to give it the current value
|
|
74
|
+
renderEdit = ({ onBlur, editorRef }) => (
|
|
75
|
+
<Text
|
|
76
|
+
color="primary"
|
|
77
|
+
size="large"
|
|
78
|
+
as="input"
|
|
79
|
+
type="text"
|
|
80
|
+
value={this.state.value}
|
|
81
|
+
onChange={this.handleChange}
|
|
82
|
+
aria-label="The title"
|
|
83
|
+
onBlur={onBlur}
|
|
84
|
+
elementRef={editorRef}
|
|
85
|
+
/>
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
// Renders the edit button.
|
|
89
|
+
// Leverage the default implementation provided by InPlaceEdit
|
|
90
|
+
renderEditButton = (props) => {
|
|
91
|
+
props.label = `Edit title "${this.state.value}"`
|
|
92
|
+
return InPlaceEdit.renderDefaultEditButton(props)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
onChangeLayout = (event) => {
|
|
96
|
+
this.setState({ inline: event.target.checked })
|
|
97
|
+
}
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
render() {
|
|
100
|
+
return (
|
|
101
|
+
<View as="div">
|
|
102
|
+
<InPlaceEdit
|
|
103
|
+
renderViewer={this.renderView}
|
|
104
|
+
renderEditor={this.renderEdit}
|
|
105
|
+
renderEditButton={this.renderEditButton}
|
|
106
|
+
onChangeMode={this.handleChangeMode}
|
|
107
|
+
mode={this.state.mode}
|
|
108
|
+
value={this.state.value}
|
|
109
|
+
inline={this.state.inline}
|
|
110
|
+
/>
|
|
111
|
+
<View as="div" margin="small 0">
|
|
112
|
+
<Checkbox
|
|
113
|
+
label="inline"
|
|
114
|
+
checked={this.state.inline}
|
|
115
|
+
onChange={this.onChangeLayout}
|
|
116
|
+
/>
|
|
117
|
+
</View>
|
|
118
|
+
</View>
|
|
119
|
+
)
|
|
120
|
+
}
|
|
101
121
|
}
|
|
122
|
+
render(<Example />)
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
- ```js
|
|
126
|
+
const Example = (props) => {
|
|
127
|
+
const [mode, setMode] = useState(props.mode || 'view')
|
|
128
|
+
const [value, setValue] = useState('This is some text')
|
|
129
|
+
const [inline, setInline] = useState(true)
|
|
130
|
+
|
|
131
|
+
// You must provide this to Editable to be
|
|
132
|
+
// notified of mode changes
|
|
133
|
+
const handleChangeMode = (mode) => {
|
|
134
|
+
setMode(mode)
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// You attach an event handler to your edit component
|
|
138
|
+
// to be notified of value changes from user interactions
|
|
139
|
+
const handleChange = (event) => {
|
|
140
|
+
setValue(event.target.value)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Renders the view component
|
|
144
|
+
// Be sure to give it the current value
|
|
145
|
+
const renderView = () => (
|
|
146
|
+
<Text
|
|
147
|
+
color={value ? 'primary' : 'secondary'}
|
|
148
|
+
weight={value ? 'normal' : 'light'}
|
|
149
|
+
size="large"
|
|
150
|
+
>
|
|
151
|
+
{value || 'Enter some text'}
|
|
152
|
+
</Text>
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
// Renders the edit component.
|
|
156
|
+
// You have to forward the props on, which
|
|
157
|
+
// includes an onBlur property to help manage
|
|
158
|
+
// the mode changes.
|
|
159
|
+
// Be sure to give it the current value
|
|
160
|
+
const renderEdit = ({ onBlur, editorRef }) => (
|
|
161
|
+
<Text
|
|
162
|
+
color="primary"
|
|
163
|
+
size="large"
|
|
164
|
+
as="input"
|
|
165
|
+
type="text"
|
|
166
|
+
value={value}
|
|
167
|
+
onChange={handleChange}
|
|
168
|
+
aria-label="The title"
|
|
169
|
+
onBlur={onBlur}
|
|
170
|
+
elementRef={editorRef}
|
|
171
|
+
/>
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
// Renders the edit button.
|
|
175
|
+
// Leverage the default implementation provided by InPlaceEdit
|
|
176
|
+
const renderEditButton = (props) => {
|
|
177
|
+
props.label = `Edit title "${value}"`
|
|
178
|
+
return InPlaceEdit.renderDefaultEditButton(props)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const onChangeLayout = (event) => {
|
|
182
|
+
setInline(event.target.checked)
|
|
183
|
+
}
|
|
102
184
|
|
|
103
|
-
render () {
|
|
104
185
|
return (
|
|
105
186
|
<View as="div">
|
|
106
187
|
<InPlaceEdit
|
|
107
|
-
renderViewer={
|
|
108
|
-
renderEditor={
|
|
109
|
-
renderEditButton={
|
|
110
|
-
onChangeMode={
|
|
111
|
-
mode={
|
|
112
|
-
value={
|
|
113
|
-
inline={
|
|
188
|
+
renderViewer={renderView}
|
|
189
|
+
renderEditor={renderEdit}
|
|
190
|
+
renderEditButton={renderEditButton}
|
|
191
|
+
onChangeMode={handleChangeMode}
|
|
192
|
+
mode={mode}
|
|
193
|
+
value={value}
|
|
194
|
+
inline={inline}
|
|
114
195
|
/>
|
|
115
196
|
<View as="div" margin="small 0">
|
|
116
|
-
<Checkbox label="inline" checked={
|
|
197
|
+
<Checkbox label="inline" checked={inline} onChange={onChangeLayout} />
|
|
117
198
|
</View>
|
|
118
199
|
</View>
|
|
119
200
|
)
|
|
120
201
|
}
|
|
121
|
-
|
|
122
|
-
render(<Example />)
|
|
123
|
-
```
|
|
202
|
+
|
|
203
|
+
render(<Example />)
|
|
204
|
+
```
|
|
124
205
|
|
|
125
206
|
A readOnly `InPlaceEdit`
|
|
126
207
|
|
|
127
|
-
```js
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
208
|
+
- ```js
|
|
209
|
+
class Example extends React.Component {
|
|
210
|
+
constructor(props) {
|
|
211
|
+
super(props)
|
|
212
|
+
this.state = {
|
|
213
|
+
mode: props.mode || 'view',
|
|
214
|
+
value: 'This is some text'
|
|
215
|
+
}
|
|
216
|
+
}
|
|
132
217
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
value: 'This is some text',
|
|
218
|
+
// You must provide this to Editable to be
|
|
219
|
+
// notified of mode changes
|
|
220
|
+
handleChangeMode = (mode) => {
|
|
221
|
+
this.setState({ mode })
|
|
138
222
|
}
|
|
139
|
-
}
|
|
140
223
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
224
|
+
// You attach an event handler to your edit component
|
|
225
|
+
// to be notified of value changes from user interactions
|
|
226
|
+
handleChange = (event) => {
|
|
227
|
+
this.setState({ value: event.target.value })
|
|
228
|
+
}
|
|
146
229
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
230
|
+
// Renders the view component
|
|
231
|
+
// Be sure to give it the current value
|
|
232
|
+
renderView = () => <Text size="large">{this.state.value}</Text>
|
|
233
|
+
|
|
234
|
+
// Renders the edit component.
|
|
235
|
+
// You have to forward the props on, which
|
|
236
|
+
// includes an onBlur property to help manage
|
|
237
|
+
// the mode changes.
|
|
238
|
+
// Be sure to give it the current value
|
|
239
|
+
renderEdit = ({ onBlur, editorRef }) => (
|
|
240
|
+
<Text
|
|
241
|
+
size="large"
|
|
242
|
+
as="input"
|
|
243
|
+
type="text"
|
|
244
|
+
value={this.state.value}
|
|
245
|
+
onChange={this.handleChange}
|
|
246
|
+
aria-label="The title"
|
|
247
|
+
onBlur={onBlur}
|
|
248
|
+
elementRef={editorRef}
|
|
249
|
+
/>
|
|
250
|
+
)
|
|
152
251
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
aria-label="The title"
|
|
174
|
-
onBlur={onBlur}
|
|
175
|
-
elementRef={editorRef}
|
|
176
|
-
/>
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
// Renders the edit button.
|
|
180
|
-
// Leverage the default implementation provided by InPlaceEdit
|
|
181
|
-
renderEditButton = (props) => {
|
|
182
|
-
props.label = `Edit title "${this.state.value}"`
|
|
183
|
-
return InPlaceEdit.renderDefaultEditButton(props)
|
|
252
|
+
// Renders the edit button.
|
|
253
|
+
// Leverage the default implementation provided by InPlaceEdit
|
|
254
|
+
renderEditButton = (props) => {
|
|
255
|
+
props.label = `Edit title "${this.state.value}"`
|
|
256
|
+
return InPlaceEdit.renderDefaultEditButton(props)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
render() {
|
|
260
|
+
return (
|
|
261
|
+
<InPlaceEdit
|
|
262
|
+
readOnly
|
|
263
|
+
renderViewer={this.renderView}
|
|
264
|
+
renderEditor={this.renderEdit}
|
|
265
|
+
renderEditButton={this.renderEditButton}
|
|
266
|
+
onChangeMode={this.handleChangeMode}
|
|
267
|
+
mode={this.state.mode}
|
|
268
|
+
value={this.state.value}
|
|
269
|
+
/>
|
|
270
|
+
)
|
|
271
|
+
}
|
|
184
272
|
}
|
|
273
|
+
render(<Example />)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
- ```js
|
|
277
|
+
const Example = (props) => {
|
|
278
|
+
const [mode, setMode] = useState(props.mode || 'view')
|
|
279
|
+
const [value, setValue] = useState('This is some text')
|
|
280
|
+
|
|
281
|
+
// You must provide this to Editable to be
|
|
282
|
+
// notified of mode changes
|
|
283
|
+
const handleChangeMode = (mode) => {
|
|
284
|
+
setMode(mode)
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// You attach an event handler to your edit component
|
|
288
|
+
// to be notified of value changes from user interactions
|
|
289
|
+
const handleChange = (event) => {
|
|
290
|
+
setValue(event.target.value)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// Renders the view component
|
|
294
|
+
// Be sure to give it the current value
|
|
295
|
+
const renderView = () => <Text size="large">{value}</Text>
|
|
296
|
+
|
|
297
|
+
// Renders the edit component.
|
|
298
|
+
// You have to forward the props on, which
|
|
299
|
+
// includes an onBlur property to help manage
|
|
300
|
+
// the mode changes.
|
|
301
|
+
// Be sure to give it the current value
|
|
302
|
+
const renderEdit = ({ onBlur, editorRef }) => (
|
|
303
|
+
<Text
|
|
304
|
+
size="large"
|
|
305
|
+
as="input"
|
|
306
|
+
type="text"
|
|
307
|
+
value={value}
|
|
308
|
+
onChange={handleChange}
|
|
309
|
+
aria-label="The title"
|
|
310
|
+
onBlur={onBlur}
|
|
311
|
+
elementRef={editorRef}
|
|
312
|
+
/>
|
|
313
|
+
)
|
|
314
|
+
|
|
315
|
+
// Renders the edit button.
|
|
316
|
+
// Leverage the default implementation provided by InPlaceEdit
|
|
317
|
+
const renderEditButton = (props) => {
|
|
318
|
+
props.label = `Edit title "${value}"`
|
|
319
|
+
return InPlaceEdit.renderDefaultEditButton(props)
|
|
320
|
+
}
|
|
185
321
|
|
|
186
|
-
render () {
|
|
187
322
|
return (
|
|
188
323
|
<InPlaceEdit
|
|
189
324
|
readOnly
|
|
190
|
-
renderViewer={
|
|
191
|
-
renderEditor={
|
|
192
|
-
renderEditButton={
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
value={this.state.value}
|
|
325
|
+
renderViewer={renderView}
|
|
326
|
+
renderEditor={renderEdit}
|
|
327
|
+
renderEditButton={renderEditButton}
|
|
328
|
+
onChangeMode={handleChangeMode}
|
|
329
|
+
mode={mode}
|
|
330
|
+
value={value}
|
|
198
331
|
/>
|
|
199
332
|
)
|
|
200
333
|
}
|
|
201
|
-
|
|
202
|
-
render(<Example />)
|
|
203
|
-
```
|
|
334
|
+
|
|
335
|
+
render(<Example />)
|
|
336
|
+
```
|
|
204
337
|
|
|
205
338
|
To edit end-justified text, wrap `<InPlaceEdit />` in a
|
|
206
339
|
`<View>` component, as follows:
|
|
207
340
|
|
|
208
|
-
```js
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
341
|
+
- ```js
|
|
342
|
+
class Example extends React.Component {
|
|
343
|
+
constructor(props) {
|
|
344
|
+
super(props)
|
|
345
|
+
this.state = {
|
|
346
|
+
mode: props.mode || 'view',
|
|
347
|
+
value: 'This is some text'
|
|
348
|
+
}
|
|
349
|
+
}
|
|
213
350
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
value: 'This is some text',
|
|
351
|
+
// You must provide this to Editable to be
|
|
352
|
+
// notified of mode changes
|
|
353
|
+
handleChangeMode = (mode) => {
|
|
354
|
+
this.setState({ mode })
|
|
219
355
|
}
|
|
220
|
-
}
|
|
221
356
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
357
|
+
// You attach an event handler to your edit component
|
|
358
|
+
// to be notified of value changes from user interactions
|
|
359
|
+
handleChange = (event) => {
|
|
360
|
+
this.setState({ value: event.target.value })
|
|
361
|
+
}
|
|
227
362
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
363
|
+
// Renders the view component
|
|
364
|
+
// Be sure to give it the current value
|
|
365
|
+
renderView = () => <Text size="large">{this.state.value}</Text>
|
|
366
|
+
|
|
367
|
+
// Renders the edit component.
|
|
368
|
+
// You have to forward the props on, which
|
|
369
|
+
// includes an onBlur property to help manage
|
|
370
|
+
// the mode changes.
|
|
371
|
+
// Be sure to give it the current value
|
|
372
|
+
renderEdit = ({ onBlur, editorRef }) => (
|
|
373
|
+
<Text
|
|
374
|
+
size="large"
|
|
375
|
+
as="input"
|
|
376
|
+
type="text"
|
|
377
|
+
value={this.state.value}
|
|
378
|
+
onChange={this.handleChange}
|
|
379
|
+
aria-label="The title"
|
|
380
|
+
onBlur={onBlur}
|
|
381
|
+
elementRef={editorRef}
|
|
382
|
+
/>
|
|
383
|
+
)
|
|
233
384
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
elementRef={editorRef}
|
|
257
|
-
/>
|
|
258
|
-
)
|
|
259
|
-
|
|
260
|
-
// Renders the edit button.
|
|
261
|
-
// Leverage the default implementation provided by InPlaceEdit
|
|
262
|
-
renderEditButton = (props) => {
|
|
263
|
-
props.label = `Edit title "${this.state.value}"`
|
|
264
|
-
return InPlaceEdit.renderDefaultEditButton(props)
|
|
385
|
+
// Renders the edit button.
|
|
386
|
+
// Leverage the default implementation provided by InPlaceEdit
|
|
387
|
+
renderEditButton = (props) => {
|
|
388
|
+
props.label = `Edit title "${this.state.value}"`
|
|
389
|
+
return InPlaceEdit.renderDefaultEditButton(props)
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
render() {
|
|
393
|
+
return (
|
|
394
|
+
<View as="div" textAlign="end">
|
|
395
|
+
<InPlaceEdit
|
|
396
|
+
renderViewer={this.renderView}
|
|
397
|
+
renderEditor={this.renderEdit}
|
|
398
|
+
renderEditButton={this.renderEditButton}
|
|
399
|
+
onChangeMode={this.handleChangeMode}
|
|
400
|
+
mode={this.state.mode}
|
|
401
|
+
value={this.state.value}
|
|
402
|
+
editButtonPlacement="start"
|
|
403
|
+
/>
|
|
404
|
+
</View>
|
|
405
|
+
)
|
|
406
|
+
}
|
|
265
407
|
}
|
|
408
|
+
render(<Example />)
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
- ```js
|
|
412
|
+
const Example = (props) => {
|
|
413
|
+
const [mode, setMode] = useState(props.mode || 'view')
|
|
414
|
+
const [value, setValue] = useState('This is some text')
|
|
415
|
+
|
|
416
|
+
// You must provide this to Editable to be
|
|
417
|
+
// notified of mode changes
|
|
418
|
+
const handleChangeMode = (mode) => {
|
|
419
|
+
setMode(mode)
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// You attach an event handler to your edit component
|
|
423
|
+
// to be notified of value changes from user interactions
|
|
424
|
+
const handleChange = (event) => {
|
|
425
|
+
setValue(event.target.value)
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Renders the view component
|
|
429
|
+
// Be sure to give it the current value
|
|
430
|
+
const renderView = () => <Text size="large">{value}</Text>
|
|
431
|
+
|
|
432
|
+
// Renders the edit component.
|
|
433
|
+
// You have to forward the props on, which
|
|
434
|
+
// includes an onBlur property to help manage
|
|
435
|
+
// the mode changes.
|
|
436
|
+
// Be sure to give it the current value
|
|
437
|
+
const renderEdit = ({ onBlur, editorRef }) => (
|
|
438
|
+
<Text
|
|
439
|
+
size="large"
|
|
440
|
+
as="input"
|
|
441
|
+
type="text"
|
|
442
|
+
value={value}
|
|
443
|
+
onChange={handleChange}
|
|
444
|
+
aria-label="The title"
|
|
445
|
+
onBlur={onBlur}
|
|
446
|
+
elementRef={editorRef}
|
|
447
|
+
/>
|
|
448
|
+
)
|
|
449
|
+
|
|
450
|
+
// Renders the edit button.
|
|
451
|
+
// Leverage the default implementation provided by InPlaceEdit
|
|
452
|
+
const renderEditButton = (props) => {
|
|
453
|
+
props.label = `Edit title "${value}"`
|
|
454
|
+
return InPlaceEdit.renderDefaultEditButton(props)
|
|
455
|
+
}
|
|
266
456
|
|
|
267
|
-
render () {
|
|
268
457
|
return (
|
|
269
458
|
<View as="div" textAlign="end">
|
|
270
459
|
<InPlaceEdit
|
|
271
|
-
renderViewer={
|
|
272
|
-
renderEditor={
|
|
273
|
-
renderEditButton={
|
|
274
|
-
onChangeMode={
|
|
275
|
-
mode={
|
|
276
|
-
value={
|
|
277
|
-
editButtonPlacement=
|
|
460
|
+
renderViewer={renderView}
|
|
461
|
+
renderEditor={renderEdit}
|
|
462
|
+
renderEditButton={renderEditButton}
|
|
463
|
+
onChangeMode={handleChangeMode}
|
|
464
|
+
mode={mode}
|
|
465
|
+
value={value}
|
|
466
|
+
editButtonPlacement="start"
|
|
278
467
|
/>
|
|
279
468
|
</View>
|
|
280
469
|
)
|
|
281
470
|
}
|
|
282
|
-
|
|
283
|
-
render(<Example />)
|
|
284
|
-
```
|
|
471
|
+
|
|
472
|
+
render(<Example />)
|
|
473
|
+
```
|
|
285
474
|
|
|
286
475
|
Same as the first example, but notifies `Editable`'s `onChange`
|
|
287
476
|
when the user has finished editing and the value has changed.
|
|
288
477
|
|
|
289
|
-
```js
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
478
|
+
- ```js
|
|
479
|
+
class Example extends React.Component {
|
|
480
|
+
constructor(props) {
|
|
481
|
+
super(props)
|
|
482
|
+
this.state = {
|
|
483
|
+
mode: props.mode || 'view',
|
|
484
|
+
value: 'Edit me',
|
|
485
|
+
onChangeValue: undefined
|
|
486
|
+
}
|
|
487
|
+
}
|
|
294
488
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
onChangeValue: undefined,
|
|
489
|
+
// typically provided by the application so it can
|
|
490
|
+
// be notified of value changes when the user is
|
|
491
|
+
// finished editing
|
|
492
|
+
onChange = (newValue) => {
|
|
493
|
+
this.setState({ onChangeValue: newValue })
|
|
301
494
|
}
|
|
302
|
-
}
|
|
303
495
|
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
}
|
|
496
|
+
// You must provide this to Editable to be
|
|
497
|
+
// notified of mode changes
|
|
498
|
+
handleChangeMode = (mode) => {
|
|
499
|
+
this.setState({ mode })
|
|
500
|
+
}
|
|
310
501
|
|
|
502
|
+
// You attach an event handler to your edit component
|
|
503
|
+
// to be notified of value changes from user interactions
|
|
504
|
+
handleChange = (event) => {
|
|
505
|
+
this.setState({ value: event.target.value })
|
|
506
|
+
}
|
|
311
507
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
508
|
+
// Renders the view component
|
|
509
|
+
// Be sure to give it the current value
|
|
510
|
+
renderView = () => <Text size="large">{this.state.value}</Text>
|
|
511
|
+
|
|
512
|
+
// Renders the edit component.
|
|
513
|
+
// You have to forward the props on, which
|
|
514
|
+
// includes an onBlur property to help manage
|
|
515
|
+
// the mode changes.
|
|
516
|
+
// Be sure to give it the current value
|
|
517
|
+
renderEdit = ({ onBlur, editorRef }) => (
|
|
518
|
+
<Text
|
|
519
|
+
size="large"
|
|
520
|
+
as="input"
|
|
521
|
+
type="text"
|
|
522
|
+
value={this.state.value}
|
|
523
|
+
onChange={this.handleChange}
|
|
524
|
+
aria-label="The title"
|
|
525
|
+
onBlur={onBlur}
|
|
526
|
+
elementRef={editorRef}
|
|
527
|
+
/>
|
|
528
|
+
)
|
|
317
529
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
530
|
+
// Renders the edit button.
|
|
531
|
+
// Leverage the default implementation provided by InPlaceEdit
|
|
532
|
+
renderEditButton = (props) => {
|
|
533
|
+
props.label = `Edit title "${this.state.value}"`
|
|
534
|
+
return InPlaceEdit.renderDefaultEditButton(props)
|
|
535
|
+
}
|
|
323
536
|
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
elementRef={editorRef}
|
|
347
|
-
/>
|
|
348
|
-
)
|
|
349
|
-
|
|
350
|
-
// Renders the edit button.
|
|
351
|
-
// Leverage the default implementation provided by InPlaceEdit
|
|
352
|
-
renderEditButton = (props) => {
|
|
353
|
-
props.label = `Edit title "${this.state.value}"`
|
|
354
|
-
return InPlaceEdit.renderDefaultEditButton(props)
|
|
537
|
+
render() {
|
|
538
|
+
return (
|
|
539
|
+
<View as="div">
|
|
540
|
+
<InPlaceEdit
|
|
541
|
+
renderViewer={this.renderView}
|
|
542
|
+
renderEditor={this.renderEdit}
|
|
543
|
+
renderEditButton={this.renderEditButton}
|
|
544
|
+
onChangeMode={this.handleChangeMode}
|
|
545
|
+
mode={this.state.mode}
|
|
546
|
+
value={this.state.value}
|
|
547
|
+
onChange={this.onChange}
|
|
548
|
+
/>
|
|
549
|
+
<div>
|
|
550
|
+
<Text fontStyle="italic">
|
|
551
|
+
{this.state.onChangeValue !== undefined
|
|
552
|
+
? `onChange said: ${this.state.onChangeValue}`
|
|
553
|
+
: `You haven't edited me yet!`}
|
|
554
|
+
</Text>
|
|
555
|
+
</div>
|
|
556
|
+
</View>
|
|
557
|
+
)
|
|
558
|
+
}
|
|
355
559
|
}
|
|
560
|
+
render(<Example />)
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
- ```js
|
|
564
|
+
const Example = (props) => {
|
|
565
|
+
const [mode, setMode] = useState(props.mode || 'view')
|
|
566
|
+
const [value, setValue] = useState('Edit me')
|
|
567
|
+
const [onChangeValue, setOnChangeValue] = useState(undefined)
|
|
568
|
+
|
|
569
|
+
// typically provided by the application so it can
|
|
570
|
+
// be notified of value changes when the user is
|
|
571
|
+
// finished editing
|
|
572
|
+
const onChange = (newValue) => {
|
|
573
|
+
setOnChangeValue(newValue)
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
// You must provide this to Editable to be
|
|
577
|
+
// notified of mode changes
|
|
578
|
+
const handleChangeMode = (mode) => {
|
|
579
|
+
setMode(mode)
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
// You attach an event handler to your edit component
|
|
583
|
+
// to be notified of value changes from user interactions
|
|
584
|
+
const handleChange = (event) => {
|
|
585
|
+
setValue(event.target.value)
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// Renders the view component
|
|
589
|
+
// Be sure to give it the current value
|
|
590
|
+
const renderView = () => <Text size="large">{value}</Text>
|
|
591
|
+
|
|
592
|
+
// Renders the edit component.
|
|
593
|
+
// You have to forward the props on, which
|
|
594
|
+
// includes an onBlur property to help manage
|
|
595
|
+
// the mode changes.
|
|
596
|
+
// Be sure to give it the current value
|
|
597
|
+
const renderEdit = ({ onBlur, editorRef }) => (
|
|
598
|
+
<Text
|
|
599
|
+
size="large"
|
|
600
|
+
as="input"
|
|
601
|
+
type="text"
|
|
602
|
+
value={value}
|
|
603
|
+
onChange={handleChange}
|
|
604
|
+
aria-label="The title"
|
|
605
|
+
onBlur={onBlur}
|
|
606
|
+
elementRef={editorRef}
|
|
607
|
+
/>
|
|
608
|
+
)
|
|
609
|
+
|
|
610
|
+
// Renders the edit button.
|
|
611
|
+
// Leverage the default implementation provided by InPlaceEdit
|
|
612
|
+
const renderEditButton = (props) => {
|
|
613
|
+
props.label = `Edit title "${value}"`
|
|
614
|
+
return InPlaceEdit.renderDefaultEditButton(props)
|
|
615
|
+
}
|
|
356
616
|
|
|
357
|
-
render () {
|
|
358
617
|
return (
|
|
359
618
|
<View as="div">
|
|
360
619
|
<InPlaceEdit
|
|
361
|
-
renderViewer={
|
|
362
|
-
renderEditor={
|
|
363
|
-
renderEditButton={
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
value={this.state.value}
|
|
369
|
-
onChange={this.onChange}
|
|
620
|
+
renderViewer={renderView}
|
|
621
|
+
renderEditor={renderEdit}
|
|
622
|
+
renderEditButton={renderEditButton}
|
|
623
|
+
onChangeMode={handleChangeMode}
|
|
624
|
+
mode={mode}
|
|
625
|
+
value={value}
|
|
626
|
+
onChange={onChange}
|
|
370
627
|
/>
|
|
371
628
|
<div>
|
|
372
629
|
<Text fontStyle="italic">
|
|
373
|
-
{
|
|
374
|
-
? `onChange said: ${
|
|
630
|
+
{onChangeValue !== undefined
|
|
631
|
+
? `onChange said: ${onChangeValue}`
|
|
632
|
+
: `You haven't edited me yet!`}
|
|
375
633
|
</Text>
|
|
376
634
|
</div>
|
|
377
635
|
</View>
|
|
378
636
|
)
|
|
379
637
|
}
|
|
380
|
-
|
|
381
|
-
render(<Example />)
|
|
382
|
-
```
|
|
638
|
+
|
|
639
|
+
render(<Example />)
|
|
640
|
+
```
|