material icon indicating copy to clipboard operation
material copied to clipboard

class-* similar to hide-* and show-*

Open canercandan opened this issue 11 years ago • 4 comments

Similar to hide-* and show-*, class-* attributes enable to apply CSS class name for a specific range of devices sm, gt-sm, md, gt-md, lg and gt-lg.

You can use it the same way you are already using hide-* and show-*. Here is an example:

<img class-sm="size-sm" class-gt-sm="size"/>
.size-sm { width: 100px; }
.size { width: 200px; }

Here is an example of implementation:

(function () {
  "use strict";

  angular.module("YourAppName")
    // directive class-sm
    .directive("classSm", [
      "$mdMedia",
      function($mdMedia) {
        if ($mdMedia("sm")) {
          return {
            restrict: "A",
            link: function(scope, elem, attrs) {
              elem.addClass(attrs.classSm);
            }
          };
        }
      }
    ])
    // directive class-gt-sm
    .directive("classGtSm", [
      "$mdMedia",
      function($mdMedia) {
        if ($mdMedia("gt-sm")) {
          return {
            restrict: "A",
            link: function(scope, elem, attrs) {
              elem.addClass(attrs.classGtSm);
            }
          };
        }
      }
    ])
    // directive class-md
    .directive("classMm", [
      "$mdMedia",
      function($mdMedia) {
        if ($mdMedia("md")) {
          return {
            restrict: "A",
            link: function(scope, elem, attrs) {
              elem.addClass(attrs.classMd);
            }
          };
        }
      }
    ])
    // directive class-gt-md
    .directive("classGtMd", [
      "$mdMedia",
      function($mdMedia) {
        if ($mdMedia("gt-md")) {
          return {
            restrict: "A",
            link: function(scope, elem, attrs) {
              elem.addClass(attrs.classGtMd);
            }
          };
        }
      }
    ])
    // directive class-lg
    .directive("classLg", [
      "$mdMedia",
      function($mdMedia) {
        if ($mdMedia("lg")) {
          return {
            restrict: "A",
            link: function(scope, elem, attrs) {
              elem.addClass(attrs.classLg);
            }
          };
        }
      }
    ])
    // directive class-gt-lg
    .directive("classGtLg", [
      "$mdMedia",
      function($mdMedia) {
        if ($mdMedia("gt-lg")) {
          return {
            restrict: "A",
            link: function(scope, elem, attrs) {
              elem.addClass(attrs.classGtLg);
            }
          };
        }
      }
    ])
  ;
}());

I think it could be useful to add it as a builtin feature.

canercandan avatar Oct 26 '15 14:10 canercandan

Interesting feature but not in scope and focus for ngMaterial.

ThomasBurleson avatar Nov 05 '15 19:11 ThomasBurleson

+1 I would also like to see this.

davidpoxon avatar Mar 06 '16 12:03 davidpoxon

@noilly That issue is already implemented, see @ThomasBurleson's solution in #3815.

  • #7121 was an attribute wrapper for $mdMedia

devversion avatar Mar 06 '16 13:03 devversion

@DevVersion cool, thank you! :)

davidpoxon avatar Mar 07 '16 08:03 davidpoxon