Skip to content

Commit 137bab4

Browse files
docs: document theme prop for React SDK components (#698)
Co-authored-by: mintlify[bot] <109931778+mintlify[bot]@users.noreply.github.com>
1 parent 5e1762b commit 137bab4

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

references/react-sdk.mdx

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ type DashboardProps = {
101101
token: string | Promise<string>; // JWT (can be async)
102102

103103
// Optional
104+
theme?: 'light' | 'dark'; // Force light or dark color scheme
104105
styles?: {
105106
backgroundColor?: string; // Background color or 'transparent'
106107
fontFamily?: string; // Font family for all text
@@ -200,6 +201,7 @@ type ChartProps = {
200201
token: string | Promise<string>; // JWT with type: 'chart'
201202

202203
// Optional
204+
theme?: 'light' | 'dark'; // Force light or dark color scheme
203205
styles?: {
204206
backgroundColor?: string; // Background color or 'transparent'
205207
fontFamily?: string; // Font family for all text
@@ -278,6 +280,7 @@ type ExploreProps = {
278280
token: string | Promise<string>; // JWT with canExplore: true
279281

280282
// Optional
283+
theme?: 'light' | 'dark'; // Force light or dark color scheme
281284
styles?: {
282285
backgroundColor?: string; // Background color or 'transparent'
283286
fontFamily?: string; // Font family for all text
@@ -465,6 +468,60 @@ Sets the background for the embedded content. Can be any color value or `'transp
465468
/>
466469
```
467470

471+
## Light and dark mode
472+
473+
Use the `theme` prop to render embedded content in either `'light'` or `'dark'` mode. This is typically driven by the host application's own theme state, so the embedded dashboard, chart, or explore matches the surrounding UI.
474+
475+
```tsx
476+
<Lightdash.Dashboard
477+
instanceUrl={lightdashUrl}
478+
token={lightdashToken}
479+
theme="dark"
480+
/>
481+
```
482+
483+
The `theme` prop is supported on `Lightdash.Dashboard`, `Lightdash.Chart`, and `Lightdash.Explore`.
484+
485+
<Info>
486+
When `theme` is set, the SDK forces the Mantine color scheme and ignores any user-toggled preference stored in the embed. Omit the prop to let the embed use its default (light) color scheme.
487+
</Info>
488+
489+
### Syncing with your app's theme
490+
491+
Pass your app's current theme value directly to the SDK so the embed re-renders when it changes:
492+
493+
```tsx
494+
import Lightdash from '@lightdash/sdk';
495+
import { useState } from 'react';
496+
497+
function EmbeddedDashboard() {
498+
const [theme, setTheme] = useState<'light' | 'dark'>('light');
499+
500+
return (
501+
<Lightdash.Dashboard
502+
instanceUrl={lightdashUrl}
503+
token={lightdashToken}
504+
theme={theme}
505+
/>
506+
);
507+
}
508+
```
509+
510+
### Combining with `styles.backgroundColor`
511+
512+
When `theme` is set, the embed uses the matching Mantine body background by default. If you also pass `styles.backgroundColor`, your value takes precedence:
513+
514+
```tsx
515+
<Lightdash.Dashboard
516+
instanceUrl={lightdashUrl}
517+
token={lightdashToken}
518+
theme="dark"
519+
styles={{
520+
backgroundColor: '#0b0b0f', // Overrides the default dark background
521+
}}
522+
/>
523+
```
524+
468525
## Color palettes
469526

470527
You can customize the appearance of embedded dashboards using color palettes. Define multiple color palettes in your organization settings, then apply them to embedded dashboards using the `paletteUuid` prop.

0 commit comments

Comments
 (0)