From f0b75b00f292ed78876042af04f1b17a05d5f123 Mon Sep 17 00:00:00 2001 From: Ian <52504170+ibacher@users.noreply.github.com> Date: Wed, 5 Jun 2024 16:15:41 -0400 Subject: [PATCH] (fix) CarbonMRS icons should inherit CSS color (#1033) --- .../esm-styleguide/src/icons/icons.module.scss | 5 +++++ .../framework/esm-styleguide/src/icons/icons.tsx | 14 ++++++++++++-- .../esm-styleguide/src/icons/svgs/reset.svg | 4 ++-- .../esm-styleguide/src/icons/svgs/save.svg | 4 ++-- 4 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 packages/framework/esm-styleguide/src/icons/icons.module.scss diff --git a/packages/framework/esm-styleguide/src/icons/icons.module.scss b/packages/framework/esm-styleguide/src/icons/icons.module.scss new file mode 100644 index 000000000..3fbfbe8fb --- /dev/null +++ b/packages/framework/esm-styleguide/src/icons/icons.module.scss @@ -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; +} diff --git a/packages/framework/esm-styleguide/src/icons/icons.tsx b/packages/framework/esm-styleguide/src/icons/icons.tsx index ee7417393..0c407ec1f 100644 --- a/packages/framework/esm-styleguide/src/icons/icons.tsx +++ b/packages/framework/esm-styleguide/src/icons/icons.tsx @@ -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; @@ -403,9 +404,18 @@ export const Icon = memo( console.error(`Invalid size '${size}' specified for ${icon}. Defaulting to 20.`); size = 20; } + const iconRef = useRef(null); + + useImperativeHandle(ref, () => iconRef.current!); + + useEffect(() => { + if (iconRef.current) { + iconRef.current.style.setProperty('--omrs-icon-fill', fill); + } + }, []); return ( - + ); diff --git a/packages/framework/esm-styleguide/src/icons/svgs/reset.svg b/packages/framework/esm-styleguide/src/icons/svgs/reset.svg index 1c77dcc2e..811c1918a 100644 --- a/packages/framework/esm-styleguide/src/icons/svgs/reset.svg +++ b/packages/framework/esm-styleguide/src/icons/svgs/reset.svg @@ -1,3 +1,3 @@ - - + + diff --git a/packages/framework/esm-styleguide/src/icons/svgs/save.svg b/packages/framework/esm-styleguide/src/icons/svgs/save.svg index ebabae191..e9c8cea25 100644 --- a/packages/framework/esm-styleguide/src/icons/svgs/save.svg +++ b/packages/framework/esm-styleguide/src/icons/svgs/save.svg @@ -1,3 +1,3 @@ - - + +