@instructure/ui-editable 10.2.2-snapshot-2 → 10.2.2-snapshot-5
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 +180 -76
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-snapshot-
|
|
6
|
+
## [10.2.2-snapshot-5](https://github.com/instructure/instructure-ui/compare/v10.2.1...v10.2.2-snapshot-5) (2024-09-10)
|
|
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-snapshot-
|
|
3
|
+
"version": "10.2.2-snapshot-5",
|
|
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-snapshot-
|
|
27
|
-
"@instructure/ui-babel-preset": "10.2.2-snapshot-
|
|
26
|
+
"@instructure/ui-axe-check": "10.2.2-snapshot-5",
|
|
27
|
+
"@instructure/ui-babel-preset": "10.2.2-snapshot-5",
|
|
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-snapshot-
|
|
36
|
-
"@instructure/emotion": "10.2.2-snapshot-
|
|
37
|
-
"@instructure/shared-types": "10.2.2-snapshot-
|
|
38
|
-
"@instructure/ui-a11y-content": "10.2.2-snapshot-
|
|
39
|
-
"@instructure/ui-buttons": "10.2.2-snapshot-
|
|
40
|
-
"@instructure/ui-dom-utils": "10.2.2-snapshot-
|
|
41
|
-
"@instructure/ui-flex": "10.2.2-snapshot-
|
|
42
|
-
"@instructure/ui-focusable": "10.2.2-snapshot-
|
|
43
|
-
"@instructure/ui-icons": "10.2.2-snapshot-
|
|
44
|
-
"@instructure/ui-utils": "10.2.2-snapshot-
|
|
45
|
-
"@instructure/ui-view": "10.2.2-snapshot-
|
|
35
|
+
"@instructure/console": "10.2.2-snapshot-5",
|
|
36
|
+
"@instructure/emotion": "10.2.2-snapshot-5",
|
|
37
|
+
"@instructure/shared-types": "10.2.2-snapshot-5",
|
|
38
|
+
"@instructure/ui-a11y-content": "10.2.2-snapshot-5",
|
|
39
|
+
"@instructure/ui-buttons": "10.2.2-snapshot-5",
|
|
40
|
+
"@instructure/ui-dom-utils": "10.2.2-snapshot-5",
|
|
41
|
+
"@instructure/ui-flex": "10.2.2-snapshot-5",
|
|
42
|
+
"@instructure/ui-focusable": "10.2.2-snapshot-5",
|
|
43
|
+
"@instructure/ui-icons": "10.2.2-snapshot-5",
|
|
44
|
+
"@instructure/ui-utils": "10.2.2-snapshot-5",
|
|
45
|
+
"@instructure/ui-view": "10.2.2-snapshot-5",
|
|
46
46
|
"prop-types": "^15.8.1"
|
|
47
47
|
},
|
|
48
48
|
"peerDependencies": {
|
package/src/Editable/README.md
CHANGED
|
@@ -17,103 +17,207 @@ will find examples.
|
|
|
17
17
|
Using `Editable` gives you complete control, over how in-place editing
|
|
18
18
|
should look.
|
|
19
19
|
|
|
20
|
-
```js
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
- ```js
|
|
21
|
+
class Example extends React.Component {
|
|
22
|
+
constructor(props) {
|
|
23
|
+
super(props)
|
|
24
|
+
|
|
25
|
+
this.state = {
|
|
26
|
+
mode: props.mode || 'view',
|
|
27
|
+
value: props.value || '',
|
|
28
|
+
readOnly: false
|
|
29
|
+
}
|
|
30
|
+
}
|
|
25
31
|
|
|
26
|
-
|
|
27
|
-
|
|
32
|
+
renderButton({ isVisible, onClick, onFocus, onBlur, buttonRef }) {
|
|
33
|
+
if (this.state.readOnly) {
|
|
34
|
+
return null
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// To correctly handle focus, always return the Button, but
|
|
38
|
+
// only visible if isVisible (if you want the UI to work in the standard way)
|
|
39
|
+
return (
|
|
40
|
+
<span style={{ opacity: isVisible ? 1 : 0 }}>
|
|
41
|
+
<Button
|
|
42
|
+
size="small"
|
|
43
|
+
margin="0 0 0 x-small"
|
|
44
|
+
onClick={onClick}
|
|
45
|
+
onFocus={onFocus}
|
|
46
|
+
onBlur={onBlur}
|
|
47
|
+
elementRef={buttonRef}
|
|
48
|
+
>
|
|
49
|
+
Do it!
|
|
50
|
+
</Button>
|
|
51
|
+
</span>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
28
54
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
value: props.value || '',
|
|
32
|
-
buttonHasFocus: false,
|
|
33
|
-
readOnly: false
|
|
55
|
+
renderViewer() {
|
|
56
|
+
return <span>{this.state.value}</span>
|
|
34
57
|
}
|
|
35
|
-
this.onFocusEditButton = null;
|
|
36
|
-
}
|
|
37
58
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return null
|
|
59
|
+
handleValueChange = (event) => {
|
|
60
|
+
this.setState({ value: event.target.value })
|
|
41
61
|
}
|
|
42
62
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
onFocus={onFocus}
|
|
63
|
+
handleModeChange = (newMode) => {
|
|
64
|
+
this.setState({ mode: newMode })
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
renderEditor({ onBlur, editorRef }) {
|
|
68
|
+
return (
|
|
69
|
+
<input
|
|
70
|
+
ref={editorRef}
|
|
52
71
|
onBlur={onBlur}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
)
|
|
59
|
-
}
|
|
72
|
+
value={this.state.value}
|
|
73
|
+
onChange={this.handleValueChange}
|
|
74
|
+
/>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
60
77
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
78
|
+
renderMe = ({
|
|
79
|
+
mode,
|
|
80
|
+
getContainerProps,
|
|
81
|
+
getViewerProps,
|
|
82
|
+
getEditorProps,
|
|
83
|
+
getEditButtonProps
|
|
84
|
+
}) => {
|
|
85
|
+
return (
|
|
86
|
+
<View {...getContainerProps()}>
|
|
87
|
+
{mode === 'view' ? this.renderViewer(getViewerProps()) : null}
|
|
88
|
+
{mode === 'edit' ? this.renderEditor(getEditorProps()) : null}
|
|
89
|
+
{this.renderButton(getEditButtonProps())}
|
|
90
|
+
</View>
|
|
91
|
+
)
|
|
92
|
+
}
|
|
64
93
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
94
|
+
onChangeReadOnly = (event) => {
|
|
95
|
+
this.setState({ readOnly: event.target.checked })
|
|
96
|
+
}
|
|
68
97
|
|
|
69
|
-
|
|
70
|
-
|
|
98
|
+
render() {
|
|
99
|
+
return (
|
|
100
|
+
<View as="div">
|
|
101
|
+
<View as="div" margin="0 0 small 0">
|
|
102
|
+
<Checkbox
|
|
103
|
+
size="small"
|
|
104
|
+
label="Read Only"
|
|
105
|
+
checked={this.state.readOnly}
|
|
106
|
+
onChange={this.onChangeReadOnly}
|
|
107
|
+
/>
|
|
108
|
+
</View>
|
|
109
|
+
<Editable
|
|
110
|
+
mode={this.state.mode}
|
|
111
|
+
onChangeMode={this.handleModeChange}
|
|
112
|
+
render={this.renderMe}
|
|
113
|
+
value={this.state.value}
|
|
114
|
+
readOnly={this.state.readOnly}
|
|
115
|
+
/>
|
|
116
|
+
</View>
|
|
117
|
+
)
|
|
118
|
+
}
|
|
71
119
|
}
|
|
120
|
+
render(<Example value="you can edit me" />)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
- ```js
|
|
124
|
+
const Example = (props) => {
|
|
125
|
+
const [mode, setMode] = useState(props.mode || 'view')
|
|
126
|
+
const [value, setValue] = useState(props.value || '')
|
|
127
|
+
const [readOnly, setReadOnly] = useState(false)
|
|
128
|
+
|
|
129
|
+
const renderButton = ({
|
|
130
|
+
isVisible,
|
|
131
|
+
onClick,
|
|
132
|
+
onFocus,
|
|
133
|
+
onBlur,
|
|
134
|
+
buttonRef
|
|
135
|
+
}) => {
|
|
136
|
+
if (readOnly) {
|
|
137
|
+
return null
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// To correctly handle focus, always return the Button, but
|
|
141
|
+
// only visible if isVisible (if you want the UI to work in the standard way)
|
|
142
|
+
return (
|
|
143
|
+
<span style={{ opacity: isVisible ? 1 : 0 }}>
|
|
144
|
+
<Button
|
|
145
|
+
size="small"
|
|
146
|
+
margin="0 0 0 x-small"
|
|
147
|
+
onClick={onClick}
|
|
148
|
+
onFocus={onFocus}
|
|
149
|
+
onBlur={onBlur}
|
|
150
|
+
elementRef={buttonRef}
|
|
151
|
+
>
|
|
152
|
+
Do it!
|
|
153
|
+
</Button>
|
|
154
|
+
</span>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
72
157
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
ref={editorRef}
|
|
77
|
-
onBlur={onBlur}
|
|
78
|
-
value={this.state.value}
|
|
79
|
-
onChange={this.handleValueChange}
|
|
80
|
-
/>
|
|
81
|
-
)
|
|
82
|
-
}
|
|
158
|
+
const renderViewer = () => {
|
|
159
|
+
return <span>{value}</span>
|
|
160
|
+
}
|
|
83
161
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
{...getContainerProps()}
|
|
88
|
-
>
|
|
89
|
-
{mode === 'view' ? this.renderViewer(getViewerProps()) : null}
|
|
90
|
-
{mode === 'edit' ? this.renderEditor(getEditorProps()): null}
|
|
91
|
-
{this.renderButton(getEditButtonProps())}
|
|
92
|
-
</View>
|
|
93
|
-
)
|
|
94
|
-
}
|
|
162
|
+
const handleValueChange = (event) => {
|
|
163
|
+
setValue(event.target.value)
|
|
164
|
+
}
|
|
95
165
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
166
|
+
const handleModeChange = (newMode) => {
|
|
167
|
+
setMode(newMode)
|
|
168
|
+
}
|
|
99
169
|
|
|
100
|
-
|
|
101
|
-
|
|
170
|
+
const renderEditor = ({ onBlur, editorRef }) => {
|
|
171
|
+
return (
|
|
172
|
+
<input
|
|
173
|
+
ref={editorRef}
|
|
174
|
+
onBlur={onBlur}
|
|
175
|
+
value={value}
|
|
176
|
+
onChange={handleValueChange}
|
|
177
|
+
/>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const renderMe = ({
|
|
182
|
+
mode,
|
|
183
|
+
getContainerProps,
|
|
184
|
+
getViewerProps,
|
|
185
|
+
getEditorProps,
|
|
186
|
+
getEditButtonProps
|
|
187
|
+
}) => {
|
|
188
|
+
return (
|
|
189
|
+
<View {...getContainerProps()}>
|
|
190
|
+
{mode === 'view' ? renderViewer(getViewerProps()) : null}
|
|
191
|
+
{mode === 'edit' ? renderEditor(getEditorProps()) : null}
|
|
192
|
+
{renderButton(getEditButtonProps())}
|
|
193
|
+
</View>
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
const onChangeReadOnly = (event) => {
|
|
198
|
+
setReadOnly(event.target.checked)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return (
|
|
102
202
|
<View as="div">
|
|
103
203
|
<View as="div" margin="0 0 small 0">
|
|
104
|
-
<Checkbox
|
|
204
|
+
<Checkbox
|
|
205
|
+
size="small"
|
|
206
|
+
label="Read Only"
|
|
207
|
+
checked={readOnly}
|
|
208
|
+
onChange={onChangeReadOnly}
|
|
209
|
+
/>
|
|
105
210
|
</View>
|
|
106
211
|
<Editable
|
|
107
|
-
mode={
|
|
108
|
-
onChangeMode={
|
|
109
|
-
render={
|
|
110
|
-
value={
|
|
111
|
-
readOnly={
|
|
212
|
+
mode={mode}
|
|
213
|
+
onChangeMode={handleModeChange}
|
|
214
|
+
render={renderMe}
|
|
215
|
+
value={value}
|
|
216
|
+
readOnly={readOnly}
|
|
112
217
|
/>
|
|
113
218
|
</View>
|
|
114
219
|
)
|
|
115
220
|
}
|
|
116
221
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```
|
|
222
|
+
render(<Example value="you can edit me" />)
|
|
223
|
+
```
|