forked from visionmedia/uikit
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Added split button (needs docs/examples)
- Loading branch information
Showing
11 changed files
with
302 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ COMPONENTS = emitter \ | |
confirmation \ | ||
color-picker \ | ||
notification \ | ||
split-button \ | ||
menu \ | ||
card | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
.menu { | ||
display: none; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
|
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,27 @@ | ||
.split-button { | ||
display: inline-block; | ||
border: 1px solid #eee; | ||
} | ||
|
||
.split-button a { | ||
display: inline-block; | ||
float: left; | ||
height: 20px; | ||
line-height: 20px; | ||
padding: 5px 10px; | ||
text-decoration: none; | ||
-webkit-user-select: none; | ||
-moz-user-select: none; | ||
} | ||
|
||
.split-button .toggle { | ||
border-left: 1px solid #eee; | ||
} | ||
|
||
.split-button .toggle span { | ||
display: block; | ||
margin-top: 8px; | ||
border-left: 4px solid transparent; | ||
border-right: 4px solid transparent; | ||
border-top: 4px solid #888; | ||
} |
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,4 @@ | ||
<div class="split-button"> | ||
<a class="button" href="#">Action</a> | ||
<a class="toggle" href="#"><span></span></a> | ||
</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,106 @@ | ||
|
||
/** | ||
* Expose `SplitButton`. | ||
*/ | ||
|
||
exports.SplitButton = SplitButton; | ||
|
||
/** | ||
* Initialize a new `SplitButton` | ||
* with an optional `label`. | ||
* | ||
* @param {String} label | ||
* @api public | ||
*/ | ||
|
||
function SplitButton(label) { | ||
ui.Emitter.call(this); | ||
this.el = $(html); | ||
this.events(); | ||
this.render({ label: label }); | ||
this.state = 'hidden'; | ||
} | ||
|
||
/** | ||
* Inherit from `Emitter.prototype`. | ||
*/ | ||
|
||
SplitButton.prototype = new ui.Emitter; | ||
|
||
/** | ||
* Register event handlers. | ||
* | ||
* @api private | ||
*/ | ||
|
||
SplitButton.prototype.events = function(){ | ||
var self = this | ||
, el = this.el; | ||
|
||
el.find('.button').click(function(e){ | ||
e.preventDefault(); | ||
self.emit('click', e); | ||
}); | ||
|
||
el.find('.toggle').click(function(e){ | ||
e.preventDefault(); | ||
self.toggle(); | ||
}); | ||
}; | ||
|
||
/** | ||
* Toggle the drop-down contents. | ||
* | ||
* @return {SplitButton} | ||
* @api public | ||
*/ | ||
|
||
SplitButton.prototype.toggle = function(){ | ||
return 'hidden' == this.state | ||
? this.show() | ||
: this.hide(); | ||
}; | ||
|
||
/** | ||
* Show the drop-down contents. | ||
* | ||
* @return {SplitButton} | ||
* @api public | ||
*/ | ||
|
||
SplitButton.prototype.show = function(){ | ||
this.state = 'visible'; | ||
this.emit('show'); | ||
return this; | ||
}; | ||
|
||
/** | ||
* Hide the drop-down contents. | ||
* | ||
* @return {SplitButton} | ||
* @api public | ||
*/ | ||
|
||
SplitButton.prototype.hide = function(){ | ||
this.state = 'hidden'; | ||
this.emit('hide'); | ||
return this; | ||
}; | ||
|
||
/** | ||
* Render the split-button with the given `options`. | ||
* | ||
* @param {Object} options | ||
* @return {SplitButton} | ||
* @api private | ||
*/ | ||
|
||
SplitButton.prototype.render = function(options){ | ||
var options = options || {} | ||
, button = this.el.find('.button') | ||
, label = options.label; | ||
|
||
if ('string' == label) button.text(label); | ||
else button.text('').append(label); | ||
return this; | ||
}; |