Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Visibility): add offset #2016

Merged
merged 4 commits into from
Sep 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class ComponentExample extends Component {
const LODASH = require('lodash')
const REACT = require('react')
const SEMANTIC_UI_REACT = require('semantic-ui-react')
let WIREFRAME
let COMMON
/* eslint-enable no-unused-vars */

Expand All @@ -191,6 +192,8 @@ class ComponentExample extends Component {
if (module === 'COMMON') {
const componentPath = examplePath.split(__PATH_SEP__).splice(0, 2).join(__PATH_SEP__)
COMMON = require(`docs/app/Examples/${componentPath}/common`)
} else if (module === 'WIREFRAME') {
WIREFRAME = require('docs/app/Examples/behaviors/Visibility/Wireframe').default
}

const constStatements = []
Expand Down Expand Up @@ -420,8 +423,10 @@ class ComponentExample extends Component {
<Grid.Column className={`rendered-example ${this.getKebabExamplePath()}`}>
{exampleElement}
</Grid.Column>
{this.renderJSX()}
{this.renderHTML()}
<Grid.Column>
{this.renderJSX()}
{this.renderHTML()}
</Grid.Column>
</Grid.Row>
</Grid>
)
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import React, { Component } from 'react'
import { Button, Checkbox, Divider, Grid, Label, Segment, Sticky, Visibility } from 'semantic-ui-react'

import Wireframe from '../Wireframe'

export default class VisibilityExampleCallbackFrequency extends Component {
state = {
continuous: false,
log: [],
logCount: 0,
once: true,
}

handleContextRef = contextRef => this.setState({ contextRef })

updateLog = eventName => () => this.setState(({
log: [
`${new Date().toLocaleTimeString()}: ${eventName}`,
...this.state.log,
].slice(0, 20),
logCount: this.state.logCount + 1,
}))

clearLog = () => this.setState({ log: [], logCount: 0 })

toggleOnce = () => this.setState({ once: !this.state.once })

toggleContinuous = () => this.setState({ continuous: !this.state.continuous })

render() {
const { continuous, contextRef, log, logCount, once } = this.state

return (
<div ref={this.handleContextRef}>
<Grid columns={2}>
<Grid.Column>
<Visibility
continuous={continuous}
once={once}
onTopVisible={this.updateLog('onTopVisible')}
onTopPassed={this.updateLog('onTopPassed')}
onBottomVisible={this.updateLog('onBottomVisible')}
onBottomPassed={this.updateLog('onBottomPassed')}
onTopVisibleReverse={this.updateLog('onTopVisibleReverse')}
onTopPassedReverse={this.updateLog('onTopPassedReverse')}
onBottomVisibleReverse={this.updateLog('onBottomVisibleReverse')}
onBottomPassedReverse={this.updateLog('onBottomPassedReverse')}
onPassing={this.updateLog('onPassing')}
onPassingReverse={this.updateLog('onPassingReverse')}
onOnScreen={this.updateLog('onOnScreen')}
onOffScreen={this.updateLog('onOffScreen')}
>
<Wireframe />
</Visibility>
</Grid.Column>

<Grid.Column>
<Sticky context={contextRef}>
<Segment.Group>
<Segment>
<Checkbox checked={once} label='Once' onChange={this.toggleOnce} toggle />
<Divider />
<Checkbox checked={continuous} label='Continuous' onChange={this.toggleContinuous} toggle />
</Segment>
<Segment>
<Button compact size='small' floated='right' onClick={this.clearLog}>Clear</Button>
Event Log <Label circular>{logCount}</Label>
</Segment>
<Segment secondary>
<pre>{log.map((e, i) => <div key={i}>{e}</div>)}</pre>
</Segment>
</Segment.Group>
</Sticky>
</Grid.Column>
</Grid>
</div>
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React, { Component } from 'react'
import { Button, Checkbox, Divider, Grid, Label, Segment, Sticky, Visibility } from 'semantic-ui-react'

import Wireframe from '../Wireframe'

export default class VisibilityExampleGroupedCallbacks extends Component {
state = {
continuous: false,
log: [],
logCount: 0,
once: true,
}

handleContextRef = contextRef => this.setState({ contextRef })

updateLog = eventName => () => this.setState(({
log: [
`${new Date().toLocaleTimeString()}: ${eventName}`,
...this.state.log,
].slice(0, 20),
logCount: this.state.logCount + 1,
}))

clearLog = () => this.setState({ log: [], logCount: 0 })

toggleOnce = () => this.setState({ once: !this.state.once })

toggleContinuous = () => this.setState({ continuous: !this.state.continuous })

render() {
const { continuous, contextRef, log, logCount, once } = this.state

return (
<div ref={this.handleContextRef}>
<Grid columns={2}>
<Grid.Column>
<Visibility
continuous={continuous}
once={once}
onPassed={{
10: this.updateLog('10px'),
100: this.updateLog('100px'),
500: this.updateLog('500px'),
'10%': this.updateLog('10%'),
'25%': this.updateLog('25%'),
'80%': this.updateLog('80%'),
}}
>
<Wireframe />
</Visibility>
</Grid.Column>

<Grid.Column>
<Sticky context={contextRef}>
<Segment.Group>
<Segment>
<Checkbox checked={once} label='Once' onChange={this.toggleOnce} toggle />
<Divider />
<Checkbox checked={continuous} label='Continuous' onChange={this.toggleContinuous} toggle />
</Segment>
<Segment>
<Button compact size='small' floated='right' onClick={this.clearLog}>Clear</Button>
Event Log <Label circular>{logCount}</Label>
</Segment>
<Segment secondary>
<pre>{log.map((e, i) => <div key={i}>{e}</div>)}</pre>
</Segment>
</Segment.Group>
</Sticky>
</Grid.Column>
</Grid>
</div>
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React, { Component } from 'react'
import { Grid, Sticky, Table, Visibility } from 'semantic-ui-react'

import Wireframe from '../Wireframe'

export default class VisibilityExampleOffset extends Component {
state = {
calculations: {
topPassed: false,
bottomPassed: false,
topVisible: false,
bottomVisible: false,
},
}

handleContextRef = contextRef => this.setState({ contextRef })

handleUpdate = (e, { calculations }) => this.setState({ calculations })

render() {
const { calculations, contextRef } = this.state

return (
<div ref={this.handleContextRef}>
<Grid columns={2}>
<Grid.Column>
<Visibility offset={[10, 10]} onUpdate={this.handleUpdate}>
<Wireframe />
</Visibility>
</Grid.Column>

<Grid.Column>
<Sticky context={contextRef}>
<Table celled>
<Table.Header>
<Table.Row>
<Table.HeaderCell>Calculation</Table.HeaderCell>
<Table.HeaderCell>Value</Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.Row>
<Table.Cell>topVisible</Table.Cell>
<Table.Cell>{calculations.topVisible.toString()}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>bottomVisible</Table.Cell>
<Table.Cell>{calculations.bottomVisible.toString()}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>topPassed</Table.Cell>
<Table.Cell>{calculations.topPassed.toString()}</Table.Cell>
</Table.Row>
<Table.Row>
<Table.Cell>bottomPassed</Table.Cell>
<Table.Cell>{calculations.bottomPassed.toString()}</Table.Cell>
</Table.Row>
</Table.Body>
</Table>
</Sticky>
</Grid.Column>
</Grid>
</div>
)
}
}
Loading