I am trying to use Joy UI and its dark mode https://mui.com/joy-ui/customization/dark-mode/
in my cljs project and am stuck with translating the part below to cljs code.
import * as React from 'react';
import { CssVarsProvider, extendTheme } from '@mui/joy/styles';
import Sheet from '@mui/joy/Sheet';
import Chip from '@mui/joy/Chip';
import Typography from '@mui/joy/Typography';
const theme = extendTheme({ cssVarPrefix: 'demo' });
export default function DarkModeByDefault() {
return (
<CssVarsProvider
defaultMode="dark"
// the props below are specific to this demo,
// you might not need them in your app.
//
theme={theme}
// the selector to apply CSS theme variables stylesheet.
colorSchemeSelector="#demo_dark-mode-by-default"
//
// the local storage key to use
modeStorageKey="demo_dark-mode-by-default"
//
// set as root provider
disableNestedContext
>
<div id="demo_dark-mode-by-default">
<Sheet sx={{ px: 3, py: 1.5, borderRadius: 'sm' }}>
<Typography
component="div"
endDecorator={
<Chip variant="outlined" color="primary" size="sm">
Default
</Chip>
}
fontSize="lg"
>
Dark mode
</Typography>
</Sheet>
</div>
</CssVarsProvider>
);
}
I am using shadow-cljs
, and I tried to translate it like the following
(ns ....
(:require
...
["@mui/joy/Button" :as mui-joy-button]
["@mui/joy/Grid" :as mui-joy-grid]
["@mui/joy/styles" :as mui-joy-styles]))
(def btn (rc/adapt-react-class (.-default mui-joy-button)))
(def grd (rc/adapt-react-class (.-default mui-joy-grid)))
(def cvp (rc/adapt-react-class mui-joy-styles/CssVarsProvider))
(def ext mui-joy-styles/extendTheme)
(def theme (ext {:cssVarPrefix "demo"}))
(defn main-page []
[cvp {:defaultMode "dark"
:theme theme
:colorSchemeSelector "#demo_dark-mode-by-default"
:modeStorageKey "demo_dark-mode-by-default"
:disableNestedContext true}]
[:div {:id "demo_dark-mode-by-default"}
[grd {:container true :spacing 2}
[grd {:xs 8} [:p "asdasdfasdf"]]
[grd {:xs 4} [btn {:variant :solid} "asdf"]]]])
But the theming and dark mode do not work. I believe my problem is CssVarsProvider part. I am not sure how I can import it.
Can someone please provide a clue?