Skip to content
Snippets Groups Projects
Commit d55dc776 authored by Sky Brewer's avatar Sky Brewer Committed by Sky Brewer
Browse files

Swap to common LabeledIcon

parent 4be022ce
No related branches found
No related tags found
2 merge requests!497CE-2790: Prepare for 4.0.0,!466CE-2710: common duration
Pipeline #190445 waiting for manual action
......@@ -9,8 +9,7 @@ import {
PauseCircleFilled
} from "@mui/icons-material";
import Popover from "../../common/Popover";
import { AlertBanner } from "@ess-ics/ce-ui-common";
import LabeledIcon from "../../common/LabeledIcon/LabeledIcon";
import { AlertBanner, LabeledIcon } from "@ess-ics/ce-ui-common";
const STATUS = {
active: "active",
......
import { Stepper, STEPPER_STATES } from "@ess-ics/ce-ui-common";
import { Stepper, STEPPER_STATES, LabeledIcon } from "@ess-ics/ce-ui-common";
import { HelpOutline } from "@mui/icons-material";
import React from "react";
import LabeledIcon from "../common/LabeledIcon";
const ActiveIcon = STEPPER_STATES.active.outlinedIcon;
const CompletedIcon = STEPPER_STATES.completed.outlinedIcon;
......
import React from "react";
import { node, oneOfType, string, oneOf, object } from "prop-types";
import { Stack, Tooltip, Typography } from "@mui/material";
/**
* Component that renders an icon with a label.
*
* @param {object} Icon icon reference (provided as e.g. TheIcon, not as JSX e.g. <TheIcon />)
* @param {object} IconProps additional props to pass to the Icon. Accessibility props are already provided.
* @param {string} label text or Component to render as the label for the icon
* @param {object} LabelProps additional props to provide to the label when rendered as a Typography component
* (not applicable when positioned as "tooltip" or "none").
* @param {string} labelPosition describes position of the label. "tooltip" provides the label as a tooltip,
* "left" and "right" positions the label to the left or right respectively, and "none" provides no visible label
* (but still includes a11y attributes so that it is visible to screen readers)
*/
const LabeledIcon = React.forwardRef((props, ref) => {
const {
className,
Icon,
IconProps,
label,
LabelProps,
labelPosition = "tooltip",
...rest
} = props;
if (labelPosition === "tooltip") {
return (
<Tooltip
title={label}
className={className}
>
<Icon
titleAccess={label}
{...IconProps}
/>
</Tooltip>
);
}
if (labelPosition === "none") {
return (
<Icon
titleAccess={label}
{...IconProps}
/>
);
}
const renderedLabel = <Typography {...LabelProps}>{label}</Typography>;
return (
<Stack
flexDirection="row"
gap={0.5}
alignItems="center"
className={className}
ref={ref}
{...rest}
>
{labelPosition === "left" ? renderedLabel : null}
<Icon {...IconProps} />
{labelPosition === "right" ? renderedLabel : null}
</Stack>
);
});
LabeledIcon.propTypes = {
Icon: object,
IconProps: object,
label: oneOfType([string, node]),
LabelProps: object,
labelPosition: oneOf(["tooltip", "right", "left", "none"])
};
export default LabeledIcon;
import LabeledIcon from "./LabeledIcon";
export { LabeledIcon };
export default LabeledIcon;
......@@ -8,7 +8,7 @@ import {
RemoveCircleOutline
} from "@mui/icons-material";
import { theme } from "../../style/Theme";
import { LabeledIcon } from "../common/LabeledIcon";
import { LabeledIcon } from "@ess-ics/ce-ui-common";
export function DeploymentStatusIcon({ status }) {
const deploymentStatusIcons = {
......
......@@ -7,7 +7,7 @@ import {
RadioButtonUnchecked,
HelpOutline
} from "@mui/icons-material";
import LabeledIcon from "../common/LabeledIcon";
import { LabeledIcon } from "@ess-ics/ce-ui-common";
export function HostStatusIcon({ host }) {
const theme = useTheme();
......
import React from "react";
import { useTheme } from "@mui/material";
import LabeledIcon from "../common/LabeledIcon";
import { LabeledIcon } from "@ess-ics/ce-ui-common";
import {
Brightness1,
RadioButtonUnchecked,
......
import React from "react";
import LabeledIcon from "../../../../components/common/LabeledIcon/LabeledIcon";
import AccountCircleIcon from "@mui/icons-material/AccountCircle";
import { RouterHarness } from "../../../../mocks/AppHarness";
export default {
title: "common/LabeledIcon",
argTypes: {
labelPosition: {
options: ["none", "right", "left"],
control: { type: "radio" }
}
}
};
const Template = (args) => {
return (
<RouterHarness>
<LabeledIcon
Icon={AccountCircleIcon}
{...args}
/>
</RouterHarness>
);
};
export const Default = (args) => <Template {...args} />;
Default.args = {
label: "Account",
LabelProps: { fontWeight: "bold" },
labelPosition: "right",
IconProps: { color: "primary" }
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment