A Class to help Manage Classes for Components

Hierarchy

  • ClassNames

Constructors

Properties

classes: string[] = []

Stores the Classes in this Instance

Accessors

  • get length(): number
  • Returns the number of values in this instance

    Returns number

Methods

  • Returns an array of values matching the search criteria

    Parameters

    • input: string | RegExp

      value to look for

    Returns string[]

  • Returns if this instance has a value matching the pattern

    Parameters

    • lookingFor: string | RegExp

      Patter to look for in this instances values

    Returns boolean

  • Add Classes to Instance if a Pattern is found in the Instance

    Returns

    this instance

    Parameters

    • pattern: string | RegExp

      the Pattern or class to look for

    • values: string | ClassNames

      values to be added if pattern is found

    Returns ClassNames

  • Add Classes to Instance if a Pattern is not found in the Instance

    Returns

    this instance

    Parameters

    • pattern: string | RegExp

      the Pattern or class to look for

    • values: string | ClassNames

      values to be added if pattern is not found

    Returns ClassNames

  • Remove Classes to Instance if a Pattern is not found in the Instance

    Returns

    this instance

    Parameters

    • pattern: string | RegExp

      the Pattern or class to look for

    • values: string | RegExp

      values to be Removed if pattern is not found

    Returns ClassNames

  • Remove Classes to Instance if a Pattern is found in the Instance

    Returns

    this instance

    Parameters

    • pattern: string | RegExp

      the Pattern or class to look for

    • values: string | RegExp

      values to be Removed if pattern is found

    Returns ClassNames

  • Validate if the provided value is an Array

    Returns

    if value is an array

    Parameters

    • value: any

      value to check

    Returns value is []

  • Check if the Provided Value is an Instance of ClassNames

    Returns

    if the value is an instance of ClassNames

    Parameters

    • value: any

      Value to Check

    Returns value is ClassNames

  • Check if this instance is empty

    Returns boolean

  • Returns this instances values as a string.

    <h1 classNames={ new ClassNames("text-xl").list() }>Hello World!</h1>

    Parameters

    Returns string

  • Convert the provided value to an Array

    Returns

    the value as an array

    Type Parameters

    • T = any

    Parameters

    • value: T | T[]

      value to convert

    Returns T[]

  • Act like a Switch Case for Added Classes

    Usage

    new ClassNames<"success" | "danger">(["rounded text-white px-4 py-2"])
    .switch(btnType, {
    "success": "bg-emerald-700",
    "danger": "bg-red-700"
    }, "bg-sky-700")

    Returns

    this instance

    Type Parameters

    • T extends string | number | symbol = string

      Union of Expected Potential Values of onValue

    Parameters

    • onValue: string | number | symbol

      The the Value to Switch On

    • options: Partial<Record<T, ClassNameAddValue>>

      Object Containing Possible Values and there Keys

    • Optional defaultValue: ClassNameAddValue

      Optional Default Value

    Returns ClassNames

  • Returns this instances values as a string

    Alias of .list()

    Returns string

  • Static accessor to isClassNames

    Shortcut Of new ClassNames().isClassNames(value)

    Returns

    if the provided value is an instance of ClassNames

    Parameters

    • value: any

      value to check

    Returns boolean

Generated using TypeDoc