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

dallas

v4.0.2

Published

A wrapper for applying classes

Downloads

148

Readme

dallas

La classe, dallas.

Install

# React is a peer dependencie
npm i dallas react

API

The api provide a classe wrapper function.

Basic usage

import { React, classe } from 'classe'
// classe takes 2 arguments
// an option and a render function
const Button = classe('my-button', props => <button {...props} />)

// this JSX:
<Button className='big' />
// render this dom
<button className='big my-button' />

React is passed down for convenience

You can pass in an array of classNames

import { React, classe } from 'dallas'

import style from './Wrapper.module.css'

const Wrapper = classe([ 'container', style.Wrapper ])

// This JSX
<Wrapper />
// render this dom
<div class="container Wrapper__Wrapper_aQn7" />

The second argument (the render function) is optionnal
It will default to rendering the className to a div. props => Merged class names !)

boolean class flags

all keys that have strings values genereate boolean flags as short hands for applying css classes.

// options can be passed last or first.
export const FlagClass = classe({
  disabled: 'dis',
  selected: 'bp-selected',
})

// this JSX
<FlagClass disabled selected />
// render this dom
<div class="dis bp-selected" />

// and this JSX
<FlagClass selected className="pouet"/>
// render this dom
<div class="pouet bp-selected" />

You can not use className or classNames as a flag.

class matcher

A class matcher is a switch, it use a string or a function for more complex logic.

// options can be passed last or first.
export const Matcher = classe({
  color: {
    info: 'color-blue',
    warning: 'color-yellow',
    error: 'color-red',
  },
  status: data => data.endDate > Date.now() ? 'available' : 'unavailable'
})

// this JSX
<Matcher color="error" />
// render this dom
<div class="color-red" />

// and this JSX
<Matcher status={{ endDate: Date.now() + 1000 }} />
// render this dom
<div class="available" />

// while
<Matcher status={{ endDate: 0 }} />
// would render this dom
<div class="available" />

The render functions are memo by default, if you want not to memo the function, use either classe.noMemo or classeNoMemo.

option consume (Boolean)

Passing the consume option to true will remove props that are used for flags.

option groups (RegExp)

A RegExp used to match exclusive props together

export const Matcher = classe({
  orange1: 'light-orange',
  orange2: 'orange',
  orange3: 'dark-orange',
  groups: /^([a-z]+)([0-9]+)$/i,
})

// this JSX
<Matcher orange="1" />
// render this dom
<div class="light-orange" />

// this JSX
<Matcher orange3 />
// render this dom
<div class="dark-orange" />

// this JSX
<Matcher orange={2} />
// render this dom
<div class="orange" />

Groups are mutualy exclusives so once flags are matched together, only the last one will be applied:

// this JSX
<Matcher orange1 orange2 orange3 />
// render this dom
<div class="dark-orange" />

Refs

A special elemRef props is checked to forward ref to the rendered element.

const ref = useRef(null)
<Matcher elemRef={ref} />