Skip to content

Commit

Permalink
Add notifications API (#73)
Browse files Browse the repository at this point in the history
* feat #71 - Notification component (#72)
  • Loading branch information
nancy-dassana authored Sep 2, 2020
1 parent 80e7a01 commit 506023c
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dassana-io/web-components",
"version": "0.2.5",
"version": "0.2.6",
"publishConfig": {
"registry": "https://npm.pkg.github.com/dassana-io"
},
Expand Down
2 changes: 1 addition & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default {
assetFileNames
}
],
external: ['react'],
external: ['antd', 'react'],
plugins: [
resolve(),
commonjs(),
Expand Down
52 changes: 52 additions & 0 deletions src/__snapshots__/storybook.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,58 @@ exports[`Storyshots Link Href 1`] = `
</a>
`;

exports[`Storyshots Notifications Error 1`] = `
<button
className="ant-btn ant-btn-default"
disabled={false}
onClick={[Function]}
type="button"
>
<span>
Error
</span>
</button>
`;

exports[`Storyshots Notifications Info 1`] = `
<button
className="ant-btn ant-btn-default"
disabled={false}
onClick={[Function]}
type="button"
>
<span>
Info
</span>
</button>
`;

exports[`Storyshots Notifications Success 1`] = `
<button
className="ant-btn ant-btn-default"
disabled={false}
onClick={[Function]}
type="button"
>
<span>
Success
</span>
</button>
`;

exports[`Storyshots Notifications Warning 1`] = `
<button
className="ant-btn ant-btn-default"
disabled={false}
onClick={[Function]}
type="button"
>
<span>
Warning
</span>
</button>
`;

exports[`Storyshots Skeleton Circle 1`] = `
<span
className="container-0-2-1 container-d3-0-2-19"
Expand Down
42 changes: 42 additions & 0 deletions src/components/Notification/Notification.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { generateNotification } from './index'
import React from 'react'
import Button, { ButtonProps } from '../Button'
import { Meta, Story } from '@storybook/react/types-6-0'

export default {
argTypes: {
children: { control: 'text' }
},
title: 'Notifications'
} as Meta

const Template: Story<ButtonProps> = args => (
<Button {...args}>{args.children}</Button>
)

export const Error = Template.bind({})
Error.args = {
children: 'Error',
onClick: () =>
generateNotification('error', 'Message for error notification')
}

export const Info = Template.bind({})
Info.args = {
children: 'Info',
onClick: () => generateNotification('info', 'Message for info notification')
}

export const Success = Template.bind({})
Success.args = {
children: 'Success',
onClick: () =>
generateNotification('success', 'Message for success notification')
}

export const Warning = Template.bind({})
Warning.args = {
children: 'Warning',
onClick: () =>
generateNotification('warning', 'Message for warning notification')
}
24 changes: 24 additions & 0 deletions src/components/Notification/Notification.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { generateNotification } from './index'
import { notification } from 'antd'

describe('Notification', () => {
it('should render a notification with the message content', () => {
generateNotification('error', 'something')

const notification = document.querySelectorAll('.ant-notification')[0]

expect(notification).toBeDefined()
expect(notification.textContent).toBe('something')
})

it('should use the notification api provided by AntD', () => {
jest.spyOn(notification, 'error')

const mockErrorNotification = 'Fake Error Notification'
generateNotification('error', mockErrorNotification)

expect(notification.error).toHaveBeenCalledWith({
message: mockErrorNotification
})
})
})
8 changes: 8 additions & 0 deletions src/components/Notification/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'antd/lib/notification/style/index.css'
import { IconType } from 'antd/lib/notification'
import { notification } from 'antd'

export const generateNotification = (type: IconType, message: string): void =>
notification[type]({
message
})
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export { default as Form } from './Form'
export { default as Input } from './Input'
export { default as Icon } from './Icon'
export { default as Link } from './Link'
export * from './Notification'
export { default as Skeleton } from './Skeleton'
export { default as Tag } from './Tag'
export { default as Toggle } from './Toggle'

0 comments on commit 506023c

Please sign in to comment.