Skip to content

Commit

Permalink
Integrated primary and secondary into MaterialComponent
Browse files Browse the repository at this point in the history
Signed-off-by: Cromefire_ <cromefirehd@gmail.com>
  • Loading branch information
Cromefire_ committed Aug 1, 2018
1 parent 4a826f4 commit a5498b9
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
6 changes: 6 additions & 0 deletions ts/Base/MaterialComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ export abstract class MaterialComponent<
}
}

['primary', 'secondary'].forEach(themeProp => {
if (themeProp in this.props && this.props[themeProp] !== false) {
classText += ` mdc-theme--${themeProp}-bg`;
}
});

return classText;
}

Expand Down
10 changes: 1 addition & 9 deletions ts/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import autobind from 'autobind-decorator';
import {h} from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
import Icon from '../Icon/index';
import generateThemeClass from '../themeUtils/generateThemeClass';

export class ButtonIcon extends Icon {
protected componentName = 'button__icon';
Expand Down Expand Up @@ -38,20 +37,13 @@ export class Button<

protected componentName = 'button';
protected mdcProps = ['dense', 'raised', 'unelevated', 'outlined'];
protected themeProps = ['primary', 'secondary'];

@autobind
protected materialDom(props) {
const ButtonElement = props.href ? 'a' : 'button';
let className = '';
this.themeProps.forEach(themeProp => {
if (themeProp in props && props[themeProp] !== false) {
className += generateThemeClass(themeProp) + ' ';
}
});

return (
<ButtonElement ref={this.setControlRef} {...props} className={className}>
<ButtonElement ref={this.setControlRef} {...props}>
{this.props.children}
</ButtonElement>
);
Expand Down
11 changes: 1 addition & 10 deletions ts/Fab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import autobind from 'autobind-decorator';
import {h} from 'preact';
import MaterialComponent from '../Base/MaterialComponent';
import Icon from '../Icon/index';
import generateThemeClass from '../themeUtils/generateThemeClass';

export class FabIcon extends Icon {
protected componentName = 'fab__icon';
Expand All @@ -26,22 +25,14 @@ export class Fab extends MaterialComponent<IFabProps, IFabState> {

protected componentName = 'fab';
protected mdcProps = ['mini', 'exited'];
protected themeProps = ['primary', 'secondary'];

@autobind
protected materialDom(props) {
const classNames: string[] = [];
this.themeProps.forEach(themeProp => {
if (themeProp in props && props[themeProp] !== false) {
classNames.push(generateThemeClass(themeProp));
}
});

return (
<button
ref={this.setControlRef}
{...props}
className={classNames.join(' ')}>
{...props}>
{props.children}
</button>
);
Expand Down
3 changes: 0 additions & 3 deletions ts/themeUtils/generateThemeClass.ts

This file was deleted.

0 comments on commit a5498b9

Please sign in to comment.