Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove color-context JS in favor of color-scheme and light-dark() #2138

Draft
wants to merge 35 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
155c5ce
docs: add color-scheme stylesheet
zeroedin Jan 22, 2025
28d5253
fix(accordion): use color-scheme
zeroedin Jan 22, 2025
d1b542d
fix(alert): use color-scheme
zeroedin Jan 22, 2025
1e75a4c
fix(audio-player): use color-scheme
zeroedin Jan 22, 2025
6bbde2a
fix(avatar): use color-scheme
zeroedin Jan 22, 2025
8af51ed
fix(badge): use color-scheme
zeroedin Jan 22, 2025
5dcec2b
fix(blockquote): use color-scheme
zeroedin Jan 22, 2025
c45da3b
fix(breadcrumb): use color-scheme
zeroedin Jan 22, 2025
4dba5c4
fix(button): use color-scheme
zeroedin Jan 22, 2025
e221bb6
fix(card): use color-scheme
zeroedin Jan 22, 2025
192f486
fix(code-block): use color-scheme
zeroedin Jan 22, 2025
4b2d898
fix(cta): use color-scheme
zeroedin Jan 22, 2025
275c44a
fix(footer): use color-scheme
zeroedin Jan 22, 2025
bf820aa
fix(health-index): use color-scheme
zeroedin Jan 22, 2025
1ebbcc7
fix(menu): use color-scheme
zeroedin Jan 22, 2025
46b9a84
fix(navigation-secondary): use color-scheme
zeroedin Jan 22, 2025
57a8e42
fix(pagination): use color-scheme
zeroedin Jan 22, 2025
9340fa2
fix(site-status): use color-scheme
zeroedin Jan 22, 2025
b220910
fix(spinner): use color-scheme
zeroedin Jan 22, 2025
fa14484
fix(stat): use color-scheme
zeroedin Jan 22, 2025
81be9f3
fix(subnav): use color-scheme
zeroedin Jan 22, 2025
92a09dc
fix(surface): use color-scheme
zeroedin Jan 22, 2025
c833810
fix(switch): use color-scheme
zeroedin Jan 22, 2025
945649f
fix(tabs): use color-scheme
zeroedin Jan 22, 2025
0ec823b
fix(tag): use color-scheme
zeroedin Jan 22, 2025
6bf8661
fix(tile): use color-scheme
zeroedin Jan 22, 2025
e22adc2
fix(tooltip): use color-scheme
zeroedin Jan 22, 2025
0c2f657
fix(video-embed): use color-scheme
zeroedin Jan 22, 2025
cb0b859
fix(context-demo): use color-scheme
zeroedin Jan 22, 2025
874962f
fix: apply only keyword to color-scheme
zeroedin Jan 23, 2025
731852a
Merge branch 'main' into poc/remove-color-context
zeroedin Jan 23, 2025
328b057
fix(cta): update cta variants
zeroedin Jan 23, 2025
497043b
fix: clean up missed dark classes
zeroedin Jan 23, 2025
172911a
fix: simplify css use computed values where optimal
zeroedin Jan 23, 2025
a95f9d8
Merge branch 'main' into poc/remove-color-context
zeroedin Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions docs/styles/color-scheme.css
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file should

  1. live in the tokens repo
  2. be generated through style dictionary build there
  3. have two flavours: :host([color-palette=whatev]) for shadow and [color-palette=whatev] for light (not super sure about the lightdom one...)

Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
:root {
--rh-color-surface:
light-dark(var(--rh-color-surface-lightest),
var(--rh-color-surface-darkest));
--rh-color-accent-base:
light-dark(var(--rh-color-accent-base-on-light),
var(--rh-color-accent-base-on-dark));
--rh-color-accent-brand:
light-dark(var(--rh-color-accent-brand-on-light),
var(--rh-color-accent-brand-on-dark));
--rh-color-border-strong:
light-dark(var(--rh-color-border-strong-on-light),
var(--rh-color-border-strong-on-dark));
--rh-color-border-subtle:
light-dark(var(--rh-color-border-subtle-on-light),
var(--rh-color-border-subtle-on-dark));
--rh-color-border-interactive:
light-dark(var(--rh-color-border-interactive-on-light),
var(--rh-color-border-interactive-on-dark));
--rh-color-border-destructive:
light-dark(var(--rh-color-border-destructive-on-light),
var(--rh-color-border-destructive-on-dark));
--rh-color-border-status-danger:
light-dark(var(--rh-color-border-status-danger-on-light),
var(--rh-color-border-status-danger-on-dark));
--rh-color-border-status-caution:
light-dark(var(--rh-color-border-status-caution-on-light),
var(--rh-color-border-status-caution-on-dark));
--rh-color-border-status-warning:
light-dark(var(--rh-color-border-status-warning-on-light),
var(--rh-color-border-status-warning-on-dark));
--rh-color-border-status-neutral:
light-dark(var(--rh-color-border-status-neutral-on-light),
var(--rh-color-border-status-neutral-on-dark));
--rh-color-border-status-info:
light-dark(var(--rh-color-border-status-info-on-light),
var(--rh-color-border-status-info-on-dark));
--rh-color-border-status-success:
light-dark(var(--rh-color-border-status-success-on-light),
var(--rh-color-border-status-success-on-dark));
--rh-color-brand-red:
light-dark(var(--rh-color-brand-red-on-light),
var(--rh-color-brand-red-on-dark));
--rh-color-icon-primary:
light-dark(var(--rh-color-icon-primary-on-light),
var(--rh-color-icon-primary-on-dark));
--rh-color-icon-secondary:
light-dark(var(--rh-color-icon-secondary-on-light),
var(--rh-color-icon-secondary-on-dark));
--rh-color-icon-status-danger:
light-dark(var(--rh-color-icon-status-danger-on-light),
var(--rh-color-icon-status-danger-on-dark));
--rh-color-icon-status-caution:
light-dark(var(--rh-color-icon-status-caution-on-light),
var(--rh-color-icon-status-caution-on-dark));
--rh-color-icon-status-warning:
light-dark(var(--rh-color-icon-status-warning-on-light),
var(--rh-color-icon-status-warning-on-dark));
--rh-color-icon-status-default:
light-dark(var(--rh-color-icon-status-default-on-light),
var(--rh-color-icon-status-default-on-dark));
--rh-color-icon-status-neutral:
light-dark(var(--rh-color-icon-status-neutral-on-light),
var(--rh-color-icon-status-neutral-on-dark));
--rh-color-icon-status-info:
light-dark(var(--rh-color-icon-status-info-on-light),
var(--rh-color-icon-status-info-on-dark));
--rh-color-icon-status-success:
light-dark(var(--rh-color-icon-status-success-on-light),
var(--rh-color-icon-status-success-on-dark));
--rh-color-interactive-primary-default:
light-dark(var(--rh-color-interactive-primary-default-on-light),
var(--rh-color-interactive-primary-default-on-dark));
--rh-color-interactive-primary-hover:
light-dark(var(--rh-color-interactive-primary-hover-on-light),
var(--rh-color-interactive-primary-hover-on-dark));
--rh-color-interactive-primary-active:
light-dark(var(--rh-color-interactive-primary-active-on-light),
var(--rh-color-interactive-primary-active-on-dark));
--rh-color-interactive-primary-focus:
light-dark(var(--rh-color-interactive-primary-focus-on-light),
var(--rh-color-interactive-primary-focus-on-dark));
--rh-color-interactive-primary-visited-default:
light-dark(var(--rh-color-interactive-primary-visited-default-on-light),
var(--rh-color-interactive-primary-visited-default-on-dark));
--rh-color-interactive-primary-visited-hover:
light-dark(var(--rh-color-interactive-primary-visited-hover-on-light),
var(--rh-color-interactive-primary-visited-hover-on-dark));
--rh-color-interactive-primary-visited-active:
light-dark(var(--rh-color-interactive-primary-visited-active-on-light),
var(--rh-color-interactive-primary-visited-active-on-dark));
--rh-color-interactive-primary-visited-focus:
light-dark(var(--rh-color-interactive-primary-visited-focus-on-light),
var(--rh-color-interactive-primary-visited-focus-on-dark));
--rh-color-interactive-secondary-default:
light-dark(var(--rh-color-interactive-secondary-default-on-light),
var(--rh-color-interactive-secondary-default-on-dark));
--rh-color-interactive-secondary-hover:
light-dark(var(--rh-color-interactive-secondary-hover-on-light),
var(--rh-color-interactive-secondary-hover-on-dark));
--rh-color-interactive-secondary-active:
light-dark(var(--rh-color-interactive-secondary-active-on-light),
var(--rh-color-interactive-secondary-active-on-dark));
--rh-color-interactive-secondary-focus:
light-dark(var(--rh-color-interactive-secondary-focus-on-light),
var(--rh-color-interactive-secondary-focus-on-dark));
--rh-color-interactive-secondary-visited-default:
light-dark(var(--rh-color-interactive-secondary-visited-default-on-light),
var(--rh-color-interactive-secondary-visited-default-on-dark));
--rh-color-interactive-secondary-visited-hover:
light-dark(var(--rh-color-interactive-secondary-visited-hover-on-light),
var(--rh-color-interactive-secondary-visited-hover-on-dark));
--rh-color-interactive-secondary-visited-active:
light-dark(var(--rh-color-interactive-secondary-visited-active-on-light),
var(--rh-color-interactive-secondary-visited-active-on-dark));
--rh-color-interactive-secondary-visited-focus:
light-dark(var(--rh-color-interactive-secondary-visited-focus-on-light),
var(--rh-color-interactive-secondary-visited-focus-on-dark));
--rh-color-status-danger:
light-dark(var(--rh-color-status-danger-on-light),
var(--rh-color-status-danger-on-dark));
--rh-color-status-caution:
light-dark(var(--rh-color-status-caution-on-light),
var(--rh-color-status-caution-on-dark));
--rh-color-status-warning:
light-dark(var(--rh-color-status-warning-on-light),
var(--rh-color-status-warning-on-dark));
--rh-color-status-neutral:
light-dark(var(--rh-color-status-neutral-on-light),
var(--rh-color-status-neutral-on-dark));
--rh-color-status-note:
light-dark(var(--rh-color-status-note-on-light),
var(--rh-color-status-note-on-dark));
--rh-color-status-info:
light-dark(var(--rh-color-status-info-on-light),
var(--rh-color-status-info-on-dark));
--rh-color-status-success:
light-dark(var(--rh-color-status-success-on-light),
var(--rh-color-status-success-on-dark));
--rh-color-surface-status-danger:
light-dark(var(--rh-color-surface-status-danger-on-light),
var(--rh-color-surface-status-danger-on-dark));
--rh-color-surface-status-caution:
light-dark(var(--rh-color-surface-status-caution-on-light),
var(--rh-color-surface-status-caution-on-dark));
--rh-color-surface-status-warning:
light-dark(var(--rh-color-surface-status-warning-on-light),
var(--rh-color-surface-status-warning-on-dark));
--rh-color-surface-status-default:
light-dark(var(--rh-color-surface-status-default-on-light),
var(--rh-color-surface-status-default-on-dark));
--rh-color-surface-status-neutral:
light-dark(var(--rh-color-surface-status-neutral-on-light),
var(--rh-color-surface-status-neutral-on-dark));
--rh-color-surface-status-info:
light-dark(var(--rh-color-surface-status-info-on-light),
var(--rh-color-surface-status-info-on-dark));
--rh-color-surface-status-success:
light-dark(var(--rh-color-surface-status-success-on-light),
var(--rh-color-surface-status-success-on-dark));
--rh-color-text-primary:
light-dark(var(--rh-color-text-primary-on-light),
var(--rh-color-text-primary-on-dark));
--rh-color-text-secondary:
light-dark(var(--rh-color-text-secondary-on-light),
var(--rh-color-text-secondary-on-dark));
--rh-color-text-brand:
light-dark(var(--rh-color-text-brand-on-light),
var(--rh-color-text-brand-on-dark));
}
2 changes: 2 additions & 0 deletions docs/styles/demo/dev-server.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
reset,
fonts,
tokens,
color-scheme,
typography,
base,
layout;

@import url('../reset.css') layer(reset);
@import url('../fonts.css') layer(fonts);
@import url('/node_modules/@rhds/tokens/css/global.css') layer(tokens);
@import url('../color-scheme.css') layer(color-scheme);
@import url('../typography.css') layer(typography);

@layer base {
Expand Down
2 changes: 2 additions & 0 deletions docs/styles/demo/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
reset,
fonts,
tokens,
color-scheme,
typography;

@import url('../reset.css') layer(reset);
@import url('../fonts.css') layer(fonts);
@import url('/assets/packages/@rhds/tokens/css/global.css') layer(tokens);
@import url('../color-scheme.css') layer(color-scheme);
@import url('../typography.css') layer(typography);

html,
Expand Down
2 changes: 2 additions & 0 deletions docs/styles/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
reset,
fonts,
tokens,
color-scheme,
typography,
base,
grid,
Expand All @@ -18,6 +19,7 @@
@import url('reset.css') layer(reset);
@import url('fonts.css') layer(fonts);
@import url('/assets/packages/@rhds/tokens/css/global.css') layer(tokens);
@import url('color-scheme.css') layer(color-scheme);
@import url('typography.css') layer(typography);
@import url('grid.css') layer(grid);
@import url('lightdom.css') layer(lightdom);
Expand Down
6 changes: 3 additions & 3 deletions elements/rh-accordion/demo/color-context.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

<rh-cta href="#">Call To Action</rh-cta>

<rh-accordion>
<rh-accordion color-palette="lightest" id="nested">

<rh-accordion-header expanded color-palette="lightest">Forced Palette</rh-accordion-header>
<rh-accordion-panel id="nested" color-palette="lightest">
<rh-accordion-header expanded>Forced Palette</rh-accordion-header>
<rh-accordion-panel>
<label> No matter the parent context, this panel should always be
<rh-context-picker target="nested" value="lightest"></rh-context-picker>
</label>
Expand Down
18 changes: 7 additions & 11 deletions elements/rh-accordion/rh-accordion-header.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
padding: 0;
margin: 0;
color: var(--rh-color-text-primary);
background-color: var(--rh-color-surface);
background-color:
light-dark(var(--rh-color-surface-lightest),
var(--rh-color-surface-darkest));
font-weight: var(--rh-font-weight-body-text-medium, 500);
}

Expand Down Expand Up @@ -75,8 +77,7 @@ span {
}

&:is(:hover,:active,:focus) {
&.light { background-color: var(--rh-color-surface-lighter); }
&.dark { background-color: var(--rh-color-surface-dark-alt); }
background-color: light-dark(var(--rh-color-surface-lighter), var(--rh-color-surface-dark-alt));

& span {
color: var(--rh-color-text-primary);
Expand All @@ -101,18 +102,13 @@ span {

&.expanded {
--_after-background-color: var(--rh-color-accent-brand);
--rh-color-surface:
light-dark(var(--rh-color-surface-lightest, #ffffff),
var(--rh-color-surface-darkest, #151515));

& #icon {
rotate: calc(var(--_isRTL, -1) * 180deg);
}

&.on.light {
--rh-color-surface: var(--rh-color-surface-lightest, #ffffff);
}

&.on.dark {
--rh-color-surface: var(--rh-color-surface-darkest, #151515);
}
}
}

Expand Down
8 changes: 2 additions & 6 deletions elements/rh-accordion/rh-accordion-header.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { observes } from '@patternfly/pfe-core/decorators/observes.js';

import { InternalsController } from '@patternfly/pfe-core/controllers/internals-controller.js';
import { DirController } from '../../lib/DirController.js';
import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/consumer.js';

import { consume } from '@lit/context';

Expand Down Expand Up @@ -55,9 +54,6 @@ export class RhAccordionHeader extends LitElement {
@property({ attribute: false })
private ctx?: RhAccordionContext;

@colorContextConsumer()
private on?: ColorTheme;

#dir = new DirController(this);

#internals = InternalsController.of(this, {
Expand All @@ -81,12 +77,12 @@ export class RhAccordionHeader extends LitElement {
}

render() {
const { expanded, on = 'light' } = this;
const { expanded } = this;
const { accents, large = false } = this.ctx ?? {};
const rtl = this.#dir.dir === 'rtl';
return html`
<button id="button"
class="${classMap({ on: true, toggle: true, [on]: !!on, rtl, large, expanded })}"
class="${classMap({ toggle: true, rtl, large, expanded })}"
@click="${this.#onClick}">
<span id="header-container" class="${classMap({ [accents ?? '']: !!accents })}">
<span id="header-text" part="text"><slot></slot></span>
Expand Down
42 changes: 37 additions & 5 deletions elements/rh-accordion/rh-accordion-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,48 @@
}

#container {
--rh-color-surface: light-dark(var(--rh-color-surface-lightest), var(--rh-color-surface-darkest));

border-inline-end: 1px solid var(--rh-color-border-subtle);
background-color: var(--rh-color-surface);
}

.expanded.on.light {
--rh-color-surface: var(--rh-color-surface-lightest, #ffffff);
&.palette-light {
--rh-color-surface: var(--rh-color-surface-light, #e0e0e0);
}

&.palette-lighter {
--rh-color-surface: var(--rh-color-surface-lighter, #f2f2f2);
}

&.palette-lightest {
--rh-color-surface: var(--rh-color-surface-lightest, #ffffff);
}

&.palette-dark {
--rh-color-surface: var(--rh-color-surface-dark, #383838);
}

&.palette-darker {
--rh-color-surface: var(--rh-color-surface-darker, #1f1f1f);
}

&.palette-darkest {
--rh-color-surface: var(--rh-color-surface-darkest, #151515);
}

&:is(.palette-light, .palette-lighter, .palette-lightest) {
color-scheme: only light;
}

&:is(.palette-dark, .palette-darker, .palette-darkest) {
color-scheme: only dark;
}
}

.expanded.on.dark {
--rh-color-surface: var(--rh-color-surface-darkest, #151515);
.expanded {
--rh-color-surface:
light-dark(var(--rh-color-surface-lightest, #ffffff),
var(--rh-color-surface-darkest, #151515));
}

.body:after {
Expand Down
12 changes: 2 additions & 10 deletions elements/rh-accordion/rh-accordion-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ import { classMap } from 'lit/directives/class-map.js';
import { customElement } from 'lit/decorators/custom-element.js';
import { property } from 'lit/decorators/property.js';

import { colorContextConsumer, type ColorTheme } from '../../lib/context/color/consumer.js';
import { colorContextProvider, type ColorPalette } from '../../lib/context/color/provider.js';

import { getRandomId } from '@patternfly/pfe-core/functions/random.js';

import styles from './rh-accordion-panel.css';
Expand All @@ -26,11 +23,6 @@ export class RhAccordionPanel extends LitElement {

@property({ type: Boolean, reflect: true }) expanded = false;

@colorContextProvider()
@property({ reflect: true, attribute: 'color-palette' }) colorPalette?: ColorPalette;

@colorContextConsumer() private on?: ColorTheme;

@consume({ context, subscribe: true })
@property({ attribute: false })
private ctx?: RhAccordionContext;
Expand All @@ -42,11 +34,11 @@ export class RhAccordionPanel extends LitElement {
}

override render() {
const { on = '', expanded } = this;
const { expanded } = this;
const { large = false } = this.ctx ?? {};
return html`
<div id="container"
class="${classMap({ on: true, [on]: !!on, large, expanded, content: true })}"
class="${classMap({ large, expanded, content: true })}"
part="container"
tabindex="-1">
<slot class="body"></slot>
Expand Down
Loading
Loading