-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding unique number, adding attributeChanged detection, adding starg…
…azers demo app
- Loading branch information
Showing
6 changed files
with
146 additions
and
1 deletion.
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Stargazers Demo</title> | ||
<script src="../../src/Slim.js"></script> | ||
<script> | ||
Slim.polyfill('https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/0.7.24/webcomponents-lite.min.js'); | ||
</script> | ||
<script src="stargazers-demo.js"></script> | ||
<script src="stargazers-item.js"></script> | ||
</head> | ||
<body> | ||
<stargazers-demo></stargazers-demo> | ||
</body> | ||
</html> |
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,49 @@ | ||
Slim.tag('stargazers-demo', | ||
|
||
`<h1 bind>[[repoName]] Stargazers!</h1> | ||
<div> | ||
<input slim-id="myInput" type="text" placeholder="user/repo" /> | ||
<button click="search">Search...</button> | ||
</div> | ||
<div id="results"> | ||
<stargazer-item handle-select="handleSelect" size="128" slim-repeat="stargazers"></stargazer-item> | ||
</div> | ||
<style bind> | ||
#results { | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
</style> | ||
`, | ||
|
||
class extends Slim { | ||
get useShadow() { return true; } | ||
|
||
onBeforeCreated() { | ||
this.repoName = 'eavichay/slim.js'; | ||
this.stargazers = []; | ||
} | ||
|
||
onCreated() { | ||
this.runQuery(); | ||
} | ||
|
||
handleSelect(data) { | ||
alert(data.html_url); | ||
} | ||
|
||
search() { | ||
this.repoName = this.myInput.value; | ||
this.stargazers = []; | ||
this.runQuery(); | ||
} | ||
|
||
runQuery() { | ||
fetch(`https://api.github.com/repos/${this.repoName}/stargazers?page=1&per_page=100`) | ||
.then(response => response.json() ) | ||
.then(stargazers => { | ||
this.stargazers = stargazers; | ||
}); | ||
} | ||
}); |
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,46 @@ | ||
|
||
Slim.tag('stargazer-item', | ||
|
||
` | ||
<img width="[[size]]" height="[[size]]" src="[[data.avatar_url]]" /> | ||
<h1 bind click="handleClick">[[data.login]]</h1> | ||
<style bind> | ||
:host { | ||
position: relative; | ||
display: inline-flex; | ||
flex-direction: column; | ||
width: [[size]]px; | ||
height: [[size]]px; | ||
border: 1px solid black; | ||
overflow: hidden; | ||
margin: 0; | ||
padding: 0; | ||
border-radius: 1em; | ||
} | ||
h1 { | ||
position: absolute; | ||
bottom: 0; | ||
left: 0; | ||
width: 100%; | ||
background-color: rgba(0,0,0,0.8); | ||
color: white; | ||
font-size: 14px; | ||
font-family: monospace; | ||
cursor: pointer; | ||
} | ||
h1::before { | ||
content: '[[data_index]] '; | ||
} | ||
</style> | ||
`, | ||
|
||
class extends Slim { | ||
get useShadow() { return true; } | ||
|
||
handleClick() { | ||
this.callAttribute('handle-select', this.data); | ||
} | ||
}); |
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