Skip to content

Commit

Permalink
feature: support hide close button on banner (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hadas Farhi authored Jun 22, 2021
1 parent b90a3f7 commit 8dbfceb
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 13 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "monday-ui-react-core",
"version": "0.3.46",
"version": "0.3.47",
"description": "Official monday.com UI resources for application development in React.js",
"main": "dist/main.js",
"scripts": {
Expand Down Expand Up @@ -167,4 +167,4 @@
"not and_qq > 0",
"not and_uc > 0"
]
}
}
26 changes: 15 additions & 11 deletions src/components/AlertBanner/AlertBanner.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import "./AlertBanner.scss";
const NOOP = () => {};

const AlertBanner = forwardRef(
({ children: originalChildren, className, backgroundColor, onClose, ariaLabel }, ref) => {
({ children: originalChildren, className, backgroundColor, onClose, ariaLabel, isCloseHidden }, ref) => {
const classNames = useMemo(() => {
return cx(className, "monday-alert-banner", `monday-alert-banner--background-color-${backgroundColor}`);
}, [className, backgroundColor]);
Expand Down Expand Up @@ -56,16 +56,18 @@ const AlertBanner = forwardRef(
})}
</div>
<div className="monday-alert-banner__close-button-wrapper">
<Button
className="monday-alert-banner__alert-banner-close-btn"
onClick={onClose}
size={Button.sizes.SMALL}
kind={Button.kinds.TERTIARY}
color={isDarkBackground ? Button.colors.ON_INVERTED_BACKGROUND : Button.colors.ON_PRIMARY_COLOR}
ariaLabel="close-toast"
>
<Icon iconType={Icon.type.SVG} clickable={false} icon={CloseSmall} iconSize="20px" ignoreFocusStyle />
</Button>
{isCloseHidden ? null : (
<Button
className="monday-alert-banner__alert-banner-close-btn"
onClick={onClose}
size={Button.sizes.SMALL}
kind={Button.kinds.TERTIARY}
color={isDarkBackground ? Button.colors.ON_INVERTED_BACKGROUND : Button.colors.ON_PRIMARY_COLOR}
ariaLabel="close-toast"
>
<Icon iconType={Icon.type.SVG} clickable={false} icon={CloseSmall} iconSize="20px" ignoreFocusStyle />
</Button>
)}
</div>
</div>
);
Expand All @@ -84,13 +86,15 @@ AlertBanner.propTypes = {
AlertBanner.backgroundColors.POSITIVE,
AlertBanner.backgroundColors.DARK
]),
isCloseHidden: PropTypes.bool,
/** ARIA description for the progress bar */
ariaLabel: PropTypes.string,
onClose: PropTypes.func
};

AlertBanner.defaultProps = {
backgroundColor: AlertBanner.backgroundColors.PRIMARY,
isCloseHidden: false,
className: "",
ariaLabel: "",
onClose: NOOP
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const Sandbox = () => (
)}
className={select("With custom class", ["alert-banner--custom-class", ""], "")}
ariaLabel={text("Bar Aria Label", "my awesome alert banner")}
isCloseHidden={boolean("Is close hidden", false)}
>
<AlertBannerText text="Lorem ipsum" />
<AlertBannerLink text="Lorem ipsum" href="https://monday.com" />
Expand Down
5 changes: 5 additions & 0 deletions src/components/AlertBanner/__tests__/AlertBanner.jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,9 @@ describe("AlertBanner", () => {
.toJSON();
expect(tree).toMatchSnapshot();
});

it("should render correctly with hidden close button", () => {
const tree = renderer.create(<AlertBanner isCloseHidden></AlertBanner>).toJSON();
expect(tree).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`AlertBanner should render correctly with hidden close button 1`] = `
<div
aria-label="banner"
className="monday-alert-banner monday-alert-banner--background-color-primary"
role="banner"
>
<div
className="monday-alert-banner__inner"
/>
<div
className="monday-alert-banner__close-button-wrapper"
/>
</div>
`;

exports[`AlertBanner should render correctly without props 1`] = `
<div
aria-label="banner"
Expand Down

0 comments on commit 8dbfceb

Please sign in to comment.