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

Update readme for theme usage #674

Merged
merged 4 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
100 changes: 100 additions & 0 deletions login-workflow/docs/theme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Using the Theme in your Project

This guide will help you integrate and use the @brightlayer-ui/react-theme in your project.

## Setup

**Install Dependencies:**

Install with npm

```shell
npm install --save @brightlayer-ui/react-themes
```

or yarn

```shell
yarn add @brightlayer-ui/react-themes
```

# Usage

To use these themes in your application, simply wrap the app in a `ThemeProvider` and pass in the theme.:

```tsx
import React, { useEffect } from 'react';
import { ThemeProvider, StyledEngineProvider } from '@mui/material/styles';
import { App } from './App';
import CssBaseline from '@mui/material/CssBaseline';
import { blueThemes } from '@brightlayer-ui/react-themes';
import rtl from 'jss-rtl';
import { create } from 'jss';
import rtlPlugin from 'stylis-plugin-rtl';
import { CacheProvider } from '@emotion/react';
import createCache from '@emotion/cache';
import jssPreset from '@mui/styles/jssPreset';
import '@brightlayer-ui/react-themes/open-sans';

document.body.setAttribute('dir', 'rtl');
const jss = create({
plugins: [...jssPreset().plugins, rtl()],
});

export const Example = (props: any): JSX.Element => {
const dir = useSelector((store: AppStore) => store.app.direction);

const cacheRtl = createCache({
key: dir === 'rtl' ? 'cssrtl' : 'cssltr',
prepend: true,
stylisPlugins: [rtlPlugin],
});

const cacheLtr = createCache({
key: dir === 'ltr' ? 'cssltr' : 'cssrtl',
prepend: true,
stylisPlugins: dir === 'ltr' ? undefined : [rtlPlugin],
});

useEffect(() => {
document.body.dir = dir;
}, [dir]);

return(
<React.StrictMode>
<StyledEngineProvider injectFirst>
<ThemeProvider theme={{...blueThemes, direction: dir}}>
<CacheProvider value={dir === 'ltr' ? cacheLtr : cacheRtl}>
<CssBaseline />
<App />
</CacheProvider>
</ThemeProvider>
</StyledEngineProvider>
</React.StrictMode>
);
```

By Default the theme will take system's mode. To set your mode(light/dark), make use of `useColorScheme()` hook to set and use theme modes using helpers `mode` & `setMode` of `useColorScheme()`.

## Example to use useColorScheme() hook

```tsx
import { useEffect } from 'react';
import { useColorScheme } from '@mui/material/styles';

export const App = (): JSX.Element => {
const { setMode } = useColorScheme();

useEffect(() => {
setMode('light');
}, []);

return (
<>
<BrowserRouter basename={'/'}>
<AppRouter />
</BrowserRouter>
</>
);
};
```
1 change: 1 addition & 0 deletions login-workflow/example-vite/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { App } from './App';
import CssBaseline from '@mui/material/CssBaseline';
import { blueThemes } from '@brightlayer-ui/react-themes';
import { createRoot } from 'react-dom/client';
import type {} from '@mui/material/themeCssVarsAugmentation';

createRoot(document.getElementById('root')!).render(
// Enable Strict Mode for more error checking
Expand Down
1 change: 1 addition & 0 deletions login-workflow/example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { blueThemes } from '@brightlayer-ui/react-themes';
import '@brightlayer-ui/react-themes/open-sans';
import './index.css';
import { createRoot } from 'react-dom/client';
import type {} from '@mui/material/themeCssVarsAugmentation';

const container = document.getElementById('root');
const root = createRoot(container || document.createDocumentFragment());
Expand Down
Loading