Trousers

@trousers/react

@trousers/react

Default export

Source

Classic React JSX factory that resolves the css and $ selection props before creating an element.

ts
function jsx<Props extends TrousersProps>(type: ElementType, props: Props | null, ...children: ReactNode[]): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;

classnames

Source

Resolve compiled styles and active selections into a string for className. Use selection keys without the $ prefix. Boolean modifiers activate on true, and named variants activate when the value matches a choice.

ts
function classnames<Styles extends CompiledStyles<VariantOptions>>(styles: Styles | false | null | undefined, selections?: Readonly<Record<string, VariantSelection>> & VariantSelections<Styles>): string;

Example

ts
classnames(button, { primary: true, size: 'm' });

Define static styles that the bundler plugin extracts into CSS. Apply the result with classnames, styled, or the JSX css prop. Use React's style prop for runtime values. Give the style definition a readable prefix in the emitted class names.

ts
function css(styles: CSSObject): CollectorReturn;
function css(id: string, styles: CSSObject): CollectorReturn;

Example

ts
const button = css('button', { borderRadius: 8 })
    .modifier('primary', { backgroundColor: '#f95b5b' });

Classic React JSX factory that resolves the css and $ selection props before creating an element.

ts
function jsx<Props extends TrousersProps>(type: ElementType, props: Props | null, ...children: ReactNode[]): import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>;

TrousersProps

Source

Styling props accepted by Trousers JSX, including $ modifier flags and variant choices.

ts
export type TrousersProps = {
    css?: CollectorReturn | false | null;
    className?: string;
    [selection: `$${string}`]: VariantSelection;
};

@trousers/react/jsx-runtime

Fragment

Source

Lets you group elements without a wrapper node.

ts
export { Fragment } from 'react';

Example

ts
```tsx
import { Fragment } from 'react';

<Fragment>
  <td>Hello</td>
  <td>World</td>
</Fragment>
text
ts
```tsx
// Using the <></> shorthand syntax:

<>
  <td>Hello</td>
  <td>World</td>
</>
text

Create an element through the automatic JSX runtime and resolve its Trousers props.

ts
function jsx(type: ElementType, props: TrousersProps, key?: Key): ReactElement;
ts
export type { JSX } from 'react/jsx-runtime';

Create an element with static children through the automatic Trousers JSX runtime.

ts
function jsxs(type: ElementType, props: TrousersProps, key?: Key): ReactElement;

@trousers/react/jsx-dev-runtime

Fragment

Source

Lets you group elements without a wrapper node.

ts
export { Fragment } from 'react';

Example

ts
```tsx
import { Fragment } from 'react';

<Fragment>
  <td>Hello</td>
  <td>World</td>
</Fragment>
text
ts
```tsx
// Using the <></> shorthand syntax:

<>
  <td>Hello</td>
  <td>World</td>
</>
text
ts
export type { JSX } from 'react/jsx-dev-runtime';

Development JSX runtime that resolves Trousers props and forwards React's debugging metadata.

ts
function jsxDEV(type: ElementType, props: TrousersProps, key: Key | undefined, isStaticChildren: boolean, source: Parameters<typeof reactJsxDEV>[4], self: unknown): ReactElement;