Skip to content

Commit

Permalink
Add BarButton (#973)
Browse files Browse the repository at this point in the history
Add BarButton
  • Loading branch information
gregorylegarec authored May 13, 2019
2 parents 18a1251 + cdc21ac commit 0b8d53f
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const webpackMerge = require('webpack-merge')
module.exports = {
title: 'Cozy UI React components',
sections: [
{
name: 'Bar',
components: () => ['../react/BarButton/index.jsx']
},
{
name: 'Basics',
components: () => [
Expand Down
37 changes: 37 additions & 0 deletions react/BarButton/Readme.md
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')} />
```
61 changes: 61 additions & 0 deletions react/BarButton/index.jsx
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
7 changes: 7 additions & 0 deletions react/BarButton/styles.styl
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)
}
30 changes: 30 additions & 0 deletions react/__snapshots__/examples.spec.jsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,36 @@ exports[`Badge should render examples: Badge 1`] = `
</div>"
`;
exports[`BarButton should render examples: BarButton 1`] = `
"<div>
<div><svg class=\\"u-silver styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#back\\"></use>
</svg></div>
</div>"
`;
exports[`BarButton should render examples: BarButton 2`] = `
"<div><a href=\\"http://cozy.io\\"><svg class=\\"u-coolGrey styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#upload\\"></use>
</svg></a></div>"
`;
exports[`BarButton should render examples: BarButton 3`] = `
"<div>
<div><svg class=\\"u-coolGrey styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#cube\\"></use>
</svg></div>
</div>"
`;
exports[`BarButton should render examples: BarButton 4`] = `
"<div>
<div><svg class=\\"u-coolGrey styles__icon___23x3R\\" width=\\"16\\" height=\\"16\\">
<use xlink:href=\\"#gear\\"></use>
</svg></div>
</div>"
`;
exports[`Button should render examples: Button 1`] = `
"<div>
<div>
Expand Down
1 change: 1 addition & 0 deletions react/examples.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ testComponent('MuiCozyTheme/ExpansionPanel')
testComponent('ActionMenu')
testComponent('Avatar')
testComponent('Badge')
testComponent('BarButton')
testComponent('Button')
testComponent('ButtonAction')
testComponent('Checkbox')
Expand Down
3 changes: 3 additions & 0 deletions react/testFromStyleguidist.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ActionMenu from './ActionMenu'
import Alerter from './Alerter'
import Avatar from './Avatar'
import Badge from './Badge'
import BarButton from './BarButton'
import Button from './Button'
import ButtonAction from './ButtonAction'
import ButtonClient from './PushClientButton'
Expand Down Expand Up @@ -70,6 +71,7 @@ const testFromStyleguidist = (name, markdown, require) => {
'Alerter',
'Avatar',
'Badge',
'BarButton',
'Button',
'ButtonAction',
'ButtonClient',
Expand Down Expand Up @@ -117,6 +119,7 @@ const testFromStyleguidist = (name, markdown, require) => {
Alerter,
Avatar,
Badge,
BarButton,
Button,
ButtonAction,
ButtonClient,
Expand Down

0 comments on commit 0b8d53f

Please sign in to comment.