Skip to content

Panel

The Panel component provides a flexible container with optional title, collapsible functionality, and draggable capabilities. It’s useful for organizing content into distinct sections with a consistent visual style.

  • Metro UI Core
  • DOM library
<div data-role="panel">
<div class="panel-content">
Panel content goes here
</div>
</div>
<div data-role="panel" data-title-caption="Panel Title">
<div class="panel-content">
Panel content with a title
</div>
</div>
<div data-role="panel" data-title-caption="Collapsible Panel" data-collapsible="true">
<div class="panel-content">
This panel can be collapsed
</div>
</div>
<div data-role="panel" data-title-caption="Draggable Panel" data-draggable="true">
<div class="panel-content">
This panel can be dragged
</div>
</div>
<div data-role="panel"
data-title-caption="Panel with Custom Buttons"
data-custom-buttons='[
{
"html": "<span class=\"mif-cog\"></span>",
"cls": "bg-transparent",
"onclick": "alert(\'Settings clicked\')"
},
{
"html": "<span class=\"mif-cross\"></span>",
"cls": "bg-transparent",
"onclick": "$(this).closest(\'.panel\').hide()"
}
]'>
<div class="panel-content">
Panel with custom buttons in the title
</div>
</div>
// Get panel plugin instance
const panel = Metro.getPlugin('#myPanel', 'panel');
// Open/expand the panel
panel.open();
// Close/collapse the panel
panel.close();
ParameterTypeDefaultDescription
panelDeferrednumber0Deferred initialization time in milliseconds
idstringnullPanel ID (auto-generated if not provided)
titleCaptionstring""Caption for the panel title
titleIconstring""Icon for the panel title (HTML string)
collapsiblebooleanfalseWhether the panel can be collapsed
collapsedbooleanfalseWhether the panel is initially collapsed
collapseDurationnumber100Duration of collapse/expand animation in milliseconds
widthstring”auto”Panel width
heightstring”auto”Panel height
draggablebooleanfalseWhether the panel can be dragged
customButtonsobjectnullCustom buttons for the panel title
clsPanelstring""Additional CSS class for the panel
clsTitlestring""Additional CSS class for the panel title
clsTitleCaptionstring""Additional CSS class for the title caption
clsTitleIconstring""Additional CSS class for the title icon
clsContentstring""Additional CSS class for the panel content
clsCollapseTogglestring""Additional CSS class for the collapse toggle
clsCustomButtonstring""Additional CSS class for custom buttons
MethodDescription
customButtons(buttons)Adds custom buttons to the panel title
collapse()Collapses the panel
expand()Expands the panel
open()Alias for expand()
close()Alias for collapse()
destroy()Destroys the panel component
// Get panel plugin instance
const panel = Metro.getPlugin('#myPanel', 'panel');
// Add custom buttons
panel.customButtons([
{
html: "<span class='mif-cog'></span>",
cls: "bg-transparent",
onclick: function() {
alert('Settings clicked');
}
}
]);
// Collapse the panel
panel.collapse();
// Expand the panel
panel.expand();
EventDescription
onCollapseTriggered when panel is collapsed
onExpandTriggered when panel is expanded
onDragStartTriggered when panel drag starts
onDragStopTriggered when panel drag stops
onDragMoveTriggered when panel is being dragged
onPanelCreateTriggered when panel is created
VariableDefault (Light)Dark ModeDescription
—panel-header-background#fbfbfb#282c35Background color of the panel header
—panel-header-color#191919#fbfbfbText color of the panel header
—panel-header-icon-background#fbfbfb#282c35Background color of the icon in the panel header
—panel-header-icon-color#191919#fbfbfbColor of the icon in the panel header
—panel-background#ffffff#2b2d30Background color of the panel
—panel-color#191919#dbdfe7Text color of the panel content
—panel-border-color#e8e8e8#4a4d51Color of the panel border
—panel-border-radius6px6pxBorder radius of the panel
—panel-dropdown-toogle-color#191919#ffffffColor of the dropdown toggle in the panel header
/* Custom styling for panels */
.custom-panel {
--panel-header-background: #3498db;
--panel-header-color: #ffffff;
--panel-background: #ecf0f1;
--panel-color: #2c3e50;
--panel-border-color: #bdc3c7;
--panel-border-radius: 10px;
}
<div data-role="panel" class="custom-panel" data-title-caption="Custom Styled Panel">
<div class="panel-content">
This panel has custom styling
</div>
</div>
  • .panel - Main container for the panel (automatically added)
  • .panel-title - Title section of the panel
  • .panel-content - Content section of the panel
  • .icon - Icon in the panel title
  • .caption - Text caption in the panel title
  • .dropdown-toggle - Toggle for collapsible functionality
  • .custom-buttons - Container for custom buttons
  • .btn-custom - Custom button in the title
  1. Use panels to group related content and provide a clear visual hierarchy
  2. Add titles to panels to clearly indicate their purpose
  3. Use collapsible panels for content that doesn’t need to be visible all the time
  4. Consider making panels draggable in dashboard-like interfaces where users might want to rearrange content
  5. Use custom buttons sparingly and with clear icons to avoid cluttering the panel title
  6. Apply consistent styling to panels throughout your application for a cohesive look and feel