diff --git a/components/templates/styleguide/_styled_tag4.ts b/components/templates/styleguide/_styled_tag4.ts index b6a03811..063ae8ae 100644 --- a/components/templates/styleguide/_styled_tag4.ts +++ b/components/templates/styleguide/_styled_tag4.ts @@ -1,3 +1,3 @@ import styled from 'styled-components' -export const StyledTag4 = styled.div`border: 4px solid black;` +export const StyledTag4 = styled.div`border: 4px solid ${({ theme }) => theme.colors.primary};` diff --git a/components/templates/styleguide/index.tsx b/components/templates/styleguide/index.tsx index 69ca4ed6..64c06786 100644 --- a/components/templates/styleguide/index.tsx +++ b/components/templates/styleguide/index.tsx @@ -2,6 +2,7 @@ import { Index2 } from './index2' import { FooBar, FooBarTag4 } from './_foo_bar' import styled, { css, keyframes, Keyframes } from 'styled-components' import { StyledTag4 } from './_styled_tag4' +import { useSetAppState, useAppState } from '@/hooks/app_state' const hover = css` &:hover { @@ -17,6 +18,8 @@ const prop = css` ` const Styleguide = () => { + const setAppState = useSetAppState() + console.log(useAppState()) return ( <> @@ -31,6 +34,12 @@ const Styleguide = () => { Let's bounce. Let's shake. This is Styled.Tag4 + + ) } @@ -90,4 +99,5 @@ const StyledTag3 = styled.div<{ animation: Keyframes }>` background-color: linen; } animation: ${({ animation }) => animation} 0.2s infinite ease-in-out alternate; + content: "${({ theme }) => theme.colors.primary}"; ` diff --git a/contexts/app_state.tsx b/contexts/app_state.tsx new file mode 100644 index 00000000..ca3b4d88 --- /dev/null +++ b/contexts/app_state.tsx @@ -0,0 +1,41 @@ +import { createContext, Dispatch, SetStateAction, useState } from 'react' +import { ThemeProvider } from 'styled-components' +import { lightTheme, darkTheme } from '@/styles/app_theme' + +interface AppState { + // TODO: Add null + themeName: 'light' | 'dark' +} + +const initialAppState: AppState = { + themeName: 'light' +} + +export const AppStateContext = createContext(initialAppState) +export const SetAppStateContext = createContext< +Dispatch> +>(() => {}) + +export const AppStateProvider = (props: { + initialAppState?: AppState + children: React.ReactNode +}) => { + const [appState, setAppState] = useState( + props.initialAppState ?? initialAppState + ) + return ( + + + + { value => ( + + { props.children } + + ) } + + + + ) +} diff --git a/hooks/app_state.tsx b/hooks/app_state.tsx new file mode 100644 index 00000000..8e5251d7 --- /dev/null +++ b/hooks/app_state.tsx @@ -0,0 +1,10 @@ +import { useContext } from 'react' +import { AppStateContext, SetAppStateContext } from '@/contexts/app_state' + +export const useAppState = () => { + return useContext(AppStateContext) +} + +export const useSetAppState = () => { + return useContext(SetAppStateContext) +} diff --git a/pages/_app.tsx b/pages/_app.tsx index 6b34fb46..6b0e8ea9 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,26 +1,23 @@ import { AppProps } from 'next/app' import Router from 'next/router' -import { ThemeProvider, DefaultTheme } from 'styled-components' import * as gtag from '@/utils/gtag' import Styles from '@/styles' +import { AppStateProvider } from '@/contexts/app_state' +import { useAppState } from '@/hooks/app_state' import '@/styles/normalize.scss' import '@/styles/highlightjs.scss' import '@/styles/fonts.scss' Router.events.on('routeChangeComplete', url => gtag.pageview(url)) -const theme: DefaultTheme = { - colors: { - primary: 'skyblue' - } -} - export default function App ({ Component, pageProps }: AppProps) { + const appState = useAppState() + return ( - + - + ) } diff --git a/styles/app_theme.ts b/styles/app_theme.ts new file mode 100644 index 00000000..868526b0 --- /dev/null +++ b/styles/app_theme.ts @@ -0,0 +1,46 @@ +export interface AppTheme { + colors: { + primary: string + } + sizes: { + font: { + XS: number + SM: number + MD: number + LG: number + XL: number + } + width: { + CONTENT: number + } + } +} + +export const lightTheme: AppTheme = { + colors: { + primary: 'skyblue' + }, + sizes: { + font: { + XS: 12, + SM: 14, + MD: 16, + LG: 18, + XL: 20 + }, + width: { + CONTENT: 1000 + } + } +} as const + +export const darkTheme: AppTheme = { + ...lightTheme, + colors: { + primary: 'pink' + } +} as const + +declare module 'styled-components' { + interface DefaultTheme extends AppTheme {} +} diff --git a/types/styled.d.ts b/types/styled.d.ts index 772f4342..30b75d6d 100644 --- a/types/styled.d.ts +++ b/types/styled.d.ts @@ -1,13 +1,2 @@ -import 'styled-components' -import { fiboMap } from '@/styles/abstractions/funcs' - -declare module 'styled-components' { - export interface DefaultTheme { - colors: { - primary: string - } - } -} - export type TFiboSizeName = 'xl6'|'xl5'|'xl4'|'xl3'|'xl2'|'xl'|'lg'|'md'|'sm'|'xs'|'xs2'|'xs3'|'xs4'|'xs5'|'xs6' export type TFiboUnit = 'px'|'rem'|'alpha'