All Projects → k1r0s → preact-stylesheet-decorator

k1r0s / preact-stylesheet-decorator

Licence: other
`@stylesheet` decorator to style preact components

Programming Languages

javascript
184084 projects - #8 most used programming language

This decorator allows to easily style Preact/React (since 1.6.*) components through adding a scoped stylesheet inside that component and defined styles only get applied to it and its descendants.

Basically it allows to style preact/react like Angular or Vue does by adding a scoped stylesheet

Demo (Preact)

Edit z3p207zxml

Getting started

install npm install stylesheet-decorator --save

usage:

  1. import
import { stylesheet } from "stylesheet-decorator[/preact]"
import { stylesheet } from "stylesheet-decorator/react"
  1. define a string with raw CSS content
const style = `
  span { font-size: 20px; color: lightblue; }
`
  1. Plug it on render fn of some Preact/React component
@stylesheet(style)
render() {
  return <span>something</span>
}

or

stylesheet(style, props => <span>something</span>)

That's all.

This decorator supports all CSS capabilities defined here: https://www.npmjs.com/package/scope-css

This development is related on this conversation: Twitter Link and this issue GH preact issue

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].