Morphable icons for SpeedDial


<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:
- Should we create SVG DOM elements for each state (which supports fades)... or dynamically inject ?
<md-icon-state>is optional; if not specified thenmd-selected-stateis ignored- If
md-selected-statevalue is not found in state registration cache, then default is the first md-icon-state registered. - To support font-icons, may need to use option (1) above.
- Update area-label in response to non-default states (e.g. hover)
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 - yes, that resource was in our list of research items.
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.
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);
});
}
}
});
}
+1
This issue is closed as part of our ‘Surge Focus on Material 2' efforts. For details, see our forum posting @ http://bit.ly/1UhZyWs.