question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Improve theming docs

See original GitHub issue

šŸ™‹ 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.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
LFDanLucommented, Sep 14, 2022

Your hunch is correct, creating your own custom theme would require reproducing the set of variables/tokens that our Spectrum themes have and replacing the values with your own colors (e.g. you could set --spectrum-global-color-gray-800: red in your own css file and set that file as your ā€˜light’ theme object that your provide to our Provider). We don’t recommend that users do so since many of the color and size choices were made with color contrast and mobile + desktop accessibility in mind.

Since you are building your own app that has its own styling in place, it may be easier to create the components with the aria/stately hooks instead so that you have full control over the styling yourself

0reactions
hugomncommented, Oct 10, 2022

@LFDanLu if I understand you correctly, does that mean that my components will always have the blue-400 as the primary color, and if I want a button with a different primary color, I need to create a new one, reimplement all the logic using aria/stately? Something like <MyCustomGreenButton />? And all the other components will still be blue-400? How about increasing the default font-sizes and input-heights?

After struggling for some hours setting up Spectrum, I’m shocked that theming is ~NOT~ customizable at all, which is quite the opposite of what you can find in the homepage and in the docs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Do You Actually Need WordPress Documentation Themes ...
BetterDocs is one of the most powerful, complete WordPress knowledge base solutions to create, manage and organize your online documentation. ItĀ ...
Read more >
Change the theme or font of your form - Google Docs Editors ...
In Google Forms, open a form. Click Customize theme Customize theme . Under "Color," you can choose a theme color and background color...
Read more >
How to Improve Site Performance | Themeco Docs
In this article, we're going to explain how to optimize your website performance in order to provide your visitors the best experience possible....
Read more >
Themes - MoodleDocs
For documentation on installing and using themes, please see the Themes user ... Moving your theme to use boost as a parent theme...
Read more >
Theming guide for Drupal 7.
A theme is a collection of files that define the presentation layer. You can also create one or more "sub-themes" or variations on...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found