Skip to content

Commit

Permalink
[CLD-586] Create Helper component
Browse files Browse the repository at this point in the history
  • Loading branch information
vuhuucuong authored and duong-se committed Dec 17, 2019
1 parent 3dae57d commit 67446e4
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/components/Helper/__tests__/__snapshots__/index.tsx.snap
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"
/>
`;
20 changes: 20 additions & 0 deletions src/components/Helper/__tests__/index.tsx
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()
})
})
})
12 changes: 12 additions & 0 deletions src/components/Helper/helper.stories.tsx
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>
))
25 changes: 25 additions & 0 deletions src/components/Helper/index.tsx
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>
)
}
1 change: 1 addition & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export * from './components/HtmlRender'
export * from './components/Form'
export * from './components/ProgressBar'
export * from './components/ToastMessage'
export * from './components/Helper'

// Utils
export * from './utils/validators'
Expand Down
21 changes: 21 additions & 0 deletions src/styles/components/helper.scss
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;
}
}
1 change: 1 addition & 0 deletions src/styles/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@
@import './components/dynamic-link.scss';
@import './components/pagination.scss';
@import './components/input.scss';
@import './components/helper.scss';

0 comments on commit 67446e4

Please sign in to comment.