Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more themes #9316

Merged
merged 73 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
a6f6a39
extract themes
adguernier Sep 25, 2023
2e992d7
add a custom ThemeToggler selector
adguernier Sep 25, 2023
1905e2d
add a custom theme context and provide a callback to allow its change
adguernier Sep 26, 2023
b0795b6
types and context interfaces
adguernier Sep 26, 2023
2035fb2
add the synthwave theme
adguernier Sep 26, 2023
e9b830c
fix theme application
adguernier Sep 26, 2023
7dfd0ed
remove purple colo
adguernier Sep 26, 2023
9276031
datagrid style
adguernier Sep 27, 2023
0e954ff
MuiToolbar style
adguernier Sep 27, 2023
b489cea
add minimalTheme
adguernier Sep 27, 2023
692d6c1
add margin top to whole layout in light and dark theme
adguernier Sep 27, 2023
2147ef4
introduce popTheme
adguernier Sep 27, 2023
e41efbf
fix toolbar
adguernier Sep 27, 2023
96eef56
rename ThemeToggler to ThemeSwipper
adguernier Sep 27, 2023
1c61a10
introduce chiptuneTheme
adguernier Sep 27, 2023
f39f476
remove defaultTheme from chiptuneTheme
adguernier Sep 28, 2023
da71bc1
add 4 new themes
adguernier Sep 29, 2023
2903507
rename synthwave to darkSynthwave
adguernier Sep 29, 2023
5a38a45
rename darkSynthwave to synthwaveDark
adguernier Sep 29, 2023
b4e8cb3
add synthwaveLightTheme
adguernier Sep 29, 2023
3928600
synthwave theme with dark and light declination
adguernier Sep 29, 2023
c17d019
enhance the minimal theme
adguernier Sep 29, 2023
6cf0299
change font for synthwave theme
adguernier Sep 29, 2023
a9914f9
change font for chiptune theme
adguernier Sep 29, 2023
5f5efaa
remove useless pop theme
adguernier Sep 29, 2023
8da50e7
change paper background in minimal theme
adguernier Sep 29, 2023
5ea4dd8
rename coldwave theme to eco theme and enhance it
adguernier Sep 29, 2023
3da0e56
make house theme greater
adguernier Oct 2, 2023
1668469
remove useless font
adguernier Oct 2, 2023
6f5ddb7
change icon and welcome color in dashboard according to theme
adguernier Oct 2, 2023
c4a84a0
remove useless png
adguernier Oct 2, 2023
3f6063d
change ecoTheme color
adguernier Oct 2, 2023
cbcf64a
update themeContext and swipper to allow choose dark or light theme f…
adguernier Oct 2, 2023
3d75fbc
remove useless theme
adguernier Oct 2, 2023
2b40a11
remove useless theme
adguernier Oct 2, 2023
fb94c84
add padding to house theme input
adguernier Oct 3, 2023
4f54a5d
Make minimal theme more minimal
fzaninotto Oct 9, 2023
74e8c04
Change ThemeSwapper to an icon button
fzaninotto Oct 9, 2023
c8b01c6
Rename ThemeSwapper
fzaninotto Oct 9, 2023
d55e18b
Make colors less bland
fzaninotto Oct 9, 2023
be66d83
adjust minimal theme
fzaninotto Oct 9, 2023
26d9191
Rename themes
fzaninotto Oct 9, 2023
85fe514
Put elevation in theme
fzaninotto Oct 9, 2023
807e7cf
micro adjustments
fzaninotto Oct 9, 2023
7ca7620
Make theme persistent
fzaninotto Oct 10, 2023
136a088
Move nano theme to ra-ui-materialui
fzaninotto Oct 10, 2023
af68bba
Fix LoadingIndicator
fzaninotto Oct 10, 2023
3cee32c
fix background of MuiToolbar in eco
adguernier Oct 10, 2023
98255ec
change welcome gradient
adguernier Oct 10, 2023
6194a73
fix border radius for menu item in house theme
adguernier Oct 10, 2023
be9990e
change accept and reject button color
adguernier Oct 10, 2023
a2f1fc8
Move theme-related files under theme folder
fzaninotto Oct 10, 2023
7866b34
Rename synthwave to radiant
fzaninotto Oct 10, 2023
beb66e3
Move radiant theme to core
fzaninotto Oct 10, 2023
2cf47f5
refactor houseTheme
fzaninotto Oct 10, 2023
e17daf9
move houseTheme to ra-ui-materialui
fzaninotto Oct 10, 2023
7fd812f
remove ecoTheme
fzaninotto Oct 10, 2023
b5febc5
Adjust demo
fzaninotto Oct 10, 2023
3c6a3a7
Adjust radiant
fzaninotto Oct 10, 2023
8597b58
Fix tests
fzaninotto Oct 11, 2023
9ae4adf
Add documentation
fzaninotto Oct 11, 2023
460c996
Add missing instructions
fzaninotto Oct 11, 2023
170b472
Fix storybook
fzaninotto Oct 11, 2023
c06172c
change English translation for the light/dark mode toggler
fzaninotto Oct 11, 2023
3020383
Fix test
fzaninotto Oct 11, 2023
91dd01d
fix house theme link
adguernier Oct 11, 2023
fd14e26
fix house theme link
adguernier Oct 11, 2023
b8f2f43
fix house theme link
adguernier Oct 11, 2023
0bc94a4
Un-glue form inputs in House theme
fzaninotto Oct 11, 2023
25b91d2
Merge branch 'next' into more-themes
fzaninotto Oct 11, 2023
2e39523
[no ci] simplify import
fzaninotto Oct 11, 2023
1aeb6f2
Add stories for each theme
fzaninotto Oct 11, 2023
da17283
Adjust Menu margin
fzaninotto Oct 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions docs/Admin.md
Original file line number Diff line number Diff line change
Expand Up @@ -819,28 +819,31 @@ Check the [Preferences documentation](./Store.md) for more details.

Material UI supports [theming](https://mui.com/material-ui/customization/theming/). This lets you customize the look and feel of an admin by overriding fonts, colors, and spacing. You can provide a custom Material UI theme by using the `theme` prop.

For instance, to use a dark theme by default:
React-admin comes with 4 built-in themes: [Default](./AppTheme.md#default), [Nano](./AppTheme.md#nano), [Radiant](./AppTheme.md#radiant), and [House](./AppTheme.md#house). The [e-commerce demo](https://marmelab.com/react-admin-demo/) contains a theme switcher, so you can test them in a real application.

```tsx
import { defaultTheme } from 'react-admin';
<video controls autoplay playsinline muted loop>
<source src="./img/demo-themes.mp4" type="video/mp4"/>
Your browser does not support the video tag.
</video>

const theme = {
...defaultTheme,
palette: { mode: 'dark' },
};
For instance, to use the Nano theme instead of the default theme:

```tsx
import { Admin, nanoLightTheme } from 'react-admin';
import { dataProvider } from './dataProvider';

const App = () => (
<Admin theme={theme} dataProvider={simpleRestProvider('http://path.to.my.api')}>
<Admin theme={nanoLightTheme} dataProvider={dataProvider}>
// ...
</Admin>
);
```

![Dark theme](./img/dark-theme.png)
![Nano light theme](./img/nanoLightTheme1.jpg)

If you want to support both a light and a dark theme, check out [the `<Admin darkTheme>` prop](#darktheme).
You can also [write your own theme](./AppTheme.md#writing-a-custom-theme) to fit your company branding. For more details on predefined and custom themes, refer to [the Application Theme chapter](./AppTheme.md).

For more details on predefined and custom themes, refer to [the Application Theme chapter](./AppTheme.md).
If you want to support both a light and a dark theme, check out [the `<Admin darkTheme>` prop](#darktheme).

## `title`

Expand Down
263 changes: 174 additions & 89 deletions docs/AppTheme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ title: "Application Theme"

If you want to override some styles across the entire application, you can use a custom theme, leveraging [the Material UI Theming support](https://mui.com/material-ui/customization/theming/). Custom themes let you override colors, fonts, spacing, and even the style of individual components.

![Music Player](./img/navidrome.png)
The [e-commerce demo](https://marmelab.com/react-admin-demo/) contains a theme switcher, so you can test them in a real application.

## Using A Custom Theme
<video controls autoplay playsinline muted loop>
<source src="./img/demo-themes.mp4" type="video/mp4"/>
Your browser does not support the video tag.
</video>

Pass a custom `theme` to the `<Admin>` component to override the style of the entire application:
## Setting The Application Theme

You can override the style of the entire application by passing a custom `theme` to the `<Admin>` component:

```jsx
import { Admin, defaultTheme } from 'react-admin';
Expand Down Expand Up @@ -41,8 +46,174 @@ const App = () => (
);
```

You can either use [built-in themes](#built-in-themes), or [write your own](#writing-a-custom-theme).

Note that you don't need to call Material-UI's `createTheme` yourself. React-admin will do it for you.

## Light And Dark Themes

It's a common practice to support both a light theme and a dark theme in an application, and let users choose which one they prefer.

<video controls autoplay playsinline muted loop>
<source src="./img/ToggleThemeButton.webm" type="video/webm"/>
<source src="./img/ToggleThemeButton.mp4" type="video/mp4"/>
Your browser does not support the video tag.
</video>


React-admin's `<Admin>` component accepts a `darkTheme` prop in addition to the `theme` prop.

```jsx
import { Admin, defaultTheme } from 'react-admin';

const lightTheme = defaultTheme;
const darkTheme = { ...defaultTheme, palette: { mode: 'dark' } };

const App = () => (
<Admin
dataProvider={...}
theme={lightTheme}
darkTheme={darkTheme}
>
// ...
</Admin>
);
```

With this setup, the default application theme depends on the user's system settings. If the user has chosen a dark mode in their OS, react-admin will use the dark theme. Otherwise, it will use the light theme.

In addition, users can switch from one theme to the other using [the `<ToggleThemeButton>` component](./ToggleThemeButton.md), which appears in the AppBar as soon as you define a `darkTheme` prop.

## Built-In Themes

React-admin comes with 4 built-in themes, each one having a light and a dark variant. You can use them as a starting point for your custom theme, or use them as-is.

### Default

The default theme is a good fit for every application, and works equally well on desktop and mobile.

[![Default light theme](./img/defaultLightTheme1.jpg)](./img/defaultLightTheme1.jpg)
[![Default light theme](./img/defaultLightTheme2.jpg)](./img/defaultLightTheme2.jpg)
[![Default dark theme](./img/defaultDarkTheme1.jpg)](./img/defaultDarkTheme1.jpg)
[![Default dark theme](./img/defaultDarkTheme2.jpg)](./img/defaultDarkTheme2.jpg)

You don't need to configure anything to use the default theme - it comes out of the box with react-admin.

### Nano

A dense theme with minimal chrome, ideal for complex apps. It uses a small font size, reduced spacing, text buttons, standard variant inputs, pale colors. Only fit for desktop apps.

[![Nano light theme](./img/nanoLightTheme1.jpg)](./img/nanoLightTheme1.jpg)
[![Nano light theme](./img/nanoLightTheme2.jpg)](./img/nanoLightTheme2.jpg)
[![Nano dark theme](./img/nanoDarkTheme1.jpg)](./img/nanoDarkTheme1.jpg)
[![Nano dark theme](./img/nanoDarkTheme2.jpg)](./img/nanoDarkTheme2.jpg)

To use the Nano theme, import the `nanoLightTheme` and `nanoDarkTheme` objects, and pass them to the `<Admin>` component:

```jsx
import { Admin, nanoLightTheme, nanoDarkTheme } from 'react-admin';
import { dataProvider } from './dataProvider';

export const App = () => (
<Admin
dataProvider={dataProvider}
theme={nanoLightTheme}
darkTheme={nanoDarkTheme}
>
// ...
</Admin>
);
```

You must also import the Onest font in your `index.html` file:

```html
<link href="https://fonts.googleapis.com/css2?family=Onest:wght@300;400;500;700&display=swap" rel="stylesheet">
```

### Radiant

A theme emphasizing clarity and ease of use. It uses generous margins, outlined inputs and buttons, no uppercase, and an acid color palette.

[![Radiant light theme](./img/radiantLightTheme1.jpg)](./img/radiantLightTheme1.jpg)
[![Radiant light theme](./img/radiantLightTheme2.jpg)](./img/radiantLightTheme2.jpg)
[![Radiant dark theme](./img/radiantDarkTheme1.jpg)](./img/radiantDarkTheme1.jpg)
[![Radiant dark theme](./img/radiantDarkTheme2.jpg)](./img/radiantDarkTheme2.jpg)

To use the Radiant theme, import the `radiantLightTheme` and `radiantDarkTheme` objects, and pass them to the `<Admin>` component:

```jsx
import { Admin, radiantLightTheme, radiantDarkTheme } from 'react-admin';
import { dataProvider } from './dataProvider';

export const App = () => (
<Admin
dataProvider={dataProvider}
theme={radiantLightTheme}
darkTheme={radiantDarkTheme}
>
// ...
</Admin>
);
```

You must also import the Gabarito font in your `index.html` file:

```html
<link href="https://fonts.googleapis.com/css2?family=Gabarito:wght@500;600;700;900&display=swap" rel="stylesheet">
```

### House

A young and joyful theme. It uses rounded corners, blurry backdrop, large padding, and a bright color palette.

[![House light theme](./img/houseLightTheme1.jpg)](./img/houseLightTheme1.jpg)
[![House light theme](./img/houseLightTheme2.jpg)](./img/houseLightTheme2.jpg)
[![House dark theme](./img/houseDarkTheme1.jpg)](./img/houseDarkTheme1.jpg)
[![House dark theme](./img/houseDarkTheme2.jpg)](./img/houseDarkTheme2.jpg)

To use the House theme, import the `houseLightTheme` and `houseDarkTheme` objects, and pass them to the `<Admin>` component:

```jsx
import { Admin, houseLightTheme, houseDarkTheme } from 'react-admin';
import { dataProvider } from './dataProvider';

export const App = () => (
<Admin
dataProvider={dataProvider}
theme={houseLightTheme}
darkTheme={houseDarkTheme}
>
// ...
</Admin>
);
```

You must also import the Open Sans font in your `index.html` file:

```html
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;500;600;700&display=swap" rel="stylesheet">
```

## Changing the Theme Programmatically

React-admin provides the `useTheme` hook to read and update the theme programmatically. It uses the same syntax as `useState`. Its used internally by [the `<ToggleThemeButton>` component](./ToggleThemeButton.md).

```jsx
import { defaultTheme, useTheme } from 'react-admin';
import { Button } from '@mui/material';

const ThemeToggler = () => {
const [theme, setTheme] = useTheme();

return (
<Button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
{theme === 'dark' ? 'Switch to light theme' : 'Switch to dark theme'}
</Button>
);
}
```

## Theming Individual Components

In a custom theme, you can override the style of a component for the entire application using the `components` key.
Expand Down Expand Up @@ -133,92 +304,6 @@ const theme = {
};
```

## Using A Dark Theme

React-admin ships two base themes: light and dark. To use the dark theme, import the `darkTheme` and pass it as the `<Admin theme>` prop:

```jsx
import { darkTheme } from 'react-admin';

const App = () => (
<Admin theme={darkTheme} dataProvider={...}>
// ...
</Admin>
);
```

![Dark theme](./img/dark-theme.png)

Alternatively, you can create a custom theme object with a `mode: 'dark'` palette:

```jsx
import { defaultTheme } from 'react-admin';

const darkTheme = {
...defaultTheme,
palette: { mode: 'dark' }
};

const App = () => (
<Admin theme={darkTheme} dataProvider={...}>
// ...
</Admin>
);
```

## Letting Users Choose The Theme

It's a common practice to support both a light theme and a dark theme in an application, and let users choose which one they prefer.

<video controls autoplay playsinline muted loop>
<source src="./img/ToggleThemeButton.webm" type="video/webm"/>
<source src="./img/ToggleThemeButton.mp4" type="video/mp4"/>
Your browser does not support the video tag.
</video>


React-admin's `<Admin>` component accepts a `darkTheme` prop in addition to the `theme` prop.

```jsx
import { Admin, defaultTheme } from 'react-admin';

const lightTheme = defaultTheme;
const darkTheme = { ...defaultTheme, palette: { mode: 'dark' } };

const App = () => (
<Admin
dataProvider={...}
theme={lightTheme}
darkTheme={darkTheme}
>
// ...
</Admin>
);
```

With this setup, the default application theme depends on the user's system settings. If the user has chosen a dark mode in their OS, react-admin will use the dark theme. Otherwise, it will use the light theme.

In addition, users can switch from one theme to the other using [the `<ToggleThemeButton>` component](./ToggleThemeButton.md), which appears in the AppBar as soon as you define a `darkTheme` prop.

## Changing the Theme Programmatically

React-admin provides the `useTheme` hook to read and update the theme programmatically. It uses the same syntax as `useState`. Its used internally by [the `<ToggleThemeButton>` component](./ToggleThemeButton.md).

```jsx
import { defaultTheme, useTheme } from 'react-admin';
import { Button } from '@mui/material';

const ThemeToggler = () => {
const [theme, setTheme] = useTheme();

return (
<Button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
{theme === 'dark' ? 'Switch to light theme' : 'Switch to dark theme'}
</Button>
);
}
```

## Customizing The Sidebar Width

You can specify the `Sidebar` width by setting the `width` and `closedWidth` properties on your custom Material UI theme:
Expand Down
33 changes: 30 additions & 3 deletions docs/Features.md
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,31 @@ Check the following components for details:

The default [Material Design](https://material.io/) look and feel is nice, but a bit... Google-y. If this bothers you, or if you need to brand your app, rest assured: react-admin is fully themeable.

For instance, you can use react-admin to build a [Music Player](https://demo.navidrome.org/app/):
React-admin comes with 4 built-in themes: [Default](./AppTheme.md#default), [Nano](./AppTheme.md#nano), [Radiant](./AppTheme.md#radiant), and [House](./AppTheme.md#house). The [e-commerce demo](https://marmelab.com/react-admin-demo/) contains a theme switcher, so you can test them in a real application.

<video controls autoplay playsinline muted loop>
<source src="./img/demo-themes.mp4" type="video/mp4"/>
Your browser does not support the video tag.
</video>

To use a custom theme, pass a theme object to the `<Admin>` [`theme`](./Admin.md#theme) and [`darkTheme`](./Admin.md#darktheme) props:

```jsx
import { Admin, nanoLightTheme, nanoDarkTheme } from 'react-admin';
import { dataProvider } from './dataProvider';

export const App = () => (
<Admin
dataProvider={dataProvider}
theme={nanoLightTheme}
darkTheme={nanoDarkTheme}
>
// ...
</Admin>
);
```

Theming is so powerful that you can even use react-admin to build a [Music Player](https://demo.navidrome.org/app/):

![Music Player](./img/navidrome.png)

Expand Down Expand Up @@ -1357,9 +1381,12 @@ const App = () => (

To learn more about theming in react-admin, check the following sections:

- [Introduction to Theming](./Theming.md)
- [Page Layouts](./Theming.md#customizing-the-page-layout)
- [The `sx` prop](./SX.md)
- [App-wide component overrides](./AppTheme.md#theming-individual-components)
- [Writing a custom theme](./AppTheme.md)
- [Built-In Themes](./AppTheme.md#built-in-themes)
- [App-wide theming](./AppTheme.md#theming-individual-components)
- [Helper Components For Layouts](./BoxStackGrid.md)
- [`<ToggleThemeButton>`](./ToggleThemeButton.md)
- [`useTheme`](./useTheme.md)
- [`useMediaQuery`](./useMediaQuery.md)
Expand Down
7 changes: 7 additions & 0 deletions docs/Theming.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ const App = () => (
);
```

React-admin comes with 4 built-in themes: [Default](./AppTheme.md#default), [Nano](./AppTheme.md#nano), [Radiant](./AppTheme.md#radiant), and [House](./AppTheme.md#house). The [e-commerce demo](https://marmelab.com/react-admin-demo/) contains a theme switcher, so you can test them in a real application.

<video controls autoplay playsinline muted loop>
<source src="./img/demo-themes.mp4" type="video/mp4"/>
Your browser does not support the video tag.
</video>

The application theme lets you customize color, typography, spacing, and component defaults. Check the [dedicated Application Theme chapter](./AppTheme.md) for more information.

## Customizing The Page Layout
Expand Down
Binary file added docs/img/defaultDarkTheme1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/defaultDarkTheme2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/defaultLightTheme1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/defaultLightTheme2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/demo-themes.mp4
Binary file not shown.
Binary file added docs/img/houseDarkTheme1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/houseDarkTheme2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/houseLightTheme1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/houseLightTheme2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/nanoDarkTheme1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/nanoDarkTheme2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/nanoLightTheme1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/nanoLightTheme2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/radiantDarkTheme1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/radiantDarkTheme2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/radiantLightTheme1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/radiantLightTheme2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading