Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

feat(panel): Panel grouping #9538

Merged
merged 1 commit into from
Sep 26, 2016
Merged
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
2 changes: 1 addition & 1 deletion src/components/panel/demoBasicUsage/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="demo-md-panel md-padding" ng-controller="BasicDemoCtrl as ctrl">
<div class="md-padding" ng-controller="BasicDemoCtrl as ctrl">
<p>
A panel can be used to create dialogs, menus, and other overlays.
</p>
Expand Down
46 changes: 46 additions & 0 deletions src/components/panel/demoGroups/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<div ng-controller="PanelGroupsCtrl as ctrl" ng-cloak>

<md-toolbar class="md-accent">
<div class="md-toolbar-tools">
<md-button
class="md-icon-button"
aria-label="Settings"
ng-click="ctrl.showToolbarMenu($event, ctrl.settings)">
<md-icon md-svg-icon="img/icons/menu.svg"></md-icon>
</md-button>
<h2>Toolbar with grouped panels (Maximum open: 2)</h2>
<span flex></span>
<md-button
class="md-icon-button"
aria-label="Favorite"
ng-click="ctrl.showToolbarMenu($event, ctrl.favorite)">
<md-icon md-svg-icon="img/icons/favorite.svg"></md-icon>
</md-button>
<md-button
class="md-icon-button"
aria-label="More"
ng-click="ctrl.showToolbarMenu($event, ctrl.more)">
<md-icon md-svg-icon="img/icons/more_vert.svg"></md-icon>
</md-button>
</div>
</md-toolbar>

<md-content layout-padding>
<p>
Panels can be added to a group. Groups are used to configure specific
behaviors on multiple panels. To add a panel to a group, use the
<code>$mdPanel.newPanelGroup</code> method, or simply add a group name
to the configuration object passed into the <code>$mdPanel.create</code>
method.
</p>
<p>
Grouping allows for methods to be applied to several panels at once, i.e.
closing all panels within the toolbar group, or destroying all panels
within a dialog group. With the <code>maxOpen</code> property, you can
also limit the number of panels allowed open within a specific group. This
can be useful in limiting the number of menu panels allowed open at a
time, etc.
</p>
</md-content>

</div>
88 changes: 88 additions & 0 deletions src/components/panel/demoGroups/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
(function() {
'use strict';

angular
.module('panelGroupsDemo', ['ngMaterial'])
.controller('PanelGroupsCtrl', PanelGroupsCtrl)
.controller('PanelMenuCtrl', PanelMenuCtrl);

function PanelGroupsCtrl($mdPanel) {
this.settings = {
name: 'settings',
items: [
'Home',
'About',
'Contact'
]
};
this.favorite = {
name: 'favorite',
items: [
'Add to Favorites'
]
};
this.more = {
name: 'more',
items: [
'Account',
'Sign Out'
]
};

this.showToolbarMenu = function($event, menu) {
var template = '' +
'<div class="menu-panel" md-whiteframe="4">' +
' <div class="menu-content">' +
' <div class="menu-item" ng-repeat="item in ctrl.items">' +
' <button class="md-button">' +
' <span>{{item}}</span>' +
' </button>' +
' </div>' +
' <md-divider></md-divider>' +
' <div class="menu-item">' +
' <button class="md-button" ng-click="ctrl.closeMenu()">' +
' <span>Close Menu</span>' +
' </button>' +
' </div>' +
' </div>' +
'</div>';

var position = $mdPanel.newPanelPosition()
.relativeTo($event.srcElement)
.addPanelPosition(
$mdPanel.xPosition.ALIGN_START,
$mdPanel.yPosition.BELOW
);

$mdPanel.newPanelGroup('toolbar', {
maxOpen: 2
});

var config = {
id: 'toolbar_' + menu.name,
attachTo: angular.element(document.body),
controller: PanelMenuCtrl,
controllerAs: 'ctrl',
template: template,
position: position,
panelClass: 'menu-panel-container',
locals: {
items: menu.items
},
openFrom: $event,
focusOnOpen: false,
zIndex: 100,
propagateContainerEvents: true,
groupName: 'toolbar'
};

$mdPanel.open(config);
}
}

function PanelMenuCtrl(mdPanelRef) {
this.closeMenu = function() {
mdPanelRef && mdPanelRef.close();
Copy link
Contributor

Choose a reason for hiding this comment

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

destroy as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ErinCoughlan I do not think so. Destroying a panel makes it unable to be re-opened, and in this demo, I am applying an ID to each opened panel, which means it can be closed and re-opened from the click event.

}
}
})();
77 changes: 77 additions & 0 deletions src/components/panel/demoGroups/style.global.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
.menu-panel-container {
pointer-events: auto;
}

.menu-panel {
width: 256px;
background-color: #fff;
border-radius: 4px;
}

.menu-panel .menu-divider {
width: 100%;
height: 1px;
min-height: 1px;
max-height: 1px;
margin-top: 4px;
margin-bottom: 4px;
background-color: rgba(0, 0, 0, 0.11);
}

.menu-panel .menu-content {
display: flex;
flex-direction: column;
padding: 8px 0;
max-height: 305px;
overflow-y: auto;
min-width: 256px;
}

.menu-panel .menu-item {
display: flex;
flex-direction: row;
min-height: 48px;
height: 48px;
align-content: center;
justify-content: flex-start;
}
.menu-panel .menu-item > * {
width: 100%;
margin: auto 0;
padding-left: 16px;
padding-right: 16px;
}
.menu-panel .menu-item > a.md-button {
padding-top: 5px;
}
.menu-panel .menu-item > .md-button {
display: inline-block;
border-radius: 0;
margin: auto 0;
font-size: 15px;
text-transform: none;
font-weight: 400;
height: 100%;
padding-left: 16px;
padding-right: 16px;
width: 100%;
text-align: left;
}
.menu-panel .menu-item > .md-button::-moz-focus-inner {
padding: 0;
border: 0;
}
.menu-panel .menu-item > .md-button md-icon {
margin: auto 16px auto 0;
}
.menu-panel .menu-item > .md-button p {
display: inline-block;
margin: auto;
}
.menu-panel .menu-item > .md-button span {
margin-top: auto;
margin-bottom: auto;
}
.menu-panel .menu-item > .md-button .md-ripple-container {
border-radius: inherit;
}
Loading