Pattern
API reference › HTML SVG › Pattern
Represents the SVG <pattern> element for defining reusable patterns.
Provides a concrete <pattern> element implementation that returns SvgBlock::PATTERN and provides geometry,
linking, pattern, and view attribute methods.
The <pattern> element defines a pattern that can be referenced by fill and stroke attributes.
Usage example:
use UIAwesome\Html\Svg\{Pattern, Rect};
echo Pattern::tag() ->id('tile') ->x(0) ->y(0) ->width(4) ->height(4) ->content(Rect::tag()->x(0)->y(0)->width(4)->height(4)->fill('currentColor')) ->render();See also: https://developer.mozilla.org/en-US/docs/Web/SVG/Element/pattern (BaseBlock for the base block-level implementation.).
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$attributes protected | mixed[] | HTML attributes array used by the implementing class. Default: []. | UIAwesome\ |
$content protected | string | Content string assigned to the element. Default: ''. | UIAwesome\ |
Methods
Section titled “Methods”Method details
Section titled “Method details”height()
Section titled “height() ”public function height(int|string|Stringable|UnitEnum|null $value): staticSets the height attribute.
Usage example:
$element->height(200);$element->height('50%');$element->height('auto');Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int|Stringable|UnitEnum| | Height value in pixels or CSS units, or null to remove the attribute. |
Returns
static: New instance with the updated height attribute.
href()
Section titled “href() ”public function href(string|Stringable|UnitEnum|null $value): staticSets the href attribute.
Usage example:
$element->href('#pattern');$element->href(null);Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string|Stringable|UnitEnum| | URL, path, or fragment, or null to remove the attribute. |
Returns
static: New instance with the updated href attribute.
patternContentUnits()
Section titled “patternContentUnits() ”public function patternContentUnits(UIAwesome\Html\Svg\Values\CoordinateUnits|string|null $value): staticSets the SVG patternContentUnits attribute for the <pattern> element.
Creates a new instance with the specified pattern content units value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Pattern content units value (for example, ‘userSpaceOnUse’, CoordinateUnits enum, or null to unset). |
Returns
static: New instance with the updated patternContentUnits attribute.
Throws
InvalidArgumentException: If the provided value is not a validCoordinateUnitsenum or string.
patternTransform()
Section titled “patternTransform() ”public function patternTransform(string|null $value): staticSets the SVG patternTransform attribute for the <pattern> element.
Creates a new instance with the specified pattern transform value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | Transform value (for example, ‘rotate(45)’, ‘scale(2)’, or null to unset). |
Returns
static: New instance with the updated patternTransform attribute.
patternUnits()
Section titled “patternUnits() ”public function patternUnits(UIAwesome\Html\Svg\Values\CoordinateUnits|string|null $value): staticSets the SVG patternUnits attribute for the <pattern> element.
Creates a new instance with the specified pattern units value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Pattern units value (for example, ‘objectBoundingBox’, CoordinateUnits enum, or null to unset). |
Returns
static: New instance with the updated patternUnits attribute.
Throws
InvalidArgumentException: If the provided value is not a validCoordinateUnitsenum or string.
preserveAspectRatio()
Section titled “preserveAspectRatio() ”public function preserveAspectRatio(UIAwesome\Html\Svg\Values\PreserveAspectRatio|string|null $value): staticSets the SVG preserveAspectRatio attribute for the element.
Creates a new instance with the specified preserve aspect ratio value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | UIAwesome\| | Preserve aspect ratio value (for example, ‘xMidYMid meet’, PreserveAspectRatio enum, or null to unset). |
Returns
static: New instance with the updated preserveAspectRatio attribute.
Throws
InvalidArgumentException: If the provided value is not a validPreserveAspectRatioenum or string.
viewBox()
Section titled “viewBox() ”public function viewBox(string|null $value): staticSets the SVG viewBox attribute for the element.
Creates a new instance with the specified view box value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | string| | ViewBox value (for example, ‘0 0 100 100’, or null to unset). |
Returns
static: New instance with the updated viewBox attribute.
width()
Section titled “width() ”public function width(int|string|Stringable|UnitEnum|null $value): staticSets the width attribute.
Usage example:
$element->width(400);$element->width('50%');$element->width('auto');$element->width(null);Parameters
| Parameter | Type | Description |
|---|---|---|
$value | int|Stringable|UnitEnum| | Width value in pixels or CSS units, or null to remove the attribute. |
Returns
static: New instance with the updated width attribute.
public function x(float|int|string|null $value): staticSets the SVG x attribute for the element.
Creates a new instance with the specified x-coordinate value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | X coordinate value (for example, ‘10’, ‘10.3’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated x attribute.
public function y(float|int|string|null $value): staticSets the SVG y attribute for the element.
Creates a new instance with the specified y-coordinate value for the rendered element.
Parameters
| Parameter | Type | Description |
|---|---|---|
$value | float| | Y coordinate value (for example, ‘20’, ‘10.3’, ‘50%’, or null to unset). |
Returns
static: New instance with the updated y attribute.
getTag()
Section titled “getTag() ”protected function getTag(): BackedEnumReturns the tag enumeration for the <pattern> element.
Returns
BackedEnum: Tag enumeration instance for <pattern>. SvgBlock for valid SVG block-level tags.