Skip to content

Easily style Hyperapp view functions/components with Scoped CSS

Notifications You must be signed in to change notification settings

aalises/hyperapp-scoped-stylesheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hyperapp Scoped Stylesheet

npm 452 gzip

Build Status

This HOF allows you to easily style Hyperapp views/components by adding styles / a scoped stylesheet that applies to that view only and its descendants.

Basically it allows to use scoped css styling like Angular or Vue does by adding a scoped stylesheet

Demo

Edit 7yk0kyy0jq

Getting started

install npm install hyperapp-scoped-stylesheet --save

Usage:

  1. Import the library
import { stylesheet } from "hyperapp-scoped-stylesheet"
  1. Define a string with raw CSS content
const style = `
  span { 
    font-size: 20px; 
    color: lightblue; 
  }
`

The library consists of a single function that wraps a Hyperapp view/component function, the first parameter is the raw CSS string and the second one is the JSX function defining the Vnodes. The signature is:

stylesheet(style, props => <span>something</span> ...)
  1. Wrap your Hyperapp view/component function as the second parameter (the first one is the raw content string), an example:
const style = `
  .test-style {
    color: #8651bb;
    font-weight: bold;
  }

  p {
    text-align: center;
  }
`
//First argument is the style string, second is the component function
const ScopeStyled = stylesheet(style, () => (
  <div class="test-style"> This is scope-styled yay! </div>
  <p> And this as well </p>
));

const view = () => (
  <div>
    <ScopeStyled />
  </div>
);

The function supports all CSS features defined here: https://www.npmjs.com/package/scope-css This project has been inspired by: https://github.com/k1r0s/preact-stylesheet-decorator

About

Easily style Hyperapp view functions/components with Scoped CSS

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published