Skip to content

Improve theming docs #3370

@vladinator1000

Description

@vladinator1000

🙋 Documentation Request

Hey folks, I'm struggling to understand how to customize the themes. The docs say

React Spectrum is built to support theming.

But it's very hard to find information on how to practically change how things look. Like, for example how do I change the default styles of the inputs?

It seems like the theme you pass to the provider points to the classes and then you need to make sure the classes are present in your CSS, but what do you actually put in these classes to start meaningfully customizing Spectrum's appearance? For example I'm using emotion, but I'd recon you can do this with any styling solution.

// spectrum.ts
import { Theme } from '@react-types/provider'
import { darkTheme } from '@adobe/react-spectrum'

export const spectrumTheme: Theme = {
  ...darkTheme,
  global: {
    spectrum: 'spectrum-global',
// Should I put anything else here?
  },
}


const spectrumGlobalStyles: Style = (theme) => ({
  '.spectrum-global': {
    backgroundColor: theme.backgroundColors.primary,
    // Do I just shove all my overrides here?
    // Should I just manually comb through this file to find what I need? https://github.com/adobe/react-spectrum/blob/main/packages/%40adobe/spectrum-css-temp/vars/spectrum-dark.css
  },
})

My app that has a lot of existing styling already.

import React from 'react'
import { Global } from '@emotion/react'
import { Provider as SpectrumProvider } from '@adobe/react-spectrum';

import globalStyles from '../../style/globalStyles'
import { spectrumGlobalStyles, spectrumTheme } from "../../style/themes/spectrum";


const App: React.FC = () => {
  return (
    <SpectrumProvider theme={spectrumTheme} locale="en-GB">
        <Global styles={[globalStyles, spectrumGlobalStyles]} />

        <h1>Hello, world!</h1>
    </SpectrumProvider>
  )
}

export default App

I'd be down to make a PR if I figure out how to do it properly. Essentially, I'm trying to "normalize" spectrum so that its default styles behave with my styles.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions