-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from WTTJ/growl
feat: add Growl component
- Loading branch information
Showing
8 changed files
with
246 additions
and
4 deletions.
There are no files selected for viewing
This file contains 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 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 { func, node } from 'prop-types' | ||
import React from 'react' | ||
|
||
import { Icon } from '../Icon' | ||
|
||
import * as S from './styles' | ||
|
||
export const GrowlAction = S.Action | ||
export const GrowlClose = S.CloseContent | ||
export { GrowlTitle } from './title' | ||
|
||
export const Growl = ({ children, onClose, close }) => ( | ||
<S.Growl> | ||
{onClose && ( | ||
<S.Close onClick={onClose}> | ||
{close || ( | ||
<S.CloseContent> | ||
<Icon name="cross" size="xs" /> | ||
</S.CloseContent> | ||
)} | ||
</S.Close> | ||
)} | ||
{children} | ||
</S.Growl> | ||
) | ||
|
||
Growl.propTypes = { | ||
children: node.isRequired, | ||
/** node element replace right position */ | ||
close: node, | ||
/** action called onclick on right position */ | ||
onClose: func | ||
} |
This file contains 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,121 @@ | ||
--- | ||
name: Growl | ||
route: /components/growl | ||
menu: Components | ||
--- | ||
|
||
import { PropsTable } from 'docz' | ||
import { StyledPlayground as Playground } from '../../../docz.styled' | ||
|
||
import { Box } from '../Box' | ||
import { Button } from '../Button' | ||
import { Growl, GrowlAction, GrowlClose, GrowlTitle } from './' | ||
import { Icon } from '../Icon' | ||
|
||
# Growl | ||
|
||
Customize with `<GrowlTitle>`, `<GrowlAction>` or `<GrowlClose>`. | ||
|
||
## Example | ||
|
||
<Playground> | ||
<Growl onClose={() => console.log('close')}> | ||
<GrowlTitle> | ||
<Icon name="megaphone" size="sm" /> Lorem ipsum dolor sit amet | ||
</GrowlTitle> | ||
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos | ||
<GrowlAction> | ||
<Button size="sm" variant="tertiary"> | ||
Action button | ||
</Button> | ||
</GrowlAction> | ||
</Growl> | ||
</Playground> | ||
|
||
## Variants | ||
|
||
Variant properties `info` (default), `error` or `warning` with automatic color. | ||
|
||
<Playground> | ||
<Box mb="10px"> | ||
<Growl onClose={() => console.log('close')}> | ||
<GrowlTitle variant="error"> | ||
<Icon name="flag" size="sm" /> Error growl | ||
</GrowlTitle> | ||
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos | ||
<GrowlAction> | ||
<Button size="sm" variant="secondary-danger"> | ||
Action button | ||
</Button> | ||
</GrowlAction> | ||
</Growl> | ||
</Box> | ||
<Box mb="10px"> | ||
<Growl onClose={() => console.log('close')}> | ||
<GrowlTitle variant="warning"> | ||
<Icon name="shield" size="sm" /> Warning growl | ||
</GrowlTitle> | ||
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos | ||
<GrowlAction> | ||
<Button size="sm" variant="secondary-warning"> | ||
Action button | ||
</Button> | ||
</GrowlAction> | ||
</Growl> | ||
</Box> | ||
<Box> | ||
<Growl onClose={() => console.log('close')}> | ||
<GrowlTitle> | ||
<Icon name="megaphone" size="sm" /> Info growl (default) | ||
</GrowlTitle> | ||
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos | ||
<GrowlAction> | ||
<Button size="sm" variant="secondary"> | ||
Action button | ||
</Button> | ||
</GrowlAction> | ||
</Growl> | ||
</Box> | ||
</Playground> | ||
|
||
## Customs | ||
|
||
Change close component, don't add icon on title, remove action button... | ||
|
||
<Playground> | ||
<Box mb="10px"> | ||
<Growl> | ||
<GrowlTitle>Without icon on title, action button and close button</GrowlTitle> | ||
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos | ||
</Growl> | ||
</Box> | ||
<Box mb="10px"> | ||
<Growl | ||
onClose={() => console.log('close')} | ||
close={ | ||
<GrowlClose> | ||
<Icon name="positive" size="sm" /> | ||
</GrowlClose> | ||
} | ||
> | ||
<GrowlTitle>Custom close button with GrowlClose component</GrowlTitle> | ||
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos | ||
</Growl> | ||
</Box> | ||
<Box> | ||
<Growl onClose={() => console.log('close')} close={<Icon name="positive" size="md" />}> | ||
<GrowlTitle>Custom close button</GrowlTitle> | ||
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos | ||
</Growl> | ||
</Box> | ||
</Playground> | ||
|
||
## Properties | ||
|
||
### Growl | ||
|
||
<PropsTable of={Growl} /> | ||
|
||
### GrowlTitle | ||
|
||
<PropsTable of={GrowlTitle} /> |
This file contains 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,49 @@ | ||
import styled, { css } from 'styled-components' | ||
|
||
import { getVariantStateColor } from '../../utils/variants' | ||
import { get, getCss } from '../../theme/helpers' | ||
|
||
export const Growl = styled.div` | ||
position: relative; | ||
width: 70%; | ||
max-width: 25rem; | ||
padding: ${get('space.lg')}; | ||
${getCss('growls.default')}; | ||
` | ||
|
||
export const Title = styled.div( | ||
({ variant }) => css` | ||
display: flex; | ||
align-items: center; | ||
color: ${getVariantStateColor(variant)}; | ||
padding-bottom: ${get('space.md')}; | ||
${getCss('growls.title')}; | ||
& > *:first-child { | ||
margin-right: ${get('space.sm')}; | ||
} | ||
` | ||
) | ||
|
||
export const Close = styled.div` | ||
position: absolute; | ||
right: ${get('space.lg')}; | ||
top: ${get('space.lg')}; | ||
cursor: pointer; | ||
` | ||
|
||
export const CloseContent = styled.button` | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
width: 1.87rem; | ||
height: 1.87rem; | ||
${getCss('growls.close')}; | ||
border: none; | ||
padding: 0; | ||
transition: background ${get('transitions.medium')}; | ||
` | ||
|
||
export const Action = styled.div` | ||
padding-top: ${get('space.md')}; | ||
` |
This file contains 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,13 @@ | ||
import { node, oneOf } from 'prop-types' | ||
import React from 'react' | ||
|
||
import { Title } from './styles' | ||
|
||
export const GrowlTitle = ({ children, variant = 'info' }) => ( | ||
<Title variant={variant}>{children}</Title> | ||
) | ||
|
||
GrowlTitle.propTypes = { | ||
children: node.isRequired, | ||
variant: oneOf(['warning', 'info', 'error']) | ||
} |
This file contains 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 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 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,21 @@ | ||
export const getGrowls = ({ fontSizes, fontWeights, colors, radii }) => ({ | ||
default: { | ||
'font-size': fontSizes.body3, | ||
'background-color': colors.light[200], | ||
'border-color': colors.nude[200], | ||
'border-width': '1px', | ||
'border-style': 'solid', | ||
'border-radius': radii.md | ||
}, | ||
title: { | ||
'font-size': fontSizes.body2, | ||
'font-weight': fontWeights.bold | ||
}, | ||
close: { | ||
'background-color': colors.nude[200], | ||
'border-radius': '50%', | ||
'&:hover, &:focus': { | ||
'background-color': colors.nude[400] | ||
} | ||
} | ||
}) |