Skip to content

Commit

Permalink
STCOM-1408: Add marginTop0 class to MessageBanner component
Browse files Browse the repository at this point in the history
  • Loading branch information
mariia-aloshyna committed Feb 13, 2025
1 parent 0043934 commit b059e84
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 @@ -23,6 +23,7 @@
* Paneset - deduplicate panes via `id` prior to registration. Refs STCOM-1386.
* 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.
* 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 @@ -46,6 +46,7 @@ const MessageBanner = forwardRef(
onExited,
show = true,
type = TYPES.DEFAULT,
marginTop0 = false,
...rest
},
ref
Expand Down Expand Up @@ -79,8 +80,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 @@ -153,6 +159,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 @@ -85,6 +85,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 b059e84

Please sign in to comment.