mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 03:00:58 +08:00
refactor(button): using createColorClasses
This commit is contained in:
@ -2,7 +2,7 @@ import { Component, Element, Event, EventEmitter, Prop, State } from '@stencil/c
|
|||||||
|
|
||||||
import { Color, CssClassMap, Mode, RouterDirection } from '../../interface';
|
import { Color, CssClassMap, Mode, RouterDirection } from '../../interface';
|
||||||
import { hasShadowDom } from '../../utils/helpers';
|
import { hasShadowDom } from '../../utils/helpers';
|
||||||
import { openURL } from '../../utils/theme';
|
import { createColorClasses, openURL } from '../../utils/theme';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
tag: 'ion-button',
|
tag: 'ion-button',
|
||||||
@ -150,12 +150,13 @@ export class Button {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
class: {
|
class: {
|
||||||
|
...createColorClasses(color),
|
||||||
...getButtonClassMap(buttonType, mode),
|
...getButtonClassMap(buttonType, mode),
|
||||||
...getButtonTypeClassMap(buttonType, expand, mode),
|
...getButtonTypeClassMap(buttonType, expand, mode),
|
||||||
...getButtonTypeClassMap(buttonType, size, mode),
|
...getButtonTypeClassMap(buttonType, size, mode),
|
||||||
...getButtonTypeClassMap(buttonType, shape, mode),
|
...getButtonTypeClassMap(buttonType, shape, mode),
|
||||||
...getButtonTypeClassMap(buttonType, strong ? 'strong' : undefined, mode),
|
...getButtonTypeClassMap(buttonType, strong ? 'strong' : undefined, mode),
|
||||||
...getColorClassMap(buttonType, color, fill, mode),
|
...getButtonTypeClassMap(buttonType, fill, mode),
|
||||||
'focused': this.keyFocus,
|
'focused': this.keyFocus,
|
||||||
},
|
},
|
||||||
'ion-activable': true,
|
'ion-activable': true,
|
||||||
@ -218,21 +219,3 @@ function getButtonTypeClassMap(buttonType: string, type: string | undefined, mod
|
|||||||
[`${buttonType}-${type}-${mode}`]: true
|
[`${buttonType}-${type}-${mode}`]: true
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function getColorClassMap(buttonType: string, color: string | undefined, fill: string | undefined, mode: Mode): CssClassMap {
|
|
||||||
let className = buttonType;
|
|
||||||
|
|
||||||
if (fill !== undefined) {
|
|
||||||
className += `-${fill.toLowerCase()}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const map: CssClassMap = {
|
|
||||||
[className]: true,
|
|
||||||
[`${className}-${mode}`]: true,
|
|
||||||
};
|
|
||||||
if (color !== undefined) {
|
|
||||||
map[`ion-color`] = true;
|
|
||||||
map[`ion-color-${color}`] = true;
|
|
||||||
}
|
|
||||||
return map;
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user