diff --git a/catalog/pages/buttons/index.js b/catalog/pages/buttons/index.js index d86ba9379..f4b17a454 100644 --- a/catalog/pages/buttons/index.js +++ b/catalog/pages/buttons/index.js @@ -5,7 +5,7 @@ import { Container, Row, Column } from "../../../src/components/Grid"; import Spacing from "../../../src/components/Spacing"; import { Button, Badge, RatingBadge } from "../../../src/components/Button"; import ButtonWithLoading from "../../../src/components/ButtonWithLoading"; -import { ChevronIcon, StarIcon } from "../../../src/components/Icons"; +import { ChevronIcon, HomeIcon, StarIcon } from "../../../src/components/Icons"; import { colors, themes } from "../../../src/theme"; const starIconStyles = { marginRight: "2px" }; @@ -18,6 +18,7 @@ export default { ButtonWithLoading, Badge, ChevronIcon, + HomeIcon, StarIcon, RatingBadge, colors, diff --git a/catalog/pages/buttons/index.md b/catalog/pages/buttons/index.md index f82c9c294..d50ff5980 100644 --- a/catalog/pages/buttons/index.md +++ b/catalog/pages/buttons/index.md @@ -18,6 +18,10 @@ rows: - Prop: href Type: string Notes: Determines wether underlying HTML element should be an `a` + - Prop: icon + Type: node + Default: null + Notes: Render as an icon with Button's children. Icon of height `16px` works best with `regular` sized button - Prop: children Type: node Default: @@ -114,7 +118,7 @@ rows: - + diff --git a/src/components/Button/Base.styles.tsx b/src/components/Button/Base.styles.tsx index e1108717c..ba452033f 100644 --- a/src/components/Button/Base.styles.tsx +++ b/src/components/Button/Base.styles.tsx @@ -1,7 +1,7 @@ import styled, { StyledComponent } from "styled-components"; import { SPECIAL, Size, ButtonVariant } from "../constants"; -import { typography, constants } from "../../theme"; +import { typography, constants, spacing } from "../../theme"; import { getThemeValue } from "../../utils"; const colorVariants = { @@ -139,10 +139,16 @@ export const StyledButton = styled.button` variant === SPECIAL ? "opacity: 0.4;" : "opacity: 0.2;"}; } - &.noFocus:focus { box-shadow: none; } + + &.iconed svg{ + position: relative; + display: inline-block; + vertical-align: text-top; + margin-right: ${spacing.cozy}; + } `; StyledButton.defaultProps = { diff --git a/src/components/Button/Base.tsx b/src/components/Button/Base.tsx index 65eb6d222..64d916c81 100644 --- a/src/components/Button/Base.tsx +++ b/src/components/Button/Base.tsx @@ -17,6 +17,7 @@ export interface ButtonProps { readonly className?: string; readonly variant: ButtonVariant; readonly size: Size; + readonly icon: any; } export interface ButtonLinkProps extends ButtonProps { @@ -35,12 +36,14 @@ class Button extends Component { static propTypes: ValidationMap> = { variant: PropTypes.oneOf(BUTTON_VARIANTS), size: PropTypes.oneOf(SIZES), + icon: PropTypes.node, children: PropTypes.node.isRequired }; static defaultProps: ButtonProps = { size: REGULAR, - variant: STANDARD + variant: STANDARD, + icon: null }; componentDidMount() { @@ -76,7 +79,7 @@ class Button extends Component { button = React.createRef(); render() { - const { variant, size, children, ...rest } = this.props; + const { variant, size, icon, children, ...rest } = this.props; if (isButtonLinkProps(this.props)) { const { rel, target } = this.props; @@ -88,8 +91,10 @@ class Button extends Component { size={size} rel={validatedRel} as="a" + className={`${icon ? "iconed" : ""}`} {...rest} > + {icon} {children} ); @@ -100,9 +105,10 @@ class Button extends Component { variant={variant} size={size} {...rest} - className={`${rest.className || ""} noFocus`} + className={`${rest.className || ""} ${icon ? "iconed" : ""} noFocus`} ref={this.button} > + {icon} {children} ); diff --git a/src/components/Button/__tests__/__snapshots__/Base.spec.js.snap b/src/components/Button/__tests__/__snapshots__/Base.spec.js.snap index 8d9078607..a1cff1c6f 100644 --- a/src/components/Button/__tests__/__snapshots__/Base.spec.js.snap +++ b/src/components/Button/__tests__/__snapshots__/Base.spec.js.snap @@ -55,6 +55,13 @@ exports[`