© V. Keerti Kotaru 2016

V. Keerti Kotaru, Material Design implementation with AngularJS, 10.1007/978-1-4842-2190-7_11

11. Miscellaneous

V. Keerti Kotaru

(1)Hyderabad, Andhra Pradesh, India

The following are some useful miscellaneous elements and attributes in Angular Material. These are simple to use and provide value in improving the user experience.

Whiteframe

On an element, Whiteframe provides an elevated, 3D appearance with shadow effect. It is an attribute directive. It could be used on an element link div in HTML. See Figure 11-1.

A416608_1_En_11_Fig1_HTML.jpg
Figure 11-1. Whiteframes with various values of elevation

Use an element/directive md-whiteframe to create a whiteframe. Consider the following code. For the four elements, dp values of 4 (default), 10, 16, and 24 are provided. Possible values are -1 to 24. The first value -1 will not show any elevation. It is useful if we dynamically need to remove the effect on an element.

<div md-whiteframe flex layout-margin style="min-height:200px">
   Default
</div>
<div md-whiteframe="10dp" flex layout-margin style="min-height:200px">
   Whiteframe - 10dp
</div>
<div md-whiteframe="16dp" flex layout-margin style="min-height:200px">
   Whiteframe - 16dp
</div>
<div md-whiteframe="24dp" flex layout-margin style="min-height:200px">
   Whiteframe - 24dp
</div>     

Tooltip

Tooltips can provide useful help on various controls in the application. In an unobtrusive way, it can provide additional information about a text field, button, and so on. For an Angular Material tooltip, see Figure 11-2.

A416608_1_En_11_Fig2_HTML.jpg
Figure 11-2. Angular Material tooltip

Use md-tooltip element/directive to create a tooltip. Refer to the following usage.

<md-input-container>
    <md-tooltip>Use last name, first name format.</md-tooltip>
    <label>Enter your fullname</label>
    <input type="text">
</md-input-container>

Consider using one of the following options with tooltip.

  1. Use the attribute md-direction, with a value left, right, top, or bottom for explicitly positioning the tooltip. Default is bottom.

  2. Use the attribute md-delay to delay showing the tooltip for a certain number of milliseconds after focus. This ensures that the tooltip is shown only when the form element really gets focus, instead of popping it while the user is in motion and quickly tabbing through the controls or moving the mouse cursor across.

  3. Use the attribute md-autohide to let the tooltip disappear after moving the mouse out of the control’s region.

  4. Use the attribute md-visible with a value false to hide tooltip programmatically.

Subheader

Use element md-subheaderto create a subheader. It is in addition to default HTML headers h1, h2, h3, and so on. Subheader indents a little to the right, indicating that it is a section under one of the headers.

md-subheader is simple to use. It has smaller font and emphasizes text for a subheader. See Figure 11-3.

A416608_1_En_11_Fig3_HTML.jpg
Figure 11-3. Headings and a subheader at the bottom

Usage

< md-subheader > Sub Header </md-subheader>  

Divider

It is a horizontal divider for sections of a view or screen. Use directive md-divider.

Usage

<div>Content Section A</div>
<md-divider></md-divider>
<div>Content Section B</div>
<md-divider md-inset></md-divider>
<div>Content Section C</div>

md-divideris an empty element that results in a horizontal divider as shown in Figure 11-4. Notice md-inset on the second divider. It results in an inset style divider. Refer to Figure 11-4.

A416608_1_En_11_Fig4_HTML.jpg
Figure 11-4. Divider

Progress Bar

Progress bars are an important aspect of any application. For a long-running process within the application, it provides important feedback to the user that the application is working in the background. The user will intuitively understand to wait and won’t see a confusing frozen window. The long-running process could be a server-side API call, file IO, and so on.

Angular Material provides linear and circular progress bars.

Linear Progress Bar

A linear progress bar is laid out horizontally. As it comparatively has bigger screen space, will show elaborate status on the long-running process. See Figure 11-5.

A416608_1_En_11_Fig5_HTML.jpg
Figure 11-5. Linear progress bar

Create a linear progress bar with a directive md-progress-linear.

Angular material provides four modes for the progress bar.

  1. Determinate: If we have definitive information on the percentage of long-running job complete, this mode will be effective. The progress bar fills up once the job is fully done. Consider the following code.

            <md-progress-linear md-mode="determinate" value="{{progress}}"></md-progress-linear>

    The precentage of job done is determined by the value attribute. The following code mimics long-running process with a timeout service. Once the value of progress is above 100, it will quit. In the sample, it is a function defined in the controller.

                   function updateProgress(){
                        $timeout(function(){
                            $scope.progress += 1;     // increment progress by 1.
                            if($scope.progress<=100){
    // Continue to call update progress recursively till progress is 100%
                                console.log($scope.progress);
                                updateProgress();
                            }
                        }, 200);                  
                   }
  2. Indeterminate: When we are not certain about the percentage of job done, this is a better mode. Hide the progress bar once the job is complete. Till then, it keeps showing work-in-progress animation.

     <md-progress-linear md-mode="indeterminate"></md-progress-linear>
  3. Buffer: When there are two statuses to show, use this mode. For example, consider video streaming. The extent video buffered and the percentage of time that the user saw the video are two statuses. See Figure 11-6 for buffer mode depiction.

    A416608_1_En_11_Fig6_HTML.jpg
    Figure 11-6. Buffer mode

    Notice two progress statuses (light orange colored progress and dark orange colored progress). On the directive, while value represents percentage of job progress, the second buffer status is determined by md-buffer-value attribute. In the sample, we use another $scope variable buffer. Based on its value, the second status progress is shown.

    <md-progress-linear md-mode="buffer" value="{{progress}}" class="md-warn"  md-buffer-value="{{buffer}}"></md-progress-linear>
  4. Query: Use this mode to depict pre-loading process. It demonstrates that the real job hasn’t begun yet.

                <md-progress-linear md-mode="query"></md-progress-linear>

Circular Progress Bar

A circular progress bar is another depiction of progress for a long-running process. See Figure 11-7 for a circular progress bar.

A416608_1_En_11_Fig7_HTML.jpg
Figure 11-7. Circular progress bar

Use the directive md-progress-circularfor creating a circular progress bar. There are two modes in which circular progress bar could be used.

  1. Determinate: It shows the extent of long-running process complete. As the circle closes fully, the job is done 100%.

    Consider the following code. Use directive md-progress-circular with md-mode value “determinate” to create it in this mode. The extent of job completion is determined by value property.

    <md-progress-circular md-mode="determinate" value="{{progress}}"></md-progress-circular>

    As for the linear progress bar, in the sample, we mimic a long-running process with a $timeout service.

                   function updateProgress(){
                        $timeout(function(){
                            $scope.progress += 1;     // increment progress by 1.
                            if($scope.progress<=100){
    // Continue to call update progress recursively till progress is 100%
                                console.log($scope.progress);
                                updateProgress();


                            }
                        }, 200);                   
                   }
  2. Indeterminate: When we do not know the percentage of job done, use this mode. Hide the progress bar once the long-running process is fully done.

    <md-progress-circular md-mode="indeterminate" ></md-progress-circular>                                                                                                                                                                                   

Summary

The chapter describes miscellaneous directives that are simple to use and are effective. We began by exploring attribute directive md-whiteframe. It provides 3D elevation and shadow effects to an element.

We explored md-tooltip for showing additional help with controls on the page. In a web application, use this directive with forms, buttons, links, tabs, and so on to show additional information about the control on mouse hover.

A divider could be useful in certain cases to show logical separation between controls and sections of the page. We use md-divider directive for the separator.

Finally, we explored linear and circular progress bars to show status on a long-running process. Such feedback to the user from the application is important. It avoids confusion, multiple form submits, unnecessary page refresh, and so on. We used directives md-progress-linear and md-progress-circular. Each has multiple modes to support different use cases with long-running processes.

References

For Angular Material documentation, use https://material.angularjs.org

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.255.178