Angular Material Tutorial - 8 - Badges

Codevolution
28 Feb 201908:03

Summary

TLDRفي هذا الفيديو، نستعرض كيفية استخدام شارات المواد في Angular Material، بداية من الاستيراد الضروري لوحدة MatBadgeModule. نقوم بإنشاء شارة أولية ونستعرض كيفية تخصيص موقعها، حجمها، ولونها باستخدام الخصائص المختلفة مثل matBadgePosition وmatBadgeSize وmatBadgeColor. بالإضافة إلى ذلك، نتعلم كيفية التحكم في تداخل الشارات مع النصوص ورموز التطبيق وكيفية ربط قيم الشارات ديناميكيًا بخصائص الفئة في Angular، مع إمكانية إخفاء الشارات بناءً على شروط معينة باستخدام الخاصية matBadgeHidden. الفيديو مصمم لتوفير فهم شامل لإمكانيات استخدام الشارات في تطبيقات Angular Material.

Takeaways

  • 📌 ال_USE_OF_MATERIAL_BADGES: الشارات المادية في Bootstrap هي ملاحظات بسيطة تشير إلى حالة العناصر الرسومية.
  • 🔧 ال_ADDING_BADGE_MODULE: لاستخدام الشارات المادية، يجب استيراد مודول الشارة المادية من angular/material/badge.
  • 🌟 ال_CREATING_A_BADGE: يمكن إنشاء الشارة المادية بإضافة سمة [matBadge] إلى عنصر HTML مثل span.
  • 📍 ال_BADGE_POSITION: يمكن تحكم موضع الشارة المادية باستخدام سمة [matBadgePosition] وتحديد القيم المناسبة مثل above, below, before, or after.
  • 🔎 ال_BADGE_SIZE: يمكن تحديد حجم الشارة المادية باستخدام سمة [matBadgeSize] مع قيم متعددة مثل small, medium, أو large.
  • 🎨 ال_BADGE_COLORING: يمكن تغيير لون الشارة المادية باستخدام سمة [matBadgeColor] مع قيم مثل primary, accent, أو warn.
  • 🚫 ال_AVOIDING_OVERLAP: يتم تجاوز الشعار بالنص بطبيعة الحال، ولكن يمكن تعطيل هذا باستخدام سمة [matBadgeOverlap] وتعيينها إلى false.
  • 🔗 ال_BINDING_VALUES: يمكنربط القيم مع الشارات المادية باستخدام الربط الوظيفي با sử dụng [property binding].
  • 📊 ال_CONDITIONAL_RENDERING: يمكن توليد الشارات المادية بشكل شرطي بناءً على القيم، مثل الاختيار من الظهور إذا كانت القيمة لا ت等于 صفر باستخدام [matBadgeHidden].
  • 🔍 ال_REFERRAL_TO_DOCUMENTATION: لمزيد من المعلومات والتفاصيل، يفضل زيارة صفحة الوثائق الرسمية للشارات المادية في material.io.
  • 👋 ال_THANK_YOU: شكراً لمشاهدة الفيديو، ولا تنسَ الاشتراك لمتابعة محتوى مستقبل.

Q & A

  • ما هي ال功用 الأساسية للشارات في واجهة المستخدم؟

    -الشارات في واجهة المستخدم تعتبر معلمات بسيطة لحالة العناصر، مثل إظهار الإشعارات أو عدد الرسائل غير مقروءة.

  • كيف يمكن استخدام شهادات Bootstrap في العمل مع Angular Material؟

    -لاستخدام شهادات Bootstrap، يجب أولاً استيراد موديول الشارة من angular/material/badge، ثم إضافةها إلى مصفوفة مكونات ماترyal.

  • كيف يمكن إنشاء شهادة في Angular Material؟

    -لإنشاء شهادة، يمكن استخدام العلامة <span> مع النص المطلوب، ثم إضافة سمة matBadge مع القيمة المطلوبة لتحديد القيمة المشير إليها.

  • كيف يمكن تغيير الموقع الافتراضي للشارة؟

    -يمكن التحكم في الموقع الافتراضي للشارة باستخدام سمة matBadgePosition، التي تتيح تحديد الموقع من خلال القيم الممكنة مثل above before, above after, below before, below after.

  • ما هي القيم المتاحة للحجم في شهادات Angular Material؟

    -القيم المتاحة للحجم في شهادات Angular Material هي small, medium, و large، بحيث medium هي القيمة الافتراضية.

  • كيف يمكن تغيير لون الخلفية للشارة؟

    -يمكن تغيير لون الخلفية للشارة باستخدام سمة matBadgeColor، التي تتيح التحكم في الألوان من خلال القيم primary, accent, و warn، والألوان محددة بناءً على تمثيل التطبيق.

  • لماذا ينصح بالتجاوز برسمة النص في بعض الأحيان؟

    -ينصح بالتجاوز برسمة النص لأن الشعارات قد تهم القراءة والفهم، لكن يفضل تجنب التجاوز في النصوص واستخدامه مع الرمزات، حيث يمكن أن يكون مفيداً.

  • كيف يمكنربط القيم مع الشارات؟

    -يمكن ربط القيم مع الشارات باستخدام الربط الشخصي، حيث يمكن استخدام العلامة [] لربط القيمة المطلوبة مع سمة matBadge.

  • كيف يمكن إخفاء الشارات الconditionally؟

    -يمكن إخفاء الشارات الconditionally باستخدام سمة matBadgeHidden مع الربط الشخصي، حيث يمكن تحديد الشرط الذي ي HID الشارة بناءً على القيمة المطلوبة.

  • أين يمكن العثور على مستندات الشارة في Angular Material؟

    -يمكن العثور على مستندات الشارة في Angular Material على الموقع material.io، في قسم Components under Buttons and Indicators، ثم النقر على الشارة.

  • كيف يمكن استخدام الشعارات في Angular Material لتحسين تجربة المستخدم؟

    -الشعارات في Angular Material يمكن استخدامها لتحسين تجربة المستخدم عن طريق توفير معلومات إضافية وметعلقة بحالة العناصر، مما يساعد على التركيز على العناصر الهامة وتحسين التنقل بين العناصر.

Outlines

00:00

📌 Introduction to Angular Material Badges

This paragraph introduces the concept of material badges in the context of Angular, drawing parallels with Bootstrap's badges. It explains that badges are small status descriptors for UI elements, useful for displaying notifications or the number of unread messages. The paragraph outlines the initial steps to use Angular Material Badges, which include importing the badge module and adding it to the material components array. It then demonstrates how to create a basic badge using the mat badge attribute and how to customize its appearance, such as changing its position and size. The paragraph emphasizes the importance of badge positioning and sizing, and it concludes with a brief mention of badge coloring and overlap attributes.

05:02

🎨 Customization and Conditional Rendering of Angular Material Badges

This paragraph delves deeper into the customization options available for Angular Material Badges. It discusses how to control the position of badges using the mat badge position attribute and how to adjust their size with the mat badge size attribute. The paragraph also explores badge coloring, explaining how to set the background color using the mat badge color attribute. An important note is made regarding the overlap of badges with text, advising against it unless necessary. The paragraph concludes with a discussion on binding values and conditional rendering of badges, showing how to dynamically display the badge's value based on a class property and how to hide the badge when the notification count is zero using the mat badge hidden attribute. The paragraph ends by directing the viewer to the official documentation for further information.

Mindmap

Keywords

💡Material Badges

Material Badges are a user interface component used in web development with Angular Material. They are designed to provide a visual cue for status or notifications, such as the number of unread messages or alerts. In the video, Material Badges are introduced as a familiar concept for those who work with Bootstrap and are explained in the context of their usage with Angular Material.

💡Angular Material

Angular Material is a UI framework based on Google's Material Design system. It provides a set of Angular components that follow Material Design guidelines, making it easier for developers to create visually appealing and consistent user interfaces. The video focuses on the implementation of Material Badges within this framework.

💡mat badge attribute

The 'mat badge' attribute is a directive in Angular Material used to add a badge to an HTML element. It is applied to an element to display a small status descriptor, such as a number or a dot, indicating the status or count of a particular UI element. In the context of the video, it is used to associate a value with an element, like showing '5' as an example notification count.

💡Positioning

Positioning in the context of Material Badges refers to the placement of the badge relative to the associated element. By default, badges are placed above and to the right of the element. However, the position can be adjusted using the 'mat badge position' attribute, allowing developers to place badges below, to the left, or in other configurations relative to the associated element.

💡Sizing

Sizing in the context of Material Badges pertains to the size of the badge. Angular Material allows for the specification of badge size using the 'mat badge size' attribute, with options such as 'small', 'medium', and 'large'. The default size is 'medium'. Adjusting the size can help to ensure that the badge is visible and fits well with the overall design of the user interface.

💡Coloring

Coloring for Material Badges refers to the background color of the badge, which can be set using the 'mat badge color' attribute. The available color options include 'primary', 'accent', and 'warn', with 'primary' being the default. The choice of color can be influenced by the theme of the application and is intended to draw attention or convey a specific meaning through visual cues.

💡Overlapping

Overlapping in the context of Material Badges indicates whether the badge is positioned over the associated text or element. By default, badges overlap the text. However, this can be controlled using the 'mat badge overlap' attribute. It is advised in the Material documentation to overlap badges for icons rather than text for better readability and design aesthetics.

💡Binding Values

Binding values in Angular Material refers to the process of linking a property from a component class to an HTML attribute in the template. This allows for dynamic updates to the UI based on changes in the component's properties. In the context of badges, the value displayed on the badge can be bound to a property, such as a notification count.

💡Conditional Rendering

Conditional rendering in Angular Material is the practice of displaying or hiding UI elements based on certain conditions. This can be achieved using the 'mat badge hidden' attribute, which hides the badge when the condition is met, such as when the notification count is zero.

💡Documentation

Documentation in the context of web development refers to the official guides and reference materials provided by a framework or library. These resources are essential for developers to understand the features, usage, and best practices of the tools they are working with. The video encourages viewers to consult the official Angular Material documentation for more information on badges.

Highlights

Introduction to material badges in Bootstrap

Badges as status descriptors for UI elements

Use case example: displaying unread message count

Importing the badge module in Angular Material

Adding a badge to a span tag using mat badge attribute

Customizing badge position with mat badge position attribute

Demonstration of different badge positions (above, after, below, before)

Adjusting badge size with mat badge size attribute

Examples of small, medium, and large badge sizes

Changing badge background color with mat badge color attribute

Options for badge color: primary, accent, and warn

Controlling badge overlap with mat badge overlap attribute

Recommendation from material documentation on overlapping badges

Binding values to a badge using property binding

Conditionally rendering a badge based on a condition

Using mat badge hidden attribute for conditional rendering

Guidance on where to find the official documentation for badges

Summary and conclusion of the video content

Transcripts

00:00

let's take a look at material badges in

00:03

this video if you work with bootstrap

00:06

badges should seem familiar to you

00:09

they are basically small status

00:11

descriptors for UI elements for example

00:16

if you have to display notifications for

00:18

a user or the number of unread messages

00:21

in your Inbox badges are the way to go

00:24

so let's see what is possible with

00:27

angular material badges in this video to

00:30

be able to use them we first need to

00:33

import the badge module in material dot

00:37

module dot es import mat badge module

00:42

from angular slash material slash badge

00:46

and then add it to the material

00:49

components array

00:51

now let's create our first badge in AB

00:55

component dot HTML I'm going to include

00:58

a span tag with the text notifications

01:03

to add a badge to the span tag we make

01:07

use of the mat badge attribute

01:12

so mad badge and this attribute is equal

01:16

to the value you want to indicate let's

01:19

go with five if we save this and take a

01:23

look at the browser you should see the

01:25

badge in action the small circular

01:28

element on the top right of the span

01:30

text now this is the most basic badge

01:34

you can have let's see how to customize

01:37

this and let's start with the position

01:40

by default a badge is placed above and

01:45

after the element it is associated with

01:48

that is to the top right we can control

01:52

the position using the mat badge

01:55

position attribute so back in the HTML

01:58

I'm going to make three more copies of

02:01

this div tag

02:06

and I'm going to specify the Matt badge

02:09

position attribute

02:17

below and before

02:21

below and after

02:26

above and before let me also add some

02:30

margin to the div tags to make sure that

02:32

there is enough spacing between the

02:34

elements so div margin three realms now

02:41

if you save the files and take a look at

02:43

the browser you can see the different

02:46

positions above and after below and

02:50

before below and after above and before

02:56

so Matt badge position attribute to

02:59

control the position of the badge next

03:03

let's talk about badge sizing we can

03:06

specify the size using the Matt badge

03:09

size attribute the possible values are

03:12

small medium and large with medium being

03:16

the default value I'm going to make

03:20

three more copies of our notification

03:22

badge and for the first one I'm going to

03:26

add Matt badge size is equal to small

03:31

the second one medium which is also the

03:34

default and for the third one large if

03:39

you now save the file and take a look at

03:41

the browser you can see the badges which

03:43

are small medium and large

03:47

alright next we have badge coloring the

03:51

badge background color can be set using

03:54

the mat badge color attribute possible

03:58

values our primary accent and born with

04:02

primary being the default value the

04:05

color of course is determined by the

04:07

theme your application is using so back

04:11

in vs code I'm going to make three more

04:13

copies of the original notification

04:16

badge

04:20

for the first one I'm going to add math

04:23

badge color is equal to primary which is

04:27

the default for the second one it is

04:30

going to be accent and for the third one

04:32

it's going to be warned if we save this

04:36

and take a look at the browser you can

04:38

see primary accent and worn colors based

04:42

on your theme

04:44

now you might have noticed in all the

04:46

notification badges the badge overlaps

04:49

with the text the overlap flag though

04:53

can be controlled as well we specify the

04:56

Matt badge overlap attribute and set it

04:58

defaults so back in vs code on the last

05:02

badge I'm going to add the attribute

05:06

Matt batch overlap is equal to false if

05:11

you go back to the browser you can see

05:14

that the batch doesn't overlap with the

05:16

text anymore

05:17

in fact material documentation advises

05:21

us to overlap badges for icons and not

05:25

for text for example if you have the

05:28

inbox icon then overlapping might be a

05:31

good choice for text however try

05:34

avoiding overlap as much as possible

05:38

finally let's talk about binding values

05:41

and also conditional rendering the value

05:44

for a batch is usually stored in a class

05:47

property to bind the value we simply use

05:50

property binding so I'm going to open

05:53

app component es and over here I'm going

05:58

to create a new property notifications

06:02

is equal to two and then in the HTML on

06:07

the very first badge I'm going to have

06:10

property binding on the mat batch

06:12

attribute so square brackets for

06:16

property binding and the property we

06:18

want to bind to is notifications

06:23

this property right here so now if we go

06:27

back to the browser

06:28

the very first badge now indicates two

06:32

now sometimes you might also want to

06:34

conditionally render based on the number

06:37

of notifications for example when

06:39

notifications is zero it doesn't really

06:42

make sense to indicate that we rather

06:45

hide the badge itself we can do that

06:49

using Mod Podge hidden attribute so back

06:52

an app component I'm going to add the

06:55

condition property binding with mat

06:58

badge hidden

07:02

and this is going to be equal to the

07:05

condition notifications is equal to zero

07:10

now if we take a look at the browser you

07:15

can still see the badge to go back to vs

07:19

code change the value to zero

07:23

and you can see that the batch is now

07:26

hidden that is how you conditionally

07:29

render a batch in angular material using

07:33

the matte batch hidden attribute alright

07:37

that's pretty much what I have about

07:39

badges

07:40

let me quickly point you to the

07:42

documentation so go to material dot io

07:45

components under buttons and indicators

07:49

there is badge and if you go to the API

07:52

tab you will know what has to be

07:55

imported alright then thank you guys for

07:58

watching don't forget to subscribe I'll

08:00

see you guys in the next video

Rate This

5.0 / 5 (0 votes)

العلامات ذات الصلة
AngularMaterialBadgesUINotificationsCustomizationPositioningSizingColoringConditional Rendering