diff --git a/components/templates/styleguide/index.tsx b/components/templates/styleguide/index.tsx index 97da5ae6..42e5708f 100644 --- a/components/templates/styleguide/index.tsx +++ b/components/templates/styleguide/index.tsx @@ -26,7 +26,7 @@ const Styleguide = () => { Styleguide -
This is css prop
+
This is css prop
Cool Styles With :hover. diff --git a/contexts/app_state.tsx b/contexts/app_state.tsx index 6f37dbe9..9eab81d0 100644 --- a/contexts/app_state.tsx +++ b/contexts/app_state.tsx @@ -29,6 +29,10 @@ export const AppStateProvider = (props: { const root = document.documentElement root.style.setProperty('--b-colors-text-body', theme.colors.text.body) root.style.setProperty('--b-colors-bg-content', theme.colors.bg.content) + + Object.entries(theme.space).forEach(([key, value]) => { + root.style.setProperty(`--theme-space-${key}`, value.px()) + }) }, [appState]) return ( diff --git a/pages/_app.tsx b/pages/_app.tsx index 4b6f1a7f..871ff80e 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -4,6 +4,7 @@ import * as gtag from '@/utils/gtag' import Styles from '@/styles' import { AppStateProvider } from '@/contexts/app_state' import { useAppState } from '@/hooks/app_state' +import { StyledBasicUtils } from '@/styles/basics/utils' import '@/styles/basics_normalize.scss' import '@/styles/basics_highlightjs.scss' import '@/styles/basics_fonts.scss' @@ -18,6 +19,7 @@ export default function App ({ Component, pageProps }: AppProps) { + ) diff --git a/styles/basics/utils.ts b/styles/basics/utils.ts new file mode 100644 index 00000000..4f20b5e2 --- /dev/null +++ b/styles/basics/utils.ts @@ -0,0 +1,33 @@ +import { createGlobalStyle, css } from 'styled-components' + +const prefix = 'u' + +export const StyledBasicUtils = createGlobalStyle` + ${({ theme }) => css` + ${ + Object.entries({ margin: 'm', padding: 'p' }).map(([prop, abbr]) => { + return Object.entries(theme.space).map(([size, unitize]) => { + return ` + .${prefix}-${abbr}-${size} { ${prop}: ${unitize.px()} !important; } + .${prefix}-${abbr}t-${size}, + .${prefix}-${abbr}y-${size} { + ${prop}-top: ${unitize.px()} !important; + } + .${prefix}-${abbr}r-${size}, + .${prefix}-${abbr}x-${size} { + ${prop}-right: ${unitize.px()} !important; + } + .${prefix}-${abbr}b-${size}, + .${prefix}-${abbr}y-${size} { + ${prop}-bottom: ${unitize.px()} !important; + } + .${prefix}-${abbr}l-${size}, + .${prefix}-${abbr}x-${size} { + ${prop}-left: ${unitize.px()} !important; + } + ` + }) + }) + } + `} +` diff --git a/styles/system.ts b/styles/system.ts index 56227b3a..e9dc98c4 100644 --- a/styles/system.ts +++ b/styles/system.ts @@ -27,7 +27,7 @@ export interface TPaddingProps { export type TSpaceProps = TMarginProps & TPaddingProps const getThemeValue = (theme: TTheme) => (value: TSpaceValue) => { - return value === '0' ? '0' : theme.space[value] + return value === '0' ? '0' : theme.space[value].px() } export const margin = (props: any) => {