طريقة إنشاء ثيمات للمشروع في Angular Material (ألوان)

 



@import '@angular/material/theming';

@include mat-core();

$my-theme-primary: mat-palette($mat-cyan);
$my-theme-accent: mat-palette($mat-pink, A200, A100, A400);
$my-theme-warn: mat-palette($mat-yellow);
$my-theme: mat-light-theme($my-theme-primary, $my-theme-accent, $my-theme-warn);
@include angular-material-theme($my-theme);



ولمزيد من التخصيص (my-theme.scss):

@import "@angular/material/theming";
@include mat-core();


$md-mcgpalette0: (
    50: #e2e6eb,
    100: #b7c1cd,
    200: #8797ac,
    300: #576d8a,
    400: #334e71,
    500: #0f2f58,
    600: #0d2a50,
    700: #0b2347,
    800: #081d3d,
    900: #04122d,
    A100: #668fff,
    A200: #3369ff,
    A400: #0044ff,
    A700: #003de6,
    contrast: (
        50: #000000,
        100: #000000,
        200: #000000,
        300: #ffffff,
        400: #ffffff,
        500: #ffffff,
        600: #ffffff,
        700: #ffffff,
        800: #ffffff,
        900: #ffffff,
        A100: #000000,
        A200: #ffffff,
        A400: #ffffff,
        A700: #ffffff
    )
);

$my-theme-primary: mat-palette($md-mcgpalette0, 600, 300, 600, 50); //
$my-theme-accent: mat-palette($mat-yellow);
$my-theme-warn: mat-palette($mat-red);
$my-theme: mat-light-theme($my-theme-primary, $my-theme-accent, $my-theme-warn);
@include angular-material-theme($my-theme);



أضف اسم الملف إلى Angular.json :
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/my-theme.scss",
              "src/styles.scss",
              "src/bootstrap.min.css",
              "node_modules/primeng/resources/themes/lara-light-blue/theme.css",
              "node_modules/primeng/resources/primeng.min.css"
            ],



لتغيير ألوان الـ Snackbar تحتاج استخدام هذه الطريقة:

.my-arabic-custom-snackbar {
    direction: rtl !important;
    text-align: right !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: #fff !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        background-color: $primary-bakery-color !important;
    }
}

.my-english-custom-snackbar {
    direction: ltr !important;
    text-align: left !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: #fff !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        background-color: $primary-bakery-color !important;
    }
}


وبهذا النحو سيكون ملف الخدمة:

export class SnackBarService {
  constructor(private _snackBar: MatSnackBar,
    private translateService: TranslateService) { }

  openSnackBarCenter(message: string, action: string) {
    this._snackBar.open(message, action, {
      panelClass: this.translateService.currentLang === 'ar'? 'my-arabic-custom-snackbar':'my-english-custom-snackbar',
      duration: 5000,
    });
  }
}

الاستخدام الأمثل للـ Snack-bars

  // ---------------------------------- Snackes -------------------------
  success(message: any, action: any, lang: string = 'ar') {
    this._snackBar.open('✔ ' + message, action, {
      panelClass: lang === 'ar' ? 'snackbar-rtl-success' : 'snackbar-ltr-success',
      duration: 5000
    });
  }

  warning(message: any, action: any, lang: string = 'ar') {
    this._snackBar.open('⚠ ' + message, action, {
      panelClass: lang === 'ar' ? 'snackbar-rtl-warning' : 'snackbar-ltr-warning',
      duration: 5000
    });
  }

  info(message: any, action: any, lang: string = 'ar') {
    this._snackBar.open('❕' + message, action, {
      panelClass: lang === 'ar' ? 'snackbar-rtl-info' : 'snackbar-ltr-info',
      duration: 5000
    });
  }

  danger(message: any, action: any, lang: string = 'ar') {
    this._snackBar.open("💔 " + message, action, {
      panelClass: lang === 'ar' ? 'snackbar-rtl-danger' : 'snackbar-ltr-danger',
      duration: 5000
    });
  }
  // ---------------------------------- End -------------------------

ملف الـ css:


// -------------------- Snack ----------------

.snackbar-rtl-success {
    direction: rtl !important;
    text-align: right !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: black !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        border: solid $border-color 1px;
        border-radius: 10px;
        box-shadow: $box-shadow;
        background-color: #5cb85c !important;
        line-height: 1.9 !important;
        text-align: center !important;
        font-weight: bold !important;
    }
}

.snackbar-ltr-success {
    direction: ltr !important;
    text-align: left !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: black !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        border: solid $border-color 1px;
        border-radius: 10px;
        box-shadow: $box-shadow;
        background-color: #5cb85c !important;
        line-height: 1.9 !important;
        text-align: center !important;
        font-weight: bold !important;
    }
}

.snackbar-rtl-info {
    direction: rtl !important;
    text-align: right !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: black !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        border: solid $border-color 1px;
        border-radius: 10px;
        box-shadow: $box-shadow;
        background-color: #33b5e5 !important;
        line-height: 1.9 !important;
        text-align: center !important;
        font-weight: bold !important;
    }
}

.snackbar-ltr-info {
    direction: ltr !important;
    text-align: left !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: black !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        border: solid $border-color 1px;
        border-radius: 10px;
        box-shadow: $box-shadow;
        background-color: #33b5e5 !important;
        line-height: 1.9 !important;
        text-align: center !important;
        font-weight: bold !important;
    }
}

.snackbar-rtl-danger {
    direction: rtl !important;
    text-align: right !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: #fff !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        border: solid $border-color 1px;
        border-radius: 10px;
        box-shadow: $box-shadow;
        background-color: #ff4444 !important;
        line-height: 1.9 !important;
        text-align: center !important;
        font-weight: bold !important;
    }
}

.snackbar-ltr-danger {
    direction: ltr !important;
    text-align: left !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: #fff !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        border: solid $border-color 1px;
        border-radius: 10px;
        box-shadow: $box-shadow;
        background-color: #ff4444 !important;
        line-height: 1.9 !important;
        text-align: center !important;
        font-weight: bold !important;
    }
}

.snackbar-rtl-warning {
    direction: rtl !important;
    text-align: right !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: black !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        border: solid $border-color 1px;
        border-radius: 10px;
        box-shadow: $box-shadow;
        background-color: #ffbb33 !important;
        line-height: 1.9 !important;
        text-align: center !important;
        font-weight: bold !important;
    }
}

.snackbar-ltr-warning {
    direction: ltr !important;
    text-align: left !important;
    // التحكم في النص
    .mat-mdc-snack-bar-label {
        color: black !important;
    }

    // التحكم في لون الخلفية
    .mdc-snackbar__surface {
        border: solid $border-color 1px;
        border-radius: 10px;
        box-shadow: $box-shadow;
        background-color: #ffbb33 !important;
        line-height: 1.9 !important;
        text-align: center !important;
        font-weight: bold !important;
    }
}

// ------------------ end -----------------------






تعليقات

المشاركات الشائعة من هذه المدونة

ngx-extended-pdf-viewer

how to getting access token for https://fcm.googleapis.com/v1/projects/al-ayahya-co/messages:send for angular and backend nestjs

طريقة تفعيل زر Inline Keyboard في Telegram Bot