Skip to content

Commit

Permalink
Merge pull request #30 in FFE/ffe-buttons-react from ffe-152-icon-sup…
Browse files Browse the repository at this point in the history
…port to master

* commit '46cc66d26dac98a5633796cdaa8705ff05d60849':
  FFE-152: Added support for left and right icon in Button * Added support for left icon in SecondaryButton and TertiaryButton * Updated changelog, readme and package.json
  • Loading branch information
Tony Daniel Bore committed Feb 20, 2017
2 parents ab60f5e + 2fe112f commit 6fec93c
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 14 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## v5.2.0
* Added support for icons in `<Button>`, `<SecondaryButton>` and `<TertiaryButton>`.
* Modified `ShortcutButton` to pass the `<ChevronIcon>` as a `rightIcon` prop to `<Button>`

## v5.1.2
* Bugfix: ShortcutButton used wrong css-class on its icon.

Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ isLoading: bool,
isTabbable: bool,
autoFocus: bool,
label: string,
leftIcon: node,
onClick: func,
rightIcon: node,
simpleContent: bool, (default: false)
style: object,
type: 'button' | 'submit' | 'reset' (default: 'submit')
Expand Down Expand Up @@ -133,6 +135,28 @@ Optionally, pass `className` to set a custom class on the button.
<Button className="testClass">...</Button>
```

### Icons

`<Button>` has support for icons, `leftIcon` and `rightIcon`
`leftIcon` will be placed to the left of the label text, and `rightIcon` to the right of the label text.

`<SecondaryButton>` and `<TertiaryButton>` support `leftIcon`


```javascript
<Button leftIcon={<MyLeftIcon />}>...</Button>
```
```javascript
<Button rightIcon={<MyRightIcon />}>...</Button>
```
```javascript
<SecondaryButton leftIcon={<MyLeftIcon />}>...</SecondaryButton>
```
```javascript
<TertiaryButton leftIcon={<MyLeftIcon />}>...</TertiaryButton>
```


### Type and onClick-handlers

The default button type is `type="submit"`, as with regular HTML buttons. If
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ffe-buttons-react",
"version": "5.1.2",
"version": "5.2.0",
"description": "React implementation of ffe-buttons",
"main": "lib/index.js",
"scripts": {
Expand Down
12 changes: 10 additions & 2 deletions src/Button.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import React, { PropTypes } from 'react';
import React, { cloneElement, PropTypes } from 'react';

export default function Button(props) {
const decorate = (icon, buttonType) => cloneElement(icon, { className: `ffe-${buttonType}-button__label-icon` });

const {
action,
ariaLoadingMessage = 'Vennligst vent',
buttonType = 'primary',
children,
className = '',
disableButton,
isLoading,
isTabbable,
label,
leftIcon,
rightIcon,
simpleContent = false,
buttonType = 'primary',
...rest
} = props;
const loadingClass = isLoading ? `ffe-${buttonType}-button--loading` : '';
Expand All @@ -33,7 +37,9 @@ export default function Button(props) {
className={`ffe-${buttonType}-button__label-text
${isLoading ? `ffe-${buttonType}-button__label-text--loading` : ''}`}
>
{leftIcon && decorate(leftIcon, buttonType)}
{label || children}
{rightIcon && rightIcon}
</span>
<span
className={`ffe-${buttonType}-button__label-spinner`}
Expand Down Expand Up @@ -66,7 +72,9 @@ Button.propTypes = {
isTabbable: PropTypes.bool,
autoFocus: PropTypes.bool,
label: PropTypes.string,
leftIcon: PropTypes.node,
onClick: PropTypes.func,
rightIcon: PropTypes.node,
simpleContent: PropTypes.bool,
style: PropTypes.object,
type: PropTypes.oneOf(['button', 'submit', 'reset']),
Expand Down
17 changes: 13 additions & 4 deletions src/SecondaryButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import React, { PropTypes } from 'react';
import Button from './Button';

export default function SecondaryButton(props) {
return <Button {...props} buttonType="secondary">
{props.children}
</Button>;
}
const {
children,
...rest
} = props;

return (
<Button
{...rest}
buttonType="secondary"
>
{children}
</Button>
);
}

SecondaryButton.propTypes = {
children: PropTypes.node
Expand Down
14 changes: 10 additions & 4 deletions src/ShortcutButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ import Button from './Button';
export default function ShortcutButton(props) {
const children = props.label ? props.label : props.children;

return <Button {...props} label={null} buttonType="shortcut">
{children}
<ChevronIcon className="ffe-shortcut-button__icon-chevron" />
</Button>;
return (
<Button
{...props}
label={null}
buttonType="shortcut"
rightIcon={<ChevronIcon className="ffe-shortcut-button__icon-chevron" />}
>
{children}
</Button>
);
}

ShortcutButton.propTypes = {
Expand Down
16 changes: 13 additions & 3 deletions src/TertiaryButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ import React, { PropTypes } from 'react';
import Button from './Button';

export default function TertiaryButton(props) {
return <Button {...props} buttonType="tertiary" simpleContent={true}>
{props.children}
</Button>;
const {
children,
...rest
} = props;
return (
<Button
{...rest}
buttonType="tertiary"
simpleContent={true}
>
{children}
</Button>
);
}

TertiaryButton.propTypes = {
Expand Down

0 comments on commit 6fec93c

Please sign in to comment.