001/* 002 * #%L 003 * GwtMaterial 004 * %% 005 * Copyright (C) 2015 - 2017 GwtMaterialDesign 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package gwt.material.design.client.ui; 021 022import gwt.material.design.client.base.AbstractSideNav; 023import gwt.material.design.client.constants.Edge; 024import gwt.material.design.client.constants.SideNavType; 025 026//@formatter:off 027 028/** 029 * SideNav (Card) is an extension to {@link MaterialSideNav} that provides 030 * a card container to it's sidenav links. Good for few sidenav link items. 031 * <p> 032 * <h3>UiBinder Usage:</h3> 033 * <pre> 034 * {@code 035 * <m:MaterialSideNavCard ui:field="sideNav" width="280" m:id="mysidebar" closeOnClick="false"> 036 * <m:MaterialLink href="#about" iconPosition="LEFT" iconType="OUTLINE" text="About" textColor="BLUE" /> 037 * <m:MaterialLink href="#gettingStarted" iconPosition="LEFT" iconType="DOWNLOAD" text="Getting Started" textColor="BLUE" > 038 * </m:MaterialSideNav> 039 * } 040 * </pre> 041 * 042 * @author kevzlou7979 043 * @author Ben Dol 044 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#sidenavs">Material SideNav</a> 045 * @see <a href="https://material.io/guidelines/patterns/navigation-drawer.html">Material Design Specification</a> 046 * @see <a href="https://gwtmaterialdesign.github.io/gwt-material-patterns/snapshot/#sidenav_card">Pattern</a> 047 */ 048//@formatter:on 049public class MaterialSideNavCard extends AbstractSideNav { 050 051 public MaterialSideNavCard() { 052 super(SideNavType.CARD); 053 } 054 055 @Override 056 protected void setup() { 057 registerHandler(addOpeningHandler(event -> pushElement(getMain(), getWidth() + 20))); 058 registerHandler(addOpenedHandler(event -> { 059 if (getEdge() == Edge.LEFT) { 060 setLeft(0); 061 } else { 062 setRight(0); 063 } 064 })); 065 registerHandler(addClosingHandler(event -> pushElement(getMain(), 0))); 066 registerHandler(addClosedHandler(event -> { 067 if (getEdge() == Edge.LEFT) { 068 setLeft(-(getWidth() + 20)); 069 } else { 070 setRight(-(getWidth() + 20)); 071 } 072 })); 073 } 074}