Skip to content
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

Add support to add label to menu group #1847

Draft
wants to merge 6 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions demos/init-app.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,10 @@ public static function get_class(\Closure $createAnonymousClassFx): string
$layout->addMenuItem(['Sliding Panel'], [$path . 'layout-panel'], $menu);

$path = $demosUrl . 'basic/';
$menu = $layout->addMenuGroup(['Basics', 'icon' => 'cubes']);
$menu = $layout->addMenuGroup(['Basics', 'label' => ['10', 'class.red' => true]]);
$layout->addMenuItem('View', [$path . 'view'], $menu);
$layout->addMenuItem('Button', [$path . 'button'], $menu);
$layout->addMenuItem('Header', [$path . 'header'], $menu);
$layout->addMenuItem(['Button', 'label' => ['10', 'class.red' => true]], [$path . 'button'], $menu);
$layout->addMenuItem(['Header', 'icon' => 'edit'], [$path . 'header'], $menu);
$layout->addMenuItem('Message', [$path . 'message'], $menu);
$layout->addMenuItem('Labels', [$path . 'label'], $menu);
$layout->addMenuItem('Menu', [$path . 'menu'], $menu);
Expand All @@ -174,9 +174,11 @@ public static function get_class(\Closure $createAnonymousClassFx): string
$layout->addMenuItem(['HTML Layout'], [$path . 'html-layout'], $menu);
$layout->addMenuItem(['Conditional Fields'], [$path . 'jscondform'], $menu);

$layout->addMenuItem(['Chats', 'label' => ['10', 'class.red' => true]], [$path . '..']);

$path = $demosUrl . 'form-control/';
$menu = $layout->addMenuGroup(['Form Controls', 'icon' => 'keyboard outline']);
$layout->addMenuItem(['Input'], [$path . 'input2'], $menu);
$layout->addMenuItem(['Input', 'label' => ['10', 'class.red' => true]], [$path . 'input2'], $menu);
$layout->addMenuItem('Input Decoration', [$path . 'input'], $menu);
$layout->addMenuItem('Calendar', [$path . 'calendar'], $menu);
$layout->addMenuItem(['Checkboxes'], [$path . 'checkbox'], $menu);
Expand Down
7 changes: 5 additions & 2 deletions docs/app.md
Original file line number Diff line number Diff line change
Expand Up @@ -447,8 +447,11 @@ $layout = $app->layout;
$layout->menuLeft->addItem(['Welcome Page', 'icon' => 'gift'], ['index']);
$layout->menuLeft->addItem(['Layouts', 'icon' => 'object group'], ['layouts']);

$EditGroup = $layout->menuLeft->addGroup(['Edit', 'icon' => 'edit']);
$EditGroup->addItem('Basics', ['edit/basic']);
$editGroup = $layout->menuLeft->addGroup(['Edit', 'icon' => 'edit']);
$editGroup->addItem('Basics', ['edit/basic']);

$newsGroup = $layout->menuLeft->addGroup(['News', 'label' => ['28', 'class.red' => true]]);
$newsGroup->addItem('Emails', ['news/emails']);
```

:::{php:attr} menu
Expand Down
6 changes: 4 additions & 2 deletions src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function addMenu($name)
$name = [$name];
}

$label = $name['title'] ?? $name['text'] ?? $name['name'] ?? $name[0] ?? null;
$label = $name['title'] ?? $name[0] ?? null;

if ($label !== null) {
$subMenu->template->set('label', $label);
Expand Down Expand Up @@ -123,14 +123,16 @@ public function addGroup($name, string $template = 'menugroup.html')
$name = [$name];
}

$title = $name['title'] ?? $name['text'] ?? $name['name'] ?? $name[0] ?? null;
$title = $name['title'] ?? $name[0] ?? null;

if ($title !== null) {
$group->template->set('title', $title);
}

if (isset($name['icon'])) {
Icon::addTo($group, [$name['icon']], ['Icon'])->removeClass('item');
} elseif (isset($name['label'])) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caveat: It would be better if the items were right-aligned (the icon or the label) - for menu items (see below), they are right aligned, so the label spreads out to the left. If anyone has a hint, how to set classes for that please contribute.

The solution is probably to implement the "menu group item" the same way as "menu item", currently the HTML/CSS for "menu group item" is using CSS/FUI columns, but "menu item" right float positioning.

Copy link
Member

@mvorisek mvorisek Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in 93ac62f I have commit debug code to debug/unify this

also IMO Maestro layout should be integrated into parametrized Admin layout

Label::addTo($group, [$name['label']], ['Icon'])->removeClass('item')->addClass('tiny');
Copy link
Member

@mvorisek mvorisek Apr 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for menu item the size is standard (class is unspecified) - ie. the font size is 12 px

for menu group, the size should not be smaller (tiny is 9 px)

related with https://github.com/atk4/ui/pull/1847/files#r1548874861 which should be solved first/instead

}

return $group;
Expand Down
Loading