N°2847 - Alert: Add properties to set if closable or collapsible

This commit is contained in:
Molkobain
2020-12-22 17:22:51 +01:00
parent 874bf38316
commit fc3f096823
3 changed files with 84 additions and 9 deletions

View File

@@ -77,6 +77,10 @@ class Alert extends UIBlock
/** @var string DEFAULT_COLOR */
public const DEFAULT_COLOR = self::ENUM_COLOR_NEUTRAL;
/** @var bool Default value for static::$bIsClosable */
public const DEFAULT_IS_CLOSABLE = true;
/** @var bool Default value for static::$bIsCollapsible */
public const DEFAULT_IS_COLLAPSIBLE = true;
/** @var string $sTitle */
protected $sTitle;
@@ -84,6 +88,10 @@ class Alert extends UIBlock
protected $sContent;
/** @var string $sColor */
protected $sColor;
/** @var bool Whether the alert can be closed or not */
protected $bIsClosable;
/** @var bool Whether the alert can be collapsed or not */
protected $bIsCollapsible;
/** @var bool */
protected $bIsOpenedByDefault;
@@ -103,6 +111,8 @@ class Alert extends UIBlock
$this->sTitle = $sTitle;
$this->sContent = $sContent;
$this->sColor = $sColor;
$this->bIsClosable = static::DEFAULT_IS_CLOSABLE;
$this->bIsCollapsible = static::DEFAULT_IS_COLLAPSIBLE;
$this->bIsOpenedByDefault = $bIsOpenedByDefault;
parent::__construct($sId);
}
@@ -170,9 +180,61 @@ class Alert extends UIBlock
return $this;
}
public function IsOpenedByDefault()
/**
* @see self::$bIsClosable
* @return bool
*/
public function IsClosable(): bool
{
return $this->bIsOpenedByDefault;
return $this->bIsClosable;
}
/**
* @see self::$bIsClosable
* @param bool $bIsClosable
*
* @return $this
*/
public function SetIsClosable(bool $bIsClosable)
{
$this->bIsClosable = $bIsClosable;
return $this;
}
/**
* @see self::$bIsCollapsible
* @return bool
*/
public function IsCollapsible(): bool
{
return $this->bIsCollapsible;
}
/**
* @see self::$bIsCollapsible
* @param bool $bIsCollapsible
*
* @return $this
*/
public function SetIsCollapsible(bool $bIsCollapsible)
{
$this->bIsCollapsible = $bIsCollapsible;
return $this;
}
/**
* @return bool
*/
public function IsOpenedByDefault(): bool
{
if($this->IsCollapsible()) {
return $this->bIsOpenedByDefault;
}
else {
return true;
}
}
/**

View File

@@ -1,11 +1,20 @@
<div id="{{ oUIBlock.GetId() }}"
class="ibo-alert ibo-is-{{ oUIBlock.GetColor() }}{% if oUIBlock.IsOpenedByDefault() %} ibo-is-opened{% endif %}">
<div class="ibo-alert--action-button ibo-alert--maximize-button" data-role="ibo-alert--collapse-toggler"><i
class="fas fa-caret-down"></i></div>
<div class="ibo-alert--action-button ibo-alert--minimize-button" data-role="ibo-alert--collapse-toggler"><i
class="fas fa-caret-up"></i>
</div>
<div class="ibo-alert--action-button ibo-alert--close-button" data-role="ibo-alert--close-button"><i class="fas fa-times"></i></div>
<div class="ibo-alert--title" data-role="ibo-alert--collapse-toggler">{{ oUIBlock.GetTitle() }}</div>
{% if oUIBlock.IsCollapsible() %}
<div class="ibo-alert--action-button ibo-alert--maximize-button" data-role="ibo-alert--collapse-toggler">
<i class="fas fa-caret-down"></i>
</div>
<div class="ibo-alert--action-button ibo-alert--minimize-button" data-role="ibo-alert--collapse-toggler">
<i class="fas fa-caret-up"></i>
</div>
{% endif %}
{% if oUIBlock.IsClosable() %}
<div class="ibo-alert--action-button ibo-alert--close-button" data-role="ibo-alert--close-button">
<i class="fas fa-times"></i>
</div>
{% endif %}
<div class="ibo-alert--title"
{% if oUIBlock.IsCollapsible() %}data-role="ibo-alert--collapse-toggler"{% endif %}
>{{ oUIBlock.GetTitle() }}</div>
<div class="ibo-alert--body">{{ oUIBlock.GetContent()|raw }}</div>
</div>

View File

@@ -78,6 +78,10 @@ $oPageContentLayout->AddMainBlock(AlertFactory::MakeForDanger('Alert for danger'
$oPageContentLayout->AddMainBlock(AlertFactory::MakeForFailure('Alert for failure', $sContent));
$oPageContentLayout->AddMainBlock(AlertFactory::MakeWithBrandingPrimaryColor('Alert with branding primary color', $sContent));
$oPageContentLayout->AddMainBlock(AlertFactory::MakeWithBrandingSecondaryColor('Alert with branding secondary color', $sContent));
$oAlertNonClosable = AlertFactory::MakeNeutral('Alert not closable, not collapsable', $sContent)
->SetIsClosable(false)
->SetIsCollapsible(false);
$oPageContentLayout->AddMainBlock($oAlertNonClosable);
$oPageContentLayout->AddMainBlock(new Html('<hr/>'));