0.17.2 • Published 2 years ago

tastycss v0.17.2

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

TastyCSS

CSS-in-JS solution modules that include state-to-style bindings, SSR, and next-level developer experience.

NPM Version Discord

Installation

# with npm
npm install tastycss

# with yarn
yarn add tastycss

# with pnpm
pnpm add tastycss

Usage of Tasty API

Let's look at styled API:

import { tasty } from 'tastycss';

const Element = tasty({
  /** The tag name of the element. */
  as: '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 attributes (example) */
  role: 'article',
  /** The list of styles that can be provided by props */
  styleProps: ['align'],
});

Now you can use this element inside your React App:

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

Extend base options

You can use tasty() function to extend styling of the existing component.

const CustomElement = tasty(Element, {
  /** Change tag name */
  as: 'input',
  /** Extend or rewrite styles */
  styles: {
    color: '#purple',
  },
  /** Add more default properties/attributes */
  role: 'article',
});

Define global styles

Use tasty() to define global styles for elements:

import { tasty } from 'tastycss';

const GlobalStyledHeading = tasty('.myButton', {
  display: 'inline-block',
  padding: '1x 2x',
  preset: 't2',
  border: true,
  radius: true,
});

Style variants

You can reduce the amount of CSS for your component by splitting it into variants.

import { tasty } from 'tastycss';

const StyledButton = tasty(Button, {
  styles: {
    /* default styles */
  },
  variants: {
    // define themes using variants
    default: {
      // default (fallback) variant
      // define new styles for `default` variant or override default styles.
    },
    danger: {
      // define new styles for `danger` variant or override default styles.
    },
  },
});

Usage example:

<StyledButton variant="danger">Danger Button</StyledButton>

If the variant prop is not provided then the default variant will be used.

IMPORTANT: It's preferred that the component will not receive any change in variant prop to avoid style replacement. But this case is supported.

Documentation is work in progress.

Contributing

Please follow our contributing guidelines.

License

TastyCSS is a project by Outpost.

Released under the MIT License.

0.17.2

2 years ago

0.13.0

2 years ago

0.15.0

2 years ago

0.11.0

2 years ago

0.9.0

2 years ago

0.9.1

2 years ago

0.10.1

2 years ago

0.12.0

2 years ago

0.10.2

2 years ago

0.10.0

2 years ago

0.8.9

2 years ago

0.8.8

2 years ago

0.8.4

2 years ago

0.8.7

2 years ago

0.8.6

2 years ago

0.8.1

2 years ago

0.8.3

2 years ago

0.8.2

2 years ago

0.7.9

2 years ago

0.7.6

2 years ago

0.7.5

2 years ago

0.6.6

3 years ago

0.7.8

2 years ago

0.7.7

2 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.6.3

3 years ago

0.6.5

3 years ago

0.6.4

3 years ago

0.5.7

3 years ago

0.5.4

3 years ago

0.6.2

3 years ago

0.5.3

3 years ago

0.5.6

3 years ago

0.5.5

3 years ago

0.6.1

3 years ago

0.5.2

3 years ago

0.5.1

3 years ago

0.3.0

3 years ago

0.4.4

3 years ago

0.4.0

3 years ago

0.2.4

3 years ago

0.1.2

3 years ago

0.2.0

3 years ago

0.1.3

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago