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

@oncomouse/hyperapp-emotion

v0.0.6

Published

*[Emotion](https://emotion.sh/) bindings for [Hyperapp](https://hyperapp.js.org/)*

Downloads

9

Readme

hyperapp-emotion

Emotion bindings for Hyperapp

This project provides a way to make styled components in Hyperapp using the Emotion CSS-in-JS framework. It is similar to preact-emotion and react-emotion in functionality, though not in implementation.

Consider the following example:

import { h } from 'hyperapp'
import styled from 'hyperapp-emotion'

const borderColor = '#0FF'

const Button = styled('button')`
  border: 1px solid ${borderColor};
  color: #000;
  font-size: ${props => props.size || '1rem'};
  &:hover {
    background: ${borderColor};
    color: #FFF;
  }
`
export default Button;

This will export a Hyperapp component with the styles above defined. Additionally, you can pass an optional size prop to change the font-size property in the button. This works the same as in other styled component implementations.

The Emotion styled components documentation mentions the following features, most of which (at this point) are supported by hyperapp-emotion:

Changing based on props

The following works in this library:

import styled from 'react-emotion'

const Button = styled('button')`
  color: ${props =>
    props.primary ? 'hotpink' : 'turquoise'};
`

const Container = styled('div')(props => ({
  display: 'flex',
  flexDirection: props.column && 'column'
}))

const view = state => (
  <Container column>
    <Button>
      This is a regular button.
    </Button>
    <Button primary>
      This is a primary button.
    </Button>
  </Container>
)

Styling any component

The following works in this library:

import styled from 'react-emotion'
const Basic = ({ className }) => (
  <div className={className}>Some text</div>
)

const Fancy = styled(Basic)`
  color: hotpink;
`

const view = state => (<Fancy />)

Change the rendered tag using withComponent

The following works in this library:

// Create a section element
const Section = styled('section')`
  background: #333;
`
// Create an aside element with the same styles as Section
const Aside = Section.withComponent('aside')
const view = (state) => (
  <div>
    <Section>This is a section</Section>
    <Aside>This is an an aside</Aside>
  </div>
)

Targeting another emotion component

Currently untested, but should work

const Child = styled('div')`
  color: red;
`

const Parent = styled('div')`
  ${Child} {
    color: green;
  }
`
const view = state => (
  <div>
    <Parent>
      <Child>green</Child>
    </Parent>
    <Child>red</Child>
  </div>
)

Pass refs down using innerRef

Does not work; is not necessary in / relevant to Hyperapp (?)

Element Shorthand

Note: babel-plugin-emotion is required for the element shorthand

Currently untested, but should work

const DivWithoutShorthand = styled('div')`
  color: green;
`

const DivWithShorthand = styled.div`
  color: hotpink;
`

const view = state => (
  <DivWithoutShorthand>
    This is green. <DivWithShorthand>This is hotpink.</DivWithShorthand>
  </DivWithoutShorthand>
)

Object styles

Currently untested, but should work

const H1 = styled.h1(
  {
    fontSize: 20
  },
  props => ({ color: props.color })
)

const view = state => (
  <H1 color="lightgreen">
    This is lightgreen.
  </H1>
)