Skip to content

Commit a06a5a7

Browse files
committed
Implement a new WysiwygTabFormContainer, which can have an icon
1 parent 2761d4f commit a06a5a7

File tree

6 files changed

+150
-5
lines changed

6 files changed

+150
-5
lines changed
Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,29 @@
1-
{include file='shared_tabMenuFormContainer' __tabMenuCSSClassName='messageTabMenuNavigation'}
1+
<div id="{$container->getPrefixedId()}Container"{*
2+
*}{if !$container->getClasses()|empty} class="{implode from=$container->getClasses() item='class' glue=' '}{$class}{/implode}"{/if}{*
3+
*}{foreach from=$container->getAttributes() key='attributeName' item='attributeValue'} {$attributeName}="{$attributeValue}"{/foreach}{*
4+
*}{if !$container->checkDependencies()} hidden{/if}>
5+
<nav class="messageTabMenuNavigation jsOnly">
6+
<ul>
7+
{foreach from=$container item='child'}
8+
{if $child->isAvailable()}
9+
<li data-name="{$child->getPrefixedId()|rawurlencode}Container"{if !$child->checkDependencies()} hidden{/if}>
10+
<button type="button">
11+
{if $child->getIcon()}{icon name=$child->getIcon()}{/if}
12+
<span>{@$child->getLabel()}</span>
13+
</button>
14+
</li>
15+
{/if}
16+
{/foreach}
17+
</ul>
18+
</nav>
19+
20+
{include file='shared_formContainerChildren'}
21+
</div>
22+
23+
{include file='shared_formContainerDependencies'}
24+
25+
<script data-relocate="true">
26+
require(['WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/WysiwygTabMenu'], ({ WysiwygTabMenu }) => {
27+
new WysiwygTabMenu('{@$container->getPrefixedId()|encodeJS}Container');
28+
});
29+
</script>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Container visibility handler implementation for a wysiwyg tab menu that checks visibility
3+
* based on the visibility of its tab menu list items.
4+
*
5+
* @author Olaf BRaun
6+
* @copyright 2001-2025 WoltLab GmbH
7+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
8+
* @since 6.2
9+
*/
10+
11+
import Abstract from "./Abstract";
12+
import * as DependencyManager from "../Manager";
13+
import * as DomUtil from "../../../../../Dom/Util";
14+
15+
export class WysiwygTabMenu extends Abstract {
16+
public checkContainer(): void {
17+
// only consider containers that have not been hidden by their own dependencies
18+
if (DependencyManager.isHiddenByDependencies(this._container)) {
19+
return;
20+
}
21+
22+
const containerIsVisible = !this._container.hidden;
23+
const listItems = this._container.parentNode!.querySelectorAll(
24+
"#" + DomUtil.identify(this._container) + " > nav > ul > li",
25+
);
26+
const containerShouldBeVisible = Array.from(listItems).some((child: HTMLElement) => !child.hidden);
27+
28+
if (containerIsVisible !== containerShouldBeVisible) {
29+
this._container.hidden = !containerShouldBeVisible;
30+
31+
// check containers again to make sure parent containers can react to
32+
// changing the visibility of this container
33+
DependencyManager.checkContainers();
34+
}
35+
}
36+
}

wcfsetup/install/files/js/WoltLabSuite/Core/Form/Builder/Field/Dependency/Container/WysiwygTabMenu.js

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygFormContainer.class.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use wcf\system\event\EventHandler;
99
use wcf\system\form\builder\button\wysiwyg\WysiwygPreviewFormButton;
1010
use wcf\system\form\builder\container\FormContainer;
11-
use wcf\system\form\builder\container\TabFormContainer;
1211
use wcf\system\form\builder\field\TMaximumLengthFormField;
1312
use wcf\system\form\builder\field\TMinimumLengthFormField;
1413
use wcf\system\form\builder\field\wysiwyg\WysiwygAttachmentFormField;
@@ -509,20 +508,23 @@ public function populate()
509508
->appendChildren([
510509
$this->smiliesContainer,
511510

512-
TabFormContainer::create($this->wysiwygId . 'AttachmentsTab')
511+
WysiwygTabFormContainer::create($this->wysiwygId . 'AttachmentsTab')
513512
->addClass('formAttachmentContent')
514513
->label('wcf.attachment.attachments')
514+
->setIcon('paperclip')
515515
->appendChild(
516516
FormContainer::create($this->wysiwygId . 'AttachmentsContainer')
517517
->appendChild($this->attachmentField)
518518
),
519519

520-
TabFormContainer::create($this->wysiwygId . 'SettingsTab')
520+
WysiwygTabFormContainer::create($this->wysiwygId . 'SettingsTab')
521521
->label('wcf.message.settings')
522+
->setIcon('gear')
522523
->appendChild($this->settingsContainer),
523524

524-
TabFormContainer::create($this->wysiwygId . 'PollTab')
525+
WysiwygTabFormContainer::create($this->wysiwygId . 'PollTab')
525526
->label('wcf.poll.management')
527+
->setIcon('chart-bar')
526528
->appendChild($this->pollContainer),
527529
]),
528530
]);

wcfsetup/install/files/lib/system/form/builder/container/wysiwyg/WysiwygSmileyFormContainer.class.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,12 @@ public function populate()
7676
$this->addClass('messageTabMenu');
7777
}
7878
}
79+
80+
/**
81+
* @see WysiwygTabFormContainer::getIcon()
82+
*/
83+
public function getIcon(): string
84+
{
85+
return 'face-smile';
86+
}
7987
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace wcf\system\form\builder\container\wysiwyg;
4+
5+
use wcf\system\form\builder\container\TabFormContainer;
6+
7+
/**
8+
* Represents a container that is a tab of a wysiwyg tab menu.
9+
*
10+
* @author Olaf Braun
11+
* @copyright 2001-2025 WoltLab GmbH
12+
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
13+
* @since 6.2
14+
*/
15+
class WysiwygTabFormContainer extends TabFormContainer
16+
{
17+
protected ?string $icon = null;
18+
19+
/**
20+
* Gets the icon associated with the tab.
21+
*/
22+
public function getIcon(): ?string
23+
{
24+
return $this->icon;
25+
}
26+
27+
/**
28+
* Sets the icon associated with the tab.
29+
*/
30+
public function setIcon(?string $icon): static
31+
{
32+
$this->icon = $icon;
33+
34+
return $this;
35+
}
36+
}

0 commit comments

Comments
 (0)