Skip to content

Implemented EdsIcon component #227

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- [#207](https://github.com/equinor/webviz-core-components/pull/207) - Added `storybook` and stories for each component. Added publishment of `storybook` to GitHub workflow. Added `storybook` link to README.
- [#219](https://github.com/equinor/webviz-core-components/pull/219) - Implemented components required by the new Webviz Layout Framework (WLF)
- [#227](https://github.com/equinor/webviz-core-components/pull/227) - Added `EdsIcon` component in order to use icons from the Equinor Design System (EDS) directly in Python.

### Changed

Expand Down
22 changes: 22 additions & 0 deletions react/src/lib/components/EdsIcon/EdsIcon.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from "react";

import { ComponentStory, ComponentMeta } from "@storybook/react";

import { EdsIcon, EdsIconProps } from "./EdsIcon";

export default {
title: "Components/EdsIcon",
component: EdsIcon,
} as ComponentMeta<typeof EdsIcon>;

const Template: ComponentStory<typeof EdsIcon> = (args: EdsIconProps) => (
<EdsIcon {...args} />
);

export const Basic = Template.bind({});
Basic.args = {
id: "Icon",
color: "#000000",
size: 32,
icon: "world",
};
52 changes: 52 additions & 0 deletions react/src/lib/components/EdsIcon/EdsIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from "react";
import PropTypes from "prop-types";
import * as edsIcons from "@equinor/eds-icons";
import { IconData } from "@equinor/eds-icons";
import { Icon } from "@equinor/eds-core-react";
import { Tooltip } from "@material-ui/core";

export type EdsIconProps = {
id?: string;
icon: string;
size?: 16 | 24 | 32 | 40 | 48;
color?: string;
};

export const EdsIcon: React.FC<EdsIconProps> = (props) => {
let icon: IconData | undefined = undefined;
if (props.icon) {
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-storybook-react.azurewebsites.net/?path=/story/icons--preview.`
}
>
<Icon
id={props.id}
data={edsIcons.report}
color="hsla(0, 100%, 50%, 1)"
className={"IconNotFound"}
size={props.size}
/>
</Tooltip>
);
}

return (
<Icon id={props.id} data={icon} size={props.size} color={props.color} />
);
};

EdsIcon.propTypes = {
id: PropTypes.string,
icon: PropTypes.string.isRequired,
size: PropTypes.oneOf([16, 24, 32, 40, 48]),
color: PropTypes.string,
};
1 change: 1 addition & 0 deletions react/src/lib/components/EdsIcon/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EdsIcon } from "./EdsIcon";
2 changes: 1 addition & 1 deletion react/src/lib/components/Menu/components/Icon/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const Icon: React.FC<IconProps> = (props) => {
`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/.`
`https://eds-storybook-react.azurewebsites.net/?path=/story/icons--preview.`
}
>
<EdsIcon
Expand Down
2 changes: 2 additions & 0 deletions react/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { WebvizSettingsGroup } from "./components/WebvizSettingsGroup";
import { WebvizPluginLayoutColumn } from "./components/WebvizPluginLayoutColumn/WebvizPluginLayoutColumn";
import { WebvizPluginLayoutRow } from "./components/WebvizPluginLayoutRow/WebvizPluginLayoutRow";
import { WebvizPluginLoadingIndicator } from "./components/WebvizPluginLoadingIndicator";
import { EdsIcon } from "./components/EdsIcon";

import "./components/FlexBox/flexbox.css";
import "./components/Layout";
Expand Down Expand Up @@ -60,4 +61,5 @@ export {
Overlay,
ScrollArea,
Dialog,
EdsIcon,
};