Skip to content

Drawer - a new component for building responsive web app layouts #5164

Description

@dxbykov

The Problem

Creating a responsive web application layout with navigation bars and collapsible panes is complex and time-consuming.

The Proposed Solution

We are planning to include the new Drawer widget in v18.2. This widget can be used to create responsive and themeable web application layouts. We are also planning to add such layouts to our products.

Below we have listed the features we would like to support in our Drawer. The code examples in this thread are in Angular. However, you can use a similar API with React, Vue and jQuery.

Specifying the main and Drawer pane content

You should wrap content in the Drawer component to add a drawer panel. In this case, the Drawer drops a shadow over the content and change its size or position when opened. The drawer pane’s content is specified via a ‘drawer-pane’ template.

<dx-drawer>
    <div *dxTemplate="let data of 'drawer-pane'">
        Drawer Panel Content
    </div>
   <div>
       Main Content
   </div>
</dx-drawer>

Opening and closing the Drawer

<dx-drawer [opened]="isDrawerOpened">
    <div *dxTemplate="let data of 'drawer-pane'">
        navigation
    </div>
   <div>
       <div (click)="isDrawerOpened = !isDrawerOpened">Toggle navigation menu</div>
   </div>
</dx-drawer>
 export class AppComponent {
   isDrawerOpened: boolean = false;
 }

or using the ‘toggle’ method:

<dx-drawer #drawer>
    <div *dxTemplate="let data of 'drawer-pane'">
        navigation
    </div>
   <div>
       <div (click)="drawer.toggle()">Toggle navigation menu</div>
   </div>
</dx-drawer>

Changing the Drawer position

 <dx-drawer [position]="'left'|'right'">
   ...
 </dx-drawer>

Changing the Drawer open behavior

   <dx-drawer
     [openedStateMode]="'shrink'|'push'|'overlap'"
     [revealMode]="'slide'|'expand'"
   >
       ...
   </dx-drawer>

The ‘openedStateMode’ option values:

  • ‘shrink’ - opening the drawer pane shrinks the main content
  • ‘push’ - the drawer pane displaces the main content
  • ‘overlap’ - the drawer pane overlaps the main content

The ‘revealMode’ option values:

  • ‘slide’ - the drawer pane content is sliding during open/close animation
  • ‘expand’ - the drawer pane content is static during open/close animation (only the pane width is animating)

Enabling/Disabling the Drawer shading

<dx-drawer [shading]="false">
       ...
</dx-drawer>

Specifying the Drawer pane width

<dx-drawer [width]="200">
       ...
</dx-drawer>

Creating a responsive layout for mobile & desktop

You can use different drawer configuration options depending on the screen size or orientation. For instance, you can implement a persistent navigation pane for desktop applications, and a temporary pane for mobile phones.

You can use the BreakpointObserver from the Angular Component Dev Kit to build apps with Angular. We’ll add an Angular example to this post soon.

Using several drawers at once

You can compose drawers if you need more that one drawer pane in your layout:

<dx-drawer #leftDrawer openedStateMode="overlap">
   <div *dxTemplate="let data of 'drawer-pane'">
       navigation
   </div>
   <dx-drawer #rightDrawer openedStateMode="push" position="right">
       <div *dxTemplate="let data of 'drawer-pane'">
           right panel content
       </div>
       <div>
           <div (click)="leftDrawer.toggle()">Toggle navigation menu</div>
           <div (click)="rightDrawer.toggle()">Toggle right pane</div>
       </div>
   </dx-drawer>
</dx-drawer>

We Need Your Feedback

Take a Quick Poll

Does the new Drawer component meet your needs?

Live Sandbox

Check out the early working prototype

Get Notified of Updates

Subscribe to this thread or to our Facebook and Twitter accounts for updates on this topic.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions