material icon indicating copy to clipboard operation
material copied to clipboard

Morphable icons for SpeedDial

Open ThomasBurleson opened this issue 11 years ago • 7 comments

Idle - State 1

Hover - State 2

ThomasBurleson avatar May 26 '15 19:05 ThomasBurleson

  <md-icon md-selected-state="vm.currentState">
     <md-icon-state name="idle" md-svg-src="actions/add.svg" />
     <md-icon-state name="hover" md-svg-src="actions/compose.svg" />
  </md-icon>
Notes:
  1. Should we create SVG DOM elements for each state (which supports fades)... or dynamically inject ?
  2. <md-icon-state> is optional; if not specified then md-selected-state is ignored
  3. If md-selected-state value is not found in state registration cache, then default is the first md-icon-state registered.
  4. To support font-icons, may need to use option (1) above.
  5. Update area-label in response to non-default states (e.g. hover)

ThomasBurleson avatar May 26 '15 20:05 ThomasBurleson

I found this the other day it might be helpful. It morphs one svg into another. Take a look at the demo.

https://github.com/alexk111/SVG-Morpheus

epelc avatar May 27 '15 14:05 epelc

@epelc - yes, that resource was in our list of research items.

ThomasBurleson avatar May 27 '15 15:05 ThomasBurleson

Keep in mind the button label will have to update along with the icon, so that a user knows what the button does at all times.

marcysutton avatar May 27 '15 18:05 marcysutton

At the moment I am using an ungly modified mdIcon directive (at iconDirective.js#L185) which uses SVGMorpheus. Requires md-morph attribute on md-icon.

    var currentSvgIcon;
    if (attrName) {
      // Use either pre-configured SVG or URL source, respectively.
      attr.$observe(attrName, function (attrVal) {
        element.empty();
        if (attrVal) {
          if (angular.isDefined(attr.mdMorph)) {
            if (currentSvgIcon) {
              var old = currentSvgIcon;
              var oldIcon = $mdIcon(old);
              var newIcon = $mdIcon(attrVal);
              $q.all([newIcon, oldIcon]).then(function (icons) {
                icons[0].firstChild.style.display = 'none';
                icons[0].firstChild.id = attrVal;
                icons[1].firstChild.style.display = 'none';
                icons[1].firstChild.id = old;
                icons[0].appendChild(icons[1].firstChild);
                element.append(icons[0]);
                new SVGMorpheus(element.children()[0]).to(attrVal, JSON.parse(attr.options || null)); // jshint ignore:line
              });
            } else {
              $mdIcon(attrVal).then(function (svg) {
                element.append(svg);
              });
            }
            currentSvgIcon = attrVal;
          } else {
            $mdIcon(attrVal).then(function (svg) {
              element.append(svg);
            });
          }
        }
      });
    }

kuhnroyal avatar Jun 15 '15 14:06 kuhnroyal

+1

noamamit92 avatar Sep 07 '15 12:09 noamamit92

This issue is closed as part of our ‘Surge Focus on Material 2' efforts. For details, see our forum posting @ http://bit.ly/1UhZyWs.

ThomasBurleson avatar Jun 02 '16 14:06 ThomasBurleson