Skip to content

Commit

Permalink
work towards input, making it clearable, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
brenthosie committed May 19, 2015
1 parent 570aa79 commit 3836321
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 2 deletions.
1 change: 1 addition & 0 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"directory":"../"}
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
# clearable-input
clearable-input is a Polymer element that encapsulates the idea of a text input that has a clickable icon inside the element to clear the input.
See the [component page](http://xrapiddavex.github.io/clearable-input/bower_components/clearable-input/) for more information.
23 changes: 23 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "clearable-input",
"version": "0.0.0",
"homepage": "https://github.com/xRapidDavex/clearable-input",
"authors": [
"Brent Hosie <[email protected]>",
"Garrett Nay <[email protected]"
],
"description": "clearable-input is a Polymer element that encapsulates the idea of a text input that has a clickable icon inside the element to clear the input.",
"main": "clearable-input.html",
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"../",
"test",
"tests"
],
"dependencies": {
"polymer": "Polymer/polymer#^0.5"
}
}
74 changes: 74 additions & 0 deletions clearable-input.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!--
`clearable-input` is a Polymer element that encapsulates the idea of a text input that has a clickable icon inside the element to clear the input.
<clearable-input></clearable-input>
@author Brent Hosie
@author Garrett Nay
@element clearable-input
@homepage http://github.com/xrapiddavex/clearable-input/
-->

<link rel="import" href="../polymer/polymer.html"/>

<polymer-element name="clearable-input" attributes="placeholder value readonly backgroundColor">
<template>
<style>
div{
border:1px solid silver;
display: inline-block;
}
input {
float: left;
border: none;
}
input:focus, button:focus{
outline:transparent;
}
button {
cursor: pointer;
border: none;
padding: 0 2px 0 0;
margin: 0;
background: #fff;
position: relative;
font-weight: bold;
opacity: 0;
}
</style>
<div>
<input type="text" id="textInput" placeholder="{{placeholder}}" background-color="{{backgroundColor}}" value="{{value}}" on-keyUp="{{keyup}}"/>
<button id="clearInput" on-click="{{clearInput}}">&#10005;</button>
</div>
</template>
<script>
(function() {
"use strict";

var determineButtonState = function() {
// when length 0, opacity is 0
this.$.clearInput.style.opacity = (this.$.textInput.value.length !== 0 ? 1 : 0);
};

Polymer({
ready: function() {
this.$.textInput.readOnly = (this.readonly !== void 0);
this.$.textInput.style.backgroundColor = this.readonlyBGColor;
},

keyup: function() {
determineButtonState.call(this);
},

textInputChanged: function() {
this.keyup();
},

clearInput: function() {
this.$.textInput.value = '';
this.keyup();
}
});
})();
</script>
</polymer-element>
12 changes: 12 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<title>clearable-input</title>
<script src="../webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="clearable-input.html">
</head>
<body unresolved>
<clearable-input></clearable-input>
</body>
</html>
14 changes: 14 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>

<script src="../webcomponentsjs/webcomponents.js"></script>
<link rel="import" href="../core-component-page/core-component-page.html">

</head>
<body unresolved>

<core-component-page></core-component-page>

</body>
</html>

0 comments on commit 3836321

Please sign in to comment.