-
Notifications
You must be signed in to change notification settings - Fork 47.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
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
51 changes: 51 additions & 0 deletions
51
fixtures/dom/src/components/fixtures/mouse-events/index.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,51 @@ | ||
const React = window.React; | ||
|
||
const Rectangle = ({style, ...props}) => ( | ||
<div {...props} style={{border: '1px solid black', padding: 40, ...style}} /> | ||
); | ||
|
||
class MouseEventsFixtures extends React.Component { | ||
state = {log: []}; | ||
|
||
log = msg => { | ||
this.setState(({log}) => ({ | ||
log: log.concat(msg), | ||
})); | ||
}; | ||
clearLog = () => { | ||
this.setState({log: []}); | ||
}; | ||
render() { | ||
let getLogger = prefix => e => this.log(`${prefix}: ${e.type}`); | ||
let outerLogger = getLogger('outer'); | ||
let innerLogger = getLogger('inner'); | ||
|
||
return ( | ||
<div> | ||
<div className="container"> | ||
<p> | ||
Mouse the mouse between the two rectangles. The console should | ||
only log for a given box when the mouse crosses into the box the first | ||
time and again when the mouse exits the | ||
{' '} | ||
<em>outer</em> | ||
{' '} | ||
bounds of each box. | ||
</p> | ||
<Rectangle onMouseEnter={outerLogger} onMouseLeave={outerLogger}> | ||
<Rectangle onMouseEnter={innerLogger} onMouseLeave={innerLogger} /> | ||
</Rectangle> | ||
</div> | ||
|
||
<div className="container"> | ||
<h4>Console: <button onClick={this.clearLog}>clear</button></h4> | ||
<pre className="output"> | ||
{this.state.log.join('\n')} | ||
</pre> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
module.exports = MouseEventsFixtures; |