-
Notifications
You must be signed in to change notification settings - Fork 2
Introduce Callout #358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TheSyscall
wants to merge
14
commits into
main
Choose a base branch
from
callouts
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−0
Open
Introduce Callout #358
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
dc48b8b
Implement Callout
TheSyscall e8b4336
Stylelint suggestions
TheSyscall eb54bbf
Left align fillwidth and form callouts
TheSyscall bed4d4c
Use constructor property promotion
TheSyscall f27828d
Allow ValidHtml as the callout body
TheSyscall 40fac24
Prefix css classes
TheSyscall 13f2811
Move convesion from string to Text into Callout::assemble
TheSyscall b7a9484
Apply suggestions from code review
TheSyscall bca3715
Rename form-callout to callout-form-element & adjust docstrings
TheSyscall 9b55d42
Apply suggestions from code review
TheSyscall b97d20e
Update src/Widget/Callout.php
TheSyscall 01c6fb9
Add comment to hardcoded margin
TheSyscall 3a9cce0
Apply suggestions from code review
TheSyscall 5628c30
Remove unused translation
TheSyscall File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Layout | ||
| .callout { | ||
| display: flex; | ||
| justify-content: center; | ||
| column-gap: 1em; | ||
|
|
||
| width: fit-content; | ||
| margin: 0 auto 1em; | ||
|
|
||
| &.callout-full-width { | ||
| width: 100%; | ||
| justify-content: start; | ||
| } | ||
|
|
||
| &.callout-form-element { | ||
| /* | ||
| * 14em is the width of the `control-label-group` element. This property value assumes that there are no | ||
| * special cases for which the label width differs. There is no way to get the width of the form label | ||
| * programmatically. | ||
| */ | ||
| margin-left: 14em; | ||
| width: auto; | ||
| justify-content: start; | ||
| } | ||
|
|
||
| i.icon::before { | ||
| margin-right: 0; | ||
| } | ||
|
|
||
| p { | ||
| margin: 0; | ||
| } | ||
|
|
||
| .callout-title { | ||
| margin-bottom: .5em; | ||
| } | ||
|
|
||
| .callout-text { | ||
| display: flex; | ||
| flex-direction: column; | ||
| } | ||
| } | ||
|
|
||
| // Style | ||
| .callout { | ||
| padding: .5em 1em; | ||
| border: 1px solid var(--callout-color); | ||
| background-color: color-mix(in srgb, var(--callout-color) 10%, transparent); | ||
| border-radius: .25em; | ||
|
|
||
| i.icon { | ||
| color: var(--callout-color); | ||
| font-size: 1.5em; | ||
| } | ||
|
|
||
| &.callout-type-info { | ||
| --callout-color: @color-pending; | ||
| } | ||
|
|
||
| &.callout-type-success { | ||
| --callout-color: @color-ok; | ||
| } | ||
|
|
||
| &.callout-type-warning { | ||
| --callout-color: @color-warning; | ||
| } | ||
|
|
||
| &.callout-type-error { | ||
| --callout-color: @color-critical; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
| namespace ipl\Web\Common; | ||
|
|
||
| use ipl\Web\Widget\Icon; | ||
|
|
||
| /** | ||
| * An enum containing all possible callout types for the {@see Callout} widget | ||
| */ | ||
| enum CalloutType: string | ||
| { | ||
| case Info = 'callout-type-info'; | ||
| case Success = 'callout-type-success'; | ||
| case Warning = 'callout-type-warning'; | ||
| case Error = 'callout-type-error'; | ||
|
|
||
| /** | ||
| * Get the icon element for use in the callout | ||
| * | ||
| * @return Icon | ||
| */ | ||
| public function getIcon(): Icon | ||
| { | ||
| return new Icon(match ($this) { | ||
| self::Info => 'circle-info', | ||
| self::Success => 'circle-check', | ||
| self::Warning => 'warning', | ||
| self::Error => 'circle-xmark', | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| <?php | ||
|
|
||
| namespace ipl\Web\Widget; | ||
|
|
||
| use ipl\Html\Attributes; | ||
| use ipl\Html\BaseHtmlElement; | ||
| use ipl\Html\HtmlElement; | ||
| use ipl\Html\Text; | ||
| use ipl\Html\ValidHtml; | ||
| use ipl\Web\Common\CalloutType; | ||
|
|
||
| /** | ||
| * Information box with a type specific color and icon | ||
| * | ||
| * The type controls both the color scheme and the icon. An optional title | ||
| * is displayed above the content. | ||
| */ | ||
|
TheSyscall marked this conversation as resolved.
|
||
| class Callout extends BaseHtmlElement | ||
|
jrauh01 marked this conversation as resolved.
|
||
| { | ||
| /** @var string Class name for form element callouts */ | ||
| protected const CLASS_FORM_ELEMENT = 'callout-form-element'; | ||
|
|
||
| /** @var string Class name for full width callouts */ | ||
| protected const CLASS_FULL_WIDTH = 'callout-full-width'; | ||
|
|
||
| protected $tag = 'div'; | ||
|
|
||
| protected $defaultAttributes = ['class' => 'callout']; | ||
|
|
||
| /** | ||
| * Create a new callout | ||
| * | ||
| * The $type parameter determines the color and icon of the callout. | ||
| * | ||
| * @param CalloutType $type The type of the callout | ||
| * @param ValidHtml|string $content The content of the callout | ||
| * @param ?string $title An optional title, displayed above the content | ||
| */ | ||
| public function __construct( | ||
| protected CalloutType $type, | ||
| protected ValidHtml|string $content, | ||
| protected ?string $title = null | ||
| ) { | ||
| $this->addAttributes(Attributes::create(['class' => $type->value])); | ||
| } | ||
|
|
||
| protected function assemble(): void | ||
| { | ||
| $this->addHtml($this->type->getIcon()); | ||
|
|
||
| $this->addHtml(HtmlElement::create( | ||
| 'div', | ||
| ['class' => 'callout-text'], | ||
| [ | ||
| $this->title | ||
| ? HtmlElement::create('strong', ['class' => 'callout-title'], Text::create($this->title)) | ||
| : null, | ||
| is_string($this->content) ? Text::create($this->content) : $this->content, | ||
| ], | ||
| )); | ||
| } | ||
|
|
||
| /** | ||
| * Set the callout width to 100% of its parent container | ||
| * | ||
| * Callouts are normally only as wide as their content. | ||
| * Setting it to full width will force the callout to be as wide as its container. | ||
| * | ||
| * @param bool $isFullWidth Whether the callout should be full width | ||
| * | ||
| * @return $this | ||
| */ | ||
| public function setFullWidth(bool $isFullWidth = true): static | ||
| { | ||
| if ($isFullWidth) { | ||
| $this->addAttributes(Attributes::create(['class' => static::CLASS_FULL_WIDTH])); | ||
| } else { | ||
| $this->removeAttribute('class', static::CLASS_FULL_WIDTH); | ||
| } | ||
|
|
||
| return $this; | ||
| } | ||
|
|
||
| /** | ||
| * Set up the callout to be used inside a form | ||
| * | ||
| * Setting this to true will allow the callout to be used for a single form element. | ||
| * This is used to visually align the callout to the content of the form element. | ||
| * | ||
| * @param bool $isFormElement Whether the callout should be used for a form element | ||
| * | ||
| * @return $this | ||
| */ | ||
| public function setFormElement(bool $isFormElement = true): static | ||
|
jrauh01 marked this conversation as resolved.
|
||
| { | ||
| if ($isFormElement) { | ||
| $this->addAttributes(Attributes::create(['class' => static::CLASS_FORM_ELEMENT])); | ||
| } else { | ||
| $this->removeAttribute('class', static::CLASS_FORM_ELEMENT); | ||
| } | ||
|
|
||
| return $this; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.