ui-awesome/html-svg

UI Awesome HTML SVG tag for PHP.

0.2.0 2024-03-31 13:02 UTC

This package is auto-updated.

Last update: 2024-12-06 02:39:08 UTC


README

UI Awesome HTML SVG Tag for PHP.


PHPUnit Codecov Infection Psalm Psalm Coverage Style ci

The svg element is a container that defines a new coordinate system and viewport.

It is used as the outermost element of SVG documents, but it can also be used to embed an SVG fragment inside an SVG or HTML document.

use UIAwesome\Html\Graphic\Svg;

echo Svg::widget()
    ->class('hidden')
    ->filePath(__DIR__ . '/svg/moon.svg')
    ->fill('currentColor')
    ->height(32)
    ->id('theme-toggle-dark-icon')
    ->width(32);

Installation

The preferred way to install this extension is through composer.

Either run

composer require --prefer-dist "ui-awesome/html-svg":"^0.1"

or add

"ui-awesome/html-svg": "^0.1"

to the require section of your composer.json file.

Usage

Instantiate the Svg class using Svg::widget().

$svg = Svg::widget();

Setting Attributes

Use the provided methods to set specific attributes for the a element.

// setting class attribute
$svg->class('container');

Or, use the attributes method to set multiple attributes at once.

$svg->attributes(['class' => 'container', 'style' => 'background-color: #eee;']);

Adding Content

If you want to include content within the svg tag, use the content method.

$svg->content('MyContent');

Rendering

Generate the HTML output using the render method, for simple instantiation.

$html = $svg->render();

Or, use the magic __toString method.

$html = (string) $svg;

Common Use Cases

Below are examples of common use cases:

// adding multiple attributes
$svg->class('external')->content('MyContent');

// setting the file path for the `HTML` output
$svg->filePath('/path/to/file')->render();

Explore additional methods for setting various attributes such as fill, heigth, lang, name, style, title, viewbox, width, xmlns, etc.

Attributes

Refer to the Attribute Tests for comprehensive examples.

The following methods are available for setting attributes:

Custom methods

Refer to the Custom Methods Tests for comprehensive examples.

The following methods are available for customizing the HTML output:

Testing

Check the documentation testing to learn about testing.

Support versions

PHP81

License

The MIT License (MIT). Please see License File for more information.

Our social networks

Twitter