Skip to content

Commit

Permalink
fix(Notification): Add onClose prop, fix semantic-icon size (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukas742 authored and MarcusNotheis committed Nov 11, 2019
1 parent 1801269 commit ed6ae9b
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ const style = ({ parameters }: JSSTheme) => ({
low: { backgroundColor: parameters.sapUiSuccessBorder },
none: { backgroundColor: parameters.sapUiNeutralBorder },
semanticIcon: {
paddingRight: '0.375rem'
paddingRight: '0.375rem',
width: '1rem',
display: 'flex'
},
error: {
color: parameters.sapUiNegativeElement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,14 @@ exports[`Notification w/ Props 1`] = `
<div
class="Notification--header-"
>
<ui5-icon
class="Notification--error- Notification--semanticIcon-"
src="message-error"
/>
<div
class="Notification--semanticIcon-"
>
<ui5-icon
class="Notification--error-"
src="message-error"
/>
</div>
<div
class="Notification--title- Notification--titleEllipsised-"
>
Expand Down
1 change: 1 addition & 0 deletions packages/main/src/components/Notification/demo.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const defaultStory = () => (
hideShowMoreButton={boolean('hideShowMoreButton', false)}
truncate={boolean('truncate', true)}
showCloseButton={boolean('showCloseButton', true)}
onClose={action('Closed')}
/>
);

Expand Down
27 changes: 18 additions & 9 deletions packages/main/src/components/Notification/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Button } from '@ui5/webcomponents-react/lib/Button';
import { ButtonDesign } from '@ui5/webcomponents-react/lib/ButtonDesign';
import { Text } from '@ui5/webcomponents-react/lib/Text';
import { Label } from '@ui5/webcomponents-react/lib/Label';
import { Event } from '@ui5/webcomponents-react-base/lib/Event';

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

children?: React.ReactElement<NotificationProptypes> | React.ReactElement<NotificationProptypes>[];
collapsed?: boolean;
Expand Down Expand Up @@ -66,7 +68,8 @@ const Notification: FC<NotificationProptypes> = forwardRef(
autoPriority,
hideShowMoreButton,
truncate,
showCloseButton
showCloseButton,
onClose
} = props;

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

const handleClose = useCallback(() => {
toggleVisible(false);
}, []);
const handleClose = useCallback(
(e) => {
toggleVisible(false);
onClose(Event.of(null, e));
},
[toggleVisible, onClose]
);

const handleNotificationClick = useCallback(
(e) => {
if (e.target.nodeName !== 'UI5-BUTTON' && e.target.nodeName !== 'UI5-ICON' && typeof onClick === 'function') {
onClick(e);
onClick(Event.of(null, e));
}
},
[onClick]
Expand Down Expand Up @@ -169,11 +176,11 @@ const Notification: FC<NotificationProptypes> = forwardRef(
}
switch (prio) {
case Priority.High:
return <Icon src="message-error" className={`${classes.error} ${classes.semanticIcon}`} />;
return <Icon src="message-error" className={classes.error} />;
case Priority.Medium:
return <Icon src="message-warning" className={`${classes.warning} ${classes.semanticIcon}`} />;
return <Icon src="message-warning" className={classes.warning} />;
case Priority.Low:
return <Icon src="message-success" className={`${classes.success} ${classes.semanticIcon}`} />;
return <Icon src="message-success" className={classes.success} />;
case Priority.None:
return null;
default:
Expand Down Expand Up @@ -245,7 +252,9 @@ const Notification: FC<NotificationProptypes> = forwardRef(
<div className={`${classes.priorityIndicator} ${indicatorClass}`} style={indicatorStyles} />
<div style={{ display: 'flex', flexDirection: 'column', width: '100%' }}>
<div className={classes.header}>
{renderSemanticIcon}
{priority && priority !== Priority.None && (
<div className={classes.semanticIcon}>{renderSemanticIcon}</div>
)}
<div className={`${classes.title} ${truncate ? classes.titleEllipsised : ''}`}>{title}</div>
{showCloseButton && (
<Button
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,10 +169,14 @@ Array [
<div
class="Notification--header-"
>
<ui5-icon
class="Notification--error- Notification--semanticIcon-"
src="message-error"
/>
<div
class="Notification--semanticIcon-"
>
<ui5-icon
class="Notification--error-"
src="message-error"
/>
</div>
<div
class="Notification--title- Notification--titleEllipsised-"
>
Expand Down Expand Up @@ -431,10 +435,14 @@ Array [
<div
class="Notification--header-"
>
<ui5-icon
class="Notification--error- Notification--semanticIcon-"
src="message-error"
/>
<div
class="Notification--semanticIcon-"
>
<ui5-icon
class="Notification--error-"
src="message-error"
/>
</div>
<div
class="Notification--title- Notification--titleEllipsised-"
>
Expand Down Expand Up @@ -832,10 +840,14 @@ Array [
<div
class="Notification--header-"
>
<ui5-icon
class="Notification--error- Notification--semanticIcon-"
src="message-error"
/>
<div
class="Notification--semanticIcon-"
>
<ui5-icon
class="Notification--error-"
src="message-error"
/>
</div>
<div
class="Notification--title- Notification--titleEllipsised-"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const defaultStory = () => (
collapsed={boolean('collapsed', false)}
showCloseButton={boolean('showCloseButton', true)}
truncate={boolean('truncate', true)}
onClose={action('Group closed')}
>
<Notification
footer={ActionButtons}
Expand Down

0 comments on commit ed6ae9b

Please sign in to comment.