Plumeria logo/ ✾ Plumeria
API reference

px

Overview

The px() function — short for Pseudo Expand — allows you to combine multiple pseudo-class strings into one unified selector.

It’s useful when working with Plumeria’s pseudo utilities like ps.hover, ps.active, or custom ps.fn.has().
The result is a single joined pseudo selector string that can be passed into css.create() or other style utilities.

✅ Designed to work with pseudo-class utility strings — not general-purpose string concatenation.


Purpose

When defining styles for complex pseudo states (:hover:focus, :has(div):focus-visible, etc.), manually writing strings becomes error-prone.
The px() function ensures type-safe composition of pseudo strings while preserving string literal types for DX and autocomplete.


Example

TypeScript
import { px } from '@plumeria/core';
 
const combined = px(
  ps.active,
  ps.focusVisible,
  ps.fn.has('div')
);
 
// Result:
// ':active:focus-visible:has(div)'

You can use the combined result in your styles:

const styles = css.create({
  container: {
    [px(ps.hover, ps.focusVisible)]: {
      background: 'lightblue',
    },
  },
});

Return value

Returns a joined pseudo selector string, preserving literal types:

const result = px(ps.hover, ps.focusVisible);
// type: ':hover:focus-visible'

Use cases

  • Combine standard pseudo-classes:
px(ps.hover, ps.focus)
  • Combine functional and state pseudo-classes:
px(ps.fn.has('input'), ps.focusVisible)

Type-safety benefit

Since px() preserves string literal types, you get full type-checking and editor autocomplete — even for composed pseudo selectors.

On this page

;