-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) O3-4249: Add component to support rendering an icon if it exists #1220
Conversation
Size Change: -148 kB (-2.35%) Total Size: 6.15 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @ibacher for working on this. I was about to discuss about the same in a few days, so happy to see this!
} | ||
}; | ||
|
||
const observer = new MutationObserver(callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note to self: I'm not sure about the performance implications of having a per-icon mutation observer vs, say, a global mutation observer that could have callbacks registered with it. This is, however, easier to write.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess we'll find out!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ibacher. LGTM. I've left a few persnickety comments.
packages/framework/esm-react-utils/src/RenderIfValueIsTruthy.tsx
Outdated
Show resolved
Hide resolved
packages/framework/esm-styleguide/src/pictograms/pictograms.tsx
Outdated
Show resolved
Hide resolved
packages/framework/esm-styleguide/src/pictograms/pictograms.tsx
Outdated
Show resolved
Hide resolved
* <MaybeIcon icon='omrs-icon-baby' className={styles.myIconStyles} /> | ||
* ``` | ||
*/ | ||
export const MaybeIcon = memo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export const MaybeIcon = memo( | |
export const MaybeIcon = memo( |
nit: Maybe LoadableIcon
reads better here?
} | ||
}; | ||
|
||
const observer = new MutationObserver(callback); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guess we'll find out!
Co-authored-by: Dennis Kigen <[email protected]>
Requirements
feat
,fix
, orchore
, among others). See existing PR titles for inspiration.For changes to apps
If applicable
Summary
This is pretty straight-forward. It adds a couple of utility components:
RenderIfValueIsTruthy
— Does what it says; either renders the provided children if thevalue
prop is truthy or else renders a specified fallback (default nothing). This is just a building block for the functionality added here, but it seemed like it may be more broadly useful.MaybeIcon
— This is basically a combination ofRenderIfValueIsTruthy
and the existingIcon
component, so that it renders as an icon if the icon specified as a string is one of the icons provided and as nothing if the icon isn't defined.MaybePictogram
— Same thing, but wrapping pictograms.The intended use case is to support configuration-driven icons, for example:
As long as
config.icon
resolves to a known icon id, e.g.,arrow-up
, this will render exactly like theArrowUpIcon
component, but ifconfig.icon
specifies something that doesn't exist, nothing will be rendered at all.Screenshots
Related Issue
Other
This also adds some docs for
UserHasAccess
which is kind of similar toRenderIfValueIsTruthy
.