-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
🐛 Bug Report
After spending hours trying to understand what React Spectrum is built to support theming
means on the official docs, I couldn't find the proper way to do any customization to a theme, even a very basic border-radius (I don't want to create a custom component, or to style a specific one using the UNSAFE_ property. We have a design system, and I want to make the components consistent without needing extra config per component).
🤔 Expected Behavior
We should be able to override theme variables or to write a full custom theme overriding the default theme.
😯 Current Behavior
First of all, the Theming docs mentions vaguely that custom themes can be created, but no examples are provided. Trying to create a custom theme
object, and passing some of the properties will override all properties. Copying the full theme file doesn't sound like a viable solution.
🔦 Context
I've tried to create a theme
object in multiple ways and to pass it to Provider
. The code sample below explains the approach and why it doesn't work.
💻 Code Sample
theme.module.css
.theme {
/* Button overrides */
--spectrum-button-primary-border-radius: 0.375rem;
}
index.ts
import customTheme from './theme.module.css';
import dark from './spectrum-dark.module.css';
import darkest from './spectrum-darkest.module.css';
import global from './spectrum-global.module.css';
import large from './spectrum-large.module.css';
import light from './spectrum-light.module.css';
import medium from './spectrum-medium.module.css';
const theme = {
global: global,
// MERGING DOESN'T WORK
dark: { ...dark, ...customTheme },
// WHEN APPLYING CUSTOM THEME FILE, ALL OTHER STYLES ARE IGNORED
// dark: customTheme,
darkest: darkest,
// MERGING DOESN'T WORK
light: { ...light, ...customTheme },
medium: medium,
large: large,
};
// COMPONENTS VARIABLES ARE NOT INCLUDED IN ANY OF THOSE FILES, I.E spectrum-button-primary-border-radius
export default theme;
🌍 Your Environment
Next.js 12.2.25
React 18.2.0
@nrwl/next 14.6.1
What am I missing here? Is it the right way to create a theme to duplicate all files from https://github.com/adobe/react-spectrum/tree/main/packages/%40adobe/spectrum-css-temp/vars? Which other option do we have?
Not being able to change a simple border-radius is frustrating. The theming docs also need to be updated to display some examples or to clarify what theming actually means. I've also based my assumptions on this example from the official storybook: https://github.com/adobe/react-spectrum/blob/main/packages/%40react-spectrum/provider/stories/custom-theme.css, which seems to be misleading as well.