Package Exports
- @plumeria/core
- @plumeria/core/package.json
- @plumeria/core/processors
- @plumeria/core/stylesheet.css
Readme
@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, ps } from '@plumeria/core';
const styles = css.create({
box: {
width: '100%',
color: 'rgb(60,60,60)',
},
text: {
color: 'yellow',
},
});
const className = css.props(styles.text, styles.box);
Use css.props()
to convert a style object into a string with a hashed key.
You can use them like this:
<div className={css.props(styles.text, styles.box)} />
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.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
css.px
Pseudo expand helper:
css.px(ps.hover, ps.after);
// => ":hover::after"
px
is also available as an export function.
import { px } from '@plumeria/core';
๐งน ESLint Support
Use @plumeria/eslint-plugin for recommended rules:
Rules: recommended
- no-destructure: error
- 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.