Skip to content

Commit ae84d8d

Browse files
Seagyn Davisseagyn
authored andcommitted
feat(toast): add toast to oxygen
1 parent bfa58a7 commit ae84d8d

File tree

4 files changed

+75
-11
lines changed

4 files changed

+75
-11
lines changed

.storybook/addons.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
import '@storybook/addon-actions/register';
21
import '@storybook/addon-links/register';
32
import '@storybook/addon-knobs/register';

src/toast/index.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,22 @@
1+
import React from 'react';
12
import { PropTypes } from 'prop-types';
2-
import Toast from './style';
3+
import { CheckIcon, ToastContainer, WarningIcon } from './style';
4+
5+
const Toast = ({ children, type }) => (
6+
<ToastContainer>
7+
{type === 'warning' && <WarningIcon />}
8+
{type === 'success' && <CheckIcon />}
9+
{children}
10+
</ToastContainer>
11+
);
312

413
Toast.propTypes = {
5-
children: PropTypes.string.isRequired
14+
children: PropTypes.string.isRequired,
15+
type: PropTypes.oneOf(['success', 'warning'])
16+
};
17+
18+
Toast.defaultProps = {
19+
type: 'success'
620
};
721

822
export default Toast;

src/toast/style.js

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,50 @@
1-
import styled from 'styled-components';
1+
import styled, { css } from 'styled-components';
22
import colors from '../colors';
3+
import breakpoints from '../breakpoints';
4+
import { CheckCircle } from 'styled-icons/material/CheckCircle';
5+
import { Warning } from 'styled-icons/material/Warning';
36

4-
export default styled.div`
7+
const Icon = css`
8+
margin-right: 7px;
9+
width: 19px;
10+
11+
@media (min-width: ${breakpoints.small}) {
12+
width: 22px;
13+
}
14+
`;
15+
16+
export const CheckIcon = styled(CheckCircle)`
17+
${Icon}
18+
color: ${colors.ocean};
19+
`;
20+
21+
export const WarningIcon = styled(Warning)`
22+
${Icon}
23+
color: ${colors.warning};
24+
`;
25+
26+
export const ToastContainer = styled.div`
527
align-items: center;
6-
background-color: ${colors.lightGallery};
28+
background-color: ${colors.white};
729
border-radius: 4px;
830
box-shadow: 0 9px 12px 0 rgba(7, 0, 37, 0.07),
931
0 2px 4px 0 rgba(7, 0, 37, 0.06);
1032
color: ${colors.lightStorm};
11-
display: block;
12-
font-weight: bold;
13-
font-size: 11px;
14-
padding: 7px 12px;
15-
text-transform: uppercase;
33+
display: flex;
34+
flex-direction: row;
35+
font: 600 14px/18px 'Source Sans Pro';
36+
height: auto;
37+
left: 0;
38+
margin: 20px;
39+
padding: 5px 10px;
40+
position: fixed;
41+
right: 0;
42+
top: 0;
43+
44+
@media (min-width: ${breakpoints.small}) {
45+
bottom: 0;
46+
font-size: 16px;
47+
left: auto;
48+
top: auto;
49+
}
1650
`;

stories/toast.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import React from 'react';
2+
import { storiesOf } from '@storybook/react';
3+
import { text, select } from '@storybook/addon-knobs';
4+
import Toast from '../src/toast';
5+
6+
const toastVariants = {
7+
Success: 'success',
8+
Warning: 'warning'
9+
};
10+
11+
storiesOf('Toast', module).add('Toast', () => {
12+
return (
13+
<Toast type={select('Type', toastVariants, 'success')}>
14+
{text('Message', 'This is a message!')}
15+
</Toast>
16+
);
17+
});

0 commit comments

Comments
 (0)