0.10.5 โ€ข Published 5 months ago

@plumeria/core v0.10.5

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@plumeria/core

Zero-runtime, expressive CSS-in-JS library for TypeScript.

๐ŸŒฑ Installation

To get started with Plumeria, install the core package:

npm install @plumeria/core

๐Ÿ›  Compiler (for static extraction)

If you want to extract styles at build time using commands like npx css, install:

npm install --save-dev @plumeria/compiler

More at: @plumeria/compiler on npm

๐ŸŽจ Stylesheet Import

In your app entry point, import the compiled CSS file:

import '@plumeria/core/stylesheet.css';

๐Ÿ“˜ API Reference

css.create()

Define a set of styles:

import { css, cx, ps, px } from '@plumeria/core';

const styles = css.create({
  box: {
    width: '100%',
    color: 'rgb(60,60,60)',
  },
  text: {
    color: 'yellow',
  },
});

Supports pseudo/media queries inline:

const styles = css.create({
  box: {
    [css.media.maxWidth(900)]: {
      width: '100%',
    },
  },
  text: {
    color: '#333',
    [ps.hover]: {
      color: 'skyblue',
      opacity: 0.9,
    },
  },
});

css.createComposite()

Creates modifier classes for a base style:

const styles = css.create({
  flexBox: {
    display: 'flex',
    flexDirection: 'column',
    justifyContent: 'center',
  },
});

const composed = css.createComposite(styles.flexBox, {
  hover: {
    [ps.hover]: {
      scale: 1.5,
    },
  },
  active: {
    [ps.active]: {
      color: css.color.gray,
    },
  },
});

This produces named modifier classes based on the base style.
You can use them like this:

<div className={composed.hover} />

Automatically generates all modifier variants while keeping the base style clean.

css.global()

Define global styles:

css.global({
  html: {
    width: '100%',
    height: '100%',
    padding: 0,
    margin: 0,
  },
  body: {
    position: 'relative',
    width: 600,
  },
  h1: {
    fontSize: 32,
  },
});

css.keyframes()

Create keyframes for animation:

const fade = css.keyframes({
  from: {
    opacity: 0,
  },
  to: {
    opacity: 1,
  },
});

const styles = css.create({
  box: {
    animationName: fade,
    animationDuration: '1s',
  },
});

css.defineConsts()

Define reusable constant values with type safety:

const breakpoints = css.defineConsts({
  xs: css.media.maxWidth(480),
  sm: css.media.maxWidth(640),
  md: css.media.maxWidth(768),
  lg: css.media.maxWidth(1024),
  xl: css.media.maxWidth(1280),
});

Use them in your style definitions:

const styles = css.create({
  container: {
    [breakpoints.sm]: {
      padding: 16,
    },
    [breakpoints.lg]: {
      padding: 32,
    },
  },
});

Constants are fully type-safe and readonly.

css.defineVars()

Define design tokens with CSS variables:

const tokens = css.defineVars({
  white: 'white',
  black: 'black',
  textPrimary: '#eaeaea',
  textSecondary: '#333',
  link: 'lightblue',
  accent: 'purple',
});

css.defineTheme()

Define theme values with responsive and conditional support:

const themes = css.defineTheme({
  text_primary: {
    default: 'rgb(60,60,60)',
    light: 'black',
    dark: 'white',
    [css.media.maxWidth(700)]: 'gray',
  },
  bg_primary: {
    light: 'white',
    dark: 'black',
  },
});

css.color

Color utility:

color: css.color.darken('skyblue', 0.12),
color: css.color.lighten('navy', 0.6),

color: css.color.skyblue,
color: css.color.aqua,
// and many more

cx

Classname merging helper:

px(ps.hover, ps.after);
// => ":hover::after"
cx(styles.text, styles.box);
// => "text_hash box_hash"

๐Ÿงน ESLint Support

Use @plumeria/eslint-plugin for recommended rules:

Rules: recommended

- no-inner-call: error
- no-unused-keys: warn
- sort-properties: warn
- validate-values: warn

Plumeria is best used alongside TypeScript for excellent autocomplete and validation support.

๐Ÿ“„ License

Plumeria is MIT licensed.

0.10.5

5 months ago

0.10.4

5 months ago

0.10.3

5 months ago

0.10.2

5 months ago

0.10.1

5 months ago

0.10.0

5 months ago

0.9.10

5 months ago

0.9.9

5 months ago

0.9.8

5 months ago

0.9.7

5 months ago

0.9.6

6 months ago

0.9.5

6 months ago

0.9.4

6 months ago

0.9.3

6 months ago

0.9.2

6 months ago

0.9.1

6 months ago

0.8.14

6 months ago

0.8.13

6 months ago

0.8.12

6 months ago

0.8.11

6 months ago

0.8.9

6 months ago

0.8.10

6 months ago

0.8.8

6 months ago

0.8.6

7 months ago

0.8.5

7 months ago

0.9.0

7 months ago

0.8.4

7 months ago

0.8.3

7 months ago

0.8.2

7 months ago

0.8.1

7 months ago

0.8.0

7 months ago

0.8.0-beta.2

7 months ago

0.8.0-beta.1

7 months ago

0.8.0--.beta.1

7 months ago

0.7.20

7 months ago

0.7.19

7 months ago

0.7.18

7 months ago

0.7.17

7 months ago

0.7.16

7 months ago

0.7.15

7 months ago

0.7.14

7 months ago

0.7.14-beta1

7 months ago

0.7.13

7 months ago

0.7.12

7 months ago

0.7.11

7 months ago

1.0.0

7 months ago

0.7.10

7 months ago

0.7.9

7 months ago

0.7.8

7 months ago

0.7.7

8 months ago

0.7.6

8 months ago

0.7.5

8 months ago

0.7.4

8 months ago

0.7.3

8 months ago

0.7.2

8 months ago

0.7.1

8 months ago

0.7.0

8 months ago

0.6.9

8 months ago

0.6.8

8 months ago

0.6.7

8 months ago

0.6.6

8 months ago

0.6.5

8 months ago

0.6.4

8 months ago

0.6.3

8 months ago

0.6.2

8 months ago

0.6.1

8 months ago

0.6.0

9 months ago

0.5.1

9 months ago

0.5.0

9 months ago

0.4.0

9 months ago

0.3.1

9 months ago

0.3.0

9 months ago

0.2.5

9 months ago

0.2.4

9 months ago

0.2.3

10 months ago

0.2.2

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago