1.1.4 • Published 6 years ago

oresome-material-ui v1.1.4

Weekly downloads
31
License
MIT
Repository
-
Last release
6 years ago

oresome-material-ui

Travis npm package Coveralls

Click here for demo

Material-UI web site

Installation

// with npm
npm install @material-ui/core @material-ui/icons oresome-material-ui

// with yarn
yarn add @material-ui/core @material-ui/icons oresome-material-ui

Usage

index.js

import React, {Component} from 'react';
import {render} from 'react-dom';

import {BrowserRouter as Router} from 'react-router-dom';
import App from './App';

const RootApp = (
  <Router>
    <App />
  </Router>
);

render(RootApp, document.querySelector('#app'))

App.js

import React, { useState } from 'react'
import { MuiThemeProvider, CssBaseline, createMuiTheme, Divider } from '@material-ui/core';
import Routes, { navigationRoutes } from './Routes';
import { Provider as AppProvider, defaultContext } from './AppProvider';

import { MainLayout, MenuItems, TopBarActions, Colours } from '../../src';
import SettingsComponentContent from './components/SettingsComponentContent';

import './App.css';

const Logo = props => (
  <div>Logo</div>
);

const App = (props) => {
  const [state, setState] = useState(defaultContext);

  const handleConfigChange = (name, value) => {
    setState({
      ...state,
      [name]: value
    });
  }

  const { colour, type, allowNightMode, allowThemeColour, allowSideBar } = state;

  const theme = createMuiTheme({
    palette: { ...Colours[colour], type: type },
    typography: {
      useNextVariants: true
    }
  });

  return (
    <AppProvider
      value={{
        ...state,
        handleConfigChange: handleConfigChange
      }}>
      <MuiThemeProvider theme={theme}>
        <CssBaseline />
        <MainLayout
          menuItems={(p) => <MenuItems navigationRoutes={navigationRoutes} {...p} />}
          topBarActions={TopBarActions}
          logo={Logo}
          title="App Title"
          updateTheme={handleConfigChange}
          colour={colour}
          nightModeDisabled={!allowNightMode}
          themeColourDisabled={!allowThemeColour}
          sideBarDisabled={!allowSideBar}
          settingsPanelContentStart={<div>Content at start of panel <Divider style={{ marginTop: '10px', marginBottom: '10px' }} /></div>}
          settingsPanelContentEnd={(
            <SettingsComponentContent
              onToggleThemeColour={() => handleConfigChange('allowThemeColour', !allowThemeColour)}
              onToggleAllowNightMode={() => handleConfigChange('allowNightMode', !allowNightMode)}
              onToggleSideBar={() => handleConfigChange('allowSideBar', !allowSideBar)}
            />
          )}
        >
          <Routes />
        </MainLayout>
      </MuiThemeProvider>
    </AppProvider>
  )
};

export default App;

      

AppProvider.js

import { createContext } from 'react';

export const defaultContext = {
  colour: 'orange',
  type: 'light',
  handleConfigChange: () => { },
  allowNightMode: true,
  allowThemeColour: true,
  allowSideBar: true
}

export const { Provider, Consumer } = createContext(defaultContext);

Routes.js

import React from 'react';
import { Route, Switch } from 'react-router-dom';
import { Dashboard, Assignment, List } from '@material-ui/icons';

import DashboardPage from './containers/Dashboard';
import RegisterPage from './containers/Register';
import TasksPage from './containers/Tasks';

export const navigationRoutes = [
  {
    exact: true,
    path: '/',
    name: 'Dashboard',
    icon: Dashboard,
    component: DashboardPage
  },
  {
    path: '/register',
    name: 'Register',
    description: 'Register',
    icon: List,
    component: RegisterPage
  },
  {
    path: '/tasks/:tabId?',
    name: 'Tasks',
    description: 'Task Description',
    icon: Assignment,
    component: TasksPage
  }
];


export default () => (
  <Switch>
    {navigationRoutes.map((r, i) => <Route key={i} exact={r.exact} path={r.path} component={r.component} />)}
  </Switch>
);
1.1.4

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.10

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago