Search by

ui-awesome / html-attribute

terabytesoftw

Type-safe traits and backed enums for HTML attribute composition: global attributes, ARIA, data-*, events, and element-specific setters.

Package info

github.com/ui-awesome/html-attribute

pkg:composer/ui-awesome/html-attribute

Statistics

Installs: 60 231

Dependents: 5

Suggesters: 0

Stars: 1

Open Issues: 0

0.8.2 2026-11-15 14:45 UTC

README

UI Awesome

Html Attribute


PHPUnit Coverage Mutation Testing PHPStan

Features

Feature Overview

A focused library for building and rendering structured HTML attributes
Type-safe helpers and value objects to compose complex attribute structures (classes, data-attributes, ARIA, etc.).

Installation

composer require ui-awesome/html-attribute:^0.8

Quick start

Compose reusable attribute APIs by combining the package traits with the immutable attribute mixin.

<?php

declare(strict_types=1);

namespace App;

use UIAwesome\Html\Attribute\Global\{HasClass, HasData, HasId};
use UIAwesome\Html\Attribute\HasRel;
use UIAwesome\Html\Attribute\Values\Rel;
use UIAwesome\Html\Helper\Attributes;
use UIAwesome\Html\Mixin\HasAttributes;

final class LinkAttributes
{
    use HasAttributes;
    use HasClass;
    use HasData;
    use HasId;
    use HasRel;

    public function render(): string
    {
        return Attributes::render($this->getAttributes());
    }
}

$attributes = (new LinkAttributes())
    ->id('documentation')
    ->class('nav-link')
    ->class('is-active')
    ->rel(Rel::NOOPENER)
    ->addDataAttribute('tracking', 'docs');

echo '<a' . $attributes->render() . ' href="/docs">Documentation</a>';
// <a class="nav-link is-active" id="documentation" rel="noopener" data-tracking="docs" href="/docs">Documentation</a>

Documentation

For detailed configuration options and advanced usage, see the repository:

AI assistance

AI agents: read the documentation index and fetch the Markdown version of a page by appending index.md to its URL. The AI agents guide covers skill installation, client setup and verification.

Match the installed package revision. If hosted documentation does not match or is unavailable, use the repository guides, the installed skill source at skills/ui-awesome-html-attribute/SKILL.md, the source PHPDoc and the changelog. The package-specific AI guide is available in the repository after the pending skill changes are published. This package is framework-independent and does not render HTML by itself; rendering comes from ui-awesome/html-helper.

Package information

PHP Latest Stable Version Total Downloads

Project status

PHPStan Level Max Quality StyleCI

Security

OpenSSF Scorecard Zizmor

Built with AI

Built with Claude Code Built with Codex Reviewed by CodeRabbit

Our social networks

Follow on X Follow on Facebook

License

License