Skip to content

Commit

Permalink
feat: add border radius radius prop to button icon (#2496)
Browse files Browse the repository at this point in the history
* feat: add borderRadius prop to ButtonIcon component

* feat: add borderRadius prop to ButtonIcon component

* add type to index.d.ts

Co-authored-by: Adrian Estevez <[email protected]>
Co-authored-by: Jose Leandro Torres <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2022
1 parent 15cca49 commit d72f26a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/components/Button/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ import React from 'react';
import { Button } from 'react-rainbow-components';

<div className="rainbow-p-vertical_large rainbow-align-content_center rainbow-flex_wrap">
<Button label="Button Square" variant="brand" className="rainbow-m-around_medium" borderRadius='square'/>
<Button label="Button Semi Rounded" variant="brand" className="rainbow-m-around_medium" borderRadius='semi-rounded'/>
<Button label="Button Rounded" variant="brand" className="rainbow-m-around_medium" borderRadius='rounded'/>
<Button label="Button Square" variant="brand" className="rainbow-m-around_medium" borderRadius="square"/>
<Button label="Button Semi Rounded" variant="brand" className="rainbow-m-around_medium" borderRadius="semi-rounded"/>
<Button label="Button Rounded" variant="brand" className="rainbow-m-around_medium" borderRadius="rounded"/>
</div>
```
1 change: 1 addition & 0 deletions src/components/ButtonIcon/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface ButtonIconProps extends BaseProps {
ariaPressed?: boolean;
form?: string;
id?: string;
borderRadius?: 'square' | 'semi-rounded' | 'rounded';
}

declare const ButtonIcon: ComponentType<ButtonIconProps>;
Expand Down
5 changes: 5 additions & 0 deletions src/components/ButtonIcon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const ButtonIcon = React.forwardRef((props, ref) => {
variant,
size,
tooltip,
borderRadius,
} = props;
const {
onMouseEnter,
Expand Down Expand Up @@ -119,6 +120,7 @@ const ButtonIcon = React.forwardRef((props, ref) => {
onMouseLeave={handleMouseLeave}
form={form}
ref={buttonRef}
borderRadius={borderRadius}
>
{icon}
<AssistiveText text={assistiveText} />
Expand Down Expand Up @@ -209,6 +211,8 @@ ButtonIcon.propTypes = {
style: PropTypes.object,
/** The id of the outer element. */
id: PropTypes.string,
/** The border radius of the button. Valid values are square, semi-rounded and rounded. This value defaults to rounded. */
borderRadius: PropTypes.oneOf(['square', 'semi-rounded', 'rounded']),
};

ButtonIcon.defaultProps = {
Expand Down Expand Up @@ -237,6 +241,7 @@ ButtonIcon.defaultProps = {
ariaControls: undefined,
ariaExpanded: undefined,
form: undefined,
borderRadius: 'rounded',
};

export default ButtonIcon;
22 changes: 22 additions & 0 deletions src/components/ButtonIcon/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ import { faStar } from '@fortawesome/free-regular-svg-icons';
</div>
```

# ButtonIcons with Border Radius
##### ButtonIcons with different border radius.

```js
import React from 'react';
import { ButtonIcon } from 'react-rainbow-components';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStar } from '@fortawesome/free-regular-svg-icons';

<div className="rainbow-p-vertical_large rainbow-p-left_x-large rainbow-flex rainbow-align_center">
<div className="rainbow-p-right_large">
<ButtonIcon variant="neutral" borderRadius="square" icon={<FontAwesomeIcon icon={faStar} />} />
</div>
<div className="rainbow-p-right_large">
<ButtonIcon variant="neutral" borderRadius="semi-rounded" icon={<FontAwesomeIcon icon={faStar} />} />
</div>
<div className="rainbow-p-right_large">
<ButtonIcon variant="neutral" borderRadius="rounded" icon={<FontAwesomeIcon icon={faStar} />} />
</div>
</div>
```

# ButtonIcons with shaded variant
##### The appearance of a ButtonIcon can be changed by implementing the shaded variant, so the whole section will appear with a shadow around it.

Expand Down
18 changes: 17 additions & 1 deletion src/components/ButtonIcon/styled/button.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import styled from 'styled-components';
import { BORDER_RADIUS_2 } from '../../../styles/borderRadius';
import {
BORDER_RADIUS_2,
BORDER_RADIUS_SQUARE,
BORDER_RADIUS_SEMI_ROUNDED,
} from '../../../styles/borderRadius';
import { COLOR_WHITE, COLOR_GRAY_3, COLOR_DARK_1 } from '../../../styles/colors';
import { lighten, colorToRgba, replaceAlpha } from '../../../styles/helpers/color';
import attachThemeAttrs from '../../../styles/helpers/attachThemeAttrs';
Expand Down Expand Up @@ -397,6 +401,18 @@ const StyledButton = attachThemeAttrs(styled.button).attrs(props => {
font-size: 1rem !important;
}
`};
${props =>
props.borderRadius === 'square' &&
`
border-radius: ${BORDER_RADIUS_SQUARE};
`};
${props =>
props.borderRadius === 'semi-rounded' &&
`
border-radius: ${BORDER_RADIUS_SEMI_ROUNDED};
`};
`;

export default StyledButton;

0 comments on commit d72f26a

Please sign in to comment.