Skip to content

Commit d0a9bf3

Browse files
committed
feat(button): preliminary color context support
1 parent 6fcc771 commit d0a9bf3

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

elements/pfe-button/demo/pfe-button.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<link rel="stylesheet" href="/elements/pfe-button/demo/demo.css">
2+
<link rel="stylesheet" href="/core/pfe-styles/pfe.min.css">
23

34
<pfe-band size="small" class="contextual">
45
<h2 slot="header">Default - Medium size</h2>

elements/pfe-button/pfe-button.scss

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,31 @@
9898
:host([variant="secondary"]) {
9999
#container {
100100
::slotted(button) {
101-
color: pfe-local(Color, pfe-var(ui-accent)) !important;
101+
color: var(--pfe-button--Color, var(--pfe-theme--color--text)) !important;
102102
&::after {
103103
border-color: pfe-local(BorderColor, $region: after, $fallback: pfe-var(ui-accent)) !important;
104104
}
105105
}
106106
}
107107
}
108108

109+
:host([on^=dark]),
110+
:host([on=saturated]) {
111+
--pfe-theme--color--text: #ffffff;
112+
}
113+
114+
:host([on^=dark][variant="tertiary"]) {
115+
--pfe-theme--color--ui-accent: #ffffff;
116+
}
117+
118+
:host([on=saturated][variant="control"]) {
119+
--pfe-button__after--BorderColor: var(--pfe-theme--color--ui--border, #8a8d90);
120+
}
121+
122+
:host([on^=dark][variant="control"]) {
123+
--pfe-button__after--BorderColor: var(--pfe-theme--color--ui--border--darker, #151515);
124+
}
125+
109126
:host([variant="tertiary"]) {
110127
#container {
111128
::slotted(button) {
@@ -123,8 +140,8 @@
123140
color: pfe-local(Color, pfe-var(text)) !important;
124141
border-radius: pfe-local(BorderRadius, 0) !important;
125142
&::after {
126-
border-color: pfe-local(BorderColor, $region: after, $fallback: pfe-var(ui--border--lightest)) !important;
127-
border-bottom-color: pfe-var(ui--border) !important;
143+
border-color: var(--pfe-button__after--BorderColor, var(--pfe-theme--color--ui--border--lightest, #f0f0f0)) !important;
144+
border-bottom-color: var(--pfe-theme--color--ui--border, #8a8d90) !important;
128145
}
129146
}
130147

elements/pfe-button/pfe-button.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { LitElement, html } from 'lit';
1+
import { LitElement, html, PropertyValueMap } from 'lit';
22
import { customElement, property } from 'lit/decorators.js';
33

4-
import { bound, observed, pfelement } from '@patternfly/pfe-core/decorators.js';
4+
import { bound, colorContextConsumer, observed, pfelement } from '@patternfly/pfe-core/decorators.js';
55
import { deprecatedCustomEvent } from '@patternfly/pfe-core/functions/deprecatedCustomEvent.js';
66
import { Logger } from '@patternfly/pfe-core/controllers/logger.js';
77

88
import styles from './pfe-button.scss';
9+
import { ColorTheme } from '@patternfly/pfe-core';
910

1011
/**
1112
* Buttons allow users to perform an action when triggered. They feature a text label, a background or a border, and icons.
@@ -81,6 +82,12 @@ export class PfeButton extends LitElement {
8182
@observed
8283
@property() type?: 'button'|'submit'|'reset';
8384

85+
/**
86+
* Sets color theme based on parent context
87+
*/
88+
@colorContextConsumer()
89+
@property({ reflect: true }) on?: ColorTheme;
90+
8491
private logger = new Logger(this);
8592

8693
private mo = new MutationObserver(this.onMutation);
@@ -91,7 +98,6 @@ export class PfeButton extends LitElement {
9198

9299
connectedCallback() {
93100
this.onSlotChange();
94-
this.onMutation();
95101
super.connectedCallback();
96102
this.addEventListener('click', this.onClick);
97103
}
@@ -104,6 +110,11 @@ export class PfeButton extends LitElement {
104110
`;
105111
}
106112

113+
protected firstUpdated(): void {
114+
this._disabledChanged();
115+
this.onMutation();
116+
}
117+
107118
protected _typeChanged() {
108119
if (this.button && this.button.type !== this.type) {
109120
if (this.type) {

0 commit comments

Comments
 (0)