Skip to content

Commit

Permalink
STCOM-1408: Add marginTop0 class to MessageBanner component (#2425)
Browse files Browse the repository at this point in the history
Introduce the marginTop0 class to the MessageBanner component to remove
the default top margin.

## Refs
https://folio-org.atlassian.net/browse/STCOM-1408
  • Loading branch information
mariia-aloshyna authored Feb 14, 2025
1 parent 2802f20 commit 71f391e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
* Calendar - improved color contrast of edge month days, as per WCAG standards. Changed hover bg color of edge/month days. Increased weight of day numbers overall. Refs STCOM-1390.
* *BREAKING* Update `react-intl` to `^7`. Refs STCOM-1406.
* *BREAKING* remove deprecated props. Refs STCOM-1398.
* Add marginTop0 prop to the MessageBanner component. Refs STCOM-1408.

## [12.2.0](https://github.com/folio-org/stripes-components/tree/v12.2.0) (2024-10-11)
[Full Changelog](https://github.com/folio-org/stripes-components/compare/v12.1.0...v12.2.0)
Expand Down
9 changes: 8 additions & 1 deletion lib/MessageBanner/MessageBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const MessageBanner = forwardRef(
onExited,
show = true,
type = TYPES.DEFAULT,
marginTop0 = false,
...rest
},
ref
Expand Down Expand Up @@ -77,8 +78,13 @@ const MessageBanner = forwardRef(
);
};

const getMessageBannerClass = () => classnames(
css.root,
{ [css.marginTop0]: marginTop0 },
);

return (
<div role="alert" aria-live={ariaLive} className={css.root}>
<div role="alert" aria-live={ariaLive} className={getMessageBannerClass()}>
<CSSTransition
in={visible}
timeout={200}
Expand Down Expand Up @@ -150,6 +156,7 @@ MessageBanner.propTypes = {
onExited: PropTypes.func,
show: PropTypes.bool,
type: PropTypes.oneOf(Object.keys(TYPES).map(key => TYPES[key])),
marginTop0: PropTypes.bool,
};

MessageBanner.displayName = 'MessageBanner';
Expand Down
4 changes: 4 additions & 0 deletions lib/MessageBanner/MessageBanner.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@

.root + .root {
margin-top: var(--message-banner-stacked-margin-top);

&.marginTop0 {
margin-top: 0;
}
}

.inner {
Expand Down
1 change: 1 addition & 0 deletions lib/MessageBanner/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ className | string | Adds a custom class name for the `<MessageBanner>` | |
contentClassName | string | Adds a custom class name for the content element inside the `<MessageBanner>` | |
element | string, element, func | Changes the root element of the `<MessageBanner>` | | div |
show | boolean | Control the visiblity externally. Using the show-prop will enable the `<MessageBanner>` to transition in and out. | true/false | |
marginTop0 | boolean | Removes the default top margin | true/false | false
The remaining props passed to `<MessageBanner>` will be spread onto the root element of the component. This component also accepts a `ref`.
5 changes: 5 additions & 0 deletions lib/MessageBanner/tests/MessageBanner-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe('MessageBanner', () => {
dismissButtonProps={{
className: 'my-dismiss-button-class'
}}
marginTop0={true}
dismissible
>
Test
Expand Down Expand Up @@ -64,6 +65,10 @@ describe('MessageBanner', () => {
messageBanner.has({ className: including('my-class') });
});

it('Should have the marginTop0 class if passed to the prop', () => {
messageBanner.has({ className: including('marginTop0') });
});

it('Should have a root element of <span> if passed via. the element prop', () => {
messageBanner.has({ tagName: 'SPAN' });
});
Expand Down

0 comments on commit 71f391e

Please sign in to comment.