RFC: Theming in Source React Component props #1080
Replies: 2 comments 7 replies
-
This would be a benefical API for Looking at the associated PR, it seems like consumers are able to pass a partial This is the approach we’ve taken for the Here’s an example which may illustrate my point: const defaultTheme = {
background: 'black',
text: 'white',
};
type Props = {
theme?: typeof defaultTheme;
children: React.ReactNode;
}
const Button = ({ theme = defaultTheme }: Props) =>
<button style={{ background: theme.background, color: theme.text }}>
{children}
</button>
// if you allow partial theme, you get too low a contrast, here 2.1
<Button theme={{ text: 'darkred' }}>Click me if you can</Button>
// if you force consumers to provide a full theme, they are responsible for an accessible ratio, here 6.5
<Button theme={{ text: 'darkred', background: 'pink', }}>Click me</Button> |
Beta Was this translation helpful? Give feedback.
-
We understand the rationale for making it more challenging for consumers to apply only a partial theme to components. However, we believe the responsibility for ensuring that the provided colours are accessible and complete should rest with the designer. As such, we prefer not to obligate consumers to spread the default theme when only a different background colour is needed. Our primary concern is that increasing the difficulty for consumers to customise components might lead them to resort to less advisable methods, such as using cssOverrides. |
Beta Was this translation helpful? Give feedback.
-
We are updating the implementation of themes in Source React components from a request for a new dark mode for DCAR. This involves a few changes to the recommended way themes are handled in our Source React components:
Introduction of a theme Prop: We are introducing a new theme prop in our Source React components. This will allow consumers to apply a custom theme to any component. This approach is necessary because the ThemeProvider in Emotion is not compatible with Islands in their current form.
Support and Deprecation Plan for ThemeProvider: While we will continue to support the ThemeProvider, we plan to phase out the old themes. Instead, we will adopt new theme objects that align more closely with the Source components in figma.
Reducing Dependency on Emotion: These changes will also help in gradually moving our Source React components away from Emotion.
Discouraging CssOverrides: We want to move away from using CssOverrides as the recommended method for altering these components.
Previously, setting a theme for components like ChoiceCard was done using the ThemeProvider:
Updated way of providing a theme. Any variables you supply in the object are optional. You can override one or multiple of the defaults
Here is the PR with the proposal for the choice card component. https://github.com/guardian/csnx/pull/1070/files.
Here is the storybook https://635a6fffacd30d393597c1ff-qtrtddfvkq.chromatic.com/?path=/docs/choicecard--docs.
Beta Was this translation helpful? Give feedback.
All reactions