Skip to content

Commit

Permalink
feat: adding icon bg color param
Browse files Browse the repository at this point in the history
  • Loading branch information
JonnCh committed Dec 11, 2024
1 parent 2f92c99 commit 18a5914
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/Icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface IconProps extends AriaAttributes, DOMProps {
icon: IconKey;
/** Defaults to currentColor */
color?: Palette | "inherit" | "currentColor";
bgColor?: Palette;
/** The size of the icon in increments, i.e. 1 == 8px, default is 3 == 24px. */
inc?: number;
/** Styles overrides */
Expand All @@ -16,7 +17,7 @@ export interface IconProps extends AriaAttributes, DOMProps {
}

export const Icon = React.memo((props: IconProps) => {
const { icon, inc = 3, color = "currentColor", xss, tooltip, ...other } = props;
const { icon, inc = 3, color = "currentColor", bgColor, xss, tooltip, ...other } = props;
const size = increment(inc);
return maybeTooltip({
title: tooltip,
Expand All @@ -28,7 +29,7 @@ export const Icon = React.memo((props: IconProps) => {
height={size}
viewBox="0 0 24 24"
xmlns="http://www.w3.org/2000/svg"
css={{ "path, rect": Css.fill(color).$, ...xss }}
css={{ "path, rect": Css.fill(color).$, ...(bgColor && Css.bgColor(bgColor).$), ...xss }}
data-icon={icon}
{...other}
>
Expand Down
10 changes: 9 additions & 1 deletion src/components/IconButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export interface IconButtonProps extends BeamButtonProps, BeamFocusableProps {
/** The icon to use within the button. */
icon: IconProps["icon"];
color?: Palette;
bgColor?: Palette;
/** The size of the icon, in increments, defaults to 3 which is 24px. */
inc?: number;
/** HTML attributes to apply to the button element when it is being used to trigger a menu. */
Expand All @@ -33,6 +34,7 @@ export function IconButton(props: IconButtonProps) {
onClick: onPress,
disabled,
color,
bgColor,
icon,
autoFocus,
inc,
Expand Down Expand Up @@ -68,6 +70,7 @@ export function IconButton(props: IconButtonProps) {
...(isHovered && (contrast ? iconButtonContrastStylesHover : iconButtonStylesHover)),
...(isFocusVisible || forceFocusStyles ? iconButtonStylesFocus : {}),
...(isDisabled && iconButtonStylesDisabled),
...(bgColor && Css.bgColor(bgColor).$),
}),
// TODO: validate this eslint-disable. It was automatically ignored as part of https://app.shortcut.com/homebound-team/story/40033/enable-react-hooks-exhaustive-deps-for-react-projects
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -86,7 +89,12 @@ export function IconButton(props: IconButtonProps) {
"aria-label": label,
};
const buttonContent = (
<Icon icon={icon} color={color || (isDisabled ? Palette.Gray400 : iconColor)} inc={compact ? 2 : inc} />
<Icon
icon={icon}
color={color || (isDisabled ? Palette.Gray400 : iconColor)}
bgColor={bgColor}
inc={compact ? 2 : inc}
/>
);

// If we're disabled b/c of a non-boolean ReactNode, or the caller specified tooltip text, then show it in a tooltip
Expand Down

0 comments on commit 18a5914

Please sign in to comment.