Skip to content

Commit

Permalink
feat: add close prop to notification
Browse files Browse the repository at this point in the history
  • Loading branch information
zwaardje committed Dec 22, 2023
1 parent 6572aca commit 24babd3
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/react-sdk/src/components/Notification/Notification.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { PropsWithChildren, ReactNode, useEffect } from 'react';
import { Placement } from '@floating-ui/react';

import { Icon } from '../Icon';

Check warning on line 4 in packages/react-sdk/src/components/Notification/Notification.tsx

View workflow job for this annotation

GitHub Actions / test-and-build

'Icon' is defined but never used

import { useFloatingUIPreset } from '../../hooks';

export type NotificationProps = {
Expand All @@ -10,6 +12,7 @@ export type NotificationProps = {
resetIsVisible?: () => void;
placement?: Placement;
iconClassName?: string | null;
close?: () => void;
};

export const Notification = (props: PropsWithChildren<NotificationProps>) => {
Expand All @@ -21,6 +24,7 @@ export const Notification = (props: PropsWithChildren<NotificationProps>) => {
resetIsVisible,
placement = 'top',
iconClassName = 'str-video__notification__icon',
close,
} = props;

const { refs, x, y, strategy } = useFloatingUIPreset({
Expand Down Expand Up @@ -53,6 +57,12 @@ export const Notification = (props: PropsWithChildren<NotificationProps>) => {
>
{iconClassName && <i className={iconClassName} />}
<span className="str-video__notification__message">{message}</span>
{close ? (
<i
className="str-video__icon str-video__icon--close str-video__notification__close"
onClick={close}
/>
) : null}
</div>
)}
{children}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PropsWithChildren } from 'react';
import { PropsWithChildren, useEffect, useState } from 'react';
import { useI18n } from '@stream-io/video-react-bindings';
import { useToggleCallRecording } from '../../hooks';
import { Notification } from './Notification';
import { IconButton } from '../Button';

Check warning on line 5 in packages/react-sdk/src/components/Notification/RecordingInProgressNotification.tsx

View workflow job for this annotation

GitHub Actions / test-and-build

'IconButton' is defined but never used

export type RecordingInProgressNotificationProps = {
text?: string;
Expand All @@ -14,14 +15,25 @@ export const RecordingInProgressNotification = ({
const { t } = useI18n();
const { isCallRecordingInProgress } = useToggleCallRecording();

const [isVisible, setVisible] = useState(false);

const message = text ?? t('Recording in progress...');

useEffect(() => {
if (isCallRecordingInProgress) {
setVisible(true);
} else {
setVisible(false);
}
}, [isCallRecordingInProgress]);

return (
<Notification
message={message}
iconClassName="str-video__icon str-video__icon--recording-on"
isVisible={isCallRecordingInProgress}
isVisible={isVisible}
placement="top-start"
close={() => setVisible(false)}
>
{children}
</Notification>
Expand Down
10 changes: 10 additions & 0 deletions packages/styling/src/Notification/Notification-layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,14 @@
.str-video__notification__message {
flex: 1;
}

.str-video__notification__close {
display: inline-block;
width: 1rem;
height: 1rem;

&:hover {
cursor: pointer;
}
}
}

0 comments on commit 24babd3

Please sign in to comment.