Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/wellguimaraes/xtheme

Experimental way to better deal with theming with React and styled components.
https://github.com/wellguimaraes/xtheme

Last synced: 12 days ago
JSON representation

Experimental way to better deal with theming with React and styled components.

Awesome Lists containing this project

README

        

# X-Theme
**Experimental** way to better deal with theming with React and styled components.

## Install it
`yarn add xtheme`

## Use it
```typescript jsx
import { createVariableSet, createGlobalTheme } from 'xtheme'

// Create types for the variable sets
// that you might have on your theme
type IColors = 'primaryDark' | 'primary' | 'primaryLight'
type IFontFamilies = 'sansSerif' | 'serif'
type IFontSize = 'XS' | 'S' | 'M' | 'L' | 'XL'

// Create the shape or your theme
const globalTheme = {
color: createVariableSet(),
fontFamily: createVariableSet(),
fontSize: createVariableSet(),
}

// Create a global theme component
// by defining the values for the theme variables
const AppGlobalTheme = createGlobalTheme([
// Colors
[globalTheme.color.primaryLight, '#27a0ff'],
[globalTheme.color.primary, '#0088ee'],
[globalTheme.color.primaryDark, '#0061ac'],

// Font families
[globalTheme.fontFamily.sansSerif, 'helvetica, roboto, arial, sans-serif'],
[globalTheme.fontFamily.serif, 'times new roman'],

// Font sizes
[globalTheme.fontSize.XS, units.px(11)],
[globalTheme.fontSize.S, units.px(13)],
[globalTheme.fontSize.M, units.px(16)],
[globalTheme.fontSize.L, units.px(19)],
[globalTheme.fontSize.XL, units.px(23)],
])

// Create a styled component and use the theme variables
const Title = styled.h1`
font-family: ${globalTheme.fontFamily.serif};
font-size: ${globalTheme.fontSize.XL};
`

const App = () => {
return (



...

Hello world!
...


)
}
```

## License
MIT License