Skip to content

Commit bca3715

Browse files
committed
Rename form-callout to callout-form-element & adjust docstrings
1 parent b7a9484 commit bca3715

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

asset/css/callout.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
width: fit-content;
88
margin: 0 auto 1em;
99

10-
&.callout-fullwidth {
10+
&.callout-full-width {
1111
width: 100%;
1212
justify-content: start;
1313
}
1414

15-
&.form-callout {
15+
&.callout-form-element {
1616
margin-left: 14em;
1717
width: auto;
1818
justify-content: start;

src/Widget/Callout.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,32 @@
1212

1313
/**
1414
* An information box that can be used to display information to the user.
15-
* It consists of a set of standardized colors and icons that can be used to visually distinguish the type of
16-
* information.
17-
* A content string and an optional title can be passed to the constructor.
15+
* It consists of a set of standardized colors and icons that can be used to
16+
* visually distinguish the type of information. A content string and an
17+
* optional title can be passed to the constructor.
1818
*/
1919
class Callout extends BaseHtmlElement
2020
{
2121
use Translation;
2222

23+
/** @var string Classname for form-element callouts */
24+
protected const CLASS_FORM_ELEMENT = 'callout-form-element';
25+
26+
/** @var string Classname for full-width callouts */
27+
protected const CLASS_FULL_WIDTH = 'callout-full-width';
28+
2329
protected $tag = 'div';
2430

2531
protected $defaultAttributes = ['class' => 'callout'];
2632

2733
/**
2834
* Create a new callout
2935
*
30-
* @param CalloutType $type the type of the callout. The type determines the color and icon that is used.
31-
* @param ValidHtml|string $content the content of the callout
32-
* @param string|null $title an optional title, displayed above the content
36+
* The $type parameter determines the color and icon of the callout.
37+
*
38+
* @param CalloutType $type The type of the callout.
39+
* @param ValidHtml|string $content The content of the callout
40+
* @param string|null $title An optional title, displayed above the content
3341
*/
3442
public function __construct(
3543
protected CalloutType $type,
@@ -56,25 +64,29 @@ protected function assemble(): void
5664
}
5765

5866
/**
59-
* Callouts are only as wide as their content.
67+
* Set the callout width to be 100% of its parent container
68+
*
69+
* Callouts are normally only as wide as their content.
6070
* Setting it to fullwidth will force the callout to be as wide as its container.
6171
*
62-
* @param bool $fullwidth Whether the callout should be full width
72+
* @param bool $isFullWidth Whether the callout should be full width
6373
*
6474
* @return $this
6575
*/
66-
public function setFullwidth(bool $fullwidth = true): static
76+
public function setFullwidth(bool $isFullWidth = true): static
6777
{
68-
if ($fullwidth) {
69-
$this->addAttributes(Attributes::create(['class' => 'callout-fullwidth']));
78+
if ($isFullWidth) {
79+
$this->addAttributes(Attributes::create(['class' => static::CLASS_FULL_WIDTH]));
7080
} else {
71-
$this->removeAttribute('class', 'callout-fullwidth');
81+
$this->removeAttribute('class', static::CLASS_FULL_WIDTH);
7282
}
7383

7484
return $this;
7585
}
7686

7787
/**
88+
* Set up the callout to be used inside a form
89+
*
7890
* Setting this to true will allow the callout to be used for a single form element.
7991
* This is used to visually align the callout to the content of the form element.
8092
*
@@ -85,9 +97,9 @@ public function setFullwidth(bool $fullwidth = true): static
8597
public function setFormElement(bool $isFormElement = true): static
8698
{
8799
if ($isFormElement) {
88-
$this->addAttributes(Attributes::create(['class' => 'form-callout']));
100+
$this->addAttributes(Attributes::create(['class' => static::CLASS_FORM_ELEMENT]));
89101
} else {
90-
$this->removeAttribute('class', 'form-callout');
102+
$this->removeAttribute('class', static::CLASS_FORM_ELEMENT);
91103
}
92104

93105
return $this;

0 commit comments

Comments
 (0)