darkMode context and button implemented
This commit is contained in:
parent
c51945b6c6
commit
d530d04691
5 changed files with 55 additions and 11 deletions
|
|
@ -11,6 +11,7 @@ import { locationContext } from "./contexts/locationContext";
|
||||||
import Sidebar from "./components/SidebarComponent";
|
import Sidebar from "./components/SidebarComponent";
|
||||||
import Header from "./components/HeaderComponent";
|
import Header from "./components/HeaderComponent";
|
||||||
import TabsManagerComponent from "./pages/FlowPage/components/tabsManagerComponent";
|
import TabsManagerComponent from "./pages/FlowPage/components/tabsManagerComponent";
|
||||||
|
import { darkContext } from "./contexts/darkContext";
|
||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
@ -24,6 +25,8 @@ export default function App() {
|
||||||
setIsStackedOpen(true);
|
setIsStackedOpen(true);
|
||||||
}, [location.pathname, setCurrent, setIsStackedOpen, setShowSideBar]);
|
}, [location.pathname, setCurrent, setIsStackedOpen, setShowSideBar]);
|
||||||
|
|
||||||
|
const {dark} = useContext(darkContext);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
errorData,
|
errorData,
|
||||||
errorOpen,
|
errorOpen,
|
||||||
|
|
@ -93,7 +96,7 @@ export default function App() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
//need parent component with width and height
|
//need parent component with width and height
|
||||||
<div className="h-full flex flex-col">
|
<div className={(dark ? "dark " : "") + "h-full flex flex-col"}>
|
||||||
<div className="flex grow-0 shrink basis-auto">
|
<div className="flex grow-0 shrink basis-auto">
|
||||||
<Header userNavigation={userNavigation} user={user}></Header>
|
<Header userNavigation={userNavigation} user={user}></Header>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ import { MagnifyingGlassIcon } from '@heroicons/react/20/solid'
|
||||||
import {
|
import {
|
||||||
BellIcon,
|
BellIcon,
|
||||||
MoonIcon,
|
MoonIcon,
|
||||||
|
SunIcon,
|
||||||
} from '@heroicons/react/24/outline'
|
} from '@heroicons/react/24/outline'
|
||||||
import { classNames } from '../../utils'
|
import { classNames } from '../../utils'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
|
|
@ -11,6 +12,7 @@ import Breadcrumb from '../breadcrumbComponent'
|
||||||
import { alertContext } from '../../contexts/alertContext'
|
import { alertContext } from '../../contexts/alertContext'
|
||||||
import { useLayer,Arrow } from 'react-laag'
|
import { useLayer,Arrow } from 'react-laag'
|
||||||
import AlertDropdown from '../../alerts/alertDropDown'
|
import AlertDropdown from '../../alerts/alertDropDown'
|
||||||
|
import { darkContext } from '../../contexts/darkContext'
|
||||||
|
|
||||||
export default function Header({user, userNavigation}){
|
export default function Header({user, userNavigation}){
|
||||||
const {notificationCenter, setNotificationCenter} = useContext(alertContext)
|
const {notificationCenter, setNotificationCenter} = useContext(alertContext)
|
||||||
|
|
@ -24,6 +26,7 @@ export default function Header({user, userNavigation}){
|
||||||
containerOffset: 12,
|
containerOffset: 12,
|
||||||
arrowOffset: 4,
|
arrowOffset: 4,
|
||||||
})
|
})
|
||||||
|
const {dark, setDark} = useContext(darkContext);
|
||||||
return (
|
return (
|
||||||
<header className="relative flex h-16 w-full shrink-0 items-center bg-white">
|
<header className="relative flex h-16 w-full shrink-0 items-center bg-white">
|
||||||
{/* Logo area */}
|
{/* Logo area */}
|
||||||
|
|
@ -47,7 +50,14 @@ export default function Header({user, userNavigation}){
|
||||||
</div>
|
</div>
|
||||||
<div className="ml-10 flex shrink-0 items-center space-x-10 pr-4">
|
<div className="ml-10 flex shrink-0 items-center space-x-10 pr-4">
|
||||||
<div className="flex items-center space-x-8">
|
<div className="flex items-center space-x-8">
|
||||||
<span className="inline-flex">
|
<span className="inline-flex gap-6">
|
||||||
|
<button className="text-gray-400 hover:text-gray-500 dark:text-slate-700 dark:hover:text-slate-600" onClick={()=>{setDark(!dark)}}>
|
||||||
|
{dark ?
|
||||||
|
<SunIcon className="h-6 w-6" />
|
||||||
|
:
|
||||||
|
<MoonIcon className="h-6 w-6" />
|
||||||
|
}
|
||||||
|
</button>
|
||||||
<button type="button" {...triggerProps} className="-mx-1 rounded-full bg-white p-1 text-gray-400 hover:text-gray-500 relative" onClick={()=>{setNotificationCenter(false);setIsOpen(true)}}>
|
<button type="button" {...triggerProps} className="-mx-1 rounded-full bg-white p-1 text-gray-400 hover:text-gray-500 relative" onClick={()=>{setNotificationCenter(false);setIsOpen(true)}}>
|
||||||
<span className="sr-only">View notifications</span>
|
<span className="sr-only">View notifications</span>
|
||||||
{notificationCenter&&<div className='absolute top-[2px] w-2 h-2 rounded-full bg-red-600 right-[7px]'></div>}
|
{notificationCenter&&<div className='absolute top-[2px] w-2 h-2 rounded-full bg-red-600 right-[7px]'></div>}
|
||||||
|
|
|
||||||
27
space_flow/src/contexts/darkContext.tsx
Normal file
27
space_flow/src/contexts/darkContext.tsx
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
import { createContext, useState } from "react";
|
||||||
|
|
||||||
|
type darkContextType = {
|
||||||
|
dark: {};
|
||||||
|
setDark: (newState: {}) => void;
|
||||||
|
};
|
||||||
|
|
||||||
|
const initialValue = {
|
||||||
|
dark: {},
|
||||||
|
setDark: () => {},
|
||||||
|
};
|
||||||
|
|
||||||
|
export const darkContext = createContext<darkContextType>(initialValue);
|
||||||
|
|
||||||
|
export function DarkProvider({ children }) {
|
||||||
|
const [dark, setDark] = useState(false);
|
||||||
|
return (
|
||||||
|
<darkContext.Provider
|
||||||
|
value={{
|
||||||
|
dark,
|
||||||
|
setDark,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</darkContext.Provider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { AlertProvider } from "./alertContext";
|
import { AlertProvider } from "./alertContext";
|
||||||
|
import { DarkProvider } from "./darkContext";
|
||||||
import { LocationProvider } from "./locationContext";
|
import { LocationProvider } from "./locationContext";
|
||||||
import PopUpProvider from "./popUpContext";
|
import PopUpProvider from "./popUpContext";
|
||||||
import { TabsProvider } from "./tabsContext";
|
import { TabsProvider } from "./tabsContext";
|
||||||
|
|
@ -8,15 +9,17 @@ export default function ContextWrapper({ children }) {
|
||||||
//element to wrap all context
|
//element to wrap all context
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<LocationProvider>
|
<DarkProvider>
|
||||||
<PopUpProvider>
|
<LocationProvider>
|
||||||
<TypesProvider>
|
<PopUpProvider>
|
||||||
<TabsProvider>
|
<TypesProvider>
|
||||||
<AlertProvider>{children}</AlertProvider>
|
<TabsProvider>
|
||||||
</TabsProvider>
|
<AlertProvider>{children}</AlertProvider>
|
||||||
</TypesProvider>
|
</TabsProvider>
|
||||||
</PopUpProvider>
|
</TypesProvider>
|
||||||
</LocationProvider>
|
</PopUpProvider>
|
||||||
|
</LocationProvider>
|
||||||
|
</DarkProvider>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@
|
||||||
const plugin = require('tailwindcss/plugin')
|
const plugin = require('tailwindcss/plugin')
|
||||||
module.exports = {
|
module.exports = {
|
||||||
content: ["./src/**/*.{js,ts,tsx,jsx}"],
|
content: ["./src/**/*.{js,ts,tsx,jsx}"],
|
||||||
|
darkMode: 'class',
|
||||||
important:true,
|
important:true,
|
||||||
theme: {
|
theme: {
|
||||||
extend: {},
|
extend: {},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue