Skip to content
This repository has been archived by the owner on Jun 10, 2023. It is now read-only.

Commit

Permalink
✨ Add List and ListItem
Browse files Browse the repository at this point in the history
Signed-off-by: Eduardo San Martin Morote <posva13@gmail.com>
  • Loading branch information
posva committed Apr 13, 2017
1 parent dd15450 commit 8d2eab4
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/List/List.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<script>
import { propsToClasses } from '../utils'
export default {
functional: true,
props: {
tag: {
type: String,
default: 'ul',
},
dense: Boolean,
twoLines: Boolean,
},
render (h, { data, children, props }) {
const tag = props.tag
delete props.tag
const staticClass = propsToClasses('mdc-list', props)
data.staticClass = data.staticClass
? `${data.staticClass} ${staticClass}`
: staticClass
return h(tag, {
...data,
}, children)
},
}
</script>

<style lang="scss" src="@material/list/mdc-list.scss">
</style>
25 changes: 25 additions & 0 deletions src/List/ListItem.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<script>
export default {
functional: true,
props: {
tag: {
type: String,
default: 'li',
},
},
render (h, { data, children, props: { tag }}) {
const staticClass = 'mdc-list-item'
data.staticClass = data.staticClass
? `${data.staticClass} ${staticClass}`
: staticClass
return h(tag, {
...data,
}, children)
},
}
</script>

<style lang="scss" src="@material/list/mdc-list.scss">
</style>
38 changes: 38 additions & 0 deletions test/specs/List.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import List from 'src/List/List.vue'
import ListItem from 'src/List/ListItem.vue'
import {
createVM,
dataPropagationTest,
attrTest,
} from '../helpers'

describe('List', function () {
it('renders an upgraded list', function () {
const vm = createVM(this, h => (
<List ref='list'>
<ListItem>Item 1</ListItem>
<ListItem>Item 2</ListItem>
</List>
), {
})
vm.$refs.list.should.have.class('mdc-list')
vm.$refs.list.should.match('ul')
})

it('can render a custom tag', function () {
const vm = createVM(this, h => (
<List ref='list' tag='div'>Hello</List>
))
vm.$refs.list.should.have.class('mdc-list')
vm.$refs.list.should.match('div')
})

it('keeps original tag data', dataPropagationTest(List))

describe('attrs', function () {
attrTest(it, 'mdc-list', List, [
'dense',
'two-lines',
])
})
})
18 changes: 18 additions & 0 deletions test/specs/ListItem.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import ListItem from 'src/List/ListItem.vue'
import {
createVM,
dataPropagationTest,
} from '../helpers'

describe('ListItem', function () {
it('renders an upgraded list item', function () {
const vm = createVM(this, `
<ListItem>Item 1</ListItem>
`, {
components: { ListItem },
})
vm
})

it('keeps original tag data', dataPropagationTest(ListItem))
})

0 comments on commit 8d2eab4

Please sign in to comment.