Seeking the most effective strategies for empowering developers to customize elements within my React shared component.
For example, I have a dropdown and want developers to choose from predefined themes that allow them to define highlight color, font size, and font family for the list element in the dropdown component. I created enums for default themes and provided a way for devs to define theme objects and add CSS properties behind those enums. I then injected the style into the functional component.
However, I soon realized that without a method for developers to adjust an element outside the theme interface, such as font weight, their styling options were limited. I would need to manually update and test various style combinations, leading to unnecessary complexity.
I'm exploring an implementation where I provide refs to elements within the component and offer an open-ended CSSProperties
style prop for developers to freely style as needed. Are there best practices for achieving this? An illustrative example would be appreciated.
It's worth noting that frameworks like Next JS may encode CSS modules, making it challenging to enable user-provided CSS manipulation due to encoding or appended IDs. This is why I believe the refs approach could be a viable solution.