-
Notifications
You must be signed in to change notification settings - Fork 0
CORE-1085: Adding Banner folder #102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
79cb9b1
Adding Banner folder
jomcarvajal ef0f462
update snaps
jomcarvajal c128ed1
linter
jomcarvajal f05dc77
bump minor version
jomcarvajal 76461f3
move styles to the same file of logic
jomcarvajal 84e39c9
fix exports
jomcarvajal 716209c
fix imports
jomcarvajal 3816408
move DismissIcon to svg folder
jomcarvajal 08f77ab
update snpas
jomcarvajal 360dea9
remove DismissIcon export
jomcarvajal f144bd3
container added for Banner stories
jomcarvajal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9014da9bbe05bd45f38841c02e34dcb5a8e3e1d8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { Banner } from "./Banner"; | ||
import renderer from 'react-test-renderer'; | ||
|
||
describe('Banner', () => { | ||
it('matches snapshot (single message, no dismiss)', () => { | ||
const tree = renderer.create( | ||
<Banner messages={['This is a note']} severity='note' /> | ||
).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('matches snapshot (multiple messages, with dismiss)', () => { | ||
const tree = renderer.create( | ||
<Banner | ||
messages={['This is warning one', 'This is warning two']} | ||
severity='warning' | ||
onDismiss={() => () => alert('dismiss checkout')} | ||
/> | ||
).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('matches snapshot (error, with dismiss)', () => { | ||
const tree = renderer.create( | ||
<Banner | ||
messages={['This is an error']} | ||
severity='error' | ||
onDismiss={() => () => alert('dismiss checkout')} | ||
/> | ||
).toJSON(); | ||
expect(tree).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import { Banner } from './Banner'; | ||
import styled from 'styled-components'; | ||
|
||
const BannerContainer = styled.div` | ||
font-size: 1.2rem; | ||
position: relative; | ||
padding-right: 2.5rem; | ||
width: 42rem; | ||
|
||
svg { | ||
position: absolute; | ||
top: 1.7rem; | ||
right: 1rem; | ||
cursor: pointer; | ||
} | ||
`; | ||
|
||
export const Error = () => ( | ||
<BannerContainer> | ||
<Banner messages={['This is an error message']} severity='error' /> | ||
</BannerContainer> | ||
); | ||
|
||
export const Warning = () => ( | ||
<BannerContainer> | ||
<Banner messages={['This is a warning message']} severity='warning' /> | ||
</BannerContainer> | ||
); | ||
|
||
export const Note = () => ( | ||
<BannerContainer> | ||
<Banner messages={['This is a note message']} severity='note' /> | ||
</BannerContainer> | ||
); | ||
|
||
export const MultipleMessages = () => ( | ||
<BannerContainer> | ||
<Banner messages={['First message', 'Second message', 'Third message']} severity='warning' /> | ||
</BannerContainer> | ||
); | ||
|
||
export const Dismissible = () => { | ||
const [visible, setVisible] = React.useState(true); | ||
return visible ? ( | ||
<BannerContainer> | ||
<Banner | ||
messages={['This is a dismissible warning message']} | ||
severity='warning' | ||
onDismiss={() => setVisible(false)} | ||
/> | ||
</BannerContainer> | ||
) : null; | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { DismissIcon } from "../svgs/DismissIcon"; | ||
import { Html } from "../Html"; | ||
import styled from 'styled-components'; | ||
import { Button, ButtonLink } from '../Button'; | ||
import { colors } from '../../theme'; | ||
|
||
export type BannerSeverity = 'note' | 'warning' | 'error'; | ||
|
||
export const Severity = styled.span` | ||
font-weight: bold; | ||
text-transform: uppercase; | ||
`; | ||
|
||
export const StyledBanner = styled.div<{severity: BannerSeverity}>` | ||
position: relative; | ||
background: ${({severity}) => severity === 'error' ? '#F8E8EA' : '#fff5e0'}; | ||
color: ${({severity}) => severity === 'error' ? colors.palette.darkRed : '#976502'}; | ||
border: ${({severity}) => severity === 'error' ? `1px solid ${colors.palette.lightRed}` : '1px solid #fdbd3e'}; | ||
padding: .6rem 1.6rem; | ||
margin: 0 0 1.6rem 0; | ||
line-height: 2rem; | ||
display: flex; | ||
align-items: center; | ||
|
||
a { | ||
text-decoration: none; | ||
color: ${colors.palette.mediumBlue}; | ||
|
||
&:hover { | ||
text-decoration: underline; | ||
color: ${colors.link.hover} | ||
} | ||
} | ||
|
||
${ButtonLink} { | ||
font-size: 1.6rem; | ||
} | ||
`; | ||
|
||
export const CloseButton = styled(Button)<{severity: BannerSeverity}>` | ||
color: ${({severity}) => severity === 'error' ? colors.palette.darkRed : '#976502'}; | ||
overflow: visible; | ||
background: none; | ||
border: none; | ||
padding: 0; | ||
font: inherit; | ||
cursor: pointer; | ||
outline: inherit; | ||
box-shadow: none; | ||
margin-left: 2.4rem; | ||
|
||
&:not([disabled]):hover, | ||
&:not([disabled]):active { | ||
background: none; | ||
} | ||
`; | ||
|
||
export const Banner = (props: {messages: string[]; severity: BannerSeverity; onDismiss?: () => void}) => { | ||
const numWarnings = props.messages.length; | ||
|
||
return <StyledBanner severity={props.severity}> | ||
<div> | ||
{props.severity !== 'error' ? <Severity>{props.severity === 'note' ? 'Note: ' : 'Warning: '}</Severity> : null} | ||
{props.messages.map((message, i) => | ||
<Html block={numWarnings > 1} key={i}> | ||
{numWarnings > 1 ? `[${i + 1} of ${numWarnings}]: ${message}`: message} | ||
</Html> | ||
)} | ||
</div> | ||
{props.onDismiss | ||
? <CloseButton severity={props.severity} onClick={props.onDismiss} aria-label='dismiss'> | ||
<DismissIcon aria-hidden='true' focusable='false' /> | ||
</CloseButton> | ||
: null} | ||
</StyledBanner>; | ||
}; |
136 changes: 136 additions & 0 deletions
136
src/components/Banner/__snapshots__/Banner.spec.tsx.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Banner matches snapshot (error, with dismiss) 1`] = ` | ||
<div | ||
className="sc-jSMfEi iGEqwr" | ||
> | ||
<div> | ||
<span | ||
dangerouslySetInnerHTML={ | ||
Object { | ||
"__html": "This is an error", | ||
} | ||
} | ||
/> | ||
</div> | ||
<button | ||
aria-label="dismiss" | ||
className="sc-bczRLJ sc-gKXOVf dOOknK dwyZcw" | ||
onClick={[Function]} | ||
severity="error" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
focusable="false" | ||
height="15px" | ||
version="1.1" | ||
viewBox="0 0 15 15" | ||
width="15px" | ||
> | ||
<g | ||
fill="none" | ||
fillRule="evenodd" | ||
stroke="none" | ||
strokeWidth="1" | ||
> | ||
<g | ||
fill="currentColor" | ||
transform="translate(-302.000000, -18.000000)" | ||
> | ||
<g | ||
transform="translate(302.000000, 18.000000)" | ||
> | ||
<path | ||
d="M7.5,5.41522791 L12.0331524,0.579865364 C12.3077536,0.286957429 12.7165503,0.24816296 12.946282,0.493210121 L13.9861449,1.60239723 C14.2158766,1.84744439 14.1795068,2.28349422 13.9049056,2.57640216 L9.37175324,7.41176471 L13.9049056,12.2471273 C14.1795068,12.5400352 14.2158766,12.976085 13.9861449,13.2211322 L12.946282,14.3303193 C12.7165503,14.5753665 12.3077536,14.536572 12.0331524,14.243664 L7.5,9.4083015 L2.96684761,14.243664 C2.69224642,14.536572 2.2834497,14.5753665 2.05371799,14.3303193 L1.01385508,13.2211322 C0.784123363,12.976085 0.820493178,12.5400352 1.09509437,12.2471273 L5.62824676,7.41176471 L1.09509437,2.57640216 C0.820493178,2.28349422 0.784123363,1.84744439 1.01385508,1.60239723 L2.05371799,0.493210121 C2.2834497,0.24816296 2.69224642,0.286957429 2.96684761,0.579865364 L7.5,5.41522791 Z" | ||
/> | ||
</g> | ||
</g> | ||
</g> | ||
</svg> | ||
</button> | ||
</div> | ||
`; | ||
|
||
exports[`Banner matches snapshot (multiple messages, with dismiss) 1`] = ` | ||
<div | ||
className="sc-jSMfEi lmuhoy" | ||
> | ||
<div> | ||
<span | ||
className="sc-eCYdqJ EIRbC" | ||
> | ||
Warning: | ||
</span> | ||
<div | ||
dangerouslySetInnerHTML={ | ||
Object { | ||
"__html": "[1 of 2]: This is warning one", | ||
} | ||
} | ||
/> | ||
<div | ||
dangerouslySetInnerHTML={ | ||
Object { | ||
"__html": "[2 of 2]: This is warning two", | ||
} | ||
} | ||
/> | ||
</div> | ||
<button | ||
aria-label="dismiss" | ||
className="sc-bczRLJ sc-gKXOVf dOOknK fGvwkl" | ||
onClick={[Function]} | ||
severity="warning" | ||
> | ||
<svg | ||
aria-hidden="true" | ||
focusable="false" | ||
height="15px" | ||
version="1.1" | ||
viewBox="0 0 15 15" | ||
width="15px" | ||
> | ||
<g | ||
fill="none" | ||
fillRule="evenodd" | ||
stroke="none" | ||
strokeWidth="1" | ||
> | ||
<g | ||
fill="currentColor" | ||
transform="translate(-302.000000, -18.000000)" | ||
> | ||
<g | ||
transform="translate(302.000000, 18.000000)" | ||
> | ||
<path | ||
d="M7.5,5.41522791 L12.0331524,0.579865364 C12.3077536,0.286957429 12.7165503,0.24816296 12.946282,0.493210121 L13.9861449,1.60239723 C14.2158766,1.84744439 14.1795068,2.28349422 13.9049056,2.57640216 L9.37175324,7.41176471 L13.9049056,12.2471273 C14.1795068,12.5400352 14.2158766,12.976085 13.9861449,13.2211322 L12.946282,14.3303193 C12.7165503,14.5753665 12.3077536,14.536572 12.0331524,14.243664 L7.5,9.4083015 L2.96684761,14.243664 C2.69224642,14.536572 2.2834497,14.5753665 2.05371799,14.3303193 L1.01385508,13.2211322 C0.784123363,12.976085 0.820493178,12.5400352 1.09509437,12.2471273 L5.62824676,7.41176471 L1.09509437,2.57640216 C0.820493178,2.28349422 0.784123363,1.84744439 1.01385508,1.60239723 L2.05371799,0.493210121 C2.2834497,0.24816296 2.69224642,0.286957429 2.96684761,0.579865364 L7.5,5.41522791 Z" | ||
/> | ||
</g> | ||
</g> | ||
</g> | ||
</svg> | ||
</button> | ||
</div> | ||
`; | ||
|
||
exports[`Banner matches snapshot (single message, no dismiss) 1`] = ` | ||
<div | ||
className="sc-jSMfEi lmuhoy" | ||
> | ||
<div> | ||
<span | ||
className="sc-eCYdqJ EIRbC" | ||
> | ||
Note: | ||
</span> | ||
<span | ||
dangerouslySetInnerHTML={ | ||
Object { | ||
"__html": "This is a note", | ||
} | ||
} | ||
/> | ||
</div> | ||
</div> | ||
`; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason to leave this out of the component itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I don't see that's part of assignments. If a put it inside the component it could break how old looks in assignments. I tried to leave everything the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you think it's okay. @bethshook
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think that's fine, as long as it looks as expected when you import it to assignments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I made some tests in assignments and everything looks like before the import from ui-components!