Skip to content
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

Create a base Icon to derive from when creating icons #589

Open
nebula-aac opened this issue Apr 27, 2024 · 0 comments
Open

Create a base Icon to derive from when creating icons #589

nebula-aac opened this issue Apr 27, 2024 · 0 comments
Labels
kind/enhancement Improvement in current feature

Comments

@nebula-aac
Copy link
Contributor

nebula-aac commented Apr 27, 2024

Current Behavior

We have multiple icons that needs to be refactored to reduce duplication on variables and constants, and rather rely on one icon to use from.

Desired Behavior

  • Create base SistentIcon
  • Widen the IconProps to include sx props as an optional field to be used with MUI
  • Add size field in IconProps to provide the default sizes for xsmall, small, medium, large, and xlarge

Implementation

The below describes the SistentIcon that will wraps the svg path or else with Box, doesn't have to be box, it can be a div.

The children was changed to allow child elements within the div or Box

export type IconSize = "xsmall" | "small" | "medium" | "large";

export type IconProps = {
  children?: React.ReactNode;
  color?: string;
  title?: string;
  width?: number | string;
  height?: number | string;
  size?: IconSize;
  sx?: SxProps<Theme>;
} & Omit<BoxProps, "sx"> &
  React.SVGProps<SVGSVGElement>;

const iconSizes: Record<IconSize, { width: number; height: number }> = {
  xsmall: { width: 16, height: 16 },
  small: { width: 24, height: 24 },
  medium: { width: 32, height: 32 },
  large: { width: 40, height: 40 },
};

export default function SistentIcon({
  color,
  title,
  size = "medium",
  fill = CHARCOAL_FILL,
  viewBox,
  sx,
  children,
  ...rest
}: IconProps) {
  const { width, height } = iconSizes[size];

  return (
    <Box
      component={"svg"}
      xmlns="http://www.w3.org/2000/svg"
      width={width}
      height={height}
      viewBox={viewBox}
      fill={fill || color}
      sx={sx}
      {...rest}
    >
      {title && <title>{title}</title>}
      {children}
    </Box>
  );
}

The fill will be a default color, in this case charcoal. This can be changed inline in project specific. You can also use sx props from MUI in order to use the theme inline.

            <IconButton
              aria-label="close"
              onClick={onClose}
              sx={(theme) => ({
                "&:hover": {
                  "& svg": {
                    fill: theme.palette.keppelGreen,
                  },
                },
              })}
              disableRipple
            >
              <CloseIcon
                sx={(theme) => ({
                  fill: theme.palette.charcoal,
                })}
              />
            </IconButton>

Acceptance Tests

Mockups


Contributor Guide

@nebula-aac nebula-aac added the kind/enhancement Improvement in current feature label Apr 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement Improvement in current feature
Development

No branches or pull requests

1 participant