UNPKG

1.99 kBJavaScriptView Raw
1/*
2Copyright 2013-2015 ASIAL CORPORATION
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15
16*/
17
18import onsElements from '../ons/elements.js';
19import BaseElement from './base/base-element.js';
20import autoStyle from '../ons/autostyle.js';
21import ModifierUtil from '../ons/internal/modifier-util.js';
22import util from '../ons/util.js';
23
24const defaultClassName = 'list-title';
25const scheme = {'': 'list-title--*'};
26
27/**
28 * @element ons-list-title
29 * @category list
30 * @description
31 * [en]Represents a list title.[/en]
32 * [ja]リストのタイトルを表現します。[/ja]
33 * @example
34 * <ons-list-title>List Title</ons-list-title>
35 * <ons-list>
36 * <ons-list-item>Item</ons-list-item>
37 * </ons-list>
38 * @modifier material
39 * [en]Display a Material Design list title.[/en]
40 * [ja][/ja]
41 */
42
43export default class ListTitleElement extends BaseElement {
44
45 constructor() {
46 super();
47
48 this._compile();
49 }
50
51 _compile() {
52 autoStyle.prepare(this);
53 this.classList.add(defaultClassName);
54 ModifierUtil.initModifier(this, scheme);
55 }
56
57 static get observedAttributes() {
58 return ['modifier', 'class'];
59 }
60
61 attributeChangedCallback(name, last, current) {
62 switch (name) {
63 case 'class':
64 util.restoreClass(this, defaultClassName, scheme);
65 break;
66 case 'modifier':
67 ModifierUtil.onModifierChanged(last, current, this, scheme);
68 break;
69 }
70 }
71}
72
73onsElements.ListTitle = ListTitleElement;
74customElements.define('ons-list-title', ListTitleElement);