Skip to content

Commit

Permalink
feat: Add optional icon prop to PushClientButton
Browse files Browse the repository at this point in the history
This allows to specify a custom icon for `PushClientButton`
(i.e: use a browser icon instead of the `DeviceLaptop` one)

If `icon` prop is not specified, then `DeviceLaptop` is still used as
default
  • Loading branch information
Ldoppea committed Jul 7, 2021
1 parent 1690b88 commit 23bc4ad
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
17 changes: 17 additions & 0 deletions react/PushClientButton/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,20 @@ import ButtonClient from 'cozy-ui/transpiled/react/PushClientButton';
className="u-m-1"
/>
```

#### icon

You can add custom icon to `icon` prop

If not defined then `DeviceLaptop` is used as default icon

```
import ButtonClient from 'cozy-ui/transpiled/react/PushClientButton';
import BrowserBraveIcon from 'cozy-ui/transpiled/react/Icons/BrowserBrave';
<ButtonClient
label="Download our extension"
href="https://cozy.io"
className="u-m-1"
icon={BrowserBraveIcon}
/>
```
8 changes: 5 additions & 3 deletions react/PushClientButton/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import Icon from '../Icon'
import DeviceLaptopIcon from 'cozy-ui/transpiled/react/Icons/DeviceLaptop'

const ButtonClient = props => {
const { label, href, onClick, className } = props
const { label, href, onClick, className, icon } = props

return (
<a
href={href}
Expand All @@ -18,7 +19,7 @@ const ButtonClient = props => {
onClick={onClick}
>
<figure>
<Icon icon={DeviceLaptopIcon} size="32" />
<Icon icon={icon || DeviceLaptopIcon} size="32" />
</figure>
<span>{label}</span>
</a>
Expand All @@ -29,7 +30,8 @@ ButtonClient.propTypes = {
label: PropTypes.string.isRequired,
href: PropTypes.string.isRequired,
className: PropTypes.string,
onClick: PropTypes.func
onClick: PropTypes.func,
icon: PropTypes.elementType
}

ButtonClient.defaultProps = {
Expand Down
24 changes: 24 additions & 0 deletions react/PushClientButton/index.spec.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react'

import { render } from '@testing-library/react'

import PushClientButton from './'

jest.mock('cozy-ui/transpiled/react/Icons/DeviceLaptop', () => () => (
<div data-testid="device-laptop" />
))

describe('PushClientButton', () => {
it('should use DeviceLaptop if icon prop is not defined', async () => {
const { getByTestId } = render(<PushClientButton />)

expect(getByTestId(/device-laptop/)).toBeInTheDocument()
})

it('should accept a custom icon', async () => {
const CustomIcon = () => <div data-testid="custom-icon" />
const { getByTestId } = render(<PushClientButton icon={CustomIcon} />)

expect(getByTestId(/custom-icon/)).toBeInTheDocument()
})
})

0 comments on commit 23bc4ad

Please sign in to comment.