Lighter color palette
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
diff --git a/elements/rh-card/rh-card.ts b/elements/rh-card/rh-card.ts
index 4b5785f3c9..e43da8e482 100644
--- a/elements/rh-card/rh-card.ts
+++ b/elements/rh-card/rh-card.ts
@@ -43,6 +43,8 @@ import styles from './rh-card.css';
export class RhCard extends LitElement {
static styles = [styles];
+ @property({ reflect: true }) id = '';
+
/**
* Sets color palette, which affects the element's styles as well as descendants' color theme.
* Overrides parent color context.
@@ -69,6 +71,7 @@ export class RhCard extends LitElement {
#slots = new SlotController(this, 'header', 'image', null, 'footer');
#isPromo = this.variant === 'promo';
+
#isStandardPromo = false;
willUpdate() {
diff --git a/elements/rh-cta/rh-cta.ts b/elements/rh-cta/rh-cta.ts
index dade2cc79f..91a3d061a6 100644
--- a/elements/rh-cta/rh-cta.ts
+++ b/elements/rh-cta/rh-cta.ts
@@ -75,6 +75,8 @@ function isSupportedContent(el: Element | null): el is HTMLAnchorElement | HTMLB
export class RhCta extends LitElement {
static readonly styles = [style];
+ @property({ reflect: true }) id = '';
+
/**
* Indicates the importance of this call-to-action in the context of the page.
* Will also influence how the call-to-action is styled.
diff --git a/lib/context/color/consumer.ts b/lib/context/color/consumer.ts
index e28de76c95..74b7eb2b3c 100644
--- a/lib/context/color/consumer.ts
+++ b/lib/context/color/consumer.ts
@@ -24,14 +24,15 @@ export type ColorTheme = (
* The consumer has no direct access to the context, it must receive it from the provider.
*/
export class ColorContextConsumer extends ContextConsumer {
- /** The last-known color context on the host */
- protected last: ColorTheme | null = null;
-
constructor(
host: ReactiveElement,
callback: (value: ContextType, dispose?: () => void) => void,
) {
- super(host, { callback, context, subscribe: true });
+ super(host, {
+ callback,
+ context,
+ subscribe: true,
+ });
new StyleController(host, styles);
}
}
@@ -44,6 +45,7 @@ export function colorContextConsumer() {
return function(proto: T, key: string | keyof T) {
(proto.constructor as typeof ReactiveElement).addInitializer((instance: ReactiveElement) => {
new ColorContextConsumer(instance, (value: ColorTheme | null) => {
+ console.log(`${instance.id ?? instance.localName} receiving`, { key, value });
(instance as T)[key as keyof T] = value as T[keyof T];
});
});
diff --git a/lib/context/color/provider.ts b/lib/context/color/provider.ts
index a411782ac9..0c4cc98103 100644
--- a/lib/context/color/provider.ts
+++ b/lib/context/color/provider.ts
@@ -1,15 +1,13 @@
-import type { ReactiveElement } from 'lit';
-import type { ColorTheme } from './consumer.js';
+import { ReactiveElement } from 'lit';
import { ContextProvider } from '@lit/context';
-import { Logger } from '@patternfly/pfe-core/controllers/logger.js';
-
import { StyleController } from '@patternfly/pfe-core/controllers/style-controller.js';
import { context } from './context.js';
import styles from '@rhds/tokens/css/color-context-provider.css.js';
+import type { ColorTheme } from './consumer.js';
/**
* A `ColorPalette` is a collection of specific color values
@@ -30,97 +28,55 @@ export type ColorPalette = (
| 'darkest'
);
-export interface ColorContextProviderOptions {
- /** Attribute to set context. Providers only */
- attribute?: string;
-}
-
/**
* `ColorContextProvider` is responsible to derive a context value from CSS and provide it to its
* descendents.
*/
-export class ColorContextProvider extends ContextProvider {
- static readonly contexts = new Map(Object.entries({
- darkest: 'dark' as const,
- darker: 'dark' as const,
- dark: 'dark' as const,
- light: 'light' as const,
- lighter: 'light' as const,
- lightest: 'light' as const,
- }));
-
- /** The last-known color context on the host */
- protected last: ColorTheme | null = null;
-
- #attribute: string;
-
- /** Mutation observer which updates consumers when `color-palette` attribute change. */
- #mo = new MutationObserver(() => this.update());
-
- #logger: Logger;
-
- get #local() {
- return ColorContextProvider.contexts.get(this.host.getAttribute(this.#attribute) ?? '');
- }
-
- constructor(protected host: ReactiveElement, options?: ColorContextProviderOptions) {
+class ColorContextProvider extends ContextProvider {
+ constructor(protected host: ReactiveElement) {
super(host, { context });
- new StyleController(host, styles);
- this.#logger = new Logger(host);
- const { attribute = 'color-palette' } = options ?? {};
- this.#attribute = attribute;
- if (this.#attribute !== 'color-palette') {
- this.#logger.warn('color context currently supports the `color-palette` attribute only.');
- }
- }
-
- /**
- * When a context provider connects, it listens for context-request events
- * it also fires all previously fired context-request events from their hosts,
- * in case this context provider upgraded after and is closer to a given consumer.
- */
- async hostConnected() {
- super.hostConnected();
- this.#mo.observe(this.host, { attributes: true, attributeFilter: [this.#attribute] });
}
+}
- /**
- * When a context provider disconnects, it disconnects its mutation observer
- */
- hostDisconnected() {
- this.#mo.disconnect();
- }
+const paletteBackgroundMap = new Map(Object.entries({
+ darkest: 'dark' as const,
+ darker: 'dark' as const,
+ dark: 'dark' as const,
+ light: 'light' as const,
+ lighter: 'light' as const,
+ lightest: 'light' as const,
+}));
- /**
- * Calls the context callback for all consumers
- * @param [force] override theme
- */
- public update(force?: ColorTheme) {
- this.setValue(force ?? this.#local ?? null);
- }
-}
/**
* Makes this element a color context provider which updates its consumers when the decorated field changes
* @param options options
*/
-export function colorContextProvider(options?: ColorContextProviderOptions) {
- return (proto: ReactiveElement, propertyName: string) => {
- const controllers = new WeakMap();
- const values = new Map();
+export function colorContextProvider() {
+ return (proto: ReactiveElement, key: string) => {
+ const controllers = new WeakMap();
+ const values = new Map();
const klass = (proto.constructor as typeof ReactiveElement);
- const propOpts = klass.getPropertyOptions(propertyName);
+ const propOpts = klass.getPropertyOptions(key);
const attribute = typeof propOpts.attribute === 'boolean' ? undefined : propOpts.attribute;
+ if (attribute !== 'color-palette') {
+ throw new Error('color context currently supports the `color-palette` attribute only.');
+ }
klass.addInitializer((instance: ReactiveElement) => {
- controllers.set(instance, new ColorContextProvider(instance, { attribute, ...options }));
+ controllers.set(instance, new ColorContextProvider(instance));
+ new StyleController(instance, styles);
});
- Object.defineProperty(proto, propertyName, {
+ Object.defineProperty(proto, key, {
get(this: ReactiveElement) {
return values.get(this);
},
- set(this: ReactiveElement, value: ColorTheme) {
- controllers.get(this)!.setValue(value);
- values.set(this, value);
+ set(this: ReactiveElement, value: ColorPalette) {
+ const background = paletteBackgroundMap.get(value) ?? null;
+ if (this.id === 'card-d' || this.outerHTML?.includes('card-d')) {
+ console.log({ value, background });
+ }
+ controllers.get(this)!.setValue(background);
+ values.set(this, background);
},
enumerable: true,
configurable: true,