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

styman

v0.1.4

Published

Styling your app with ease

Downloads

1,290

Readme

styman

Styling your app with ease

Installation

with NPM

npm i styman --save

with YARN

yarn add styman

Features

  1. Work with all JS frameworks
  2. Tailwind like syntactic sugar supported
  3. Flexible styling
  4. SSR supported
  5. Fully Typescript supported
  6. No boilerplate, no provider

Usages

Vanilla JS

import { sheet } from "styman";

const styles = sheet({
  heading: {
    color: "red",
    "&:hover": {
      color: "blue",
    },
  },
});

document.getElementById("app").innerHTML = `<h1 class="${styles({
  heading: true,
})}">Hello Vanilla!</h1>
`;

React JS

import { sheet } from "styman";

const styles = sheet({
  heading: {
    color: "red",
    "&:hover": {
      color: "blue",
    },
  },
});

const App = () => <h1 className={styles({ heading: true })}>Hello React JS</h1>
`;

Global styles

import { root } from "styman";

root(`
  * {
    box-sizing: border-box;
  }
  @font-face {
    font-family: 'Patrick Hand SC';
    font-style: normal;
    font-weight: 400;
    src: local('Patrick Hand SC'),
      local('PatrickHandSC-Regular'),
      url(https://fonts.gstatic.com/s/patrickhandsc/v4/OYFWCgfCR-7uHIovjUZXsZ71Uis0Qeb9Gqo8IZV7ckE.woff2)
        format('woff2');
    unicode-range: U+0100-024f, U+1-1eff,
      U+20a0-20ab, U+20ad-20cf, U+2c60-2c7f,
      U+A720-A7FF;
  }
`);

Animation Keyframes

keyframes generates a unique animation name that can be used to animate elements with CSS animations.

import { keyframes, sheet } from "styman";

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)",
  },
});

const styles = sheet({
  boxAnimation: {
    width: 96,
    height: 96,
    borderRadius: "50%",
    animation: `${bounce} 1s ease infinite`,
    transformOrigin: "center bottom",
  },
});

Toggle style rules

import { sheet } from "styman";

const styles = sheet({
  bold: { fontWeight: "bold" },
  color: (color) => ({ color }),
});

const Text = ({ bold, color, children }) => (
  // styman will skip all falsy values, using true value for enabling no param rule, literal rule
  <div className={styles({ bold, color })}>{children}</div>
);

Adding custom classes or styles

import { sheet } from "styman";

const styles = sheet({
  bold: { fontWeight: "bold" },
  color: (color) => ({ color }),
});

const Text = ({ className, bold, color, children }) => (
  <div
    className={styles(
      // rule selector
      { bold, color },
      // allow parent component to overwrite Text styles
      className,
      // custom styles
      { fontSize: "20px" }
      // add many classes or styles you want here
      // otherClass,
      // otherStyles
      // you can use conditional styling
      // condition ? class1 : class2
      // or condition && class1
    )}
  >
    {children}
  </div>
);

Re-use styles

import { sheet } from "styman";

const commonStyles = sheet({
  link: {
    color: "silver",
    textDecoration: "underline",
    "&:hover": { textDecoration: "none" },
  },
});

const articleStyles = sheet({
  link: commonStyles({ link: true }),
});

const otherLinkStyles = sheet({
  link: [
    articleStyles({ link: true }),
    // add more custom styles
    { color: "blue", "&:hover": { color: "red" } },
  ],
});

Parameterized rule

import { keyframes, sheet } from "styman";

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)",
  },
});

const styles = sheet({
  // rule has param
  boxAnimation: (time) => ({
    animation: `${bounce} ${time} ease infinite`,
    transformOrigin: "center bottom",
  }),
  // rule has no param
  box: () => ({
    backgroundColor: "silver",
    borderRadius: "50%",
    width: 96,
    height: 96,
  }),
});

<div
  className={styles({
    boxAnimation: "2s",
    box: true,
  })}
></div>;

Cached rules

import { keyframes, sheet, once } from "styman";

// create bounce animation factory
const bounce = once(() =>
  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)",
    },
  })
);

const styles = sheet({
  boxAnimation: (time) => ({
    // bounce() will run once and the bounce animation will be only created when bounce() is called
    animation: `${bounce()} ${time} ease infinite`,
    transformOrigin: "center bottom",
  }),
  // rule has no param
  box: () => ({
    backgroundColor: "silver",
    borderRadius: "50%",
    width: 96,
    height: 96,
  }),
});

Generating class from CSS text

import { css } from "styman";
import { createElement } from "react";

const Button = (props) => (
  <button
    {...props}
    className={css`
      color: ${props.disabled ? "gray" : "black"};
    `}
  />
);

<div className={css({ fontWeight: "bold", backgroundColor: "red" })}></div>;

<div
  className={css`
    font-weight: bold;
    background-color: red;
  `}
></div>;

// create styled component factory
const styled =
  (tag) =>
  (template, ...args) =>
  (props) =>
    createElement(props.as || tag, {
      ...props,
      className: css(
        template,
        ...args.map((x) => (typeof x === "function" ? x(props) : x))
      ),
    });

const StyledButton = styled("button")`
  color: red;
`;

Styler

Styler is utils that helps to generate css class faster, it provides a lot of styling modules. It works similar Tailwind CSS

Styler features:

  • Easy to customize (colors, modifiers, utils)
  • No purging needed
  • Fully Typescript supported
  • SSR supported

Creating default Styler

Styman provides a default styler that includes pre-defined style modules. The styler has similar Tailwind classes and modifiers

import {
  buildDefaultStyler,
  createStyler,
  defaultColorScheme,
} from "styman/styler";

// create a styler with default color scheme
const styler = createStyler({
  colors: defaultColorScheme,
  // using buildDefaultStyler to build a styler with common modules
  build: buildDefaultStyler,
});

// single variant
const class1 = styler({ bg: "red" });

// multiple variants
const class2 = styler({ bg: ["red", "scroll"] });

// combine with normal CSS props
const class2 = styler(
  { bg: ["red", "no-repeat"], font: "2xl" },
  { backgroundImage: `url(your-image)` }
);

const buttonClass = styler({
  bg: {
    hover: "blue-400", // background color for hover status
    active: "blue-600", // background color for active status
    $: "blue", // background color for normal status
  },
  px: 4, // padding horizontal 1rem
  py: 2, // padding vertical 0.5rem
  r: "md", // medium border radius
  shadow: "lg", // box shadow
  text: "white", // color
  transition: [
    "all", // apply transition for all props
    "in-out", // ease in out
  ],
  scale: { hover: 120 }, // apply scale 120% when hover
});

// easy to apply the styles
<button className={buttonClass}>Submit</button>;

Default Styler References

Creating custom Styler

import {
  BuildContext,
  backgroundModule,
  borderModule,
  cursorModule,
  fontModule,
  sizingModule,
  textModule,
  listModule,
  flexModule,
  tableModule,
  transformModule,
  layoutModule,
  opacityModule,
  animationModule,
  interactivityModule,
  svgModule,
  filterModule,
  divideModule,
  spaceModule,
  marginModule,
  paddingModule,
  transitionModule,
  borderRadiusModule,
  outlineModule,
  boxShadowModule,
  red,
  green,
  blue,
  orange,
} from "styman/styler";

const buildCustomStyler = (context) => {
  return {
    ...backgroundModule(context),
    ...textModule(context),
    ...fontModule(context),
    ...cursorModule(context),
    ...borderModule(context),
    ...sizingModule(context),
    ...listModule(context),
    ...flexModule(context),
    ...tableModule(context),
    ...transformModule(context),
    ...layoutModule(context),
    ...opacityModule(context),
    ...animationModule(context),
    ...interactivityModule(context),
    ...svgModule(context),
    ...filterModule(context),
    ...divideModule(context),
    ...spaceModule(context),
    ...marginModule(context),
    ...paddingModule(context),
    ...transitionModule(context),
    ...borderRadiusModule(context),
    ...outlineModule(context),
    ...boxShadowModule(context),
  };
};

const styler = createStyler({
  // custom color scheme
  colors: {
    primary: blue,
    success: green,
    danger: red,
    wraning: orange,
  },
  build: buildCustomStyler,
});