Component Traits
PHP traits are used to provide common implementations of an attribute's conversion from $attributes
array element to object field.
This provides a central location for validation logic and documentation, reducing duplication and ensuring consistency.
BackgroundColor
- Property
backgroundColor
Type:ThemeColor
Background colour keyword
- Method
set_background_color_from_attrs
Returns:void
Retrieves the relevant properties from the component $attributes array, validates them, and assigns them to the corresponding component instance field.
- Method
get_background_color
Returns:ThemeColor
Get the background colour of the component.
- Method
set_background_color
Returns:void
Allows the background colour of a component to be set based on contextual factors not available at instantiation.
- Method
simplify_all_background_colors
Returns:void
Clean up duplication of background colours between this and its inner components simplify HTML and CSS. Runs either remove_redundant_background_colors() or set_background_color_based_on_children() as appropriate.
- Method
remove_redundant_background_colors
Returns:void
If this component has a background colour set, remove the same background from any children that have it to simplify HTML and CSS. This method is public as there are some components where we want to do this, but not assign a background colour to the component.
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use BackgroundColor;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_background_color_from_attrs($attributes);
}
}
ColorTheme
- Property
colorTheme
Type:ThemeColor
Colour keyword for the fill or outline colour
- Method
set_color_theme_from_attrs
Returns:void
Retrieves the relevant properties from the component $attributes array, validates them, and assigns them to the corresponding component instance field.
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use ColorTheme;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_color_theme_from_attrs($attributes);
}
}
Icon
- Property
iconPrefix
Type:?string
Icon prefix class name
- Property
icon
Type:?string
Icon class name
- Method
set_icon_from_attrs
Returns:void
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use Icon;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_icon_from_attrs($attributes);
}
}
LayoutAlignment
- Property
hAlign
Type:Alignment
- Property
vAlign
Type:Alignment
- Method
set_layout_alignment_from_attrs
Returns:void
Retrieves the relevant properties from the component $attributes array, validates them, and assigns them to the corresponding component instance field.
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use LayoutAlignment;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_layout_alignment_from_attrs($attributes);
}
}
LayoutContainerSize
- Property
size
Type:ContainerSize
Keyword specifying the relative width of the container for the inner content
- Method
set_size_from_attrs
Returns:void
Retrieves the relevant properties from the component $attributes array, validates them, and assigns them to the corresponding component instance field.
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use LayoutContainerSize;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_size_from_attrs($attributes);
}
}
LayoutOrientation
- Property
orientation
Type:Orientation
- Method
set_orientation_from_attrs
Returns:void
Retrieves the relevant properties from the component $attributes array, validates them, and assigns them to the corresponding component instance field.
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use LayoutOrientation;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_orientation_from_attrs($attributes);
}
}
TextAlign
- Property
textAlign
Type:Alignment
- Method
set_text_align_from_attrs
Returns:void
Retrieves the relevant properties from the component $attributes array, validates them, and assigns them to the corresponding component instance field.
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use TextAlign;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_text_align_from_attrs($attributes);
}
}
TextColor
- Property
textColor
Type:ThemeColor
- Method
set_text_color_from_attrs
Returns:void
Retrieves the relevant properties from the component $attributes array, validates them, and assigns them to the corresponding component instance field.
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use TextColor;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_text_color_from_attrs($attributes);
}
}