All Projects β†’ cssinjs β†’ Styled Jss

cssinjs / Styled Jss

Licence: mit
Styled Components on top of JSS.

Programming Languages

javascript
184084 projects - #8 most used programming language
js
455 projects

Projects that are alternatives of or similar to Styled Jss

Prejss
Get the power of PostCSS with plugins in your JSS styles. 🎨 Just put CSS into JS and get it as JSS object.
Stars: ✭ 238 (+9.68%)
Mutual labels:  styled-components, stylesheets, jss
gloss
a powerful style system for building ui kits
Stars: ✭ 16 (-92.63%)
Mutual labels:  stylesheets, jss
tsstyled
A small, fast, and simple CSS-in-JS solution for React.
Stars: ✭ 52 (-76.04%)
Mutual labels:  styled-components, jss
jss-material-ui
A enhanced styling engine for material-ui
Stars: ✭ 15 (-93.09%)
Mutual labels:  styled-components, jss
Postjss
Use the power of PostCSS in compiling with JSS
Stars: ✭ 40 (-81.57%)
Mutual labels:  styled-components, jss
Css In Js Benchmarks
Stars: ✭ 360 (+65.9%)
Mutual labels:  styled-components, jss
Css In Js
Autocomplete React Native / JS Styles and converting plain CSS to JS styles
Stars: ✭ 192 (-11.52%)
Mutual labels:  styled-components, jss
Styled Tools
Useful interpolated functions for CSS-in-JS
Stars: ✭ 761 (+250.69%)
Mutual labels:  styled-components, jss
Jss
JSS is an authoring tool for CSS which uses JavaScript as a host language.
Stars: ✭ 6,576 (+2930.41%)
Mutual labels:  stylesheets, jss
Css In React
🍭 CSS in React - Learn the best CSS in JS frameworks by example
Stars: ✭ 101 (-53.46%)
Mutual labels:  styled-components, jss
Elm Styled
Styling your Html Elements with typed Css πŸ’…
Stars: ✭ 180 (-17.05%)
Mutual labels:  styled-components
Styled Theme
Extensible theming system for styled-components πŸ’…
Stars: ✭ 183 (-15.67%)
Mutual labels:  styled-components
Lerna Yarn Workspaces Monorepo
πŸ‰ A Monorepo with multiple packages and a shared build, test, and release process.
Stars: ✭ 201 (-7.37%)
Mutual labels:  styled-components
Uigradients
Gradients-as-a-react-componentβ„’
Stars: ✭ 211 (-2.76%)
Mutual labels:  styled-components
Grid
This package has moved and renamed
Stars: ✭ 2,079 (+858.06%)
Mutual labels:  styled-components
Styled React Boilerplate
Minimal & Modern boilerplate for building apps with React & styled-components
Stars: ✭ 198 (-8.76%)
Mutual labels:  styled-components
Felipefialho.com
😺 My personal website
Stars: ✭ 177 (-18.43%)
Mutual labels:  styled-components
Ran
⚑ RAN! React . GraphQL . Next.js Toolkit ⚑ - SEO-Ready, Production-Ready, SSR, Hot-Reload, CSS-in-JS, Caching, CLI commands and more...
Stars: ✭ 2,128 (+880.65%)
Mutual labels:  styled-components
Antd Scss Theme Plugin
A Webpack plugin for customizing Ant Design with an SCSS theme file and using Ant Design's compiled variables in SCSS files throughout your project.
Stars: ✭ 176 (-18.89%)
Mutual labels:  stylesheets
Styled Loaders
Loaders Built with Preact and Styled Components
Stars: ✭ 212 (-2.3%)
Mutual labels:  styled-components
styled-jss

Styled Components on top of JSS

Travis branch Coverage Status branch npm version npm license

Styled-JSS implements a styled-primitives interface on top of JSS. Its API is similar to styled-components but thanks to the JSS core, it supports all features and plugins JSS does. For e.g. you can use full JSON Syntax inside.

Try it out on playground.

Default styled function

import styled from 'styled-jss'

const Button = styled('button')({
  fontSize: 12,
  color: (props) => props.theme.textColor
})

// You can also use curried interface this way.
const div = styled('div')

const Container = div({
  padding: 20
})

// Composition.
const PrimaryButton = styled(Button)({
  color: 'red'
})

// Composition with unstyled React Components too.
const Button = styled(UnstyledButton)({
  color: 'blue'
})

// Component Selectors.
const ButtonContainer = styled(Container)({
  [`& ${PrimaryButton}`]: {
    color: 'green'
  }
})

Theming

styled-jss has out of the box support for theme customization with the unified theming package.

import styled, {ThemeProvider} from 'styled-jss'

const Button = styled('button')(({margin, theme}) => ({
  margin,
  color: theme.color,
  backgroundColor: theme.backgroundColor,
}))

const themes = {
  light: {
    color: 'black',
    backgroundColor: 'yellow',
  },
}

const App = () => (
  <ThemeProvider theme={themes.light}>
    <Button margin={20}>This is themed Button</Button>
  </ThemeProvider>
)

export default App

Composable styles

Example on the CodeSandbox

You can compose your style-objects and style-functions.

Let's say this is our mods.js:

export const theme = ({ theme }) => ({
  color: theme.colors.primary,
  backgroundColor: theme.colors.secondary,
})

export const font = ({ bold }) => ({
  font: {
    weight: bold ? 'bold' : 'normal',
    family: 'Arial',
  },
})

export const size = ({ size = 'm' }) => ({
  s: {
    fontSize: 12,
    lineHeight: 1.2,
  },
  m: {
    fontSize: 16,
    lineHeight: 1.5
  }
})[size]

export const rounded = ({ rounded }) => rounded && { borderRadius: 5 }

Now we can mix them to our Button Component:

import styled from 'styled-jss'
import {theme, font, size, rounded} from 'mods'

const Button = styled('button')(
  {
    border: 0,
    padding: [5, 10],
    display: 'inline-block',
  },
  theme,
  font,
  size,
  rounded,
)

export default Button

And Usage:

import {ThemeProvider} from 'styled-jss'
import Button from './components/Button'

const theme = {
  dark: {
    colors: {
      primary: 'white',
      secondary: 'purple'
    }
  }
}

export default () => (
  <ThemeProvider theme={theme.dark}>
    <Button>normal button</Button>
    <Button bold>bold button</Button>
    <Button size="s">small button</Button>
    <Button rounded>rounded button</Button>
  </ThemeProvider>
)

Base Style Sheet

Using base Style Sheet we can reuse classes in the render function and inside of a styled component.

import { Styled, injectStyled } from 'styled-jss'

// Base styles, like a regular jss object.
const styled = Styled({
  root: {
    margin: 10,
    '& $baseButton': {
      fontSize: 16
    }
  },
  baseButton: {
    padding: 10,
    '& + &': {
      marginLeft: 10
    }
  }
})

const NormalButton = styled('button')({
  composes: '$baseButton',
  border: [1, 'solid', 'grey'],
  color: 'black'
})

// Composition - same way.
const PrimaryButton = styled(NormalButton)({
  color: 'red'
})

// One can use classes AND styled primitives.
const MyComponent = ({classes}) => (
  <div className={classes.root}>
    <NormalButton>normal button</NormalButton>
    <PrimaryButton>primary button</PrimaryButton>
  </div>
)

const MyStyledComponent = injectStyled(styled)(MyComponent)

Custom JSS setup

Styled-JSS uses jss-preset-default by default. You can require createStyled function and provide your custom JSS instance.

import { create as createJss } from 'jss'
import vendorPrefixer from 'jss-vendor-prefixer'
import createStyled from 'styled-jss/createStyled'

const jss = createJss()
jss.use(vendorPrefixer())

// Create a custom Styled function, that allows to set BaseStyles.
export const Styled = createStyled(jss)

// Create a custom styled function that allows to create styled components.
const styled = Styled()

export default styled

Install

npm install --save styled-jss

Install peer dependencies react and react-dom in your project.

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].