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

@dusanjovanov/vanilla-style

v0.5.3

Published

Vanilla CSS-in-JS library

Downloads

6

Readme

vanilla-style 🍦

css-in-js library - kinda like tailwind but with objects

yarn add @dusanjovanov/vanilla-style

npm npm bundle size

Usage

import { createVanillaStyle, defaultTheme } from "@dusanjovanov/vanilla-style";

const { classes: c } = createVanillaStyle(defaultTheme);

// or merge your theme with the defaultTheme
// defaultTheme is more or less same as tailwind's
const { classes: c } = createVanillaStyle({
  ...defaultTheme,
  backgroundColor: {
    ...defaultTheme.backgroundColor,
    brandColor: "dodgerblue",
  },
});

const element = document.createElement("div");

element.className = c.bg.blue500; // blue background

// or if you use React
import { cx } from "@dusanjovanov/vanilla-style";

const Button = () => {
  return (
    <button
      className={cx(
        c.bg.blue500,
        c.hover.bg.blue700,
        c.color.white,
        c.borderRadius.all.md
      )}
    >
      Button
    </button>
  );
};

// if you need multiple classes (and you will most of the time),
// use 'cx' function (reexported from @emotion/css)

If you need a custom (fixed) value, you can do this:

const className = c.fontSize.custom(14);
// or
const className = c.fontSize.custom("20px");

// this works for any css property

There are pseudo selectors

const className = c.dark.color.white; // only applied when inside a container with .dark class

const className = c.focus.boxShadow.md; // applied on focus

Custom selector function

const className = c.selector("td,th").border.all.width[1]; // applied to child elements

// you can chain pseudo selectors as well
const className = c.selector("td,th").hover.border.right.style.solid; // this is applied when the child elements are hovered

// when the parent is hovered
const className = c.selector(":hover td,th").border.bottom.color.custom("red");

Media queries

const className = c.screen.md.width.full;

const className = c.screen.lg.hover.color.red500;

Animations

There are a few built in animations (same as Tailwind).

const { classes: c } = createVanillaStyle(defaultTheme);

// special animation shorthand method
// animation shothand doesn't have individual, ordered arguments like the border and outline shorthands
// it just accepts a string - css animation has too many properties :)
const className = c.animation.shorthand(
  `350ms ${c.animation.name.spin} linear infinite`
);

// or set everything individually
const className = cx(
  c.animation.duration[500],
  c.animation.name.spin,
  c.animation.timingFunction.linear
  c.animation.iterationCount.infinite,
);

// custom animation (not from the theme)
// animation name needs to the string that keyframes returns !
import { keyframes } from "@dusanjovanov/vanilla-style"; // reexported from @emotion/css

const bounce = keyframes({
  "from, 20%, 53%, 80%, to": {
    transform: "translate3d(0,0,0)",
  },
  "40%, 43%": {
    transform: "translate3d(0, -30px, 0)",
  },
  "70%": {
    transform: "translate3d(0, -15px, 0)",
  },
  "90%": {
    transform: "translate3d(0,-4px,0)",
  },
});

// shorthand
const className = c.animation.shorthand(`1s ${bounce} ease infinite`);

// individual property
const className = c.animation.name.custom(bounce);

About the library:

  • Built with Typescript and has full type inference
  • Framework agnostic (just has to be JS)
  • 1 dependency: @emotion/css

🔔 There will be a docs site with more details and examples soon!

Also stable version coming soon!