-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
269 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules/ | ||
dev/ |
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,81 @@ | ||
# sling-web-component-list | ||
|
||
Sling Card Basic Component. | ||
|
||
## Install | ||
|
||
``` | ||
npm instal sling-web-component-list | ||
``` | ||
|
||
## Tag | ||
|
||
```HTML | ||
<sling-list></sling-list> | ||
``` | ||
|
||
## Dependencies | ||
|
||
* **sling-framework** | ||
* **sling-helpers** | ||
|
||
## Attributes and properties | ||
|
||
|Name|Type|Default Values|ReflectToAttribute|Observer|callSdk| | ||
|:--|:--|:--|:--:|:--|:--:| | ||
|srcdata|Array||| | ||
|srckeys|Array||| | ||
|cascadelist|Boolean|**false**|:heavy_check_mark:| | ||
|
||
### Description | ||
|
||
|Name|Description| | ||
|:---|:---| | ||
|srcdata |Uma lista que define o conteudo do componente..| | ||
|srckeys|Uma lista de chaves que dispõe com base na lista de dados a ordem dos dados.| | ||
|cascadelist|Define se a lista vai ser em cascata ou não.| | ||
|
||
## Events | ||
|
||
This component have no events. | ||
|
||
### Usage | ||
|
||
```HTML | ||
<sling-list | ||
srcdata="" | ||
srckeys=""> | ||
</sling-list> | ||
|
||
<script> | ||
const keys = [ | ||
'Descrição', | ||
'UF', | ||
'Cidade', | ||
'Endereço', | ||
'Número', | ||
'Complemento', | ||
'Bairro', | ||
]; | ||
const data = [ | ||
{ | ||
Descrição: 'teste', | ||
UF: 'teste', | ||
Cidade: 'teste', | ||
Endereço: 'teste', | ||
Número: 'teste', | ||
Complemento: 'teste', | ||
Bairro: 'teste', | ||
}, | ||
] | ||
const $list = Array.from(document.querySelectorAll('sling-list')); | ||
$list.forEach($list=> { | ||
$list.srcdata = data; | ||
$list.srckeys = keys; | ||
}); | ||
</script> | ||
``` | ||
|
||
![image](https://user-images.githubusercontent.com/22959060/46169828-82201100-c272-11e8-918a-05f1faa8dcfa.png) |
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,14 @@ | ||
{ | ||
"name": "sling-web-component-list", | ||
"version": "0.17.0", | ||
"description": "Sling List component", | ||
"author": "Stone Pagamentos", | ||
"module": "src/index.js", | ||
"main": "dist/cjs/es5/index.js", | ||
"jsnext:main": "dist/es/es6/index.js", | ||
"browser": "dist/iife/es6/index.js", | ||
"dependencies": { | ||
"sling-framework": "^1.5.0", | ||
"sling-helpers": "^1.5.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<script src="../../../scripts/helpers/injectDependencies.js"></script> | ||
<title>sling-list</title> | ||
</head> | ||
<body> | ||
<!-- cascade-list attribute for vertical view and slot for title--> | ||
<sling-list | ||
cascadelist | ||
srcdata="" | ||
srckeys=""> | ||
</sling-list> | ||
|
||
<sling-list | ||
srcdata="" | ||
srckeys=""> | ||
</sling-list> | ||
|
||
<script> | ||
const keys = [ | ||
'Descrição', | ||
'UF', | ||
'Cidade', | ||
'Endereço', | ||
'Número', | ||
'Complemento', | ||
'Bairro', | ||
]; | ||
|
||
const data = [ | ||
{ | ||
Descrição: 'teste', | ||
UF: 'teste', | ||
Cidade: 'teste', | ||
Endereço: 'teste', | ||
Número: 'teste', | ||
Complemento: 'teste', | ||
Bairro: 'teste', | ||
}, | ||
] | ||
|
||
const $list = Array.from(document.querySelectorAll('sling-list')); | ||
$list.forEach($list=> { | ||
$list.srcdata = data; | ||
$list.srckeys = keys; | ||
}); | ||
</script> | ||
</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,35 @@ | ||
.list-view { | ||
list-style: none; | ||
padding: 0; | ||
margin: 0 0 20px 0; | ||
} | ||
|
||
.list-view__row { | ||
color: #181c24; | ||
text-align: left; | ||
display: flex; | ||
font-size: 24px; | ||
} | ||
|
||
.list-view__key, | ||
.list-view__value { | ||
flex-basis: 0; | ||
} | ||
|
||
.list-view__key { | ||
font-weight: bold; | ||
padding: 5px; | ||
margin-top: 0; | ||
color: #424b54; | ||
white-space: nowrap; | ||
} | ||
|
||
.list-view__value { | ||
flex-grow: 1; | ||
padding: 5px; | ||
color: #181c24; | ||
} | ||
|
||
.list-view_cascade .list-view__row { | ||
flex-direction: column; | ||
} |
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,9 @@ | ||
:host { | ||
display: block; | ||
} | ||
|
||
/* for compatibility */ | ||
|
||
sling-list { | ||
display: block; | ||
} |
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,37 @@ | ||
import { html, SlingElement } from 'sling-framework'; | ||
|
||
export class List extends SlingElement { | ||
static get properties() { | ||
return { | ||
srcdata: Array, | ||
srckeys: Array, | ||
cascadelist: { | ||
type: Boolean, | ||
reflectToAttribute: true, | ||
}, | ||
}; | ||
} | ||
|
||
render() { | ||
const data = this.srcdata || []; | ||
const keys = this.srckeys || []; | ||
|
||
return html` | ||
<style> | ||
@import url('sling-web-component-list/src/index.css'); | ||
</style> | ||
${data.map(list => html` | ||
<ul className="list-view ${this.cascadelist ? 'list-view_cascade' : ''}"> | ||
${Object.values(list).map((item, index) => html` | ||
<li class="list-view__row"> | ||
<span class="list-view__key"> | ||
${keys[index]}${this.cascadelist ? '' : ':'} | ||
</span> | ||
<span class="list-view__value">${item != null ? item : '---'}</span> | ||
</li> | ||
`)} | ||
</ul> | ||
`)} | ||
`; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
packages/sling-web-component-list/src/component/List.test.js
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,32 @@ | ||
import { registerComponent } from 'sling-helpers'; | ||
import { List } from './List.js'; | ||
|
||
registerComponent('sling-list', List); | ||
|
||
let $List; | ||
|
||
describe('List', () => { | ||
beforeEach(() => { | ||
$List = document.createElement('sling-list'); | ||
document.body.appendChild($List); | ||
}); | ||
|
||
afterEach(() => { | ||
if ($List != null) { | ||
document.body.removeChild($List); | ||
$List = undefined; | ||
} | ||
}); | ||
|
||
it('Should reflect "cascadelist" to attribute to property', () => { | ||
$List.setAttribute('cascadelist', ''); | ||
|
||
expect($List.cascadelist).to.be.true; | ||
}); | ||
|
||
it('Should reflect "cascadelist" to attribute to property', () => { | ||
$List.cascadelist = false; | ||
|
||
expect($List.cascadelist).to.be.false; | ||
}); | ||
}); |
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,2 @@ | ||
@import url('assets/List.css'); | ||
@import url('assets/host.css'); |
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 @@ | ||
import { registerComponent } from 'sling-helpers'; | ||
import { List } from './component/List.js'; | ||
|
||
registerComponent('sling-list', List); |