Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 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 @@ -245,6 +246,16 @@ describe('packages/Icon/createIconComponent', () => {
const glyph = getByTestId('my-glyph');
expect(glyph).toHaveAttribute('role', 'presentation');
});

test('`fill` prop applies CSS color correctly', () => {
const { container } = render(<Icon glyph="Edit" fill="red" />);
const svg = container.querySelector('svg');
expect(svg).toBeTruthy();
// The fill prop should be applied as a CSS color via emotion
// We check that the SVG has a className (from emotion) and the computed style
const computedStyle = window.getComputedStyle(svg!);
expect(computedStyle.color).toBe('red');
});
});

test('returned Icon function logs an error when glyph does not exist', () => {
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 fill={fill} {...rest} />;
} else {
// TODO: improve fuzzy match
// Suggest the proper icon casing if there's a near match
Expand Down
Loading