Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,12 @@ describe('Notification', () => {
datetime="1337 Minutes ago"
avatar="ME"
priority={Priority.High}
visible
hideShowMoreButton={false}
showCloseButton
truncate
/>
);
expect(wrapper).toMatchSnapshot();
});

test('Hidden', () => {
const wrapper = renderThemedComponent(<Notification visible={false} />);
expect(wrapper).toMatchSnapshot();
});

test('w/ custom Avatar', () => {
const wrapper = renderThemedComponent(
<Notification avatar={<Avatar size={AvatarSize.XS} shape={AvatarShape.Circle} image={sampleAvatar} />} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ exports[`Notification Default 1`] = `
</div>
`;

exports[`Notification Hidden 1`] = `null`;

exports[`Notification Long Title and Description 1`] = `
<div
class="Notification--notificationContainer- undefined"
Expand Down
5 changes: 2 additions & 3 deletions packages/main/src/components/Notification/demo.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ export const defaultStory = () => (
datetime={text('datetime', 'Datetime')}
avatar={<Avatar size={AvatarSize.XS} shape={AvatarShape.Circle} image={sampleAvatar} />}
priority={select('priority', Priority, Priority.None)}
visible={boolean('visible', true)}
onClick={action('Notification clicked')}
hideShowMoreButton={boolean('hideShowMoreButton', false)}
noShowMoreButton={boolean('noShowMoreButton', false)}
truncate={boolean('truncate', true)}
showCloseButton={boolean('showCloseButton', true)}
noCloseButton={boolean('noCloseButton', false)}
onClose={action('Closed')}
/>
);
Expand Down
34 changes: 13 additions & 21 deletions packages/main/src/components/Notification/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,15 @@ export interface NotificationProptypes extends CommonProps {
loading?: boolean;
datetime?: string;
priority?: Priority;
showCloseButton?: boolean;
visible?: boolean;
noCloseButton?: boolean;
onClick?: (e: any) => any;
hideShowMoreButton?: boolean;
noShowMoreButton?: boolean;
truncate?: boolean;
onClose?: (event: Event) => void;

children?: React.ReactElement<NotificationProptypes> | React.ReactElement<NotificationProptypes>[];
collapsed?: boolean;
autoPriority?: boolean;

isChild?: boolean;
isLastChild?: boolean;
}

const useStyles = createUseStyles<JSSTheme, keyof ReturnType<typeof styles>>(styles, { name: 'Notification' });
Expand All @@ -56,31 +52,24 @@ const Notification: FC<NotificationProptypes> = forwardRef(
datetime,
avatar,
priority,
visible,
onClick,
children,
collapsed,
className,
tooltip,
style,
isChild,
isLastChild,
autoPriority,
hideShowMoreButton,
noShowMoreButton,
truncate,
showCloseButton,
noCloseButton,
onClose
} = props;

const classes = useStyles(props);
const [visibleState, toggleVisible] = useState(visible);
const [visibleState, toggleVisible] = useState(true);
const [showChildren, toggleChildrenVisible] = useState(!collapsed);
const [showMore, toggleShowMore] = useState(!truncate);

useEffect(() => {
toggleVisible(visible);
}, [visible]);

useEffect(() => {
toggleChildrenVisible(!collapsed);
}, [collapsed]);
Expand Down Expand Up @@ -129,6 +118,9 @@ const Notification: FC<NotificationProptypes> = forwardRef(
toggleShowMore(!showMore);
}, [showMore]);

const isLastChild = props['isLastChild'];
const isChild = props['isChild'];

const notificationContainerStyles = useMemo(() => {
const borderRadius = () => {
if (isChild) {
Expand Down Expand Up @@ -211,11 +203,13 @@ const Notification: FC<NotificationProptypes> = forwardRef(
return React.Children.map(children, (item, index) => {
if (React.Children.count(children) === index + 1) {
return React.cloneElement(item, {
// @ts-ignore
isLastChild: true,
className: `${item.props.className} ${classes.notificationContainerChild}`
});
}
return React.cloneElement(item, {
// @ts-ignore
isChild: true,
className: `${item.props.className} ${classes.notificationContainerChild}`
});
Expand Down Expand Up @@ -256,7 +250,7 @@ const Notification: FC<NotificationProptypes> = forwardRef(
<div className={classes.semanticIcon}>{renderSemanticIcon}</div>
)}
<div className={`${classes.title} ${truncate ? classes.titleEllipsised : ''}`}>{title}</div>
{showCloseButton && (
{!noCloseButton && (
<Button
className={classes.closeButton}
design={ButtonDesign.Transparent}
Expand Down Expand Up @@ -284,7 +278,7 @@ const Notification: FC<NotificationProptypes> = forwardRef(
</div>
<div className={classes.footer}>
<div style={{ display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }}>
{!hideShowMoreButton && (
{!noShowMoreButton && (
<Button design={ButtonDesign.Transparent} onClick={handleShowMore}>
{showMore ? 'Show Less' : 'Show More'}
</Button>
Expand All @@ -311,9 +305,7 @@ const Notification: FC<NotificationProptypes> = forwardRef(
);

Notification.defaultProps = {
visible: true,
truncate: true,
showCloseButton: true
truncate: true
};

Notification.displayName = 'Notification';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ describe('NotificationGroup', () => {
datetime="1337 Minutes ago"
avatar="ME"
priority={Priority.High}
visible
hideShowMoreButton={false}
showCloseButton
truncate
/>
<Notification avatar={<Avatar size={AvatarSize.XS} shape={AvatarShape.Circle} image={sampleAvatar} />} />
Expand Down Expand Up @@ -76,9 +73,6 @@ describe('NotificationGroup', () => {
datetime="1337 Minutes ago"
avatar="ME"
priority={Priority.High}
visible
hideShowMoreButton={false}
showCloseButton
truncate
/>
<Notification avatar={<Avatar size={AvatarSize.XS} shape={AvatarShape.Circle} image={sampleAvatar} />} />
Expand All @@ -104,9 +98,6 @@ describe('NotificationGroup', () => {
datetime="1337 Minutes ago"
avatar="ME"
priority={Priority.High}
visible
hideShowMoreButton={false}
showCloseButton
truncate
/>
<Notification avatar={<Avatar size={AvatarSize.XS} shape={AvatarShape.Circle} image={sampleAvatar} />} />
Expand All @@ -132,9 +123,6 @@ describe('NotificationGroup', () => {
datetime="1337 Minutes ago"
avatar="ME"
priority={Priority.High}
visible
hideShowMoreButton={false}
showCloseButton
truncate
>
<Notification description="description" title="title" />
Expand Down
10 changes: 3 additions & 7 deletions packages/main/src/components/NotificationGroup/demo.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ export const defaultStory = () => (
datetime={text('datetime', 'Datetime')}
avatar={<Avatar size={AvatarSize.XS} shape={AvatarShape.Circle} image={sampleAvatar} />}
priority={select('priority', Priority, Priority.None)}
visible={boolean('visible', true)}
onClick={action('Notification clicked')}
hideShowMoreButton={boolean('hideShowMoreButton', false)}
noShowMoreButton={boolean('noShowMoreButton', false)}
autoPriority={boolean('autoPriority', true)}
collapsed={boolean('collapsed', false)}
showCloseButton={boolean('showCloseButton', true)}
noCloseButton={boolean('noCloseButton', false)}
truncate={boolean('truncate', true)}
onClose={action('Group closed')}
>
Expand All @@ -47,18 +46,15 @@ export const defaultStory = () => (
authorName="Author"
avatar="LH"
priority={Priority.Medium}
visible={true}
showCloseButton={false}
truncate={boolean('truncate', true)}
/>
<Notification
description="Short description"
title="Very long Title. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
authorName="Author"
priority={Priority.Low}
visible={true}
onClick={action('Child Notification clicked')}
showCloseButton={false}
noCloseButton={true}
truncate={boolean('truncate', true)}
/>
</NotificationGroup>
Expand Down
4 changes: 1 addition & 3 deletions packages/main/src/components/NotificationGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ const NotificationGroup: FC<NotificationProptypes> = forwardRef(
);

NotificationGroup.defaultProps = {
visible: true,
autoPriority: true,
truncate: true,
showCloseButton: true
truncate: true
};

NotificationGroup.displayName = 'Notification Group';
Expand Down