Skip to content

Commit ed6ae9b

Browse files
Lukas742MarcusNotheis
authored andcommitted
fix(Notification): Add onClose prop, fix semantic-icon size (#220)
1 parent 1801269 commit ed6ae9b

File tree

6 files changed

+55
-26
lines changed

6 files changed

+55
-26
lines changed

packages/main/src/components/Notification/Notification.jss.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ const style = ({ parameters }: JSSTheme) => ({
105105
low: { backgroundColor: parameters.sapUiSuccessBorder },
106106
none: { backgroundColor: parameters.sapUiNeutralBorder },
107107
semanticIcon: {
108-
paddingRight: '0.375rem'
108+
paddingRight: '0.375rem',
109+
width: '1rem',
110+
display: 'flex'
109111
},
110112
error: {
111113
color: parameters.sapUiNegativeElement

packages/main/src/components/Notification/__snapshots__/Notification.test.tsx.snap

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,14 @@ exports[`Notification w/ Props 1`] = `
237237
<div
238238
class="Notification--header-"
239239
>
240-
<ui5-icon
241-
class="Notification--error- Notification--semanticIcon-"
242-
src="message-error"
243-
/>
240+
<div
241+
class="Notification--semanticIcon-"
242+
>
243+
<ui5-icon
244+
class="Notification--error-"
245+
src="message-error"
246+
/>
247+
</div>
244248
<div
245249
class="Notification--title- Notification--titleEllipsised-"
246250
>

packages/main/src/components/Notification/demo.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export const defaultStory = () => (
3434
hideShowMoreButton={boolean('hideShowMoreButton', false)}
3535
truncate={boolean('truncate', true)}
3636
showCloseButton={boolean('showCloseButton', true)}
37+
onClose={action('Closed')}
3738
/>
3839
);
3940

packages/main/src/components/Notification/index.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { Button } from '@ui5/webcomponents-react/lib/Button';
1616
import { ButtonDesign } from '@ui5/webcomponents-react/lib/ButtonDesign';
1717
import { Text } from '@ui5/webcomponents-react/lib/Text';
1818
import { Label } from '@ui5/webcomponents-react/lib/Label';
19+
import { Event } from '@ui5/webcomponents-react-base/lib/Event';
1920

2021
export interface NotificationProptypes extends CommonProps {
2122
footer?: ReactNode | ReactNode[];
@@ -31,6 +32,7 @@ export interface NotificationProptypes extends CommonProps {
3132
onClick?: (e: any) => any;
3233
hideShowMoreButton?: boolean;
3334
truncate?: boolean;
35+
onClose?: (event: Event) => void;
3436

3537
children?: React.ReactElement<NotificationProptypes> | React.ReactElement<NotificationProptypes>[];
3638
collapsed?: boolean;
@@ -66,7 +68,8 @@ const Notification: FC<NotificationProptypes> = forwardRef(
6668
autoPriority,
6769
hideShowMoreButton,
6870
truncate,
69-
showCloseButton
71+
showCloseButton,
72+
onClose
7073
} = props;
7174

7275
const classes = useStyles(props);
@@ -101,14 +104,18 @@ const Notification: FC<NotificationProptypes> = forwardRef(
101104
return null;
102105
}, [avatar]);
103106

104-
const handleClose = useCallback(() => {
105-
toggleVisible(false);
106-
}, []);
107+
const handleClose = useCallback(
108+
(e) => {
109+
toggleVisible(false);
110+
onClose(Event.of(null, e));
111+
},
112+
[toggleVisible, onClose]
113+
);
107114

108115
const handleNotificationClick = useCallback(
109116
(e) => {
110117
if (e.target.nodeName !== 'UI5-BUTTON' && e.target.nodeName !== 'UI5-ICON' && typeof onClick === 'function') {
111-
onClick(e);
118+
onClick(Event.of(null, e));
112119
}
113120
},
114121
[onClick]
@@ -169,11 +176,11 @@ const Notification: FC<NotificationProptypes> = forwardRef(
169176
}
170177
switch (prio) {
171178
case Priority.High:
172-
return <Icon src="message-error" className={`${classes.error} ${classes.semanticIcon}`} />;
179+
return <Icon src="message-error" className={classes.error} />;
173180
case Priority.Medium:
174-
return <Icon src="message-warning" className={`${classes.warning} ${classes.semanticIcon}`} />;
181+
return <Icon src="message-warning" className={classes.warning} />;
175182
case Priority.Low:
176-
return <Icon src="message-success" className={`${classes.success} ${classes.semanticIcon}`} />;
183+
return <Icon src="message-success" className={classes.success} />;
177184
case Priority.None:
178185
return null;
179186
default:
@@ -245,7 +252,9 @@ const Notification: FC<NotificationProptypes> = forwardRef(
245252
<div className={`${classes.priorityIndicator} ${indicatorClass}`} style={indicatorStyles} />
246253
<div style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>
247254
<div className={classes.header}>
248-
{renderSemanticIcon}
255+
{priority && priority !== Priority.None && (
256+
<div className={classes.semanticIcon}>{renderSemanticIcon}</div>
257+
)}
249258
<div className={`${classes.title} ${truncate ? classes.titleEllipsised : ''}`}>{title}</div>
250259
{showCloseButton && (
251260
<Button

packages/main/src/components/NotificationGroup/__snapshots__/Notification.test.tsx.snap

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,14 @@ Array [
169169
<div
170170
class="Notification--header-"
171171
>
172-
<ui5-icon
173-
class="Notification--error- Notification--semanticIcon-"
174-
src="message-error"
175-
/>
172+
<div
173+
class="Notification--semanticIcon-"
174+
>
175+
<ui5-icon
176+
class="Notification--error-"
177+
src="message-error"
178+
/>
179+
</div>
176180
<div
177181
class="Notification--title- Notification--titleEllipsised-"
178182
>
@@ -431,10 +435,14 @@ Array [
431435
<div
432436
class="Notification--header-"
433437
>
434-
<ui5-icon
435-
class="Notification--error- Notification--semanticIcon-"
436-
src="message-error"
437-
/>
438+
<div
439+
class="Notification--semanticIcon-"
440+
>
441+
<ui5-icon
442+
class="Notification--error-"
443+
src="message-error"
444+
/>
445+
</div>
438446
<div
439447
class="Notification--title- Notification--titleEllipsised-"
440448
>
@@ -832,10 +840,14 @@ Array [
832840
<div
833841
class="Notification--header-"
834842
>
835-
<ui5-icon
836-
class="Notification--error- Notification--semanticIcon-"
837-
src="message-error"
838-
/>
843+
<div
844+
class="Notification--semanticIcon-"
845+
>
846+
<ui5-icon
847+
class="Notification--error-"
848+
src="message-error"
849+
/>
850+
</div>
839851
<div
840852
class="Notification--title- Notification--titleEllipsised-"
841853
>

packages/main/src/components/NotificationGroup/demo.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export const defaultStory = () => (
3737
collapsed={boolean('collapsed', false)}
3838
showCloseButton={boolean('showCloseButton', true)}
3939
truncate={boolean('truncate', true)}
40+
onClose={action('Group closed')}
4041
>
4142
<Notification
4243
footer={ActionButtons}

0 commit comments

Comments
 (0)