-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from Availity/feature/add-removable-labels
adding removable labels
- Loading branch information
Showing
8 changed files
with
178 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
--- | ||
title: Removable Labels | ||
--- | ||
<div data-ng-controller="RemovableLabelController"> | ||
<div class="guide-example"> | ||
<form role="form"> | ||
<div class="row"> | ||
<div class="form-group col-sm-3"> | ||
<label for="newRemovableLabel">Label</label> | ||
<input id="newRemovableLabel" type="text" class="form-control" data-ng-model="newRemovableLabel"> | ||
</div> | ||
<div class="form-group col-sm-6"> | ||
<label for="newLabelType">Type</label> | ||
<div id="newLabelType" class="btn-group input-group"> | ||
<button type="button" class="btn btn-default" data-ng-click="addLabel('label-default')">Default</button> | ||
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> | ||
<span class="caret"></span> | ||
<span class="sr-only">Toggle Dropdown</span> | ||
</button> | ||
<ul class="dropdown-menu"> | ||
<li><a data-ng-click="addLabel('label-unstyled')">Unstyled</a></li> | ||
<li><a data-ng-click="addLabel('label-primary')">Primary</a></li> | ||
<li><a data-ng-click="addLabel('label-success')">Success</a></li> | ||
<li><a data-ng-click="addLabel('label-info')">Info</a></li> | ||
<li><a data-ng-click="addLabel('label-warning')">Warning</a></li> | ||
<li><a data-ng-click="addLabel('label-danger')">Danger</a></li> | ||
<li><a data-ng-click="addLabel('label-brand')">Brand</a></li> | ||
<li><a data-ng-click="addLabel('label-extra')">Extra</a></li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<button type="button" class="btn btn-default btn-xs" data-ng-click="clearLabels()">Clear All</button> | ||
<span data-ng-repeat="label in labels"> | ||
<span class="label" data-ng-class="label.labelClass" data-av-removable-label data-on-remove="removeLabel" data-remove-value="$index"> | ||
<span data-ng-bind="label.value"></span> | ||
</span> | ||
</span> | ||
</div> | ||
</form> | ||
</div> | ||
<code class="language-markup"> | ||
<span data-ng-repeat="label in labels"> | ||
<span class="label" | ||
data-ng-class="label.labelClass" | ||
data-av-removable-label | ||
data-on-remove="removeLabel" | ||
data-remove-value="$index"> | ||
<span data-ng-bind="label.value"></span> | ||
</span> | ||
</span> | ||
</code> | ||
</div> |
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,30 @@ | ||
(function(root) { | ||
|
||
'use strict'; | ||
|
||
var availity = root.availity; | ||
|
||
availity.demo.controller('RemovableLabelController', function($scope) { | ||
$scope.labels = [ | ||
{ value: 'Default', labelClass: 'label-default' }, | ||
{ value: 'Primary', labelClass: 'label-primary' }, | ||
{ value: 'Success', labelClass: 'label-success' }, | ||
{ value: 'Info', labelClass: 'label-info' }, | ||
{ value: 'Warning', labelClass: 'label-warning' }, | ||
{ value: 'Danger', labelClass: 'label-danger' } | ||
]; | ||
|
||
$scope.addLabel = function(labelClass) { | ||
$scope.labels.push({value: $scope.newRemovableLabel, labelClass: labelClass}); | ||
}; | ||
|
||
$scope.removeLabel = function(index) { | ||
$scope.labels.splice(index, 1); | ||
}; | ||
|
||
$scope.clearLabels = function() { | ||
$scope.labels = []; | ||
}; | ||
}); | ||
|
||
})(window); |
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 @@ | ||
<a data-ng-click="removeLabel()"><i class="icon icon-cancel"></i></a><span data-ng-transclude></span> |
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,29 @@ | ||
(function(root) { | ||
'use strict'; | ||
|
||
var availity = root.availity; | ||
|
||
availity.ui.constant('AV_REMOVABLE_LABEL', { | ||
TEMPLATE: 'ui/removable-label/removable-label-tpl.html' | ||
}); | ||
|
||
availity.ui.directive('avRemovableLabel', function(AV_REMOVABLE_LABEL) { | ||
return { | ||
templateUrl: AV_REMOVABLE_LABEL.TEMPLATE, | ||
transclude: true, | ||
scope: { | ||
removeValue: '=', | ||
onRemove: '&' | ||
}, | ||
link: function(scope, element, attrs) { | ||
element.addClass('label-remove'); | ||
scope.removeLabel = function() { | ||
if(!attrs.disabled) { | ||
scope.onRemove()(scope.removeValue); | ||
} | ||
}; | ||
} | ||
}; | ||
}); | ||
|
||
})(window); |
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,59 @@ | ||
/* global beforeEach, availity, expect, module, inject, describe, it */ | ||
describe('avRemovableLabel', function() { | ||
|
||
'use strict'; | ||
|
||
beforeEach(function() { | ||
module('availity'); | ||
module('availity.ui'); | ||
}); | ||
|
||
beforeEach(inject(function($templateCache) { | ||
|
||
$templateCache.put('ui/removable-label/removable-label-tpl.html', ''); | ||
})); | ||
|
||
availity.mock.directiveSpecHelper(); | ||
var $el; | ||
|
||
// jscs: disable | ||
var fixtures = { | ||
'default': '<div av-removable-label on-remove="demo.removeLabel" remove-value="1">New Label</div>', | ||
'disabled': '<div av-removable-label on-remove="demo.removeLabel" remove-value="1" disabled="disabled">New Label</div>' | ||
}; | ||
// jscs: enable | ||
|
||
beforeEach(inject(function() { | ||
|
||
availity.mock.$scope.demo = {}; | ||
availity.mock.$scope.demo.removeLabel = function() {}; | ||
|
||
spyOn(availity.mock.$scope.demo, 'removeLabel').and.callFake(function() { | ||
}); | ||
|
||
})); | ||
|
||
it('should add label-remove class', function() { | ||
|
||
$el = availity.mock.compileDirective(fixtures['default']); | ||
|
||
expect($el.hasClass('label-remove')).toBe(true); | ||
}); | ||
|
||
it('should call remove label callback function with removed value', function() { | ||
|
||
$el = availity.mock.compileDirective(fixtures['default']); | ||
|
||
$el.data('$isolateScope').removeLabel(); | ||
expect(availity.mock.$scope.demo.removeLabel).toHaveBeenCalledWith(1); | ||
}); | ||
|
||
it('should not call remove label callback function when disabled', function() { | ||
|
||
$el = availity.mock.compileDirective(fixtures['disabled']); | ||
|
||
$el.data('$isolateScope').removeLabel(); | ||
expect(availity.mock.$scope.demo.removeLabel).not.toHaveBeenCalled(); | ||
}); | ||
|
||
}); |