Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions .changeset/polite-turkeys-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@leafygreen-ui/icon': patch
---

Fixed an issue where icons generated through createIconComponent were not passing in fill value correctly
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Fixed an issue where icons generated through createIconComponent were not passing in fill value correctly
Fixed an issue where icons generated through `createIconComponent` were not passing in fill value correctly

13 changes: 13 additions & 0 deletions packages/icon/src/Icon.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { typeIs } from '@leafygreen-ui/lib';

import EditIcon from './generated/Edit';
import { Size } from './glyphCommon';
import { Icon } from './Icon';
import { isComponentGlyph } from './isComponentGlyph';
import { SVGR } from './types';
import { createGlyphComponent, createIconComponent, glyphs } from '.';
Expand Down Expand Up @@ -256,6 +257,18 @@ describe('packages/Icon/createIconComponent', () => {
});
});

describe('packages/Icon/Icon', () => {
test('`fill` prop applies CSS color correctly', () => {
const { container } = render(<Icon glyph="Edit" fill="red" />);
const svg = container.querySelector('svg');
expect(svg).toBeTruthy();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(svg).toBeTruthy();
expect(svg).toBeInTheDocument();

// The fill prop should be applied as a CSS color via emotion
// We check that the computed style has the correct color
const computedStyle = window.getComputedStyle(svg!);
expect(computedStyle.color).toBe('red');
});
});

describe('Generated glyphs', () => {
test('Edit icon has displayName: "Edit"', () => {
expect(EditIcon.displayName).toBe('Edit');
Expand Down
4 changes: 2 additions & 2 deletions packages/icon/src/createIconComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ type GlyphObject = Record<string, LGGlyph.Component>;
export function createIconComponent<G extends GlyphObject = GlyphObject>(
glyphs: G,
) {
const Icon = ({ glyph, ...rest }: IconProps) => {
const Icon = ({ glyph, fill, ...rest }: IconProps) => {
const SVGComponent = glyphs[glyph];

if (SVGComponent) {
return <SVGComponent {...rest} />;
return <SVGComponent {...rest} fill={fill} />;
} else {
// TODO: improve fuzzy match
// Suggest the proper icon casing if there's a near match
Expand Down
Loading