ui-awesome / html-svg
UI Awesome HTML SVG tag for PHP.
Installs: 1 316
Dependents: 7
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: ^8.1
- ext-dom: *
- ext-libxml: *
- enshrined/svg-sanitize: ^0.18
- php-forge/awesome-widget: ^0.1
- ui-awesome/html-attribute: ^0.2
- ui-awesome/html-concern: ^0.2
- ui-awesome/html-core: ^0.1
- ui-awesome/html-interop: ^0.1
Requires (Dev)
- maglnet/composer-require-checker: ^4.7
- php-forge/support: ^0.1
- phpunit/phpunit: ^10.5
- roave/infection-static-analysis-plugin: ^1.34
- symplify/easy-coding-standard: ^12.1
- vimeo/psalm: ^5.20
This package is auto-updated.
Last update: 2024-12-06 02:39:08 UTC
README
UI Awesome HTML SVG Tag for PHP.
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
License
The MIT License (MIT). Please see License File for more information.