radix-ui / themes

Radix Themes is an open-source component library optimized for fast development, easy maintenance, and accessibility. Maintained by @workos.
https://radix-ui.com/themes
MIT License
5.45k stars 194 forks source link

dark mode doesn't work with vite #26

Closed bkyerv closed 8 months ago

jd-carroll commented 1 year ago

@bkyerv I've documented the potential issue your facing in #22 with this comment

However, there is no way to assess your problem as you didn't even bother providing a description

diboune commented 1 year ago

same here, on a brand new Tauri project with Vite React, Dark mode is not working.

balintd commented 1 year ago

I have the same issue with Radix and Vite as well. I just started a project with the react-ts vite template and added Radix Themes. Every other theme configuration works properly except for appearance which does nothing and defaults to light.

main.tsx

import React from 'react'
import ReactDOM from 'react-dom/client'
import { Theme } from '@radix-ui/themes'
import App from './App.tsx'

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <Theme
      appearance='dark'
      accentColor='violet'
      grayColor='mauve'
      panelBackground='translucent'
      radius='small'
    >
      <App />
    </Theme>
  </React.StrictMode>,
)

vite.config.ts

import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})
vgrafe commented 1 year ago

Here's a solution using https://usehooks-ts.com/react-hook/use-dark-mode:

Jes015 commented 12 months ago

There are some "hacks" to fix this. Check out issue #22 . Resume: <body class="dark">