Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 1, 2022 08:47 pm GMT

Customizing a Drawer Element in a Quick App

About the Drawer Element

The drawer element is a special pop-up panel that can create the effect of opening and closing a drawer in an app. This element has the following features:

  • It can be displayed on either side of the screen.
  • Its width can be customized.
  • It has a mask layer that a user can tap to close the drawer.
  • It can be opened by swiping on the screen.

The drawer element consists of two parts: controls and content. In most cases, controls is a clickable element, such as button or icon that can be seen as real handles, whereas content refers to what is inside the drawer. You can expand or collapse content by tapping controls. Therefore, when the drawer element is used, the page layout can be designed as follows:

<div class=page">    <div class=controls">      <image></image>     </div>    <stack class=drawer_container>        <div class=page_content>                   </div>         <drawer class="drawer">            <div class=content>                          </div>          </drawer >    </stack> </div>

Development Procedure

The drawer element is an extended capability that you cannot implement using the existing elements of quick apps. It requires custom elements.

Customizing the Subelements

Unlike the drawers appearance, which can be universally used, the layout of the drawers content may vary and therefore cannot be hardcoded. Otherwise, once any part of the content UI is changed, the subelements need to be modified, which violates the open-closed principle of programming.
Therefore, in the drawer.ux file, the slot element is used to bear the content defined in the parent element, and the drawer element is used to define the contents layout. The code is as follows:

Image descriptio

Customizing the Attributes and Supported Events of Subelements

Supported attributes

Image descriptin

Supported event

Image descriptin

Designing the Opening and Closing Animation of the Drawer

  • Set display to none to hide the drawer by default.
  • Control the opening and closing animation of the drawer by changing the X coordinate. When opened, the drawer moves to the visible area, and when closed, it moves off the screen. The animation effect is smooth regardless of whether the drawer is opened or closed.
  • Control the displayed position of the drawer through flex-direction of the div element. To display the drawer on the left or right, set the value to row or row-reverse accordingly.

Image descripion

Figure 1: Style for opening and closing the drawer on the left

Image descripton

Figure 2: Style for opening and closing the drawer on the right

Image descripton

Figure 3: Code for opening and closing the drawer on the left

Image descriptin

Figure 4: Code for opening and closing the drawer on the right

Designing the Mask Layer

The mask layer is hidden by default, which means the value of display is none. The mask layer is displayed when the drawer is opened and hidden when the drawer is closed.

Image descrption

Implementing Data Communication Between the Parent Element and Subelements

  • The parent element transfers events of opening and closing the drawer to subelements through parentVm.$broadcast(). The subelements listen to events and parameters through $on().
  • The subelements listen to how mode changes through $watch() to modify the CSS style, displaying the drawer in the correct position.
  • The subelements notify the parent element through the drawerchange event and returned parameters.

Opening the Drawer by Swiping

By listening to the touchstart and touchend events, you can swipe on the edge of the screen to open the drawer.

Summary

In this article, you will learn how to:

  • Customize subelements, including their attributes and supported events.
  • Implement data communication between the parent element and subelements.
  • Design the opening and closing animation.
  • Design the mask layer.

You can check related documents to learn even more.

Sample code drawer.ux


Original Link: https://dev.to/josholadele/customizing-a-drawer-element-in-a-quick-app-93a

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To