Skip to content

Commit

Permalink
feat(Alert): Adding Alert Component
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenfitzpatrick committed Mar 3, 2018
1 parent be33d38 commit b12b195
Show file tree
Hide file tree
Showing 11 changed files with 5,787 additions and 1,220 deletions.
6,758 changes: 5,562 additions & 1,196 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"dependencies": {
"classnames": "^2.2.5",
"downshift": "^1.28.0",
"npm": "^5.7.1",
"prop-types": "^15.6.0"
},
"peerDependencies": {
Expand Down
26 changes: 22 additions & 4 deletions src/components/Alert/Alert.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
import PropTypes from 'prop-types';
import React from 'react';
import React, { Fragment } from 'react';

import { FitzyAlert, FitzyClose } from './Alert.styled';

function Alert({ onCancel, type, className, children }) {
function Alert({ onCancel, type, className, children, title }) {
return (
<FitzyAlert role="alert" type={type} className={className}>
{onCancel ? <FitzyClose onClick={onCancel}>×</FitzyClose> : null}
{children}
<Fragment>
<h2>{title}</h2>
<div>{children}</div>
</Fragment>
{onCancel ? (
<FitzyClose onClick={onCancel}>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 212.982 212.982">
<path
d="M131.804 106.491l75.936-75.936c6.99-6.99 6.99-18.323 0-25.312-6.99-6.99-18.322-6.99-25.312 0L106.491 81.18 30.554 5.242c-6.99-6.99-18.322-6.99-25.312 0-6.989 6.99-6.989 18.323 0 25.312l75.937 75.936-75.937 75.937c-6.989 6.99-6.989 18.323 0 25.312 6.99 6.99 18.322 6.99 25.312 0l75.937-75.937 75.937 75.937c6.989 6.99 18.322 6.99 25.312 0 6.99-6.99 6.99-18.322 0-25.312l-75.936-75.936z"
fill-rule="evenodd"
clip-rule="evenodd"
/>
</svg>
<span />
</FitzyClose>
) : null}
</FitzyAlert>
);
}

Alert.propTypes = {
/**
* Title for the error message
*/
title: PropTypes.string.isRequired,
/**
* Handler to close the Alert Banner
*/
Expand Down
39 changes: 34 additions & 5 deletions src/components/Alert/Alert.styled.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import styled from 'styled-components';

import { CloseButton } from '../../styles/helpers.styled';

const sizes = {
Error: 'red',
Warning: 'yellow',
Expand All @@ -10,15 +12,42 @@ const sizes = {
const FitzyAlert = styled.div`
position: relative;
color: white;
padding: 8px;
padding: 1rem;
background-color: ${({ type }) => sizes[type]};
display: flex;
align-items: baseline;
flex-wrap: wrap;
width: 100%;
padding-right: 25px;
border: 1px solid #d05353;
background-color: #d97575;
h2 {
line-height: normal;
font-weight: bold;
margin-right: 1.5rem;
margin-bottom: 0.25rem;
}
div {
margin-top: 0.25rem;
}
`;

const FitzyClose = styled.button`
const FitzyClose = CloseButton.extend`
position: absolute;
right: 0;
top: 0;
color: white;
right: 1.5rem;
top: 1.5rem;
height: 0.75rem;
width: 0.75rem;
> svg {
fill: currentColor;
}
> span {
}
`;

/** @component */
Expand Down
12 changes: 3 additions & 9 deletions src/components/Alert/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ Basic Alert :
```jsx
initialState = { value: '' };

<Alert>Oops, looks like an issue has occured.</Alert>;
```

Alert with close button :

```jsx
initialState = { value: '' };

<Alert onCancel={() => {}}>Oops, looks like an issue has occured.</Alert>;
<Alert title="Authentication Error" onCancel={() => {}}>
Oops, looks like an issue has occured.
</Alert>;
```
66 changes: 62 additions & 4 deletions src/components/Alert/__tests__/__snapshots__/AlertTest.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,90 @@ exports[`Alert snapshots should match for basic 1`] = `
.c0 {
position: relative;
color: white;
padding: 8px;
padding: 1rem;
background-color: red;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: baseline;
-webkit-box-align: baseline;
-ms-flex-align: baseline;
align-items: baseline;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
width: 100%;
padding-right: 25px;
border: 1px solid #d05353;
background-color: #d97575;
}
.c0 h2 {
line-height: normal;
font-weight: bold;
margin-right: 1.5rem;
margin-bottom: 0.25rem;
}
.c0 div {
margin-top: 0.25rem;
}
<div
className="c0"
role="alert"
type="Error"
>
This is an error
<h2 />
<div>
This is an error
</div>
</div>
`;

exports[`Alert snapshots should match with button 1`] = `
.c0 {
position: relative;
color: white;
padding: 8px;
padding: 1rem;
background-color: red;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-align-items: baseline;
-webkit-box-align: baseline;
-ms-flex-align: baseline;
align-items: baseline;
-webkit-flex-wrap: wrap;
-ms-flex-wrap: wrap;
flex-wrap: wrap;
width: 100%;
padding-right: 25px;
border: 1px solid #d05353;
background-color: #d97575;
}
.c0 h2 {
line-height: normal;
font-weight: bold;
margin-right: 1.5rem;
margin-bottom: 0.25rem;
}
.c0 div {
margin-top: 0.25rem;
}
<div
className="c0"
role="alert"
type="Error"
>
This is an error
<h2 />
<div>
This is an error
</div>
</div>
`;
2 changes: 1 addition & 1 deletion src/components/Input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Input.propTypes = {
/**
* Pass down a ref for the Input
*/
innerRef: PropTypes.node
innerRef: PropTypes.oneOfType([PropTypes.object, PropTypes.func])
};

Input.defaultProps = {
Expand Down
41 changes: 41 additions & 0 deletions src/styles/cancel-music.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/styles/helpers.styled.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import styled from 'styled-components';

const CloseButton = styled.button`
-webkit-appearance: none;
background: transparent;
padding: 0;
border: 0;
outline: none;
color: inherit;
cursor: pointer;
line-height: 1;
`;

export { CloseButton };
46 changes: 46 additions & 0 deletions styleguide-config/reset.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,50 @@
*/
*:before, *:after,* {
box-sizing: border-box
}

html {
box-sizing: border-box;
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}

body {
-moz-osx-font-smoothing: grayscale;
-webkit-font-smoothing: antialiased;
text-rendering: optimizeLegibility;
}

html,
body {
height: 100%;
margin: 0;
width: 100%;
}

*,
*::before,
*::after {
box-sizing: inherit;
}

h1,
h2,
h3,
h4 {
font-size: inherit;
font-weight: inherit;
}

h1,
h2,
h3,
h4,
p,
blockquote,
figure,
ol,
ul {
margin: 0;
padding: 0;
}
2 changes: 1 addition & 1 deletion styleguide.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
styles: {
StyleGuide: {
'@global body': {
fontFamily: 'Source Sans Pro'
fontFamily: ['-apple-system', 'BlinkMacSystemFont']
}
}
},
Expand Down

0 comments on commit b12b195

Please sign in to comment.