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

[RFC]: Support common theme colors for CTB icons in the Icon component #810

Closed
markkaylor opened this issue Dec 16, 2022 · 1 comment · Fixed by #1696
Closed

[RFC]: Support common theme colors for CTB icons in the Icon component #810

markkaylor opened this issue Dec 16, 2022 · 1 comment · Fixed by #1696
Assignees
Labels
issue: discussion A general discussion issue issue: enhancement Issue suggesting an enhancement to an existing feature source: icons relates to icons package
Milestone

Comments

@markkaylor
Copy link
Contributor

markkaylor commented Dec 16, 2022

Context

CTB icons behave differently than other icons. They maintain a consistent color between themes. We provide some icons intended for custom field developers to use as CTB icons, but if they use them directly with <Icon> the color does not remain consistent between themes and therefore seem out of place within the design system.

before.mov

This means custom field developers have to do something like this to hard code the values to get the desired behavior.

const IconBox = styled(Flex)`
  /* Hard code color values */
  /* to stay consistent between themes */
  background-color: #f0f0ff; /* primary100 */
  border: 1px solid #d9d8ff; /* primary200 */

  svg > path {
    fill: #4945ff; /* primary600 */
  }
`;

const ColorPickerIcon = () => {
  return (
    <IconBox justifyContent="center" alignItems="center" width={7} height={6} hasRadius aria-hidden>
      <Icon as={Paint} />
    </IconBox>
  );
};
after.mov

Proposal

The design system could provide a way to access a color dictionary that does not change between themes.

The Icon component could then accept a boolean prop like isConsistent or isCtbIcon and handle whether or not to use the common colors or the theme colors.

const getColorDictionary = (isConsistent, theme) => {
  if (isConsistent) {
    return theme.commonColors;
  }

  return theme.colors;
};

const IconWrapper = styled(Flex)`
  path {
    fill: ${({ isConsistent, theme, color }) => getColorDictionary(isConsistent, theme)[color]};
  }
  background-color: ${({ background, isConsistent, theme }) => getColorDictionary(isConsistent, theme)[background]};
  border-color: ${({ borderColor, isConsistent, theme }) => getColorDictionary(isConsistent, theme)[borderColor]};
  ${({ theme, colors }) => colors(theme)}
`;

export const Icon = React.forwardRef(({ as, ...props }, ref) => {
  return (
    <IconWrapper {...props} ref={ref}>
      <Box as={as} />
    </IconWrapper>
  );
});

Reasons

CTB icons use the same colors between themes according to the Figma UI kit. To my knowledge this is not possible with Icon component.

CTB icon color rules:

color: {themeColor}600
backgroundColor: {themeColor}200
borderColor: {themeColor}100
@markkaylor markkaylor added the issue: discussion A general discussion issue label Dec 16, 2022
@markkaylor markkaylor self-assigned this Dec 16, 2022
@markkaylor markkaylor changed the title [RFC]: Support common colors for CTB icons in the Icon component [RFC]: Support common theme colors for CTB icons in the Icon component Dec 19, 2022
@joshuaellis joshuaellis pinned this issue Jan 30, 2023
@joshuaellis joshuaellis added this to the v2.0.0 milestone Apr 30, 2024
@joshuaellis joshuaellis linked a pull request Apr 30, 2024 that will close this issue
@joshuaellis joshuaellis added issue: enhancement Issue suggesting an enhancement to an existing feature source: icons relates to icons package labels Apr 30, 2024
@joshuaellis
Copy link
Member

solved by #1696

@joshuaellis joshuaellis unpinned this issue May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: discussion A general discussion issue issue: enhancement Issue suggesting an enhancement to an existing feature source: icons relates to icons package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants