Skip to content

Commit d51a509

Browse files
authored
Merge pull request #9316 from marmelab/more-themes
Add more themes
2 parents 2fbcd26 + da17283 commit d51a509

File tree

78 files changed

+1487
-202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+1487
-202
lines changed

docs/Admin.md

+14-11
Original file line numberDiff line numberDiff line change
@@ -819,28 +819,31 @@ Check the [Preferences documentation](./Store.md) for more details.
819819

820820
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.
821821

822-
For instance, to use a dark theme by default:
822+
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.
823823

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

827-
const theme = {
828-
...defaultTheme,
829-
palette: { mode: 'dark' },
830-
};
829+
For instance, to use the Nano theme instead of the default theme:
830+
831+
```tsx
832+
import { Admin, nanoLightTheme } from 'react-admin';
833+
import { dataProvider } from './dataProvider';
831834

832835
const App = () => (
833-
<Admin theme={theme} dataProvider={simpleRestProvider('http://path.to.my.api')}>
836+
<Admin theme={nanoLightTheme} dataProvider={dataProvider}>
834837
// ...
835838
</Admin>
836839
);
837840
```
838841

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

841-
If you want to support both a light and a dark theme, check out [the `<Admin darkTheme>` prop](#darktheme).
844+
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).
842845

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

845848
## `title`
846849

docs/AppTheme.md

+174-89
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@ title: "Application Theme"
77

88
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.
99

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

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

14-
Pass a custom `theme` to the `<Admin>` component to override the style of the entire application:
17+
## Setting The Application Theme
18+
19+
You can override the style of the entire application by passing a custom `theme` to the `<Admin>` component:
1520

1621
```jsx
1722
import { Admin, defaultTheme } from 'react-admin';
@@ -41,8 +46,174 @@ const App = () => (
4146
);
4247
```
4348

49+
You can either use [built-in themes](#built-in-themes), or [write your own](#writing-a-custom-theme).
50+
4451
Note that you don't need to call Material-UI's `createTheme` yourself. React-admin will do it for you.
4552

53+
## Light And Dark Themes
54+
55+
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.
56+
57+
<video controls autoplay playsinline muted loop>
58+
<source src="./img/ToggleThemeButton.webm" type="video/webm"/>
59+
<source src="./img/ToggleThemeButton.mp4" type="video/mp4"/>
60+
Your browser does not support the video tag.
61+
</video>
62+
63+
64+
React-admin's `<Admin>` component accepts a `darkTheme` prop in addition to the `theme` prop.
65+
66+
```jsx
67+
import { Admin, defaultTheme } from 'react-admin';
68+
69+
const lightTheme = defaultTheme;
70+
const darkTheme = { ...defaultTheme, palette: { mode: 'dark' } };
71+
72+
const App = () => (
73+
<Admin
74+
dataProvider={...}
75+
theme={lightTheme}
76+
darkTheme={darkTheme}
77+
>
78+
// ...
79+
</Admin>
80+
);
81+
```
82+
83+
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.
84+
85+
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.
86+
87+
## Built-In Themes
88+
89+
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.
90+
91+
### Default
92+
93+
The default theme is a good fit for every application, and works equally well on desktop and mobile.
94+
95+
[![Default light theme](./img/defaultLightTheme1.jpg)](./img/defaultLightTheme1.jpg)
96+
[![Default light theme](./img/defaultLightTheme2.jpg)](./img/defaultLightTheme2.jpg)
97+
[![Default dark theme](./img/defaultDarkTheme1.jpg)](./img/defaultDarkTheme1.jpg)
98+
[![Default dark theme](./img/defaultDarkTheme2.jpg)](./img/defaultDarkTheme2.jpg)
99+
100+
You don't need to configure anything to use the default theme - it comes out of the box with react-admin.
101+
102+
### Nano
103+
104+
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.
105+
106+
[![Nano light theme](./img/nanoLightTheme1.jpg)](./img/nanoLightTheme1.jpg)
107+
[![Nano light theme](./img/nanoLightTheme2.jpg)](./img/nanoLightTheme2.jpg)
108+
[![Nano dark theme](./img/nanoDarkTheme1.jpg)](./img/nanoDarkTheme1.jpg)
109+
[![Nano dark theme](./img/nanoDarkTheme2.jpg)](./img/nanoDarkTheme2.jpg)
110+
111+
To use the Nano theme, import the `nanoLightTheme` and `nanoDarkTheme` objects, and pass them to the `<Admin>` component:
112+
113+
```jsx
114+
import { Admin, nanoLightTheme, nanoDarkTheme } from 'react-admin';
115+
import { dataProvider } from './dataProvider';
116+
117+
export const App = () => (
118+
<Admin
119+
dataProvider={dataProvider}
120+
theme={nanoLightTheme}
121+
darkTheme={nanoDarkTheme}
122+
>
123+
// ...
124+
</Admin>
125+
);
126+
```
127+
128+
You must also import the Onest font in your `index.html` file:
129+
130+
```html
131+
<link href="https://fonts.googleapis.com/css2?family=Onest:wght@300;400;500;700&display=swap" rel="stylesheet">
132+
```
133+
134+
### Radiant
135+
136+
A theme emphasizing clarity and ease of use. It uses generous margins, outlined inputs and buttons, no uppercase, and an acid color palette.
137+
138+
[![Radiant light theme](./img/radiantLightTheme1.jpg)](./img/radiantLightTheme1.jpg)
139+
[![Radiant light theme](./img/radiantLightTheme2.jpg)](./img/radiantLightTheme2.jpg)
140+
[![Radiant dark theme](./img/radiantDarkTheme1.jpg)](./img/radiantDarkTheme1.jpg)
141+
[![Radiant dark theme](./img/radiantDarkTheme2.jpg)](./img/radiantDarkTheme2.jpg)
142+
143+
To use the Radiant theme, import the `radiantLightTheme` and `radiantDarkTheme` objects, and pass them to the `<Admin>` component:
144+
145+
```jsx
146+
import { Admin, radiantLightTheme, radiantDarkTheme } from 'react-admin';
147+
import { dataProvider } from './dataProvider';
148+
149+
export const App = () => (
150+
<Admin
151+
dataProvider={dataProvider}
152+
theme={radiantLightTheme}
153+
darkTheme={radiantDarkTheme}
154+
>
155+
// ...
156+
</Admin>
157+
);
158+
```
159+
160+
You must also import the Gabarito font in your `index.html` file:
161+
162+
```html
163+
<link href="https://fonts.googleapis.com/css2?family=Gabarito:wght@500;600;700;900&display=swap" rel="stylesheet">
164+
```
165+
166+
### House
167+
168+
A young and joyful theme. It uses rounded corners, blurry backdrop, large padding, and a bright color palette.
169+
170+
[![House light theme](./img/houseLightTheme1.jpg)](./img/houseLightTheme1.jpg)
171+
[![House light theme](./img/houseLightTheme2.jpg)](./img/houseLightTheme2.jpg)
172+
[![House dark theme](./img/houseDarkTheme1.jpg)](./img/houseDarkTheme1.jpg)
173+
[![House dark theme](./img/houseDarkTheme2.jpg)](./img/houseDarkTheme2.jpg)
174+
175+
To use the House theme, import the `houseLightTheme` and `houseDarkTheme` objects, and pass them to the `<Admin>` component:
176+
177+
```jsx
178+
import { Admin, houseLightTheme, houseDarkTheme } from 'react-admin';
179+
import { dataProvider } from './dataProvider';
180+
181+
export const App = () => (
182+
<Admin
183+
dataProvider={dataProvider}
184+
theme={houseLightTheme}
185+
darkTheme={houseDarkTheme}
186+
>
187+
// ...
188+
</Admin>
189+
);
190+
```
191+
192+
You must also import the Open Sans font in your `index.html` file:
193+
194+
```html
195+
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;500;600;700&display=swap" rel="stylesheet">
196+
```
197+
198+
## Changing the Theme Programmatically
199+
200+
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).
201+
202+
```jsx
203+
import { defaultTheme, useTheme } from 'react-admin';
204+
import { Button } from '@mui/material';
205+
206+
const ThemeToggler = () => {
207+
const [theme, setTheme] = useTheme();
208+
209+
return (
210+
<Button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
211+
{theme === 'dark' ? 'Switch to light theme' : 'Switch to dark theme'}
212+
</Button>
213+
);
214+
}
215+
```
216+
46217
## Theming Individual Components
47218

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

136-
## Using A Dark Theme
137-
138-
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:
139-
140-
```jsx
141-
import { darkTheme } from 'react-admin';
142-
143-
const App = () => (
144-
<Admin theme={darkTheme} dataProvider={...}>
145-
// ...
146-
</Admin>
147-
);
148-
```
149-
150-
![Dark theme](./img/dark-theme.png)
151-
152-
Alternatively, you can create a custom theme object with a `mode: 'dark'` palette:
153-
154-
```jsx
155-
import { defaultTheme } from 'react-admin';
156-
157-
const darkTheme = {
158-
...defaultTheme,
159-
palette: { mode: 'dark' }
160-
};
161-
162-
const App = () => (
163-
<Admin theme={darkTheme} dataProvider={...}>
164-
// ...
165-
</Admin>
166-
);
167-
```
168-
169-
## Letting Users Choose The Theme
170-
171-
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.
172-
173-
<video controls autoplay playsinline muted loop>
174-
<source src="./img/ToggleThemeButton.webm" type="video/webm"/>
175-
<source src="./img/ToggleThemeButton.mp4" type="video/mp4"/>
176-
Your browser does not support the video tag.
177-
</video>
178-
179-
180-
React-admin's `<Admin>` component accepts a `darkTheme` prop in addition to the `theme` prop.
181-
182-
```jsx
183-
import { Admin, defaultTheme } from 'react-admin';
184-
185-
const lightTheme = defaultTheme;
186-
const darkTheme = { ...defaultTheme, palette: { mode: 'dark' } };
187-
188-
const App = () => (
189-
<Admin
190-
dataProvider={...}
191-
theme={lightTheme}
192-
darkTheme={darkTheme}
193-
>
194-
// ...
195-
</Admin>
196-
);
197-
```
198-
199-
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.
200-
201-
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.
202-
203-
## Changing the Theme Programmatically
204-
205-
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).
206-
207-
```jsx
208-
import { defaultTheme, useTheme } from 'react-admin';
209-
import { Button } from '@mui/material';
210-
211-
const ThemeToggler = () => {
212-
const [theme, setTheme] = useTheme();
213-
214-
return (
215-
<Button onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}>
216-
{theme === 'dark' ? 'Switch to light theme' : 'Switch to dark theme'}
217-
</Button>
218-
);
219-
}
220-
```
221-
222307
## Customizing The Sidebar Width
223308

224309
You can specify the `Sidebar` width by setting the `width` and `closedWidth` properties on your custom Material UI theme:

docs/Features.md

+30-3
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,31 @@ Check the following components for details:
12571257

12581258
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.
12591259

1260-
For instance, you can use react-admin to build a [Music Player](https://demo.navidrome.org/app/):
1260+
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.
1261+
1262+
<video controls autoplay playsinline muted loop>
1263+
<source src="./img/demo-themes.mp4" type="video/mp4"/>
1264+
Your browser does not support the video tag.
1265+
</video>
1266+
1267+
To use a custom theme, pass a theme object to the `<Admin>` [`theme`](./Admin.md#theme) and [`darkTheme`](./Admin.md#darktheme) props:
1268+
1269+
```jsx
1270+
import { Admin, nanoLightTheme, nanoDarkTheme } from 'react-admin';
1271+
import { dataProvider } from './dataProvider';
1272+
1273+
export const App = () => (
1274+
<Admin
1275+
dataProvider={dataProvider}
1276+
theme={nanoLightTheme}
1277+
darkTheme={nanoDarkTheme}
1278+
>
1279+
// ...
1280+
</Admin>
1281+
);
1282+
```
1283+
1284+
Theming is so powerful that you can even use react-admin to build a [Music Player](https://demo.navidrome.org/app/):
12611285

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

@@ -1357,9 +1381,12 @@ const App = () => (
13571381

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

1384+
- [Introduction to Theming](./Theming.md)
1385+
- [Page Layouts](./Theming.md#customizing-the-page-layout)
13601386
- [The `sx` prop](./SX.md)
1361-
- [App-wide component overrides](./AppTheme.md#theming-individual-components)
1362-
- [Writing a custom theme](./AppTheme.md)
1387+
- [Built-In Themes](./AppTheme.md#built-in-themes)
1388+
- [App-wide theming](./AppTheme.md#theming-individual-components)
1389+
- [Helper Components For Layouts](./BoxStackGrid.md)
13631390
- [`<ToggleThemeButton>`](./ToggleThemeButton.md)
13641391
- [`useTheme`](./useTheme.md)
13651392
- [`useMediaQuery`](./useMediaQuery.md)

docs/Theming.md

+7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ const App = () => (
119119
);
120120
```
121121

122+
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.
123+
124+
<video controls autoplay playsinline muted loop>
125+
<source src="./img/demo-themes.mp4" type="video/mp4"/>
126+
Your browser does not support the video tag.
127+
</video>
128+
122129
The application theme lets you customize color, typography, spacing, and component defaults. Check the [dedicated Application Theme chapter](./AppTheme.md) for more information.
123130

124131
## Customizing The Page Layout

docs/img/defaultDarkTheme1.jpg

44.7 KB
Loading

docs/img/defaultDarkTheme2.jpg

81 KB
Loading

docs/img/defaultLightTheme1.jpg

44.8 KB
Loading

docs/img/defaultLightTheme2.jpg

81 KB
Loading

docs/img/demo-themes.mp4

679 KB
Binary file not shown.

docs/img/houseDarkTheme1.jpg

46.4 KB
Loading

docs/img/houseDarkTheme2.jpg

70.8 KB
Loading

docs/img/houseLightTheme1.jpg

48.9 KB
Loading

docs/img/houseLightTheme2.jpg

75.4 KB
Loading

docs/img/nanoDarkTheme1.jpg

35.7 KB
Loading

docs/img/nanoDarkTheme2.jpg

63.7 KB
Loading

docs/img/nanoLightTheme1.jpg

36.1 KB
Loading

docs/img/nanoLightTheme2.jpg

66.9 KB
Loading

docs/img/radiantDarkTheme1.jpg

49.6 KB
Loading

docs/img/radiantDarkTheme2.jpg

81.8 KB
Loading

docs/img/radiantLightTheme1.jpg

46.2 KB
Loading

docs/img/radiantLightTheme2.jpg

75.3 KB
Loading

0 commit comments

Comments
 (0)