-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(Button): add example with replicating button behaviour (#1951)
- Loading branch information
1 parent
9184402
commit 3c22d18
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
docs/app/Examples/elements/Button/Usage/ButtonExampleAttachedEvents.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,45 @@ | ||
import React, { Component } from 'react' | ||
import { Button, Grid, Segment } from 'semantic-ui-react' | ||
|
||
export default class ButtonExampleAttachedEvents extends Component { | ||
state = { log: [] } | ||
|
||
handleClick = () => this.updateLog('Button received click with mouse') | ||
|
||
handleKeyPress = (e) => { | ||
if (e.charCode === 32 || e.charCode === 13) { | ||
// Prevent the default action to stop scrolling when space is pressed | ||
e.preventDefault() | ||
this.updateLog('Button received click with keyboard') | ||
} | ||
} | ||
|
||
updateLog = message => this.setState({ log: [message, ...this.state.log] }) | ||
|
||
render() { | ||
const { log } = this.state | ||
|
||
return ( | ||
<Grid> | ||
<Grid.Column width={8}> | ||
<Segment attached='top'> | ||
The button bellow accepts clicks with mouse and key presses with Space Bar or Enter. | ||
</Segment> | ||
<Button | ||
attached='bottom' | ||
content='Click' | ||
onClick={this.handleClick} | ||
onKeyPress={this.handleKeyPress} | ||
/> | ||
</Grid.Column> | ||
<Grid.Column width={8}> | ||
<Segment> | ||
<pre style={{ height: 100, overflowY: 'scroll' }}> | ||
{log.map((e, i) => <p key={i}>{e}</p>)} | ||
</pre> | ||
</Segment> | ||
</Grid.Column> | ||
</Grid> | ||
) | ||
} | ||
} |
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