@instructure/ui-editable 11.0.1-snapshot-0 → 11.0.1-snapshot-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/Editable/README.md +92 -192
- package/src/InPlaceEdit/README.md +20 -322
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -31,98 +31,10 @@ 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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.state = {
|
|
39
|
-
mode: props.mode || 'view',
|
|
40
|
-
value: 'This is some text',
|
|
41
|
-
inline: true
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// You must provide this to Editable to be
|
|
46
|
-
// notified of mode changes
|
|
47
|
-
handleChangeMode = (mode) => {
|
|
48
|
-
this.setState({ mode })
|
|
49
|
-
}
|
|
50
|
-
|
|
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
|
-
}
|
|
56
|
-
|
|
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
|
-
)
|
|
68
|
-
|
|
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
|
-
|
|
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
|
-
}
|
|
121
|
-
}
|
|
122
|
-
render(<Example />)
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
- ```js
|
|
34
|
+
```js
|
|
35
|
+
---
|
|
36
|
+
type: example
|
|
37
|
+
---
|
|
126
38
|
const Example = (props) => {
|
|
127
39
|
const [mode, setMode] = useState(props.mode || 'view')
|
|
128
40
|
const [value, setValue] = useState('This is some text')
|
|
@@ -201,79 +113,14 @@ the case when the text is empty. Use the checkbox to switch between inline and b
|
|
|
201
113
|
}
|
|
202
114
|
|
|
203
115
|
render(<Example />)
|
|
204
|
-
|
|
116
|
+
```
|
|
205
117
|
|
|
206
118
|
A readOnly `InPlaceEdit`
|
|
207
119
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
this.state = {
|
|
213
|
-
mode: props.mode || 'view',
|
|
214
|
-
value: 'This is some text'
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
// You must provide this to Editable to be
|
|
219
|
-
// notified of mode changes
|
|
220
|
-
handleChangeMode = (mode) => {
|
|
221
|
-
this.setState({ mode })
|
|
222
|
-
}
|
|
223
|
-
|
|
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
|
-
}
|
|
229
|
-
|
|
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
|
-
)
|
|
251
|
-
|
|
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
|
-
}
|
|
272
|
-
}
|
|
273
|
-
render(<Example />)
|
|
274
|
-
```
|
|
275
|
-
|
|
276
|
-
- ```js
|
|
120
|
+
```js
|
|
121
|
+
---
|
|
122
|
+
type: example
|
|
123
|
+
---
|
|
277
124
|
const Example = (props) => {
|
|
278
125
|
const [mode, setMode] = useState(props.mode || 'view')
|
|
279
126
|
const [value, setValue] = useState('This is some text')
|
|
@@ -333,82 +180,15 @@ A readOnly `InPlaceEdit`
|
|
|
333
180
|
}
|
|
334
181
|
|
|
335
182
|
render(<Example />)
|
|
336
|
-
|
|
183
|
+
```
|
|
337
184
|
|
|
338
185
|
To edit end-justified text, wrap `<InPlaceEdit />` in a
|
|
339
186
|
`<View>` component, as follows:
|
|
340
187
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
this.state = {
|
|
346
|
-
mode: props.mode || 'view',
|
|
347
|
-
value: 'This is some text'
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// You must provide this to Editable to be
|
|
352
|
-
// notified of mode changes
|
|
353
|
-
handleChangeMode = (mode) => {
|
|
354
|
-
this.setState({ mode })
|
|
355
|
-
}
|
|
356
|
-
|
|
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
|
-
}
|
|
362
|
-
|
|
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
|
-
)
|
|
384
|
-
|
|
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
|
-
}
|
|
407
|
-
}
|
|
408
|
-
render(<Example />)
|
|
409
|
-
```
|
|
410
|
-
|
|
411
|
-
- ```js
|
|
188
|
+
```js
|
|
189
|
+
---
|
|
190
|
+
type: example
|
|
191
|
+
---
|
|
412
192
|
const Example = (props) => {
|
|
413
193
|
const [mode, setMode] = useState(props.mode || 'view')
|
|
414
194
|
const [value, setValue] = useState('This is some text')
|
|
@@ -470,97 +250,15 @@ To edit end-justified text, wrap `<InPlaceEdit />` in a
|
|
|
470
250
|
}
|
|
471
251
|
|
|
472
252
|
render(<Example />)
|
|
473
|
-
|
|
253
|
+
```
|
|
474
254
|
|
|
475
255
|
Same as the first example, but notifies `Editable`'s `onChange`
|
|
476
256
|
when the user has finished editing and the value has changed.
|
|
477
257
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
this.state = {
|
|
483
|
-
mode: props.mode || 'view',
|
|
484
|
-
value: 'Edit me',
|
|
485
|
-
onChangeValue: undefined
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
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 })
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// You must provide this to Editable to be
|
|
497
|
-
// notified of mode changes
|
|
498
|
-
handleChangeMode = (mode) => {
|
|
499
|
-
this.setState({ mode })
|
|
500
|
-
}
|
|
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
|
-
}
|
|
507
|
-
|
|
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
|
-
)
|
|
529
|
-
|
|
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
|
-
}
|
|
536
|
-
|
|
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
|
-
}
|
|
559
|
-
}
|
|
560
|
-
render(<Example />)
|
|
561
|
-
```
|
|
562
|
-
|
|
563
|
-
- ```js
|
|
258
|
+
```js
|
|
259
|
+
---
|
|
260
|
+
type: example
|
|
261
|
+
---
|
|
564
262
|
const Example = (props) => {
|
|
565
263
|
const [mode, setMode] = useState(props.mode || 'view')
|
|
566
264
|
const [value, setValue] = useState('Edit me')
|
|
@@ -637,4 +335,4 @@ when the user has finished editing and the value has changed.
|
|
|
637
335
|
}
|
|
638
336
|
|
|
639
337
|
render(<Example />)
|
|
640
|
-
|
|
338
|
+
```
|