diff --git a/apps/web-sandbox/src/App.tsx b/apps/web-sandbox/src/App.tsx index 30c45227..8e345d8a 100644 --- a/apps/web-sandbox/src/App.tsx +++ b/apps/web-sandbox/src/App.tsx @@ -1,112 +1,15 @@ -import React from 'react'; -import styled, { ThemeProvider } from 'styled-components'; -import { theme, parsers, Component } from '@morfeo/web'; -import { useTheme } from '@morfeo/hooks'; +import { useState, useCallback, FC } from 'react'; +import { ThemeProvider } from 'styled-components'; +import { theme, Component } from '@morfeo/web'; +import { useTheme, useStyles } from '@morfeo/hooks'; +import { customStyled } from './styled'; +import { darkTheme, lightTheme } from './theme'; -const lightTheme = { - colors: { - primary: 'white', - secondary: 'black', - danger: 'red', - }, - radii: { - m: '10px', - round: '50%', - }, - space: { - s: '40px', - m: '100px', - }, - sizes: { - s: '10px', - m: '100px', - xl: '200px', - }, - borderWidths: { - s: '2px', - }, - breakpoints: { - md: '900px', - lg: '1300px', - }, - transitions: { - light: 'all 0.5s', - }, - components: { - Button: { - style: { - componentTag: 'button', - transition: 'light', - height: 'm', - width: 'm', - bg: { - md: 'danger', - lg: 'primary', - }, - color: 'secondary', - borderRadius: 'm', - borderWidth: 's', - borderStyle: 'solid', - borderColor: 'primary', - '&:hover': { - bg: 'secondary', - color: 'primary', - }, - }, - variants: { - primary: { - bg: 'secondary', - borderColor: 'primary', - color: 'primary', - '&:hover': { - bg: 'primary', - color: 'secondary', - }, - }, - round: { - borderRadius: 'round', - }, - }, - }, - }, -}; - -const darkTheme = { - colors: { - primary: 'black', - secondary: 'white', - }, -}; - -theme.set(lightTheme as any); - -function customStyled(component: Component) { - const { components } = theme.get(); - const config = components[component]; - const tag = config.style.componentTag || component; - - return (props: any = {}) => { - const variant: any = props.variant as any; - const variantTag = - props.variant && config.variants - ? config.variants[variant].componentTag - : tag; - - const Component = styled(variantTag || (tag as any))( - ({ theme: styledTheme, ...style }) => { - return parsers.resolve({ - style: { ...(style as any), componentName: component }, - }); - }, - ); - - return ; - }; -} +theme.set(lightTheme); const Button = customStyled('Button'); -const StyledProvider: React.FC = ({ children }) => { +const StyledProvider: FC = ({ children }) => { const currentTheme = useTheme(); return {children}; @@ -123,15 +26,24 @@ function getStyle(component: Component, variant?: string) { } function App() { - const [light, setLight] = React.useState(true); + const [light, setLight] = useState(true); - const onClick = React.useCallback(() => { - theme.set(light ? (darkTheme as any) : (lightTheme as any)); + const onClick = useCallback(() => { + theme.set(light ? darkTheme : lightTheme); setLight(prev => !prev); }, [light]); - const containerStyle = parsers.resolve({ - style: { + const { containerStyle, blockStyle, codeStyle } = useStyles({ + containerStyle: { + bg: 'secondary', + width: '100vw' as any, + display: 'flex', + height: '100vh' as any, + alignItems: 'center', + justifyContent: 'space-evenly', + transition: 'light', + }, + blockStyle: { flex: 1, display: 'flex', flexDirection: 'column', @@ -139,36 +51,25 @@ function App() { justifyContent: 'space-evenly', height: '100%' as any, }, - }); - - const codeStyle = parsers.resolve({ - style: { color: 'primary', display: 'block', py: 's' }, + codeStyle: { + color: 'primary', + display: 'block', + py: 's', + }, }); return ( -
-
+
+
{getStyle('Button')}
-
+
{getStyle('Button', 'primary')}
-
+
{getStyle('Button', 'round')}
diff --git a/apps/web-sandbox/src/styled.tsx b/apps/web-sandbox/src/styled.tsx index ed2701d7..c416ea23 100644 --- a/apps/web-sandbox/src/styled.tsx +++ b/apps/web-sandbox/src/styled.tsx @@ -1,38 +1,30 @@ -// import React from 'react'; -// import scStyled, { StyledInterface } from 'styled-components'; -// import { Component, theme, parsers, Style, Theme } from '@morfeo/web'; - -// const customStyled = (tag: keyof StyledInterface) => { -// const callback =

({ -// theme: styledTheme, -// ...style -// }: P) => scStyled[tag](parsers.resolve({ style })); - -// const styledKeys = Object.keys(scStyled) as (keyof StyledInterface)[]; - -// for (let tag of styledKeys) { -// callback[tag] = callback(tag); -// } - -// return callback; -// }; - -// export function themeComponent(component: Component) { -// const { components } = theme.get(); -// const config = components[component]; -// const tag = config.style.componentTag || component; - -// return (props: Style = {}) => { -// const variant = props.variant; -// const variantTag = -// variant && config.variants ? config.variants[variant].componentTag : tag; - -// const Component = customStyled(variantTag || tag) as React.FC