-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1514 from Automattic/fix/143-header-cake-back-ove…
…rflow Components: header cake cleanup
- Loading branch information
Showing
10 changed files
with
144 additions
and
84 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
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