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

tastycss-react

v0.6.6

Published

A set of modules is for CSS-in-JS solution that includes state-to-style bindings, SSR and next-level developer experience. It includes a framework-agnostic implementation

Downloads

45

Readme

TastyCSS

A set of modules is for CSS-in-JS solution that includes state-to-style bindings, SSR and next-level developer experience. It includes a framework-agnostic implementation

NPM Version Discord

Installation

Framework-agnostic version:

# with npm
npm install tastycss

# with yarn
yarn add tastycss

React version:

# with npm
npm install tastycss-react

# with yarn
yarn add tastycss-react

Documentation

TastyCSS utils allow generating performant CSS with responsiveness and style-to-state bindings.

TastyCSS React is a styled version for React Apps that uses styled-components under-the-hood.

React

Let's look at styled API:

import styled from 'tastycss-react';

const Element = styled({
  /** The name of the element. It can be used to override styles in context. */
  name: 'Article',
  /** The tag name of the element. */
  tag: 'span',
  /** Default styles of the element. */
  styles: {
    // tokens
    '@local-padding': ['2x', '1x'], // responsive styles
    '@text-color': 'rgba(255, 0, 0)',
    // styles
    padding: '@local-padding',
    color: {
      // the default color
      '': '#text',
      // the color if `blue` mod is specified
      blue: 'blue',
    }, // use color token
  },
  /** Default raw css of the element. */
  css: `
    appearance: none;
  `,
  /** Default attributes */
  attrs: {
    role: 'article',
  },
  availableMods: ['blue'],
});

Now you can use this element inside your React App:

export default function Component({ title, children }) {
  return <>
    <Heading>{title}</Heading>
    <Element>{chidlren}</Element>
  </>;
}

Customize styles in-place using styles attribute:

<Element styles={{ color: 'red' }}>{chidlren}</Element>

Customize styles in context:

import { StylesProvider } from 'tastycss-react';

export default function Component({ title, children }) {
  return <StylesProvider Article={{
    color: 'red',
  }}>
    <Heading>{title}</Heading>
    <Element>{chidlren}</Element>
    <Element>{chidlren}</Element>
  </StylesProvider>;
}

Responsive breakpoints

Customize responsive breakpoints:

import { BreakpointsProvider } from 'tastycss-react';

export default function Component({ title, children }) {
  return <BreakpointsProvider value={[1200, 960]}>
    <Heading>{title}</Heading>
    <Element>{chidlren}</Element>
    <Element>{chidlren}</Element>
  </BreakpointsProvider>;
}

This will create two breakpoints (1200px and 960px) which will split possible screen width into three zones: >=1200px, >=960px & <1200px, <960px.

Then you can create responsive styles with specific value for each zone:

<Element styles={{ 
  color: [
    'red', // >=1200px
    'blue', // >=960px & <1200px
    'purple', // <960px
  ],
}}>
  content
</Element>

Style-to-state bindings

Style-to-state binding works gracefully and allows to use logical operators:

// This example is not a real-life case. It's only a demonstation of library capabilities.
<Element styles={{
  color: {
    // default
    '': 'yellow',
    // if `blue` mod is presented on the element
    'blue': 'blue',
    // if `blue` mod is not presented on the element and the element is hovered
    '!blue & :hover': 'purple',
    // if `green` or `success` mod is presented on the element
    'success | green': 'green',
    // if either `red` or `danger` mod is presented on the element
    'success ^ green': 'green',
  }
}}></Element>

You can use even more complex expressions with brackets. The algorithm will go from the last to the first expression trying to match every possible combination of modifiers. If the combination is matched then it applies the style value to that selector.

This documentation is work in progress. It is not yet ready.

Contributing

Please follow our contributing guidelines.

Authors

License

TastyCSS is a project by Forneu.

Released under the MIT License.