Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cnto 8202 notification #77

Merged
merged 13 commits into from
Feb 13, 2024
19 changes: 18 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"registry": "https://npm.pkg.github.com"
},
"repository": "git://github.com/contacto-io/contacto-console",
"version": "0.5.85",
"version": "0.5.99",
"main": "build/index.js",
"module": "build/index.es.js",
"files": [
Expand Down
30 changes: 30 additions & 0 deletions src/components/Notification/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React, { useEffect } from 'react'
import { Icon } from '../Icon/index'
import { Text } from '../Typography/index'
import { notification } from 'antd'
import './notification.scss'

const iconMap = {
info: 'info',
warning: 'error',
error: 'report',
success: 'check_circle',
}
export const showNotification = (type, message) => {
notification[type]({
message: <Text type="title-3">{message}</Text>,
className: `notification-${type}`,
icon: <Icon name={iconMap[type]} size={24} />,
closeIcon: (
<Icon name="close" size={24} color="primary-text-color" hoverColor="primary-text-color" />
),
duration: 5,
})
}

export const Notification = ({ type, message }) => {
useEffect(() => {
showNotification(type, message)
}, [type])
return <>This is notification of type {type}</>
}
33 changes: 33 additions & 0 deletions src/components/Notification/index.stories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import { Notification, showNotification } from './'

export default {
title: 'Components/Notification',
component: showNotification,
}

const Template = (args) => <Notification {...args} />

export const Info = Template.bind({})
Info.args = {
message: 'This is info notification',
type: 'info',
}

export const Success = Template.bind({})
Success.args = {
message: 'This is success notification',
type: 'success',
}

export const Error = Template.bind({})
Error.args = {
message: 'This is error notification',
type: 'error',
}

export const Warning = Template.bind({})
Warning.args = {
message: 'This is warning notification',
type: 'warning',
}
76 changes: 76 additions & 0 deletions src/components/Notification/notification.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.notification {
&-success {
color: var(--success-color);
border-left: 4px solid var(--toast-success-color);
}

&-device-change {
background: rgba(6, 14, 43, 0.9) !important;
width: 100% !important;
min-height: 36px;
padding: 8px !important;
.ant-notification-notice-message {
display: flex;
align-items: center;
justify-content: center;
margin: 0px;
}
}

&-error {
color: var(--danger-color);
border-left: 4px solid var(--danger-color);
}

&-warning {
color: var(--warning-color);
border-left: 4px solid var(--warning-color);
}

&-info {
color: var(--primary-color);
border-left: 4px solid var(--primary-color);
}

}

.ant-notification {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add our custom css name later if some dependency comes with notification css may break

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a custom class and handled CSS inside it but few elements of notification is mounted on top of document so had to handle it separately.

&-notice-content {
display: flex;
margin-right: 40px;
}
&-notice-description {
margin: 0;
}

&-notice-message {
display: flex;
margin: 0 !important;
margin-left: 32px !important;
padding-right: 0 !important;
&-single-line-auto-margin {
display: none;
}
}
&-notice-with-icon {
display: initial !important;
}
&-notice-close-icon,
&-close-icon {
svg {
height: 1.5rem !important;
width: 1.5rem !important;
fill: var(--primary-text-color) !important;
}
}
&-notice-close {
right: 16px;
}
&-notice-icon {
margin: 0;
}
&-notice {
padding: 16px;
width: 337px;
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ export * from './components/TopBanner/index'
export * from './components/TimeLeftBar/index'
export * from './components/PhoneNumberInput/index'
export * from './components/ChatLoader/index'

export * from './components/Notification/index'