diff --git a/docs/app/Examples/addons/Portal/Types/PortalExampleControlled.js b/docs/app/Examples/addons/Portal/Types/PortalExampleControlled.js new file mode 100644 index 0000000000..a2352a149a --- /dev/null +++ b/docs/app/Examples/addons/Portal/Types/PortalExampleControlled.js @@ -0,0 +1,42 @@ +import React, { Component } from 'react' +import { Button, Grid, Header, Segment, Portal } from 'semantic-ui-react' + +export default class PortalExampleControlled extends Component { + state = { + open: false, + } + + handleClick = () => this.setState({ open: !this.state.open }) + + handleClose = () => this.setState({ open: false }) + + render() { + const { open } = this.state + + return ( + + + + + + + This is a controlled portal + Portals have tons of great callback functions to hook into. + To close, simply click the close button or click away + + + + + ) + } +} diff --git a/docs/app/Examples/addons/Portal/Types/PortalExamplePortal.js b/docs/app/Examples/addons/Portal/Types/PortalExamplePortal.js index a22e92f2a7..a06f359f6b 100644 --- a/docs/app/Examples/addons/Portal/Types/PortalExamplePortal.js +++ b/docs/app/Examples/addons/Portal/Types/PortalExamplePortal.js @@ -1,26 +1,35 @@ import React, { Component } from 'react' -import { Button, Grid, Header, Segment, Portal } from 'semantic-ui-react' +import { Button, Grid, Header, Label, Segment, Portal } from 'semantic-ui-react' -export default class ExamplePortal extends Component { +export default class PortalExamplePortal extends Component { state = { log: [], + logCount: 0, open: false, } handleOpen = () => { this.setState({ open: true }) - this.writeLog('Portal mounted') + this.writeLog('onOpen()') } handleClose = () => { this.setState({ open: false }) - this.writeLog('Portal closed') + this.writeLog('onClose()') } - writeLog = message => this.setState({ log: [message, ...this.state.log] }) + clearLog = () => this.setState({ log: [], logCount: 0 }) + + writeLog = eventName => this.setState(({ + log: [ + `${new Date().toLocaleTimeString()}: ${eventName}`, + ...this.state.log, + ].slice(0, 20), + logCount: this.state.logCount + 1, + })) render() { - const { log, open } = this.state + const { log, logCount, open } = this.state return ( @@ -46,11 +55,15 @@ export default class ExamplePortal extends Component { - - - {log.map((e, i) => {e})} - - + + + Clear + Event Log {logCount} + + + {log.map((e, i) => {e})} + + ) diff --git a/docs/app/Examples/addons/Portal/Types/index.js b/docs/app/Examples/addons/Portal/Types/index.js index 9f9809d4e2..7f2ad57bb3 100644 --- a/docs/app/Examples/addons/Portal/Types/index.js +++ b/docs/app/Examples/addons/Portal/Types/index.js @@ -10,6 +10,11 @@ const PortalTypesExamples = () => ( description='A basic portal.' examplePath='addons/Portal/Types/PortalExamplePortal' /> + )
Portals have tons of great callback functions to hook into.
To close, simply click the close button or click away
- {log.map((e, i) => {e})} -
{e}
{log.map((e, i) => {e})}