refactor(components): move function to get classes from host to utils

Moved getElementClassObject function to utils/theme and updated the
components with child buttons to use this function to get the host
classes.

Adds the ability to pass classes down from host to child for content
and segment button

closes ionic-team/stencil#84
This commit is contained in:
Brandy Carney
2017-08-11 13:26:10 -04:00
parent 319d38ac1a
commit 4dcb174245
11 changed files with 80 additions and 68 deletions

View File

@ -1,5 +1,6 @@
import { Component, CssClassMap, Element, Prop } from '@stencil/core';
import { getElementClassObject } from '../../utils/theme';
@Component({
tag: 'ion-chip-button',
@ -71,25 +72,14 @@ export class ChipButton {
return classList;
}
/**
* @hidden
* Get the element classes to add to the child element
*/
private getElementClassList() {
let classList = [].concat(
this.el.className.length ? this.el.className.split(' ') : []
);
return classList;
}
render() {
const buttonType = 'chip-button';
var buttonClasses: CssClassMap = []
const hostClasses = getElementClassObject(this.el.classList);
const elementClasses: CssClassMap = []
.concat(
this.getButtonClassList(buttonType, this.mode),
this.getElementClassList(),
this.getStyleClassList(buttonType)
)
.reduce((prevValue, cssClass) => {
@ -99,6 +89,11 @@ export class ChipButton {
const TagType = this.href ? 'a' : 'button';
const buttonClasses = {
...hostClasses,
...elementClasses
}
return (
<TagType class={buttonClasses} disabled={this.disabled}>
<span class='button-inner'>