This repository has been archived by the owner on Sep 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ripple): move component specific logic
BREAKING CHANGE: Removed attach(button|tab|checkbox|list)Behavior in favor of composing an injectable ripple service specific to your target. $mdInkRipple was too aware of how to configure components. You now have access to $mdButtonInkRipple, $mdTabInkRipple, $mdListInkRipple, $mdCheckboxInkRipple. Change your code from this: ``` javascript function MyService($mdInkRipple) { //... Included for brevity $mdInkRipple.attachButtonBehavior(scope, element, options); } ``` To this: ``` javascript function MyService($mdButtonInkRipple) { //... Included for brevity $mdButtonInkRipple.attach(scope, element, options); } ```
- Loading branch information
1 parent
198199c
commit 3b0f12e
Showing
14 changed files
with
350 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc service | ||
* @name $mdButtonInkRipple | ||
* @module material.core | ||
* | ||
* @description | ||
* Provides ripple effects for md-button. See $mdInkRipple service for all possible configuration options. | ||
* | ||
* @param {object=} scope Scope within the current context | ||
* @param {object=} element The element the ripple effect should be applied to | ||
* @param {object=} options (Optional) Configuration options to override the defaultripple configuration | ||
*/ | ||
|
||
angular.module('material.core') | ||
.factory('$mdButtonInkRipple', MdButtonInkRipple); | ||
|
||
function MdButtonInkRipple($mdInkRipple) { | ||
return { | ||
attach: attach | ||
}; | ||
|
||
function attach(scope, element, options) { | ||
var elementOptions = optionsForElement(element); | ||
return $mdInkRipple.attach(scope, element, angular.extend(elementOptions, options)); | ||
}; | ||
|
||
function optionsForElement(element) { | ||
if (element.hasClass('md-icon-button')) { | ||
return { | ||
isMenuItem: element.hasClass('md-menu-item'), | ||
fitRipple: true, | ||
center: true | ||
}; | ||
} else { | ||
return { | ||
isMenuItem: element.hasClass('md-menu-item'), | ||
dimBackground: true | ||
} | ||
} | ||
}; | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
describe('MdButtonInkRipple', function() { | ||
|
||
beforeEach(module('material.core')); | ||
|
||
var $element, $rootScope, $mdButtonInkRipple, $mdInkRipple; | ||
beforeEach(inject(function(_$rootScope_, _$mdButtonInkRipple_, _$mdInkRipple_) { | ||
$rootScope = _$rootScope_; | ||
$mdButtonInkRipple = _$mdButtonInkRipple_; | ||
$mdInkRipple = _$mdInkRipple_; | ||
|
||
$element = angular.element('<button></button>'); | ||
spyOn($mdInkRipple, 'attach'); | ||
})); | ||
|
||
it('applies the correct ripple configuration for a md-icon-button', function() { | ||
$element.addClass('md-icon-button'); | ||
|
||
$mdButtonInkRipple.attach($rootScope, $element); | ||
|
||
var expected = { | ||
isMenuItem: false, | ||
fitRipple: true, | ||
center: true | ||
}; | ||
|
||
expect($mdInkRipple.attach).toHaveBeenCalledWith($rootScope, $element, expected); | ||
}); | ||
|
||
it('applies the correct ripple configuration for all other buttons', function() { | ||
$mdButtonInkRipple.attach($rootScope, $element); | ||
|
||
var expected = { | ||
isMenuItem: false, | ||
dimBackground: true | ||
}; | ||
|
||
expect($mdInkRipple.attach).toHaveBeenCalledWith($rootScope, $element, expected); | ||
}); | ||
|
||
it('configures the button as a menu item when it is a md-menu-item', function() { | ||
$element.addClass('md-menu-item'); | ||
|
||
$mdButtonInkRipple.attach($rootScope, $element); | ||
|
||
var expected = { | ||
isMenuItem: true, | ||
dimBackground: true | ||
}; | ||
|
||
expect($mdInkRipple.attach).toHaveBeenCalledWith($rootScope, $element, expected); | ||
}); | ||
|
||
it('allows ripple configuration to be overridden', function() { | ||
$mdButtonInkRipple.attach($rootScope, $element, { dimBackground: false }); | ||
|
||
var expected = { | ||
isMenuItem: false, | ||
dimBackground: false | ||
}; | ||
|
||
expect($mdInkRipple.attach).toHaveBeenCalledWith($rootScope, $element, expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc service | ||
* @name $mdCheckboxInkRipple | ||
* @module material.core | ||
* | ||
* @description | ||
* Provides ripple effects for md-checkbox. See $mdInkRipple service for all possible configuration options. | ||
* | ||
* @param {object=} scope Scope within the current context | ||
* @param {object=} element The element the ripple effect should be applied to | ||
* @param {object=} options (Optional) Configuration options to override the defaultripple configuration | ||
*/ | ||
|
||
angular.module('material.core') | ||
.factory('$mdCheckboxInkRipple', MdCheckboxInkRipple); | ||
|
||
function MdCheckboxInkRipple($mdInkRipple) { | ||
return { | ||
attach: attach | ||
}; | ||
|
||
function attach(scope, element, options) { | ||
return $mdInkRipple.attach(scope, element, angular.extend({ | ||
center: true, | ||
dimBackground: false, | ||
fitRipple: true | ||
}, options)); | ||
}; | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
describe('MdCheckboxInkRipple', function() { | ||
|
||
beforeEach(module('material.core')); | ||
|
||
var $element, $rootScope, $mdCheckboxInkRipple, $mdInkRipple; | ||
beforeEach(inject(function(_$rootScope_, _$mdCheckboxInkRipple_, _$mdInkRipple_) { | ||
$rootScope = _$rootScope_; | ||
$mdCheckboxInkRipple = _$mdCheckboxInkRipple_; | ||
$mdInkRipple = _$mdInkRipple_; | ||
|
||
$element = jasmine.createSpy('element'); | ||
spyOn($mdInkRipple, 'attach'); | ||
})); | ||
|
||
it('applies the correct ripple configuration', function() { | ||
$mdCheckboxInkRipple.attach($rootScope, $element); | ||
|
||
var expected = { | ||
center: true, | ||
dimBackground: false, | ||
fitRipple: true | ||
}; | ||
|
||
expect($mdInkRipple.attach).toHaveBeenCalledWith($rootScope, $element, expected); | ||
}); | ||
|
||
it('allows ripple configuration to be overridden', function() { | ||
$mdCheckboxInkRipple.attach($rootScope, $element, { center: false, fitRipple: false }); | ||
|
||
var expected = { | ||
center: false, | ||
dimBackground: false, | ||
fitRipple: false | ||
}; | ||
|
||
expect($mdInkRipple.attach).toHaveBeenCalledWith($rootScope, $element, expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc service | ||
* @name $mdListInkRipple | ||
* @module material.core | ||
* | ||
* @description | ||
* Provides ripple effects for md-list. See $mdInkRipple service for all possible configuration options. | ||
* | ||
* @param {object=} scope Scope within the current context | ||
* @param {object=} element The element the ripple effect should be applied to | ||
* @param {object=} options (Optional) Configuration options to override the defaultripple configuration | ||
*/ | ||
|
||
angular.module('material.core') | ||
.factory('$mdListInkRipple', MdListInkRipple); | ||
|
||
function MdListInkRipple($mdInkRipple) { | ||
return { | ||
attach: attach | ||
}; | ||
|
||
function attach(scope, element, options) { | ||
return $mdInkRipple.attach(scope, element, angular.extend({ | ||
center: false, | ||
dimBackground: true, | ||
outline: false, | ||
rippleSize: 'full' | ||
}, options)); | ||
}; | ||
}; | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
describe('MdListInkRipple', function() { | ||
|
||
beforeEach(module('material.core')); | ||
|
||
var $element, $rootScope, $mdListInkRipple, $mdInkRipple; | ||
beforeEach(inject(function(_$rootScope_, _$mdListInkRipple_, _$mdInkRipple_) { | ||
$rootScope = _$rootScope_; | ||
$mdListInkRipple = _$mdListInkRipple_; | ||
$mdInkRipple = _$mdInkRipple_; | ||
|
||
$element = jasmine.createSpy('element'); | ||
spyOn($mdInkRipple, 'attach'); | ||
})); | ||
|
||
it('applies the correct ripple configuration', function() { | ||
$mdListInkRipple.attach($rootScope, $element); | ||
|
||
var expected = { | ||
center: false, | ||
dimBackground: true, | ||
outline: false, | ||
rippleSize: 'full' | ||
}; | ||
|
||
expect($mdInkRipple.attach).toHaveBeenCalledWith($rootScope, $element, expected); | ||
}); | ||
|
||
it('allows ripple configuration to be overridden', function() { | ||
$mdListInkRipple.attach($rootScope, $element, { center: true, outline: true }); | ||
|
||
var expected = { | ||
center: true, | ||
dimBackground: true, | ||
outline: true, | ||
rippleSize: 'full' | ||
}; | ||
|
||
expect($mdInkRipple.attach).toHaveBeenCalledWith($rootScope, $element, expected); | ||
}); | ||
}); |
Oops, something went wrong.