-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add BarButton
- Loading branch information
Showing
7 changed files
with
143 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# BarButton | ||
This component is used to display a back Button into the Cozy Bar. | ||
|
||
### Example | ||
|
||
```jsx static | ||
const { BarLeft } = cozy.bar | ||
return ( | ||
<BarLeft> | ||
<BarButton /> | ||
</BarLeft> | ||
) | ||
``` | ||
|
||
## `disabled` | ||
|
||
```jsx | ||
<BarButton icon="back" disabled /> | ||
``` | ||
|
||
## `href` | ||
|
||
```jsx | ||
<BarButton icon="upload" href="http://cozy.io" /> | ||
``` | ||
|
||
## `icon` | ||
|
||
```jsx | ||
<BarButton icon="cube" /> | ||
``` | ||
|
||
## `onClick` | ||
|
||
```jsx | ||
<BarButton icon="gear" onClick={() => alert('BarButton has been clicked')} /> | ||
``` |
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 @@ | ||
import React, { PureComponent } from 'react' | ||
import PropTypes from 'prop-types' | ||
|
||
import styles from './styles.styl' | ||
|
||
import Icon from '../Icon' | ||
|
||
class MaybeLink extends PureComponent { | ||
render() { | ||
const { children, href, ...restProps } = this.props | ||
return href ? ( | ||
<a href={href} {...restProps}> | ||
{children} | ||
</a> | ||
) : ( | ||
<div {...restProps}>{children}</div> | ||
) | ||
} | ||
} | ||
|
||
MaybeLink.propTypes = { | ||
className: PropTypes.string, | ||
href: PropTypes.string, | ||
onClick: PropTypes.func | ||
} | ||
|
||
export class BarButton extends PureComponent { | ||
render() { | ||
const { disabled, icon, href, onClick } = this.props | ||
return ( | ||
<MaybeLink | ||
className={styles['bar-btn']} | ||
href={!disabled && href} | ||
onClick={!disabled && onClick} | ||
> | ||
<Icon icon={icon} className={disabled ? 'u-silver' : 'u-coolGrey'} /> | ||
</MaybeLink> | ||
) | ||
} | ||
} | ||
|
||
BarButton.propTypes = { | ||
/** | ||
* Renders the component using a lighter grey color. | ||
*/ | ||
disabled: PropTypes.bool, | ||
/** | ||
* Renders the component using a anchor tag | ||
*/ | ||
href: PropTypes.string, | ||
/** | ||
* Used to render the internal `<Icon />` component. | ||
*/ | ||
icon: Icon.propTypes.icon, | ||
/** | ||
* Click event handler on the component. | ||
*/ | ||
onClick: PropTypes.func | ||
} | ||
|
||
export default BarButton |
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,7 @@ | ||
.c-bar-btn { | ||
display flex | ||
align-items center | ||
justify-content center | ||
width rem(48) | ||
height rem(48) | ||
} |
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