1.0.32 • Published 2 years ago

material-ui-theme-state v1.0.32

Weekly downloads
127
License
ISC
Repository
github
Last release
2 years ago

README.md

a way for change material-ui theme

install

yarn add material-ui-theme-state
import { useTheme, createTheme } from 'material-ui-theme-state/lib/global';
import { useTheme, createTheme } from 'material-ui-theme-state/esm/global';

or

import createMuiThemeState, { IThemeExtra } from 'material-ui-theme-state';
const { useTheme, createTheme } = createMuiThemeState();

import React, { useState, Dispatch, SetStateAction, useEffect, ReactNode } from "react";
import useMediaQuery from '@material-ui/core/useMediaQuery';
import { MuiThemeProvider, Theme } from '@material-ui/core/styles';
import { ThemeOptions } from '@material-ui/core/styles/createMuiTheme';
import { Button } from '@material-ui/core';
import { ButtonTypeMap } from '@material-ui/core/Button/Button';
import createMuiThemeState, { IThemeExtra } from 'material-ui-theme-state';

export function prefersLightMode()
{
	try
	{
		return useMediaQuery('(prefers-color-scheme: light)');
	}
	catch (e)
	{

	}
}

const { useTheme, createTheme } = createMuiThemeState();

export function ButtonTheme(props: ButtonTypeMap["props"] & {
	children: string | ReactNode,
})
{
	const { theme, setTheme } = useTheme();

	let click = () =>
	{
		setTheme(theme => {

				theme.palette.type = (theme.palette.type !== 'light') ? 'light' : 'dark';

			return theme;
		}, true)
	};

	return (<Button variant="contained" color="secondary" {...props} onClick={click}/>)
}

export default function (props)
{
	let bool = prefersLightMode();
	let theme: ThemeOptions | Theme;
	let setTheme: IThemeExtra["setTheme"];

	([theme, setTheme] = useState({
		palette: {
			type: bool ? 'light': 'dark',
		},
		//direction: 'rtl'
	}));
	
	const muiTheme = createTheme(theme, {
		setTheme,
	}).theme;

	return (<MuiThemeProvider theme={muiTheme}>{props.children}</MuiThemeProvider>)
}
1.0.32

2 years ago

1.0.31

2 years ago

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.19

5 years ago

1.0.22

5 years ago

1.0.18

5 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.11

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago