Skip to content

Commit 28a9916

Browse files
committed
comp(MdSubheader): create subheaders
1 parent f790ba9 commit 28a9916

File tree

13 files changed

+151
-4
lines changed

13 files changed

+151
-4
lines changed

docs/app/i18n/en-US.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ export default {
5252
switch: {
5353
title: 'Switch'
5454
},
55+
subheader: {
56+
title: 'Subheader'
57+
},
5558
toolbar: {
5659
title: 'Toolbar'
5760
},

docs/app/pages/Components/Divider/Divider.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<example src="./examples/Divider.vue" />
22

33
<template>
4-
<page-container centered :title="$t('pages.content.title')">
4+
<page-container centered :title="$t('pages.divider.title')">
55
<div class="page-container-section">
66
<p>A divider is a thin, lightweight rule that groups content in lists and page layouts and help organize page content and hierarchy into individual tiles.</p>
77
<p>The dividers can be used in lists and to separate content. They fit well in navigation panels and menus.</p>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<example src="./examples/Subheader.vue" />
2+
3+
<template>
4+
<page-container centered :title="$t('pages.subheader.title')">
5+
<div class="page-container-section">
6+
<p>Subheaders are list tiles that delineate sections of a list or grid list.</p>
7+
<p>The subheader can be used in lists, grid and even on selects and are typically related to filtering or sorting criteria. They fit well in navigation panels and grid lists.</p>
8+
</div>
9+
10+
<div class="page-container-section">
11+
<h2>Subheader</h2>
12+
13+
<code-example title="Subheader" :component="examples['subheader']" />
14+
15+
<api-item title="API - md-subheader">
16+
<p>This componen do not have any extra option.</p>
17+
</api-item>
18+
</div>
19+
</page-container>
20+
</template>
21+
22+
<script>
23+
import examples from 'docs-mixins/docsExample'
24+
25+
export default {
26+
name: 'Subheader',
27+
mixins: [examples]
28+
}
29+
</script>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<template>
2+
<div>
3+
<md-subheader>Subheader Default</md-subheader>
4+
<md-subheader class="md-primary">Subheader Primary</md-subheader>
5+
</div>
6+
</template>
7+
8+
<style lang="scss" scoped>
9+
.md-subheader + .md-subheader {
10+
margin-top: 16px;
11+
}
12+
</style>
13+
14+
<script>
15+
export default {
16+
name: 'Subheader'
17+
}
18+
</script>

docs/app/routes.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ export const routes = [
6464
name: 'components/radio',
6565
component: () => import('./pages/Components/Radio/Radio.vue')
6666
},
67+
{
68+
path: '/components/subheader',
69+
name: 'components/subheader',
70+
component: () => import('./pages/Components/Subheader/Subheader.vue')
71+
},
6772
{
6873
path: '/components/switch',
6974
name: 'components/switch',

docs/app/template/MainNavContent.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
</div>
2020

2121
<router-link to="/components/icon">{{ $t('pages.icon.title') }}</router-link>
22+
<router-link to="/components/subheader">{{ $t('pages.subheader.title') }}</router-link>
2223
<router-link to="/components/toolbar">{{ $t('pages.toolbar.title') }}</router-link>
2324
</div>
2425

src/components/MdDivider/MdDivider.vue

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<template>
2-
<div class="md-divider" :class="[$mdActiveTheme]">
3-
<slot />
4-
</div>
2+
<hr class="md-divider" :class="[$mdActiveTheme]">
53
</template>
64

75
<script>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import Vue from 'vue'
2+
import mountTemplate from 'test/utils/mountTemplate'
3+
import MdSubheader from './MdSubheader.vue'
4+
5+
test('should render the subheader', async () => {
6+
const template = '<md-subheader>Lorem ipsum</md-subheader>'
7+
const wrapper = await mountTemplate(MdSubheader, template)
8+
9+
expect(wrapper.hasClass('md-subheader')).toBe(true)
10+
expect(wrapper.text()).toBe('Lorem ipsum')
11+
})
12+
13+
test('should render the theme class', async () => {
14+
const template = '<md-subheader md-theme="alt">Lorem ipsum</md-subheader>'
15+
const wrapper = await mountTemplate(MdSubheader, template)
16+
17+
expect(wrapper.hasClass('md-theme-alt')).toBe(true)
18+
})
19+
20+
test('should render a <li> tag when inside lists', async () => {
21+
Vue.component('MdList', {
22+
template: '<div><slot></slot></div>'
23+
})
24+
const template = `
25+
<md-list>
26+
<md-subheader>Lorem ipsum</md-subheader>
27+
</md-list>`
28+
const wrapper = await mountTemplate(MdSubheader, template)
29+
const subheader = wrapper.find(MdSubheader)[0]
30+
31+
expect(subheader.vm.$el.tagName.toLowerCase()).toBe('li')
32+
})
33+
34+
test('should render a <div> tag when inside any other element', async () => {
35+
const template = `<md-subheader>Lorem ipsum</md-subheader>`
36+
const wrapper = await mountTemplate(MdSubheader, template)
37+
const subheader = wrapper.find(MdSubheader)[0]
38+
39+
expect(subheader.vm.$el.tagName.toLowerCase()).toBe('div')
40+
})
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<template>
2+
<li class="md-subheader" :class="[$mdActiveTheme]" v-if="insideList">
3+
<slot></slot>
4+
</li>
5+
6+
<div class="md-subheader" :class="[$mdActiveTheme]" v-else>
7+
<slot></slot>
8+
</div>
9+
</template>
10+
11+
<script>
12+
import MdComponent from 'core/MdComponent'
13+
14+
export default new MdComponent({
15+
name: 'MdSubheader',
16+
computed: {
17+
insideList () {
18+
return this.$parent.$options._componentTag === 'md-list'
19+
}
20+
}
21+
})
22+
</script>
23+
24+
<style lang="scss">
25+
@import "~components/MdAnimation/variables";
26+
27+
.md-subheader {
28+
min-height: 48px;
29+
padding: 0 16px;
30+
display: flex;
31+
align-items: center;
32+
flex-flow: row wrap;
33+
font-size: 14px;
34+
font-weight: 500;
35+
}
36+
</style>

src/components/MdSubheader/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import MdSubheader from './MdSubheader'
2+
3+
export default Vue => {
4+
Vue.component(MdSubheader.name, MdSubheader)
5+
}

0 commit comments

Comments
 (0)