tsx-util
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

TSX Util

Utility functions for working with html in typescript and tsx.

cn

Builds a className string from a list of (conditional) class names.

function cn(...classNames: (string | false | undefined)[]): string;

// Example
<button className={cn('my-button', animated && 'animated', props.className)} />;

ifTrue

Converts an (optional) boolean to true or undefined. Can be used to set an attribute conditionally.

function ifTrue(value: boolean | undefined): true | undefined;

// Example
<input data-disabled={ifTrue(disabled)} />;

ifFalse

Returns true if the value is false, otherwise undefined. Can be used to set an attribute conditionally.

function ifFalse(value: boolean | undefined): true | undefined;

// Example
<input data-valid={ifFalse(invalid)} />;

/tsx-util/

    Package Sidebar

    Install

    npm i tsx-util

    Weekly Downloads

    1

    Version

    0.1.2

    License

    none

    Unpacked Size

    4.62 kB

    Total Files

    6

    Last publish

    Collaborators

    • freehour