facy - v0.1.0
    Preparing search index...

    Class ElementTag<T>

    Subclass of ComposableTag that manages an Element and allows setting attributes and CSS classes.

    Type Parameters

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    VALUES: WeakMap<Element, any> = ...

    Methods

    • Manually give this element an ID. Make sure it is always unique within the entire document! If you don't care about the exact value, calling ElementTag.getId will assign a unique one for you. We recommend using classes instead of IDs for styling anyway.

      Parameters

      • value: string

      Returns this

    • Returns the ID of this element. If the element doesn't have one yet, a random one is generated and assigned for you.

      Returns string

    • Give this tag a name, which is used to add a main CSS class that identifies this tag and aids debugging. Required when using state!

      Parameters

      • name: string

      Returns this

      CONFIG.deriveMainClass to customize how the CSS class is generated

    • Convenience alias for ElementTag.withClasses that allows passing classes as a variable number of arguments.

      Parameters

      • ...classes: MaybeReactive<string>[]

      Returns this

    • Set the given CSS classes on the managed element, either as an optionally reactive array of class names or an object whose keys represent class names and whose optionally reactive values enable or disable them based on truthiness. In the latter case, the keys are transformed to class names using CONFIG.formatClass, which allows for more JS-friendly keys.

      Parameters

      • classes: MaybeReactive<string[]> | Record<string, any>

      Returns this

      With default config, `{ myCoolClass: true }` results in the class `my-cool-class` being set.
      

      This replaces any existing classes set with this method or ElementTag.withClass.

    • Sets CSS classes that describe element state.

      You provide the state as an object whose keys represent state names and whose corresponding, optionally reactive values enable or disable them based on truthiness.

      Parameters

      • state: Record<string, MaybeReactive<Truthiness>>

      Returns this

      With default configuration and a tag name set to `user-form`, passing
      `{ validField: errors.derive(e => e.length === 0) }`
      sets or removes the class `user-form--valid-field` when the given condition evaluates to truthy or falsy respectively.
      • The tag needs to have a name for this to work!
      • Replaces any existing state config.

      CONFIG.deriveStateClass to customize how corresponding CSS classes are generated.

    • Convenience function to set multiple attributes at once as an object that maps key-value pairs.

      Parameters

      • attributes: Record<string, MaybeReactive<any>>

      Returns this

    • Sets a single attribute with the given name and value. Overriding an existing attribute discards the previous one.

      Parameters

      • name: string
      • value: any

      Returns this

      Since boolean attributes are considered to be true simply by being present on an element, regardless of their value, an empty attribute is set when the given value is strictly equal to true. If the value is otherwise truthy, it is converted to a string by the browser. In all other cases, if an attribute already exists, it is removed. However, there is an important exception for value attributes (attributes with the name "value").

    • Associates this element with the given value. Passing null or undefined removes any previously set value. The value is stored internally as is, so it can be used by e.g. InputTag to efficiently link radio, checkbox and select options. If this element has a value property (i.e. it's an input element), that is updated. Otherwise, if the value is a string or number, a "value" attribute is created or updated with it, Otherwise, if such an attribute already exists, it is removed.

      Parameters

      • value: any

      Returns this