Skip to content

Commit

Permalink
Merge pull request #669 from Varand-ticketmaster/DSCO-5817
Browse files Browse the repository at this point in the history
DSCO-5817: Add 'custom' variant to Banner
  • Loading branch information
Varand-ticketmaster authored Jun 23, 2020
2 parents 573611e + 9ec79da commit ca50b00
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 32 deletions.
17 changes: 17 additions & 0 deletions catalog/pages/banner/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,23 @@ rows:
}}
/>
<Spacing bottom={{small: "moderate"}}/>
<Banner
heading="This is your primary message text."
content="This is the content section"
linkText="Link"
href="https://www.ticketmaster.com/"
linkProps={{ target: '_blank' }}
isOpen
variant="custom"
expandedText="expandedText"
collapsedText="collapsedText"
isExpanded
customColors={{
primaryColor: "#c56fff",
backgroundColor: "rgba(240, 218, 255, 0.4)",
textColor: "#262626"
}}
/>
<FunctionalBannerDemo />
</div>
```
10 changes: 10 additions & 0 deletions src/components/Banner/Banner.styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,28 @@ export const Container = styled.div`
background-color: ${getThemeValue("primary", "lightest")};
border-color: ${getThemeValue("primary", "base")};
}
&.banner-variant-custom {
background-color: ${props => props.customColors.backgroundColor};
border-color: ${props => props.customColors.primaryColor};
}
`;

export const ContentSection = styled.div`
font-family: Averta, Courier, monospace;
padding-right: ${spacing.comfy};
`;

export const HeaderText = styled(Text)`
color: ${props => props.customColors.textColor};
`;

export const Content = styled(Text)`
padding-top: 12px;
opacity: 1;
transition: opacity 0.3s ${constants.easing.easeInOutQuad} 0.1s;
line-height: 1.29;
color: ${props => props.customColors.textColor};
.collapsed & {
transition: opacity 0.3s ${constants.easing.easeInOutQuad};
Expand Down
42 changes: 21 additions & 21 deletions src/components/Banner/__tests__/__snapshots__/index.spec.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ exports[`<Banner /> renders correctly when open 1`] = `
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down Expand Up @@ -248,7 +248,7 @@ exports[`<Banner /> renders correctly when variant is set 1`] = `
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down Expand Up @@ -344,7 +344,7 @@ exports[`<Banner /> renders correctly with close button 1`] = `
opacity: 0;
}
.sc-fzqBZW.c6 {
.sc-fzqNJr.c6 {
background-color: transparent;
border: none;
padding: 0;
Expand All @@ -368,8 +368,8 @@ exports[`<Banner /> renders correctly with close button 1`] = `
justify-content: center;
}
.sc-fzqBZW.c6:active,
.sc-fzqBZW.c6:hover {
.sc-fzqNJr.c6:active,
.sc-fzqNJr.c6:hover {
background-color: transparent;
}
Expand Down Expand Up @@ -429,7 +429,7 @@ exports[`<Banner /> renders correctly with close button 1`] = `
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down Expand Up @@ -606,7 +606,7 @@ exports[`<Banner /> renders correctly with close button hidden 1`] = `
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down Expand Up @@ -724,7 +724,7 @@ exports[`<Banner /> renders correctly with content 1`] = `
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down Expand Up @@ -864,7 +864,7 @@ exports[`<Banner /> renders correctly with custom icon 1`] = `
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down Expand Up @@ -964,7 +964,7 @@ exports[`<Banner /> renders correctly with custom title for the close button 1`]
opacity: 0;
}
.sc-fzoyAV.c7 {
.sc-fzoLag.c7 {
background-color: transparent;
border: none;
padding: 0;
Expand All @@ -988,8 +988,8 @@ exports[`<Banner /> renders correctly with custom title for the close button 1`]
justify-content: center;
}
.sc-fzoyAV.c7:active,
.sc-fzoyAV.c7:hover {
.sc-fzoLag.c7:active,
.sc-fzoLag.c7:hover {
background-color: transparent;
}
Expand Down Expand Up @@ -1049,7 +1049,7 @@ exports[`<Banner /> renders correctly with custom title for the close button 1`]
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down Expand Up @@ -1183,7 +1183,7 @@ exports[`<Banner /> renders correctly with expand/collapse button 1`] = `
opacity: 0;
}
.sc-fzoLag.c7 {
.sc-fzoXzr.c7 {
background-color: transparent;
border: none;
padding: 0;
Expand All @@ -1207,8 +1207,8 @@ exports[`<Banner /> renders correctly with expand/collapse button 1`] = `
justify-content: center;
}
.sc-fzoLag.c7:active,
.sc-fzoLag.c7:hover {
.sc-fzoXzr.c7:active,
.sc-fzoXzr.c7:hover {
background-color: transparent;
}
Expand Down Expand Up @@ -1268,7 +1268,7 @@ exports[`<Banner /> renders correctly with expand/collapse button 1`] = `
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down Expand Up @@ -1403,7 +1403,7 @@ exports[`<Banner /> renders correctly with link 1`] = `
opacity: 0;
}
.sc-fzqNJr.c7 {
.sc-fzoyAV.c7 {
background-color: transparent;
border: none;
padding: 0;
Expand All @@ -1427,8 +1427,8 @@ exports[`<Banner /> renders correctly with link 1`] = `
justify-content: center;
}
.sc-fzqNJr.c7:active,
.sc-fzqNJr.c7:hover {
.sc-fzoyAV.c7:active,
.sc-fzoyAV.c7:hover {
background-color: transparent;
}
Expand Down Expand Up @@ -1488,7 +1488,7 @@ exports[`<Banner /> renders correctly with link 1`] = `
class="c2"
>
<span
class="c3 text text--dark text--primary"
class="c3 text text--dark text--primary "
>
This is your primary message text.
</span>
Expand Down
5 changes: 3 additions & 2 deletions src/components/Banner/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ErrorIcon, SuccessIcon, AlertIcon, InfoIcon } from "../Icons";

export const variants = ["error", "success", "alert", "info"];
export const variants = ["error", "success", "alert", "info", "custom"];
export const variantsIcons = {
[variants[0]]: ErrorIcon,
[variants[1]]: SuccessIcon,
[variants[2]]: AlertIcon,
[variants[3]]: InfoIcon
[variants[3]]: InfoIcon,
[variants[4]]: InfoIcon
};
47 changes: 38 additions & 9 deletions src/components/Banner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { Component } from "react";
import PropTypes from "prop-types";
import classnames from "classnames";
import { Transition } from "react-transition-group";
import { Text } from "../Text";
import { variants, variantsIcons } from "./constants";
import { constants } from "../../theme";
import {
Expand All @@ -13,6 +12,7 @@ import {
ContentSection,
CloseIcon,
Link,
HeaderText,
BASE_BANNER_HEIGHT,
MAX_BANNER_HEIGHT
} from "./Banner.styles";
Expand All @@ -35,7 +35,12 @@ class Banner extends Component {
variant: PropTypes.oneOf(variants),
icon: PropTypes.node,
closeButtonTitleText: PropTypes.string,
closeButtonHidden: PropTypes.bool
closeButtonHidden: PropTypes.bool,
customColors: PropTypes.shape({
primaryColor: PropTypes.string,
backgroundColor: PropTypes.string,
textColor: PropTypes.string
})
};

static defaultProps = {
Expand All @@ -55,7 +60,8 @@ class Banner extends Component {
variant: null,
icon: null,
closeButtonTitleText: "Close banner",
closeButtonHidden: false
closeButtonHidden: false,
customColors: {}
};

// Container max height should be handled programmatically as content height is unknown
Expand All @@ -78,6 +84,8 @@ class Banner extends Component {

content = React.createRef();

isCustomVariant = () => this.props.variant === variants[4];

toggleContent = () => {
const { onButtonClick } = this.props;
const collapsedMaxHeight = `${BASE_BANNER_HEIGHT}px`;
Expand Down Expand Up @@ -142,17 +150,31 @@ class Banner extends Component {
};

renderIcon = () => {
const { variant, icon } = this.props;
const {
variant,
icon,
customColors: { primaryColor: color }
} = this.props;
if (!variant && !icon) {
return null;
}
const Icon = variantsIcons[variant];

return icon || <Icon type="filled" size="regular" />;
let customColor = null;
if (this.isCustomVariant()) customColor = { color };

return icon || <Icon type="filled" size="regular" {...customColor} />;
};

render() {
const { isOpen, heading, content, variant, style } = this.props;
const {
isOpen,
heading,
content,
variant,
style,
customColors
} = this.props;
const { isExpanded, maxHeight } = this.state;

return (
Expand All @@ -169,15 +191,22 @@ class Banner extends Component {
[`banner-variant-${variant}`]: variant,
"visible-banner": state === "entered"
})}
customColors={this.isCustomVariant() && customColors}
>
<IconSection>{this.renderIcon()}</IconSection>
<ContentSection>
<Text tag="span" weight="semiBold">
<HeaderText
tag="span"
weight="semiBold"
customColors={this.isCustomVariant() && customColors}
>
{heading}
</Text>
</HeaderText>
{this.renderControl()}
<div ref={this.content} style={{ ...style, maxHeight }}>
<Content>{content}</Content>
<Content customColors={this.isCustomVariant() && customColors}>
{content}
</Content>
</div>
</ContentSection>
{this.renderCloseButton()}
Expand Down

0 comments on commit ca50b00

Please sign in to comment.