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

@codeurs/front

v0.17.0

Published

Collection of mithril utilities and components

Downloads

113

Readme

Components

A collection of (currently) unfinished and undocumented mithril utilities and components.

Table of Contents

Action

Use an action component when you have an internal or external link.

import {action} from '@codeurs/front'

view() {
  return m('a', action('/url'))
}

If you have multiple attributes you must write it a little bit different.

import {action} from '@codeurs/front'

view() {
  return m('a', {
    class: 'link',
    ...action('/url')
  })
}

Classes

Conditionally join classNames together. Uses classNames in its implementation but allows you to easily prefix them.

import {classes} from '@codeurs/front'

view() {
  const {mod} = this.attrs
  const open = true

  return [
    //class will be 'mod-small'
    m('a', classes({mod: 'small'}), 'Size'),

    //class will be 'mod-small.mod-black'
    m('a', classes({mod: ['small', 'black']}), 'Size and color'),

    //class will not be set if mod is falsy (false/null/undefined/0/NaN/'')
    m('a', classes({mod}), 'Modification'),

    //class will be 'is-open' if open evaluates to true
    m('a', classes({is: {open}}), 'Is open'),

    //class will be 'is-active' if url is '/home'
    m('a', classes({is: {active: action.isActive('/home')}}), 'Is active')
  ]
}

MediaQuery

Media queries are useful when you want to modify your site depending on the browser's width. The big advantage over css media queries is that elements are not shown but also not drawn.

import {MediaQuery} from '@codeurs/front'

view() {
  return [
    m(MediaQuery, {
      maxWidth: 767,
      view: () => m('p', 'Content that can only be seen up to 768 pixels.')
    }),
    m(MediaQuery, {
      minWidth: 768,
      view: () => m('p', 'Content that can only be seen from 768 pixels.')
    })
  ]
}

Modal

A temporary UI overlay.

import {Component, ModalStore, Modal, ModalOverlay} from '@codeurs/front'

class ModalExample extends Component {
  modal = new ModalStore()
  view() {
    return [
      m('a', {onclick: this.modal.open}, 'Open modal'),
      m(Modal, this.modal, [
        m(ModalOverlay),
        m('.modalexample', 'Popup content')
      ])
    ]
  }
}

Portal

Creates a top-level node in the body and mounts its children. Useful to escape z-index stacking for modals.

import {Component, Portal} from '@codeurs/front'

class PortalExample extends Component {
  view() {
    return m(Portal, [
      m('.portalexample', 'This is placed at the end of document.body')
    ])
  }
}

Slider

Horizontal touch enabled slider. Slides can be of variable width.

import {Component, Slider, SliderStore} from '@codeurs/front'

export default class SliderExample extends Component {
  slider = new SliderStore()
  view() {
    return m('.sliderexample', [
      m(Slider, this.slider, [
        m('.sliderexample-slide'), // display: inline-block
        m('.sliderexample-slide')  // etc ...
      ]),
      m('a', {onclick: e => this.slider.goPrevious()}, 'Previous'),
      m('a', {onclick: e => this.slider.goNext()}, 'Next')
    ])
  }
}