forked from Semantic-Org/Semantic-UI-React
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Visibility): add component (Semantic-Org#1174)
* feat(visibility): create Visibility component * feat(visibility): add behaviour meta * docs(visibility): create first docs example * feat(visibility): add scroll handler * feat(visibility): generate calculations on scroll * feat(visibility): add standard events * feat(visibility): make Visibility conformant * refactor(visibility): remove empty function * fix(visibility): fix typo * docs(Visibility): callback frequency example * feat(Visibility): add support for continuous * refactor(Visibility): add default values to props * refactor(Visibility): bind handleScroll to this * docs(Visibility): bind `continuous` and `once` * feat(Visibility): add once and continuous * docs(Visibility): minor fix * feat(Visibility): add reverse callbacks * feat(Visibility): add onOnScreen and onOffScreen * docs(Visibility): split examples * fix(Visibility): change once default value * test(Visibility): create tests * feat(Visibility): add grouped callbacks * fix(tests): revert change to tests.bundle.js * chore(behavior): rename from behaviour * chore(behavior): rename from behaviour * Fix(Visibility): remove event listener after unmounting * style(Visibility): shorten example description * tests(common): update regexp * refactor(Visibility): wip * refactor(Visibility): wip * style(Visibility): add typings, update events signatures
- Loading branch information
1 parent
fc61b05
commit 989f52a
Showing
20 changed files
with
1,082 additions
and
3 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
docs/app/Examples/behaviors/Visibility/Settings/CallbackFrequencyExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, { Component } from 'react' | ||
import { Button, Checkbox, Divider, Grid, Segment, Visibility } from 'semantic-ui-react' | ||
import Wireframe from '../Wireframe' | ||
|
||
export default class VisibilityExample extends Component { | ||
state = { | ||
continuous: false, | ||
log: [], | ||
once: true, | ||
} | ||
|
||
updateLog = eventName => () => this.setState({ log: [eventName, ...this.state.log] }) | ||
|
||
clearLog = () => this.setState({ log: [] }) | ||
|
||
toggleOnce = () => this.setState({ once: !this.state.once }) | ||
|
||
toggleContinuous = () => this.setState({ continuous: !this.state.continuous }) | ||
|
||
render() { | ||
const { continuous, log, once } = this.state | ||
|
||
return ( | ||
<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> | ||
<Segment.Group> | ||
<Segment> | ||
<Button floated='right' onClick={this.clearLog}>Clear</Button> | ||
<Checkbox checked={once} label='Once' onChange={this.toggleOnce} toggle /> | ||
<Divider /> | ||
<Checkbox checked={continuous} label='Continuous' onChange={this.toggleContinuous} toggle /> | ||
</Segment> | ||
<Segment>Event Log</Segment> | ||
<Segment> | ||
<pre style={{ height: 300, overflowY: 'scroll' }}> | ||
{log.map((e, i) => <p key={i}>{e} fired</p>)} | ||
</pre> | ||
</Segment> | ||
</Segment.Group> | ||
</Grid.Column> | ||
</Grid> | ||
) | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
docs/app/Examples/behaviors/Visibility/Settings/GroupedCallbacksExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { Component } from 'react' | ||
import { Button, Checkbox, Divider, Grid, Segment, Visibility } from 'semantic-ui-react' | ||
import Wireframe from '../Wireframe' | ||
|
||
class VisibilityExample extends Component { | ||
state = { | ||
continuous: false, | ||
log: [], | ||
once: true, | ||
} | ||
|
||
updateLog = eventName => () => this.setState({ log: [eventName, ...this.state.log] }) | ||
|
||
clearLog = () => this.setState({ log: [] }) | ||
|
||
toggleOnce = () => this.setState({ once: !this.state.once }) | ||
|
||
toggleContinuous = () => this.setState({ continuous: !this.state.continuous }) | ||
|
||
render() { | ||
const { continuous, log, once } = this.state | ||
|
||
return ( | ||
<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> | ||
<Segment.Group> | ||
<Segment> | ||
<Button floated='right' onClick={this.clearLog}>Clear</Button> | ||
<Checkbox checked={once} label='Once' onChange={this.toggleOnce} toggle /> | ||
<Divider /> | ||
<Checkbox checked={continuous} label='Continuous' onChange={this.toggleContinuous} toggle /> | ||
</Segment> | ||
<Segment>Event Log</Segment> | ||
<Segment> | ||
<pre style={{ height: 300, overflowY: 'scroll' }}> | ||
{log.map((e, i) => <p key={i}>{e} fired</p>)} | ||
</pre> | ||
</Segment> | ||
</Segment.Group> | ||
</Grid.Column> | ||
</Grid> | ||
) | ||
} | ||
} | ||
|
||
export default VisibilityExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import React from 'react' | ||
|
||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection' | ||
|
||
const VisibilityExample = () => ( | ||
<ExampleSection title='Settings'> | ||
<ComponentExample | ||
title='Callback frequency' | ||
description='You can change the callback frequency with `once` and `continuous` settings' | ||
examplePath='behaviors/Visibility/Settings/CallbackFrequencyExample' | ||
/> | ||
<ComponentExample | ||
title='Grouped callbacks' | ||
description='You can specify callbacks that occur after different percentages or pixels of an element are passed' | ||
examplePath='behaviors/Visibility/Settings/GroupedCallbacksExample' | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default VisibilityExample |
101 changes: 101 additions & 0 deletions
101
docs/app/Examples/behaviors/Visibility/Types/VisibilityExample.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import React, { Component } from 'react' | ||
import { Grid, Table, Visibility } from 'semantic-ui-react' | ||
import Wireframe from '../Wireframe' | ||
|
||
class VisibilityExample extends Component { | ||
state = { | ||
calculations: { | ||
height: 0, | ||
width: 0, | ||
topPassed: false, | ||
bottomPassed: false, | ||
pixelsPassed: 0, | ||
percentagePassed: 0, | ||
topVisible: false, | ||
bottomVisible: false, | ||
fits: false, | ||
passing: false, | ||
onScreen: false, | ||
offScreen: false, | ||
}, | ||
} | ||
|
||
handleUpdate = (e, { calculations }) => this.setState({ calculations }) | ||
|
||
render() { | ||
const { calculations } = this.state | ||
|
||
return ( | ||
<Grid columns={2}> | ||
<Grid.Column> | ||
<Visibility onUpdate={this.handleUpdate}> | ||
<Wireframe /> | ||
</Visibility> | ||
</Grid.Column> | ||
|
||
<Grid.Column> | ||
<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>pixelsPassed</Table.Cell> | ||
<Table.Cell>{calculations.pixelsPassed.toFixed()}px</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell>percentagePassed</Table.Cell> | ||
<Table.Cell>{(calculations.percentagePassed * 100).toFixed()}%</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell>fits</Table.Cell> | ||
<Table.Cell>{calculations.fits.toString()}</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell>width</Table.Cell> | ||
<Table.Cell>{calculations.width.toFixed()}px</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell>height</Table.Cell> | ||
<Table.Cell>{calculations.height.toFixed()}px</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell>onScreen</Table.Cell> | ||
<Table.Cell>{calculations.onScreen.toString()}</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell>offScreen</Table.Cell> | ||
<Table.Cell>{calculations.offScreen.toString()}</Table.Cell> | ||
</Table.Row> | ||
<Table.Row> | ||
<Table.Cell>passing</Table.Cell> | ||
<Table.Cell>{calculations.passing.toString()}</Table.Cell> | ||
</Table.Row> | ||
<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> | ||
</Grid.Column> | ||
</Grid> | ||
) | ||
} | ||
} | ||
|
||
export default VisibilityExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
|
||
import ComponentExample from 'docs/app/Components/ComponentDoc/ComponentExample' | ||
import ExampleSection from 'docs/app/Components/ComponentDoc/ExampleSection' | ||
|
||
const VisibilityExample = () => ( | ||
<ExampleSection title='Types'> | ||
<ComponentExample | ||
title='Default' | ||
description='An example of Visibility' | ||
examplePath='behaviors/Visibility/Types/VisibilityExample' | ||
/> | ||
</ExampleSection> | ||
) | ||
|
||
export default VisibilityExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import React from 'react' | ||
import { Divider, Image, Segment } from 'semantic-ui-react' | ||
|
||
export default (props) => ( | ||
<Segment> | ||
<Image src='http://semantic-ui.com/images/wireframe/centered-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/short-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/media-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/centered-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/short-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/media-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/short-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/centered-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/short-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/media-paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/paragraph.png' /> | ||
<Divider /> | ||
<Image src='http://semantic-ui.com/images/wireframe/short-paragraph.png' /> | ||
</Segment> | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
|
||
import Types from './Types' | ||
import Settings from './Settings' | ||
|
||
const VisibilityExamples = () => ( | ||
<div> | ||
<Types /> | ||
<Settings /> | ||
</div> | ||
) | ||
|
||
export default VisibilityExamples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.