Skip to content

Commit 20094f8

Browse files
committed
chore: convert class components to functions in example code blocks
1 parent c55794b commit 20094f8

File tree

1 file changed

+72
-84
lines changed

1 file changed

+72
-84
lines changed

example/src/_examples.ts

Lines changed: 72 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
export const example1 = `import React, { Component } from 'react'
22
import EdiText from 'react-editext'
33
4-
export default class App extends Component {
5-
onSave = val => {
4+
export default function App() {
5+
function onSave(val) {
66
console.log('Edited Value -> ', val)
77
}
88
9-
render () {
10-
return (
11-
<EdiText
12-
type='text'
13-
value='What is real? How do you define real?'
14-
onSave={this.onSave}
15-
/>
16-
)
17-
}
9+
return (
10+
<EdiText
11+
type='text'
12+
value='What is real? How do you define real?'
13+
onSave={this.onSave}
14+
/>
15+
)
1816
}
1917
`
2018
export const example2 = `<EdiText
@@ -50,29 +48,27 @@ export const example4 = `<EdiText
5048
onSave={this.onSave}
5149
/>`
5250

53-
export const example5 = `export default class App extends Component {
54-
onSave = val => {
51+
export const example5 = `export default function App() {
52+
function onSave(val) {
5553
console.log('Edited Value -> ', val)
5654
}
5755
58-
validationFailed = textValue => {
56+
function validationFailed(textValue) {
5957
alert(\`The text <\${textValue}> is not valid.\nYou shall not use the word SMITH here!!!\`)
6058
}
6159
62-
render () {
63-
return (
64-
<EdiText
65-
type="text"
66-
validation={val => val.toLowerCase().indexOf('smith') < 0}
67-
onValidationFail={this.validationFailed}
68-
inputProps={{
69-
placeholder: "Don't use the word 'Smith'..."
70-
}}
71-
value="Why Mr. Anderson? Why? Why? Why?"
72-
onSave={this.onSave}
73-
/>
74-
)
75-
}
60+
return (
61+
<EdiText
62+
type="text"
63+
validation={val => val.toLowerCase().indexOf('smith') < 0}
64+
onValidationFail={this.validationFailed}
65+
inputProps={{
66+
placeholder: "Don't use the word 'Smith'..."
67+
}}
68+
value="Why Mr. Anderson? Why? Why? Why?"
69+
onSave={this.onSave}
70+
/>
71+
)
7672
}`
7773

7874
export const example6 = `<EdiText
@@ -173,28 +169,26 @@ export const example12 = `<EdiText
173169
export const example13 = `import React, { Component } from 'react'
174170
import EdiText from 'react-editext'
175171
176-
export default class App extends Component {
177-
onSave = val => {
172+
export default function App() {
173+
function onSave(val) {
178174
console.log('Edited Value -> ', val)
179175
}
180176
181-
render () {
182-
return (
183-
<EdiText
184-
viewContainerClassName='my-custom-view-wrapper'
185-
type='textarea'
186-
inputProps={{
187-
rows: 5
188-
}}
189-
saveButtonContent='Apply'
190-
cancelButtonContent={<strong>Cancel</strong>}
191-
editButtonContent='Edit This Quote'
192-
value="How do you define real? If you're talking about what you can feel, what you can smell,
193-
what you can taste and see, then real is simply electrical signals interpreted by your brain"
194-
onSave={this.onSave}
195-
/>
196-
)
197-
}
177+
return (
178+
<EdiText
179+
viewContainerClassName='my-custom-view-wrapper'
180+
type='textarea'
181+
inputProps={{
182+
rows: 5
183+
}}
184+
saveButtonContent='Apply'
185+
cancelButtonContent={<strong>Cancel</strong>}
186+
editButtonContent='Edit This Quote'
187+
value="How do you define real? If you're talking about what you can feel, what you can smell,
188+
what you can taste and see, then real is simply electrical signals interpreted by your brain"
189+
onSave={this.onSave}
190+
/>
191+
)
198192
}`
199193

200194
export const example13Style = `
@@ -214,41 +208,37 @@ export const example13Style = `
214208
export const example14 = `import React, { Component } from 'react'
215209
import EdiText from 'react-editext'
216210
217-
export default class App extends Component {
218-
onSave = val => {
211+
export default function App() {
212+
function onSave(val) {
219213
console.log('Edited Value -> ', val)
220214
}
221215
222-
render () {
223-
return (
224-
<EdiText
225-
type='text'
226-
buttonsAlign='before'
227-
value='What is real? How do you define real?'
228-
onSave={this.onSave}
229-
/>
230-
)
231-
}
216+
return (
217+
<EdiText
218+
type='text'
219+
buttonsAlign='before'
220+
value='What is real? How do you define real?'
221+
onSave={this.onSave}
222+
/>
223+
)
232224
}
233225
`
234226
export const example15 = `import React, { Component } from 'react'
235227
import EdiText from 'react-editext'
236228
237-
export default class App extends Component {
238-
onSave = val => {
229+
export default function App() {
230+
function onSave(val) {
239231
console.log('Edited Value -> ', val)
240232
}
241233
242-
render () {
243-
return (
244-
<EdiText
245-
type='text'
246-
value='What is real? How do you define real?'
247-
onSave={this.onSave}
248-
editOnViewClick={true}
249-
/>
250-
)
251-
}
234+
return (
235+
<EdiText
236+
type='text'
237+
value='What is real? How do you define real?'
238+
onSave={this.onSave}
239+
editOnViewClick={true}
240+
/>
241+
)
252242
}`
253243

254244
export const example16 = `import React, { Component } from 'react'
@@ -258,7 +248,7 @@ export default function App() {
258248
const [editing, setEditing] = useState(false)
259249
const [data, setData] = useState({ name: 'Wake up, Neo...' })
260250
261-
const onSave = val => {
251+
function onSave(val) {
262252
console.log('Edited Value -> ', val)
263253
}
264254
@@ -291,19 +281,17 @@ export default function App() {
291281
export const example17 = `import React, { Component } from 'react'
292282
import EdiText from 'react-editext'
293283
294-
export default class App extends Component {
284+
export default function App() {
295285
296-
render () {
297-
return (
298-
<EdiText
299-
type='text'
300-
onCancel={v => console.log('CANCELLED: ', v}
301-
onEditingStart={v => console.log('EDITING STARTED: ', v}
302-
onSave={v => console.log('SAVED: ', v}
303-
value={"You've been living in a dream world, Neo."}
304-
/>
305-
)
306-
}
286+
return (
287+
<EdiText
288+
type='text'
289+
onCancel={v => console.log('CANCELLED: ', v}
290+
onEditingStart={v => console.log('EDITING STARTED: ', v}
291+
onSave={v => console.log('SAVED: ', v}
292+
value={"You've been living in a dream world, Neo."}
293+
/>
294+
)
307295
}`
308296

309297
export const example18 = `<EdiText

0 commit comments

Comments
 (0)