gwt.material.design.client.ui.MaterialSideNavDrawer Maven / Gradle / Ivy
/*
* #%L
* GwtMaterial
* %%
* Copyright (C) 2015 - 2017 GwtMaterialDesign
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
package gwt.material.design.client.ui;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.dom.client.Style;
import gwt.material.design.client.base.AbstractSideNav;
import gwt.material.design.client.base.HasWithHeader;
import gwt.material.design.client.constants.OverlayOption;
import gwt.material.design.client.constants.SideNavType;
import static gwt.material.design.client.js.JsMaterialElement.$;
//@formatter:off
/**
* SideNav (Drawer) is an extension to {@link MaterialSideNav} that provides
* a drawer / overlay like structure. Good for Full Content view.
*
*
UiBinder Usage:
*
* {@code
*
*
*
*
* }
*
*
* @author kevzlou7979
* @author Ben Dol
* @see Material SideNav
* @see Material Design Specification
* @see Pattern
* @see Pattern with Header
*/
//@formatter:on
public class MaterialSideNavDrawer extends AbstractSideNav implements HasWithHeader {
private boolean withHeader;
public MaterialSideNavDrawer() {
super(SideNavType.DRAWER);
setShowOnAttach(false);
}
@Override
protected void setup() {
if (withHeader) {
applyDrawerWithHeader();
} else {
applyDrawerType();
}
}
/**
* Provides an overlay / drawer sidenav just like when opening sidenav on mobile / tablet
*/
protected void applyDrawerType() {
setType(SideNavType.DRAWER);
registerHandler(addOpeningHandler(event -> Scheduler.get().scheduleDeferred(() -> $("[id=sidenav-overlay]").css("visibility", "visible"))));
Scheduler.get().scheduleDeferred(() -> {
pushElement(getHeader(), 0);
pushElement(getMain(), 0);
});
overlayOption.setVisibility(Style.Visibility.VISIBLE);
}
/**
* Provides an overlay / drawer sidenav that will float on top of the content not the navbar without
* any grey overlay behind it.
*/
protected void applyDrawerWithHeader() {
setType(SideNavType.DRAWER_WITH_HEADER);
applyBodyScroll();
if (isShowOnAttach()) {
Scheduler.get().scheduleDeferred(() -> {
pushElement(getHeader(), 0);
pushElement(getMain(), 0);
});
}
overlayOption.setVisibility(Style.Visibility.HIDDEN);
}
@Override
public void setWithHeader(boolean withHeader) {
this.withHeader = withHeader;
}
@Override
public boolean isWithHeader() {
return withHeader;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy