|
@@ -4,21 +4,44 @@ import Body from './body'
|
|
|
import Action from './action'
|
|
import Action from './action'
|
|
|
import Close from '../../../../shared/components/close'
|
|
import Close from '../../../../shared/components/close'
|
|
|
import classnames from 'classnames'
|
|
import classnames from 'classnames'
|
|
|
|
|
+import NewNotification, {
|
|
|
|
|
+ NotificationType,
|
|
|
|
|
+} from '@/shared/components/notification'
|
|
|
|
|
+import getMeta from '@/utils/meta'
|
|
|
|
|
|
|
|
type NotificationProps = {
|
|
type NotificationProps = {
|
|
|
bsStyle: AlertProps['bsStyle']
|
|
bsStyle: AlertProps['bsStyle']
|
|
|
- children: React.ReactNode
|
|
|
|
|
|
|
+ children?: React.ReactNode
|
|
|
|
|
+ body?: React.ReactNode
|
|
|
|
|
+ action?: React.ReactElement
|
|
|
onDismiss?: AlertProps['onDismiss']
|
|
onDismiss?: AlertProps['onDismiss']
|
|
|
className?: string
|
|
className?: string
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Renders either a legacy-styled notification using Boostrap `Alert`, or a new-styled notification using
|
|
|
|
|
+ * the shared `Notification` component.
|
|
|
|
|
+ *
|
|
|
|
|
+ * The content of the notification is provided either with `children` (keeping backwards compatibility),
|
|
|
|
|
+ * or a `body` prop (along with an optional `action`).
|
|
|
|
|
+ *
|
|
|
|
|
+ * When the content is provided via `body` prop the notification is rendered with the new Notification component
|
|
|
|
|
+ * if `ol-newNotificationStyle` meta is set to true.
|
|
|
|
|
+ */
|
|
|
function Notification({
|
|
function Notification({
|
|
|
bsStyle,
|
|
bsStyle,
|
|
|
children,
|
|
children,
|
|
|
onDismiss,
|
|
onDismiss,
|
|
|
className,
|
|
className,
|
|
|
|
|
+ body,
|
|
|
|
|
+ action,
|
|
|
...props
|
|
...props
|
|
|
}: NotificationProps) {
|
|
}: NotificationProps) {
|
|
|
|
|
+ const newNotificationStyle = getMeta(
|
|
|
|
|
+ 'ol-newNotificationStyle',
|
|
|
|
|
+ false
|
|
|
|
|
+ ) as boolean
|
|
|
|
|
+
|
|
|
const [show, setShow] = useState(true)
|
|
const [show, setShow] = useState(true)
|
|
|
|
|
|
|
|
const handleDismiss = () => {
|
|
const handleDismiss = () => {
|
|
@@ -33,18 +56,49 @@ function Notification({
|
|
|
return null
|
|
return null
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return (
|
|
|
|
|
- <li className={classnames('notification-entry', className)} {...props}>
|
|
|
|
|
- <Alert bsStyle={bsStyle}>
|
|
|
|
|
- {children}
|
|
|
|
|
- {onDismiss ? (
|
|
|
|
|
- <div className="notification-close">
|
|
|
|
|
- <Close onDismiss={handleDismiss} />
|
|
|
|
|
- </div>
|
|
|
|
|
- ) : null}
|
|
|
|
|
- </Alert>
|
|
|
|
|
- </li>
|
|
|
|
|
- )
|
|
|
|
|
|
|
+ if (newNotificationStyle && body) {
|
|
|
|
|
+ const newNotificationType = (
|
|
|
|
|
+ bsStyle === 'danger' ? 'error' : bsStyle
|
|
|
|
|
+ ) as NotificationType
|
|
|
|
|
+ return (
|
|
|
|
|
+ <NewNotification
|
|
|
|
|
+ type={newNotificationType}
|
|
|
|
|
+ isDismissible={onDismiss != null}
|
|
|
|
|
+ onDismiss={handleDismiss}
|
|
|
|
|
+ content={body as React.ReactElement}
|
|
|
|
|
+ action={action}
|
|
|
|
|
+ />
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (body) {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <li className={classnames('notification-entry', className)} {...props}>
|
|
|
|
|
+ <Alert bsStyle={bsStyle}>
|
|
|
|
|
+ <Body>{body}</Body>
|
|
|
|
|
+ {action && <Action>{action}</Action>}
|
|
|
|
|
+ {onDismiss ? (
|
|
|
|
|
+ <div className="notification-close">
|
|
|
|
|
+ <Close onDismiss={handleDismiss} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ </Alert>
|
|
|
|
|
+ </li>
|
|
|
|
|
+ )
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return (
|
|
|
|
|
+ <li className={classnames('notification-entry', className)} {...props}>
|
|
|
|
|
+ <Alert bsStyle={bsStyle}>
|
|
|
|
|
+ {children}
|
|
|
|
|
+ {onDismiss ? (
|
|
|
|
|
+ <div className="notification-close">
|
|
|
|
|
+ <Close onDismiss={handleDismiss} />
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ) : null}
|
|
|
|
|
+ </Alert>
|
|
|
|
|
+ </li>
|
|
|
|
|
+ )
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Notification.Body = Body
|
|
Notification.Body = Body
|