Skip to content

Commit

Permalink
docs: convert examples to be functional components
Browse files Browse the repository at this point in the history
  • Loading branch information
layershifter committed Dec 30, 2023
1 parent 5646905 commit 6b54e0b
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 118 deletions.
47 changes: 24 additions & 23 deletions docs/src/examples/addons/Confirm/Types/ConfirmExampleCallbacks.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
import React, { Component } from 'react'
import React from 'react'
import { Button, Confirm } from 'semantic-ui-react'

class ConfirmExampleCallbacks extends Component {
state = { open: false, result: 'show the modal to capture a result' }
function ConfirmExampleCallbacks() {
const [open, setOpen] = React.useState(false)
const [result, setResult] = React.useState(
'show the modal to capture a result',
)

show = () => this.setState({ open: true })
handleConfirm = () => this.setState({ result: 'confirmed', open: false })
handleCancel = () => this.setState({ result: 'cancelled', open: false })

render() {
const { open, result } = this.state
const show = () => setOpen(true)
const handleConfirm = () => {
setResult('confirmed')
setOpen(false)
}
const handleCancel = () => {
setResult('cancelled')
setOpen(false)
}

return (
<div>
<p>
Result: <em>{result}</em>
</p>
return (
<div>
<p>
Result: <em>{result}</em>
</p>

<Button onClick={this.show}>Show</Button>
<Confirm
open={open}
onCancel={this.handleCancel}
onConfirm={this.handleConfirm}
/>
</div>
)
}
<Button onClick={show}>Show</Button>
<Confirm open={open} onCancel={handleCancel} onConfirm={handleConfirm} />
</div>
)
}

export default ConfirmExampleCallbacks
28 changes: 11 additions & 17 deletions docs/src/examples/addons/Confirm/Types/ConfirmExampleConfirm.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import React, { Component } from 'react'
import React from 'react'
import { Button, Confirm } from 'semantic-ui-react'

class ConfirmExampleConfirm extends Component {
state = { open: false }
function ConfirmExampleConfirm() {
const [open, setOpen] = React.useState(false)

open = () => this.setState({ open: true })
close = () => this.setState({ open: false })
const show = () => setOpen(true)
const close = () => setOpen(false)

render() {
return (
<div>
<Button onClick={this.open}>Show</Button>
<Confirm
open={this.state.open}
onCancel={this.close}
onConfirm={this.close}
/>
</div>
)
}
return (
<div>
<Button onClick={show}>Show</Button>
<Confirm open={open} onCancel={close} onConfirm={close} />
</div>
)
}

export default ConfirmExampleConfirm
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import React, { Component } from 'react'
import React from 'react'
import { Button, Confirm } from 'semantic-ui-react'

class ConfirmExampleHeader extends Component {
state = { open: false }
function ConfirmExampleHeader() {
const [open, setOpen] = React.useState(false)

show = () => this.setState({ open: true })
handleConfirm = () => this.setState({ open: false })
handleCancel = () => this.setState({ open: false })
const show = () => setOpen(true)
const handleConfirm = () => setOpen(false)
const handleCancel = () => setOpen(false)

render() {
return (
<div>
<Button onClick={this.show}>Show</Button>
<Confirm
open={this.state.open}
cancelButton='Never mind'
confirmButton="Let's do it"
onCancel={this.handleCancel}
onConfirm={this.handleConfirm}
/>
</div>
)
}
return (
<div>
<Button onClick={show}>Show</Button>
<Confirm
open={open}
cancelButton='Never mind'
confirmButton="Let's do it"
onCancel={handleCancel}
onConfirm={handleConfirm}
/>
</div>
)
}

export default ConfirmExampleHeader
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import React, { Component } from 'react'
import React from 'react'
import { Button, Confirm } from 'semantic-ui-react'

class ConfirmExampleContent extends Component {
state = { open: false }
function ConfirmExampleContent() {
const [open, setOpen] = React.useState(false)

show = () => this.setState({ open: true })
handleConfirm = () => this.setState({ open: false })
handleCancel = () => this.setState({ open: false })
const show = () => setOpen(true)
const handleConfirm = () => setOpen(false)
const handleCancel = () => setOpen(false)

render() {
return (
<div>
<Button onClick={this.show}>Show</Button>
<Confirm
open={this.state.open}
content='This is a custom message'
onCancel={this.handleCancel}
onConfirm={this.handleConfirm}
/>
</div>
)
}
return (
<div>
<Button onClick={show}>Show</Button>
<Confirm
open={open}
content='This is a custom message'
onCancel={handleCancel}
onConfirm={handleConfirm}
/>
</div>
)
}

export default ConfirmExampleContent
36 changes: 17 additions & 19 deletions docs/src/examples/addons/Confirm/Variations/ConfirmExampleHeader.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
import React, { Component } from 'react'
import React from 'react'
import { Button, Confirm } from 'semantic-ui-react'

class ConfirmExampleHeader extends Component {
state = { open: false }
function ConfirmExampleHeader() {
const [open, setOpen] = React.useState(false)

show = () => this.setState({ open: true })
handleConfirm = () => this.setState({ open: false })
handleCancel = () => this.setState({ open: false })
const show = () => setOpen(true)
const handleConfirm = () => setOpen(false)
const handleCancel = () => setOpen(false)

render() {
return (
<div>
<Button onClick={this.show}>Show</Button>
<Confirm
open={this.state.open}
header='This is a custom header'
onCancel={this.handleCancel}
onConfirm={this.handleConfirm}
/>
</div>
)
}
return (
<div>
<Button onClick={show}>Show</Button>
<Confirm
open={open}
header='This is a custom header'
onCancel={handleCancel}
onConfirm={handleConfirm}
/>
</div>
)
}

export default ConfirmExampleHeader
40 changes: 20 additions & 20 deletions docs/src/examples/addons/Confirm/Variations/ConfirmExampleSize.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
import React, { Component } from 'react'
import React from 'react'
import { Button, Confirm } from 'semantic-ui-react'

export default class ConfirmExampleSize extends Component {
state = { open: false }
function ConfirmExampleSize() {
const [open, setOpen] = React.useState(false)

handleButtonClick = () => this.setState({ open: true })
handleConfirm = () => this.setState({ open: false })
handleCancel = () => this.setState({ open: false })
const show = () => setOpen(true)
const handleConfirm = () => setOpen(false)
const handleCancel = () => setOpen(false)

render() {
return (
<div>
<Button onClick={this.handleButtonClick}>Show Large</Button>
<Confirm
header='This is a large confirm'
open={this.state.open}
onCancel={this.handleCancel}
onConfirm={this.handleConfirm}
size='large'
/>
</div>
)
}
return (
<div>
<Button onClick={show}>Show Large</Button>
<Confirm
header='This is a large confirm'
open={open}
onCancel={handleCancel}
onConfirm={handleConfirm}
size='large'
/>
</div>
)
}

export default ConfirmExampleSize

0 comments on commit 6b54e0b

Please sign in to comment.