Skip to content

Commit

Permalink
(fix) CarbonMRS icons should inherit CSS color (#1033)
Browse files Browse the repository at this point in the history
  • Loading branch information
ibacher authored Jun 5, 2024
1 parent 59df721 commit f0b75b0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions packages/framework/esm-styleguide/src/icons/icons.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.icon {
// fill must be marked !important or else it will be overridden by default Carbon selectors
// like '.btn__icon svg' that are interpretted as "more specific" than this class.
fill: var(--omrs-icon-fill, 'currentColor') !important;
}
14 changes: 12 additions & 2 deletions packages/framework/esm-styleguide/src/icons/icons.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @category Icons */
import React, { forwardRef, memo } from 'react';
import React, { forwardRef, memo, useEffect, useImperativeHandle, useRef } from 'react';
import classNames, { type Argument } from 'classnames';
import style from './icons.module.scss';

export type IconProps = {
className?: Argument;
Expand Down Expand Up @@ -403,9 +404,18 @@ export const Icon = memo(
console.error(`Invalid size '${size}' specified for ${icon}. Defaulting to 20.`);
size = 20;
}
const iconRef = useRef<SVGSVGElement>(null);

useImperativeHandle(ref, () => iconRef.current!);

useEffect(() => {
if (iconRef.current) {
iconRef.current.style.setProperty('--omrs-icon-fill', fill);
}
}, []);

return (
<svg ref={ref} className={classNames(className)} height={size} width={size} fill={fill} viewBox="0 0 16 16">
<svg ref={iconRef} className={classNames(className, style.icon)} height={size} width={size} viewBox="0 0 16 16">
<use xlinkHref={`#${icon}`} />
</svg>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/framework/esm-styleguide/src/icons/svgs/reset.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions packages/framework/esm-styleguide/src/icons/svgs/save.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f0b75b0

Please sign in to comment.