-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Components: header cake cleanup #1514
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,19 @@ | ||
Back Button aka Header Cake | ||
=========================== | ||
|
||
The "header cake" component should be used at the top of an item's detail page. It's purpose is to display a title and back link. | ||
|
||
## Usage | ||
|
||
``` | ||
```js | ||
var HeaderCake = require( 'components/header-cake' ); | ||
|
||
<HeaderCake onClick={ callback }>Button Text</HeaderCake> | ||
<HeaderCake onClick={ callback }>Item Details</HeaderCake> | ||
``` | ||
|
||
## Props | ||
|
||
* `onClick` - Function to trigger when the back text is clicked | ||
* `onClick` - (**required**) Function to trigger when the back text is clicked | ||
* `onTitleClick` - Function to trigger when the title is clicked | ||
* `backText` - React Element or string to use in place of default "Back" text | ||
* `isCompact` - Optional variant of a more visually compact header cake |
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,61 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import React, { PropTypes } from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import ObserveWindowSizeMixin from 'lib/mixins/observe-window-resize'; | ||
import Gridicon from 'components/gridicon'; | ||
|
||
/** | ||
* Module variables | ||
*/ | ||
const HIDE_BACK_CRITERIA = { | ||
windowWidth: 480, | ||
characterLength: 8 | ||
}; | ||
|
||
export default React.createClass( { | ||
|
||
displayName: 'HeaderCakeBack', | ||
|
||
mixins: [ ObserveWindowSizeMixin ], | ||
|
||
propTypes: { | ||
onClick: PropTypes.func, | ||
href: PropTypes.string, | ||
text: PropTypes.string, | ||
spacer: PropTypes.bool | ||
}, | ||
|
||
getDefaultProps() { | ||
return { | ||
spacer: false | ||
}; | ||
}, | ||
|
||
render() { | ||
const { text = this.translate( 'Back' ), href, onClick, spacer } = this.props; | ||
const windowWidth = window.innerWidth; | ||
const hideText = windowWidth <= HIDE_BACK_CRITERIA.windowWidth && text.length >= HIDE_BACK_CRITERIA.characterLength || windowWidth <= 300; | ||
const linkClasses = classNames( { | ||
'header-cake__back': true, | ||
'is-spacer': spacer | ||
} ); | ||
|
||
return ( | ||
<a className={ linkClasses } href={ href } onClick={ onClick }> | ||
<Gridicon icon="chevron-left" size={ 18 } /> | ||
{ ! hideText && <span className="header-cake__back-text">{ text }</span> } | ||
</a> | ||
); | ||
}, | ||
|
||
onWindowResize() { | ||
this.forceUpdate(); | ||
} | ||
|
||
} ); |
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
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
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.
Is this optional? If not we can add a
PropTypes.func.isRequired
here.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.
In this particular case it is actually optional because of the spacer usage. In order to give the title the most about of space possible and still keep in centered, the corners were changed to display the same text in both places (the right one is hidden). The right corner still uses the back component, but doesn't include any
onClick
props.