Skip to content

Commit

Permalink
feat(preset-default): preset theme package
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaSimonePorceddu committed Aug 1, 2021
1 parent c72670a commit 7a66269
Show file tree
Hide file tree
Showing 33 changed files with 441 additions and 142 deletions.
1 change: 1 addition & 0 deletions apps/web-sandbox/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@morfeo/react": "^0.1.8",
"@morfeo/dev-tools": "^0.1.8",
"@morfeo/styled-components-web": "^0.1.8",
"@morfeo/preset-default": "^0.1.8",
"@testing-library/jest-dom": "^5.12.0",
"@testing-library/react": "^11.2.6",
"@testing-library/user-event": "^12.8.3",
Expand Down
6 changes: 3 additions & 3 deletions apps/web-sandbox/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ThemeProvider } from '@morfeo/styled-components-web';
import { theme, Component, Variant, useStyles } from '@morfeo/react';
import { darkTheme, lightTheme } from '@morfeo/preset-default';
import { Box, Button, Typography, ThemeToggle } from './components';
import { darkTheme, lightTheme } from './theme';

function getStyle<C extends Component = Component>(
component: C,
Expand All @@ -24,13 +24,13 @@ function getStyle<C extends Component = Component>(
function App() {
const { containerStyle, blockStyle, codeStyle } = useStyles({
containerStyle: {
bg: 'secondary',
bg: 'background',
width: '100%' as any,
display: 'flex',
minHeight: '100vh' as any,
alignItems: 'center',
justifyContent: 'space-evenly',
transition: 'light',
transition: 'slow',
pt: 's',
pb: 's',
},
Expand Down
13 changes: 9 additions & 4 deletions apps/web-sandbox/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ import { theme, resetCss, loadFont } from '@morfeo/react';
import ReactDOM from 'react-dom';
import App from './App';
import reportWebVitals from './reportWebVitals';
import { lightTheme } from './theme';
import { enableMorfeoDevTool } from '@morfeo/dev-tools';
import { lightTheme } from '@morfeo/preset-default';
import { lightTheme as localTheme } from './theme';


enableMorfeoDevTool();
resetCss();

theme.set(lightTheme);
theme.set(localTheme as any)

loadFont({
importFontFace: true,
Expand All @@ -14,9 +22,6 @@ loadFont({
name: 'regular',
family: 'Roboto',
})
enableMorfeoDevTool();
resetCss();
theme.set(lightTheme as any);

ReactDOM.render(
<React.StrictMode>
Expand Down
158 changes: 30 additions & 128 deletions apps/web-sandbox/src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,105 +1,4 @@
export const gradients = {
primary: {
start: 0,
angle: 90,
end: 100,
colors: ['success', 'accent'],
kind: 'linear',
},
secondary: {
start: 0,
end: 100,
angle: 0,
colors: ['accent', 'success'],
kind: 'linear',
},
loading: {
start: 0,
end: 100,
angle: 90,
colors: ['transparent', 'grey', 'transparent'],
kind: 'linear',
},
};

export const lightTheme = {
colors: {
grey: '#bdc3c7',
primary: 'white',
danger: '#e74c3c',
secondary: 'black',
success: '#2ecc71',
accent: '#3498db',
warning: '#f39c12',
transparent: 'transparent',
},
fonts: {
regular: 'Roboto',
},
gradients,
radii: {
m: '10px',
round: '50%',
},
spacings: {
s: '40px',
m: '100px',
},
lineHeights: {
s: 1.7,
},
letterSpacings: {
s: 1.6,
},
fontSizes: {
s: '14px',
},
sizes: {
s: '10px',
m: '100px',
xl: '200px',
},
borderWidths: {
s: '2px',
},
shadows: {
none: {
color: 'transparent',
offset: { width: 0, height: 0 },
opacity: 0,
elevation: 0,
},
soft: {
color: 'accent',
offset: { width: 0, height: 2 },
opacity: 0.2,
radius: 4,
elevation: 2,
},
medium: {
color: 'black',
offset: { width: 0, height: 3 },
opacity: 0.3,
radius: 4,
elevation: 3,
},
strong: {
color: 'black',
offset: { width: 0, height: 4 },
opacity: 0.4,
radius: 4,
elevation: 4,
},
},
breakpoints: {
xs: '300px',
sm: '600px',
md: '900px',
lg: '1300px',
},
transitions: {
light: 'all 0.5s',
},
components: {
Box: {
tag: 'div',
Expand All @@ -108,20 +7,19 @@ export const lightTheme = {
Button: {
tag: 'button',
style: {
transition: 'light',
height: 'm',
width: 'm',
transition: 'slow',
height: 'xxl',
width: 'xxl',
bg: {
md: 'danger',
md: 'primary',
lg: 'primary',
},
color: 'secondary',
color: 'white',
borderRadius: 'm',
borderWidth: 's',
borderStyle: 'solid',
borderColor: 'primary',
'&:hover': {
gradient: 'secondary',
bg: 'transparent',
color: 'primary',
},
},
Expand All @@ -135,53 +33,57 @@ export const lightTheme = {
'aria-label': 'primary button',
},
style: {
bg: 'secondary',
borderColor: 'primary',
color: 'primary',
width: '200px',
bg: 'primary',
color: 'white',
'&:hover': {
bg: 'primary',
color: 'secondary',
bg: 'transparent',
color: 'primary',
},
},
},
round: {
style: { borderRadius: 'round' },
style: {
bg: 'secondary',
height: '150px',
width: '150px',
borderRadius: 'round',
borderColor: 'secondary',
'&:hover': {
bg: 'transparent',
color: 'secondary',
},
},
},
},
},
Typography: {
tag: 'p',
style: {
fontFamily: 'regular',
fontSize: 's',
lineHeight: 's',
letterSpacing: 's',
fontSize: 'm',
lineHeight: 'm',
letterSpacing: 'm',
color: 'textColor',
},
variants: {
h1: {
tag: 'h1',
style: { color: 'red' },
style: { color: 'headTextColor' },
},
h2: {
tag: 'h1',
style: { color: 'green' },
style: { color: 'headTextColor' },
},
h3: {
tag: 'h3',
style: { color: 'blue' },
style: { color: 'headTextColor' },
},
code: {
tag: 'pre',
style: { color: 'primary' },
style: { color: 'textColor' },
},
},
},
},
};

export const darkTheme = {
colors: {
primary: 'black',
secondary: 'white',
},
} as any;
2 changes: 1 addition & 1 deletion packages/core/src/theme/createTheme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export function createTheme() {

const breakPointsKey = Object.keys(breakPoints);
breakPointsKey.forEach(bp => {
mediaQuery = mediaQuery.replace(`{{${bp}}}`, breakPoints[bp]);
mediaQuery = (mediaQuery as string).replace(`{{${bp}}}`, breakPoints[bp]);
});

return mediaQuery;
Expand Down
25 changes: 25 additions & 0 deletions packages/preset-default/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

The MIT License (MIT)

Copyright (c) 2021 Mauro Erta.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
42 changes: 42 additions & 0 deletions packages/preset-default/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"name": "@morfeo/preset-default",
"author": {
"name": "Andrea Simone Porceddu",
"email": "mauro@vlkstudio.com"
},
"private": false,
"version": "0.1.8",
"license": "MIT",
"main": "build/index.js",
"module": "build/index.js",
"types": "build/index",
"typings": "build/index",
"keywords": [
"design",
"system",
"morfeo",
"morfeo-js",
"react"
],
"scripts": {
"build": "rimraf build && tsc",
"watch": "tsc -w"
},
"dependencies": {
"@morfeo/spec": "^0.1.6"
},
"publishConfig": {
"access": "public"
},
"files": [
"build"
],
"repository": {
"type": "git",
"url": "https://github.com/VLK-STUDIO/morfeo/tree/main/packages/preset-default"
},
"homepage": "https://morfeo.dev",
"bugs": {
"url": "https://github.com/VLK-STUDIO/morfeo/issues"
}
}
38 changes: 38 additions & 0 deletions packages/preset-default/src/base/baseTheme.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Theme } from '@morfeo/spec';
import { borderStyles } from './borderStyles';
import { borderWidths } from './borderWidths';
import { borders } from './borders';
import { breakpoints } from './breakpoints';
import { baseColors } from './colors';
import { fontSizes } from './fontSizes';
import { fontWeights } from './fontWeights';
import { gradients } from './gradients';
import { letterSpacings } from './letterSpacings';
import { lineHeights } from './lineHeights';
import { opacities } from './opacities';
import { radii } from './radii';
import { shadows } from './shadows';
import { sizes } from './sizes';
import { spacings } from './spacings';
import { transitions } from './transitions';
import { zIndices } from './zIndices';

export const baseTheme: Omit<Theme, 'components' | 'fonts' | 'colors'> = {
borderStyles,
borderWidths,
borders,
breakpoints,
fontSizes,
fontWeights,
gradients,
letterSpacings,
lineHeights,
opacities,
radii,
shadows,
sizes,
spacings,
transitions,
zIndices,
mediaQueries: {},
};
Loading

0 comments on commit 7a66269

Please sign in to comment.