@instructure/ui-editable 10.2.1 → 10.2.2-pr-snapshot-1726164252153

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 CHANGED
@@ -3,6 +3,14 @@
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-pr-snapshot-1726164252153](https://github.com/instructure/instructure-ui/compare/v10.2.1...v10.2.2-pr-snapshot-1726164252153) (2024-09-12)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-editable
9
+
10
+
11
+
12
+
13
+
6
14
  ## [10.2.1](https://github.com/instructure/instructure-ui/compare/v10.2.0...v10.2.1) (2024-08-30)
7
15
 
8
16
  **Note:** Version bump only for package @instructure/ui-editable
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-editable",
3
- "version": "10.2.1",
3
+ "version": "10.2.2-pr-snapshot-1726164252153",
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.1",
27
- "@instructure/ui-babel-preset": "10.2.1",
26
+ "@instructure/ui-axe-check": "10.2.2-pr-snapshot-1726164252153",
27
+ "@instructure/ui-babel-preset": "10.2.2-pr-snapshot-1726164252153",
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.1",
36
- "@instructure/emotion": "10.2.1",
37
- "@instructure/shared-types": "10.2.1",
38
- "@instructure/ui-a11y-content": "10.2.1",
39
- "@instructure/ui-buttons": "10.2.1",
40
- "@instructure/ui-dom-utils": "10.2.1",
41
- "@instructure/ui-flex": "10.2.1",
42
- "@instructure/ui-focusable": "10.2.1",
43
- "@instructure/ui-icons": "10.2.1",
44
- "@instructure/ui-utils": "10.2.1",
45
- "@instructure/ui-view": "10.2.1",
35
+ "@instructure/console": "10.2.2-pr-snapshot-1726164252153",
36
+ "@instructure/emotion": "10.2.2-pr-snapshot-1726164252153",
37
+ "@instructure/shared-types": "10.2.2-pr-snapshot-1726164252153",
38
+ "@instructure/ui-a11y-content": "10.2.2-pr-snapshot-1726164252153",
39
+ "@instructure/ui-buttons": "10.2.2-pr-snapshot-1726164252153",
40
+ "@instructure/ui-dom-utils": "10.2.2-pr-snapshot-1726164252153",
41
+ "@instructure/ui-flex": "10.2.2-pr-snapshot-1726164252153",
42
+ "@instructure/ui-focusable": "10.2.2-pr-snapshot-1726164252153",
43
+ "@instructure/ui-icons": "10.2.2-pr-snapshot-1726164252153",
44
+ "@instructure/ui-utils": "10.2.2-pr-snapshot-1726164252153",
45
+ "@instructure/ui-view": "10.2.2-pr-snapshot-1726164252153",
46
46
  "prop-types": "^15.8.1"
47
47
  },
48
48
  "peerDependencies": {
@@ -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
- type: example
23
- ---
24
- class Example extends React.Component {
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
- constructor (props) {
27
- super(props)
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
- this.state = {
30
- mode: props.mode || 'view',
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
- renderButton ({ isVisible, onClick, onFocus, onBlur, buttonRef }) {
39
- if(this.state.readOnly) {
40
- return null
59
+ handleValueChange = (event) => {
60
+ this.setState({ value: event.target.value })
41
61
  }
42
62
 
43
- // To correctly handle focus, always return the Button, but
44
- // only visible if isVisible (if you want the UI to work in the standard way)
45
- return (
46
- <span style={{opacity: isVisible ? 1 : 0}}>
47
- <Button
48
- size="small"
49
- margin="0 0 0 x-small"
50
- onClick={onClick}
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
- elementRef={buttonRef}
54
- >
55
- Do it!
56
- </Button>
57
- </span>
58
- )
59
- }
72
+ value={this.state.value}
73
+ onChange={this.handleValueChange}
74
+ />
75
+ )
76
+ }
60
77
 
61
- renderViewer () {
62
- return <span>{this.state.value}</span>
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
- handleValueChange = (event) => {
66
- this.setState({value: event.target.value})
67
- }
94
+ onChangeReadOnly = (event) => {
95
+ this.setState({ readOnly: event.target.checked })
96
+ }
68
97
 
69
- handleModeChange = (newMode) => {
70
- this.setState({mode: newMode})
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
- renderEditor ({ onBlur, editorRef }) {
74
- return (
75
- <input
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
- renderMe = ({mode, getContainerProps, getViewerProps, getEditorProps, getEditButtonProps}) => {
85
- return (
86
- <View
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
- onChangeReadOnly = (event) => {
97
- this.setState({readOnly: event.target.checked})
98
- }
166
+ const handleModeChange = (newMode) => {
167
+ setMode(newMode)
168
+ }
99
169
 
100
- render () {
101
- return (
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 size="small" label="Read Only" checked={this.state.readOnly} onChange={this.onChangeReadOnly}/>
204
+ <Checkbox
205
+ size="small"
206
+ label="Read Only"
207
+ checked={readOnly}
208
+ onChange={onChangeReadOnly}
209
+ />
105
210
  </View>
106
211
  <Editable
107
- mode={this.state.mode}
108
- onChangeMode={this.handleModeChange}
109
- render={this.renderMe}
110
- value={this.state.value}
111
- readOnly={this.state.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
- render(<Example value="you can edit me" />)
119
- ```
222
+ render(<Example value="you can edit me" />)
223
+ ```