mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 11:41:20 +08:00
Support raw element enhancement
This commit is contained in:
@ -2,7 +2,7 @@ import {NgElement, Decorator} from 'angular2/angular2'
|
|||||||
import {IonicComponent} from 'ionic/config/component'
|
import {IonicComponent} from 'ionic/config/component'
|
||||||
|
|
||||||
@Decorator({
|
@Decorator({
|
||||||
selector: 'ion-button, [ion-button],.button',
|
selector: 'button, ion-button, [ion-button],.button',
|
||||||
})
|
})
|
||||||
export class Button {
|
export class Button {
|
||||||
constructor(
|
constructor(
|
||||||
@ -13,5 +13,6 @@ export class Button {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
new IonicComponent(Button, {
|
new IonicComponent(Button, {
|
||||||
|
enhanceRawElement: true,
|
||||||
propClasses: ['primary', 'secondary', 'danger', 'light', 'stable', 'dark', 'block']
|
propClasses: ['primary', 'secondary', 'danger', 'light', 'stable', 'dark', 'block']
|
||||||
})
|
})
|
||||||
|
@ -51,10 +51,10 @@
|
|||||||
<h2>With Properties</h2>
|
<h2>With Properties</h2>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<button ion-button primary>button.primary</button>
|
<button primary>button.primary</button>
|
||||||
<button ion-button secondary>button.secondary</button>
|
<button secondary>button.secondary</button>
|
||||||
<button ion-button stable>button.stable</button>
|
<button stable>button.stable</button>
|
||||||
<button ion-button light>button.light</button>
|
<button light>button.light</button>
|
||||||
<button ion-button dark>button.dark</button>
|
<button dark>button.dark</button>
|
||||||
<button ion-button danger>button.danger</button>
|
<button danger>button.danger</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,6 +11,7 @@ let platformMode = Platform.getMode();
|
|||||||
export class IonicComponent {
|
export class IonicComponent {
|
||||||
constructor(ComponentClass, {
|
constructor(ComponentClass, {
|
||||||
bind,
|
bind,
|
||||||
|
enhanceRawElement,
|
||||||
delegates,
|
delegates,
|
||||||
propClasses
|
propClasses
|
||||||
}) {
|
}) {
|
||||||
@ -31,6 +32,11 @@ export class IonicComponent {
|
|||||||
|
|
||||||
this.delegates = delegates || (delegates = {})
|
this.delegates = delegates || (delegates = {})
|
||||||
this.propClasses = propClasses || (propClasses = []);
|
this.propClasses = propClasses || (propClasses = []);
|
||||||
|
|
||||||
|
// Whether to support raw element enhancement (for example, supporting <button>).
|
||||||
|
// We only do this if there is a matching style property on the element
|
||||||
|
this.enhanceRawElement = enhanceRawElement || false;
|
||||||
|
|
||||||
// for (let delegateName of delegates) {
|
// for (let delegateName of delegates) {
|
||||||
// let delegate = delegates[delegateName]
|
// let delegate = delegates[delegateName]
|
||||||
// }
|
// }
|
||||||
@ -41,18 +47,27 @@ export class IonicComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
invoke(instance) {
|
invoke(instance) {
|
||||||
const config = this
|
const config = this;
|
||||||
|
|
||||||
dom.addClasses(instance.domElement, this.componentCssName, `${this.componentCssName}-${platformMode}`);
|
|
||||||
|
|
||||||
// For each property class, check if it exists on the element and add the
|
// For each property class, check if it exists on the element and add the
|
||||||
// corresponding classname for it
|
// corresponding classname for it, otherwise add it
|
||||||
|
let foundMatchingPropClass = false;
|
||||||
for (let propClass of this.propClasses) {
|
for (let propClass of this.propClasses) {
|
||||||
if(dom.hasAttribute(instance.domElement, propClass)) {
|
if(dom.hasAttribute(instance.domElement, propClass)) {
|
||||||
dom.addClass(instance.domElement, `${this.componentCssName}-${propClass}`);
|
dom.addClass(instance.domElement, `${this.componentCssName}-${propClass}`);
|
||||||
|
foundMatchingPropClass = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we want to enhance a raw element (for example, a button),
|
||||||
|
// only do it if we also have a matching prop class
|
||||||
|
if(!foundMatchingPropClass && this.enhanceRawElement) {
|
||||||
|
// Don't enhace this raw element
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add the base element classes (ex, button and button-ios)
|
||||||
|
dom.addClasses(instance.domElement, this.componentCssName, `${this.componentCssName}-${platformMode}`);
|
||||||
|
|
||||||
// Check and apply and property classes (properties that should be
|
// Check and apply and property classes (properties that should be
|
||||||
// converted to class names). For example, <button primary> should
|
// converted to class names). For example, <button primary> should
|
||||||
|
Reference in New Issue
Block a user