-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3dae57d
commit 67446e4
Showing
7 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
src/components/Helper/__tests__/__snapshots__/index.tsx.snap
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,35 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Helper should default to variant info without close button 1`] = ` | ||
<div | ||
className="notification helper-wrap helper-info" | ||
/> | ||
`; | ||
|
||
exports[`Helper should match snapshot with button for variant info 1`] = ` | ||
<div | ||
className="notification helper-wrap helper-info" | ||
/> | ||
`; | ||
|
||
exports[`Helper should match snapshot with button for variant warning 1`] = ` | ||
<div | ||
className="notification helper-wrap helper-warning" | ||
/> | ||
`; | ||
|
||
exports[`Helper should match with/without closeButton 1`] = ` | ||
<div | ||
className="notification helper-wrap helper-info" | ||
> | ||
<button | ||
className="delete" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`Helper should match with/without closeButton 2`] = ` | ||
<div | ||
className="notification helper-wrap helper-info" | ||
/> | ||
`; |
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,20 @@ | ||
import * as React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { Helper, Variant } from '../index' | ||
|
||
const variants: Variant[] = ['info', 'warning'] | ||
|
||
describe('Helper', () => { | ||
it('should default to variant info without close button', () => { | ||
expect(shallow(<Helper />)).toMatchSnapshot() | ||
}) | ||
it('should match with/without closeButton', () => { | ||
expect(shallow(<Helper closeButton={true} />)).toMatchSnapshot() | ||
expect(shallow(<Helper closeButton={false} />)).toMatchSnapshot() | ||
}) | ||
variants.forEach(variant => { | ||
it('should match snapshot with button for variant ' + variant, () => { | ||
expect(shallow(<Helper variant={variant} />)).toMatchSnapshot() | ||
}) | ||
}) | ||
}) |
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,12 @@ | ||
import React from 'react' | ||
import { storiesOf } from '@storybook/react' | ||
import { Helper } from './index' | ||
|
||
storiesOf('Helper', module) | ||
.add('Info', () => <Helper variant="info">Helper variant info</Helper>) | ||
.add('Warning', () => <Helper variant="warning">Helper variant warning</Helper>) | ||
.add('With close button', () => ( | ||
<Helper variant="info" closeButton={true} onCloseClick={() => console.log('clicked')}> | ||
Helper with closeButton | ||
</Helper> | ||
)) |
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,25 @@ | ||
import * as React from 'react' | ||
|
||
export type Variant = 'info' | 'warning' | ||
|
||
export interface HelperProps { | ||
variant?: Variant | ||
children?: React.ReactNode | ||
closeButton?: boolean | ||
onCloseClick?: (e: React.MouseEvent<HTMLButtonElement>) => void | ||
} | ||
|
||
export const Helper: React.FC<HelperProps> = ({ | ||
variant = 'info', | ||
children = '', | ||
closeButton = false, | ||
onCloseClick | ||
}) => { | ||
const helperColor = variant === 'warning' ? 'helper-warning' : 'helper-info' | ||
return ( | ||
<div className={`notification helper-wrap ${helperColor}`}> | ||
{closeButton && <button className="delete" onClick={onCloseClick}></button>} | ||
{children} | ||
</div> | ||
) | ||
} |
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 @@ | ||
@import '../base/colors.scss'; | ||
@import '../base/fonts.scss'; | ||
|
||
.notification { | ||
&.helper-wrap { | ||
font-size: 1rem; | ||
font-family: $family-sans-serif; | ||
text-transform: lowercase; | ||
margin-bottom: 1rem; | ||
} | ||
|
||
&.helper-info { | ||
background-color: transparentize($reapit-mid-blue, 0.8); | ||
color: $reapit-mid-blue; | ||
} | ||
|
||
&.helper-warning { | ||
background-color: transparentize($reapit-red, 0.8); | ||
color: $reapit-red; | ||
} | ||
} |
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