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

bau-solidcss

v0.1.15

Published

css-in-js for SolidJS

Downloads

4

Readme

CSS-in-JS for SolidJS

Shamlessly copied BauCSS, added styled for SolidJS. npm bundle size

Usage

pnpm i bau-solidcss
import BauSolidCss from "bau-solidcss";
const { css, styled, keyframes, createGlobalStyles } = BauSolidCss();

Worked example

cd example
pnpm i
pnpm run dev

bau-solidcss package

It exports 4 primitives: cssto build classes, keyframes to build animations, createGlobalStyles for global styles and styled to build styled components and easy conditional styling.

Global style with createGlobalStyles

createGlobalStyles`
  :root {
    margin: 0;
    --main-color: midnightblue;
  }
  
  body {
    text-align: center;
  }
`;

Build a class with css

You write template strings, pass it to the function css to build a class.

const main = css`
  background-color: bisque;
  color: var(--main-color);
`;

<div class={main}>I am an div</div>;

Build a styled component with styled

const P = (props) => styled("p", props)`
  color: ${props.color ?? "var(--main-color)"};
`;

<P>I am blue</P>
<P color="red">I am red</P>;

Add rules to a styled component

Yo ucan extend rules, not overwrite them. To overwrite them, use the conditional form with props, see below.

const B = (props) => (
  <P
    color="midnightblue"
    class={css`
      background-color: bisque;
    `}
  >
    {props.children}
  </P>
);

<B> A bisqued "P"</B>;

Conditional classes

Take CSS rules in the form of the object below:

const styles = (props) => {
  base: `
    cursor: pointer;
    font-size: ${props.size ?? 1}em;
    border-radius: 0.3em;
    padding: 0.3em;
  `,
  danger: `
    color: red;
    animation: ${rescale} 1s ease infinite;
  `,
  disabled: `
    pointer-events: none;
    opacity: ${props.opacity};
  `;
}

You can do:

const Btn = (props) =>
  styled("button", props)`
    ${styles(props).root +
    (props.danger ? styles(props).danger : "") +
    (props.disabled ? styles(props).disabled : "")}
  `;

Alternatively, when you use the boject above, then the styled primitive merges the styles from the props. In other words, with:

const Button = (props) => styled("button", props)`
  ${styles(props).base}
  ${styles(props)}
`;

you can do:

// the 1st version:
<Btn size={2} onClick={()=> alert('hi')}>Base size 2</Btn>
<Btn danger="true">Danger</Btn>

//or the second version
<Button>Base Button</Button>
<Button
  danger="true"
  disabled
  size={1.5}
  className={css`
    box-shadow: 6px -6px bisque;
  `}
>
  Shadowed Danger
</Button>;

Reactive style of a component

const [size, setSize] = createSignal(1)


const Dyn = (props) => {
  const size = () => props.size || 1;
  return (
    <div style={{ "font-size": `${size()}em` }}>{props.children}</div>
  );
};

<input type="number" value={size()} onchange={e => setSize(e.target.value)} />
<Dyn size={size()}>Dynamic</Dyn>

Animations with keyframes

const rescale = keyframes`
0% {transform: scale(0.5)}
100% {transform: scale(1)}
`;

const AnimSurf = (props) => styled("span", props)`
  font-size: ${props.size}em;
  animation: ${rescale} 2s ease infinite;
`;

<AnimSurf size={3}>🏄</AnimSurf>;