-
Notifications
You must be signed in to change notification settings - Fork 104
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
No jsx bind #265
Merged
Merged
No jsx bind #265
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
9e883a5
refactor(Select): introduce SelectItem to avoid binding in JSX
nikgraf 4daced0
refactor(ComboBox): introduce ComboBoxItem to avoid binding in JSX
nikgraf 0bc95d6
refactor(DatePicker): remove legacy refs
nikgraf 3eb1fc9
doc(ComboBox, Select): add info why the item component exits
nikgraf a2cf90d
refactor(DatePicker): introduce DisabledDay & Day to avoid binding in…
nikgraf 297faef
test(DatePicker, ComboBox): avoid mocking ComboBoxItem, Day & Disable…
nikgraf 6c538cf
refactor(ComboBox): clean up after avoiding jsx binding
nikgraf f29df7d
test(ComboBox): fixing test cases
jpuri 898c946
test(DatePicker): minor indentation change
jpuri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
/** | ||
* Belle internal component to wrap an Option in a ComboBox. | ||
* | ||
* This component exists to avoid binding functions in JSX. | ||
*/ | ||
export default class ComboBoxItem extends Component { | ||
|
||
static displayName = 'ComboBoxItem'; | ||
|
||
static propTypes = { | ||
children: PropTypes.node.isRequired, | ||
index: PropTypes.number.isRequired, | ||
onItemClick: PropTypes.func.isRequired, | ||
onItemTouchStart: PropTypes.func.isRequired, | ||
onItemTouchEnd: PropTypes.func.isRequired, | ||
onItemTouchCancel: PropTypes.func.isRequired, | ||
onItemMouseEnter: PropTypes.func.isRequired, | ||
onItemMouseLeave: PropTypes.func.isRequired, | ||
}; | ||
|
||
_onClick = () => { | ||
this.props.onItemClick(this.props.index); | ||
}; | ||
|
||
_onTouchStart = (event) => { | ||
this.props.onItemTouchStart(event, this.props.index); | ||
}; | ||
|
||
_onTouchEnd = (event) => { | ||
this.props.onItemTouchEnd(event, this.props.index); | ||
}; | ||
|
||
_onTouchCancel = () => { | ||
this.props.onItemTouchCancel(); | ||
}; | ||
|
||
_onMouseEnter = () => { | ||
this.props.onItemMouseEnter(this.props.index); | ||
}; | ||
|
||
_onMouseLeave = () => { | ||
this.props.onItemMouseLeave(); | ||
}; | ||
|
||
_onMouseDown = (event) => { | ||
event.preventDefault(); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<li | ||
onClick={ this._onClick } | ||
onMouseEnter={ this._onMouseEnter } | ||
onMouseLeave={ this._onMouseLeave } | ||
onMouseDown={ this._onMouseDown } | ||
onTouchStart={ this._onTouchStart } | ||
onTouchEnd={ this._onTouchEnd } | ||
onTouchCancel={ this._onTouchCancel } | ||
role="option" | ||
> | ||
{ this.props.children } | ||
</li> | ||
); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
/** | ||
* Belle internal component to wrap a Day in a DatePicker. | ||
* | ||
* This component exists to avoid binding functions in JSX. | ||
*/ | ||
export default class Day extends Component { | ||
|
||
static displayName = 'Day'; | ||
|
||
static propTypes = { | ||
children: PropTypes.node.isRequired, | ||
dateKey: PropTypes.string.isRequired, | ||
onDayMouseEnter: PropTypes.func.isRequired, | ||
onDayMouseLeave: PropTypes.func.isRequired, | ||
onDayMouseDown: PropTypes.func.isRequired, | ||
onDayMouseUp: PropTypes.func.isRequired, | ||
onDayTouchStart: PropTypes.func.isRequired, | ||
onDayTouchEnd: PropTypes.func.isRequired, | ||
onDayTouchCancel: PropTypes.func.isRequired, | ||
style: PropTypes.object.isRequired, | ||
dayProps: PropTypes.any, | ||
selected: PropTypes.bool.isRequired, | ||
}; | ||
|
||
_onMouseEnter = (event) => { | ||
this.props.onDayMouseEnter(this.props.dateKey, event); | ||
}; | ||
|
||
_onMouseLeave = (event) => { | ||
this.props.onDayMouseLeave(this.props.dateKey, event); | ||
}; | ||
|
||
_onMouseDown = (event) => { | ||
this.props.onDayMouseDown(this.props.dateKey, event); | ||
}; | ||
|
||
_onMouseUp = (event) => { | ||
this.props.onDayMouseUp(this.props.dateKey, event); | ||
}; | ||
|
||
_onTouchStart = (event) => { | ||
this.props.onDayTouchStart(this.props.dateKey, event); | ||
}; | ||
|
||
_onTouchEnd = (event) => { | ||
this.props.onDayTouchEnd(this.props.dateKey, event); | ||
}; | ||
|
||
_onTouchCancel = (event) => { | ||
this.props.onDayTouchCancel(this.props.dateKey, event); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<span | ||
style={ this.props.style } | ||
onMouseEnter={ this._onMouseEnter } | ||
onMouseLeave={ this._onMouseLeave } | ||
onMouseDown={ this._onMouseDown } | ||
onMouseUp={ this._onMouseUp } | ||
onTouchStart={ this._onTouchStart } | ||
onTouchEnd={ this._onTouchEnd } | ||
onTouchCancel={ this._onTouchCancel } | ||
aria-selected={ this.props.selected } | ||
style={ this.props.style } | ||
role="gridcell" | ||
{...this.props.dayProps} | ||
> | ||
{ this.props.children } | ||
</span> | ||
); | ||
} | ||
} |
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,41 @@ | ||
import React, { Component, PropTypes } from 'react'; | ||
|
||
/** | ||
* Belle internal component to wrap a DisabledDay in a DatePicker. | ||
* | ||
* This component exists to avoid binding functions in JSX. | ||
*/ | ||
export default class DisabledDay extends Component { | ||
|
||
static displayName = 'DisabledDay'; | ||
|
||
static propTypes = { | ||
children: PropTypes.node.isRequired, | ||
dateKey: PropTypes.string.isRequired, | ||
onDayMouseEnter: PropTypes.func.isRequired, | ||
onDayMouseLeave: PropTypes.func.isRequired, | ||
style: PropTypes.object.isRequired, | ||
disabledDayProps: PropTypes.any, | ||
}; | ||
|
||
_onMouseEnter = (event) => { | ||
this.props.onDayMouseEnter(this.props.dateKey, event); | ||
}; | ||
|
||
_onMouseLeave = (event) => { | ||
this.props.onDayMouseLeave(this.props.dateKey, event); | ||
}; | ||
|
||
render() { | ||
return ( | ||
<span | ||
style={ this.props.style } | ||
onMouseEnter={ this._onDayMouseEnter } | ||
onMouseLeave={ this._onDayMouseLeave } | ||
{...this.props.disabledDayProps} | ||
> | ||
{ this.props.children } | ||
</span> | ||
); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nikgraf I do not like the idea of extracting a component which just handles event callbacks to get rid of bindings. A component should be a more logical entity and should be able to handle its styling logic and stuff like making dayKey out of date.
If we can do this kind of component it will help us in not just getting rid of bindings but also simplify these complex components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm open to a PR to simplify the whole structure 😄
I'm not a big fan of having these components just for event handling, but it's the best option I'm aware of to avoid performance issue and therefor more important than not doing it at all.