npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hyper-fela

v1.5.0

Published

hyperscript-style bindings for Fela

Downloads

4

Readme

hyper-fela

hyperscript-style bindings for fela

API based on react-fela

npm install --save hyper-fela

example

const hyperFela = require('hyper-fela')
const h = require('hyps')
const { createRenderer } = require('fela')
const { render } = require('fela-dom')

// intialize renderer
const renderer = createRenderer()
const { renderRule } = renderer

// setup stylesheet render
const stylesheet = document.createElement('style')
document.head.appendChild(stylesheet)
render(renderer, stylesheet)

// create styled element creator
const createStyledElement = hyperFela({ h, renderRule })

// create some styled elements!

const GreenSpan = createStyledElement('span', props => ({
  color: 'green'
}))

const Button = createStyledElement((props, children) => {
  return h('h1', {
    events: {
      click: (ev) => console.log('clicked!')
    }
  }, children)
}, props => ({
  fontWeight: 'bold'
}))

// render all the things
const button = Button([
  GreenSpan([
    'click me!'
  ])
])

document.body.appendChild(button)

usage

hyperFela = require('hyper-fela')

createStyledElement = hyperFela({ h, renderRule })

{ createStyledElement } = hyperFela({ h, renderRule })

h is a hyperscript-compatible function of shape (tagName, properties, children) => HTMLElment.

renderRule is fela.createRenderer().renderRule.

Element = createStyleElement([type], rule, [options])

(optional) type is either:

rule is either:

  • a fela rule (function that returns a style object)
  • a style object

(optional) options is object with keys:

  • passThrough: a list of props that get passed to the underlying element.

element = Element([properties], [children])

passThrough props

using the passThrough parameter allows us to pass propertiess to the underlying DOM element. this is helpful if you want to pass e.g. events such as events.click. there are some props that are automatically passed and thus do not need to be specified explicitly:

  • className
  • id
  • className
  • events
  • attributes
  • style
  • hooks
  • data

if passing a className, it will automatically be concatenated with the Fela generated className. this allows composing multiple Fela elements.

dynamically passing props

this use case is especially important for library owners. instead of passing the passThrough props to the createStyleElement call directly, one can also use the passThrough prop on the created element constructor to achieve the same effect.

example

const title = props => ({
  color: 'red'
})

const Title = createStyleElement(title)

const greet = () => alert('Hello World')

const element = Title({ events: { click: greet } }, 'Hello World')
// => <div className="a" onclick="...">Hello World</div>

custom type on runtime

to change the type on runtime and/or for each component, you may use the is prop.

const title = props => ({
  color: 'red'
})

const Title = createStyleElement(title)

const element = Title({ is: 'h1' }, 'Hello World')
// => <h1 className="a">Hello World</h1>

{ connectStyles } = hyperFela({ h, renderRule })

Element = connectStyles(mapStylesToProps, Element)

const Header = ({ title, styles }) => {
  return h('header', { className: styles.container }, [
    h('h1', { className: styles.title }, [
      title
    ])
  ])
}

const container = props => ({
  textAlign: 'center',
  padding: '20px',
  height: '200px'
})

const title = props => ({
  lineHeight: 1.2,
  fontSize: props.fontSize,
  color: props.color
})

// we use both the components props and
// renderRule to compose our classNames
const mapStylesToProps = props => renderer => ({
  container: renderRule(container),
  title: renderRule(title, {
    fontSize: props.size + 'px',
    color: props.color
  })
})

Header = connect(mapStylesToProps, Header)

const header = Header({
  title: 'Hello World',
  color: 'red',
  size: 17
})
// =>
// <header className="a b c">
//   <h1 className="d e f">
//     Hello World
//   </h1>
// </header>

license

The Apache License

Copyright © 2017 Michael Williams

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.