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
backgroundColorType:ThemeColorBackground colour keyword
- Method
set_background_colorReturns:voidRetrieves the relevant properties from the component $attributes array or component defaults, validates them, and assigns them to the corresponding component instance field.
- Method
get_background_colorReturns:ThemeColorGet the background colour of the component.
- Method
update_background_colorReturns:voidAllows the background colour of a component to be set based on contextual factors not available at instantiation.
- Method
simplify_all_background_colorsReturns:voidClean 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_colorsReturns:voidIf this component has a background colour set, remove the same background from any children that have it to simplify HTML and CSS.
- Method
set_background_color_based_on_inner_componentsReturns:void
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use BackgroundColor;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_background_color($attributes);
}
}
BlockElementModifier
- Property
bladeFileType:string- Method
init_bem_structureReturns:static- Method
and_bemReturns:void- Method
set_bem_blockReturns:static- Method
set_bem_elementReturns:static- Method
set_bem_modifierReturns:static- Method
get_bem_structureReturns:array- Method
get_bem_classesReturns:array- Method
get_filtered_classesReturns:array- Method
get_bem_prefixReturns:string- Method
get_contextReturns:?string- Method
init_contextReturns:static- Method
with_explicit_contextReturns:static- Method
update_contextReturns:static- Method
set_shortnameReturns:void- Method
set_shortname_from_blade_fileReturns:void- Method
get_shortnameReturns:string
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use BlockElementModifier;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->init_bem_structure($attributes);
}
}
ColorTheme
- Property
colorThemeType:ThemeColorColour keyword for theming purposes.
- Method
set_color_themeReturns:voidRetrieves 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($attributes);
}
}
ContextHierarchy
- Property
bladeFileType:string- Method
get_contextReturns:?string- Method
init_contextReturns:static- Method
with_explicit_contextReturns:static- Method
update_contextReturns:static
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use ContextHierarchy;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->get_context($attributes);
}
}
GroupLayoutType
- Property
layoutType:GroupLayoutLayout style for grouping elements together.
- Property
maxPerRowType:intMaximum number of items to display per row in grid layouts.
- Method
set_group_layoutReturns:voidRetrieves 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 GroupLayoutType;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_group_layout($attributes);
}
}
Icon
- Property
iconPrefixType:?stringIcon prefix class name
- Property
iconType:?stringIcon class name
- Method
set_icon_from_attrsReturns: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);
}
}
ImageCropProperties
- Property
aspectRatioType:AspectRatioCrop image to the given aspect ratio by default
- Property
originalImageOrientationType:OrientationThe original orientation of the image; can be used as a data attribute to tweak CSS for cropping
- Property
focalPointType:?arrayThe focal point of the image to use when cropping - x and y values between 0 and 100
- Property
offsetType:?arrayThe percentage offsets of the image to use when cropping
- Method
set_aspect_ratio_from_attrsReturns:void- Method
set_original_image_orientation_from_attrsReturns:void- Method
set_focal_point_from_attrsReturns:void- Method
set_image_offset_from_attrsReturns:void- Method
get_local_css_propertiesReturns:string
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use ImageCropProperties;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_aspect_ratio_from_attrs($attributes);
}
}
LayoutAlignment
- Property
hAlignType:AlignmentHorizontal alignment, if applicable
- Property
vAlignType:AlignmentVertical alignment, if applicable
- Method
set_layout_alignmentReturns:voidRetrieves 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($attributes);
}
}
LayoutContainerSize
- Property
sizeType:ContainerSizeKeyword specifying the relative width of the container for the inner content if the component is not nested inside another layout component. Ignored if the component has an isNested attribute set to true, or other logic determines that it is not nested.
- Method
set_sizeReturns:voidRetrieves 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($attributes);
}
}
LayoutOrientation
- Property
orientationType:OrientationOrientation of the component content, if applicable
- Method
set_orientationReturns:voidRetrieves 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($attributes);
}
}
NestedState
- Method
set_is_nestedReturns:void- Method
get_is_nestedReturns:bool
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use NestedState;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_is_nested($attributes);
}
}
ShortName
- Method
set_shortnameReturns:void- Method
set_shortname_from_blade_fileReturns:void- Method
get_shortnameReturns:string
Example usage
namespace Doubleedesign\Comet\Core;
class MyComponent {
use ShortName;
function __construct(array $attributes, array $innerComponents) {
parent::__construct($attributes, $innerComponents);
$this->set_shortname($attributes);
}
}
TextAlign
- Property
textAlignType:Alignment- Method
set_text_align_from_attrsReturns:voidRetrieves 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);
}
}
