For generic components, I like to use the first class module type :
It allows to enforce styling rules based on component props.
// Button.res
module type Icon = {
@react.component
let make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element
}
@react.component
let make = (
~leftIcon: option<module(Icon)>=?,
...
) => {
{leftIcon->Option.mapWithDefault(React.null, icon => {
let module(Icon) = icon
<span>
<Icon size={24} />
</span>
})}
}
// ReactIcons.res
module Md3dRotation = {
@module("react-icons/md") @react.component
external make: (~size: int=?, ~color: string=?, ~className: string=?) => React.element =
"Md3dRotation"
}
<Button leftIcon={module(Md3dRotation)} />