Skip to content

Commit

Permalink
Bug fix: exception when icon does not exist. (#179)
Browse files Browse the repository at this point in the history
* Bug fix: exception when icon does not exist.
  • Loading branch information
rubenthoms authored Oct 19, 2021
1 parent a6ce00f commit 8f2df22
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [UNRELEASED] - YYYY-MM-DD

### Fixed

- [#177](https://github.com/equinor/webviz-core-components/pull/177) - Bug fix: Menu missing if using non-existent icon.

## [0.5.2] - 2021-10-08

Expand Down
20 changes: 20 additions & 0 deletions react/src/lib/components/Menu/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from "prop-types";
import * as edsIcons from "@equinor/eds-icons";
import { IconData } from "@equinor/eds-icons";
import { Icon as EdsIcon } from "@equinor/eds-core-react";
import { Tooltip } from "@material-ui/core";

type IconProps = {
icon: string;
Expand All @@ -16,6 +17,25 @@ export const Icon: React.FC<IconProps> = (props) => {
icon = Object.values(edsIcons).find((el) => el.name === props.icon);
}

if (!icon) {
return (
<Tooltip
title={
`An icon with name "${props.icon}" does not exist.` +
` Please check the icon name for typos. ` +
`An overview of all available icons can be found at ` +
`https://eds.equinor.com/assets/system-icons/library/.`
}
>
<EdsIcon
data={edsIcons.report}
color="hsla(0, 100%, 50%, 1)"
className={(props.className || "") + " Menu__IconNotFound"}
/>
</Tooltip>
);
}

return (
<EdsIcon
data={icon}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
flex-direction: row;
}

.Menu__SectionTitle > svg * {
.Menu__SectionTitle > svg:not(.Menu__IconNotFound) * {
fill: #007079;
}

Expand Down

0 comments on commit 8f2df22

Please sign in to comment.