Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Purpose
Some apps have a strict size restriction and can't simply include all
<Icons />
provided as an SVG sheet.That means using
Select
andSearch
can have serious size implications.Currently, their only option is to construct their own SVG sheet, presumably by taking the one provided by
@onfido/castor-icons
and removing unused icons.This PR aims to offer an alternative in a per-component API to replace default icons.
Approach
Offer an
icon
prop that allows overriding default icon.Because the prop accepts a
JSX.Element
, it is not limited to@onfido/castor-icons
, any React component's output will work.Testing
Modified Select and Search stories, including a new story to demonstrate how to use the new API.
Risks
Elements in component props is not an ergonomic API in my opinion, we should still prefer
children
and composition.However this is an exception with limited applications and it prevents weird APIs like wrapping special children in React context.
We could also simply use inline icons in those components and accept the trade-off of more runtime DOM elements but reduced bundle size.
A valid alternative in case we don't want to extend components with the proposed API.