diff --git a/core/src/components.d.ts b/core/src/components.d.ts index 2aa816ffa0..559bf6bfb0 100644 --- a/core/src/components.d.ts +++ b/core/src/components.d.ts @@ -4442,6 +4442,10 @@ declare namespace LocalJSX { * The mode determines which platform styles to use. */ "mode"?: "ios" | "md"; + /** + * Emitted when the color changes. + */ + "onIonColor"?: (event: CustomEvent) => void; /** * Emitted when the styles change. */ diff --git a/core/src/components/item/item.md.scss b/core/src/components/item/item.md.scss index cfe05fdb7b..af1b4d5e11 100644 --- a/core/src/components/item/item.md.scss +++ b/core/src/components/item/item.md.scss @@ -282,3 +282,14 @@ :host(.item-has-focus:not(.ion-color)) ::slotted(.label-floating) { color: $label-md-text-color-focused; } + +// Material Design Inputs: Highlight Color +// -------------------------------------------------- + +:host(.ion-color) { + --highlight-color-focused: #{current-color(contrast)}; +} + +:host(.item-label-color) { + --highlight-color-focused: #{current-color(base)}; +} diff --git a/core/src/components/item/item.tsx b/core/src/components/item/item.tsx index 124cc8edfc..179c34d845 100644 --- a/core/src/components/item/item.tsx +++ b/core/src/components/item/item.tsx @@ -28,6 +28,7 @@ import { createColorClasses, hostContext, openURL } from '../../utils/theme'; }) export class Item implements ComponentInterface, AnchorInterface, ButtonInterface { + private labelColorStyles = {}; private itemStyles = new Map(); @Element() el!: HTMLIonItemElement; @@ -111,6 +112,18 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac */ @Prop() type: 'submit' | 'reset' | 'button' = 'button'; + @Listen('ionColor') + labelColorChanged(ev: CustomEvent) { + const { color } = this; + + // There will be a conflict with item color if + // we apply the label color to item, so we ignore + // the label color if the user sets a color on item + if (color === undefined) { + this.labelColorStyles = ev.detail; + } + } + @Listen('ionStyle') itemStyle(ev: CustomEvent) { ev.stopPropagation(); @@ -212,7 +225,7 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac } render() { - const { detail, detailIcon, download, lines, disabled, href, rel, target, routerAnimation, routerDirection } = this; + const { detail, detailIcon, download, labelColorStyles, lines, disabled, href, rel, target, routerAnimation, routerDirection } = this; const childStyles = {}; const mode = getIonMode(this); const clickable = this.isClickable(); @@ -236,6 +249,7 @@ export class Item implements ComponentInterface, AnchorInterface, ButtonInterfac aria-disabled={disabled ? 'true' : null} class={{ ...childStyles, + ...labelColorStyles, ...createColorClasses(this.color, { 'item': true, [mode]: true, diff --git a/core/src/components/label/label.md.scss b/core/src/components/label/label.md.scss index 4bdb56c259..5a773408d2 100644 --- a/core/src/components/label/label.md.scss +++ b/core/src/components/label/label.md.scss @@ -44,11 +44,16 @@ @include transform(translateY(50%), scale(.75)); } -:host-context(.item-has-focus).label-stacked, -:host-context(.item-has-focus).label-floating { +:host-context(.item-has-focus).label-stacked:not(.ion-color), +:host-context(.item-has-focus).label-floating:not(.ion-color) { color: $label-md-text-color-focused; } +:host-context(.item-has-focus.ion-color).label-stacked:not(.ion-color), +:host-context(.item-has-focus.ion-color).label-floating:not(.ion-color) { + color: #{current-color(contrast)}; +} + // MD Typography // -------------------------------------------------- diff --git a/core/src/components/label/label.tsx b/core/src/components/label/label.tsx index 2bf557004f..5acef0a20d 100644 --- a/core/src/components/label/label.tsx +++ b/core/src/components/label/label.tsx @@ -32,6 +32,12 @@ export class Label implements ComponentInterface { */ @Prop() position?: 'fixed' | 'stacked' | 'floating'; + /** + * Emitted when the color changes. + * @internal + */ + @Event() ionColor!: EventEmitter; + /** * Emitted when the styles change. * @internal @@ -44,6 +50,7 @@ export class Label implements ComponentInterface { this.inRange = !!this.el.closest('ion-range'); this.noAnimate = (this.position === 'floating'); this.emitStyle(); + this.emitColor(); } componentDidLoad() { @@ -54,11 +61,25 @@ export class Label implements ComponentInterface { } } + @Watch('color') + colorChanged() { + this.emitColor(); + } + @Watch('position') positionChanged() { this.emitStyle(); } + private emitColor() { + const { color } = this; + + this.ionColor.emit({ + 'item-label-color': color !== undefined, + [`ion-color-${color}`]: color !== undefined + }); + } + private emitStyle() { const { inRange, position } = this; diff --git a/core/src/components/label/test/basic/index.html b/core/src/components/label/test/basic/index.html index 60ff708164..3f0954d145 100644 --- a/core/src/components/label/test/basic/index.html +++ b/core/src/components/label/test/basic/index.html @@ -17,6 +17,11 @@ Label - Basic + + + Color Change + + @@ -58,10 +63,37 @@ Floating + + Floating: Success + + Stacked + + Stacked: Danger + + + + + + + (Item: Tertiary) Floating + + + + (Item: Primary) Stacked + + + + (Item: Tertiary) Floating: Success + + + + (Item: Primary) Stacked: Danger + + @@ -70,6 +102,17 @@ color: lightblue; } + +