Skip to content

tqwewe/emotion-solid

main
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Emotion Solid

Emotion JS support for Solid JS.

Installation

npm i emotion-solid
# or
yarn add emotion-solid

Usage

import { styled } from 'emotion-solid'

export type ButtonProps = {
  block?: boolean
}

const StyledButton = styled('button')<ButtonProps>(
  {
    display: 'inline-block',
    padding: '8px 6px',
    borderRadius: 8,
  },
  ({ block }) =>
    block && {
      display: 'block',
      width: '100%',
    }
)

const Button: Component<ButtonProps> = (props) => {
  return <StyledButton {...props}>{props.children}</StyledButton>
}

export default Button
import { render } from 'solid-js/web'
import Button from './Button'

function App() {
  return <Button block>Click Me</Button>
}

render(() => <App />, document.getElementById('app'))

Themes

You can pass theme to all your styled components with ThemeProvider.

import type { Component } from 'solid-js/web'
import { ThemeProvider, styled } from 'emotion-solid'

const StyledButton = styled('button')(
  ({ theme }) =>
    {
      backgroundColor: theme.color,
      width: '100%',
    }
)

const App: Component = () => {
  const [theme, setTheme] = createSignal({color: 'green'});
  return <ThemeProvider theme={theme}><Button>Click Me</Button></ThemeProvider>
}

Note that you have to pass accessor function that returns the theme object instead of just giving the theme object itself.

Contributing πŸ™Œ

Contributions are more than welcome. If you see any changes fit, go ahead and open an issue or PR.


Any support is a huge motivation, thank you very much!

Buy Me A Coffee

About

Emotion JS support for Solid JS projects

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published