Skip to content

Commit 4584c4b

Browse files
committed
Tweaked the previous feature
1 parent 87e4406 commit 4584c4b

File tree

7 files changed

+62
-27
lines changed

7 files changed

+62
-27
lines changed

assets/css/easyadmin-theme/base.scss

+23
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,29 @@ body.ea-mobile-sidebar-visible .main-sidebar {
344344
margin: 0;
345345
padding: 15px 17px 15px 20px;
346346
}
347+
.content-panel-header.collapsible {
348+
padding: 0;
349+
}
350+
.content-panel-header.collapsible > a {
351+
color: inherit;
352+
display: block;
353+
padding: 15px 17px 15px 20px;
354+
}
355+
.content-panel-header.collapsible.with-help > a {
356+
padding: 15px 17px 1px 20px;
357+
}
358+
.content-panel-header.collapsible .collapse-icon {
359+
color: var(--color-primary);
360+
margin-right: 5px;
361+
transition: all .1s linear;
362+
}
363+
.content-panel-collapse:not(.collapsed) .collapse-icon {
364+
transform: rotate(90deg);
365+
}
366+
.content-panel-header.collapsible.with-help .content-panel-header-help {
367+
padding: 0 17px 15px 20px;
368+
}
369+
347370
.content-panel-header-help {
348371
color: var(--gray-500);
349372
font-size: var(--font-size-base);

assets/css/easyadmin-theme/fields.scss

-9
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,3 @@
143143
max-height: 480px;
144144
overflow-y: auto;
145145
}
146-
147-
// Collapsible panel
148-
.content-panel-collapse:not(.collapsed) .expand-icon {
149-
display: none;
150-
}
151-
152-
.content-panel-collapse.collapsed .collapse-icon {
153-
display: none;
154-
}

src/Field/FormField.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ final class FormField implements FieldInterface
1414
use FieldTrait;
1515

1616
public const OPTION_ICON = 'icon';
17-
1817
public const OPTION_COLLAPSIBLE = 'collapsible';
1918
public const OPTION_COLLAPSED = 'collapsed';
2019

@@ -53,15 +52,31 @@ public function setIcon(string $iconCssClass): self
5352

5453
public function collapsible(bool $collapsible = true): self
5554
{
55+
if (!$this->hasLabelOrIcon()) {
56+
throw new \InvalidArgumentException(sprintf('The %s() method used in one of your panels requires that the panel defines either a label or an icon, but it defines none of them.', __METHOD__));
57+
}
58+
5659
$this->setCustomOption(self::OPTION_COLLAPSIBLE, $collapsible);
5760

5861
return $this;
5962
}
6063

61-
public function collapsed(bool $collapsed = true): self
64+
public function renderCollapsed(bool $collapsed = true): self
6265
{
66+
if (!$this->hasLabelOrIcon()) {
67+
throw new \InvalidArgumentException(sprintf('The %s() method used in one of your panels requires that the panel defines either a label or an icon, but it defines none of them.', __METHOD__));
68+
}
69+
70+
$this->setCustomOption(self::OPTION_COLLAPSIBLE, true);
6371
$this->setCustomOption(self::OPTION_COLLAPSED, $collapsed);
6472

6573
return $this;
6674
}
75+
76+
private function hasLabelOrIcon(): bool
77+
{
78+
// don't use empty() because the label can contain only white spaces (it's a valid edge-case)
79+
return (null !== $this->dto->getLabel() && '' !== $this->dto->getLabel())
80+
|| null !== $this->dto->getCustomOption(self::OPTION_ICON);
81+
}
6782
}

src/Resources/public/app.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/public/app.rtl.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Resources/views/crud/detail.html.twig

+10-7
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,18 @@
101101
{% set collapsed = field.customOption('collapsed') %}
102102
<div class="{{ field.cssClass }}">
103103
<div class="content-panel">
104-
<div class="content-panel-header">
105-
{% if field.customOption('icon') %}
106-
<i class="{{ field.customOption('icon') }}"></i>
107-
{% endif %}
108-
{{ field.label|raw }}
104+
<div class="content-panel-header {{ collapsible ? 'collapsible' }} {{ field.help is not empty ? 'with-help' }}">
109105
{% if collapsible %}
110106
<a href="#content-{{ field.property }}" data-toggle="collapse" class="content-panel-collapse {{ collapsed ? 'collapsed' }}" aria-expanded="{{ collapsed ? 'false' : 'true' }}" aria-controls="content-{{ field.property }}">
111-
<i class="fa fa-plus-square expand-icon"></i>
112-
<i class="fa fa-minus-square collapse-icon"></i>
107+
<i class="fas fw fa-chevron-right collapse-icon"></i>
108+
{% endif %}
109+
110+
{% if field.customOption('icon') %}
111+
<i class="{{ field.customOption('icon') }}"></i>
112+
{% endif %}
113+
{{ field.label|raw }}
114+
115+
{% if collapsible %}
113116
</a>
114117
{% endif %}
115118

src/Resources/views/crud/form_theme.html.twig

+10-7
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,18 @@
371371
<div class="{{ panel_config.css_class ?? '' }}">
372372
<div class="content-panel">
373373
{% if panel_has_header %}
374-
<div class="content-panel-header">
375-
{% if panel_config.icon|default(false) %}
376-
<i class="{{ panel_config.icon }}"></i>
377-
{% endif %}
378-
{{ panel_config.label|raw }}
374+
<div class="content-panel-header {{ collapsible ? 'collapsible' }} {{ panel_config.help|default(false) is not empty ? 'with-help' }}">
379375
{% if collapsible %}
380376
<a href="#content-{{ panel_name }}" data-toggle="collapse" class="content-panel-collapse {{ collapsed ? 'collapsed' }}" aria-expanded="{{ collapsed ? 'false' : 'true' }}" aria-controls="content-{{ panel_name }}">
381-
<i class="fa fa-plus-square expand-icon"></i>
382-
<i class="fa fa-minus-square collapse-icon"></i>
377+
<i class="fas fw fa-chevron-right collapse-icon"></i>
378+
{% endif %}
379+
380+
{% if panel_config.icon|default(false) %}
381+
<i class="{{ panel_config.icon }}"></i>
382+
{% endif %}
383+
{{ panel_config.label|raw }}
384+
385+
{% if collapsible %}
383386
</a>
384387
{% endif %}
385388

0 commit comments

Comments
 (0)